mirror of
https://github.com/openappsec/attachment.git
synced 2026-01-17 16:00:26 +03:00
nano attachment add
This commit is contained in:
@@ -195,7 +195,7 @@ uint16_t GetResponseCode(
|
||||
);
|
||||
|
||||
///
|
||||
/// @brief Retrieves the redict page data for a response.
|
||||
/// @brief Retrieves the redirect page data for a response.
|
||||
///
|
||||
/// @param attachment The NanoAttachment object associated with the session.
|
||||
/// @param session_data The HttpSessionData object representing the session.
|
||||
@@ -209,6 +209,21 @@ RedirectPageData GetRedirectPage(
|
||||
AttachmentVerdictResponse *response
|
||||
);
|
||||
|
||||
///
|
||||
/// @brief Retrieves the custom response with headers data.
|
||||
///
|
||||
/// @param attachment The NanoAttachment object associated with the session.
|
||||
/// @param session_data The HttpSessionData object representing the session.
|
||||
/// @param response The AttachmentVerdictResponse object containing the verdict.
|
||||
///
|
||||
/// @return CustomResponseWithHeaders structure containing response code, headers, and body.
|
||||
///
|
||||
CustomResponseWithHeaders * GetCustomResponseWithHeaders(
|
||||
NanoAttachment *attachment,
|
||||
HttpSessionData *session_data,
|
||||
AttachmentVerdictResponse *response
|
||||
);
|
||||
|
||||
///
|
||||
/// @brief Free allocated resources of an AttachmentVerdictResponse.
|
||||
///
|
||||
|
||||
@@ -21,6 +21,8 @@ typedef int64_t NanoHttpCpInjectPos;
|
||||
#define MAX_NGINX_UID_LEN 32
|
||||
#define MAX_SHARED_MEM_PATH_LEN 128
|
||||
#define NUM_OF_NGINX_IPC_ELEMENTS 200
|
||||
// The maximum is 2048, but we limit it to 2000 to avoid Alpine memory page layout issues (SIGBUS)
|
||||
#define NUM_OF_NGINX_IPC_ELEMENTS_ASYNC 2000
|
||||
#define DEFAULT_KEEP_ALIVE_INTERVAL_MSEC 300000u
|
||||
#define SHARED_MEM_PATH "/dev/shm/"
|
||||
#define SHARED_REGISTRATION_SIGNAL_PATH SHARED_MEM_PATH "check-point/cp-nano-attachment-registration"
|
||||
@@ -49,6 +51,7 @@ typedef enum NanoWebResponseType
|
||||
CUSTOM_WEB_BLOCK_PAGE_RESPONSE,
|
||||
RESPONSE_CODE_ONLY,
|
||||
REDIRECT_WEB_RESPONSE,
|
||||
CUSTOM_RESPONSE_WITH_HEADERS,
|
||||
|
||||
NO_WEB_RESPONSE
|
||||
} NanoWebResponseType;
|
||||
@@ -220,18 +223,6 @@ typedef enum ServiceVerdict
|
||||
TRAFFIC_VERDICT_CUSTOM_RESPONSE
|
||||
} ServiceVerdict;
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef enum class AttachmentContentType
|
||||
#else
|
||||
typedef enum AttachmentContentType
|
||||
#endif
|
||||
{
|
||||
CONTENT_TYPE_APPLICATION_JSON,
|
||||
CONTENT_TYPE_TEXT_HTML,
|
||||
CONTENT_TYPE_TEXT_PLAIN,
|
||||
CONTENT_TYPE_OTHER
|
||||
} AttachmentContentType;
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef enum class AttachmentVerdict
|
||||
#else
|
||||
@@ -285,12 +276,14 @@ typedef struct __attribute__((__packed__)) HttpWebResponseData {
|
||||
} response_data;
|
||||
} HttpWebResponseData;
|
||||
|
||||
typedef struct __attribute__((__packed__)) HttpJsonResponseData {
|
||||
// Custom response structure with dynamic headers
|
||||
typedef struct __attribute__((__packed__)) HttpCustomResponseData {
|
||||
uint16_t response_code;
|
||||
uint16_t body_size;
|
||||
AttachmentContentType content_type;
|
||||
char body[0];
|
||||
} HttpJsonResponseData;
|
||||
uint8_t headers_count;
|
||||
char data[0]; // headers followed by body
|
||||
// Memory layout: [HttpHeaderPackedData1][HttpHeaderPackedData2]...[body_data]
|
||||
} HttpCustomResponseData;
|
||||
|
||||
typedef struct {
|
||||
size_t len;
|
||||
@@ -307,6 +300,21 @@ typedef struct RedirectData {
|
||||
unsigned char redirect_location[REDIRECT_RESPONSE_LOCATION_SIZE];
|
||||
} RedirectData;
|
||||
|
||||
typedef struct CustomResponseHeaderData {
|
||||
uint16_t key_size;
|
||||
uint16_t value_size;
|
||||
char *key;
|
||||
char *value;
|
||||
} CustomResponseHeaderData;
|
||||
|
||||
typedef struct CustomResponseWithHeaders {
|
||||
uint16_t response_code;
|
||||
uint16_t body_size;
|
||||
uint8_t headers_count;
|
||||
CustomResponseHeaderData *headers;
|
||||
char *body;
|
||||
} CustomResponseWithHeaders;
|
||||
|
||||
typedef struct WebResponseData {
|
||||
NanoWebResponseType web_response_type;
|
||||
unsigned char uuid[UUID_SIZE];
|
||||
@@ -416,6 +424,13 @@ typedef struct HttpHeaderData {
|
||||
nano_str_t value;
|
||||
} HttpHeaderData;
|
||||
|
||||
// Packed header data structure for dynamic headers in custom responses (IPC transfer)
|
||||
typedef struct __attribute__((__packed__)) HttpHeaderPackedData {
|
||||
uint16_t key_size;
|
||||
uint16_t value_size;
|
||||
char data[0]; // key followed by value
|
||||
} HttpHeaderPackedData;
|
||||
|
||||
typedef struct HttpHeaders {
|
||||
HttpHeaderData *data;
|
||||
size_t headers_count;
|
||||
@@ -448,7 +463,7 @@ typedef struct AttachmentData {
|
||||
typedef union __attribute__((__packed__)) HttpModifyData {
|
||||
HttpInjectData inject_data[0];
|
||||
HttpWebResponseData web_response_data[0];
|
||||
HttpJsonResponseData json_response_data[0];
|
||||
HttpCustomResponseData custom_response_data[0];
|
||||
} HttpModifyData;
|
||||
|
||||
typedef struct __attribute__((__packed__)) HttpReplyFromService {
|
||||
|
||||
Reference in New Issue
Block a user