diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgi.c | 7 | ||||
-rw-r--r-- | src/cookie.c | 5 | ||||
-rw-r--r-- | src/fastcgi.c | 22 | ||||
-rw-r--r-- | src/file.c | 2 | ||||
-rw-r--r-- | src/loadfiles.c (renamed from src/loadfile.c) | 2 | ||||
-rw-r--r-- | src/multipart.c | 8 | ||||
-rw-r--r-- | src/param.c | 2 | ||||
-rw-r--r-- | src/request.c | 15 | ||||
-rw-r--r-- | src/session.c | 40 |
9 files changed, 83 insertions, 20 deletions
@@ -161,9 +161,8 @@ static void mhead(void *any, magi_param *header) fputs("\r\n", stdout); } -static void mstart_body(void *any) +static void mstart_body() { - (void)any; fputs("\r\n", stdout); } @@ -189,7 +188,7 @@ static void mfile(void *any, FILE *file) } } -static void mclose(void *any) { (void)any; } +static void mclose() {} static void setup_response(magi_request *r) { @@ -208,7 +207,7 @@ static void setup_response(magi_request *r) r->response->head_general = 0; r->response->head_entity = 0; r->response->head_done = 0; - magi_response_content_type(r, "application/xhtml+xml"); + magi_response_content_type(r, "text/html"); magi_response_status(r, 200, "OK"); } diff --git a/src/cookie.c b/src/cookie.c index 7b40f1a..a64f5cb 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -14,9 +14,10 @@ void magi_cookies_add(magi_cookies **cookies, magi_cookie *newitem) } } -magi_cookie *magi_cookies_get(magi_cookies *cookies, const char *name) +const magi_cookie *magi_cookies_get(const magi_cookies *cookies, + const char *name) { - magi_cookie *res = 0; + const magi_cookie *res = 0; if (!cookies || !name) { return 0; } diff --git a/src/fastcgi.c b/src/fastcgi.c index 39c57ca..8959c14 100644 --- a/src/fastcgi.c +++ b/src/fastcgi.c @@ -1 +1,23 @@ #include "fastcgi.h" + + +int magi_fastcgi_head(magi_session *s, magi_request *r) +{ + (void)s; + (void)r; + return 1; +} + + +int magi_fastcgi_body(magi_session *s, magi_request *r) +{ + (void)s; + (void)r; + return 1; +} + + +int magi_fastcgi(magi_session *s, magi_request *r) +{ + return magi_fastcgi_head(s, r) && magi_fastcgi_body(s, r); +} @@ -14,7 +14,7 @@ void magi_files_add(magi_files **files, magi_file *newitem) } } -magi_file *magi_files_get(magi_files *files, const char *name) +const magi_file *magi_files_get(const magi_files *files, const char *name) { if (!files || !name) { return 0; diff --git a/src/loadfile.c b/src/loadfiles.c index d76f562..b3efff7 100644 --- a/src/loadfile.c +++ b/src/loadfiles.c @@ -1,4 +1,4 @@ -#include "loadfile.h" +#include "loadfiles.h" #include <stdio.h> #include <stdlib.h> diff --git a/src/multipart.c b/src/multipart.c index 2284ced..d2a1c7f 100644 --- a/src/multipart.c +++ b/src/multipart.c @@ -63,10 +63,10 @@ static char *extract_filename(char *n) if (!n) { return 0; } - n += strspn(n, " \t") + 1; + n += strspn(n + 1, " \t") + 1; if (*n == '"') { ++n; - return magi_str_create_copy(n, n - strchr(n, '"')); + return magi_str_create_copy(n, strchr(n, '"') - n); } else { return magi_str_create_copy(n, strcspn(n, " \t")); } @@ -78,10 +78,10 @@ static int content_disposition(automata *a) if (!n) { return 0; } - n += strspn(n, " \t") + 1; + n += strspn(n + 1, " \t") + 1; if (*n == '"') { ++n; - a->param.name = magi_str_create_copy(n, n - strchr(n, '"')); + a->param.name = magi_str_create_copy(n, strchr(n, '"') - n); if (!a->param.name || !*a->param.name) { return 0; } diff --git a/src/param.c b/src/param.c index 9c94555..dcf33d4 100644 --- a/src/param.c +++ b/src/param.c @@ -28,7 +28,7 @@ void magi_params_set(magi_params **params, magi_param *newitem) } } -char *magi_params_get(magi_params *params, const char *name) +char *magi_params_get(const magi_params *params, const char *name) { if (!params || !name) { return 0; diff --git a/src/request.c b/src/request.c index ce0f84f..d80bf20 100644 --- a/src/request.c +++ b/src/request.c @@ -69,12 +69,12 @@ void magi_request_free(magi_request *request) } -char *magi_request_meta(magi_request *r, const char *name) +char *magi_request_meta(const magi_request *r, const char *name) { return magi_params_get(r->meta, name); } -char *magi_request_param(magi_request *r, const char *name) +char *magi_request_param(const magi_request *r, const char *name) { char *res = magi_params_get(r->body, name); if (!res) { @@ -83,26 +83,27 @@ char *magi_request_param(magi_request *r, const char *name) return res; } -char *magi_request_urlparam(magi_request *r, const char *name) +char *magi_request_urlparam(const magi_request *r, const char *name) { return magi_params_get(r->head, 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) { return magi_files_get(r->files, name); } -char *magi_request_cookie(magi_request *r, const char *name) +char *magi_request_cookie(const magi_request *r, const char *name) { - magi_cookie *res = magi_cookies_get(r->cookies, name); + const magi_cookie *res = magi_cookies_get(r->cookies, name); if (!res) { return 0; } return res->data; } -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) { return magi_cookies_get(r->cookies, name); } diff --git a/src/session.c b/src/session.c new file mode 100644 index 0000000..35e9200 --- /dev/null +++ b/src/session.c @@ -0,0 +1,40 @@ +#include "session.h" + +#include <arpa/inet.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> + + +void magi_session_init(magi_session *s) +{ + s->socket = 0; +} + +void magi_session_free(magi_session *s) +{ + if (s->socket) { + shutdown(s->socket, SHUT_RDWR); + s->socket = 0; + } +} + + +int magi_session_inet(magi_session *s, const char *address, int port) +{ + struct sockaddr_in addr; + s->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = inet_addr(address); + return !connect(s->socket, (struct sockaddr *)&addr, sizeof(addr)); +} + +int magi_session_unix(magi_session *s, const char *path) +{ + struct sockaddr_un addr; + s->socket = socket(AF_UNIX, SOCK_STREAM, IPPROTO_TCP); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); + return !connect(s->socket, (struct sockaddr *)&addr, sizeof(addr)); +} |