aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/magi/cgi.h10
-rw-r--r--include/magi/cookie.h25
-rw-r--r--include/magi/file.h23
-rw-r--r--include/magi/loadfile.h22
-rw-r--r--include/magi/param.h19
-rw-r--r--include/magi/request.h107
-rw-r--r--include/magi/response.h52
-rw-r--r--include/magi/urlenc.h4
8 files changed, 114 insertions, 148 deletions
diff --git a/include/magi/cgi.h b/include/magi/cgi.h
index 4d182b7..9b29a98 100644
--- a/include/magi/cgi.h
+++ b/include/magi/cgi.h
@@ -10,25 +10,25 @@
#include "response.h"
-/** @brief Analyses non-post part of request from environment.
+/** Analyses non-post part of request from environment.
* @return 1 if ok, 0 if error. */
int magi_request_cgi_head(magi_request *request);
-/** @brief Complete request with post body from standard input.
+/** Complete request with post body from standard input.
* @return 1 if ok, 0 if error. */
int magi_request_cgi_body(magi_request *request);
-/** @brief Shortcut for analysing both head and body of request.
+/** Shortcut for analysing both head and body of request.
* @return 1 if ok, 0 if error. */
int magi_request_cgi(magi_request *request);
-/** @brief Sends response to standard output and destroys it.
+/** Sends response to standard output and destroys it.
* @return 1 if ok, 0 if error. */
int magi_response_cgi(magi_response *response);
-/** @brief Sends a standard response of Bad Request error.
+/** Sends a standard response of Bad Request error.
* @return 1 if ok, 0 if error. */
int magi_error_cgi(magi_error error);
diff --git a/include/magi/cookie.h b/include/magi/cookie.h
index e6a5c4f..8a92a82 100644
--- a/include/magi/cookie.h
+++ b/include/magi/cookie.h
@@ -7,31 +7,30 @@
*/
-/** @brief HTTP Cookie. */
+/** HTTP Cookie. */
typedef struct magi_cookie {
- char *name; /**<@brief Cookie name. */
- char *data; /**<@brief Cookie value. */
- char *path; /**<@brief Path on wich cookie is set.
+ char *name; /**< Cookie name. */
+ char *data; /**< Cookie value. */
+ char *path; /**< Path on wich cookie is set.
* Without '/' at the end. */
- char *domain; /**<@brief Domain in wich cookie is set.
+ char *domain; /**< Domain in wich cookie is set.
* With dot at the begining. */
- char *max_age; /**<@brief In seconds until discard (response only). */
+ char *max_age; /**< In seconds until discard (response only). */
} magi_cookie;
-/** @ brief HTTP cookies collection.
- *
+/** HTTP cookies collection.
* Implemented as a linked list. */
typedef struct magi_cookies {
- struct magi_cookies *next; /**<@brief Pointer to next cookies. */
- magi_cookie item; /**<@brief Cookie on top. */
+ struct magi_cookies *next; /**< Pointer to next cookies. */
+ magi_cookie item; /**< Cookie on top. */
} magi_cookies;
-/** @brief Add @p newitem to @p cookies.
+/** Add @p newitem to @p cookies.
* @param[in,out] cookies to add into.
* @param[in] newitem to add onto top of @p cookies. */
void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem);
-/** @brief Get data of cookie from @p cookies with @p name.
+/** Get data of cookie from @p cookies with @p name.
* @note Cookies in @p cookies are in reverse request order, and first cookie
* from request is the most accurate in terms of domain and path.
* @param[in] params to search in.
@@ -40,7 +39,7 @@ void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem);
* null only if no such parameter. */
char *magi_cookies_get(magi_cookies *cookies, const char *name);
-/** @brief Free memory used by @p cookies.
+/** Free memory used by @p cookies.
* @param[in,out] cookies to be destructed. */
void magi_cookies_free(magi_cookies *cookies);
diff --git a/include/magi/file.h b/include/magi/file.h
index 474913d..07baadc 100644
--- a/include/magi/file.h
+++ b/include/magi/file.h
@@ -6,35 +6,34 @@
#include "param.h"
-/** @brief Form field of file with its parameters. */
+/** Form field of file with its parameters. */
typedef struct magi_file {
- char *field; /**<@brief Name of form field. */
- char *filename; /**<@brief File name on user's computer. */
- magi_params *params; /**<@brief Multipart params (e.g. type). */
+ char *field; /**< Name of form field. */
+ char *filename; /**< File name on user's computer. */
+ magi_params *params; /**< Multipart params (e.g. type). */
} magi_file;
-/** @brief Form files collection.
- *
+/** Form files collection.
* Implemented as a linked list. */
typedef struct magi_files {
- struct magi_files *next; /**<@brief Pointer to next files. */
- magi_file item; /**<@brief File on top. */
+ struct magi_files *next; /**< Pointer to next files. */
+ magi_file item; /**< File on top. */
} magi_files;
-/** @brief Add @p newitem to @p files.
+/** Add @p newitem to @p files.
* @param[in,out] files to add into.
* @param[in] newitem to add onto top of @p files. */
void magi_files_add(magi_files **files, magi_file *newitem);
-/** @brief Get file with @p name from @p files.
+/** Get file with @p name from @p files.
* @param[in] files to search in.
* @param[in] name of needed file.
* @return first from top of @p files file with @p name,
- null only if no such file. */
+ * null only if no such file. */
magi_file *magi_files_get(magi_files *files, const char *name);
-/** @brief Free memory used by @p files.
+/** Free memory used by @p files.
* @param[in,out] files to be destructed. */
void magi_files_free(magi_files *files);
diff --git a/include/magi/loadfile.h b/include/magi/loadfile.h
index 41622d8..04e5c2c 100644
--- a/include/magi/loadfile.h
+++ b/include/magi/loadfile.h
@@ -13,25 +13,23 @@
#include "request.h"
-/** @brief Rule of loading single file.
- *
+/** Rule of loading single file.
* There is no need to form or edit it directly. */
typedef struct magi_loadfile {
- const char *name; /**<@brief Form field to load file from. */
- const char *path; /**<@brief Path to load file in. */
- int max; /**<@brief Limit in bytes. Null means unlimited. */
+ 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;
-/** @brief Table of rules for loading files.
- *
+/** Table of rules for loading files.
* Set @c count and @c files as null to initialize. */
typedef struct magi_loadfiles {
- int count; /**<@brief Size of @c files.*/
- magi_loadfile *files; /**<@brief Dynamic array of rules to load files. */
+ int count; /**< Size of @c files.*/
+ magi_loadfile *files; /**< Dynamic array of rules to load files. */
} magi_loadfiles;
-/** @brief Add entity into @p table.
+/** Add entity into @p table.
* @param[in,out] table is the table to add into.
* @param[in] name is the form field name to load file from.
* @param[in] path to load file in.
@@ -41,12 +39,12 @@ void magi_loadfiles_add(magi_loadfiles *table,
const char *path,
int max);
-/** @brief Free memmory used by @p table.
+/** Free memmory used by @p table.
* @warning Request using @p table will become invalid.
* @param[in,out] table to be destructed. */
void magi_loadfiles_free(magi_loadfiles *table);
-/** @brief Setup @p request to use loadfiles callback with @p table.
+/** Setup @p request to use loadfiles callback with @p table.
* @param[in,out] request to setup using loadfiles callback.
* @param[in] table to use in loadfiles callback. */
void magi_loadfiles_set(magi_request *request, magi_loadfiles *table);
diff --git a/include/magi/param.h b/include/magi/param.h
index 7e1262b..0ad1919 100644
--- a/include/magi/param.h
+++ b/include/magi/param.h
@@ -5,34 +5,33 @@
*/
-/** @brief Parameter as name-value pair. */
+/** Parameter as name-value pair. */
typedef struct magi_param {
- char *name; /**<@brief Cannot be null. */
- char *data; /**<@brief Cannot be null. */
+ char *name; /**< Cannot be null. */
+ char *data; /**< Cannot be null. */
} magi_param;
-/** @brief Parameters collection.
- *
+/** Parameters collection.
* Implemented as a linked list. */
typedef struct magi_params {
- struct magi_params *next; /**<@brief Pointer to next parameters. */
- magi_param item; /**<@brief Parameter on top. */
+ struct magi_params *next; /**< Pointer to next parameters. */
+ magi_param item; /**< Parameter on top. */
} magi_params;
-/** @brief Add @p newitem to @p params.
+/** Add @p newitem to @p params.
* @param[in,out] params to add into.
* @param[in] newitem to add onto top of @p params. */
void magi_params_add(magi_params **params, magi_param *newitem);
-/** @brief Get data of parameter from @p params with @p name.
+/** Get data of parameter from @p params with @p name.
* @param[in] params to search in.
* @param[in] name of needed parameter.
* @return data of the first from top of @p params parameter with @p name,
* null only if no such parameter. */
char *magi_params_get(magi_params *params, const char *name);
-/** @brief Free memory used by @p params.
+/** Free memory used by @p params.
* @param[in,out] params to be destructed. */
void magi_params_free(magi_params *params);
diff --git a/include/magi/request.h b/include/magi/request.h
index 47acb27..0be32dc 100644
--- a/include/magi/request.h
+++ b/include/magi/request.h
@@ -11,82 +11,69 @@
#include "param.h"
+typedef struct magi_request_meta {
+ char *uri; /**< REQUEST_URI */
+ char *document_root; /**< DOCUMENT_ROOT */
+ char *document_uri; /**< DOCUMENT_URI */
+ char *script_name; /**< SCRIPT_NAME */
+ char *script_filename; /**< SCRIPT_FILENAME */
+ char *remote_addr; /**< REMOTE_ADDR */
+ char *remote_port; /**< REMOTE_PORT */
+ char *addr; /**< SERVER_ADDR */
+ char *name; /**< SERVER_NAME */
+ char *port; /**< SERVER_PORT */
+ char *protocol; /**< SERVER_PROTOCOL */
+ char *software; /**< SERVER_COFTWARE */
+} magi_request_meta;
+
+typedef struct magi_request_config {
+} magi_request_config;
+
+typedef struct magi_request_response {
+} magi_request_response;
+
+typedef struct magi_request_methods {
+} magi_request_methods;
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /**
- * @brief Request
+ * Request and response handler.
*
* Can be created via 'magi_request_{gateway interface name}', but will have
* nullified 'post'-related fields ('params' & 'files'). Reason is unlimited
* 'post' body size, with possible dependence of wanted limits from data of
* headers (e.g. session id from cookies, enabling some users to load more).
* To proceed 'post' use 'magi_request_resume_{gateway interface name}',
- * specifying settings if necessary.
- *
- *
- * Cheatsheet on environment:
- *
- * Request URL: http[s]://{server_name}[:{server_port}]{uri}
- * example.com 80
- * uri: {document_uri}[?{urlencode(url_params)}]
- * alfar=9973&veles=on
- * document_uri: {script_name}{path_info}
- * /bin/script /article/magic
- */
+ * specifying settings if necessary. */
typedef struct magi_request {
- /* * * Results * * */
- /* All pointers of this section must be valid as 'free' arguments. */
-
- /* Parsed */
- magi_cookie_list *cookies;
- magi_param_list *http_params; /* HTTP Header parameters */
- magi_param_list *url_params; /* Paramteres from URL */
- magi_param_list *params; /* Parameters from 'post' body */
- magi_file_list *files; /* 'Post' multipart files */
-
- /* Environment Shortcuts */
- char *method; /* REQUEST_METHOD */
- char *uri; /* REQUEST_URI */
- char *document_root; /* DOCUMENT_ROOT */
- char *document_uri; /* DOCUMENT_URI */
- char *script_name; /* SCRIPT_NAME */
- char *script_filename; /* SCRIPT_FILENAME */
- char *remote_addr; /* REMOTE_ADDR */
- char *remote_port; /* REMOTE_PORT */
- char *server_addr; /* SERVER_ADDR */
- char *server_name; /* SERVER_NAME */
- char *server_port; /* SERVER_PORT */
- char *server_protocol; /* SERVER_PROTOCOL */
- char *server_software; /* SERVER_COFTWARE */
- char *path_info; /* PATH_INFO */
-
- /* Request Error Code */
- magi_error error;
+ magi_cookies *cookies;
+ magi_params *params_head; /**< Paramteres from URL */
+ magi_params *params_body; /**< Parameters from 'post' body */
+ magi_files *files; /**< 'Post' multipart files */
+ magi_request_meta meta;
+ char *method; /**< REQUEST_METHOD */
+ char *path; /**< PATH_INFO */
+ int is_https;
+ magi_error error;
- /* * * Settings * * */
+ magi_request_config config;
+ magi_request_response response;
+ magi_request_methods *methods;
+} magi_request;
- /* Callback for processing files */
- void (*file_callback)(magi_file *file,
- char *addon,
- int addon_len,
- int is_addon_last,
- void *userdata);
- void *file_callback_userdata;
- int file_callback_addon_max;
- /* Limits for memory used (null <=> unlimitted) */
- int cookies_max;
- int url_params_max;
- int http_params_max;
- int params_max;
-} magi_request;
+void magi_request_init(magi_request *request);
+void magi_request_free(magi_request *request);
-/* Setup request with default settings. */
-void magi_request_setup(magi_request *request);
+char *magi_request_param(magi_request *request, const char *name);
+char *magi_request_param_url(magi_request *request, const char *name);
+magi_file *magi_request_file(magi_request *request, const char *name);
-/* Destroys request. */
-void magi_request_destroy(magi_request *request);
+char *magi_request_cookie(magi_request *request, const char *name);
+magi_cookie *magi_request_cookie_complex(magi_request *request,
+ const char *name);
#endif
diff --git a/include/magi/response.h b/include/magi/response.h
index 18f4b63..bee2e2c 100644
--- a/include/magi/response.h
+++ b/include/magi/response.h
@@ -1,47 +1,31 @@
#ifndef MAGI_INCLUDED_RESPONSE
#define MAGI_INCLUDED_RESPONSE
/** @file response.h
- * @brief General response functionality.
+ * @brief General response functionality for magi_request.
*
- * blah-blah-blah
+ * 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).
+ *
+ * @warning Use body related functions only after dealing with headers.
+ * (Since storing possibly large body in memory is a bad idea,
+ * all headers should be sent before anything from the body.)
*/
-/* TODO: rewrite in such way, that only headers are in memory. */
-#include "cookie.h"
-#include "param.h"
-
-
-typedef struct magi_response {
- magi_cookie_list *cookies;
- magi_param_list *http_params;
- char *content_type;
- char *content;
- int len;
- int size;
-} magi_response;
-
-
-void magi_response_setup(magi_response *response);
-
-
-void magi_response_content_type(magi_response *response, const char *type);
-
-void magi_response_add(magi_response *response, const char *addon);
-
-void magi_response_cookie(magi_response *response, magi_cookie *cookie);
-void magi_response_cookie_easy(magi_response *response,
- const char *name,
- const char *value);
-void magi_response_cookie_discard(magi_response *response,
- const char *name);
+void magi_response_status(magi_request *r, magi_status code);
+void magi_response_status_custom(magi_request *r, int code, const char *desc);
-void magi_response_http(magi_response *response,
- const char *name,
- const char *data);
+void magi_response_cookie(magi_request *r, const char *name, const char *data);
+void magi_response_cookie_complex(magi_request *r, magi_cookie *c);
+void magi_response_cookie_discard(magi_request *r, const char *name);
+void magi_response_content_length(magi_request *r, int length);
+void magi_response_content_type(magi_request *r, const char *type);
-void magi_response_destroy(magi_response *response);
+void magi_response(magi_request *r, const char *addon);
+void magi_response_format(magi_request *r, const char *format, ...);
+void magi_response_file(magi_request *r, FILE *file);
#endif
diff --git a/include/magi/urlenc.h b/include/magi/urlenc.h
index 99f7bbe..0eff58b 100644
--- a/include/magi/urlenc.h
+++ b/include/magi/urlenc.h
@@ -15,12 +15,12 @@
*/
-/** @brief Count URL-code size for @p plain.
+/** Count URL-code size for @p plain.
* @param[in] plain is a text to count code size for.
* @return size of URL-code of @p plain. */
int magi_urlenc_size(const char *plain);
-/** @brief Encode @p plain to url-code @p code.
+/** Encode @p plain to url-code @p code.
* @warning @p code must be at least size of #magi_urlenc_size(@p plain).
* @param[in] plain is a text to be encoded.
* @param[out] code will be filled with URL-code of @p plain. */