aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-07-13 10:21:47 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-07-13 10:21:47 +0300
commit4d77e4bb69a47daf23ad4a902b300bf1aa7d5597 (patch)
treeb3c21c9bb01cf84d07e3b9e51b707e24e2afabd2 /src
parent915f37b5ad202dfeb51999faba5a2849318ebea2 (diff)
downloadmagi-4d77e4bb69a47daf23ad4a902b300bf1aa7d5597.tar
magi-4d77e4bb69a47daf23ad4a902b300bf1aa7d5597.tar.xz
magi-4d77e4bb69a47daf23ad4a902b300bf1aa7d5597.zip
typedef struct removed to support C++98.
Diffstat (limited to 'src')
-rw-r--r--src/cookie.c11
-rw-r--r--src/cookies.c82
-rw-r--r--src/cookies.h2
-rw-r--r--src/error.c4
-rw-r--r--src/file.c9
-rw-r--r--src/loadfiles.c27
-rw-r--r--src/multipart.c110
-rw-r--r--src/multipart.h8
-rw-r--r--src/param.c10
-rw-r--r--src/parse.c24
-rw-r--r--src/request.c26
-rw-r--r--src/response.c51
-rw-r--r--src/urlencoded.c41
-rw-r--r--src/urlencoded.h3
14 files changed, 211 insertions, 197 deletions
diff --git a/src/cookie.c b/src/cookie.c
index fc66428..ebca599 100644
--- a/src/cookie.c
+++ b/src/cookie.c
@@ -4,7 +4,7 @@
#include <string.h>
-void magi_cookies_free(magi_cookies *cookies)
+void magi_cookies_free(struct magi_cookies *cookies)
{
if (cookies) {
magi_cookies_free(cookies->next);
@@ -17,9 +17,10 @@ void magi_cookies_free(magi_cookies *cookies)
}
}
-void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem)
+void magi_cookies_add(struct magi_cookies **cookies,
+ struct magi_cookie *newitem)
{
- magi_cookies *node = malloc(sizeof(*node));
+ struct magi_cookies *node = malloc(sizeof(*node));
if (node) {
node->next = *cookies;
node->item = *newitem;
@@ -27,8 +28,8 @@ void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem)
}
}
-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)
{
if (!name) {
return 0;
diff --git a/src/cookies.c b/src/cookies.c
index d1aeb46..98c1794 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -5,23 +5,23 @@
#include <string.h>
-typedef enum dt { dt_plain = 0, dt_version, dt_path, dt_domain } dt;
-
-typedef struct automata {
- magi_cookies **list;
- magi_cookie cookie;
- char *buf;
- int buf_len;
- int buf_size;
- int is_first;
- int is_advanced;
- int is_quoted;
- dt datatype;
-} automata;
-typedef void *(*state)(automata *a, char c);
-
-
-static void nulify_cookie(automata *a)
+enum dt { dt_plain = 0, dt_version, dt_path, dt_domain };
+
+struct automata {
+ struct magi_cookies **list;
+ struct magi_cookie cookie;
+ char *buf;
+ int buf_len;
+ int buf_size;
+ int is_first;
+ int is_advanced;
+ int is_quoted;
+ enum dt datatype;
+};
+typedef void *(*state)(struct automata *a, char c);
+
+
+static void nulify_cookie(struct automata *a)
{
a->cookie.name = 0;
a->cookie.data = 0;
@@ -30,7 +30,7 @@ static void nulify_cookie(automata *a)
a->cookie.max_age = 0;
}
-static void buf_new(automata *a)
+static void buf_new(struct automata *a)
{
a->buf = 0;
a->buf_len = 0;
@@ -38,9 +38,9 @@ static void buf_new(automata *a)
}
-static dt what_is_name(const automata *a)
+static enum dt what_is_name(const struct automata *a)
{
- dt datatype = dt_plain;
+ enum dt datatype = dt_plain;
if (a->is_first && !strcmp(a->buf, "$Version")) {
datatype = dt_version;
} else if (a->is_advanced) {
@@ -54,7 +54,7 @@ static dt what_is_name(const automata *a)
}
-static void end_name(automata *a)
+static void end_name(struct automata *a)
{
a->datatype = what_is_name(a);
if (a->datatype == dt_plain) {
@@ -70,7 +70,7 @@ static void end_name(automata *a)
buf_new(a);
}
-static int end_data(automata *a)
+static int end_data(struct automata *a)
{
switch (a->datatype) {
case dt_plain: a->cookie.data = a->buf; break;
@@ -82,8 +82,8 @@ static int end_data(automata *a)
return 1;
}
-static void *state_name(automata *a, char c);
-static void *state_pre_name(automata *a, char c)
+static void *state_name(struct automata *a, char c);
+static void *state_pre_name(struct automata *a, char c)
{
if (c == ' ' || c == '\t'){
return state_pre_name;
@@ -94,9 +94,9 @@ static void *state_pre_name(automata *a, char c)
return 0;
}
-static void *state_pre_data(automata *a, char c);
-static void *state_post_name(automata *a, char c);
-static void *state_name(automata *a, char c)
+static void *state_pre_data(struct automata *a, char c);
+static void *state_post_name(struct automata *a, char c);
+static void *state_name(struct automata *a, char c)
{
if (c == '=') {
end_name(a);
@@ -111,7 +111,7 @@ static void *state_name(automata *a, char c)
return 0;
}
-static void *state_post_name(automata *a, char c)
+static void *state_post_name(struct automata *a, char c)
{
if (c == '=') {
return state_pre_data;
@@ -121,9 +121,9 @@ static void *state_post_name(automata *a, char c)
return 0;
}
-static void *state_data(automata *a, char c);
-static void *state_data_quoted(automata *a, char c);
-static void *state_pre_data(automata *a, char c)
+static void *state_data(struct automata *a, char c);
+static void *state_data_quoted(struct automata *a, char c);
+static void *state_pre_data(struct automata *a, char c)
{
if (c == '"') {
return state_data_quoted;
@@ -136,8 +136,8 @@ static void *state_pre_data(automata *a, char c)
return 0;
}
-static void *state_post_data(automata *a, char c);
-static void *state_data(automata *a, char c)
+static void *state_post_data(struct automata *a, char c);
+static void *state_data(struct automata *a, char c)
{
if (c == ';' || (c == ',' && a->is_first)) {
a->is_first = 0;
@@ -151,7 +151,7 @@ static void *state_data(automata *a, char c)
return 0;
}
-static void *state_data_quoted(automata *a, char c)
+static void *state_data_quoted(struct automata *a, char c)
{
if (c == '"') {
return end_data(a) ? state_post_data : 0;
@@ -159,7 +159,7 @@ static void *state_data_quoted(automata *a, char c)
return state_data_quoted;
}
-static void *state_post_data(automata *a, char c)
+static void *state_post_data(struct automata *a, char c)
{
if (c == ';' || (c == ',' && a->is_first)) {
a->is_first = 0;
@@ -171,7 +171,7 @@ static void *state_post_data(automata *a, char c)
}
-static void parse_end(magi_error *e, automata *a, state s)
+static void parse_end(enum magi_error *e, struct automata *a, state s)
{
if (s == state_data_quoted) {
*e = magi_error_cookies;
@@ -190,12 +190,12 @@ static void parse_end(magi_error *e, automata *a, state s)
}
-void magi_parse_cookies(magi_request *request, const char *data)
+void magi_parse_cookies(struct magi_request *request, const char *data)
{
- state s;
- automata a = { 0, { 0, 0, 0, 0, 0 }, 0, 0, 0, 1, 0, 0, 0 };
- a.list = &request->cookies;
- request->cookies = 0;
+ state s;
+ struct automata a = { 0, { 0, 0, 0, 0, 0 }, 0, 0, 0, 1, 0, 0, 0 };
+ a.list = &request->cookies;
+ request->cookies = 0;
for (s = state_pre_name; s && *data; ++data) {
s = s(&a, *data);
}
diff --git a/src/cookies.h b/src/cookies.h
index 30b9746..62b7249 100644
--- a/src/cookies.h
+++ b/src/cookies.h
@@ -4,7 +4,7 @@
#include "request.h"
-void magi_parse_cookies(magi_request *request, const char *data);
+void magi_parse_cookies(struct magi_request *request, const char *data);
#endif
diff --git a/src/error.c b/src/error.c
index 0bb553b..0ae2704 100644
--- a/src/error.c
+++ b/src/error.c
@@ -3,7 +3,7 @@
#include <stdio.h>
-const char *magi_error_message(magi_error error)
+const char *magi_error_message(enum magi_error error)
{
static const char *const messages[] = {
0, /* magi_error_none */
@@ -19,7 +19,7 @@ const char *magi_error_message(magi_error error)
return messages[error];
}
-void magi_error_response(magi_error error)
+void magi_error_response(enum magi_error error)
{
fputs("Status: 400 Bad Request\r\n"
"Content-Type: text/html\r\n\r\n"
diff --git a/src/file.c b/src/file.c
index 7e3d2f8..30b085c 100644
--- a/src/file.c
+++ b/src/file.c
@@ -4,9 +4,9 @@
#include <string.h>
-void magi_files_add(magi_files **files, magi_file *newitem)
+void magi_files_add(struct magi_files **files, struct magi_file *newitem)
{
- magi_files *node = malloc(sizeof(*node));
+ struct magi_files *node = malloc(sizeof(*node));
if (node) {
node->next = *files;
node->item = *newitem;
@@ -14,7 +14,8 @@ void magi_files_add(magi_files **files, magi_file *newitem)
}
}
-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)
{
if (!files || !name) {
return 0;
@@ -25,7 +26,7 @@ const magi_file *magi_files_get(const magi_files *files, const char *name)
}
}
-void magi_files_free(magi_files *files)
+void magi_files_free(struct magi_files *files)
{
if (files) {
magi_files_free(files->next);
diff --git a/src/loadfiles.c b/src/loadfiles.c
index 6d68895..963e351 100644
--- a/src/loadfiles.c
+++ b/src/loadfiles.c
@@ -5,10 +5,10 @@
#include <string.h>
-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)
{
static const int size = sizeof(*table->files);
if (!table) {
@@ -25,7 +25,7 @@ void magi_loadfiles_add(magi_loadfiles *table,
table->count++;
}
-void magi_loadfiles_free(magi_loadfiles *table)
+void magi_loadfiles_free(struct magi_loadfiles *table)
{
if (!table) {
return;
@@ -34,14 +34,14 @@ void magi_loadfiles_free(magi_loadfiles *table)
table->count = 0;
}
-static void loadfiles_callback(void *userdata,
- int newfile,
- magi_file *file,
- char *addon,
- int addon_len)
+static void loadfiles_callback(void *userdata,
+ int newfile,
+ struct magi_file *file,
+ char *addon,
+ int addon_len)
{
- magi_loadfiles *table = userdata;
- int pos;
+ int pos;
+ struct magi_loadfiles *table = userdata;
if (!file->filename || !*file->filename) {
return;
}
@@ -71,7 +71,8 @@ static void loadfiles_callback(void *userdata,
}
}
-void magi_loadfiles_set(magi_request *request, magi_loadfiles *table)
+void magi_loadfiles_set(struct magi_request *request,
+ struct magi_loadfiles *table)
{
request->callback.act = loadfiles_callback;
request->callback.userdata = table;
diff --git a/src/multipart.c b/src/multipart.c
index 8164bfd..a412603 100644
--- a/src/multipart.c
+++ b/src/multipart.c
@@ -32,25 +32,25 @@ static int is_str_token(char *str)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Automata for multipart/form-data
*/
-typedef struct automata {
- magi_request *request;
- magi_file file;
- magi_param param;
- magi_param subparam;
- char *buf;
- int buf_size;
- int size;
- int len;
- char *boundary;
- int boundary_pos;
- int boundary_len;
- int is_end_suspected;
- int is_CR_readed;
- int is_quoted;
- int readed;
- int newfile;
-} automata;
-typedef void *(*state)(automata *a, char c);
+struct automata {
+ struct magi_request *request;
+ struct magi_file file;
+ struct magi_param param;
+ struct magi_param subparam;
+ char *buf;
+ int buf_size;
+ int size;
+ int len;
+ char *boundary;
+ int boundary_pos;
+ int boundary_len;
+ int is_end_suspected;
+ int is_CR_readed;
+ int is_quoted;
+ int readed;
+ int newfile;
+};
+typedef void *(*state)(struct automata *a, char c);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -71,7 +71,7 @@ static char *extract_filename(char *n)
}
}
-static int content_disposition(automata *a)
+static int content_disposition(struct automata *a)
{
char *n = strchr(a->subparam.data, '=');
if (!n) {
@@ -103,7 +103,7 @@ static int content_disposition(automata *a)
return 1;
}
-static int subparam_end(automata *a)
+static int subparam_end(struct automata *a)
{
a->size = 1;
a->len = 0;
@@ -117,7 +117,7 @@ static int subparam_end(automata *a)
return 1;
}
-static int param_end(automata *a)
+static int param_end(struct automata *a)
{
if (a->file.filename) {
a->request->callback.act(a->request->callback.userdata,
@@ -151,7 +151,7 @@ static int param_end(automata *a)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Boundary Interfaces
*/
-static char sepget(const automata *a)
+static char sepget(const struct automata *a)
{
char c;
const int pos_after = a->boundary_pos - 4 - a->boundary_len;
@@ -173,9 +173,7 @@ static char sepget(const automata *a)
return c;
}
-static int seplen(const automata *a) { return a->boundary_len + 6; }
-
-static char endget(const automata *a)
+static char endget(const struct automata *a)
{
char c;
const int pos_after = a->boundary_pos - 4 - a->boundary_len;
@@ -199,12 +197,10 @@ static char endget(const automata *a)
return c;
}
-static int endlen(const automata *a)
-{
- return a->boundary_len + 8;
-}
+static int seplen(const struct automata *a) { return a->boundary_len + 6; }
+static int endlen(const struct automata *a) { return a->boundary_len + 8; }
-static int is_semiend(const automata *a)
+static int is_semiend(const struct automata *a)
{ /* Is end readed, expect last two chars, which are CR LF? */
return a->is_end_suspected && (a->boundary_pos == endlen(a) - 2);
}
@@ -213,7 +209,7 @@ static int is_semiend(const automata *a)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Data Reading
*/
-static void apply_callback(automata *a)
+static void apply_callback(struct automata *a)
{
int full = a->buf_size == a->request->callback.addon_max;
if (a->file.filename && full) {
@@ -225,9 +221,13 @@ static void apply_callback(automata *a)
}
}
-static void *state_pname_pre(automata *a, char c);
-static void *state_data(automata *a, char c);
-static void *data_add_act(automata *a, char c, char **dest, int *l, int *s)
+static void *state_pname_pre(struct automata *a, char c);
+static void *state_data(struct automata *a, char c);
+static void *data_add_act(struct automata *a,
+ char c,
+ char **dest,
+ int *l,
+ int *s)
{
int pos = a->boundary_pos;
for (a->boundary_pos = 0; a->boundary_pos < pos; ++a->boundary_pos) {
@@ -254,7 +254,7 @@ static void *data_add_act(automata *a, char c, char **dest, int *l, int *s)
return state_data;
}
-static void *data_add(automata *a, char c)
+static void *data_add(struct automata *a, char c)
{
if (a->file.filename) {
int max = a->request->callback.addon_max + 1;
@@ -268,7 +268,7 @@ static void *data_add(automata *a, char c)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* State analysers
*/
-static void *state_begin(automata *a, char c)
+static void *state_begin(struct automata *a, char c)
{
if (sepget(a) != c) { /* 'c' is not wanted character from separator; */
a->boundary_pos = 0; /* so nullify progress in reading separator. */
@@ -281,8 +281,8 @@ static void *state_begin(automata *a, char c)
return state_begin;
}
-static void *state_pname(automata *a, char c);
-static void *state_pname_pre(automata *a, char c)
+static void *state_pname(struct automata *a, char c);
+static void *state_pname_pre(struct automata *a, char c)
{
if (a->is_CR_readed) {
if (c != '\n') {
@@ -301,9 +301,9 @@ static void *state_pname_pre(automata *a, char c)
return 0;
}
-static void *state_pdata(automata *a, char c);
-static void *state_pname_end(automata *a, char c);
-static void *state_pname(automata *a, char c)
+static void *state_pdata(struct automata *a, char c);
+static void *state_pname_end(struct automata *a, char c);
+static void *state_pname(struct automata *a, char c)
{
if (c == ':') {
a->len = 0;
@@ -318,7 +318,7 @@ static void *state_pname(automata *a, char c)
return 0;
}
-static void *state_pname_end(automata *a, char c)
+static void *state_pname_end(struct automata *a, char c)
{
if (c == ':') {
a->len = 0;
@@ -330,7 +330,7 @@ static void *state_pname_end(automata *a, char c)
return 0;
}
-static void *state_pdata(automata *a, char c)
+static void *state_pdata(struct automata *a, char c)
{
if (a->is_CR_readed) {
a->is_CR_readed = 0;
@@ -347,8 +347,8 @@ static void *state_pdata(automata *a, char c)
return state_pdata;
}
-static void *state_end(automata *a, char c);
-static void *state_data(automata *a, char c)
+static void *state_end(struct automata *a, char c);
+static void *state_data(struct automata *a, char c)
{
if (a->is_end_suspected) {
if (endget(a) != c) {
@@ -375,15 +375,15 @@ static void *state_data(automata *a, char c)
return state_data;
}
-static void *state_end(automata *a, char c) { return state_end; }
+static void *state_end(struct automata *a, char c) { return state_end; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Automata Runner
*/
-static void run_automata(automata *a,
- int (*next)(void *next_userdata),
- void *next_userdata)
+static void run_automata(struct automata *a,
+ int (*next)(void *next_userdata),
+ void *next_userdata)
{
state s;
int c = next(next_userdata);
@@ -409,12 +409,12 @@ static void run_automata(automata *a,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Automata Interfaces
*/
-void magi_parse_multipart(magi_request *request,
- char *boundary,
- int (*next)(void *userdata),
- void *next_userdata)
+void magi_parse_multipart(struct magi_request *request,
+ char *boundary,
+ int (*next)(void *userdata),
+ void *next_userdata)
{
- automata a = {
+ struct automata a = {
0, { 0, 0, 0 }, { 0, 0 }, { 0, 0 }, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1
};
a.request = request;
diff --git a/src/multipart.h b/src/multipart.h
index 617c3f8..0b55e8c 100644
--- a/src/multipart.h
+++ b/src/multipart.h
@@ -4,10 +4,10 @@
#include "request.h"
-void magi_parse_multipart(magi_request *request,
- char *boundary,
- int (*next)(void *userdata),
- void *next_userdata);
+void magi_parse_multipart(struct magi_request *request,
+ char *boundary,
+ int (*next)(void *userdata),
+ void *next_userdata);
#endif
diff --git a/src/param.c b/src/param.c
index dcf33d4..5854231 100644
--- a/src/param.c
+++ b/src/param.c
@@ -4,9 +4,9 @@
#include <string.h>
-void magi_params_add(magi_params **params, magi_param *newitem)
+void magi_params_add(struct magi_params **params, struct magi_param *newitem)
{
- magi_params *node = malloc(sizeof(*node));
+ struct magi_params *node = malloc(sizeof(*node));
if (node) {
node->next = *params;
node->item = *newitem;
@@ -14,7 +14,7 @@ void magi_params_add(magi_params **params, magi_param *newitem)
}
}
-void magi_params_set(magi_params **params, magi_param *newitem)
+void magi_params_set(struct magi_params **params, struct magi_param *newitem)
{
if (!*params) {
magi_params_add(params, newitem);
@@ -28,7 +28,7 @@ void magi_params_set(magi_params **params, magi_param *newitem)
}
}
-char *magi_params_get(const magi_params *params, const char *name)
+char *magi_params_get(const struct magi_params *params, const char *name)
{
if (!params || !name) {
return 0;
@@ -39,7 +39,7 @@ char *magi_params_get(const magi_params *params, const char *name)
}
}
-void magi_params_free(magi_params *params)
+void magi_params_free(struct magi_params *params)
{
if (params) {
magi_params_free(params->next);
diff --git a/src/parse.c b/src/parse.c
index 83884f0..fa8b54a 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -37,13 +37,13 @@ static char *lower_env(char *env_name)
return env;
}
-static void cgi_http_env(magi_request *r)
+static void cgi_http_env(struct magi_request *r)
{
char **env;
int len = 0;
r->meta = 0;
for (env = environ; *env; ++env) {
- magi_param meta;
+ struct magi_param meta;
char *name_end = strchr(*env, '=');
int nlen = name_end - *env;
int dlen = strlen(name_end + 1);
@@ -58,7 +58,7 @@ static void cgi_http_env(magi_request *r)
}
}
-static void cgi_env(magi_request *r)
+static void cgi_env(struct magi_request *r)
{
cgi_http_env(r);
r->method = plain_env("REQUEST_METHOD");
@@ -78,7 +78,7 @@ static void cgi_env(magi_request *r)
r->path = plain_env("PATH_INFO");
}
-static void cgi_cookies(magi_request *r)
+static void cgi_cookies(struct magi_request *r)
{
const char *env = getenv("HTTP_COOKIE");
if (!env || !*env) {
@@ -92,7 +92,7 @@ static void cgi_cookies(magi_request *r)
magi_parse_cookies(r, env);
}
-static void cgi_input_get(magi_error *e, char **input, int max)
+static void cgi_input_get(enum magi_error *e, char **input, int max)
{
const char *env_input = getenv("QUERY_STRING");
if (env_input) {
@@ -105,7 +105,7 @@ static void cgi_input_get(magi_error *e, char **input, int max)
}
}
-static void cgi_url(magi_request *request)
+static void cgi_url(struct magi_request *request)
{
char *in = 0;
cgi_input_get(&request->error, &in, request->limits.params_head);
@@ -115,7 +115,7 @@ static void cgi_url(magi_request *request)
}
}
-static void cgi_input_post(magi_error *e, char **input, int max)
+static void cgi_input_post(enum magi_error *e, char **input, int max)
{
int input_len = strtoul(getenv("CONTENT_LENGTH"), 0, 10);
if (!input_len) {
@@ -175,7 +175,7 @@ static int next(void *userdata)
}
/* Interfacial CGI Request Handling */
-int magi_parse_head(magi_request *request)
+int magi_parse_head(struct magi_request *request)
{
request->cookies = 0;
request->files = 0;
@@ -189,10 +189,10 @@ int magi_parse_head(magi_request *request)
return !request->error;
}
-int magi_parse_body(magi_request *request)
+int magi_parse_body(struct magi_request *request)
{
- magi_error *e = &request->error;
- request->error = magi_error_none;
+ enum magi_error *e = &request->error;
+ request->error = magi_error_none;
if (request->method && !strcmp(request->method, "POST")) {
const char *t = getenv("CONTENT_TYPE");
if (!t) {
@@ -223,7 +223,7 @@ int magi_parse_body(magi_request *request)
return !request->error;
}
-int magi_parse(magi_request *request)
+int magi_parse(struct magi_request *request)
{
return magi_parse_head(request) && magi_parse_body(request);
}
diff --git a/src/request.c b/src/request.c
index 22b3f30..e957889 100644
--- a/src/request.c
+++ b/src/request.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
-void magi_request_init(magi_request *request)
+void magi_request_init(struct magi_request *request)
{
if (request) {
request->callback.act = 0;
@@ -18,7 +18,7 @@ void magi_request_init(magi_request *request)
}
-static void request_free(magi_request *request)
+static void request_free(struct magi_request *request)
{
free(request->cookies);
free(request->meta);
@@ -32,7 +32,7 @@ static void request_free(magi_request *request)
free(request->path);
}
-static void request_annul(magi_request *request)
+static void request_annul(struct magi_request *request)
{
request->cookies = 0;
request->meta = 0;
@@ -45,7 +45,7 @@ static void request_annul(magi_request *request)
request->path = 0;
}
-void magi_request_free(magi_request *request)
+void magi_request_free(struct magi_request *request)
{
if (request) {
magi_cookies_free(request->cookies);
@@ -59,12 +59,12 @@ void magi_request_free(magi_request *request)
}
-char *magi_request_meta(const magi_request *r, const char *name)
+char *magi_request_meta(const struct magi_request *r, const char *name)
{
return magi_params_get(r->meta, name);
}
-char *magi_request_param(const magi_request *r, const char *name)
+char *magi_request_param(const struct magi_request *r, const char *name)
{
char *res = magi_params_get(r->body, name);
if (!res) {
@@ -73,27 +73,29 @@ char *magi_request_param(const magi_request *r, const char *name)
return res;
}
-char *magi_request_urlparam(const magi_request *r, const char *name)
+char *magi_request_urlparam(const struct magi_request *r, const char *name)
{
return magi_params_get(r->head, 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)
{
return magi_files_get(r->files, name);
}
-char *magi_request_cookie(const magi_request *r, const char *name)
+char *magi_request_cookie(const struct magi_request *r, const char *name)
{
- const magi_cookie *res = magi_cookies_get(r->cookies, name);
+ const struct magi_cookie *res = magi_cookies_get(r->cookies, name);
if (!res) {
return 0;
}
return res->data;
}
-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)
{
return magi_cookies_get(r->cookies, name);
}
diff --git a/src/response.c b/src/response.c
index 7723e26..43da57e 100644
--- a/src/response.c
+++ b/src/response.c
@@ -6,7 +6,7 @@
#include <string.h>
-void magi_response_init(magi_response *r)
+void magi_response_init(struct magi_response *r)
{
r->head_response = 0;
r->head_general = 0;
@@ -15,7 +15,7 @@ void magi_response_init(magi_response *r)
magi_response_content_type(r, "text/html");
}
-static void response_headers(magi_params *p)
+static void response_headers(struct magi_params *p)
{
for (; p; p = p->next) {
fputs(p->item.name, stdout);
@@ -25,7 +25,7 @@ static void response_headers(magi_params *p)
}
}
-void magi_response_send(magi_response *r)
+void magi_response_send(struct magi_response *r)
{
response_headers(r->head_response);
response_headers(r->head_general);
@@ -33,7 +33,7 @@ void magi_response_send(magi_response *r)
fputs("\r\n", stdout);
}
-void magi_response_free(magi_response *r)
+void magi_response_free(struct magi_response *r)
{
magi_params_free(r->head_response);
magi_params_free(r->head_general);
@@ -54,10 +54,12 @@ void magi_response_default()
}
-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)
{
- int dlen;
- magi_param addon;
+ int dlen;
+ struct magi_param addon;
if (code <= 99 || 600 <= code) {
return;
}
@@ -72,11 +74,13 @@ void magi_response_status(magi_response *r, int code, const char *description)
magi_params_set(&r->head_response, &addon);
}
-void magi_response_cookie(magi_response *r, const char *name, const char *data)
+void magi_response_cookie(struct magi_response *r,
+ const char *name,
+ const char *data)
{
- magi_param addon;
- int nlen;
- int dlen;
+ int nlen;
+ int dlen;
+ struct magi_param addon;
if (!name || !data) {
return;
}
@@ -90,10 +94,11 @@ void magi_response_cookie(magi_response *r, const char *name, const char *data)
magi_params_add(&r->head_general, &addon);
}
-void magi_response_cookie_complex(magi_response *r, magi_cookie *c)
+void magi_response_cookie_complex(struct magi_response *r,
+ struct magi_cookie *c)
{
- magi_param addon;
- char *pointer;
+ char *pointer;
+ struct magi_param addon;
int nlen, dlen, dsize, psize, msize;
const int cdsize = 9;
const int cpsize = 7;
@@ -134,10 +139,10 @@ void magi_response_cookie_complex(magi_response *r, magi_cookie *c)
magi_params_add(&r->head_general, &addon);
}
-void magi_response_cookie_discard(magi_response *r, const char *name)
+void magi_response_cookie_discard(struct magi_response *r, const char *name)
{
- magi_param addon;
int len;
+ struct magi_param addon;
if (!name) {
return;
}
@@ -149,17 +154,19 @@ void magi_response_cookie_discard(magi_response *r, const char *name)
magi_params_add(&r->head_general, &addon);
}
-void magi_response_header(magi_response *r, const char *name, const char *data)
+void magi_response_header(struct magi_response *r,
+ const char *name,
+ const char *data)
{
- magi_param addon;
+ struct magi_param addon;
addon.name = magi_str_create_copy(name, strlen(name));
addon.data = magi_str_create_copy(data, strlen(data));
magi_params_add(&r->head_general, &addon);
}
-void magi_response_content_length(magi_response *r, int length)
+void magi_response_content_length(struct magi_response *r, int length)
{
- magi_param addon;
+ struct magi_param addon;
int len = 1;
addon.name = magi_str_create_copy("Content-Length", 14);
addon.data = malloc(len + 1);
@@ -173,9 +180,9 @@ void magi_response_content_length(magi_response *r, int length)
magi_params_set(&r->head_entity, &addon);
}
-void magi_response_content_type(magi_response *r, const char *type)
+void magi_response_content_type(struct magi_response *r, const char *type)
{
- magi_param addon;
+ struct magi_param addon;
addon.name = magi_str_create_copy("Content-Type", 12);
addon.data = magi_str_create_copy(type, strlen(type));
magi_params_set(&r->head_entity, &addon);
diff --git a/src/urlencoded.c b/src/urlencoded.c
index 27c9c21..f00492b 100644
--- a/src/urlencoded.c
+++ b/src/urlencoded.c
@@ -61,19 +61,19 @@ static int deurl(char **data)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Urlencoded Automata
*/
-typedef struct automata {
- magi_params **list;
- char *name;
- int nlen;
- int nsize;
- char *data;
- int dlen;
- int dsize;
-} automata;
-typedef void *(*state)(automata *a, char c);
+struct automata {
+ struct magi_params **list;
+ char *name;
+ int nlen;
+ int nsize;
+ char *data;
+ int dlen;
+ int dsize;
+};
+typedef void *(*state)(struct automata *a, char c);
-static void *state_parse_data(automata *a, char c);
-static void *state_parse_name(automata *a, char c)
+static void *state_parse_data(struct automata *a, char c);
+static void *state_parse_name(struct automata *a, char c)
{
if (c == '&' || c == ';') {
return 0;
@@ -84,9 +84,9 @@ static void *state_parse_name(automata *a, char c)
return state_parse_name;
}
-static void add_to_list(automata *a)
+static void add_to_list(struct automata *a)
{
- magi_param param;
+ struct magi_param param;
param.name = a->name;
param.data = a->data;
magi_params_add(a->list, &param);
@@ -94,7 +94,7 @@ static void add_to_list(automata *a)
a->data = 0;
}
-static void *state_parse_data(automata *a, char c)
+static void *state_parse_data(struct automata *a, char c)
{
if (c == '=') {
return 0;
@@ -109,12 +109,13 @@ static void *state_parse_data(automata *a, char c)
return state_parse_data;
}
-magi_error magi_parse_urlencoded(magi_params **list, const char *encoded)
+enum magi_error magi_parse_urlencoded(struct magi_params **list,
+ const char *encoded)
{
- state s;
- automata a = { 0, 0, 0, 0, 0, 0, 0 };
- a.list = list;
- *list = 0;
+ state s;
+ struct automata a = { 0, 0, 0, 0, 0, 0, 0 };
+ a.list = list;
+ *list = 0;
if (!encoded || !*encoded) {
return 0;
}
diff --git a/src/urlencoded.h b/src/urlencoded.h
index df33fe4..5933669 100644
--- a/src/urlencoded.h
+++ b/src/urlencoded.h
@@ -6,7 +6,8 @@
/* Add decoded params from 'encoded' to 'list'. */
-magi_error magi_parse_urlencoded(magi_params **list, const char *encoded);
+enum magi_error magi_parse_urlencoded(struct magi_params **list,
+ const char *encoded);
#endif