aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-04-04 19:39:38 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-04-04 19:39:38 +0300
commit07657b8a9f5c2fd9047594ec8604b9c439a999e4 (patch)
treeefc15cde781a74f5782c780422dde6ec0dfb1af4 /include
parentcb6a86b8db5a26b92073c4fc5ceffffa8cd842c2 (diff)
downloadmagi-07657b8a9f5c2fd9047594ec8604b9c439a999e4.tar
magi-07657b8a9f5c2fd9047594ec8604b9c439a999e4.tar.xz
magi-07657b8a9f5c2fd9047594ec8604b9c439a999e4.zip
[magi] Finalization.
Diffstat (limited to 'include')
-rw-r--r--include/magi.h3
-rw-r--r--include/magi/error.h4
-rw-r--r--include/magi/fastcgi.h14
-rw-r--r--include/magi/loadfiles.h2
-rw-r--r--include/magi/parse.h (renamed from include/magi/cgi.h)12
-rw-r--r--include/magi/request.h20
-rw-r--r--include/magi/response.h63
-rw-r--r--include/magi/session.h17
-rw-r--r--include/magi/urlenc.h2
9 files changed, 37 insertions, 100 deletions
diff --git a/include/magi.h b/include/magi.h
index d8e1245..e89a322 100644
--- a/include/magi.h
+++ b/include/magi.h
@@ -3,13 +3,12 @@
/* All headers are included here.
* You can include this, if you don't want to think about headers.
*/
-#include "magi/cgi.h"
#include "magi/cookie.h"
#include "magi/error.h"
-#include "magi/fastcgi.h"
#include "magi/file.h"
#include "magi/loadfiles.h"
#include "magi/param.h"
+#include "magi/parse.h"
#include "magi/request.h"
#include "magi/response.h"
#include "magi/urlenc.h"
diff --git a/include/magi/error.h b/include/magi/error.h
index e928ed2..19538ae 100644
--- a/include/magi/error.h
+++ b/include/magi/error.h
@@ -1,6 +1,7 @@
#ifndef MAGI_INCLUDED_ERROR
#define MAGI_INCLUDED_ERROR
/* Error codes and messages
+ * You can output default error message via magi_error_response.
*/
@@ -20,4 +21,7 @@ typedef enum magi_error {
const char *magi_error_message(magi_error error);
+void magi_error_response(magi_error error);
+
+
#endif
diff --git a/include/magi/fastcgi.h b/include/magi/fastcgi.h
deleted file mode 100644
index 3d91b7b..0000000
--- a/include/magi/fastcgi.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef MAGI_INCLUDED_FASTCGI
-#define MAGI_INCLUDED_FASTCGI
-/* Fast CGI implementation
- */
-#include "session.h"
-#include "request.h"
-
-
-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/loadfiles.h b/include/magi/loadfiles.h
index bf3421c..d6cdaeb 100644
--- a/include/magi/loadfiles.h
+++ b/include/magi/loadfiles.h
@@ -6,8 +6,6 @@
* 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"
diff --git a/include/magi/cgi.h b/include/magi/parse.h
index 0de637e..a71018a 100644
--- a/include/magi/cgi.h
+++ b/include/magi/parse.h
@@ -1,18 +1,18 @@
-#ifndef MAGI_INCLUDED_CGI
-#define MAGI_INCLUDED_CGI
-/* Common Gateway Interface implementation
+#ifndef MAGI_INCLUDED_PARSE
+#define MAGI_INCLUDED_PARSE
+/* Common Gateway Interface request parsing implementation
*/
#include "request.h"
/* Analyses non-post part of request from environment. True if ok. */
-int magi_cgi_head(magi_request *request);
+int magi_parse_head(magi_request *request);
/* Complete request with post body from standard input. True if ok. */
-int magi_cgi_body(magi_request *request);
+int magi_parse_body(magi_request *request);
/* Shortcut for analysing both head and body of request. True if ok. */
-int magi_cgi(magi_request *request);
+int magi_parse(magi_request *request);
#endif
diff --git a/include/magi/request.h b/include/magi/request.h
index 7245feb..32d31b5 100644
--- a/include/magi/request.h
+++ b/include/magi/request.h
@@ -2,13 +2,13 @@
#define MAGI_INCLUDED_REQUEST
/* Request handler
*
- * Can be created via magi_{gateway interface name}_head, 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_{gateway interface name}_body, specifying
- * settings if necessary.
- * Or just use shortcut magi_{gateway interface name} to do both parts.
+ * Can be created via magi_parse_head, 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); and also
+ * dependence of place to load files by callback from head data.
+ * To proceed POST use magi_parse_body, specifying settings if necessary.
+ * Or just use shortcut magi_parse to do both parts.
*/
#include "cookie.h"
#include "error.h"
@@ -44,12 +44,6 @@ typedef struct magi_request {
magi_file_callback callback; /* Callback to actually load files. */
magi_request_limits limits;
-
- /* Implementation of response for this request.
- * Especially helpful in case of FastCGI,
- * when you can handle many requests simultaniously,
- * and need to know how to response each of them. */
- struct magi_response_implementation *response;
} magi_request;
diff --git a/include/magi/response.h b/include/magi/response.h
index 11acf75..e67b279 100644
--- a/include/magi/response.h
+++ b/include/magi/response.h
@@ -1,66 +1,41 @@
#ifndef MAGI_INCLUDED_RESPONSE
#define MAGI_INCLUDED_RESPONSE
-/* General response functionality for magi_request.
+/* General CGI headers response functionality.
*
- * 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 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,
- * all headers should be sent before anything from the body.)
+ * There are two parts of response, namely head and body.
+ * You need to output head first, it is done with magi_response_free or with
+ * magi_response_default. Default content-type is HTML, status is 200 (Ok).
+ * Body can be outputed after head into stdout.
*/
-#include "request.h"
+#include "cookie.h"
+#include "param.h"
#include <stdio.h>
#include <stdarg.h>
-/* * * TODO: Comments * * */
-typedef void (*magi_response_method_head)(void *ud, magi_param *header);
-typedef void (*magi_response_method_start_body)(void *ud);
-typedef void (*magi_response_method_body)(void *ud, const char *data, int len);
-typedef void (*magi_response_method_fmt)(void *ud, const char *f, va_list a);
-typedef void (*magi_response_method_file)(void *ud, FILE *file);
-typedef void (*magi_response_method_close)(void *ud);
-
-typedef struct magi_response_methods {
- magi_response_method_head head;
- magi_response_method_start_body start_body;
- magi_response_method_body body;
- magi_response_method_fmt format;
- magi_response_method_file file;
- magi_response_method_close close;
-} magi_response_methods;
-
-typedef struct magi_response_implementation {
- const magi_response_methods *methods;
- void *userdata;
+typedef struct magi_response {
magi_params *head_response;
magi_params *head_general;
magi_params *head_entity;
- int head_done;
-} magi_response_implementation;
-
+} magi_response;
-void magi_response_status(magi_request *r, int code, const char *description);
-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_init(magi_response *r);
+void magi_response_free(magi_response *r);
-void magi_response_header(magi_request *r, const char *name, const char *data);
+void magi_response_default();
-void magi_response_content_length(magi_request *r, int length);
-void magi_response_content_type(magi_request *r, const char *type);
-void magi_response_head(magi_request *r);
+void magi_response_status(magi_response *r, int code, const char *description);
-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);
+void magi_response_cookie(magi_response *r, const char *n, const char *d);
+void magi_response_cookie_complex(magi_response *r, magi_cookie *c);
+void magi_response_cookie_discard(magi_response *r, const char *name);
+void magi_response_header(magi_response *r, const char *n, const char *d);
-void magi_response_error(magi_request *r);
+void magi_response_content_length(magi_response *r, int length);
+void magi_response_content_type(magi_response *r, const char *type);
#endif
diff --git a/include/magi/session.h b/include/magi/session.h
deleted file mode 100644
index c1c5903..0000000
--- a/include/magi/session.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#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
diff --git a/include/magi/urlenc.h b/include/magi/urlenc.h
index dadebe7..1b629f9 100644
--- a/include/magi/urlenc.h
+++ b/include/magi/urlenc.h
@@ -9,8 +9,6 @@
* RFC 3986 describes URL-encoding. Briefly it is changing every space into
* plus sign and every not alpha-numerical and not @c "~-._" character into
* percent sign followed by hexadecimal representation of given character.
- *
- * This module is optional.
*/