From 8acbd33a82d2c13e70eb17447bc6abfd86cf9512 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 20 Mar 2020 23:06:46 +0300 Subject: [magi] --- include/magi.h | 2 +- include/magi/cookie.h | 3 ++- include/magi/fastcgi.h | 7 +++++-- include/magi/file.h | 2 +- include/magi/loadfile.h | 48 ------------------------------------------------ include/magi/loadfiles.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/magi/param.h | 2 +- include/magi/request.h | 13 +++++++------ include/magi/response.h | 2 +- include/magi/session.h | 17 +++++++++++++++++ 10 files changed, 83 insertions(+), 61 deletions(-) delete mode 100644 include/magi/loadfile.h create mode 100644 include/magi/loadfiles.h create mode 100644 include/magi/session.h (limited to 'include') diff --git a/include/magi.h b/include/magi.h index a5b047d..d8e1245 100644 --- a/include/magi.h +++ b/include/magi.h @@ -8,7 +8,7 @@ #include "magi/error.h" #include "magi/fastcgi.h" #include "magi/file.h" -#include "magi/loadfile.h" +#include "magi/loadfiles.h" #include "magi/param.h" #include "magi/request.h" #include "magi/response.h" diff --git a/include/magi/cookie.h b/include/magi/cookie.h index 96e4273..4760b75 100644 --- a/include/magi/cookie.h +++ b/include/magi/cookie.h @@ -30,7 +30,8 @@ void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem); /* Get last from top of cookies cookie with name, null if no such cookie. * Cookies are in reversed request order, and first cookie from request is * the most accurate in terms of domain and path. */ -magi_cookie *magi_cookies_get(magi_cookies *cookies, const char *name); +const magi_cookie *magi_cookies_get(const magi_cookies *cookies, + const char *name); #endif diff --git a/include/magi/fastcgi.h b/include/magi/fastcgi.h index fb1f2e5..3d91b7b 100644 --- a/include/magi/fastcgi.h +++ b/include/magi/fastcgi.h @@ -2,10 +2,13 @@ #define MAGI_INCLUDED_FASTCGI /* Fast CGI implementation */ -/* * * TODO * * */ +#include "session.h" +#include "request.h" -enum { magi_to_avoid_warning }; +int magi_fastcgi_head(magi_session *s, magi_request *r); +int magi_fastcgi_body(magi_session *s, magi_request *r); +int magi_fastcgi(magi_session *s, magi_request *r); #endif diff --git a/include/magi/file.h b/include/magi/file.h index d4c5e98..cd3d675 100644 --- a/include/magi/file.h +++ b/include/magi/file.h @@ -25,7 +25,7 @@ void magi_files_free(magi_files *files); void magi_files_add(magi_files **files, magi_file *newitem); /* Get first from top of files file with name, null if no such file. */ -magi_file *magi_files_get(magi_files *files, const char *name); +const magi_file *magi_files_get(const magi_files *files, const char *name); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/include/magi/loadfile.h b/include/magi/loadfile.h deleted file mode 100644 index bf3421c..0000000 --- a/include/magi/loadfile.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef MAGI_INCLUDED_LOADFILE -#define MAGI_INCLUDED_LOADFILE -/* Simple callback to load files. - * - * Generally satisfies task of receiving files. Fill magi_loadfiles table - * via magi_loadfiles_add, specifying which file-parameter to load into which - * path, and what are size limitations for it. When table is complete, setup - * your request to use this callback with magi_loadfiles_set. - * - * This module is optional. - */ -#include "request.h" - - -/* Rule of loading single file. - * There is no need to form or edit it directly. */ -typedef 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; - - -/* Free memory used by table. Request using table will become invalid. */ -void magi_loadfiles_free(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); - - -/* Setup request to use loadfiles callback with table. */ -void magi_loadfiles_set(magi_request *request, magi_loadfiles *table); - - -#endif diff --git a/include/magi/loadfiles.h b/include/magi/loadfiles.h new file mode 100644 index 0000000..bf3421c --- /dev/null +++ b/include/magi/loadfiles.h @@ -0,0 +1,48 @@ +#ifndef MAGI_INCLUDED_LOADFILE +#define MAGI_INCLUDED_LOADFILE +/* Simple callback to load files. + * + * Generally satisfies task of receiving files. Fill magi_loadfiles table + * via magi_loadfiles_add, specifying which file-parameter to load into which + * path, and what are size limitations for it. When table is complete, setup + * your request to use this callback with magi_loadfiles_set. + * + * This module is optional. + */ +#include "request.h" + + +/* Rule of loading single file. + * There is no need to form or edit it directly. */ +typedef 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; + + +/* Free memory used by table. Request using table will become invalid. */ +void magi_loadfiles_free(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); + + +/* Setup request to use loadfiles callback with table. */ +void magi_loadfiles_set(magi_request *request, magi_loadfiles *table); + + +#endif diff --git a/include/magi/param.h b/include/magi/param.h index 589db9f..c0879a9 100644 --- a/include/magi/param.h +++ b/include/magi/param.h @@ -29,7 +29,7 @@ void magi_params_set(magi_params **params, magi_param *newitem); /* Get data of the first from top of params parameter with name, * null if no such parameter. */ -char *magi_params_get(magi_params *params, const char *name); +char *magi_params_get(const magi_params *params, const char *name); #endif diff --git a/include/magi/request.h b/include/magi/request.h index 3d0d48a..7245feb 100644 --- a/include/magi/request.h +++ b/include/magi/request.h @@ -60,20 +60,21 @@ void magi_request_free(magi_request *r); /* Get value of meta-param with name. */ -char *magi_request_meta(magi_request *r, const char *name); +char *magi_request_meta(const magi_request *r, const char *name); /* Get value of form field param (prioritising body) with name. */ -char *magi_request_param(magi_request *r, const char *name); +char *magi_request_param(const magi_request *r, const char *name); /* Get value of form field param with name from url. */ -char *magi_request_urlparam(magi_request *r, const char *name); +char *magi_request_urlparam(const magi_request *r, const char *name); /* Get metadata structure of file from file field with name. */ -magi_file *magi_request_file(magi_request *r, const char *name); +const magi_file *magi_request_file(const magi_request *r, const char *name); /* Get value of cookie with name. */ -char *magi_request_cookie(magi_request *r, const char *name); +char *magi_request_cookie(const magi_request *r, const char *name); /* Get cookie with name. */ -magi_cookie *magi_request_cookie_complex(magi_request *r, const char *name); +const magi_cookie *magi_request_cookie_complex(const magi_request *r, + const char *name); #endif diff --git a/include/magi/response.h b/include/magi/response.h index 4b71ef5..11acf75 100644 --- a/include/magi/response.h +++ b/include/magi/response.h @@ -4,7 +4,7 @@ * * There are two parts of response, namely header and body. * You can directly dive into filling the body, since default headers are set. - * Defult content-type is XHTML, status is 200 (Ok). + * Defult content-type is HTML, status is 200 (OK). * * Use body related functions only after dealing with headers. * (Since storing possibly large body in memory is a bad idea, diff --git a/include/magi/session.h b/include/magi/session.h new file mode 100644 index 0000000..c1c5903 --- /dev/null +++ b/include/magi/session.h @@ -0,0 +1,17 @@ +#ifndef MAGI_INCLUDED_SESSION +#define MAGI_INCLUDED_SESSION + + +typedef struct magi_session { + int socket; +} magi_session; + + +void magi_session_init(magi_session *s); +void magi_session_free(magi_session *s); + +int magi_session_inet(magi_session *s, const char *address, int port); +int magi_session_unix(magi_session *s, const char *path); + + +#endif -- cgit v1.2.3