X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=http_blerg.c;h=6a6de827651eb190dd47be092fa2f63f18e65223;hb=c4025f5d80dc8f3f15ee6814ac689b9eee1dba10;hp=f8513c51835c0adb9553f2c6681c47272edea9b0;hpb=c7dff84524c5e3e8cee6054533a3043da6851c87;p=blerg.git diff --git a/http_blerg.c b/http_blerg.c index f8513c5..6a6de82 100644 --- a/http_blerg.c +++ b/http_blerg.c @@ -4,6 +4,7 @@ #include #include "database.h" #include "tags.h" +#include "auth.h" #define URL_INFO_AUTHOR 0x1 #define URL_INFO_RECORD 0x2 @@ -18,6 +19,7 @@ struct create_state { struct MHD_Response *response_404; struct MHD_Response *response_501; struct MHD_Response *response_JSON_Success; +struct MHD_Response *response_JSON_Failure; void init_responses() { #define CONTENT_404 "404 Not Found

404 Not Found

I couldn't find that." @@ -28,6 +30,9 @@ void init_responses() { #define JSON_SUCCESS "{status: \"success\"}" response_JSON_Success = MHD_create_response_from_data(strlen(JSON_SUCCESS), JSON_SUCCESS, MHD_NO, MHD_NO); + +#define JSON_FAILURE "{status: \"failure\"}" + response_JSON_Failure = MHD_create_response_from_data(strlen(JSON_FAILURE), JSON_FAILURE, MHD_NO, MHD_NO); } int respond_404(struct MHD_Connection *connection) { @@ -42,6 +47,10 @@ int respond_JSON_Success(struct MHD_Connection *connection) { return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Success); } +int respond_JSON_Failure(struct MHD_Connection *connection) { + return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Failure); +} + int parse_url_info(const char *url, char *author, uint64_t *record) { const char *c; int ret = 0; @@ -199,14 +208,15 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c *upload_data_size = 0; return MHD_YES; } else { - printf("username: %s, password: %s\n", cs->username, cs->password); - if (cs->username[0] == 0 || cs->password[0] == 0) - return MHD_NO; // TODO: Give a better response + return respond_JSON_Failure(connection); + + if (blerg_exists(cs->username)) + return respond_JSON_Failure(connection); struct blerg *b = blerg_open(cs->username); blerg_close(b); - /* auth_set_password(cs->username, cs->password); */ + auth_set_password(cs->username, cs->password); MHD_destroy_post_processor(cs->pp); free(cs);