Skip to content

Commit

Permalink
http1: register progress state names
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjulien committed Jan 27, 2025
1 parent ace169f commit 5a123a1
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/app-layer-htp.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,82 @@ static const char *HTTPGetFrameNameById(const uint8_t frame_id)
return name;
}

static SCEnumCharMap http_state_client_table[] = {
{
"request_not_started",
HTP_REQUEST_NOT_STARTED,
},
{
"request_line",
HTP_REQUEST_PROGRESS_LINE,
},
{
"request_headers",
HTP_REQUEST_PROGRESS_HEADERS,
},
{
"request_body",
HTP_REQUEST_PROGRESS_BODY,
},
{
"request_trailer",
HTP_REQUEST_PROGRESS_TRAILER,
},
{
"request_complete",
HTP_REQUEST_PROGRESS_COMPLETE,
},
{ NULL, -1 },
};

static SCEnumCharMap http_state_server_table[] = {
{
"response_not_started",
HTP_RESPONSE_NOT_STARTED,
},
{
"response_line",
HTP_RESPONSE_PROGRESS_LINE,
},
{
"response_headers",
HTP_RESPONSE_PROGRESS_HEADERS,
},
{
"response_body",
HTP_RESPONSE_PROGRESS_BODY,
},
{
"response_trailer",
HTP_RESPONSE_PROGRESS_TRAILER,
},
{
"response_complete",
HTP_RESPONSE_PROGRESS_COMPLETE,
},
{ NULL, -1 },
};

static int HtpStateGetStateIdByName(const char *name, const uint8_t direction)
{
SCEnumCharMap *map =
direction == STREAM_TOSERVER ? http_state_client_table : http_state_server_table;

int id = SCMapEnumNameToValue(name, map);
if (id < 0) {
return -1;
}
return id;
}

static const char *HtpStateGetStateNameById(const int id, const uint8_t direction)
{
SCEnumCharMap *map =
direction == STREAM_TOSERVER ? http_state_client_table : http_state_server_table;
const char *name = SCMapEnumValueToName(id, map);
return name;
}

static void *HTPStateGetTx(void *alstate, uint64_t tx_id);
static int HTPStateGetAlstateProgress(void *tx, uint8_t direction);
static uint64_t HTPStateGetTxCnt(void *alstate);
Expand Down Expand Up @@ -2873,6 +2949,9 @@ void RegisterHTPParsers(void)
AppLayerParserRegisterGetFrameFuncs(
IPPROTO_TCP, ALPROTO_HTTP1, HTTPGetFrameIdByName, HTTPGetFrameNameById);
/* app-layer-frame-documentation tag end: registering relevant callbacks */
AppLayerParserRegisterGetStateFuncs(
IPPROTO_TCP, ALPROTO_HTTP1, HtpStateGetStateIdByName, HtpStateGetStateNameById);

HTPConfigure();
} else {
SCLogInfo("Parser disabled for %s protocol. Protocol detection still on.", proto_name);
Expand Down

0 comments on commit 5a123a1

Please sign in to comment.