-int POST_subscribe_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) {
- struct subscribe_state *ss = cls;
+int process_put(struct MHD_Connection *connection, const char *method, const char *upload_data, size_t *upload_data_size, void **ptr) {
+ struct put_state *ps = (struct put_state *) *ptr;
+
+ if (ps == NULL) {
+ if (strcmp(method, MHD_HTTP_METHOD_POST) != 0)
+ return respond_405(connection);
+
+ *ptr = (void *) 1;
+
+ struct put_state *ps = malloc(sizeof(struct put_state));
+ ps->data = NULL;
+ ps->data_size = 0;
+ ps->pp = MHD_create_post_processor(connection, 16384, &POST_put_iterator, ps);
+ ps->username[0] = 0;
+ *ptr = ps;
+ return MHD_YES;
+ }
+
+ if (*upload_data_size) {
+ MHD_post_process(ps->pp, upload_data, *upload_data_size);
+ *upload_data_size = 0;
+ return MHD_YES;
+ }
+
+ return MHD_NO;
+}
+
+int process_and_check_put(struct MHD_Connection *connection, const char *method, const char *upload_data, size_t *upload_data_size, void **ptr) {
+ struct put_state *ps = (struct put_state *) *ptr;
+
+ if (process_put(connection, method, upload_data, upload_data_size, ptr) == MHD_YES)
+ return MHD_YES;
+
+ const char *given_token = MHD_lookup_connection_value(connection, MHD_COOKIE_KIND, "auth");
+ if (!auth_check_token(ps->username, given_token))
+ return respond_403(connection);
+
+ return MHD_NO;
+}
+
+int POST_auth_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) {
+ struct auth_state *as = cls;