summaryrefslogtreecommitdiff
path: root/src/http_decoder/http_decoder.c
diff options
context:
space:
mode:
authorliuwentan <[email protected]>2023-12-28 18:31:44 +0800
committerliuwentan <[email protected]>2023-12-28 18:31:44 +0800
commita9afd24fafcf867b6fa272e6651c41dac5407567 (patch)
tree5d83d3480b55cf2358f99005e452c7a9259102a0 /src/http_decoder/http_decoder.c
parent9354f4ca90570739aab9a0d61a91cb8822565440 (diff)
[PATCH]bugfix for compressed body
Diffstat (limited to 'src/http_decoder/http_decoder.c')
-rw-r--r--src/http_decoder/http_decoder.c129
1 files changed, 72 insertions, 57 deletions
diff --git a/src/http_decoder/http_decoder.c b/src/http_decoder/http_decoder.c
index 584d53e..c2d1c55 100644
--- a/src/http_decoder/http_decoder.c
+++ b/src/http_decoder/http_decoder.c
@@ -23,9 +23,9 @@
#define HTTP_IDENTIFY_LEN 16
#define HTTP_DECODER_RESULT_QUEUE_SIZE 16
-#define HTTP_DECODER_IS_CACHE_LINE 1
-#define HTTP_DECODER_IS_CACHE_BODY 1
-#define HTTP_DECODER_IS_CACHE_HEADER 1
+#define HD_IS_CACHE_LINE 1
+#define HD_IS_CACHE_BODY 1
+#define HD_IS_CACHE_HEADER 1
const char *http_decoder_topic = "HTTP_DECODER_MESSAGE";
@@ -330,78 +330,89 @@ static int http_protocol_identify(const char *data, size_t data_len)
int http_decoder_entry(struct session *sess, int events, const struct packet *pkt, void *cb_arg)
{
- int ret = 0;
- size_t payload_len = 0;
struct http_decoder_context *ctx = (struct http_decoder_context *)cb_arg;
- struct http_decoder_result_queue *queue = NULL;
+ size_t payload_len = 0;
+ uint64_t inner_flag = 0;
+
+ int ret = session_is_inner_most(sess, &inner_flag);
+ if (0 == ret) {
+ return 0;
+ }
+
+ struct http_decoder_result_queue *queue = session_get_ex_data(sess, ctx->ex_data_idx);;
+
+ const char *tmp_payload = session_get0_current_payload(sess, &payload_len);
+
+ if (events & SESS_EV_CLOSING) {
+ if (queue != NULL) {
+ http_decoder_result_queue_free(queue);
+ session_set_ex_data(sess, ctx->ex_data_idx, NULL);
+ }
- if (events & SESS_EV_TCP) {
- const char *payload = session_get0_current_payload(sess, &payload_len);
- if (NULL == payload || 0 == payload_len) {
- return 0;
+ return 0;
+ }
+
+ const char *payload = session_get0_current_payload(sess, &payload_len);
+ if (events & SESS_EV_OPENING) {
+ if (queue != NULL) {
+ fprintf(stderr, "http_decoder_result_queue should be null for new session\n");
+ return -1;
}
- queue = session_get_ex_data(sess, ctx->ex_data_idx);
- if (NULL == queue) {
- size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN
- ? HTTP_IDENTIFY_LEN
- : payload_len;
+ //If not http, ignore this session
+ if (payload_len > 0) {
+ size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN ? HTTP_IDENTIFY_LEN : payload_len;
ret = http_protocol_identify(payload, http_identify_len);
if (ret < 0) {
// ignore this session's event
- struct session_event *s_event =
- session_get_intrinsic_event(sess, ctx->plugin_id);
- session_event_assign(s_event, ctx->st, sess, 0,
- http_decoder_entry, ctx);
+ struct session_event *s_event = session_get_intrinsic_event(sess, ctx->plugin_id);
+ session_event_assign(s_event, ctx->st, sess, 0, http_decoder_entry, ctx);
return 0;
}
-
- queue = http_decoder_result_queue_new(HTTP_DECODER_RESULT_QUEUE_SIZE);
- queue->ref_session = sess;
- session_set_ex_data(sess, ctx->ex_data_idx, queue);
}
- int dir = packet_get_direction(pkt);
- if (dir < 0) {
- return -1;
- }
+ queue = http_decoder_result_queue_new(HTTP_DECODER_RESULT_QUEUE_SIZE);
+ queue->ref_session = sess;
+ session_set_ex_data(sess, ctx->ex_data_idx, queue);
+ }
- // printf("\n-------------------------------------------\n");
- // for (size_t i = 0; i < payload_len; i++) {
- // printf(" %x", payload[i]);
- // }
- // printf("\n-------------------------------------------\n");
+ if (0 == payload_len) {
+ return 0;
+ }
- if (NULL == ctx->decoder) {
- ctx->decoder = http_decoder_new(http_event_handler, HTTP_DECODER_IS_CACHE_LINE,
- HTTP_DECODER_IS_CACHE_HEADER, HTTP_DECODER_IS_CACHE_BODY);
- }
+ int dir = packet_get_direction(pkt);
+ if (dir < 0) {
+ return -1;
+ }
- struct http_decoder_half *cur_half = NULL;
- if (dir == PACKET_DIRECTION_C2S) {
- cur_half = ctx->decoder->c2s_half;
- } else {
- cur_half = ctx->decoder->s2c_half;
- }
+ // printf("\n-------------------------------------------\n");
+ // for (size_t i = 0; i < payload_len; i++) {
+ // printf(" %x", payload[i]);
+ // }
+ // printf("\n-------------------------------------------\n");
- ctx->http_ev_ctx->topic_id = ctx->topic_id;
- ctx->http_ev_ctx->ref_queue = queue;
- ctx->http_ev_ctx->ref_session = sess;
+ if (NULL == ctx->decoder) {
+ ctx->decoder = http_decoder_new(http_event_handler, HD_IS_CACHE_LINE,
+ HD_IS_CACHE_HEADER, 0);
+ }
- ret = http_decoder_half_parse(cur_half, ctx->http_ev_ctx, payload, payload_len);
- if (ret < 0) {
- if (dir == PACKET_DIRECTION_C2S) {
- http_decoder_result_queue_pop(queue, queue->req_index);
- } else {
- http_decoder_result_queue_pop(queue, queue->res_index);
- }
- }
+ struct http_decoder_half *cur_half = NULL;
+ if (dir == PACKET_DIRECTION_C2S) {
+ cur_half = ctx->decoder->c2s_half;
+ } else {
+ cur_half = ctx->decoder->s2c_half;
}
- if (events & SESS_EV_CLOSING) {
- if (queue != NULL) {
- http_decoder_result_queue_free(queue);
- session_set_ex_data(sess, ctx->ex_data_idx, NULL);
+ ctx->http_ev_ctx->topic_id = ctx->topic_id;
+ ctx->http_ev_ctx->ref_queue = queue;
+ ctx->http_ev_ctx->ref_session = sess;
+
+ ret = http_decoder_half_parse(cur_half, ctx->http_ev_ctx, payload, payload_len);
+ if (ret < 0) {
+ if (dir == PACKET_DIRECTION_C2S) {
+ http_decoder_result_queue_pop(queue, queue->req_index);
+ } else {
+ http_decoder_result_queue_pop(queue, queue->res_index);
}
}
@@ -468,6 +479,10 @@ void http_decoder_exit(void *decoder_ctx)
ctx->decoder = NULL;
}
+ if (ctx->topic_id >= 0) {
+ session_mq_destroy_topic(ctx->st, ctx->topic_id);
+ }
+
FREE(decoder_ctx);
}