summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http_content_decompress.cpp6
-rw-r--r--src/http_decoder.cpp55
-rw-r--r--src/http_decoder_half.cpp3
-rw-r--r--src/http_decoder_inc.h4
-rw-r--r--src/http_decoder_stat.cpp1
-rw-r--r--src/http_decoder_stat.h1
-rw-r--r--src/http_decoder_tunnel.h3
7 files changed, 42 insertions, 31 deletions
diff --git a/src/http_content_decompress.cpp b/src/http_content_decompress.cpp
index 5c436d9..44fcdf3 100644
--- a/src/http_content_decompress.cpp
+++ b/src/http_content_decompress.cpp
@@ -136,9 +136,8 @@ http_content_decompress_write_zlib(struct http_content_decompress *decompress,
*outdata = NULL;
*outdata_len = 0;
- int ret = 0;
do {
- ret = inflate(z_stream_ptr, Z_NO_FLUSH);
+ int ret = inflate(z_stream_ptr, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT
|| ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
(void)inflateEnd(z_stream_ptr);
@@ -182,9 +181,8 @@ http_content_decompress_write_br(struct http_content_decompress *decompress,
*outdata = NULL;
*outdata_len = 0;
- int ret;
for (;;) {
- ret = BrotliDecoderDecompressStream(decompress->br_state, &available_in,
+ int ret = BrotliDecoderDecompressStream(decompress->br_state, &available_in,
&next_in, &available_out, &next_out, 0);
size_t have = decompress->buffer_size - available_out;
if (have > 0) {
diff --git a/src/http_decoder.cpp b/src/http_decoder.cpp
index 3af4dad..551b0b0 100644
--- a/src/http_decoder.cpp
+++ b/src/http_decoder.cpp
@@ -86,6 +86,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);
if(httpd_tunnel_identify(PACKET_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_get_url(half_data, mempool);
break;
@@ -112,17 +113,6 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
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);
-
- if(httpd_is_tunnel_session(exdata)){
- session_is_symmetric(ev_ctx->ref_session, &flow_flag);
- if(SESSION_SEEN_C2S_FLOW == flow_flag){
- exdata->tunnel_state = HTTP_TUN_INNER_STARTING;
- http_half_pre_context_free(ev_ctx->ref_session, exdata);
- exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_TUNNEL_INDEX].sub_topic_id;
- }else{
- exdata->tunnel_state = HTTP_TUN_C2S_HDR_END;
- }
- }
}
break;
case HTTP_EVENT_REQ_BODY_BEGIN:
@@ -139,12 +129,21 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
case HTTP_EVENT_REQ_END:
{
session_is_symmetric(ev_ctx->ref_session, &flow_flag);
+
if(SESSION_SEEN_C2S_FLOW == flow_flag){
msg = http_message_new(HTTP_TRANSACTION_FREE, 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);
}
+ if(httpd_is_tunnel_session(exdata)){
+ if(SESSION_SEEN_C2S_FLOW == flow_flag){
+ exdata->tunnel_state = HTTP_TUN_INNER_STARTING;
+ exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_TUNNEL_INDEX].sub_topic_id;
+ }else{
+ exdata->tunnel_state = HTTP_TUN_C2S_END;
+ }
+ }
http_half_update_state(half_data, event);
http_decoder_result_queue_inc_req_index(queue);
half_data = http_decoder_result_queue_pop_req(queue);
@@ -216,13 +215,12 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
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);
-
+
if(httpd_is_tunnel_session(exdata)){
exdata->tunnel_state = HTTP_TUN_INNER_STARTING;
http_half_pre_context_free(ev_ctx->ref_session, exdata);
exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_TUNNEL_INDEX].sub_topic_id;
- // http_decoder_push_tunnel_data(ev_ctx->ref_session, exdata, HTTP_TUNNEL_OPENING);
- }
+ }
}
break;
case HTTP_EVENT_RES_BODY_BEGIN:
@@ -243,6 +241,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
if(SESSION_SEEN_S2C_FLOW == flow_flag){
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C, 1);
}
+
http_half_update_state(half_data, event);
http_decoder_result_queue_inc_res_index(queue);
half_data = http_decoder_result_queue_pop_res(queue);
@@ -625,7 +624,7 @@ extern "C"
case HTTP_TUNNEL_OPENING:
{
if(NULL != exdata){
- //not support nested http tunnel
+ //not support nested http tunnel
session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
return;
}
@@ -642,21 +641,26 @@ extern "C"
exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_MSG_INDEX].sub_topic_id;
exdata->in_tunnel_is_http = 1;
}else{
- exdata = CALLOC(struct http_decoder_exdata, 1);
- exdata->decoder = NULL;
- exdata->pub_topic_id = -1;
- exdata->in_tunnel_is_http = 0;
- session_exdata_set(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_TUNNEL_INDEX].exdata_id, exdata);
- //do nothing, but can't call stellar_session_plugin_dettach_current_session() !!!
+ //inner tunnel is not http, do nothing, do not push this message again !!!
+ session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
return;
}
}
break;
case HTTP_TUNNEL_ACTIVE:
+ if(NULL == exdata){
+ session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
+ http_decoder_stat_update(&httpd_env->hd_stat, session_get_current_thread_id(sess), HTTPD_STAT_PARSE_ERR, 1);
+ return;
+ }
break;
case HTTP_TUNNEL_CLOSING:
+ if(NULL == exdata){
+ http_decoder_stat_update(&httpd_env->hd_stat, session_get_current_thread_id(sess), HTTPD_STAT_PARSE_ERR, 1);
+ return;
+ }
if(exdata->in_tunnel_is_http){
http_half_pre_context_free(sess, exdata);
}
@@ -689,11 +693,20 @@ extern "C"
break;
case SESSION_STATE_ACTIVE:
+ if(NULL == exdata){
+ session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
+ http_decoder_stat_update(&httpd_env->hd_stat, session_get_current_thread_id(sess), HTTPD_STAT_PARSE_ERR, 1);
+ return;
+ }
//go on
break;
case SESSION_STATE_CLOSING:
{
+ if(NULL == exdata){
+ http_decoder_stat_update(&httpd_env->hd_stat, session_get_current_thread_id(sess), HTTPD_STAT_PARSE_ERR, 1);
+ return;
+ }
if(httpd_in_tunnel_transmitting(exdata)){
http_decoder_push_tunnel_data(sess, exdata, HTTP_TUNNEL_CLOSING);
}else{
diff --git a/src/http_decoder_half.cpp b/src/http_decoder_half.cpp
index 6074307..b2d3f07 100644
--- a/src/http_decoder_half.cpp
+++ b/src/http_decoder_half.cpp
@@ -1048,12 +1048,11 @@ int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data *
void http_half_pre_context_free(struct session *sess, struct http_decoder_exdata *exdata)
{
struct http_message *msg = NULL;
- struct http_decoder_half_data *req_data;
struct http_decoder_half_data *res_data;
struct http_decoder_result_queue *queue = exdata->queue;
for(int i = 0; i < queue->queue_size; i++){
- req_data = queue->array[i].req_data;
+ struct http_decoder_half_data *req_data = queue->array[i].req_data;
res_data = queue->array[i].res_data;
if ((req_data != NULL) && (NULL == res_data) && (req_data->state < HTTP_EVENT_REQ_END))
{
diff --git a/src/http_decoder_inc.h b/src/http_decoder_inc.h
index 0e0f0c5..9b64cad 100644
--- a/src/http_decoder_inc.h
+++ b/src/http_decoder_inc.h
@@ -46,8 +46,8 @@ extern "C"
#define MEMPOOL_REALLOC(pool)
#define MEMPOOL_FREE(pool, p) nmx_pfree(pool, p)
-#define ENABLE_MEMPOOL 1
-#ifdef ENABLE_MEMPOOL
+#define ENABLE_MEMPOOL 0
+#if ENABLE_MEMPOOL
#define HD_CALLOC(pool, type, number) MEMPOOL_CALLOC(pool, number, type)
#define HD_FREE(pool, p) MEMPOOL_FREE(pool, p)
#else
diff --git a/src/http_decoder_stat.cpp b/src/http_decoder_stat.cpp
index a2b6205..290af64 100644
--- a/src/http_decoder_stat.cpp
+++ b/src/http_decoder_stat.cpp
@@ -16,6 +16,7 @@ static const struct hd_stat_config_tuple g_httpd_stat_tuple[HTTPD_STAT_MAX] =
{HTTPD_STAT_SESSION_NEW, "session_new"},
{HTTPD_STAT_SESSION_FREE, "session_free"},
{HTTPD_STAT_SESSION_EXCEPTION, "sess_exception"},
+ {HTTPD_STAT_TUNNEL, "tunnel"},
{HTTPD_STAT_TRANSACTION_NEW, "trans_new"},
{HTTPD_STAT_TRANSACTION_FREE, "trans_free"},
{HTTPD_STAT_ASYMMETRY_SESSION_C2S, "asymmetry_sess_c2s"},
diff --git a/src/http_decoder_stat.h b/src/http_decoder_stat.h
index e8f18d8..f78f6b6 100644
--- a/src/http_decoder_stat.h
+++ b/src/http_decoder_stat.h
@@ -14,6 +14,7 @@ enum http_decoder_stat_type
HTTPD_STAT_SESSION_NEW,
HTTPD_STAT_SESSION_FREE,
HTTPD_STAT_SESSION_EXCEPTION, // rst, kickout, lost packet, etc.
+ HTTPD_STAT_TUNNEL,
HTTPD_STAT_TRANSACTION_NEW,
HTTPD_STAT_TRANSACTION_FREE,
HTTPD_STAT_ASYMMETRY_SESSION_C2S,
diff --git a/src/http_decoder_tunnel.h b/src/http_decoder_tunnel.h
index b1e74df..2b67649 100644
--- a/src/http_decoder_tunnel.h
+++ b/src/http_decoder_tunnel.h
@@ -6,9 +6,8 @@
enum http_tunnel_state{
HTTP_TUN_NON = 0, // init, or not tunnel session
HTTP_TUN_C2S_HDR_START, //CONNECT ...
- HTTP_TUN_C2S_HDR_END, //CONNECT request all heades end with \r\n
+ HTTP_TUN_C2S_END, //CONNECT request end
HTTP_TUN_S2C_START, // HTTP 200 connet established
- // HTTP_TUN_S2C_END, // http response all heades end with \r\n
HTTP_TUN_INNER_STARTING, // http inner tunnel protocol starting
HTTP_TUN_INNER_TRANS, // http inner tunnel protocol transmitting
};