From 4d77e4bb69a47daf23ad4a902b300bf1aa7d5597 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Mon, 13 Jul 2020 10:21:47 +0300 Subject: typedef struct removed to support C++98. --- include/magi/cookie.h | 19 ++++++++++--------- include/magi/error.h | 8 ++++---- include/magi/file.h | 40 +++++++++++++++++++++------------------- include/magi/loadfiles.h | 25 +++++++++++++------------ include/magi/param.h | 21 ++++++++++++--------- include/magi/parse.h | 9 +++++---- include/magi/request.h | 43 ++++++++++++++++++++++--------------------- include/magi/response.h | 38 +++++++++++++++++++++++--------------- 8 files changed, 110 insertions(+), 93 deletions(-) (limited to 'include') diff --git a/include/magi/cookie.h b/include/magi/cookie.h index 7573747..68cbe3f 100644 --- a/include/magi/cookie.h +++ b/include/magi/cookie.h @@ -5,32 +5,33 @@ */ -typedef struct magi_cookie { +struct magi_cookie { char *name; /* Cookie name. */ char *data; /* Cookie value. */ char *path; /* Path on which cookie is set. Without '/' at the end. */ char *domain; /* Domain in wich cookie is set. * With dot at the begining. */ char *max_age; /* In seconds until discard (response only). */ -} magi_cookie; +}; /* HTTP cookies collection, implemented as a linked list. */ -typedef struct magi_cookies { +struct magi_cookies { struct magi_cookies *next; /* Pointer to next cookies. */ - magi_cookie item; /* Cookie on top. */ -} magi_cookies; + struct magi_cookie item; /* Cookie on top. */ +}; /* Free memory used by cookies. */ -void magi_cookies_free(magi_cookies *cookies); +void magi_cookies_free(struct magi_cookies *cookies); /* Add newitem onto top of cookies. */ -void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem); +void magi_cookies_add(struct magi_cookies **cookies, + struct magi_cookie *newitem); /* Get first cookie with given name, null if no such cookie. * First cookie is the most accurate in terms of domain and path. */ -const magi_cookie *magi_cookies_get(const magi_cookies *cookies, - const char *name); +const struct magi_cookie *magi_cookies_get(const struct magi_cookies *cookies, + const char *name); #endif diff --git a/include/magi/error.h b/include/magi/error.h index 6f64228..c11ed51 100644 --- a/include/magi/error.h +++ b/include/magi/error.h @@ -6,7 +6,7 @@ /* Magi error codes. */ -typedef enum magi_error { +enum magi_error { magi_error_none = 0, /* No error, all is ok. */ magi_error_nobound, /* No boundary provided for multipart/form-data. */ magi_error_unknown, /* Unknown Content Type. */ @@ -16,14 +16,14 @@ typedef enum magi_error { magi_error_urlenc, /* Wrong url encoding. */ magi_error_multipart, /* Malformed multipart/form-data. */ magi_error_limit /* One of specified limits reached. */ -} magi_error; +}; /* Get description message of given error. */ -const char *magi_error_message(magi_error error); +const char *magi_error_message(enum magi_error error); /* Response default error page for given error. */ -void magi_error_response(magi_error error); +void magi_error_response(enum magi_error error); #endif diff --git a/include/magi/file.h b/include/magi/file.h index d976194..615d8b7 100644 --- a/include/magi/file.h +++ b/include/magi/file.h @@ -5,46 +5,48 @@ #include "param.h" -typedef struct magi_file { - char *field; /* Name of form field. */ - char *filename; /* File name on user's computer. */ - magi_params *params; /* Multipart params (e.g. type). */ -} magi_file; +struct magi_file { + char *field; /* Name of form field. */ + char *filename; /* File name on user's computer. */ + struct magi_params *params; /* Multipart params (e.g. type). */ +}; /* Form files collection, implemented as a linked list. */ -typedef struct magi_files { +struct magi_files { struct magi_files *next; /* Pointer to next files. */ - magi_file item; /* File on top. */ -} magi_files; + struct magi_file item; /* File on top. */ +}; /* Free memory used by files. */ -void magi_files_free(magi_files *files); +void magi_files_free(struct magi_files *files); /* Add newitem onto top of files. */ -void magi_files_add(magi_files **files, magi_file *newitem); +void magi_files_add(struct magi_files **files, + struct magi_file *newitem); /* Get first from top of files file with name, null if no such file. */ -const magi_file *magi_files_get(const magi_files *files, const char *name); +const struct magi_file *magi_files_get(const struct magi_files *files, + const char *name); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Callback to load files while analysing request. * addon_len is not null if something to add is in addon - * and null if file_to_add_into is ended. + * and null if file is ended. * newfile flag is setted up in the beginning of new file. * Files are passed sequentialy, one by one. */ -typedef void (*magi_file_callback_act)(void *userdata, - int newfile, - magi_file *file_to_add_into, - char *addon, - int addon_len); +typedef void (*magi_file_callback_act)(void *userdata, + int newfile, + struct magi_file *file, + char *addon, + int addon_len); -typedef struct magi_file_callback { +struct magi_file_callback { magi_file_callback_act act; void *userdata; int addon_max; -} magi_file_callback; +}; #endif diff --git a/include/magi/loadfiles.h b/include/magi/loadfiles.h index d6cdaeb..9d7978f 100644 --- a/include/magi/loadfiles.h +++ b/include/magi/loadfiles.h @@ -12,35 +12,36 @@ /* Rule of loading single file. * There is no need to form or edit it directly. */ -typedef struct magi_loadfile { +struct magi_loadfile { const char *name; /* Form field to load file from. */ const char *path; /* Path to load file in. */ int max; /* Limit in bytes. Null means unlimited. */ -} magi_loadfile; +}; /* Table of rules for loading files. * Set count and files as null to initialize. */ -typedef struct magi_loadfiles { - int count; /* Size of files array.*/ - magi_loadfile *files; /* Dynamic array of rules to load files. */ -} magi_loadfiles; +struct magi_loadfiles { + int count; /* Size of files array.*/ + struct magi_loadfile *files; /* Dynamic array of rules to load files. */ +}; /* Free memory used by table. Request using table will become invalid. */ -void magi_loadfiles_free(magi_loadfiles *table); +void magi_loadfiles_free(struct magi_loadfiles *table); /* Add entity into table. * Specify form field to load file from with name, * wnated loaction to load file with path, * and file size limit in bytes with max (pass null to unlimit). */ -void magi_loadfiles_add(magi_loadfiles *table, - const char *name, - const char *path, - int max); +void magi_loadfiles_add(struct magi_loadfiles *table, + const char *name, + const char *path, + int max); /* Setup request to use loadfiles callback with table. */ -void magi_loadfiles_set(magi_request *request, magi_loadfiles *table); +void magi_loadfiles_set(struct magi_request *request, + struct magi_loadfiles *table); #endif diff --git a/include/magi/param.h b/include/magi/param.h index c0879a9..44ea384 100644 --- a/include/magi/param.h +++ b/include/magi/param.h @@ -4,32 +4,35 @@ */ -typedef struct magi_param { +struct magi_param { char *name; /* Cannot be null. */ char *data; /* Cannot be null. */ -} magi_param; +}; /* Parameters collection, implemented as a linked list. */ -typedef struct magi_params { +struct magi_params { struct magi_params *next; /* Pointer to next parameters. */ - magi_param item; /* Parameter on top. */ -} magi_params; + struct magi_param item; /* Parameter on top. */ +}; /* Free memory used by params. */ -void magi_params_free(magi_params *params); +void magi_params_free(struct magi_params *params); /* Add newitem onto top of params. */ -void magi_params_add(magi_params **params, magi_param *newitem); +void magi_params_add(struct magi_params **params, + struct magi_param *newitem); /* Set newitem in params. * If param with name of newitem is in params it will be replaced with newitem, * otherwise newitem will be added into the end of params. */ -void magi_params_set(magi_params **params, magi_param *newitem); +void magi_params_set(struct magi_params **params, + struct magi_param *newitem); /* Get data of the first from top of params parameter with name, * null if no such parameter. */ -char *magi_params_get(const magi_params *params, const char *name); +char *magi_params_get(const struct magi_params *params, + const char *name); #endif diff --git a/include/magi/parse.h b/include/magi/parse.h index a71018a..502af6e 100644 --- a/include/magi/parse.h +++ b/include/magi/parse.h @@ -5,14 +5,15 @@ #include "request.h" -/* Analyses non-post part of request from environment. True if ok. */ -int magi_parse_head(magi_request *request); +/* Analyses non-post part of request (everything except body and files) + * from environment. True if ok. */ +int magi_parse_head(struct magi_request *request); /* Complete request with post body from standard input. True if ok. */ -int magi_parse_body(magi_request *request); +int magi_parse_body(struct magi_request *request); /* Shortcut for analysing both head and body of request. True if ok. */ -int magi_parse(magi_request *request); +int magi_parse(struct magi_request *request); #endif diff --git a/include/magi/request.h b/include/magi/request.h index 0ec17e8..fe0f745 100644 --- a/include/magi/request.h +++ b/include/magi/request.h @@ -17,22 +17,22 @@ /* Limits on possibly enormous structures. Null means unlimited. */ -typedef struct magi_request_limits { +struct magi_request_limits { int cookies; int params_meta; int params_head; int params_body; int read_buffer; -} magi_request_limits; +}; -typedef struct magi_request { - magi_error error; +struct magi_request { + enum magi_error error; - magi_cookies *cookies; /* Passed HTTP cookies. */ - magi_params *meta; /* Request parameters. */ - magi_params *head; /* Form field values from URL. */ - magi_params *body; /* Form field values from body. */ - magi_files *files; /* Form field files metadatas. */ + 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. */ char *document_root; /* Server's document root (e.g. /var/www/htdocs). */ char *method; /* Request method (GET, HEAD, POST, etc...). */ @@ -43,33 +43,34 @@ typedef struct magi_request { char *path; /* Path requested for the script (e.g. /login). */ /* URL has form 'http[s]://{host}:{port}{script}{path}'. */ - magi_file_callback callback; /* Callback to actually load files. */ - magi_request_limits limits; -} magi_request; + struct magi_file_callback callback; /* Callback to load files. */ + struct magi_request_limits limits; +}; /* Request initialiser, setup defaults. */ -void magi_request_init(magi_request *r); +void magi_request_init(struct magi_request *r); /* Free memory used by request. */ -void magi_request_free(magi_request *r); +void magi_request_free(struct magi_request *r); /* Get value of meta-param with name. */ -char *magi_request_meta(const magi_request *r, const char *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 magi_request *r, const char *name); +char *magi_request_param(const struct magi_request *r, const char *name); /* Get value of form field param with name from url. */ -char *magi_request_urlparam(const magi_request *r, const char *name); +char *magi_request_urlparam(const struct magi_request *r, const char *name); /* Get metadata structure of file from file field with name. */ -const magi_file *magi_request_file(const magi_request *r, const char *name); +const struct magi_file *magi_request_file(const struct magi_request *r, + const char *name); /* Get value of cookie with name. */ -char *magi_request_cookie(const magi_request *r, const char *name); +char *magi_request_cookie(const struct magi_request *r, const char *name); /* Get cookie with name. */ -const magi_cookie *magi_request_cookie_complex(const magi_request *r, - const char *name); +const struct magi_cookie * +magi_request_cookie_complex(const struct magi_request *r, const char *name); #endif diff --git a/include/magi/response.h b/include/magi/response.h index c38e3f9..3ef053a 100644 --- a/include/magi/response.h +++ b/include/magi/response.h @@ -12,41 +12,49 @@ /* Response headers as three sequential groups. */ -typedef struct magi_response { - magi_params *head_response; - magi_params *head_general; - magi_params *head_entity; -} magi_response; +struct magi_response { + struct magi_params *head_response; + struct magi_params *head_general; + struct magi_params *head_entity; +}; /* Response initialiser, setup defaults. */ -void magi_response_init(magi_response *r); +void magi_response_init(struct magi_response *r); /* Send response headers. */ -void magi_response_send(magi_response *r); +void magi_response_send(struct magi_response *r); /* Free memory used by response headers. */ -void magi_response_free(magi_response *r); +void magi_response_free(struct magi_response *r); /* Just response defaults. (text/html, 200 Ok) */ void magi_response_default(); /* Change resposne status header. */ -void magi_response_status(magi_response *r, int code, const char *description); +void magi_response_status(struct magi_response *r, + int code, + const char *description); /* Add cookie to response. */ -void magi_response_cookie(magi_response *r, const char *n, const char *d); +void magi_response_cookie(struct magi_response *r, + const char *n, + const char *d); /* Add cookie with additional information to response. */ -void magi_response_cookie_complex(magi_response *r, magi_cookie *c); +void magi_response_cookie_complex(struct magi_response *r, + struct magi_cookie *c); /* Add request to discard cookie to response. */ -void magi_response_cookie_discard(magi_response *r, const char *name); +void magi_response_cookie_discard(struct magi_response *r, + const char *name); /* Just add some general custom header. */ -void magi_response_header(magi_response *r, const char *n, const char *d); +void magi_response_header(struct magi_response *r, + const char *n, + const char *d); /* Change Content-Length header. */ -void magi_response_content_length(magi_response *r, int length); +void magi_response_content_length(struct magi_response *r, int length); /* Change Content-Type header. */ -void magi_response_content_type(magi_response *r, const char *type); +void magi_response_content_type(struct magi_response *r, const char *type); #endif -- cgit v1.2.3