From: Chip Black Date: Wed, 22 Dec 2010 06:23:00 +0000 (-0600) Subject: Some refactoring, remove build bits for libmicrohttpd X-Git-Tag: ohfuckreddit~48 X-Git-Url: http://git.bytex64.net/?a=commitdiff_plain;h=3d6d277d4cdfff7c11729cde0e2498b4b3912a98;p=blerg.git Some refactoring, remove build bits for libmicrohttpd --- diff --git a/Makefile b/Makefile index 761b2bb..bf27046 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ -libmicrohttpd_a = libmicrohttpd-0.9.3/src/daemon/.libs/libmicrohttpd.a - -CFLAGS = -g -Ilibmicrohttpd-0.9.3/src/include -LIBS = +CFLAGS = -g -Ilibmicrohttpd-0.9.3/src/include -Iyajl/build/yajl-1.0.11/include +LDFLAGS = -Llibmicrohttpd-0.9.3/src/daemon/.libs -Lyajl/build/yajl-1.0.11/lib targets = blerg.a blergtool http_blerg blerg_a_objects = database.o tags.o @@ -12,19 +10,15 @@ all: $(targets) clean: rm -f $(targets) $(blerg_a_objects) $(blergtool_objects) $(http_blerg_objects) - -cd libmicrohttpd-0.9.3 && make distclean blerg.a: $(blerg_a_objects) ar rcu $@ $(blerg_a_objects) -$(libmicrohttpd_a): - cd libmicrohttpd-0.9.3 && ./configure --disable-https --disable-shared && make - blergtool: $(blergtool_objects) gcc $^ -o $@ -http_blerg: $(http_blerg_objects) $(libmicrohttpd_a) - gcc $(http_blerg_objects) -lpthread $(libmicrohttpd_a) -o $@ +http_blerg: $(http_blerg_objects) + gcc $(LDFLAGS) $(http_blerg_objects) -lpthread -lmicrohttpd -lyajl_s -o $@ %.o: %.c gcc $(CFLAGS) $(LIBS) -c $< -o $@ diff --git a/http_blerg.c b/http_blerg.c index 3cbc207..e6eddad 100644 --- a/http_blerg.c +++ b/http_blerg.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "database.h" #include "tags.h" #include "auth.h" @@ -131,10 +132,17 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c char *data; if (strncmp(url, "/get", 4) == 0 && strlen(url) > 4) { - if (strcmp(method, MHD_HTTP_METHOD_GET) != 0) - return MHD_NO; + if (*ptr == NULL) { + if (strcmp(method, MHD_HTTP_METHOD_GET) != 0) + return respond_405(connection); + + *ptr = (void *) 1; + return MHD_YES; + } + if (url[4] != '/') return respond_404(connection); + ret = parse_url_info(url + 5, author, &record); if ((ret & URL_INFO_AUTHOR) == 0) return respond_404(connection); @@ -142,37 +150,26 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c if (!blerg_exists(author)) return respond_404(connection); + *ptr == NULL; + if (ret & URL_INFO_RECORD) { - if (*ptr == NULL) { - *ptr = (void *) 1; - return MHD_YES; - } else { - *ptr == NULL; - - struct blerg *b = blerg_open(author); - ret = blerg_fetch(b, record, &data, &len); - blerg_close(b); - - if (ret == 0) { - return respond_404(connection); - } else { - response = MHD_create_response_from_data(len, data, MHD_YES, MHD_NO); - ret = MHD_queue_response(connection, MHD_HTTP_OK, response); - } - MHD_destroy_response(response); - return ret; - } - } else { - if (*ptr == NULL) { - *ptr = (void*) 1; - return MHD_YES; + struct blerg *b = blerg_open(author); + ret = blerg_fetch(b, record, &data, &len); + blerg_close(b); + + if (ret == 0) { + return respond_404(connection); } else { - *ptr == NULL; - response = MHD_create_response_from_data(strlen(DERP), DERP, MHD_NO, MHD_NO); + response = MHD_create_response_from_data(len, data, MHD_YES, MHD_NO); ret = MHD_queue_response(connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - return ret; } + MHD_destroy_response(response); + return ret; + } else { + response = MHD_create_response_from_data(strlen(DERP), DERP, MHD_NO, MHD_NO); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); + return ret; } } else if (strncmp(url, "/put", 4) == 0) { struct put_state *ps = (struct put_state *) *ptr;