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);
siri_api_content_t content_type;
siri_api_req_t request_type;
service_request_t service_type;
- siri_api_flags_t flags;
+ _Bool service_authenticated;
http_parser parser;
uv_write_t req;
};
ar->len = 0;
ar->size = 0;
ar->on_state = NULL;
- ar->flags = 0;
+ ar->service_authenticated = 0;
ar->request_type = SIRI_API_RT_NONE;
ar->content_type = SIRI_API_CT_TEXT;
}
goto done;
}
- if (ar->flags & SIRI_API_FLAG_MESSAGE_COMPLETED)
- api__reset(ar);
-
buf->base[HTTP_MAX_HEADER_SIZE-1] = '\0';
parsed = http_parser_execute(
{
if (ar->request_type == SIRI_APT_RT_SERVICE)
{
- if (siri_service_account_check_basic(&siri, at, n))
- ar->flags |= SIRI_API_FLAG_SERVICE_AUTHENTICATED;
+ ar->service_authenticated = \
+ siri_service_account_check_basic(&siri, at, n);
return 0;
}
siridb_user_t * user;
"error writing HTTP API response: `%s`",
uv_strerror(status));
+ /* reset the API to support multiple request on the same connection */
+ api__reset(ar);
+
/* Resume parsing */
http_parser_pause(&ar->parser, 0);
break;
}
- if (~ar->flags & SIRI_API_FLAG_SERVICE_AUTHENTICATED)
+ if (!ar->service_authenticated)
return api__plain_response(ar, E401_UNAUTHORIZED);
switch (ar->content_type)
{
siri_api_request_t * ar = parser->data;
- ar->flags |= SIRI_API_FLAG_MESSAGE_COMPLETED;
-
- /* Pause the HTTP parser */
+ /* Pause the HTTP parser;
+ * This is required since SiriDB will handle queries and inserts
+ * asynchronously and SiriDB must be sure that the request does not
+ * change during this time. It is also important to write the responses
+ * in order and this solves both issues. */
http_parser_pause(&ar->parser, 1);
switch(ar->request_type)
api__write_cb(req, status);
}
-
-
static int api__close_resp(
siri_api_request_t * ar,
const siri_api_header_t ht,