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 *
HttpParamDecode(char * in)
HttpParamDecode(char *in)
{
HashMap *params;
@ -383,9 +383,6 @@ HttpParamDecode(char * in)
return NULL;
}
printf("HttpParamDecode(%s)\n", in);
fflush(stdout);
params = HashMapCreate();
if (!params)
{
@ -409,7 +406,7 @@ HttpParamDecode(char * in)
while (*in && *in != '=')
{
if (len >= allocated)
if (len >= allocated - 1)
{
allocated += TELODENDRIA_STRING_CHUNK;
buf = Realloc(buf, allocated);
@ -420,6 +417,8 @@ HttpParamDecode(char * in)
in++;
}
buf[len] = '\0';
/* Sanity check */
if (*in != '=')
{
@ -449,7 +448,7 @@ HttpParamDecode(char * in)
while (*in && *in != '&')
{
if (len >= allocated)
if (len >= allocated - 1)
{
allocated += TELODENDRIA_STRING_CHUNK;
buf = Realloc(buf, allocated);
@ -460,6 +459,8 @@ HttpParamDecode(char * in)
in++;
}
buf[len] = '\0';
/* Decode value */
decVal = HttpUrlDecode(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;
}

View file

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