diff --git a/common/include/tfe_http.h b/common/include/tfe_http.h index 2b0c9de..f343ea6 100644 --- a/common/include/tfe_http.h +++ b/common/include/tfe_http.h @@ -300,6 +300,7 @@ typedef void (http_session_end_cb)(const struct tfe_stream * stream, struct http_field_name * http_field_name_duplicate(const struct http_field_name * orig); int http_field_name_compare(const struct http_field_name * lvalue, const struct http_field_name * rvalue); const char * http_field_name_to_string(const struct http_field_name * field); +enum tfe_http_std_field http_field_name_to_std_field(const char * field_name, size_t field_name_len); void http_field_name_destory(struct http_field_name *); /* Tools functions for standard HTTP method */ diff --git a/common/src/tfe_http.cpp b/common/src/tfe_http.cpp index 78d27c3..36c98d7 100644 --- a/common/src/tfe_http.cpp +++ b/common/src/tfe_http.cpp @@ -110,6 +110,19 @@ struct http_field_name * http_field_construct_from_string(const char * str_field return NULL; } +enum tfe_http_std_field http_field_name_to_std_field(const char * field_name, size_t field_name_len) +{ + unsigned int i = 0; + for (i = 1; i < __str_std_header_field_map_size; i++) + { + if (field_name_len == strlen(__str_std_header_field_map[i]) && !strncasecmp(field_name, __str_std_header_field_map[i], field_name_len)) + { + return (enum tfe_http_std_field)i; + } + } + return TFE_HTTP_UNKNOWN_FIELD; +} + const char * http_field_name_to_string(const struct http_field_name * field) { if (field->field_id != TFE_HTTP_UNKNOWN_FIELD) return __str_std_header_field_map[field->field_id]; diff --git a/plugin/business/doh/src/logger.cpp b/plugin/business/doh/src/logger.cpp index db5c0ac..a1ab494 100644 --- a/plugin/business/doh/src/logger.cpp +++ b/plugin/business/doh/src/logger.cpp @@ -307,6 +307,7 @@ static int doh_get_ip_client_geolocation(struct tfe_cmsg * cmsg, cJSON *common_o for(i=TFE_CMSG_SRC_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2) { + memset(opt_val, 0, sizeof(opt_val)); int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size); if (ret == 0) { @@ -325,6 +326,7 @@ static int doh_get_ip_server_geolocation(struct tfe_cmsg * cmsg, cJSON *common_o for(i=TFE_CMSG_DST_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2) { + memset(opt_val, 0, sizeof(opt_val)); int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size); if (ret == 0) { diff --git a/plugin/business/tsg-http/src/edit_element.cpp b/plugin/business/tsg-http/src/edit_element.cpp index a24b202..b77d544 100644 --- a/plugin/business/tsg-http/src/edit_element.cpp +++ b/plugin/business/tsg-http/src/edit_element.cpp @@ -658,6 +658,7 @@ finish: size_t format_multidelete_json_type(const char * in, size_t in_sz, const struct edit_element_rule * rules, char** out) { + int match=0; char *new_out=NULL, *pre_out=NULL; char * tmp = ALLOC(char, in_sz+1); char * token = NULL, * sub_token = NULL, * saveptr = NULL; @@ -685,10 +686,25 @@ size_t format_multidelete_json_type(const char * in, size_t in_sz, const struct memcpy(new_out+new_out_len, "\r\n", 2); new_out_len +=2; FREE(&pre_out); + match++; + } + else + { + memcpy(new_out+new_out_len, sub_token, strlen(sub_token)); + new_out_len += strlen(sub_token); + memcpy(new_out+new_out_len, "\r\n", 2); + new_out_len +=2; } } - if(new_out) + if(match == 0 && new_out != NULL) + { + free(new_out); + new_out=NULL; + *out = new_out; + output_size = 0; + } + else if(new_out) { *out = new_out; output_size = strlen(new_out); diff --git a/plugin/business/tsg-http/src/http_lua.cpp b/plugin/business/tsg-http/src/http_lua.cpp index 78b93ba..1832645 100644 --- a/plugin/business/tsg-http/src/http_lua.cpp +++ b/plugin/business/tsg-http/src/http_lua.cpp @@ -657,7 +657,15 @@ static int http_lua_rewrite_header(struct elua_vm *vm) return 0; } - tfe_http_nonstd_field_write(tsg_ctx->replacing, field_name, field_value); + enum tfe_http_std_field field_id=http_field_name_to_std_field(field_name, strlen(field_name)); + if(field_id == TFE_HTTP_UNKNOWN_FIELD) + { + tfe_http_nonstd_field_write(tsg_ctx->replacing, field_name, field_value); + } + else + { + tfe_http_std_field_write(tsg_ctx->replacing, field_id, field_value); + } tsg_ctx->execut_lua_sucess=1; tsg_ctx->rewrite_header=1; diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp index 52a99e6..e1cc528 100644 --- a/plugin/business/tsg-http/src/tsg_logger.cpp +++ b/plugin/business/tsg-http/src/tsg_logger.cpp @@ -145,6 +145,7 @@ static int get_ip_client_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj) for(i=TFE_CMSG_SRC_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2) { + memset(opt_val, 0, sizeof(opt_val)); int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size); if (ret == 0) { @@ -163,6 +164,7 @@ static int get_ip_server_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj) for(i=TFE_CMSG_DST_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2) { + memset(opt_val, 0, sizeof(opt_val)); int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size); if (ret == 0) { diff --git a/plugin/business/tsg-http/test/test_data/header_filter_by_lua.lua b/plugin/business/tsg-http/test/test_data/header_filter_by_lua.lua new file mode 100644 index 0000000..a7e2f47 --- /dev/null +++ b/plugin/business/tsg-http/test/test_data/header_filter_by_lua.lua @@ -0,0 +1,198 @@ +--[[ + Request header template +---]] +-- content-length: LLLEEENNN +http_resp_header = [[ + HTTP/1.1 404 Not Found + Server: nqinx + Date: TTTIIIMMM + Content-Type: text/html + Transfer-Encodinq: chunked + X-Powered-By: PHP/5.3.10 + Set-Cookie:PHPSESSID=mmc1i020i83evg47rjb3233hb7;path=/ + Expires:Thu, 19 Nov 1981 08:52:00 GMT + Cache-Control:no-store,no-cachemust-revalidate,post-check=0preC] + Pragma:no-cache + Location:http://UUURRRLLLUUURRRIII +]] + +--[[ + Private key template +---]] + +private_key =[[ + MIIEpAIBAAKCAQEAyAfT3h +]] + +--[[ + Response body template +---]] + +http_resp_body = [[ + + +
+ +