From 43968691c2a7f1f95cf7476fc8ab3c0bba8bab54 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 18 Jul 2020 08:29:10 +0300 Subject: Removed unnecessary field meta from request. --- examples/echo.c | 3 --- include/magi/request.h | 5 ----- man/magi.3 | 13 ++++++++++--- src/parse.c | 25 ------------------------- src/request.c | 9 --------- 5 files changed, 10 insertions(+), 45 deletions(-) diff --git a/examples/echo.c b/examples/echo.c index c93a897..ae95aa1 100644 --- a/examples/echo.c +++ b/examples/echo.c @@ -83,9 +83,6 @@ void response(struct magi_request *r) printf("

Cookies:

"); list_cookies(r); - printf("

Parameters:

"); - list_params(r->meta); - printf("

URL Parameters:

"); list_params(r->head); diff --git a/include/magi/request.h b/include/magi/request.h index fe0f745..2d998c7 100644 --- a/include/magi/request.h +++ b/include/magi/request.h @@ -19,7 +19,6 @@ /* Limits on possibly enormous structures. Null means unlimited. */ struct magi_request_limits { int cookies; - int params_meta; int params_head; int params_body; int read_buffer; @@ -29,7 +28,6 @@ struct magi_request { enum magi_error error; struct magi_cookies *cookies; /* Passed HTTP cookies. */ - struct magi_params *meta; /* Request parameters. */ struct magi_params *head; /* Form field values from URL. */ struct magi_params *body; /* Form field values from body. */ struct magi_files *files; /* Form field files metadatas. */ @@ -54,9 +52,6 @@ void magi_request_init(struct magi_request *r); void magi_request_free(struct magi_request *r); -/* Get value of meta-param with name. */ -char *magi_request_meta(const struct magi_request *r, const char *name); - /* Get value of form field param (prioritising body) with name. */ char *magi_request_param(const struct magi_request *r, const char *name); /* Get value of form field param with name from url. */ diff --git a/man/magi.3 b/man/magi.3 index 1188dca..32b0c92 100644 --- a/man/magi.3 +++ b/man/magi.3 @@ -158,11 +158,18 @@ field of .B magi_request structure. For other modules error codes seem to be overkill. .SH COMPATIBILTY +Sine +.B magi +only uses C standard library and the C language itself it should be able +to run on every environment with them, i.e. Linux, OpenBSD, FreeBSD, macOS, +Windows, etc. +.P The .B magi -library runs on any UNIX environment, -i.e. Linux, OpenBSD, FreeBSD, macOS, etc. -Windows is currently not supported. +library should work well with any server supporting CGI, since it is +compatible with +.IR "RFC 3875" , +i.e. Apache, nginx, Caddy, etc. .P The library is compatible with C++, since it avoid using typedefs for structs. However it doesn't have 'extern "C"' in the headers, so you need to wrap your diff --git a/src/parse.c b/src/parse.c index 0ca1cd9..390900f 100644 --- a/src/parse.c +++ b/src/parse.c @@ -15,8 +15,6 @@ #include #include -extern char **const environ; - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * CGI Request @@ -37,30 +35,8 @@ static char *lower_env(char *env_name) return env; } -static void cgi_http_env(struct magi_request *r) -{ - char **env; - int len = 0; - r->meta = 0; - for (env = environ; *env; ++env) { - struct magi_param meta; - 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, nlen); - meta.data = magi_str_create_copy(name_end + 1, dlen); - magi_params_add(&r->meta, &meta); - } -} - static void cgi_env(struct magi_request *r) { - cgi_http_env(r); r->method = plain_env("REQUEST_METHOD"); r->document_root = plain_env("DOCUMENT_ROOT"); r->script = plain_env("SCRIPT_NAME"); @@ -179,7 +155,6 @@ int magi_parse_head(struct magi_request *request) { request->cookies = 0; request->files = 0; - request->meta = 0; request->head = 0; request->body = 0; request->error = 0; diff --git a/src/request.c b/src/request.c index d401e67..fd13f74 100644 --- a/src/request.c +++ b/src/request.c @@ -10,7 +10,6 @@ void magi_request_init(struct magi_request *request) request->callback.userdata = 0; request->callback.addon_max = 1024; request->limits.cookies = 0; - request->limits.params_meta = 0; request->limits.params_head = 0; request->limits.params_body = 0; request->limits.read_buffer = 65536; @@ -21,7 +20,6 @@ void magi_request_init(struct magi_request *request) static void request_free(struct magi_request *request) { free(request->cookies); - free(request->meta); free(request->head); free(request->body); free(request->files); @@ -35,7 +33,6 @@ static void request_free(struct magi_request *request) static void request_annul(struct magi_request *request) { request->cookies = 0; - request->meta = 0; request->head = 0; request->body = 0; request->files = 0; @@ -49,7 +46,6 @@ void magi_request_free(struct magi_request *request) { if (request) { magi_cookies_free(request->cookies); - magi_params_free(request->meta); magi_params_free(request->head); magi_params_free(request->body); magi_files_free(request->files); @@ -59,11 +55,6 @@ void magi_request_free(struct magi_request *request) } -char *magi_request_meta(const struct magi_request *r, const char *name) -{ - return magi_params_get(r->meta, name); -} - char *magi_request_param(const struct magi_request *r, const char *name) { char *res = magi_params_get(r->body, name); -- cgit v1.2.3