http业务层与解析层集成。

This commit is contained in:
zhengchao
2018-09-18 12:01:56 +08:00
committed by Lu Qiuwen
parent bec093524f
commit 50d0d7ead1

View File

@@ -3,6 +3,7 @@
#include <tfe_stream.h> #include <tfe_stream.h>
#include <tfe_utils.h> #include <tfe_utils.h>
#include <tfe_http.h> #include <tfe_http.h>
#include <tfe_plugin.h>
#include <MESA/Maat_rule.h> #include <MESA/Maat_rule.h>
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
@@ -114,7 +115,7 @@ static Maat_feather_t create_maat_feather(const char* profile, const char* secti
} }
return target; return target;
} }
void pangu_http_init(struct tfe_proxy * proxy) int pangu_http_init(struct tfe_proxy * proxy)
{ {
const char* profile="./pangu/pangu_pxy.conf"; const char* profile="./pangu/pangu_pxy.conf";
const char* logfile="./log/pangu_pxy.log"; const char* logfile="./log/pangu_pxy.log";
@@ -158,11 +159,11 @@ void pangu_http_init(struct tfe_proxy * proxy)
g_pangu_rt->tpl_451 = ctemplate::Template::GetTemplate(page_path,ctemplate::DO_NOT_STRIP); g_pangu_rt->tpl_451 = ctemplate::Template::GetTemplate(page_path,ctemplate::DO_NOT_STRIP);
TFE_LOG_INFO(NULL, "Pangu HTTP init success."); TFE_LOG_INFO(NULL, "Pangu HTTP init success.");
return; return 0;
error_out: error_out:
TFE_LOG_ERROR(NULL, "Pangu HTTP init failed."); TFE_LOG_ERROR(NULL, "Pangu HTTP init failed.");
return; return -1;
} }
static void _wrap_std_field_write(struct tfe_http_half * half, enum tfe_http_std_field field_id, const char * value) static void _wrap_std_field_write(struct tfe_http_half * half, enum tfe_http_std_field field_id, const char * value)
{ {
@@ -344,7 +345,7 @@ static void html_free(char** page_buff)
FREE(page_buff); FREE(page_buff);
return; return;
} }
static int is_http_request(uint64_t events) static int is_http_request(enum tfe_http_event events)
{ {
if((events&EV_HTTP_REQ_HDR)|(events&EV_HTTP_REQ_BODY_BEGIN)|(events&EV_HTTP_REQ_BODY_END)|(events&EV_HTTP_REQ_BODY_CONT)) if((events&EV_HTTP_REQ_HDR)|(events&EV_HTTP_REQ_BODY_BEGIN)|(events&EV_HTTP_REQ_BODY_END)|(events&EV_HTTP_REQ_BODY_CONT))
{ {
@@ -365,7 +366,7 @@ enum replace_zone zone_name_to_id(const char* name)
"http_resp_body", "http_resp_body",
"http_resp_body"}; "http_resp_body"};
size_t i=0; size_t i=0;
for(i=0;i< sizeof(std_name)/sizeof(const char*);i++) for(i=0; i<sizeof(std_name)/sizeof(const char*); i++)
{ {
if(0==strcasecmp(name,std_name[i])) if(0==strcasecmp(name,std_name[i]))
{ {
@@ -581,7 +582,7 @@ struct evbuffer* execute_replace_rule(const char* in, size_t in_sz,
return out; return out;
} }
void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session, void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session,
uint64_t events, const char* body_frag, size_t frag_size,struct pangu_http_ctx* ctx) enum tfe_http_event events, const unsigned char* body_frag, size_t frag_size,struct pangu_http_ctx* ctx)
{ {
void* interator=NULL; void* interator=NULL;
struct http_field_name tmp_name; struct http_field_name tmp_name;
@@ -688,7 +689,7 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio
} }
static void http_reject(const struct tfe_http_session * session, uint64_t events, struct pangu_http_ctx* ctx) static void http_reject(const struct tfe_http_session * session, enum tfe_http_event events, struct pangu_http_ctx* ctx)
{ {
int resp_code=0,ret=0; int resp_code=0,ret=0;
@@ -719,7 +720,7 @@ error_out:
html_free(&page_buff); html_free(&page_buff);
return; return;
} }
static void http_redirect(const struct tfe_http_session * session, uint64_t events, struct pangu_http_ctx* ctx) static void http_redirect(const struct tfe_http_session * session, enum tfe_http_event events, struct pangu_http_ctx* ctx)
{ {
int resp_code=0,ret=0; int resp_code=0,ret=0;
char* url=NULL; char* url=NULL;
@@ -745,8 +746,8 @@ error_out:
return; return;
} }
enum pangu_action http_scan(const struct tfe_http_session * session, uint64_t events, enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_http_event events,
const char* body_frag, size_t frag_size, struct pangu_http_ctx* ctx) const unsigned char* body_frag, size_t frag_size, struct pangu_http_ctx* ctx)
{ {
void * interator=NULL; void * interator=NULL;
const char* field_val=NULL; const char* field_val=NULL;
@@ -795,7 +796,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, uint64_t ev
} }
if(body_frag!=NULL) if(body_frag!=NULL)
{ {
scan_ret=Maat_stream_scan_string(&(ctx->sp),CHARSET_UTF8, body_frag, (int)frag_size scan_ret=Maat_stream_scan_string(&(ctx->sp),CHARSET_UTF8, (const char*)body_frag, (int)frag_size
,result+hit_cnt, NULL, MAX_SCAN_RESULT-hit_cnt, &(ctx->mid)); ,result+hit_cnt, NULL, MAX_SCAN_RESULT-hit_cnt, &(ctx->mid));
if(scan_ret>0) if(scan_ret>0)
{ {
@@ -853,6 +854,7 @@ void pangu_on_http_begin(const struct tfe_stream * stream,
{ {
tfe_http_session_detach(session); tfe_http_session_detach(session);
} }
return;
} }
@@ -871,8 +873,8 @@ void pangu_on_http_end(const struct tfe_stream * stream,
return; return;
} }
void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_session * session, void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_session * session,
uint64_t events, const char* body_frag, size_t frag_size, unsigned int thread_id, void ** pme) enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, void ** pme)
{ {
struct pangu_http_ctx* ctx=*(struct pangu_http_ctx**)pme; struct pangu_http_ctx* ctx=*(struct pangu_http_ctx**)pme;
enum pangu_action hit_action=PG_ACTION_NONE; enum pangu_action hit_action=PG_ACTION_NONE;
@@ -909,4 +911,17 @@ Re_Enter:
return; return;
} }
struct tfe_plugin pangu_http_spec={
.symbol=NULL,
.type = TFE_PLUGIN_TYPE_BUSINESS,
.on_init = pangu_http_init,
.on_deinit = NULL,
.on_open = NULL,
.on_data = NULL,
.on_close = NULL,
.on_session_begin=pangu_on_http_begin,
.on_session_data=pangu_on_http_data,
.on_session_end=pangu_on_http_end
};
TFE_PLUGIN_REGISTER(pangu_http, pangu_http_spec)