diff options
Diffstat (limited to 'decoders/http/http_decoder.cpp')
| -rw-r--r-- | decoders/http/http_decoder.cpp | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/decoders/http/http_decoder.cpp b/decoders/http/http_decoder.cpp index 218c508..f1c65f7 100644 --- a/decoders/http/http_decoder.cpp +++ b/decoders/http/http_decoder.cpp @@ -3,7 +3,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include "http_decoder_inc.h" +#include "http_decoder_private.h" #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -123,7 +123,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d /* llhttp always call on_message_begin() even if llhttp_execute() error!!! */ msg = http_message_new(HTTP_TRANSACTION_START, queue, queue_idx, HTTP_REQUEST); session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_NEW, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_NEW, 1); break; case HTTP_EVENT_REQ_LINE: msg = http_message_new(HTTP_MESSAGE_REQ_LINE, queue, queue_idx, HTTP_REQUEST); @@ -131,7 +131,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d if (httpd_tunnel_identify(httpd_env, FLOW_DIRECTION_C2S, half_data)) { exdata->tunnel_state = HTTP_TUN_C2S_HDR_START; - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TUNNEL, 1); + // http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TUNNEL, 1); } if (httpd_is_tunnel_session(httpd_env, exdata)) { @@ -157,11 +157,11 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); int tot_c2s_headers = http_half_data_get_total_parsed_header_count(half_data); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_HEADERS_C2S, tot_c2s_headers); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_HEADERS, tot_c2s_headers); hstring tmp_url = {}; http_half_data_get_url(half_data, &tmp_url); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_URL_BYTES, tmp_url.iov_len); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_URL_BYTES, tmp_url.iov_len); } break; case HTTP_EVENT_REQ_BODY_BEGIN: @@ -176,9 +176,10 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d http_half_get_lastest_decompress_buffer(half_data, &decompress_body); msg = http_body_message_new(HTTP_MESSAGE_REQ_BODY, queue, queue_idx, HTTP_REQUEST, &raw_body, &decompress_body); session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); - if(decompress_body.iov_base != NULL){ - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ZIP_BYTES, raw_body.iov_len); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_UNZIP_BYTES, decompress_body.iov_len); + if (decompress_body.iov_base != NULL) + { + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ZIP_BYTES, raw_body.iov_len); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_UNZIP_BYTES, decompress_body.iov_len); } } break; @@ -194,8 +195,8 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d { msg = http_message_new(HTTP_TRANSACTION_END, queue, queue_idx, HTTP_REQUEST); session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_FREE, 1); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_FREE, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ASYMMETRY_TRANSACTION, 1); } if (httpd_is_tunnel_session(httpd_env, exdata)) { @@ -285,7 +286,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); int tot_s2c_headers = http_half_data_get_total_parsed_header_count(half_data); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_HEADERS_S2C, tot_s2c_headers); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_HEADERS, tot_s2c_headers); if (httpd_is_tunnel_session(httpd_env, exdata)) { @@ -304,13 +305,14 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d hstring raw_body = {}; http_decoder_half_data_get_raw_body(half_data, &raw_body); hstring decompress_body = {}; - http_half_get_lastest_decompress_buffer(half_data, &decompress_body); + http_half_get_lastest_decompress_buffer(half_data, &decompress_body); msg = http_body_message_new(HTTP_MESSAGE_RES_BODY, queue, queue_idx, HTTP_RESPONSE, &raw_body, &decompress_body); session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); - if(decompress_body.iov_base != NULL){ - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ZIP_BYTES, raw_body.iov_len); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_UNZIP_BYTES, decompress_body.iov_len); - } + if (decompress_body.iov_base != NULL) + { + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ZIP_BYTES, raw_body.iov_len); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_UNZIP_BYTES, decompress_body.iov_len); + } } break; case HTTP_EVENT_RES_BODY_END: @@ -320,11 +322,11 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d case HTTP_EVENT_RES_END: msg = http_message_new(HTTP_TRANSACTION_END, queue, queue_idx, HTTP_RESPONSE); session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_FREE, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_FREE, 1); session_is_symmetric(ev_ctx->ref_session, &flow_flag); if (SESSION_SEEN_S2C_FLOW == flow_flag) { - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ASYMMETRY_TRANSACTION, 1); } http_half_update_state(half_data, event); @@ -604,7 +606,7 @@ static struct http_decoder_exdata *httpd_session_exdata_new(struct session *sess httpd_env, req_start_seq, res_start_seq); // exdata->sub_topic_id = sub_topic_id; int thread_id = stellar_get_current_thread_index(); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_SESSION_NEW, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_SESSION_NEW, 1); return exdata; } @@ -645,13 +647,13 @@ extern "C" if (SESSION_SEEN_C2S_FLOW == flow_flag) { - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_SESSION_C2S, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ASYMMETRY_SESSION, 1); } else if (SESSION_SEEN_S2C_FLOW == flow_flag) { - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_SESSION_S2C, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ASYMMETRY_SESSION, 1); } - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_SESSION_FREE, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_SESSION_FREE, 1); } static void http_decoder_execute(struct session *sess, struct http_decoder_env *httpd_env, http_decoder_exdata *exdata, const char *payload, uint16_t payload_len) @@ -669,21 +671,21 @@ extern "C" if (FLOW_DIRECTION_C2S == sess_dir) { cur_half = exdata->decoder->c2s_half; - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_BYTES_C2S, payload_len); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TCP_SEG_C2S, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_BYTES, payload_len); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_TCP_SEG, 1); } else { cur_half = exdata->decoder->s2c_half; - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_BYTES_S2C, payload_len); - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TCP_SEG_S2C, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_BYTES, payload_len); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_TCP_SEG, 1); } http_decoder_half_reinit(cur_half, exdata->queue, exdata->mempool, sess); int ret = http_decoder_half_parse(httpd_env->hd_cfg.proxy_enable, cur_half, payload, payload_len); if (ret < 0) { - http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_PARSE_ERR, 1); + http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_STAT_PARSE_ERR, 1); stellar_session_plugin_dettach_current_session(sess); } } @@ -742,7 +744,7 @@ extern "C" if (NULL == exdata) { session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id); - http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1); + http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTP_STAT_PARSE_ERR, 1); return; } break; @@ -750,7 +752,7 @@ extern "C" case HTTP_TUNNEL_CLOSING: if (NULL == exdata) { - http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1); + http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTP_STAT_PARSE_ERR, 1); return; } if (exdata->in_tunnel_is_http) @@ -1086,23 +1088,20 @@ extern "C" } /** * @brief If the body hasn't been compressed, same as http_message_raw_body_get0(). - * - */ - - if (HTTP_MESSAGE_REQ_BODY_START == msg->type - || HTTP_MESSAGE_REQ_BODY == msg->type - || HTTP_MESSAGE_REQ_BODY_END == msg->type) + * + */ + + if (HTTP_MESSAGE_REQ_BODY_START == msg->type || HTTP_MESSAGE_REQ_BODY == msg->type || HTTP_MESSAGE_REQ_BODY_END == msg->type) { ref_data = msg->ref_queue->array[msg->queue_index].req_data; } - else if (HTTP_MESSAGE_RES_BODY_START == msg->type - || HTTP_MESSAGE_RES_BODY == msg->type - || HTTP_MESSAGE_RES_BODY_END == msg->type) + else if (HTTP_MESSAGE_RES_BODY_START == msg->type || HTTP_MESSAGE_RES_BODY == msg->type || HTTP_MESSAGE_RES_BODY_END == msg->type) { ref_data = msg->ref_queue->array[msg->queue_index].res_data; } ecode = http_half_data_get_content_encoding(ref_data); - if(ref_data != NULL && HTTP_CONTENT_ENCODING_NONE != ecode){ + if (ref_data != NULL && HTTP_CONTENT_ENCODING_NONE != ecode) + { goto fail; } |
