Complete parameter parsing

This commit is contained in:
Jordan Bancino 2022-10-15 19:17:49 -04:00
parent 52abd18324
commit 5ca5ec7dd4
2 changed files with 119 additions and 129 deletions

View file

@ -374,7 +374,7 @@ HttpUrlDecode(char *str)
} }
HashMap * HashMap *
HttpParamDecode(char * in) HttpParamDecode(char *in)
{ {
HashMap *params; HashMap *params;
@ -383,9 +383,6 @@ HttpParamDecode(char * in)
return NULL; return NULL;
} }
printf("HttpParamDecode(%s)\n", in);
fflush(stdout);
params = HashMapCreate(); params = HashMapCreate();
if (!params) if (!params)
{ {
@ -409,7 +406,7 @@ HttpParamDecode(char * in)
while (*in && *in != '=') while (*in && *in != '=')
{ {
if (len >= allocated) if (len >= allocated - 1)
{ {
allocated += TELODENDRIA_STRING_CHUNK; allocated += TELODENDRIA_STRING_CHUNK;
buf = Realloc(buf, allocated); buf = Realloc(buf, allocated);
@ -420,6 +417,8 @@ HttpParamDecode(char * in)
in++; in++;
} }
buf[len] = '\0';
/* Sanity check */ /* Sanity check */
if (*in != '=') if (*in != '=')
{ {
@ -449,7 +448,7 @@ HttpParamDecode(char * in)
while (*in && *in != '&') while (*in && *in != '&')
{ {
if (len >= allocated) if (len >= allocated - 1)
{ {
allocated += TELODENDRIA_STRING_CHUNK; allocated += TELODENDRIA_STRING_CHUNK;
buf = Realloc(buf, allocated); buf = Realloc(buf, allocated);
@ -460,6 +459,8 @@ HttpParamDecode(char * in)
in++; in++;
} }
buf[len] = '\0';
/* Decode value */ /* Decode value */
decVal = HttpUrlDecode(buf); decVal = HttpUrlDecode(buf);
Free(buf); Free(buf);
@ -484,17 +485,6 @@ HttpParamDecode(char * in)
} }
} }
printf("Done with decoding, here's what we got:\n");
{
char *key;
char *val;
while (HashMapIterate(params, &key, (void **) &val))
{
printf(" [%s]: [%s]\n", key, val);
}
}
return params; return params;
} }

View file

@ -75,7 +75,7 @@ struct HttpServerContext
static HttpServerContext * static HttpServerContext *
HttpServerContextCreate(HttpRequestMethod requestMethod, HttpServerContextCreate(HttpRequestMethod requestMethod,
char *requestPath, HashMap *requestParams, FILE * stream) char *requestPath, HashMap * requestParams, FILE * stream)
{ {
HttpServerContext *c; HttpServerContext *c;