-//
// This module handles HTTP transactions.
//
-// Copyright (c) 1996-2021 by the citadel.org team
+// Copyright (c) 1996-2022 by the citadel.org team
//
// This program is open source software. It runs great on the
// Linux operating system (and probably elsewhere). You can use,
}
// If the URL had any query parameters in it, parse them out now.
- char *p = strchr(h.url, '?');
+ char *p = (h.url ? strchr(h.url, '?') : NULL);
if (p) {
*p++ = 0; // insert a null to remove parameters from the URL
char *tok, *saveptr = NULL;
kv.key = strdup(tok);
kv.val = strdup(eq);
array_append(h.request_parms, &kv);
+ syslog(LOG_DEBUG, "\033[1m\033[33m| %s = %s\033[0m", kv.key, kv.val);
}
}
}
h.request_body = malloc(h.request_body_length);
client_read(ch, h.request_body, h.request_body_length);
- //write(2, HKEY("\033[31m"));
- //write(2, h.request_body, h.request_body_length);
- //write(2, HKEY("\033[0m\n"));
+ // Write the entire request body to stderr -- not what you want during normal operation.
+ #ifdef BODY_TO_STDERR
+ write(2, HKEY("\033[31m"));
+ write(2, h.request_body, h.request_body_length);
+ write(2, HKEY("\033[0m\n"));
+ #endif
}
+
// Now pass control up to the next layer to perform the request.
perform_request(&h);
- // Output the results back to the client.
- //write(2, HKEY("\033[32m"));
- //write(2, h.response_body, h.response_body_length);
- //write(2, HKEY("\033[0m\n"));
+ // Write the entire response body to stderr -- not what you want during normal operation.
+ #ifdef BODY_TO_STDERR
+ write(2, HKEY("\033[32m"));
+ write(2, h.response_body, h.response_body_length);
+ write(2, HKEY("\033[0m\n"));
+ #endif
+ // Output the results back to the client.
syslog(LOG_DEBUG, "> %03d %s", h.response_code, h.response_string);
client_printf(ch, "HTTP/1.1 %03d %s\r\n", h.response_code, h.response_string);
client_printf(ch, "Connection: close\r\n");
}
return (NULL);
}
+
+
+// Utility function to fetch a specific URL parameter from a completely read-in request.
+// Returns the value of the requested parameter, or NULL if the specified parameter was not sent.
+// The caller does NOT own the memory of the returned pointer, but can count on the pointer
+// to still be valid through the end of the transaction.
+char *get_url_param(struct http_transaction *h, char *requested_param) {
+ struct keyval *kv;
+ int i;
+ for (i=0; i<array_len(h->request_parms); ++i) {
+ kv = array_get_element_at(h->request_parms, i);
+ if (!strcasecmp(kv->key, requested_param)) {
+ return (kv->val);
+ }
+ }
+ return (NULL);
+}