summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/HTTP_Analyze.c7
-rw-r--r--src/HTTP_Message.c16
-rw-r--r--src/HTTP_Message.h10
-rw-r--r--src/HTTP_Message_Entry.c122
-rw-r--r--src/HTTP_Message_Header.c19
-rw-r--r--src/Makefile2
6 files changed, 101 insertions, 75 deletions
diff --git a/src/HTTP_Analyze.c b/src/HTTP_Analyze.c
index af07f72..98c81bb 100644
--- a/src/HTTP_Analyze.c
+++ b/src/HTTP_Analyze.c
@@ -691,7 +691,10 @@ void http_releaseHttpLinkNode(http_stream *a_http_stream,struct streaminfo *a_tc
if(cur_node->ungzip_handle!=NULL)
{
- docanalyze_endstream(cur_node->ungzip_handle);
+ //docanalyze_endstream(cur_node->ungzip_handle);
+ inflateEnd(cur_node->ungzip_handle);
+ dictator_free(thread_seq, cur_node->ungzip_handle);
+ cur_node->ungzip_handle = NULL;
}
if(cur_node->parser.cont_range!=NULL)
{
@@ -1133,7 +1136,7 @@ uchar http_analyseHttpConnection(http_stream* a_http_stream,struct streaminfo *a
#endif
*/
- //��Ϣ�����?
+ //��Ϣ�����?
/*set mgs_status because cur_http_node maybe release*/
uchar mgs_status = HTTP_RETURN_GIVEME;
rec = http_findAndDoWithEntity(&mgs_status, cur_http_node, a_http_stream, a_tcp, thread_seq, a_packet);
diff --git a/src/HTTP_Message.c b/src/HTTP_Message.c
index 41ce708..d85b962 100644
--- a/src/HTTP_Message.c
+++ b/src/HTTP_Message.c
@@ -363,13 +363,13 @@ int HTTP_INIT(void)
return -1;
}
- /*ungzip init*/
- g_http_prog_para.docanly_handler = docanalyze_initialize(g_iThreadNum);
- if(NULL==g_http_prog_para.docanly_handler)
- {
- MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "docanalyze_initialize error!");
- return -1;
- }
+ /*ungzip init*/
+ // g_http_prog_para.docanly_handler = docanalyze_initialize(g_iThreadNum);
+ // if(NULL==g_http_prog_para.docanly_handler)
+ // {
+ // MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "docanalyze_initialize error!");
+ // return -1;
+ // }
int i=0;
g_http_prog_para.unzip_content=(fold_infor_t *)malloc(sizeof(fold_infor_t)*g_iThreadNum);
@@ -568,7 +568,7 @@ void HTTP_DESTROY(void)
MESA_destroy_runtime_log_handle(g_http_prog_para.http_log_handle);
/*ungzip*/
- docanalyze_destroy(g_http_prog_para.docanly_handler);
+ // docanalyze_destroy(g_http_prog_para.docanly_handler);
/*unzip_content*/
int i=0;
diff --git a/src/HTTP_Message.h b/src/HTTP_Message.h
index 03234ec..fbc7b8f 100644
--- a/src/HTTP_Message.h
+++ b/src/HTTP_Message.h
@@ -4,7 +4,8 @@
#include <stdio.h>
#include "http.h"
#include "stream.h"
-#include "DocumentAnalyze.h"
+//#include "DocumentAnalyze.h"
+#include <zlib.h>
#define HTTP_PLUGIN_NAME "http.so"
@@ -104,7 +105,7 @@
#define LINE_FLAG_LF 0x02
#define LINE_FLAG_CRLF 0x03
-#define HTTP_UNZIP_CONTENT_LEN 16*1024
+#define HTTP_UNZIP_CONTENT_LEN 16384
typedef enum
{
@@ -158,7 +159,8 @@ typedef struct _http_parser_t
uint32 processed_offset; //�Ѵ��������ڵ�ǰ����ƫ����,��������һ������Ҫ����
uint64 packet_entity_len; //δ������ʵ�峤��
- docanalyze_streamparam_t ungzip_handle;
+ //docanalyze_streamparam_t ungzip_handle;
+ z_stream *ungzip_handle;
uint64 acc_cont_length;
int64 batch_prot_flag;
char* url_buf;
@@ -187,7 +189,7 @@ typedef struct _http_prog_runtime_parameter_t
void* http_log_handle;
void* region_hash; //��չ���ʶ��
void* stat_handler;
- void* docanly_handler;
+ //void* docanly_handler;
uint16 http_plugid;
uint16 http_log_level;
diff --git a/src/HTTP_Message_Entry.c b/src/HTTP_Message_Entry.c
index 3e8b7f4..a51d20d 100644
--- a/src/HTTP_Message_Entry.c
+++ b/src/HTTP_Message_Entry.c
@@ -5,7 +5,7 @@
#include "MESA_handle_logger.h"
#include "HTTP_Common.h"
#include "field_stat.h"
-
+#include <assert.h>
extern http_prog_runtime_parameter_t g_http_prog_para;
/**********************************************************
@@ -39,73 +39,89 @@ static void http_clearSpace(http_stream *a_http_stream, struct streaminfo *a_tcp
return;
}
+static z_stream *zlib_decompress_startstream(int encoding, int thread_seq)
+{
+ int ret;
+ z_stream *zins = (z_stream *)dictator_malloc(thread_seq, sizeof(z_stream));
+ memset(zins, 0, sizeof(z_stream));
+
+ switch (encoding)
+ {
+ case HTTP_CONT_ENCOD_GZIP:
+ ret = inflateInit2(zins, MAX_WBITS + 16);
+ break;
+ case HTTP_CONT_ENCOD_DEFLATE:
+ ret = inflateInit2(zins, -MAX_WBITS);
+ break;
+ default:
+ MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "not support encoding type:%d", encoding);
+ ret = Z_ERRNO;
+ break;
+ }
+
+ if (ret != Z_OK)
+ {
+ MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "zlib init fail:%d", ret);
+ dictator_free(thread_seq, zins);
+ return NULL;
+ }
+
+ return zins;
+}
+
void http_doWithGzipData(http_parser_t *cur_http_node, struct streaminfo *a_tcp, int thread_seq, void *a_packet)
{
int ret=0;
- result_array_t *result_array = (result_array_t*)dictator_malloc(thread_seq, sizeof(result_array_t));
- memset(result_array, 0, sizeof(result_array_t));
- if(cur_http_node->ungzip_handle==NULL)
+
+ if (cur_http_node->ungzip_handle == NULL)
{
- //20160128
- switch(cur_http_node->parser.cont_encoding)
+ cur_http_node->ungzip_handle = zlib_decompress_startstream(cur_http_node->parser.cont_encoding, thread_seq);
+ if (cur_http_node->ungzip_handle == NULL)
{
- case HTTP_CONT_ENCOD_GZIP:
- cur_http_node->ungzip_handle=docanalyze_startstream(DOC_GZIP_TYPE, g_http_prog_para.docanly_handler, thread_seq);
- break;
-
- case HTTP_CONT_ENCOD_DEFLATE:
- cur_http_node->ungzip_handle=docanalyze_startstream(DOC_DEFLATE_TYPE, g_http_prog_para.docanly_handler, thread_seq);
- break;
-
- default:
- break;
- }
+ MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "zlib decompress startstream error!");
+ // dictator_free(thread_seq, result_array);
+ return;
+ }
}
- if(cur_http_node->ungzip_handle==NULL)
- {
- MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "docanalyze_startstream error!");
- dictator_free(thread_seq, result_array);
- return ;
- }
+ z_stream *zins = cur_http_node->ungzip_handle;
+ zins->avail_in = cur_http_node->session.buflen;
+ zins->next_in = cur_http_node->session.buf;
- ret=docanalyze_parsestream(cur_http_node->ungzip_handle,
- (const char*)cur_http_node->session.buf,
- cur_http_node->session.buflen,
- result_array);
- if(ret==DOC_PRO_OK)
+ do
{
- fold_infor_t *unzip_content=&(g_http_prog_para.unzip_content[thread_seq]);
- unzip_content->buflen=0;
+ zins->avail_out = HTTP_UNZIP_CONTENT_LEN;
+ zins->next_out = g_http_prog_para.unzip_content[thread_seq].buf;
- int k=0;
- for (k=0; k < result_array->result_num; k++)
+ ret = inflate(zins, Z_NO_FLUSH);
+ switch (ret)
{
- int min_len=MIN(result_array->result_buff[k].size, HTTP_UNZIP_CONTENT_LEN-unzip_content->buflen);
- if(min_len<=0)
- {
- break;
- }
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "zlib inflate error:%d", ret);
+ return;
+ }
- memcpy(unzip_content->buf+unzip_content->buflen, result_array->result_buff[k].presult, min_len);
- unzip_content->buflen+=min_len;
+ int have = HTTP_UNZIP_CONTENT_LEN - zins->avail_out;
+ if (have > 0)
+ {
+ cur_http_node->session.buf = g_http_prog_para.unzip_content[thread_seq].buf;
+ cur_http_node->session.buflen = have;
+ cur_http_node->interested_reg_mask = HTTP_UNGZIP_CONTENT_MASK;
+ http_callPlugin(cur_http_node, a_tcp, thread_seq, a_packet);
+ cur_http_node->session.buf = NULL;
+ cur_http_node->session.buflen = 0;
}
- FLAG_SET(cur_http_node->flag, HTTP_FLAG_BATCH_CALLBACK);
+ if (0 == zins->avail_out)
+ {
+ MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_INFO, HTTP_PLUGIN_NAME,
+ "zlib decompress payload size:%d more than max out buff size:%d", have, HTTP_UNZIP_CONTENT_LEN);
+ }
+ } while (0 == zins->avail_out);
- cur_http_node->session.buf=unzip_content->buf;
- cur_http_node->session.buflen=unzip_content->buflen;
- http_callPlugin(cur_http_node, a_tcp, thread_seq, a_packet);
- cur_http_node->session.buf=NULL;
- cur_http_node->session.buflen=0;
- }
- else if(ret==DOC_PRO_ERR)
- {
- MESA_handle_runtime_log(g_http_prog_para.http_log_handle, RLOG_LV_FATAL, HTTP_PLUGIN_NAME, "docanalyze_parsestream return DOC_PRO_ERR!");
- }
- docanalyze_freeresult(result_array);
- dictator_free(thread_seq, result_array);
- return ;
+ return;
}
void http_judgeContentEncoding(http_parser_t *a_http, struct streaminfo *a_tcp, int thread_seq, void *a_packet)
diff --git a/src/HTTP_Message_Header.c b/src/HTTP_Message_Header.c
index bdc30e0..36f3a93 100644
--- a/src/HTTP_Message_Header.c
+++ b/src/HTTP_Message_Header.c
@@ -44,7 +44,9 @@ void http_initHttpCommonInfor( http_parser_t *a_http, int thread_seq)
if(a_http->ungzip_handle!=NULL)
{
- docanalyze_endstream(a_http->ungzip_handle);
+ //docanalyze_endstream(a_http->ungzip_handle);
+ inflateEnd(a_http->ungzip_handle);
+ dictator_free(thread_seq, a_http->ungzip_handle);
a_http->ungzip_handle = NULL;
}
@@ -62,7 +64,7 @@ void http_initHttpCommonInfor( http_parser_t *a_http, int thread_seq)
}
/**********************************************************
- * ���ܣ���Ӧ��Ϣ����ʱ�������Ӧ���������?��Ϣ��
+ * ���ܣ���Ӧ��Ϣ����ʱ�������Ӧ���������?��Ϣ��
* a_http:��ǰ�ڵ㡣
**********************************************************/
void http_resetResponseSpace(http_parser_t *a_http, int thread_seq)
@@ -128,7 +130,7 @@ void http_initHttpCommonInfor( http_parser_t *a_http, int thread_seq)
/**********************************************************
* ���ܣ�����HTTP����������
* a_http����ǰ��������
- * curdir:tcp���ݰ��ķ��򣬱�����˫�����?
+ * curdir:tcp���ݰ��ķ��򣬱�����˫�����?
* dir����ǰ���ķ���
*********************************************************/
void http_buildHttpInforLink(http_stream *a_http_stream, int thread_seq, struct streaminfo *a_tcp, void *a_packet)
@@ -210,7 +212,7 @@ void http_initHttpCommonInfor( http_parser_t *a_http, int thread_seq)
/**********************************************************
* ���ܣ���ʼ��HTTP���ӡ�
- * curdir:tcp���ݰ��ķ��򣬱�����˫�����?
+ * curdir:tcp���ݰ��ķ��򣬱�����˫�����?
* dir����ǰ���ķ���
* pme������������
***********************************************************/
@@ -320,7 +322,10 @@ static void http_reseaseHttpInforList(http_parser_t**a_http, UINT16 uncomplete_c
if(cur_http_node->ungzip_handle!=NULL)
{
- docanalyze_endstream(cur_http_node->ungzip_handle);
+ //docanalyze_endstream(cur_http_node->ungzip_handle);
+ inflateEnd(cur_http_node->ungzip_handle);
+ dictator_free(thread_seq, cur_http_node->ungzip_handle);
+ cur_http_node->ungzip_handle = NULL;
}
if(cur_http_node->parser.cont_range!=NULL)
{
@@ -674,7 +679,7 @@ uchar http_processHttpProxy(http_parser_t *a_http, http_stream *a_http_stream, s
pProxydetail->uiApendLen = a_http->url_buflen;
}
- //����������������?��
+ //����������������?��
/*user and passwd in C2S*/
if(a_http->parser.curdir==DIR_C2S)
{
@@ -738,7 +743,7 @@ uchar http_analyseHttpProxy(http_parser_t *a_http, http_stream *a_http_stream,
a_http_stream->p_stream_proxy->type = STREAM_TYPE_HTTP_PROXY;
struct proxydetail* pProxydetail = (struct proxydetail *)(a_http_stream->p_stream_proxy->pdetail);
- //������״ν���?
+ //������״ν���?
if(pProxydetail==NULL)
{
pProxydetail=(struct proxydetail*)dictator_malloc(thread_seq,sizeof(struct proxydetail));
diff --git a/src/Makefile b/src/Makefile
index b2365d4..fa7333a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,7 +17,7 @@ LIB += -lMESA_handle_logger
LIB += -lMESA_prof_load
LIB += -lMESA_htable
LIB += -lMESA_field_stat
-LIB += -ldocumentanalyze
+#LIB += -ldocumentanalyze
LIB += ./lib/libhttp_parser.a
LIB_FILE = $(wildcard ./lib/*.a)