mirror of
https://github.com/andreili/camera-streamer.git
synced 2025-08-23 11:24:07 +02:00
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:
parent
f7b673cb94
commit
5e689449d4
@ -103,9 +103,31 @@ static void *http_get_param_fn(struct http_worker_s *worker, FILE *stream, const
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <pthread.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user