struct put_state {
struct MHD_PostProcessor *pp;
+ char username[33];
char *data;
int data_size;
};
memcpy(ps->data + off, data, size);
if (ps->data_size == MAX_RECORD_SIZE)
return MHD_NO;
+ } else if (strncmp(key, "username", 9) == 0) {
+ if (size > 32) size = 32;
+ memcpy(ps->username, data, size);
+ ps->username[size] = 0;
}
return MHD_YES;
*ptr = (void *) 1;
- username = MHD_digest_auth_get_username(connection);
- if (username == NULL)
- return respond_401(connection, MHD_NO);
- auth_get_password(username, password);
-
- ret = MHD_digest_auth_check(connection, REALM, username, password, 300);
- free(username);
-
- if (ret == MHD_INVALID_NONCE || ret == MHD_NO)
- return respond_401(connection, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
-
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;
}
return MHD_YES;
}
- if (ps->data == NULL || ps->data_size == 0)
+ if (ps->data == NULL || ps->data_size == 0 || ps->username[0] == 0)
+ return respond_JSON_Failure(connection);
+
+ const char *given_token = MHD_lookup_connection_value(connection, MHD_COOKIE_KIND, "auth");
+ if (!auth_check_token(ps->username, given_token))
return respond_JSON_Failure(connection);
- username = MHD_digest_auth_get_username(connection);
- struct blerg *b = blerg_open(username);
+ struct blerg *b = blerg_open(ps->username);
if (b == NULL)
return respond_JSON_Failure(connection);
if (blerg_store(b, ps->data, ps->data_size) == -1) {
blerg_close(b);
MHD_destroy_post_processor(ps->pp);
- free(username);
free(ps->data);
free(ps);
*ptr = NULL;