#include <stdlib.h>
#include <string.h>
#include <microhttpd.h>
+#include <yajl/yajl_gen.h>
#include "database.h"
#include "tags.h"
#include "auth.h"
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);
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;