diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgi.c | 22 | ||||
-rw-r--r-- | src/param.c | 3 | ||||
-rw-r--r-- | src/request.c | 9 | ||||
-rw-r--r-- | src/response.c | 2 | ||||
-rw-r--r-- | src/tools.c | 12 | ||||
-rw-r--r-- | src/tools.h | 2 | ||||
-rw-r--r-- | src/urlencoded.c | 2 |
7 files changed, 25 insertions, 27 deletions
@@ -15,7 +15,7 @@ #include <stdlib.h> #include <string.h> -extern char **environ; +extern char **const environ; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -32,7 +32,9 @@ static char *plain_env(char *env_name) static char *lower_env(char *env_name) { - return magi_str_lowercase(plain_env(env_name)); + char *env = plain_env(env_name); + magi_str_lowercase(env); + return env; } static void cgi_http_env(magi_request *r) @@ -42,21 +44,15 @@ static void cgi_http_env(magi_request *r) r->meta = 0; for (env = environ; *env; ++env) { magi_param meta; - char *name_end; - int dlen; - if (!strncmp(*env, "HTTP_COOKIE=", 12) || - !strncmp(*env, "QUERY_STRING=", 13)) { - continue; - } - /* At least one '=' must be in *env, according to format. */ - name_end = strchr(*env, '='); - dlen = strlen(name_end + 1); - len += name_end - *env + dlen; + char *name_end = strchr(*env, '='); + int nlen = name_end - *env; + int dlen = strlen(name_end + 1); + len += nlen + dlen; if (len > r->limits.params_meta && r->limits.params_meta) { r->error = magi_error_limit; return; } - meta.name = magi_str_create_copy(*env, name_end - *env); + meta.name = magi_str_create_copy(*env, nlen); meta.data = magi_str_create_copy(name_end + 1, dlen); magi_params_add(&r->meta, &meta); } diff --git a/src/param.c b/src/param.c index dd89a48..9c94555 100644 --- a/src/param.c +++ b/src/param.c @@ -19,6 +19,9 @@ void magi_params_set(magi_params **params, magi_param *newitem) if (!*params) { magi_params_add(params, newitem); } else if (!strcmp((*params)->item.name, newitem->name)) { + free((*params)->item.name); + free((*params)->item.data); + (*params)->item.name = newitem->name; (*params)->item.data = newitem->data; } else { magi_params_set(&(*params)->next, newitem); diff --git a/src/request.c b/src/request.c index 41b77fe..ce0f84f 100644 --- a/src/request.c +++ b/src/request.c @@ -10,10 +10,10 @@ void magi_request_init(magi_request *request) request->callback.act = 0; request->callback.userdata = 0; request->callback.addon_max = 1024; - request->limits.cookies = 1024 * 16; - request->limits.params_meta = 1024 * 16; - request->limits.params_head = 1024 * 16; - request->limits.params_body = 1024 * 16; + request->limits.cookies = 0; + request->limits.params_meta = 0; + request->limits.params_head = 0; + request->limits.params_body = 0; } } @@ -25,6 +25,7 @@ static void request_free(magi_request *request) free(request->head); free(request->body); free(request->files); + free(request->document_root); free(request->method); free(request->host); free(request->script); diff --git a/src/response.c b/src/response.c index d7d2c86..f7a6f67 100644 --- a/src/response.c +++ b/src/response.c @@ -91,7 +91,7 @@ void magi_response_content_length(magi_request *r, int length) void magi_response_content_type(magi_request *r, const char *type) { magi_param addon; - if (r->response->head_done || !type) { + if (r->response->head_done) { return; } addon.name = magi_str_create_copy("Content-Type", 12); diff --git a/src/tools.c b/src/tools.c index d6170bc..3d3a51e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -5,15 +5,11 @@ #include <string.h> -char *magi_str_lowercase(char *str) +void magi_str_lowercase(char *str) { - if (!str) { - return str; - } - for (; *str; ++str) { + for (; str && *str; ++str) { *str = tolower(*str); } - return str; } char *magi_str_create_copy(const char *first, int len) @@ -40,6 +36,6 @@ void magi_str_add(char **str, int *len, int *size, char c) *size *= 2; *str = realloc(*str, *size); } - *str[*len] = c; - *str[++*len] = 0; + (*str)[*len] = c; + (*str)[++*len] = 0; } diff --git a/src/tools.h b/src/tools.h index 0152f35..c84b7fd 100644 --- a/src/tools.h +++ b/src/tools.h @@ -2,7 +2,7 @@ #define MAGI_INCLUDED_TOOLS -char *magi_str_lowercase(char *str); +void magi_str_lowercase(char *str); /* Results of both create functions are malloced, so need to be freed. */ char *magi_str_create_copy(const char *first, int len); diff --git a/src/urlencoded.c b/src/urlencoded.c index 4f9efe8..b0891dc 100644 --- a/src/urlencoded.c +++ b/src/urlencoded.c @@ -87,6 +87,7 @@ static void state_parse_name(automata *a, char c) return; } a->s = state_parse_data; + return; } magi_str_add(&a->name, &a->nlen, &a->nsize, c); } @@ -114,6 +115,7 @@ static void state_parse_data(automata *a, char c) } add_to_list(a); a->s = state_parse_name; + return; } magi_str_add(&a->data, &a->dlen, &a->dsize, c); } |