mirror of
https://github.com/openappsec/attachment.git
synced 2026-01-17 16:00:26 +03:00
Added response verdict popping from the queue and implemented PopFromNanoQueue.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "nano_blockpage.h"
|
#include "nano_blockpage.h"
|
||||||
#include "compression_utils.h"
|
#include "compression_utils.h"
|
||||||
#include "nano_compression.h"
|
#include "nano_compression.h"
|
||||||
|
#include "nano_attachment_io.h"
|
||||||
|
|
||||||
NanoAttachment *
|
NanoAttachment *
|
||||||
InitNanoAttachment(uint8_t attachment_type, int worker_id, int num_of_workers, int logging_fd)
|
InitNanoAttachment(uint8_t attachment_type, int worker_id, int num_of_workers, int logging_fd)
|
||||||
@@ -282,12 +283,24 @@ SessionID
|
|||||||
PopFromNanoQueue(NanoAttachment *attachment)
|
PopFromNanoQueue(NanoAttachment *attachment)
|
||||||
{
|
{
|
||||||
AttachmentVerdictResponse response;
|
AttachmentVerdictResponse response;
|
||||||
SessionID session_id = 0;
|
SessionID session_id;
|
||||||
NanoCommunicationResult res;
|
NanoCommunicationResult res;
|
||||||
// Pop from queue
|
|
||||||
|
|
||||||
|
response = PopResponseVerdictFromQueue(attachment);
|
||||||
|
if (response.session_id == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
session_id = response.session_id;
|
||||||
res = NanoAsyncAddResponse(attachment, session_id, &response);
|
res = NanoAsyncAddResponse(attachment, session_id, &response);
|
||||||
if (res != NANO_OK) {
|
if (res != NANO_OK) {
|
||||||
|
write_dbg(
|
||||||
|
attachment,
|
||||||
|
session_id,
|
||||||
|
DBG_LEVEL_WARNING,
|
||||||
|
"Failed to add async response for session ID: %d",
|
||||||
|
session_id
|
||||||
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1749,6 +1749,57 @@ nano_request_delayed_verdict(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AttachmentVerdictResponse
|
||||||
|
PopResponseVerdictFromQueue(NanoAttachment *attachment)
|
||||||
|
{
|
||||||
|
const char *reply_data;
|
||||||
|
uint16_t reply_size;
|
||||||
|
HttpReplyFromService *reply_p;
|
||||||
|
int pop_result;
|
||||||
|
SessionID session_id = 0;
|
||||||
|
|
||||||
|
if (attachment == NULL || attachment->nano_service_ipc == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isDataAvailable(attachment->nano_service_ipc)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pop_result = receiveData(attachment->nano_service_ipc, &reply_size, &reply_data);
|
||||||
|
if (pop_result < 0 || reply_data == NULL) {
|
||||||
|
write_dbg(
|
||||||
|
attachment,
|
||||||
|
0,
|
||||||
|
DBG_LEVEL_WARNING,
|
||||||
|
"Failed to receive data from queue"
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply_p = (HttpReplyFromService *)reply_data;
|
||||||
|
|
||||||
|
pop_result = popData(attachment->nano_service_ipc);
|
||||||
|
if (pop_result < 0) {
|
||||||
|
write_dbg(
|
||||||
|
attachment,
|
||||||
|
session_id,
|
||||||
|
DBG_LEVEL_WARNING,
|
||||||
|
"Failed to pop data from queue"
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.verdict = reply_p->verdict;
|
||||||
|
response.session_id = reply_p->session_id;
|
||||||
|
|
||||||
|
// TODO: Deal with data leak.
|
||||||
|
response.web_response_data = NULL;
|
||||||
|
response.modifications = NULL;
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nano_send_metric_data_sender(NanoAttachment *attachment)
|
nano_send_metric_data_sender(NanoAttachment *attachment)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -231,4 +231,18 @@ nano_request_delayed_verdict(
|
|||||||
void
|
void
|
||||||
nano_send_metric_data_sender(NanoAttachment *attachment);
|
nano_send_metric_data_sender(NanoAttachment *attachment);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Pops one element from the shared memory queue and returns its session ID.
|
||||||
|
///
|
||||||
|
/// This function checks if data is available in the queue, receives the data,
|
||||||
|
/// extracts the session ID from the HttpReplyFromService structure, and pops
|
||||||
|
/// the element from the queue.
|
||||||
|
///
|
||||||
|
/// @param attachment A pointer to a NanoAttachment structure representing the attachment to the nano service.
|
||||||
|
///
|
||||||
|
/// @return The session ID of the popped element, or 0 if the queue is empty or an error occurred.
|
||||||
|
///
|
||||||
|
AttachmentVerdictResponse
|
||||||
|
PopResponseVerdictFromQueue(NanoAttachment *attachment);
|
||||||
|
|
||||||
#endif // __NANO_ATTACHMENT_IO_H__
|
#endif // __NANO_ATTACHMENT_IO_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user