http: decode POST parameters before applying options. (#174)

Code greatly reduced by @ayufan.

Fixes https://github.com/ayufan/camera-streamer/issues/115
This commit is contained in:
Arkadiusz Miśkiewicz 2025-07-02 20:59:27 +02:00 committed by GitHub
parent f7b673cb94
commit 5e689449d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -103,9 +103,31 @@ static void *http_get_param_fn(struct http_worker_s *worker, FILE *stream, const
return NULL; return NULL;
} }
// Helper function to decode percent-encoded strings
static void http_url_decode(const char *in, char *out)
{
while (*in) {
if (*in == '%' && isxdigit(in[1]) && isxdigit(in[2])) {
char hex[3] = {in[1], in[2], '\0'};
*out++ = (char)strtoul(hex, NULL, 16);
in += 3;
} else if (*in == '+') {
*out++ = ' ';
in++;
} else {
*out++ = *in++;
}
}
*out = '\0';
}
char *http_get_param(http_worker_t *worker, const char *key) char *http_get_param(http_worker_t *worker, const char *key)
{ {
return http_enum_params(worker, NULL, http_get_param_fn, (void*)key); char *param = http_enum_params(worker, NULL, http_get_param_fn, (void*)key);
if (param) {
http_url_decode(param, param);
}
return param;
} }
static void http_process(http_worker_t *worker, FILE *stream) static void http_process(http_worker_t *worker, FILE *stream)

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <pthread.h> #include <pthread.h>
#include <netinet/ip.h> #include <netinet/ip.h>