Modify backend to use new auth cookie format
[blerg.git] / http / http_blerg.c
index 85a1e5b..8a5b9a5 100644 (file)
@@ -294,7 +294,6 @@ struct MHD_Response *create_response_for_range(struct blerg *b, uint64_t from, u
        uint64_t record_count = blerg_get_record_count(b);
 
        if (from > to || from >= record_count || to >= record_count || to - from > 99) {
-               blerg_close(b);
                free(gs);
                return NULL;
        }
@@ -521,12 +520,12 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c
                if (as->username[0] == 0 || as->password[0] == 0)
                        return respond_JSON_Failure(connection);
 
-               if (!auth_login(as->username, as->password))
+               char *token = auth_login(as->username, as->password);
+               if (token == NULL)
                        return respond_JSON_Failure(connection);
 
                response = MHD_create_response_from_data(strlen(JSON_SUCCESS), JSON_SUCCESS, MHD_NO, MHD_NO);
 
-               char *token = auth_get_token(as->username);
                data = malloc(512);
                snprintf(data, 512, "auth=%s", token);
                MHD_add_response_header(response, "Set-Cookie", data);
@@ -548,7 +547,8 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c
 
                struct auth_state *as = (struct auth_state *) *ptr;
 
-               auth_logout(as->username);
+               const char *given_token = MHD_lookup_connection_value(connection, MHD_COOKIE_KIND, "auth");
+               auth_logout(as->username, given_token);
                return respond_JSON_Success(connection);
        } else if (strncmp(url, "/subscribe", 10) == 0 || strncmp(url, "/unsubscribe", 12) == 0) {
                ret = process_and_check_auth(connection, method, upload_data, upload_data_size, ptr);