+ } else if (strncmp(url, "/put", 4) == 0) {
+ char *username;
+ const char *password = "testpass";
+ const char *realm = "Blerg Post";
+
+#define OPAQUE "d29fb6db8f21a6e99903651a9f87470e"
+#define DENIED "DENIED, MOTHERFUCKER"
+#define PAGE "DERP DERP AUTHENTICATED DERP"
+
+ if (*ptr == NULL) {
+ *ptr = (void *) 1;
+
+ username = MHD_digest_auth_get_username(connection);
+ if (username == NULL) {
+ response = MHD_create_response_from_data(strlen (DENIED), DENIED, MHD_NO, MHD_NO);
+ ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response, MHD_NO);
+ MHD_destroy_response(response);
+ return ret;
+ }
+
+ printf("username: %s\n", username);
+
+ ret = MHD_digest_auth_check(connection, realm, username, password, 300);
+ free(username);
+
+ if (ret == MHD_INVALID_NONCE || ret == MHD_NO) {
+ response = MHD_create_response_from_data(strlen (DENIED), DENIED, MHD_NO, MHD_NO);
+ ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response,
+ (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
+ MHD_destroy_response(response);
+ return ret;
+ }
+ }
+
+ *ptr = NULL;
+
+ 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);
+
+ response = MHD_create_response_from_data(strlen(PAGE), PAGE, MHD_NO, MHD_NO);
+ ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
+ MHD_destroy_response(response);
+ return ret;
+ } else if (strncmp(url, "/create", 8) == 0) {
+ struct create_state *cs = (struct create_state *) *ptr;
+
+ if (cs == NULL) {
+ if (strcmp(method, MHD_HTTP_METHOD_POST) != 0)
+ return respond_501(connection);
+
+ struct create_state *cs = malloc(sizeof(struct create_state));
+ cs->username[0] = cs->password[0] = 0;
+ cs->pp = MHD_create_post_processor(connection, 1024, &POST_create_iterator, cs);
+ *ptr = cs;
+ return MHD_YES;
+ }
+
+ if (*upload_data_size) {
+ MHD_post_process(cs->pp, upload_data, *upload_data_size);
+ *upload_data_size = 0;
+ return MHD_YES;
+ } else {
+ if (cs->username[0] == 0 || cs->password[0] == 0)
+ 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);
+
+ MHD_destroy_post_processor(cs->pp);
+ free(cs);
+ return respond_JSON_Success(connection);
+ }