Added flag to track whenever an api message is complete
authorJeroen van der Heijden <jeroen@transceptor.technology>
Tue, 2 Feb 2021 08:41:27 +0000 (09:41 +0100)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Tue, 2 Feb 2021 08:41:27 +0000 (09:41 +0100)
include/siri/api.h
include/siri/version.h
src/siri/api.c

index cad41e58ca1a1af03304d7d0dc0b4da9a4fddc09..5bdb4305f07c5155f1c31c41694352af2bb15935 100644 (file)
@@ -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;
 };
index 3be9a1d773155f115d15c0fda990bf77b2e4dee4..cfe52c5337bdf0affc23000754f75b3455ed5526 100644 (file)
@@ -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"
index f579636852e5d7970c00aab95a8cd977766897a0..6fc55e06396b5f7add72a1ac2f5347145507e922 100644 (file)
@@ -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: