From: Jeroen van der Heijden Date: Tue, 2 Feb 2021 08:41:27 +0000 (+0100) Subject: Added flag to track whenever an api message is complete X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2^2~1^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=53e17b9524f9b58fabb6ac9676bd9be9ff98feaa;p=siridb-server.git Added flag to track whenever an api message is complete --- diff --git a/include/siri/api.h b/include/siri/api.h index cad41e58..5bdb4305 100644 --- a/include/siri/api.h +++ b/include/siri/api.h @@ -38,6 +38,12 @@ typedef enum E503_SERVICE_UNAVAILABLE } siri_api_header_t; +typedef enum +{ + SIRI_API_FLAG_SERVICE_AUTHENTICATED =1<<0, + SIRI_API_FLAG_MESSAGE_COMPLETED =1<<1, +} siri_api_flags_t; + typedef struct siri_api_request_s siri_api_request_t; typedef int (*on_state_cb_t)(siri_api_request_t * ar, const char * at, size_t n); @@ -63,7 +69,7 @@ struct siri_api_request_s siri_api_content_t content_type; siri_api_req_t request_type; service_request_t service_type; - _Bool service_authenticated; + siri_api_flags_t flags; http_parser parser; uv_write_t req; }; diff --git a/include/siri/version.h b/include/siri/version.h index 3be9a1d7..cfe52c53 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -15,7 +15,7 @@ * Note that debian alpha packages should use versions like this: * 2.0.34-0alpha0 */ -#define SIRIDB_VERSION_PRE_RELEASE "-alpha-5" +#define SIRIDB_VERSION_PRE_RELEASE "-alpha-6" #ifndef NDEBUG #define SIRIDB_VERSION_BUILD_RELEASE "+debug" diff --git a/src/siri/api.c b/src/siri/api.c index f5796368..6fc55e06 100644 --- a/src/siri/api.c +++ b/src/siri/api.c @@ -142,7 +142,7 @@ static void api__reset(siri_api_request_t * ar) ar->len = 0; ar->size = 0; ar->on_state = NULL; - ar->service_authenticated = 0; + ar->flags = 0; ar->request_type = SIRI_API_RT_NONE; ar->content_type = SIRI_API_CT_TEXT; } @@ -167,7 +167,8 @@ static void api__data_cb( goto done; } - api__reset(ar); + if (ar->flags & SIRI_API_FLAG_MESSAGE_COMPLETED) + api__reset(ar); buf->base[HTTP_MAX_HEADER_SIZE-1] = '\0'; @@ -381,8 +382,8 @@ static int api__on_authorization(siri_api_request_t * ar, const char * at, size_ { if (ar->request_type == SIRI_APT_RT_SERVICE) { - ar->service_authenticated = siri_service_account_check_basic( - &siri, at, n); + if (siri_service_account_check_basic(&siri, at, n)) + ar->flags |= SIRI_API_FLAG_SERVICE_AUTHENTICATED; return 0; } siridb_user_t * user; @@ -750,7 +751,7 @@ static int api__service_cb(http_parser * parser) break; } - if (!ar->service_authenticated) + if (~ar->flags & SIRI_API_FLAG_SERVICE_AUTHENTICATED) return api__plain_response(ar, E401_UNAUTHORIZED); switch (ar->content_type) @@ -810,6 +811,8 @@ static int api__message_complete_cb(http_parser * parser) { siri_api_request_t * ar = parser->data; + ar->flags |= SIRI_API_FLAG_MESSAGE_COMPLETED; + switch(ar->request_type) { case SIRI_API_RT_NONE: