mirror of
https://github.com/openappsec/attachment.git
synced 2026-01-17 16:00:26 +03:00
Implemented Async Request Start, Request Header, Request Body, Request End in async manner.
This commit is contained in:
@@ -1564,7 +1564,8 @@ nano_body_sender(
|
|||||||
HttpEventThreadCtx *ctx,
|
HttpEventThreadCtx *ctx,
|
||||||
AttachmentDataType body_type,
|
AttachmentDataType body_type,
|
||||||
uint32_t cur_request_id,
|
uint32_t cur_request_id,
|
||||||
unsigned int *num_messages_sent
|
unsigned int *num_messages_sent,
|
||||||
|
bool is_verdict_requested
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char *fragments[BODY_DATA_COUNT];
|
char *fragments[BODY_DATA_COUNT];
|
||||||
@@ -1626,6 +1627,7 @@ nano_body_sender(
|
|||||||
bodies->bodies_count
|
bodies->bodies_count
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (is_verdict_requested) {
|
||||||
ctx->res = service_reply_receiver(
|
ctx->res = service_reply_receiver(
|
||||||
attachment,
|
attachment,
|
||||||
ctx->session_data_p,
|
ctx->session_data_p,
|
||||||
@@ -1633,6 +1635,9 @@ nano_body_sender(
|
|||||||
&ctx->modifications,
|
&ctx->modifications,
|
||||||
body_type
|
body_type
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
ctx->res = NANO_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1641,7 +1646,8 @@ nano_end_transaction_sender(
|
|||||||
AttachmentDataType end_transaction_type,
|
AttachmentDataType end_transaction_type,
|
||||||
HttpEventThreadCtx *ctx,
|
HttpEventThreadCtx *ctx,
|
||||||
SessionID cur_request_id,
|
SessionID cur_request_id,
|
||||||
unsigned int *num_messages_sent
|
unsigned int *num_messages_sent,
|
||||||
|
bool is_verdict_requested
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char *fragments[END_TRANSACTION_DATA_COUNT];
|
char *fragments[END_TRANSACTION_DATA_COUNT];
|
||||||
@@ -1679,6 +1685,7 @@ nano_end_transaction_sender(
|
|||||||
|
|
||||||
*num_messages_sent += 1;
|
*num_messages_sent += 1;
|
||||||
|
|
||||||
|
if (is_verdict_requested) {
|
||||||
ctx->res = service_reply_receiver(
|
ctx->res = service_reply_receiver(
|
||||||
attachment,
|
attachment,
|
||||||
ctx->session_data_p,
|
ctx->session_data_p,
|
||||||
@@ -1686,6 +1693,9 @@ nano_end_transaction_sender(
|
|||||||
&ctx->modifications,
|
&ctx->modifications,
|
||||||
end_transaction_type
|
end_transaction_type
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
ctx->res = NANO_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ nano_header_sender(
|
|||||||
/// @param body_type Enum value indicating whether the body is a request or response body.
|
/// @param body_type Enum value indicating whether the body is a request or response body.
|
||||||
/// @param cur_request_id Current request ID for logging and tracking purposes.
|
/// @param cur_request_id Current request ID for logging and tracking purposes.
|
||||||
/// @param num_messages_sent Pointer to an unsigned int to track the number of messages sent.
|
/// @param num_messages_sent Pointer to an unsigned int to track the number of messages sent.
|
||||||
|
/// @param is_verdict_requested Boolean value indicating if a verdict is requested.
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
nano_body_sender(
|
nano_body_sender(
|
||||||
@@ -181,7 +182,8 @@ nano_body_sender(
|
|||||||
HttpEventThreadCtx *ctx,
|
HttpEventThreadCtx *ctx,
|
||||||
AttachmentDataType body_type,
|
AttachmentDataType body_type,
|
||||||
uint32_t cur_request_id,
|
uint32_t cur_request_id,
|
||||||
unsigned int *num_messages_sent
|
unsigned int *num_messages_sent,
|
||||||
|
bool is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -192,6 +194,7 @@ nano_body_sender(
|
|||||||
/// @param ctx Pointer to the HttpEventThreadCtx struct containing the context of the current thread.
|
/// @param ctx Pointer to the HttpEventThreadCtx struct containing the context of the current thread.
|
||||||
/// @param cur_request_id The ID of the current request.
|
/// @param cur_request_id The ID of the current request.
|
||||||
/// @param num_messages_sent Pointer to an unsigned integer to store the number of messages sent.
|
/// @param num_messages_sent Pointer to an unsigned integer to store the number of messages sent.
|
||||||
|
/// @param is_verdict_requested Boolean value indicating if a verdict is requested.
|
||||||
/// @return NANO_OK if the end transaction event was sent successfully, NANO_ERROR otherwise.
|
/// @return NANO_OK if the end transaction event was sent successfully, NANO_ERROR otherwise.
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
@@ -200,7 +203,8 @@ nano_end_transaction_sender(
|
|||||||
AttachmentDataType end_transaction_type,
|
AttachmentDataType end_transaction_type,
|
||||||
HttpEventThreadCtx *ctx,
|
HttpEventThreadCtx *ctx,
|
||||||
SessionID cur_request_id,
|
SessionID cur_request_id,
|
||||||
unsigned int *num_messages_sent
|
unsigned int *num_messages_sent,
|
||||||
|
bool is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "nano_attachment_common.h"
|
#include "nano_attachment_common.h"
|
||||||
#include "nano_initializer.h"
|
#include "nano_initializer.h"
|
||||||
|
#include "nano_attachment_io.h"
|
||||||
|
#include "nano_attachment_sender_thread.h"
|
||||||
|
|
||||||
NanoCommunicationResult
|
NanoCommunicationResult
|
||||||
RegistrationCommSocketAsyncImpl(
|
RegistrationCommSocketAsyncImpl(
|
||||||
@@ -32,9 +34,33 @@ SendRequestFilterAsyncImpl(
|
|||||||
HttpRequestFilterData *start_data
|
HttpRequestFilterData *start_data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(void)attachment;
|
NanoCommunicationResult res;
|
||||||
(void)session_data_p;
|
|
||||||
(void)start_data;
|
if (start_data == NULL) {
|
||||||
|
return NANO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_data->meta_data != NULL) {
|
||||||
|
res = SendMetadataAsyncImpl(attachment, session_data_p, start_data->meta_data);
|
||||||
|
if (res != NANO_OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_data->req_headers != NULL) {
|
||||||
|
res = SendRequestHeadersAsyncImpl(attachment, session_data_p, start_data->req_headers);
|
||||||
|
if (res != NANO_OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!start_data->contains_body) {
|
||||||
|
res = SendRequestEndAsyncImpl(attachment, session_data_p);
|
||||||
|
if (res != NANO_OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NANO_OK;
|
return NANO_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +71,30 @@ SendMetadataAsyncImpl(
|
|||||||
HttpMetaData *metadata
|
HttpMetaData *metadata
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(void)attachment;
|
HttpEventThreadCtx ctx;
|
||||||
(void)session_data_p;
|
bool is_verdict_requested = false;
|
||||||
(void)metadata;
|
|
||||||
return NANO_OK;
|
if (attachment == NULL || session_data_p == NULL || metadata == NULL) {
|
||||||
|
return NANO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.attachment = attachment;
|
||||||
|
ctx.data = NULL;
|
||||||
|
ctx.session_data_p = session_data_p;
|
||||||
|
ctx.res = NANO_OK;
|
||||||
|
ctx.web_response_data = NULL;
|
||||||
|
ctx.modifications = NULL;
|
||||||
|
|
||||||
|
nano_metadata_sender(
|
||||||
|
attachment,
|
||||||
|
metadata,
|
||||||
|
&ctx,
|
||||||
|
session_data_p->session_id,
|
||||||
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
|
);
|
||||||
|
|
||||||
|
return ctx.res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NanoCommunicationResult
|
NanoCommunicationResult
|
||||||
@@ -58,10 +104,31 @@ SendRequestHeadersAsyncImpl(
|
|||||||
HttpHeaders *headers
|
HttpHeaders *headers
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(void)attachment;
|
HttpEventThreadCtx ctx;
|
||||||
(void)session_data_p;
|
bool is_verdict_requested = false;
|
||||||
(void)headers;
|
|
||||||
return NANO_OK;
|
if (attachment == NULL || session_data_p == NULL || headers == NULL) {
|
||||||
|
return NANO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.attachment = attachment;
|
||||||
|
ctx.data = NULL;
|
||||||
|
ctx.session_data_p = session_data_p;
|
||||||
|
ctx.res = NANO_OK;
|
||||||
|
ctx.web_response_data = NULL;
|
||||||
|
ctx.modifications = NULL;
|
||||||
|
|
||||||
|
nano_header_sender(
|
||||||
|
attachment,
|
||||||
|
headers,
|
||||||
|
&ctx,
|
||||||
|
REQUEST_HEADER,
|
||||||
|
session_data_p->session_id,
|
||||||
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
|
);
|
||||||
|
|
||||||
|
return ctx.res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NanoCommunicationResult
|
NanoCommunicationResult
|
||||||
@@ -84,10 +151,30 @@ SendRequestBodyAsyncImpl(
|
|||||||
NanoHttpBody *bodies
|
NanoHttpBody *bodies
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(void)attachment;
|
HttpEventThreadCtx ctx;
|
||||||
(void)session_data_p;
|
|
||||||
(void)bodies;
|
if (attachment == NULL || session_data_p == NULL || bodies == NULL) {
|
||||||
return NANO_OK;
|
return NANO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.attachment = attachment;
|
||||||
|
ctx.data = NULL;
|
||||||
|
ctx.session_data_p = session_data_p;
|
||||||
|
ctx.res = NANO_OK;
|
||||||
|
ctx.web_response_data = NULL;
|
||||||
|
ctx.modifications = NULL;
|
||||||
|
|
||||||
|
nano_body_sender(
|
||||||
|
attachment,
|
||||||
|
bodies,
|
||||||
|
&ctx,
|
||||||
|
REQUEST_BODY,
|
||||||
|
session_data_p->session_id,
|
||||||
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
return ctx.res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NanoCommunicationResult
|
NanoCommunicationResult
|
||||||
@@ -109,9 +196,29 @@ SendRequestEndAsyncImpl(
|
|||||||
HttpSessionData *session_data_p
|
HttpSessionData *session_data_p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(void)attachment;
|
HttpEventThreadCtx ctx;
|
||||||
(void)session_data_p;
|
|
||||||
return NANO_OK;
|
if (attachment == NULL || session_data_p == NULL) {
|
||||||
|
return NANO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.attachment = attachment;
|
||||||
|
ctx.data = NULL;
|
||||||
|
ctx.session_data_p = session_data_p;
|
||||||
|
ctx.res = NANO_OK;
|
||||||
|
ctx.web_response_data = NULL;
|
||||||
|
ctx.modifications = NULL;
|
||||||
|
|
||||||
|
nano_end_transaction_sender(
|
||||||
|
attachment,
|
||||||
|
REQUEST_END,
|
||||||
|
&ctx,
|
||||||
|
session_data_p->session_id,
|
||||||
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
return ctx.res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NanoCommunicationResult
|
NanoCommunicationResult
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ SendRequestFilterThread(void *_ctx)
|
|||||||
REQUEST_END,
|
REQUEST_END,
|
||||||
ctx,
|
ctx,
|
||||||
session_data_p->session_id,
|
session_data_p->session_id,
|
||||||
&session_data_p->remaining_messages_to_reply
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +233,7 @@ SendRequestBodyThread(void *_ctx)
|
|||||||
NanoHttpBody *bodies = (NanoHttpBody*)ctx->data->data;
|
NanoHttpBody *bodies = (NanoHttpBody*)ctx->data->data;
|
||||||
NanoAttachment *attachment = ctx->attachment;
|
NanoAttachment *attachment = ctx->attachment;
|
||||||
HttpSessionData *session_data_p = ctx->session_data_p;
|
HttpSessionData *session_data_p = ctx->session_data_p;
|
||||||
|
bool is_verdict_requested = true;
|
||||||
|
|
||||||
nano_body_sender(
|
nano_body_sender(
|
||||||
attachment,
|
attachment,
|
||||||
@@ -239,7 +241,8 @@ SendRequestBodyThread(void *_ctx)
|
|||||||
ctx,
|
ctx,
|
||||||
REQUEST_BODY,
|
REQUEST_BODY,
|
||||||
session_data_p->session_id,
|
session_data_p->session_id,
|
||||||
&session_data_p->remaining_messages_to_reply
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -252,6 +255,7 @@ SendResponseBodyThread(void *_ctx)
|
|||||||
NanoHttpBody *bodies = (NanoHttpBody*)ctx->data->data;
|
NanoHttpBody *bodies = (NanoHttpBody*)ctx->data->data;
|
||||||
NanoAttachment *attachment = ctx->attachment;
|
NanoAttachment *attachment = ctx->attachment;
|
||||||
HttpSessionData *session_data_p = ctx->session_data_p;
|
HttpSessionData *session_data_p = ctx->session_data_p;
|
||||||
|
bool is_verdict_requested = true;
|
||||||
|
|
||||||
nano_body_sender(
|
nano_body_sender(
|
||||||
attachment,
|
attachment,
|
||||||
@@ -259,7 +263,8 @@ SendResponseBodyThread(void *_ctx)
|
|||||||
ctx,
|
ctx,
|
||||||
RESPONSE_BODY,
|
RESPONSE_BODY,
|
||||||
session_data_p->session_id,
|
session_data_p->session_id,
|
||||||
&session_data_p->remaining_messages_to_reply
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -271,13 +276,15 @@ SendRequestEndThread(void *_ctx)
|
|||||||
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)_ctx;
|
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)_ctx;
|
||||||
NanoAttachment *attachment = ctx->attachment;
|
NanoAttachment *attachment = ctx->attachment;
|
||||||
HttpSessionData *session_data_p = ctx->session_data_p;
|
HttpSessionData *session_data_p = ctx->session_data_p;
|
||||||
|
bool is_verdict_requested = true;
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
nano_end_transaction_sender(
|
||||||
attachment,
|
attachment,
|
||||||
REQUEST_END,
|
REQUEST_END,
|
||||||
ctx,
|
ctx,
|
||||||
session_data_p->session_id,
|
session_data_p->session_id,
|
||||||
&session_data_p->remaining_messages_to_reply
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -289,13 +296,15 @@ SendResponseEndThread(void *_ctx)
|
|||||||
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)_ctx;
|
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)_ctx;
|
||||||
NanoAttachment *attachment = ctx->attachment;
|
NanoAttachment *attachment = ctx->attachment;
|
||||||
HttpSessionData *session_data_p = ctx->session_data_p;
|
HttpSessionData *session_data_p = ctx->session_data_p;
|
||||||
|
bool is_verdict_requested = true;
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
nano_end_transaction_sender(
|
||||||
attachment,
|
attachment,
|
||||||
RESPONSE_END,
|
RESPONSE_END,
|
||||||
ctx,
|
ctx,
|
||||||
session_data_p->session_id,
|
session_data_p->session_id,
|
||||||
&session_data_p->remaining_messages_to_reply
|
&session_data_p->remaining_messages_to_reply,
|
||||||
|
is_verdict_requested
|
||||||
);
|
);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user