It's Friday night, Wesley is out, Sammi is not hungry, and Miss Melissa is asleep...
authorArt Cancro <ajc@citadel.org>
Sat, 11 Dec 2021 01:19:42 +0000 (20:19 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 11 Dec 2021 01:19:42 +0000 (20:19 -0500)
webcit-ng/http.c
webcit-ng/webcit.h

index 1df8b8efc035f84a97ad9be13477df58b6951a76..29a1fba6d5070e9ec4218d4fa5c6ae153c7e40c0 100644 (file)
@@ -114,6 +114,7 @@ void perform_one_http_transaction(struct client_handle *ch) {
 
        memset(&h, 0, sizeof h);
        h.request_headers = array_new(sizeof(struct keyval));
+       h.request_parms = array_new(sizeof(struct keyval));
        h.response_headers = array_new(sizeof(struct keyval));
 
        while (len = client_readline(ch, buf, sizeof buf), (len > 0)) {
@@ -158,6 +159,24 @@ void perform_one_http_transaction(struct client_handle *ch) {
 
        }
 
+       // If the URL had any query parameters in it, parse them out now.
+       char *p = strchr(h.url, '?');
+       if (p) {
+               *p++ = 0;                                               // insert a null to remove parameters from the URL
+               char *tok, *saveptr = NULL;
+               for (tok = strtok_r(p, "&", &saveptr); tok!=NULL; tok = strtok_r(NULL, "&", &saveptr)) {
+                       char *eq = strchr(tok, '=');
+                       if (eq) {
+                               *eq++ = 0;
+                               unescape_input(eq);
+                               struct keyval kv;
+                               kv.key = strdup(tok);
+                               kv.val = strdup(eq);
+                               array_append(h.request_parms, &kv);
+                       }
+               }
+       }
+
        // build up the site prefix, such as https://foo.bar.com:4343
        h.site_prefix = malloc(256);
        strcpy(h.site_prefix, (is_https ? "https://" : "http://"));
@@ -236,6 +255,13 @@ void perform_one_http_transaction(struct client_handle *ch) {
                array_delete_element_at(h.request_headers, 0);
        }
        array_free(h.request_headers);
+       while (array_len(h.request_parms) > 0) {
+               struct keyval *kv = array_get_element_at(h.request_parms, 0);
+               if (kv->key) free(kv->key);
+               if (kv->val) free(kv->val);
+               array_delete_element_at(h.request_parms, 0);
+       }
+       array_free(h.request_parms);
        while (array_len(h.response_headers) > 0) {
                struct keyval *kv = array_get_element_at(h.response_headers, 0);
                if (kv->key) free(kv->key);
index 0e5321354b0d67b121d5bf26ca6fd5d1ad671fa0..06269da81553cfcf0bc7a5dd921dcb67f997a222 100644 (file)
@@ -65,6 +65,7 @@ struct http_transaction {                     // The lifetime of an HTTP request goes through this
        Array *request_headers;
        char *request_body;
        long request_body_length;
+       Array *request_parms;                   // anything after the "?" in the URL
        int response_code;
        char *response_string;
        Array *response_headers;