diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index 85b152e..53d4c4b 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -97,7 +97,8 @@ struct manipulate_profile char *profile_name; char *profile_msg; char *profile_type; - ctemplate::Template * tpl; + ctemplate::Template * tpl; + pthread_mutex_t lock; }; struct policy_action_param @@ -638,7 +639,9 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li memset(ply_profile, 0, sizeof(struct manipulate_profile)); ply_profile->profile_id=profile_id; - ply_profile->ref_cnt=1; + ply_profile->ref_cnt=1; + pthread_mutex_init(&(ply_profile->lock), NULL); + if(strcasecmp(formate, "template") == 0) { ply_profile->tpl = ctemplate::Template::GetTemplate(profile_path, ctemplate::DO_NOT_STRIP); @@ -672,7 +675,8 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t return; } struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1); - ply_profile->ref_cnt=1; + ply_profile->ref_cnt=1; + pthread_mutex_init(&(ply_profile->lock), NULL); ply_profile->profile_id=profile_id; ply_profile->profile_msg=tfe_strdup(profile_path); @@ -687,17 +691,27 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t void ma_profile_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp) { - struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*ad); - ply_obj->ref_cnt--; - - if (ply_obj->ref_cnt==0) + if(*ad==NULL) { - FREE(&ply_obj->profile_type); - FREE(&ply_obj->profile_msg); - FREE(&ply_obj->profile_name); - FREE(&ply_obj); - *ad=NULL; + return; } + struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*ad); + pthread_mutex_lock(&(ply_obj->lock)); + ply_obj->ref_cnt--; + if(ply_obj->ref_cnt>0) + { + pthread_mutex_unlock(&(ply_obj->lock)); + return; + } + pthread_mutex_unlock(&(ply_obj->lock)); + pthread_mutex_destroy(&(ply_obj->lock)); + + FREE(&ply_obj->profile_type); + FREE(&ply_obj->profile_msg); + FREE(&ply_obj->profile_name); + FREE(&ply_obj); + *ad=NULL; + return; } void ma_profile_table_free(struct manipulate_profile* ply_obj) @@ -708,7 +722,9 @@ void ma_profile_table_free(struct manipulate_profile* ply_obj) void ma_profile_table_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp) { struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*from); + pthread_mutex_lock(&(ply_obj->lock)); ply_obj->ref_cnt++; + pthread_mutex_unlock(&(ply_obj->lock)); *to=ply_obj; } @@ -1566,7 +1582,7 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e struct manipulate_profile* hijack_profile=get_profile_by_id(POLICY_PROFILE_TABLE_HIJACK, param->profile_id); if (NULL == hijack_profile) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "get table obj faild, table_id = %d", param->profile_id); + TFE_LOG_ERROR(g_pangu_rt->local_logger, "get table obj faild, profile_id = %d", param->profile_id); ctx->action = PG_ACTION_NONE; return; } diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/pangu-http/src/pangu_logger.cpp index 8d9f087..91dcdc0 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/pangu-http/src/pangu_logger.cpp @@ -189,7 +189,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) char src_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0}; char dst_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0}; - const char *app_proto[]= {"unkonw","http1.0", "http2.0"}; + const char *app_proto[]= {"unkonw","http1", "http2"}; struct json_spec req_fields[]={ {"cookie", TFE_HTTP_COOKIE}, {"referer", TFE_HTTP_REFERER}, diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 30eaa25..7514279 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -387,7 +387,7 @@ h2_half_ops_append_body(struct tfe_http_half * half, char * buff, size_t size, i struct tfe_h2_half_private * resp = nghttp2_to_half_private(half); struct tfe_h2_payload *body = &resp->h2_payload; - if (buff == NULL && size == 0){ + if (buff == NULL || size == 0){ if (body->gzip != HTTP2_CONTENT_ENCODING_NONE){ xret = deflate_write(&body->deflate, NULL, 0, resp->h2_payload.evbuf_body, body->gzip, 1); } @@ -661,6 +661,10 @@ upstream_read_callback(nghttp2_session *session, int32_t stream_id, if (!to_send_body->evbuf_body || !(input = evbuffer_pullup(to_send_body->evbuf_body, -1)) || 0==(inputlen = evbuffer_get_length(to_send_body->evbuf_body))) { + if ((to_send_body->flags & NGHTTP2_FLAG_END_STREAM) == 0) + { + *data_flags |= NGHTTP2_DATA_FLAG_NO_END_STREAM; + } *data_flags |= NGHTTP2_DATA_FLAG_EOF; return 0; } @@ -689,6 +693,7 @@ nghttp2_server_frame_submit_response(struct tfe_h2_stream *h2_stream_info, return ACTION_FORWARD_DATA; struct tfe_h2_payload *body = &pangu_resp->h2_payload; + body->flags |= NGHTTP2_FLAG_END_STREAM; char str_sz_evbuf_body[TFE_STRING_MAX]; snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body));