diff --git a/common/include/tfe_http.h b/common/include/tfe_http.h index 7b961fa..68d1ad9 100644 --- a/common/include/tfe_http.h +++ b/common/include/tfe_http.h @@ -268,6 +268,7 @@ struct tfe_http_session unsigned int session_id; short major_version; short minor_version; + time_t start_time; struct tfe_http_session_ops * ops; struct tfe_http_half * req; diff --git a/common/include/tfe_kafka_logger.h b/common/include/tfe_kafka_logger.h index 0ccd223..3e5e609 100644 --- a/common/include/tfe_kafka_logger.h +++ b/common/include/tfe_kafka_logger.h @@ -23,10 +23,11 @@ extern "C" rd_kafka_topic_t *kafka_topic; } tfe_kafka_logger_t; - tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, const char *brokerlist, const char *topic_name, - const char *sasl_username, const char *sasl_passwd, void *local_logger); - void tfe_kafka_logger_destroy(tfe_kafka_logger_t *logger); - int tfe_kafka_logger_send(tfe_kafka_logger_t *logger, const char *data, int len); +tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, const char *brokerlist, const char *topic_name, + const char *sasl_username, const char *sasl_passwd, void *local_logger); + +void tfe_kafka_logger_destroy(tfe_kafka_logger_t *logger); +int tfe_kafka_logger_send(tfe_kafka_logger_t *logger, const char *data, int len); #ifdef __cpluscplus } diff --git a/common/src/tfe_kafka_logger.cpp b/common/src/tfe_kafka_logger.cpp index 59a90f2..e9ef74c 100644 --- a/common/src/tfe_kafka_logger.cpp +++ b/common/src/tfe_kafka_logger.cpp @@ -106,6 +106,7 @@ static rd_kafka_t *create_kafka_handle(const char *brokerlist, const char *sasl_ tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, const char *brokerlist, const char *topic_name, const char *sasl_username, const char *sasl_passwd, void *local_logger) { + char *override_sled_ip=NULL; tfe_kafka_logger_t *logger = (tfe_kafka_logger_t *)calloc(1, sizeof(tfe_kafka_logger_t)); if (!logger) return NULL; @@ -114,15 +115,23 @@ tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, co if (!logger->enable) return logger; - logger->local_ip_num = get_ip_by_eth_name(nic_name); - if (logger->local_ip_num == INADDR_NONE) - { - TFE_LOG_ERROR(local_logger, "Error to get NIC_NAME: %s.", nic_name); - free(logger); - return NULL; - } - inet_ntop(AF_INET, &(logger->local_ip_num), logger->local_ip_str, sizeof(logger->local_ip_str)); + override_sled_ip = getenv("OVERRIDE_SLED_IP"); + if(override_sled_ip != NULL) + { + strncpy(logger->local_ip_str, override_sled_ip, strlen(override_sled_ip)); + goto create_kafka; + } + logger->local_ip_num = get_ip_by_eth_name(nic_name); + if (logger->local_ip_num == INADDR_NONE) + { + TFE_LOG_ERROR(local_logger, "Error to get NIC_NAME: %s.", nic_name); + free(logger); + return NULL; + } + inet_ntop(AF_INET, &(logger->local_ip_num), logger->local_ip_str, sizeof(logger->local_ip_str)); + +create_kafka: strncpy(logger->broker_list, brokerlist, strlen(brokerlist)); logger->kafka_handle = create_kafka_handle(logger->broker_list, sasl_username, sasl_passwd, local_logger); if (logger->kafka_handle == NULL) diff --git a/common/src/tfe_resource.cpp b/common/src/tfe_resource.cpp index 3d149db..2940e9f 100644 --- a/common/src/tfe_resource.cpp +++ b/common/src/tfe_resource.cpp @@ -156,7 +156,7 @@ error_out: static tfe_kafka_logger_t *create_kafka_logger(const char *profile, const char *section, void *logger) { int enable = 0; - char nic_name[64] = {0}; + char nic_name[TFE_SYMBOL_MAX] = {0}; char brokerlist[TFE_STRING_MAX] = {0}; char topic_name[TFE_STRING_MAX] = {0}; char sasl_username[TFE_STRING_MAX] = {0}; diff --git a/common/src/tfe_scan.cpp b/common/src/tfe_scan.cpp index d743cf4..05bf81c 100644 --- a/common/src/tfe_scan.cpp +++ b/common/src/tfe_scan.cpp @@ -205,11 +205,11 @@ int tfe_scan_ip_location(const struct tfe_stream *stream, struct Maat_rule_t *re memset(buff, 0, sizeof(buff)); if(strlen(dst_subdivsion)) { - snprintf(buff, sizeof(buff), "%s,%s,%s,%s", dst_country, dst_provine, dst_city, dst_subdivsion); + snprintf(buff, sizeof(buff), "%s.%s.%s.%s", dst_country, dst_provine, dst_city, dst_subdivsion); } else { - snprintf(buff, sizeof(buff), "%s,%s,%s", dst_country, dst_provine, dst_city); + snprintf(buff, sizeof(buff), "%s.%s.%s", dst_country, dst_provine, dst_city); } *location_server = tfe_strdup(buff); } @@ -237,11 +237,11 @@ int tfe_scan_ip_location(const struct tfe_stream *stream, struct Maat_rule_t *re memset(buff, 0, sizeof(buff)); if(strlen(src_subdivsion)) { - snprintf(buff, sizeof(buff), "%s,%s,%s,%s", src_country, src_provine, src_city, src_subdivsion); + snprintf(buff, sizeof(buff), "%s.%s.%s.%s", src_country, src_provine, src_city, src_subdivsion); } else { - snprintf(buff, sizeof(buff), "%s,%s,%s", src_country, src_provine, src_city); + snprintf(buff, sizeof(buff), "%s.%s.%s", src_country, src_provine, src_city); } *location_client = tfe_strdup(buff); } diff --git a/conf/tfe/zlog.conf b/conf/tfe/zlog.conf index 70e3f72..e671d19 100644 --- a/conf/tfe/zlog.conf +++ b/conf/tfe/zlog.conf @@ -17,4 +17,4 @@ tfe.DEBUG "./log/tfe.log.%d(%F)"; http.DEBUG "./log/http.log.%d(%F)"; http2.DEBUG "./log/http2.log.%d(%F)"; doh.DEBUG "./log/doh_pxy.log.%d(%F)"; -pangu.DEBUG "./log/pangu_pxy.log.%d(%F)"; \ No newline at end of file +tsg_http.DEBUG "./log/tsg_http_pxy.log.%d(%F)"; diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index 388c8dd..c6c34f2 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -41,7 +41,7 @@ if(ENABLE_PLUGIN_DOH) endif() if(ENABLE_PLUGIN_PANGU_HTTP) - target_link_libraries(tfe -Wl,--whole-archive pangu-http -Wl,--no-whole-archive) + target_link_libraries(tfe -Wl,--whole-archive tsg-http -Wl,--no-whole-archive) endif() if(ENABLE_PLUGIN_SSL_POLICY) diff --git a/platform/src/ssl_fetch_cert.cpp b/platform/src/ssl_fetch_cert.cpp index 61e97df..b88fb5f 100644 --- a/platform/src/ssl_fetch_cert.cpp +++ b/platform/src/ssl_fetch_cert.cpp @@ -45,7 +45,7 @@ void ssl_mid_cert_kafka_logger_destory(void) int ssl_mid_cert_kafka_logger_create(const char *profile, const char *section) { int enable = 0; - char nic_name[64] = {0}; + char nic_name[TFE_SYMBOL_MAX] = {0}; char broker_list[TFE_SYMBOL_MAX] = {0}; char topic_name[TFE_SYMBOL_MAX] = {0}; char sasl_username[TFE_STRING_MAX] = {0}; diff --git a/plugin/business/CMakeLists.txt b/plugin/business/CMakeLists.txt index 229060b..5832980 100644 --- a/plugin/business/CMakeLists.txt +++ b/plugin/business/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(traffic-mirror) add_subdirectory(doh) -add_subdirectory(pangu-http) +add_subdirectory(tsg-http) add_subdirectory(ssl-policy) diff --git a/plugin/business/pangu-http/CMakeLists.txt b/plugin/business/pangu-http/CMakeLists.txt deleted file mode 100644 index f7a2d59..0000000 --- a/plugin/business/pangu-http/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -add_library(pangu-http src/pangu_logger.cpp src/pangu_http.cpp src/pattern_replace.cpp src/pangu_web_cache.cpp src/edit_element.cpp src/http_lua.cpp) -target_link_libraries(pangu-http PUBLIC common http tango-cache-client) -target_link_libraries(pangu-http PUBLIC rdkafka ctemplate-static cjson pcre2-static ratelimiter-static libdablooms pthread) -target_link_libraries(pangu-http PUBLIC maatframe tsglua) -target_link_libraries(pangu-http PUBLIC libxml2-static z) - -add_executable(test_pattern_replace src/test_pattern_replace.cpp src/pattern_replace.cpp) -target_link_libraries(test_pattern_replace common gtest pcre2-static) -file(COPY test_data DESTINATION ./) - -add_executable(test_edit_element src/test_edit_element.cpp src/edit_element.cpp) -target_link_libraries(test_edit_element common gtest pcre2-static libxml2-static z) - -add_executable(test_http_lua src/test_http_lua.cpp src/http_lua.cpp) -target_link_libraries(test_http_lua common gtest tsglua z) - -add_executable(replace_tool src/replace_tool.cpp src/pattern_replace.cpp) -target_link_libraries(replace_tool common pcre2-static) diff --git a/plugin/business/pangu-http/src/http_lua.cpp b/plugin/business/pangu-http/src/http_lua.cpp deleted file mode 100644 index 6b87d57..0000000 --- a/plugin/business/pangu-http/src/http_lua.cpp +++ /dev/null @@ -1,713 +0,0 @@ -#include "pattern_replace.h" -#include "http_lua.h" - -#include -#include - -#include -#include -#include -#include -#include - -static const char __attribute__((__unused__))*http_lua_log_get_url(struct tsg_script_ctx *tsg_ctx) -{ - enum tfe_http_event events = tsg_ctx->events; - if(events < EV_HTTP_REQ_HDR) - { - return NULL; - } - - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return NULL; - } - struct tfe_http_half * in_req_half = session->req; - if(in_req_half == NULL) - return NULL; - struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; - if(in_req_spec == NULL) - return NULL; - - if (in_req_spec->url != NULL) - { - return in_req_spec->url; - } - return NULL; -} - -static int http_lua_log_debug(lua_State *L) -{ - int out_lua_argc=0, i=0; - lua_arg_t *out_lua_argv=NULL; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc < 1 || out_lua_argv == NULL) - { - return 0; - } - - char buff[TFE_STRING_MAX]={0}, *p = NULL; - p = buff; - for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%20s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); - - free_param_form_lua(out_lua_argc, out_lua_argv); - return 1; -} - -static int http_lua_log_info(lua_State *L) -{ - int out_lua_argc=0, i=0; - lua_arg_t *out_lua_argv=NULL; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc < 1 || out_lua_argv == NULL) - { - return 0; - } - - char buff[TFE_STRING_MAX]={0}, *p = NULL; - p = buff; - for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); - - free_param_form_lua(out_lua_argc, out_lua_argv); - return 1; -} - -static int http_lua_log_error(lua_State *L) -{ - int out_lua_argc=0, i=0; - lua_arg_t *out_lua_argv=NULL; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc < 1 || out_lua_argv == NULL) - { - return 0; - } - - char buff[TFE_STRING_MAX]={0}, *p = NULL; - p = buff; - for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); - - free_param_form_lua(out_lua_argc, out_lua_argv); - return 1; -} - -static int http_lua_get_method(lua_State *L) -{ - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - if(tfe_http_in_response(events)) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - - struct tfe_http_half * in_req_half = session->req; - struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; - - const char *method_str = http_std_method_to_string(in_req_spec->method); - if(method_str != NULL) - { - c_push_string_into_lua(L, method_str, strlen(method_str)); - } - - return 1; -} - -static int http_lua_get_uri(lua_State *L) -{ - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - if(tfe_http_in_response(events) || !tsg_ctx->http_req_uri) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - - struct tfe_http_half * in_req_half = session->req; - struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; - if (in_req_spec->uri != NULL) - { - c_push_string_into_lua(L, in_req_spec->uri, strlen(in_req_spec->uri)); - } - - return 1; -} - -static int http_lua_set_uri(lua_State *L) -{ - int out_lua_argc = 0; - lua_arg_t *out_lua_argv = NULL; - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc != 1 || out_lua_argv == NULL) - { - return 0; - } - - char * rewrite_uri = out_lua_argv[0].str; - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - if(tfe_http_in_response(events) || !tsg_ctx->http_req_uri) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - - struct tfe_http_half * in_req_half = session->req; - struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; - if (in_req_spec->uri != NULL) - { - tsg_ctx->execut_lua_sucess=1; - in_req_spec->uri = tfe_strdup(rewrite_uri); - } - free_param_form_lua(out_lua_argc, out_lua_argv); - - return 1; -} - -static int http_lua_get_status_code(lua_State *L) -{ - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - if(tfe_http_in_request(events)) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - struct tfe_http_half * in_resp_half = session->resp; - struct tfe_http_resp_spec * in_resp_spec = &in_resp_half->resp_spec; - - if (in_resp_spec != NULL) - { - c_push_num_into_lua(L, in_resp_spec->resp_code); - } - - return 1; -} - -static int http_lua_set_status_code(lua_State *L) -{ - int out_lua_argc = 0; - lua_arg_t *out_lua_argv = NULL; - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc != 1 || out_lua_argv == NULL) - { - return 0; - } - - int lua_resp_code = out_lua_argv[0].num; - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - if(tfe_http_in_request(events)) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - - struct tfe_http_half * in_resp_half = session->resp; - struct tfe_http_resp_spec * in_resp_spec = &in_resp_half->resp_spec; - - if(lua_resp_code != 0) - { - in_resp_spec->resp_code = lua_resp_code; - } - free_param_form_lua(out_lua_argc, out_lua_argv); - - return 1; -} - -static int http_lua_exit(lua_State *L) -{ - int out_lua_argc = 0; - lua_arg_t *out_lua_argv = NULL; - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc != 1 || out_lua_argv == NULL) - { - return 0; - } - - int exit_code = out_lua_argv[0].num; - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - if(exit_code == 0) - { - tsg_ctx->events = (enum tfe_http_event )0; - return 0; - } - - return 1; -} - -static int http_lua_get_current_stage(lua_State *L) -{ - const char * stage_name[] = {"http_req_uri", "http_req_header","http_req_body","http_resp_header","http_resp_body","http_stage_test"}; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - - //For test_http_lua - if(tsg_ctx->http_req_uri==2) - { - c_push_string_into_lua(L, stage_name[5], strlen(stage_name[5])); - return 1; - } - - if(events & EV_HTTP_REQ_HDR) - { - if(tsg_ctx->http_req_uri) - { - c_push_string_into_lua(L, stage_name[0], strlen(stage_name[0])); - } - else - { - c_push_string_into_lua(L, stage_name[1], strlen(stage_name[1])); - } - } - - if((events & EV_HTTP_REQ_BODY_BEGIN) | (events & EV_HTTP_REQ_BODY_END) | (events & EV_HTTP_REQ_BODY_CONT)) - { - c_push_string_into_lua(L, stage_name[2], strlen(stage_name[2])); - } - - if(events & EV_HTTP_RESP_HDR) - { - c_push_string_into_lua(L, stage_name[3], strlen(stage_name[3])); - } - - if((events & EV_HTTP_RESP_BODY_BEGIN) | (events & EV_HTTP_RESP_BODY_CONT) | (events & EV_HTTP_RESP_BODY_END)) - { - c_push_string_into_lua(L, stage_name[4], strlen(stage_name[4])); - } - - return 1; -} - -static int http_lua_get_headers(lua_State *L) -{ - int i=0; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - - struct tfe_http_half * in_req_half = session->req; - struct tfe_http_half * in_resp_half = session->resp; - - struct tfe_http_half * in_half = tfe_http_in_request(events) ? in_req_half : in_resp_half; - if(in_half == NULL) - { - return 0; - } - - struct http_field_name in_header_field{}; - const char * in_header_value = NULL; - void * iterator = NULL; - - const char *in_field_name[256], *in_field_value[256]; - - while (true) - { - if ((in_header_value = tfe_http_field_iterate(in_half, &iterator, &in_header_field)) == NULL) - { - break; - } - - in_field_name[i] = http_field_name_to_string(&in_header_field); - in_field_value[i] = in_header_value; - i++; - } - - c_push_table_into_lua(L, in_field_name, in_field_value, i); - - return 1; -} - -static int http_lua_set_headers(lua_State *L) -{ - int actually_write=0; - - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - const struct tfe_http_session * session = tsg_ctx->session; - if(session == NULL) - { - return 0; - } - enum tfe_http_event events = tsg_ctx->events; - - struct tfe_http_half * in_req_half = session->req; - struct tfe_http_half * in_resp_half = session->resp; - - struct tfe_http_half * in_half = tfe_http_in_request(events) ? in_req_half : in_resp_half; - if(in_half == NULL) - { - return 0; - } - - struct http_field_name in_header_field{}; - const char * in_header_value = NULL; - void * iterator = NULL; - - int out_lua_argc = 0; - lua_arg_t *out_lua_argv = NULL; - - const char *in_field_name; - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - if(out_lua_argc != 2 || out_lua_argv == NULL) - { - return 0; - } - - char *field_name=out_lua_argv[0].str, *field_value=out_lua_argv[1].str; - - if(field_name == NULL || field_value == NULL) - { - return 0; - } - - while (true) - { - if ((in_header_value = tfe_http_field_iterate(in_half, &iterator, &in_header_field)) == NULL) - { - break; - } - in_field_name = http_field_name_to_string(&in_header_field); - if(strcasecmp(in_field_name, field_name)==0 && strcasecmp(field_value, "nil")!=0) - { - if(in_header_field.field_id == TFE_HTTP_UNKNOWN_FIELD) - { - continue; - } - tfe_http_std_field_write(in_half, in_header_field.field_id, NULL); - tfe_http_std_field_write(in_half, in_header_field.field_id, field_value); - actually_write=1; - break; - } - - if(strcasecmp(http_field_name_to_string(&in_header_field), field_name)==0 && strcasecmp(field_value, "nil")==0) - { - if(in_header_field.field_id == TFE_HTTP_UNKNOWN_FIELD) - { - continue; - } - tfe_http_std_field_write(in_half, in_header_field.field_id, NULL); - actually_write=1; - break; - } - } - - if(actually_write ==1) - { - tsg_ctx->execut_lua_sucess=1; - } - - if(actually_write!=1 && strcasecmp(field_value, "nil")!=0) - { - tfe_http_nonstd_field_write(in_half, field_name, field_value); - tsg_ctx->execut_lua_sucess=1; - } - - free_param_form_lua(out_lua_argc, out_lua_argv); - return 0; -} - -static int http_lua_get_body(lua_State *L) -{ - struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - - if(tsg_ctx->http_body == NULL) - { - TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, "Can't to get req/resp body data"); - return 0; - } - - char * __http_body = (char *) evbuffer_pullup(tsg_ctx->http_body, -1); - size_t __http_body_len = evbuffer_get_length(tsg_ctx->http_body); - - c_push_string_into_lua(L, __http_body, __http_body_len); - - return 1; -} - -static int http_lua_set_body(lua_State *L) -{ - int i=0; - struct tsg_script_ctx *tsg_ctx= (struct tsg_script_ctx *)lua_get_userdata(L); - if(tsg_ctx == NULL) - { - return 0; - } - - int out_lua_argc = 0; - lua_arg_t *out_lua_argv = NULL; - - c_pull_param_from_lua(L, &out_lua_argc, &out_lua_argv); - - if(out_lua_argc < 1 || out_lua_argv == NULL) - { - return 0; - } - - tsg_ctx->http_lua_body = evbuffer_new(); - for(i=0; ihttp_lua_body, in, in_sz); - } - free_param_form_lua(out_lua_argc, out_lua_argv); - - return 0; -} - -lua_script_context http_lua_ctx_new(struct tsg_lua_script *lua_script, unsigned int thread_id) -{ - return lua_script_context_malloc(lua_script->http_lua_handle[thread_id]); -} - -void http_lua_ctx_free(struct tsg_lua_script *lua_script, unsigned int thread_id, lua_script_context lua_ctx) -{ - if(lua_ctx) - lua_script_context_free(lua_script->http_lua_handle[thread_id], lua_ctx); -} - -int http_lua_map_cache_script(tsg_lua_handle lua_handle, const char *profile_msg, size_t msg_len) -{ - return tsg_lua_cache_script(lua_handle, profile_msg, msg_len); -} - -void http_lua_inject_http_consts(tsg_lua_handle L) -{ - lua_register_function(L, NULL, "get_current_stage", http_lua_get_current_stage); - lua_register_function(L, NULL, "log_debug", http_lua_log_debug); - lua_register_function(L, NULL, "log_info", http_lua_log_info); - lua_register_function(L, NULL, "log_error", http_lua_log_error); - lua_register_function(L, NULL, "exit", http_lua_exit); -} - -void http_lua_inject_req_header_api(tsg_lua_handle L) -{ - lua_register_function(L, "req", "get_method", http_lua_get_method); - lua_register_function(L, "req", "get_uri", http_lua_get_uri); - lua_register_function(L, "req", "set_uri", http_lua_set_uri); - lua_register_function(L, "req", "get_headers", http_lua_get_headers); - lua_register_function(L, "req", "set_header", http_lua_set_headers); -} - -void http_lua_inject_req_body_api(tsg_lua_handle L) -{ - lua_register_function(L, "req", "get_body_data", http_lua_get_body); - lua_register_function(L, "req", "set_body_data", http_lua_set_body); -} - -void http_lua_inject_resp_header_api(tsg_lua_handle L) -{ - lua_register_function(L, "resp", "get_status_code", http_lua_get_status_code); - lua_register_function(L, "resp", "set_status_code", http_lua_set_status_code); - - lua_register_function(L, "resp", "get_headers", http_lua_get_headers); - lua_register_function(L, "resp", "set_header", http_lua_set_headers); -} - -void http_lua_inject_resp_body_api(tsg_lua_handle L) -{ - lua_register_function(L, "resp", "get_body_data", http_lua_get_body); - lua_register_function(L, "resp", "set_body_data", http_lua_set_body); -} - -void http_lua_inject_api(tsg_lua_handle L) -{ - http_lua_inject_http_consts(L); - http_lua_inject_req_header_api(L); - http_lua_inject_req_body_api(L); - http_lua_inject_resp_header_api(L); - http_lua_inject_resp_body_api(L); -} - -tsg_lua_handle *http_lua_handle_create(int thread_num, const char *name_space) -{ - int id=0; - tsg_lua_handle *http_lua_handle = NULL; - - http_lua_handle = (tsg_lua_handle *)ALLOC(tsg_lua_handle, thread_num); - if(http_lua_handle == NULL) - { - return NULL; - } - - for(id=0; id < thread_num; id++) - { - http_lua_handle[id] = tsg_lua_vm_create_with_name(name_space); - if(http_lua_handle[id] == NULL) - { - return NULL; - } - http_lua_inject_api(http_lua_handle[id]); - } - - return http_lua_handle; -} - -size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id, lua_script_context lua_ctx, unsigned int thread_id, void *user_data) -{ - int ret=0, timeout=0; - int *lua_script_id=NULL; - char *profile_msg; size_t msg_len; - - ret=lua_script->http_lua_profile(profile_id, &profile_msg, &msg_len, &lua_script_id, &timeout); - if(ret<0) - { - return ret; - } - - lua_data_t in; in.data = (char *)"tfe"; in.len = strlen(in.data); - lua_arg_t out; out.type = STRING; out.len = 1024; out.str = (char *)malloc(10); - - lua_data_t tsg_script_data; - tsg_script_data.data=profile_msg; - tsg_script_data.len=msg_len; - - if(lua_script->lua_is_cache==1) - { - ret=lua_cache_exec(lua_script->http_lua_handle[thread_id], lua_script_id[thread_id], in, user_data, lua_ctx, timeout, &out); - } - else - { - - ret=lua_exec(lua_script->http_lua_handle[thread_id], tsg_script_data, in, user_data, lua_ctx, timeout, &out); - } - - FREE(&out.str); - FREE(&profile_msg); - - return ret; -} - diff --git a/plugin/business/pangu-http/src/http_lua.h b/plugin/business/pangu-http/src/http_lua.h deleted file mode 100644 index b00e600..0000000 --- a/plugin/business/pangu-http/src/http_lua.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include - -#include - -#include "pattern_replace.h" -#include -#include - -struct tsg_lua_script -{ - int lua_is_cache; - tsg_lua_handle *http_lua_handle; - int (*http_lua_profile)(int profile_id, char **profile_msg, size_t *msg_len, int **script_id, int *timeout); -}; - -struct tsg_script_ctx -{ - int config_id; - int profile_id; - int http_req_uri; - int execut_lua_sucess; - lua_script_context lua_ctx; - enum tfe_http_event events; - void * local_logger; - const struct tfe_http_session *session; - struct tfe_http_half *replacing; - struct evbuffer *http_body; - struct evbuffer *http_lua_body; - int actually_executed; -}; - -lua_script_context http_lua_ctx_new(struct tsg_lua_script *lua_script, unsigned int thread_id); -void http_lua_ctx_free(struct tsg_lua_script *lua_script, unsigned int thread_id, lua_script_context lua_ctx); - -size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id, lua_script_context lua_ctx, unsigned int thread_id, void *user_data); -int http_lua_map_cache_script(tsg_lua_handle lua_handle, const char *profile_msg, size_t msg_len); -tsg_lua_handle *http_lua_handle_create(int thread_num, const char *name_space); - diff --git a/plugin/business/tsg-http/CMakeLists.txt b/plugin/business/tsg-http/CMakeLists.txt new file mode 100644 index 0000000..9c5fc9a --- /dev/null +++ b/plugin/business/tsg-http/CMakeLists.txt @@ -0,0 +1,23 @@ +add_library(tsg-http src/tsg_logger.cpp src/tsg_http.cpp src/pattern_replace.cpp src/tsg_web_cache.cpp src/edit_element.cpp src/http_lua.cpp) +target_include_directories(tsg-http PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +target_link_libraries(tsg-http PUBLIC common http tango-cache-client) +target_link_libraries(tsg-http PUBLIC rdkafka ctemplate-static cjson pcre2-static ratelimiter-static libdablooms pthread) +target_link_libraries(tsg-http PUBLIC maatframe tsglua) +target_link_libraries(tsg-http PUBLIC libxml2-static z) + +add_executable(test_pattern_replace test/test_pattern_replace.cpp src/pattern_replace.cpp) +target_include_directories(test_pattern_replace PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +target_link_libraries(test_pattern_replace common gtest pcre2-static) +file(COPY test/test_data DESTINATION ./) + +add_executable(test_edit_element test/test_edit_element.cpp src/edit_element.cpp) +target_include_directories(test_edit_element PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +target_link_libraries(test_edit_element common gtest pcre2-static libxml2-static z) + +add_executable(test_http_lua test/test_http_lua.cpp src/http_lua.cpp) +target_include_directories(test_http_lua PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +target_link_libraries(test_http_lua common gtest tsglua z) + +add_executable(replace_tool test/replace_tool.cpp src/pattern_replace.cpp) +target_include_directories(replace_tool PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +target_link_libraries(replace_tool common pcre2-static) diff --git a/plugin/business/pangu-http/src/edit_element.h b/plugin/business/tsg-http/include/edit_element.h similarity index 100% rename from plugin/business/pangu-http/src/edit_element.h rename to plugin/business/tsg-http/include/edit_element.h diff --git a/plugin/business/tsg-http/include/http_lua.h b/plugin/business/tsg-http/include/http_lua.h new file mode 100644 index 0000000..5f506cb --- /dev/null +++ b/plugin/business/tsg-http/include/http_lua.h @@ -0,0 +1,40 @@ +#pragma once +#include + +#include + +#include "pattern_replace.h" +#include +#include + +struct tsg_lua_script +{ + int lua_is_cache; + struct elua_vm **http_lua_handle; + int (*http_lua_profile)(int profile_id, struct elua_script ***elua_ctx); +}; + +struct tsg_script_ctx +{ + int config_id; + int profile_id; + int http_req_uri; + char *rewrite_uri; + int execut_lua_sucess; + struct elua_context *elua_ctx; + enum tfe_http_event events; + void * local_logger; + const struct tfe_http_session *session; + struct tfe_http_half *replacing; + struct evbuffer *http_body; + struct evbuffer *http_lua_body; + int actually_executed; +}; + +struct elua_context * http_lua_ctx_new(struct tsg_lua_script *lua_script, unsigned int thread_id); +void http_lua_ctx_free(struct tsg_lua_script *lua_script, unsigned int thread_id, struct elua_context * lua_ctx); +struct elua_script *http_lua_map_cache_script(struct elua_vm *vm, const char *script, size_t script_len, size_t timeout_ms); + +size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id, struct elua_context * lua_ctx, unsigned int thread_id, void *user_data); +int http_lua_handle_create(struct tsg_lua_script *lua_script, int thread_num, const char *name_space); + diff --git a/plugin/business/pangu-http/src/pattern_replace.h b/plugin/business/tsg-http/include/pattern_replace.h similarity index 100% rename from plugin/business/pangu-http/src/pattern_replace.h rename to plugin/business/tsg-http/include/pattern_replace.h diff --git a/plugin/business/pangu-http/src/pangu_logger.h b/plugin/business/tsg-http/include/tsg_proxy_logger.h similarity index 73% rename from plugin/business/pangu-http/src/pangu_logger.h rename to plugin/business/tsg-http/include/tsg_proxy_logger.h index 8de3cdc..182485b 100644 --- a/plugin/business/pangu-http/src/pangu_logger.h +++ b/plugin/business/tsg-http/include/tsg_proxy_logger.h @@ -4,7 +4,7 @@ #include #include -struct pangu_log +struct proxy_log { const struct tfe_stream *stream; const struct tfe_http_session* http; @@ -18,11 +18,11 @@ struct pangu_log char *location_client; char *location_server; }; -struct pangu_logger; -struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger); +struct proxy_logger; +struct proxy_logger* proxy_log_handle_create(const char* profile, const char* section, void* local_logger); //return 0 if SUCCESS, otherwise return -1 -int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg); +int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg); diff --git a/plugin/business/pangu-http/src/pangu_web_cache.h b/plugin/business/tsg-http/include/tsg_proxy_web_cache.h similarity index 100% rename from plugin/business/pangu-http/src/pangu_web_cache.h rename to plugin/business/tsg-http/include/tsg_proxy_web_cache.h diff --git a/plugin/business/pangu-http/src/edit_element.cpp b/plugin/business/tsg-http/src/edit_element.cpp similarity index 97% rename from plugin/business/pangu-http/src/edit_element.cpp rename to plugin/business/tsg-http/src/edit_element.cpp index 988ba6e..a24b202 100644 --- a/plugin/business/pangu-http/src/edit_element.cpp +++ b/plugin/business/tsg-http/src/edit_element.cpp @@ -39,6 +39,14 @@ int match_start_indicator(xmlNodePtr parent, char * start_indicator) { if(parent->properties == NULL) { + if(parent->name == NULL) + { + return 0; + } + if(!strcasecmp((char *)parent->name, start_indicator)) + { + return 1; + } return 0; } @@ -57,6 +65,30 @@ int match_start_indicator(xmlNodePtr parent, char * start_indicator) return 0; } +#if 0 +int match_start_indicator(xmlNodePtr parent, char * start_indicator) +{ + if(parent->properties == NULL) + { + return 0; + } + + struct _xmlAttr *properties = parent->properties; + if(properties->children == NULL || properties->children->content == NULL) + { + return 0; + } + + xmlNodePtr children = properties->children; + if(!strcasecmp((char *)children->content, start_indicator)) + { + return 1; + } + + return 0; +} +#endif + #if 0 int match_string(const char * in, size_t in_sz, char *contained_keyword) { diff --git a/plugin/business/tsg-http/src/http_lua.cpp b/plugin/business/tsg-http/src/http_lua.cpp new file mode 100644 index 0000000..b7bfb82 --- /dev/null +++ b/plugin/business/tsg-http/src/http_lua.cpp @@ -0,0 +1,775 @@ +#include "pattern_replace.h" +#include "http_lua.h" + +#include +#include + +#include +#include +#include +#include +#include + +static const char __attribute__((__unused__))*http_lua_log_get_url(struct tsg_script_ctx *tsg_ctx) +{ + enum tfe_http_event events = tsg_ctx->events; + if(events < EV_HTTP_REQ_HDR) + { + return NULL; + } + + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return NULL; + } + struct tfe_http_half * in_req_half = session->req; + if(in_req_half == NULL) + return NULL; + struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; + if(in_req_spec == NULL) + return NULL; + + if (in_req_spec->url != NULL) + { + return in_req_spec->url; + } + return NULL; +} + +static int http_get_param_from_lua(struct elua_vm *vm, struct elua_data **out_lua_argv) +{ + int i=0, out_lua_argc=0; + struct elua_data *lua_argv=NULL; + + out_lua_argc = elua_cbinding_get_input_params_num(vm); + if(out_lua_argc <= 0) + { + return 0; + } + + lua_argv = ALLOC(struct elua_data, out_lua_argc); + for (i = 0; i < out_lua_argc; i++) + { + elua_cbinding_get_input_param(vm, i+1, &lua_argv[i]); + } + *out_lua_argv = lua_argv; + + return out_lua_argc; +} + +void http_free_params(struct elua_data *out_lua_argv) +{ + if(out_lua_argv) + FREE(&out_lua_argv); +} + +int http_set_string_to_lua(struct elua_vm *vm, const char *buff, size_t len) +{ + struct elua_data edata; + edata.type = STRING; + edata.buff = (char *)buff; + edata.len = len; + elua_cbinding_append_output_params(vm, &edata, 1); + return 1; +} + +int http_set_num_to_lua(struct elua_vm *vm, long num) +{ + struct elua_data retvalue; + retvalue.type = INTEGER; + retvalue.len = sizeof(long); + retvalue.integer = num; + elua_cbinding_append_output_params(vm, &retvalue, 1); + return 1; +} + +int http_set_table_to_lua(struct elua_vm *vm, struct elua_table *table) +{ + struct elua_data retvalue; + retvalue.type = TABLE; + retvalue.table = table; + retvalue.len = sizeof(struct elua_data); + elua_cbinding_append_output_params(vm, &retvalue, 1); + elua_destroy_table(table); + return 1; +} + +static int http_lua_log_debug(struct elua_vm *vm) +{ + int out_lua_argc=0, i=0; + struct elua_data *out_lua_argv=NULL; + + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc < 1 || out_lua_argv == NULL) + { + return 0; + } + + char buff[TFE_STRING_MAX]={0}, *p = NULL; + p = buff; + for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%20s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); + + http_free_params(out_lua_argv); + return 1; +} + +static int http_lua_log_info(struct elua_vm *vm) +{ + int out_lua_argc=0, i=0; + struct elua_data *out_lua_argv=NULL; + + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc < 1 || out_lua_argv == NULL) + { + return 0; + } + + char buff[TFE_STRING_MAX]={0}, *p = NULL; + p = buff; + for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); + + http_free_params(out_lua_argv); + return 1; +} + +static int http_lua_log_error(struct elua_vm *vm) +{ + int out_lua_argc=0, i=0; + struct elua_data *out_lua_argv=NULL; + + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc < 1 || out_lua_argv == NULL) + { + return 0; + } + + char buff[TFE_STRING_MAX]={0}, *p = NULL; + p = buff; + for(i=0; ilocal_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, buff); + + http_free_params(out_lua_argv); + return 1; +} + +static int http_lua_get_method(struct elua_vm *vm) +{ + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + if(tfe_http_in_response(events)) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + + struct tfe_http_half * in_req_half = session->req; + struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; + + const char *method_str = http_std_method_to_string(in_req_spec->method); + if(method_str != NULL) + { + http_set_string_to_lua(vm, method_str, strlen(method_str)); + } + + return 1; +} + +static int http_lua_get_uri(struct elua_vm *vm) +{ + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + if(tfe_http_in_response(events) || !tsg_ctx->http_req_uri) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + + struct tfe_http_half * in_req_half = session->req; + struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; + if (in_req_spec->uri != NULL) + { + http_set_string_to_lua(vm, in_req_spec->uri, strlen(in_req_spec->uri)); + } + + return 1; +} + +static int http_lua_set_uri(struct elua_vm *vm) +{ + int out_lua_argc = 0; + struct elua_data *out_lua_argv = NULL; + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc != 1 || out_lua_argv == NULL) + { + return 0; + } + + char * rewrite_uri = out_lua_argv[0].buff; + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + if(tfe_http_in_response(events) || !tsg_ctx->http_req_uri) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + + struct tfe_http_half * in_req_half = session->req; + struct tfe_http_req_spec * in_req_spec = &in_req_half->req_spec; + if (in_req_spec->uri != NULL) + { + tsg_ctx->execut_lua_sucess=1; + tsg_ctx->rewrite_uri = tfe_strdup(rewrite_uri); + } + http_free_params(out_lua_argv); + + return 1; +} + +static int http_lua_get_status_code(struct elua_vm *vm) +{ + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + if(tfe_http_in_request(events)) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + struct tfe_http_half * in_resp_half = session->resp; + struct tfe_http_resp_spec * in_resp_spec = &in_resp_half->resp_spec; + + if (in_resp_spec != NULL) + { + http_set_num_to_lua(vm, in_resp_spec->resp_code); + } + + return 1; +} + +static int http_lua_set_status_code(struct elua_vm *vm) +{ + int out_lua_argc = 0; + struct elua_data *out_lua_argv = NULL; + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc != 1 || out_lua_argv == NULL) + { + return 0; + } + + int lua_resp_code = out_lua_argv[0].integer; + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + if(tfe_http_in_request(events)) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + + struct tfe_http_half * in_resp_half = session->resp; + struct tfe_http_resp_spec * in_resp_spec = &in_resp_half->resp_spec; + + if(lua_resp_code != 0) + { + in_resp_spec->resp_code = lua_resp_code; + } + http_free_params(out_lua_argv); + + return 1; +} + +static int http_lua_exit(struct elua_vm *vm) +{ + int out_lua_argc = 0; + struct elua_data *out_lua_argv = NULL; + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc != 1 || out_lua_argv == NULL) + { + return 0; + } + + int exit_code = out_lua_argv[0].integer; + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + if(exit_code == 0) + { + tsg_ctx->events = (enum tfe_http_event )0; + return 0; + } + http_free_params(out_lua_argv); + + return 1; +} + +static int http_lua_get_current_stage(struct elua_vm *vm) +{ + const char * stage_name[] = {"http_req_uri", "http_req_header","http_req_body","http_resp_header","http_resp_body","http_stage_test"}; + + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + + //For test_http_lua + if(tsg_ctx->http_req_uri==2) + { + http_set_string_to_lua(vm, stage_name[5], strlen(stage_name[5])); + return 1; + } + + if(events & EV_HTTP_REQ_HDR) + { + if(tsg_ctx->http_req_uri) + { + http_set_string_to_lua(vm, stage_name[0], strlen(stage_name[0])); + } + else + { + http_set_string_to_lua(vm, stage_name[1], strlen(stage_name[1])); + } + } + + if((events & EV_HTTP_REQ_BODY_BEGIN) | (events & EV_HTTP_REQ_BODY_END) | (events & EV_HTTP_REQ_BODY_CONT)) + { + http_set_string_to_lua(vm, stage_name[2], strlen(stage_name[2])); + } + + if(events & EV_HTTP_RESP_HDR) + { + http_set_string_to_lua(vm, stage_name[3], strlen(stage_name[3])); + } + + if((events & EV_HTTP_RESP_BODY_BEGIN) | (events & EV_HTTP_RESP_BODY_CONT) | (events & EV_HTTP_RESP_BODY_END)) + { + http_set_string_to_lua(vm, stage_name[4], strlen(stage_name[4])); + } + + return 1; +} + +static int http_lua_get_headers(struct elua_vm *vm) +{ + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + + struct tfe_http_half * in_req_half = session->req; + struct tfe_http_half * in_resp_half = session->resp; + + struct tfe_http_half * in_half = tfe_http_in_request(events) ? in_req_half : in_resp_half; + if(in_half == NULL) + { + return 0; + } + + struct http_field_name in_header_field{}; + const char * in_header_value = NULL; + void * iterator = NULL; + + struct elua_data in_field_name, in_field_value; + struct elua_table *table = elua_create_table(vm); + in_field_name.type = STRING; + in_field_value.type = STRING; + + while (true) + { + if ((in_header_value = tfe_http_field_iterate(in_half, &iterator, &in_header_field)) == NULL) + { + break; + } + + in_field_name.buff = (char *)http_field_name_to_string(&in_header_field); + in_field_name.len = strlen(http_field_name_to_string(&in_header_field)); + + in_field_value.buff = (char *)in_header_value; + in_field_value.len = strlen(in_header_value); + elua_add_table(table, &in_field_name, &in_field_value); + } + + http_set_table_to_lua(vm, table); + + return 1; +} + +static int http_lua_set_headers(struct elua_vm *vm) +{ + int actually_write=0; + + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + const struct tfe_http_session * session = tsg_ctx->session; + if(session == NULL) + { + return 0; + } + enum tfe_http_event events = tsg_ctx->events; + + struct tfe_http_half * in_req_half = session->req; + struct tfe_http_half * in_resp_half = session->resp; + + struct tfe_http_half * in_half = tfe_http_in_request(events) ? in_req_half : in_resp_half; + if(in_half == NULL) + { + return 0; + } + + struct http_field_name in_header_field{}; + const char * in_header_value = NULL; + void * iterator = NULL; + + int out_lua_argc = 0; + struct elua_data *out_lua_argv = NULL; + + const char *in_field_name; + + out_lua_argc = http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc != 2 || out_lua_argv == NULL) + { + return 0; + } + + char *field_name=out_lua_argv[0].buff, *field_value=out_lua_argv[1].buff; + + if(field_name == NULL || field_value == NULL) + { + return 0; + } + + while (true) + { + if ((in_header_value = tfe_http_field_iterate(in_half, &iterator, &in_header_field)) == NULL) + { + break; + } + in_field_name = http_field_name_to_string(&in_header_field); + if(strcasecmp(in_field_name, field_name)==0 && strcasecmp(field_value, "nil")!=0) + { + if(in_header_field.field_id == TFE_HTTP_UNKNOWN_FIELD) + { + continue; + } + tfe_http_std_field_write(in_half, in_header_field.field_id, NULL); + tfe_http_std_field_write(in_half, in_header_field.field_id, field_value); + actually_write=1; + break; + } + + if(strcasecmp(http_field_name_to_string(&in_header_field), field_name)==0 && strcasecmp(field_value, "nil")==0) + { + if(in_header_field.field_id == TFE_HTTP_UNKNOWN_FIELD) + { + continue; + } + tfe_http_std_field_write(in_half, in_header_field.field_id, NULL); + actually_write=1; + break; + } + } + + if(actually_write ==1) + { + tsg_ctx->execut_lua_sucess=1; + } + + if(actually_write!=1 && strcasecmp(field_value, "nil")!=0) + { + tfe_http_nonstd_field_write(in_half, field_name, field_value); + tsg_ctx->execut_lua_sucess=1; + } + + http_free_params(out_lua_argv); + return 0; +} + +static int http_lua_get_body(struct elua_vm *vm) +{ + struct tsg_script_ctx *tsg_ctx = (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + + if(tsg_ctx->http_body == NULL) + { + TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%d, profile_id:%d, message:%s", tsg_ctx->config_id, tsg_ctx->profile_id, "Can't to get req/resp body data"); + return 0; + } + + char * __http_body = (char *) evbuffer_pullup(tsg_ctx->http_body, -1); + size_t __http_body_len = evbuffer_get_length(tsg_ctx->http_body); + + http_set_string_to_lua(vm, __http_body, __http_body_len); + + return 1; +} + +static int http_lua_set_body(struct elua_vm *vm) +{ + int i=0; + struct tsg_script_ctx *tsg_ctx= (struct tsg_script_ctx *)elua_get_execute_userdata(vm); + if(tsg_ctx == NULL) + { + return 0; + } + + int out_lua_argc = 0; + struct elua_data *out_lua_argv = NULL; + + out_lua_argc=http_get_param_from_lua(vm, &out_lua_argv); + if(out_lua_argc < 1 || out_lua_argv == NULL) + { + return 0; + } + + tsg_ctx->http_lua_body = evbuffer_new(); + for(i=0; ihttp_lua_body, in, in_sz); + } + http_free_params(out_lua_argv); + + return 0; +} + +struct elua_context *http_lua_ctx_new(struct tsg_lua_script *lua_script, unsigned int thread_id) +{ + return elua_create_context(lua_script->http_lua_handle[thread_id], "context"); +} + +struct elua_script *http_lua_map_cache_script(struct elua_vm *vm, const char *script, size_t script_len, size_t timeout_ms) +{ + return elua_cache_script(vm, script, script_len, timeout_ms); +} + +void http_lua_ctx_free(struct tsg_lua_script *lua_script, unsigned int thread_id, struct elua_context *elua_ctx) +{ + if(elua_ctx) + elua_destroy_context(elua_ctx); +} + +void http_lua_inject_http_consts(struct elua_vm *vm) +{ + elua_register_cbinding(vm, NULL, "get_current_stage", http_lua_get_current_stage); + elua_register_cbinding(vm, NULL, "log_debug", http_lua_log_debug); + elua_register_cbinding(vm, NULL, "log_info", http_lua_log_info); + elua_register_cbinding(vm, NULL, "log_error", http_lua_log_error); + elua_register_cbinding(vm, NULL, "exit", http_lua_exit); +} + +void http_lua_inject_req_header_api(struct elua_vm *vm) +{ + elua_register_cbinding(vm, "req", "get_method", http_lua_get_method); + elua_register_cbinding(vm, "req", "get_uri", http_lua_get_uri); + elua_register_cbinding(vm, "req", "set_uri", http_lua_set_uri); + elua_register_cbinding(vm, "req", "get_headers", http_lua_get_headers); + elua_register_cbinding(vm, "req", "set_header", http_lua_set_headers); +} + +void http_lua_inject_req_body_api(struct elua_vm *vm) +{ + elua_register_cbinding(vm, "req", "get_body_data", http_lua_get_body); + elua_register_cbinding(vm, "req", "set_body_data", http_lua_set_body); +} + +void http_lua_inject_resp_header_api(struct elua_vm *vm) +{ + elua_register_cbinding(vm, "resp", "get_status_code", http_lua_get_status_code); + elua_register_cbinding(vm, "resp", "set_status_code", http_lua_set_status_code); + + elua_register_cbinding(vm, "resp", "get_headers", http_lua_get_headers); + elua_register_cbinding(vm, "resp", "set_header", http_lua_set_headers); +} + +void http_lua_inject_resp_body_api(struct elua_vm *vm) +{ + elua_register_cbinding(vm, "resp", "get_body_data", http_lua_get_body); + elua_register_cbinding(vm, "resp", "set_body_data", http_lua_set_body); +} + +void http_lua_inject_api(struct elua_vm *vm) +{ + http_lua_inject_http_consts(vm); + http_lua_inject_req_header_api(vm); + http_lua_inject_req_body_api(vm); + http_lua_inject_resp_header_api(vm); + http_lua_inject_resp_body_api(vm); +} + +int http_lua_handle_create(struct tsg_lua_script *lua_script, int thread_num, const char *name_space) +{ + int id=0; + struct elua_vm **http_lua_handle = NULL; + + http_lua_handle = ALLOC(struct elua_vm *, thread_num); + if(http_lua_handle == NULL) + { + return 0; + } + + for(id=0; id < thread_num; id++) + { + http_lua_handle[id] = elua_create_vm(name_space); + if(http_lua_handle[id] == NULL) + { + goto finish; + } + http_lua_inject_api(http_lua_handle[id]); + } + lua_script->http_lua_handle=http_lua_handle; + + return 1; +finish: + for(id=0; id < thread_num; id++) + { + if(http_lua_handle[id]) + FREE(&http_lua_handle[id]) + } + free(http_lua_handle); + return 0; +} + +size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id, struct elua_context *elua_ctx, unsigned int thread_id, void *user_data) +{ + int ret=0; + struct elua_script **escript=NULL; + + ret=lua_script->http_lua_profile(profile_id, &escript); + if(ret<0) + { + return ret; + } + + const char *input="tfe"; + size_t input_len=strlen(input); + + ret=elua_execute_script(escript[thread_id], input, input_len, user_data, elua_ctx, NULL); + if(ret !=0 ) + { + struct tsg_script_ctx *tsg_ctx= (struct tsg_script_ctx *)user_data; + if(tsg_ctx != NULL && tsg_ctx->local_logger != NULL) + { + TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%d, profile_id:%d, error_code:%d, error: %s", tsg_ctx->config_id, tsg_ctx->profile_id, ret, elua_get_last_error_string(lua_script->http_lua_handle[thread_id])); + } + } + return ret; +} + diff --git a/plugin/business/pangu-http/src/pattern_replace.cpp b/plugin/business/tsg-http/src/pattern_replace.cpp similarity index 100% rename from plugin/business/pangu-http/src/pattern_replace.cpp rename to plugin/business/tsg-http/src/pattern_replace.cpp diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/tsg-http/src/tsg_http.cpp similarity index 82% rename from plugin/business/pangu-http/src/pangu_http.cpp rename to plugin/business/tsg-http/src/tsg_http.cpp index 6e4e01e..97f2d1d 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/tsg-http/src/tsg_http.cpp @@ -1,8 +1,8 @@ -#include "pangu_logger.h" +#include "tsg_proxy_logger.h" #include "edit_element.h" #include "pattern_replace.h" #include "http_lua.h" -#include "pangu_web_cache.h" +#include "tsg_proxy_web_cache.h" #include #include @@ -34,18 +34,18 @@ #define MAX_EDIT_ZONE_NUM 64 -enum pangu_action //Bigger action number is prior. +enum proxy_action //Bigger action number is prior. { - PG_ACTION_NONE = 0x00, - PG_ACTION_MONIT = 0x01, - PG_ACTION_FORWARD = 0x02, /* N/A */ - PG_ACTION_REJECT = 0x10, - PG_ACTION_DROP = 0x20, /* N/A */ - PG_ACTION_MANIPULATE = 0x30, - PG_ACTION_RATELIMIT = 0x40, /* N/A */ - PG_ACTION_LOOP = 0x60, /* N/A */ - PG_ACTION_WHITELIST = 0x80, - __PG_ACTION_MAX + PX_ACTION_NONE = 0x00, + PX_ACTION_MONIT = 0x01, + PX_ACTION_FORWARD = 0x02, /* N/A */ + PX_ACTION_REJECT = 0x10, + PX_ACTION_DROP = 0x20, /* N/A */ + PX_ACTION_MANIPULATE = 0x30, + PX_ACTION_RATELIMIT = 0x40, /* N/A */ + PX_ACTION_LOOP = 0x60, /* N/A */ + PX_ACTION_WHITELIST = 0x80, + __PX_ACTION_MAX }; enum manipulate_action @@ -73,7 +73,7 @@ enum scan_table __SCAN_TABLE_MAX }; -enum pangu_http_stat +enum proxy_http_stat { STAT_SESSION, STAT_LOG_NUM, @@ -89,7 +89,7 @@ enum pangu_http_stat STAT_ACTION_RUN_SCRIPT, STAT_ACTION_WHITELSIT, STAT_SUSPENDING, - __PG_STAT_MAX + __PX_STAT_MAX }; enum manipulate_profile_table @@ -110,7 +110,7 @@ struct manipulate_profile char *profile_msg; char *profile_type; char *profile_position; - int *script_id; + struct elua_script **escript_ctx; int timeout; ctemplate::Template * tpl; pthread_mutex_t lock; @@ -137,10 +137,10 @@ struct policy_action_param pthread_mutex_t lock; }; -struct pangu_rt +struct tsg_proxy_rt { Maat_feather_t maat; - struct pangu_logger * send_logger; + struct proxy_logger * send_logger; void * local_logger; int thread_num; int scan_table_id[__SCAN_TABLE_MAX]; @@ -154,8 +154,8 @@ struct pangu_rt struct cache_handle* cache; screen_stat_handle_t fs_handle; - long long stat_val[__PG_STAT_MAX]; - int fs_id[__PG_STAT_MAX]; + long long stat_val[__PX_STAT_MAX]; + int fs_id[__PX_STAT_MAX]; struct event_base* gc_evbase; struct event* gcev; @@ -167,24 +167,24 @@ struct pangu_rt int ca_store_reseting; int enable_plugin; }; -struct pangu_rt * g_pangu_rt; +struct tsg_proxy_rt * g_proxy_rt; -static void pangu_http_gc_cb(evutil_socket_t fd, short what, void * arg) +static void proxy_http_gc_cb(evutil_socket_t fd, short what, void * arg) { int i=0; - for(i=0;i<__PG_STAT_MAX;i++) + for(i=0;i<__PX_STAT_MAX;i++) { - FS_operate(g_pangu_rt->fs_handle, g_pangu_rt->fs_id[i], 0, FS_OP_SET, ATOMIC_READ(&(g_pangu_rt->stat_val[i]))); + FS_operate(g_proxy_rt->fs_handle, g_proxy_rt->fs_id[i], 0, FS_OP_SET, ATOMIC_READ(&(g_proxy_rt->stat_val[i]))); } return; } -static void pangu_http_stat_init(struct pangu_rt * pangu_runtime) +static void proxy_http_stat_init(struct tsg_proxy_rt * pangu_runtime) { int i=0; struct timeval gc_delay = {0, 500*1000}; //Microseconds, we set 500 miliseconds here. - const char* spec[__PG_STAT_MAX]={0}; + const char* spec[__PX_STAT_MAX]={0}; spec[STAT_SESSION]="http_sess"; spec[STAT_LOG_NUM]="log_num"; spec[STAT_ACTION_MONIT]="intcp_mon_num"; @@ -200,34 +200,34 @@ static void pangu_http_stat_init(struct pangu_rt * pangu_runtime) spec[STAT_ACTION_WHITELSIT]="intcp_allow_num"; spec[STAT_SUSPENDING]="suspending"; - for(i=0;i<__PG_STAT_MAX;i++) + for(i=0;i<__PX_STAT_MAX;i++) { if(spec[i]!=NULL) { pangu_runtime->fs_id[i]=FS_register(pangu_runtime->fs_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, spec[i]); } } - g_pangu_rt->gcev = event_new(pangu_runtime->gc_evbase, -1, EV_PERSIST, pangu_http_gc_cb, NULL); - evtimer_add(g_pangu_rt->gcev, &gc_delay); + g_proxy_rt->gcev = event_new(pangu_runtime->gc_evbase, -1, EV_PERSIST, proxy_http_gc_cb, NULL); + evtimer_add(g_proxy_rt->gcev, &gc_delay); return; } void increase_redirect_policy_hit_num(void) { - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REDIRECT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_REDIRECT])); } void trusted_CA_update_start_cb(int update_type, void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - if(g_pangu_rt->ca_store_reseting==0) + if(g_proxy_rt->ca_store_reseting==0) { tfe_proxy_ssl_reset_trust_ca(); - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store Reset Start."); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store Reset Start."); } - g_pangu_rt->ca_store_reseting++; + g_proxy_rt->ca_store_reseting++; } } @@ -238,7 +238,7 @@ void trusted_CA_update_cert_cb(int table_id, const char* table_line, void* u_par ret=sscanf(table_line, "%d\t%s\t%s\t%d", &cfg_id, cert_name, cert_file, &is_valid); if(ret!=4) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store parse cert config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store parse cert config failed: %s", table_line); return; } if(is_valid==1) @@ -246,11 +246,11 @@ void trusted_CA_update_cert_cb(int table_id, const char* table_line, void* u_par ret=tfe_proxy_ssl_add_trust_ca(cert_file); if(ret<0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store add cert failed %d:%s:%s", cfg_id, cert_name, cert_file); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store add cert failed %d:%s:%s", cfg_id, cert_name, cert_file); } else { - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store add cert success %d:%s:%s", cfg_id, cert_name, cert_file); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store add cert success %d:%s:%s", cfg_id, cert_name, cert_file); } } else @@ -258,11 +258,11 @@ void trusted_CA_update_cert_cb(int table_id, const char* table_line, void* u_par ret=tfe_proxy_ssl_del_trust_ca(cert_file); if(ret<0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store del cert failed %d:%s:%s", cfg_id, cert_name, cert_file); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store del cert failed %d:%s:%s", cfg_id, cert_name, cert_file); } else { - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store del cert success %d:%s:%s", cfg_id, cert_name, cert_file); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store del cert success %d:%s:%s", cfg_id, cert_name, cert_file); } } return; @@ -274,7 +274,7 @@ void trusted_CA_update_crl_cb(int table_id,const char* table_line,void* u_para) ret=sscanf(table_line, "%d\t%d\t%s\t%d", &crl_id, &cert_id, crl_file, &is_valid); if(ret!=4) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store parse crl config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store parse crl config failed: %s", table_line); return; } if(is_valid==1) @@ -282,11 +282,11 @@ void trusted_CA_update_crl_cb(int table_id,const char* table_line,void* u_para) ret=tfe_proxy_ssl_add_crl(crl_file); if(ret<0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store add crl failed %d:%d:%s", crl_id, cert_id, crl_file); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store add crl failed %d:%d:%s", crl_id, cert_id, crl_file); } else { - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store add crl success %d:%d:%s", crl_id, cert_id, crl_file); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store add crl success %d:%d:%s", crl_id, cert_id, crl_file); } } else @@ -294,24 +294,24 @@ void trusted_CA_update_crl_cb(int table_id,const char* table_line,void* u_para) ret=tfe_proxy_ssl_del_crl(crl_file); if(ret<0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Trusted CA Store del crl failed %d:%d:%s", crl_id, cert_id, crl_file); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Trusted CA Store del crl failed %d:%d:%s", crl_id, cert_id, crl_file); } else { - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store del crl success %d:%d:%s", crl_id, cert_id, crl_file); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store del crl success %d:%d:%s", crl_id, cert_id, crl_file); } } return; } void trusted_CA_update_finish_cb(void* u_para) { - if(g_pangu_rt->ca_store_reseting>0) + if(g_proxy_rt->ca_store_reseting>0) { - g_pangu_rt->ca_store_reseting--; - if(g_pangu_rt->ca_store_reseting==0) + g_proxy_rt->ca_store_reseting--; + if(g_proxy_rt->ca_store_reseting==0) { tfe_proxy_ssl_reset_trust_ca_finish(); - TFE_LOG_INFO(g_pangu_rt->local_logger, "Trusted CA Store Reset Finish."); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Trusted CA Store Reset Finish."); } } } @@ -337,6 +337,42 @@ static enum manipulate_action manipulate_action_str2idx(const char *action_str) return (enum manipulate_action)i; } +void octal_utf8_escapes(char *input) +{ +#define AFMTSIZE (67+2+1+2) + char afmt [AFMTSIZE]; + int num,NConsumed,last,lbuf_sz=0; + + const char *fmt ="\\%3lo"; + snprintf(afmt,AFMTSIZE,"%s%%n",fmt); + + char lbuf[1024]={0}; + snprintf(lbuf, sizeof(lbuf), "%s", input); + lbuf_sz = strlen(lbuf); + + last = lbuf_sz - 1; + if(lbuf[last] == '\n') + { + lbuf[last] = '\0'; + last--; + } + + char *iptr = input; + while (*iptr) + { + if((last = sscanf(iptr,afmt,&num, &NConsumed)) > 0) + { + putchar(num); + iptr+=NConsumed; + } + else + { + iptr+=1; + } + } + return; +} + void policy_action_param_new(int idx, const struct Maat_rule_t* rule, const char* srv_def_large, MAAT_RULE_EX_DATA* ad, long argl, void *argp) { @@ -347,7 +383,7 @@ void policy_action_param_new(int idx, const struct Maat_rule_t* rule, const char { return; } - if((unsigned char)rule->action!=PG_ACTION_MANIPULATE&&(unsigned char)rule->action!=PG_ACTION_REJECT) + if((unsigned char)rule->action!=PX_ACTION_MANIPULATE&&(unsigned char)rule->action!=PX_ACTION_REJECT) { return; } @@ -356,14 +392,14 @@ void policy_action_param_new(int idx, const struct Maat_rule_t* rule, const char json=cJSON_Parse(srv_def_large); if(json==NULL) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "invalid policy parameter: id = %d", rule->config_id); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "invalid policy parameter: id = %d", rule->config_id); return; } item=cJSON_GetObjectItem(json, "protocol"); if(unlikely(!item || !cJSON_IsString(item))) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Invalid policy parameter: %d invalid protocol format", rule->config_id); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Invalid policy parameter: %d invalid protocol format", rule->config_id); goto error_out; } if(0!=strcasecmp(item->valuestring, "http")) @@ -449,7 +485,9 @@ void policy_action_param_new(int idx, const struct Maat_rule_t* rule, const char break; } param->repl_rule[rule_id].find = tfe_strdup(cJSON_GetObjectItem(item , "find")->valuestring); + octal_utf8_escapes(param->repl_rule[rule_id].find); param->repl_rule[rule_id].replace_with = tfe_strdup(cJSON_GetObjectItem(item , "replace_with")->valuestring); + octal_utf8_escapes(param->repl_rule[rule_id].replace_with); rule_id++; } param->n_rule = rule_id; @@ -545,7 +583,7 @@ void policy_action_param_new(int idx, const struct Maat_rule_t* rule, const char break; } *ad=param; - TFE_LOG_INFO(g_pangu_rt->local_logger, "Add ctrl policy: %d", rule->config_id); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Add ctrl policy: %d", rule->config_id); error_out: cJSON_Delete(json); return; @@ -625,7 +663,7 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li ret=sscanf(table_line, "%d\t%s\t%s\t%s\t%d", &profile_id, profile_name, formate, profile_path, &is_valid); if(ret!=5) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Policy table parse config failed: %s", table_line); return; } @@ -644,13 +682,13 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li ply_profile->profile_msg = tfe_read_file(profile_path, &ply_profile->msg_len); if (ply_profile->profile_msg == NULL) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); } } ply_profile->profile_name=tfe_strdup(profile_name); ply_profile->profile_type=tfe_strdup(formate); - TFE_LOG_INFO(g_pangu_rt->local_logger, "Policy table add success %d", profile_id); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Policy table add success %d", profile_id); *ad = ply_profile; return; @@ -665,7 +703,7 @@ void ma_insert_profile_table_new_cb(int table_id, const char* key, const char* t ret=sscanf(table_line, "%d\t%s\t%s\t%s\t%s\t%d", &profile_id, profile_name, formate, profile_path, profile_position, &is_valid); if(ret!=6) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Policy table parse config failed: %s", table_line); return; } struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1); @@ -683,14 +721,14 @@ void ma_insert_profile_table_new_cb(int table_id, const char* key, const char* t ply_profile->profile_msg = tfe_read_file(profile_path, &ply_profile->msg_len); if (ply_profile->profile_msg == NULL) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); } } ply_profile->profile_name=tfe_strdup(profile_name); ply_profile->profile_type=tfe_strdup(formate); ply_profile->profile_position=tfe_strdup(profile_position); - TFE_LOG_INFO(g_pangu_rt->local_logger, "Policy table add success %d", profile_id); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Policy table add success %d", profile_id); *ad = ply_profile; return; @@ -705,7 +743,7 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t ret=sscanf(table_line, "%d\t%s\t%s\t%s\t%s\t%d", &profile_id, profile_name, hijack_name, formate, profile_path, &is_valid); if(ret!=6) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Policy table parse config failed: %s", table_line); return; } struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1); @@ -717,7 +755,7 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t ply_profile->profile_name=tfe_strdup(hijack_name); ply_profile->profile_type=tfe_strdup(formate); - TFE_LOG_INFO(g_pangu_rt->local_logger, "Policy table add success %d", profile_id); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Policy table add success %d", profile_id); *ad = ply_profile; return; @@ -732,7 +770,7 @@ void ma_lua_profile_table_new_cb(int table_id, const char* key, const char* tabl ret=sscanf(table_line, "%d\t%s\t%d\t%d", &profile_id, profile_path, &timeout, &is_valid); if(ret!=4) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Policy table parse config failed: %s", table_line); return; } struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1); @@ -745,25 +783,21 @@ void ma_lua_profile_table_new_cb(int table_id, const char* key, const char* tabl ply_profile->timeout=timeout; if (ply_profile->profile_msg == NULL) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path); *ad = ply_profile; return; } - int i=0, thread_num = g_pangu_rt->thread_num; - struct tsg_lua_script *lua_script = &(g_pangu_rt->lua_script); + int i=0, thread_num = g_proxy_rt->thread_num; + struct tsg_lua_script *lua_script = &(g_proxy_rt->lua_script); - if(lua_script->lua_is_cache==1) + ply_profile->escript_ctx = ALLOC(struct elua_script *, thread_num); + for(i=0; iscript_id = ALLOC(int, thread_num); - - for(i=0; iscript_id[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], ply_profile->profile_msg, ply_profile->msg_len); - } + ply_profile->escript_ctx[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], ply_profile->profile_msg, ply_profile->msg_len, timeout); } - TFE_LOG_INFO(g_pangu_rt->local_logger, "Policy table add success %d", profile_id); + TFE_LOG_INFO(g_proxy_rt->local_logger, "Policy table add success %d", profile_id); *ad = ply_profile; return; @@ -792,8 +826,16 @@ void ma_profile_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, if(ply_obj->profile_msg) FREE(&ply_obj->profile_msg); - if(ply_obj->script_id) - FREE(&ply_obj->script_id); + if(ply_obj->escript_ctx) + { + int i=0; + for(i=0; ithread_num; i++) + { + elua_cleanup_script(ply_obj->escript_ctx[i]); + } + free(ply_obj->escript_ctx); + ply_obj->escript_ctx=NULL; + } FREE(&ply_obj->profile_name); if (ply_obj->profile_position) @@ -823,10 +865,10 @@ int maat_table_init(const char* table_name, { int table_id=0; - table_id=Maat_table_register(g_pangu_rt->maat, table_name); + table_id=Maat_table_register(g_proxy_rt->maat, table_name); if(table_id>=0) { - Maat_table_callback_register(g_pangu_rt->maat, table_id, + Maat_table_callback_register(g_proxy_rt->maat, table_id, start, update, finish, u_para); } return table_id; @@ -856,10 +898,10 @@ int maat_table_ex_init(int profile_idx, [POLICY_PROFILE_TABLE_LUA] = ma_lua_profile_table_new_cb, }; - table_id=g_pangu_rt->plolicy_table_id[profile_idx]=Maat_table_register(g_pangu_rt->maat, table_name); + table_id=g_proxy_rt->plolicy_table_id[profile_idx]=Maat_table_register(g_proxy_rt->maat, table_name); if(table_id >= 0) { - table_id=Maat_plugin_EX_register(g_pangu_rt->maat, table_id, + table_id=Maat_plugin_EX_register(g_proxy_rt->maat, table_id, new_func[profile_idx], free_func, dup_func, @@ -870,10 +912,10 @@ int maat_table_ex_init(int profile_idx, return -1; } -int pangu_policy_init(const char* profile_path, const char* static_section, const char* dynamic_section) +int proxy_policy_init(const char* profile_path, const char* static_section, const char* dynamic_section) { int ret = 0; - g_pangu_rt->maat = (Maat_feather_t)tfe_bussiness_resouce_get(STATIC_MAAT); + g_proxy_rt->maat = (Maat_feather_t)tfe_bussiness_resouce_get(STATIC_MAAT); const char * table_name[__SCAN_TABLE_MAX]; table_name[PXY_CTRL_IP] = "TSG_SECURITY_ADDR"; @@ -886,15 +928,15 @@ int pangu_policy_init(const char* profile_path, const char* static_section, cons table_name[PXY_CTRL_APP_ID] = "TSG_OBJ_APP_ID"; for (int i = 0; i < __SCAN_TABLE_MAX; i++) { - g_pangu_rt->scan_table_id[i] = Maat_table_register(g_pangu_rt->maat, table_name[i]); - if (g_pangu_rt->scan_table_id[i] < 0) + g_proxy_rt->scan_table_id[i] = Maat_table_register(g_proxy_rt->maat, table_name[i]); + if (g_proxy_rt->scan_table_id[i] < 0) { TFE_LOG_ERROR(NULL, "Pangu HTTP Maat table %s register failed.", table_name[i]); goto error_out; } } - g_pangu_rt->ctrl_compile_idx=Maat_rule_get_ex_new_index(g_pangu_rt->maat, "PXY_CTRL_COMPILE", + g_proxy_rt->ctrl_compile_idx=Maat_rule_get_ex_new_index(g_proxy_rt->maat, "PXY_CTRL_COMPILE", policy_action_param_new, policy_action_param_free_cb, policy_action_param_dup, @@ -904,7 +946,7 @@ int pangu_policy_init(const char* profile_path, const char* static_section, cons trusted_CA_update_start_cb, trusted_CA_update_cert_cb, trusted_CA_update_finish_cb, - g_pangu_rt); + g_proxy_rt); if(ret<0) { TFE_LOG_INFO(NULL, "Pangu HTTP register table PXY_OBJ_TRUSTED_CA_CERT failed."); @@ -915,7 +957,7 @@ int pangu_policy_init(const char* profile_path, const char* static_section, cons trusted_CA_update_start_cb, trusted_CA_update_crl_cb, trusted_CA_update_finish_cb, - g_pangu_rt); + g_proxy_rt); if(ret<0) { TFE_LOG_INFO(NULL, "Pangu HTTP register table PXY_OBJ_TRUSTED_CA_CRL failed."); @@ -945,18 +987,18 @@ Ratelimiter_handle_t ratelimit_handle_create(const char* profile_path, const cha Ratelimiter_handle_t ratelimit = NULL; - MESA_load_profile_int_def(profile_path, static_section, "enable", &(g_pangu_rt->enable_rate), 0); + MESA_load_profile_int_def(profile_path, static_section, "enable", &(g_proxy_rt->enable_rate), 0); MESA_load_profile_int_def(profile_path, static_section, "redis_port", &(redis_port), 6379); MESA_load_profile_string_def(profile_path, static_section, "redis_server", redis_server, sizeof(redis_server), ""); MESA_load_profile_string_def(profile_path, static_section, "token_name", token_name, sizeof(token_name), ""); MESA_load_profile_int_def(profile_path, static_section, "redis_db_index", &(redis_db_idx), 0); MESA_load_profile_int_def(profile_path, static_section, "interval_sec", &(interval_sec), 1); - if (g_pangu_rt->enable_rate != 1) + if (g_proxy_rt->enable_rate != 1) { return NULL; } - ratelimit=Ratelimiter_create(token_name, g_pangu_rt->local_logger); + ratelimit=Ratelimiter_create(token_name, g_proxy_rt->local_logger); Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_INTERVAL_SEC, &interval_sec, sizeof(interval_sec)); Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_REDIS_IP, redis_server, strlen(redis_server) + 1); Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_REDIS_PORT, &redis_port, sizeof(redis_port)); @@ -977,7 +1019,7 @@ Ratelimiter_handle_t ratelimit_handle_create(const char* profile_path, const cha ret = Ratelimiter_start(ratelimit); if (ret < 0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "%s Ratelimiter init failed.", __FUNCTION__); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "%s Ratelimiter init failed.", __FUNCTION__); goto error_out; } return ratelimit; @@ -986,41 +1028,39 @@ error_out: return NULL; } -int pangu_http_init(struct tfe_proxy * proxy) +int proxy_http_init(struct tfe_proxy * proxy) { const char * profile_path = "./conf/pangu/pangu_pxy.conf";; int temp=0; - g_pangu_rt = ALLOC(struct pangu_rt, 1); - MESA_load_profile_int_def(profile_path, "DEBUG", "enable_plugin", &(g_pangu_rt->enable_plugin), 1); - if (!g_pangu_rt->enable_plugin) + g_proxy_rt = ALLOC(struct tsg_proxy_rt, 1); + MESA_load_profile_int_def(profile_path, "DEBUG", "enable_plugin", &(g_proxy_rt->enable_plugin), 1); + if (!g_proxy_rt->enable_plugin) { return 0; } - g_pangu_rt->thread_num = tfe_proxy_get_work_thread_count(); - g_pangu_rt->gc_evbase=tfe_proxy_get_gc_evbase(); + g_proxy_rt->thread_num = tfe_proxy_get_work_thread_count(); + g_proxy_rt->gc_evbase=tfe_proxy_get_gc_evbase(); - g_pangu_rt->local_logger = MESA_create_runtime_log_handle("pangu", RLOG_LV_DEBUG); + g_proxy_rt->local_logger = MESA_create_runtime_log_handle("tsg_http", RLOG_LV_DEBUG); - g_pangu_rt->send_logger = pangu_log_handle_create(profile_path, "LOG", g_pangu_rt->local_logger); - if (!g_pangu_rt->send_logger) + g_proxy_rt->send_logger = proxy_log_handle_create(profile_path, "LOG", g_proxy_rt->local_logger); + if (!g_proxy_rt->send_logger) { goto error_out; } - g_pangu_rt->fs_handle = tfe_proxy_get_fs_handle(); - g_pangu_rt->ratelimiter=ratelimit_handle_create(profile_path, "ratelimit"); + g_proxy_rt->fs_handle = tfe_proxy_get_fs_handle(); + g_proxy_rt->ratelimiter=ratelimit_handle_create(profile_path, "ratelimit"); - pangu_http_stat_init(g_pangu_rt); + proxy_http_stat_init(g_proxy_rt); - g_pangu_rt->lua_script.http_lua_handle=http_lua_handle_create(g_pangu_rt->thread_num, "tfe"); - if(g_pangu_rt->lua_script.http_lua_handle==NULL) + if(http_lua_handle_create(&g_proxy_rt->lua_script, g_proxy_rt->thread_num, "tfe") <0) { goto error_out; } - - if(pangu_policy_init(profile_path, "MAAT", "DYNAMIC_MAAT")<0) + if(proxy_policy_init(profile_path, "MAAT", "DYNAMIC_MAAT")<0) { goto error_out; } @@ -1029,36 +1069,36 @@ int pangu_http_init(struct tfe_proxy * proxy) memset(page_path, 0, sizeof(page_path)); MESA_load_profile_string_def(profile_path, "TEMPLATE", "PAGE_403", page_path, sizeof(page_path), "./resource/pangu/HTTP403.html"); - g_pangu_rt->tpl_403 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); + g_proxy_rt->tpl_403 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); memset(page_path, 0, sizeof(page_path)); MESA_load_profile_string_def(profile_path, "TEMPLATE", "PAGE_404", page_path, sizeof(page_path), "./resource/pangu/HTTP404.html"); - g_pangu_rt->tpl_404 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); + g_proxy_rt->tpl_404 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); memset(page_path, 0, sizeof(page_path)); MESA_load_profile_string_def(profile_path, "TEMPLATE", "PAGE_451", page_path, sizeof(page_path), "./resource/pangu/HTTP451.html"); - g_pangu_rt->tpl_451 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); + g_proxy_rt->tpl_451 = ctemplate::Template::GetTemplate(page_path, ctemplate::DO_NOT_STRIP); MESA_load_profile_int_def(profile_path, "TANGO_CACHE", "suspend_max", &(temp), 1024*1024); - g_pangu_rt->suspend_max=temp; + g_proxy_rt->suspend_max=temp; - MESA_load_profile_int_def(profile_path, "TANGO_CACHE", "enable_cache", &(g_pangu_rt->cache_enabled), 1); - if(g_pangu_rt->cache_enabled) + MESA_load_profile_int_def(profile_path, "TANGO_CACHE", "enable_cache", &(g_proxy_rt->cache_enabled), 1); + if(g_proxy_rt->cache_enabled) { - g_pangu_rt->cache = create_web_cache_handle(profile_path, "TANGO_CACHE", g_pangu_rt->gc_evbase, - g_pangu_rt->maat, g_pangu_rt->local_logger); - if(!g_pangu_rt->cache) + g_proxy_rt->cache = create_web_cache_handle(profile_path, "TANGO_CACHE", g_proxy_rt->gc_evbase, + g_proxy_rt->maat, g_proxy_rt->local_logger); + if(!g_proxy_rt->cache) { TFE_LOG_INFO(NULL, "Tango Cache init failed."); goto error_out; } TFE_LOG_INFO(NULL, "Tango Cache Enabled."); } - TFE_LOG_INFO(NULL, "Pangu HTTP init success."); + TFE_LOG_INFO(NULL, "Tsg_pxy HTTP init success."); return 0; error_out: - TFE_LOG_ERROR(NULL, "Pangu HTTP init failed."); + TFE_LOG_ERROR(NULL, "Tsg_pxy HTTP init failed."); return -1; } @@ -1096,10 +1136,10 @@ struct ip_data_ctx char *location_server; }; -struct pangu_http_ctx +struct proxy_http_ctx { int magic_num; - enum pangu_action action; + enum proxy_action action; char * action_para; int hit_cnt; struct Maat_rule_t result[MAX_SCAN_RESULT]; @@ -1121,7 +1161,7 @@ struct pangu_http_ctx int (* resumed_cb)(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event event, const unsigned char * data, - size_t datalen, unsigned int thread_id, struct pangu_http_ctx* ctx); + size_t datalen, unsigned int thread_id, struct proxy_http_ctx* ctx); enum cache_pending_result pending_result; struct future *f_cache_pending, *f_cache_query; @@ -1186,7 +1226,7 @@ void http_tsg_ctx_free(struct tsg_script_ctx *tsg_ctx, int thread_id) evbuffer_free(tsg_ctx->http_lua_body); tsg_ctx->http_lua_body = NULL; } - http_lua_ctx_free(&g_pangu_rt->lua_script, thread_id, tsg_ctx->lua_ctx); + http_lua_ctx_free(&g_proxy_rt->lua_script, thread_id, tsg_ctx->elua_ctx); FREE(&tsg_ctx); return; } @@ -1204,16 +1244,16 @@ void http_ip_ctx_free(struct ip_data_ctx *ip_ctx) } #define HTTP_CTX_MAGIC_NUM 20181021 -static struct pangu_http_ctx * pangu_http_ctx_new(unsigned int thread_id) +static struct proxy_http_ctx * proxy_http_ctx_new(unsigned int thread_id) { - struct pangu_http_ctx * ctx = ALLOC(struct pangu_http_ctx, 1); + struct proxy_http_ctx * ctx = ALLOC(struct proxy_http_ctx, 1); ctx->magic_num=HTTP_CTX_MAGIC_NUM; ctx->scan_mid = NULL; ctx->thread_id = (int) thread_id; return ctx; } -static void pangu_http_ctx_free(struct pangu_http_ctx * ctx) +static void proxy_http_ctx_free(struct proxy_http_ctx * ctx) { assert(ctx->magic_num==HTTP_CTX_MAGIC_NUM); if(ctx->rep_ctx) @@ -1311,52 +1351,52 @@ static struct manipulate_profile* get_profile_by_id(int profile_table, int profi char cfg_id_str[16] = {0}; snprintf(cfg_id_str, sizeof(cfg_id_str), "%d", profile_id); - int table_id = g_pangu_rt->plolicy_table_id[profile_table]; + int table_id = g_proxy_rt->plolicy_table_id[profile_table]; - result = (struct manipulate_profile*)Maat_plugin_get_EX_data(g_pangu_rt->maat, table_id, (const char*)cfg_id_str); + result = (struct manipulate_profile*)Maat_plugin_get_EX_data(g_proxy_rt->maat, table_id, (const char*)cfg_id_str); return result; } static unsigned long long try_send_by_token(int inject_sz) { - if (g_pangu_rt->enable_rate != 1) + if (g_proxy_rt->enable_rate != 1) { return 1; } - return Ratelimiter_customer_factory(g_pangu_rt->ratelimiter, inject_sz); + return Ratelimiter_customer_factory(g_proxy_rt->ratelimiter, inject_sz); } -static int pangu_action_weight[__PG_ACTION_MAX] = {0}; +static int pangu_action_weight[__PX_ACTION_MAX] = {0}; void __pangu_action_weight_init() __attribute__((constructor, used)); void __pangu_action_weight_init() { - pangu_action_weight[PG_ACTION_NONE] = 0; - pangu_action_weight[PG_ACTION_MONIT] = 1; - pangu_action_weight[PG_ACTION_MANIPULATE] = 2; - pangu_action_weight[PG_ACTION_REJECT] = 3; - pangu_action_weight[PG_ACTION_WHITELIST] = 4; + pangu_action_weight[PX_ACTION_NONE] = 0; + pangu_action_weight[PX_ACTION_MONIT] = 1; + pangu_action_weight[PX_ACTION_MANIPULATE] = 2; + pangu_action_weight[PX_ACTION_REJECT] = 3; + pangu_action_weight[PX_ACTION_WHITELIST] = 4; } -static inline int action_cmp(enum pangu_action a1, enum pangu_action a2) +static inline int action_cmp(enum proxy_action a1, enum proxy_action a2) { return pangu_action_weight[a1] - pangu_action_weight[a2]; } //enforce_rules[0] contains execute action. -static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules, size_t n_hit, +static enum proxy_action decide_ctrl_action(const struct Maat_rule_t * hit_rules, size_t n_hit, struct Maat_rule_t ** enforce_rules, size_t * n_enforce, struct policy_action_param **param) { size_t n_monit = 0, exist_enforce_num = 0, i = 0; const struct Maat_rule_t * prior_rule = hit_rules; struct Maat_rule_t monit_rule[n_hit]; - enum pangu_action prior_action = PG_ACTION_NONE; + enum proxy_action prior_action = PX_ACTION_NONE; for (i = 0; i < n_hit && imaat, prior_rule, g_pangu_rt->ctrl_compile_idx); + void *ex_data=Maat_rule_get_ex_data(g_proxy_rt->maat, prior_rule, g_proxy_rt->ctrl_compile_idx); if(ex_data!=NULL) { *param=(struct policy_action_param*)ex_data; @@ -1438,11 +1478,11 @@ static void template_generate(int status_code, const char* msg, char ** page_buf switch (status_code) { - case 403: tpl = g_pangu_rt->tpl_403; + case 403: tpl = g_proxy_rt->tpl_403; break; - case 404: tpl = g_pangu_rt->tpl_404; + case 404: tpl = g_proxy_rt->tpl_404; break; - case 451: tpl = g_pangu_rt->tpl_451; + case 451: tpl = g_proxy_rt->tpl_451; break; default: return; } @@ -1511,7 +1551,7 @@ static int http_enforcement_ratio(float enforcement_ratio) return 0; } -int http_lua_profile(int profile_id, char **profile_msg, size_t *msg_len, int **script_id, int *timeout) +int http_lua_profile(int profile_id, struct elua_script ***elua_ctx) { int ret = 0; @@ -1522,30 +1562,26 @@ int http_lua_profile(int profile_id, char **profile_msg, size_t *msg_len, int ** return ret; } - *profile_msg = tfe_strdup(lua_profile->profile_msg); - *msg_len = lua_profile->msg_len; - *script_id = lua_profile->script_id; - *timeout=lua_profile->timeout; - + *elua_ctx=lua_profile->escript_ctx; ma_profile_table_free(lua_profile); lua_profile = NULL; return ret; } void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx) + const unsigned char * body_frag, size_t frag_size, struct proxy_http_ctx * ctx) { int ret = 0; struct tfe_http_session * to_write_sess = NULL; - struct tsg_lua_script *lua_script=&g_pangu_rt->lua_script; + struct tsg_lua_script *lua_script=&g_proxy_rt->lua_script; lua_script->http_lua_profile=http_lua_profile; to_write_sess = tfe_http_session_allow_write(session); if (to_write_sess == NULL) //fail to wirte, abandon. { TFE_STREAM_LOG_INFO(stream, "tfe_http_session_allow_write() %s failed.", session->req->req_spec.uri); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } @@ -1557,18 +1593,18 @@ void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * struct policy_action_param *param = ctx->param; ctx->tsg_ctx = tsg_ctx = ALLOC(struct tsg_script_ctx, 1); tsg_ctx->profile_id = param->profile_id; - tsg_ctx->lua_ctx = http_lua_ctx_new(lua_script, ctx->thread_id); + tsg_ctx->elua_ctx = http_lua_ctx_new(lua_script, ctx->thread_id); } else { TFE_STREAM_LOG_INFO(stream, "Can only setup replace on REQ/RESP headers, detached."); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } } tsg_ctx->events = events; tsg_ctx->session = session; - tsg_ctx->local_logger = g_pangu_rt->local_logger; + tsg_ctx->local_logger = g_proxy_rt->local_logger; tsg_ctx->config_id = ctx->enforce_rules[0].config_id; struct tfe_http_half * in_req_half = session->req; @@ -1581,14 +1617,14 @@ void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * if (tfe_http_in_request(events)) { tsg_ctx->http_req_uri=1; tsg_ctx->execut_lua_sucess=0; - ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->lua_ctx, ctx->thread_id, (void *)tsg_ctx); - if(ret>0 && tsg_ctx->execut_lua_sucess==1) + ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->elua_ctx, ctx->thread_id, (void *)tsg_ctx); + if(ret==0 && tsg_ctx->execut_lua_sucess==1) { tsg_ctx->actually_executed =1; } tsg_ctx->http_req_uri=0; tsg_ctx->execut_lua_sucess=0; - tsg_ctx->replacing = tfe_http_session_request_create(to_write_sess, in_req_spec->method, in_req_spec->uri); + tsg_ctx->replacing = tfe_http_session_request_create(to_write_sess, in_req_spec->method, tsg_ctx->rewrite_uri !=NULL ? tsg_ctx->rewrite_uri : in_req_spec->uri); tfe_http_session_request_set(to_write_sess, tsg_ctx->replacing); } else @@ -1597,8 +1633,13 @@ void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * tfe_http_session_response_set(to_write_sess, tsg_ctx->replacing); } - ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->lua_ctx, ctx->thread_id, (void *)tsg_ctx); - if(ret>0 && tsg_ctx->execut_lua_sucess==1) + if (tsg_ctx->rewrite_uri != NULL) + { + FREE(&tsg_ctx->rewrite_uri); + } + + ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->elua_ctx, ctx->thread_id, (void *)tsg_ctx); + if(ret==0 && tsg_ctx->execut_lua_sucess==1) { tsg_ctx->actually_executed =1; } @@ -1635,10 +1676,10 @@ void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * char * __http_body = (char *) evbuffer_pullup(tsg_ctx->http_body, -1); size_t __http_body_len = evbuffer_get_length(tsg_ctx->http_body); - ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->lua_ctx, ctx->thread_id, (void *)tsg_ctx); + ret=execute_lua_script_rule(lua_script, tsg_ctx->profile_id, tsg_ctx->elua_ctx, ctx->thread_id, (void *)tsg_ctx); char * __http_lua_body = NULL; size_t __http_body_lua_len = 0; - if(ret > 0 && tsg_ctx->http_lua_body != NULL) + if(ret == 0 && tsg_ctx->http_lua_body != NULL) { tsg_ctx->actually_executed =1; __http_lua_body = (char *) evbuffer_pullup(tsg_ctx->http_lua_body, -1); @@ -1678,7 +1719,7 @@ void http_lua(const struct tfe_stream * stream, const struct tfe_http_session * } void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx) + const unsigned char * body_frag, size_t frag_size, struct proxy_http_ctx * ctx) { struct tfe_http_session * to_write_sess = NULL; char * rewrite_buff = NULL; @@ -1688,15 +1729,15 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio int ratio = http_enforcement_ratio(param->enforcement_ratio); if (ratio != 1) { - TFE_LOG_DEBUG(g_pangu_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); - ctx->action = PG_ACTION_NONE; + TFE_LOG_DEBUG(g_proxy_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); + ctx->action = PX_ACTION_NONE; return; } to_write_sess = tfe_http_session_allow_write(session); if (to_write_sess == NULL) //fail to wirte, abandon. { TFE_STREAM_LOG_INFO(stream, "tfe_http_session_allow_write() %s failed.", session->req->req_spec.uri); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } @@ -1715,7 +1756,7 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio else { TFE_STREAM_LOG_INFO(stream, "Can only setup replace on REQ/RESP headers, detached."); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } } @@ -1856,7 +1897,7 @@ static void http_get_subscriber_id(const struct tfe_stream * stream, char *repla ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_SRC_SUB_ID, (unsigned char *)source_subscribe_id, sizeof(source_subscribe_id), &opt_out_size); if (ret != 0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "fetch src sub id from cmsg failed, ret: %d addr: %s", ret, stream->str_stream_info); + TFE_LOG_ERROR(g_proxy_rt->local_logger, "fetch src sub id from cmsg failed, ret: %d addr: %s", ret, stream->str_stream_info); } } if(strlen(source_subscribe_id) > 0) @@ -1921,7 +1962,7 @@ static int http_regex_replace(const struct tfe_stream * stream, char *message, i } static void http_redirect(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - struct pangu_http_ctx * ctx) + struct proxy_http_ctx * ctx) { struct tfe_http_half * response = NULL; struct tfe_http_session * to_write = NULL; @@ -1935,13 +1976,13 @@ static void http_redirect(const struct tfe_stream * stream, const struct tfe_htt int ratio = http_enforcement_ratio(param->enforcement_ratio); if (ratio != 1) { - TFE_LOG_DEBUG(g_pangu_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); - ctx->action = PG_ACTION_NONE; + TFE_LOG_DEBUG(g_proxy_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); + ctx->action = PX_ACTION_NONE; return; } ctx->manipulate_replaced = 1; if (resp_code <= 0 || rd_url == NULL){ - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Invalid redirect rule %d paramter", + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Invalid redirect rule %d paramter", ctx->enforce_rules[0].config_id); goto error_out; } @@ -1949,7 +1990,7 @@ static void http_redirect(const struct tfe_stream * stream, const struct tfe_htt if ((events & EV_HTTP_RESP_BODY_BEGIN) || (events & EV_HTTP_RESP_BODY_CONT) || (events & EV_HTTP_RESP_BODY_END) || (events & EV_HTTP_RESP_END)) { - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; return; } @@ -1959,7 +2000,7 @@ static void http_redirect(const struct tfe_stream * stream, const struct tfe_htt assert(0); } - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REDIRECT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_REDIRECT])); response = tfe_http_session_response_create(to_write, resp_code); @@ -1985,7 +2026,7 @@ error_out: } static void http_block(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - struct pangu_http_ctx * ctx) + struct proxy_http_ctx * ctx) { int ret = -1; struct tfe_http_half * response = NULL; @@ -2001,8 +2042,8 @@ static void http_block(const struct tfe_stream * stream, const struct tfe_http_s char *message = param->message; if (resp_code <= 0 || profile_id < 0){ - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Invalid block rule %d", ctx->enforce_rules[0].config_id); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Invalid block rule %d", ctx->enforce_rules[0].config_id); + ctx->action = PX_ACTION_NONE; return; } @@ -2032,7 +2073,7 @@ static void http_block(const struct tfe_stream * stream, const struct tfe_http_s snprintf(cont_len_str, sizeof(cont_len_str), "%lu", page_size); tfe_http_std_field_write(response, TFE_HTTP_CONT_LENGTH, cont_len_str); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REJECT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_REJECT])); tfe_http_half_append_body(response, page_buff, page_size, 0); tfe_http_half_append_body(response, NULL, 0, 0); tfe_http_session_response_set(to_write_sess, response); @@ -2041,7 +2082,7 @@ static void http_block(const struct tfe_stream * stream, const struct tfe_http_s } else { - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REJECT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_REJECT])); to_write_sess = tfe_http_session_allow_write(session); tfe_http_session_kill(to_write_sess); } @@ -2049,7 +2090,7 @@ static void http_block(const struct tfe_stream * stream, const struct tfe_http_s } static void http_hijack(const struct tfe_http_session * session, enum tfe_http_event events, - struct pangu_http_ctx * ctx) + struct proxy_http_ctx * ctx) { struct policy_action_param *param = ctx->param; struct tfe_http_half * response = NULL; @@ -2057,16 +2098,16 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e if (param->profile_id <= 0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Invalid hijack rule %d", + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Invalid hijack rule %d", ctx->enforce_rules[0].config_id); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; return; } if (http_enforcement_ratio(param->enforcement_ratio) != 1) { - TFE_LOG_DEBUG(g_pangu_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); - ctx->action = PG_ACTION_NONE; + TFE_LOG_DEBUG(g_proxy_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); + ctx->action = PX_ACTION_NONE; return; } ctx->manipulate_replaced = 1; @@ -2080,8 +2121,8 @@ 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, profile_id = %d", param->profile_id); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "get table obj faild, profile_id = %d", param->profile_id); + ctx->action = PX_ACTION_NONE; return; } @@ -2089,20 +2130,20 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e hijack_buff = tfe_read_file(hijack_profile->profile_msg, &hijack_size); if (NULL == hijack_buff){ - TFE_LOG_ERROR(g_pangu_rt->local_logger, "read hijack file faild, path = %s", hijack_profile->profile_msg); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "read hijack file faild, path = %s", hijack_profile->profile_msg); + ctx->action = PX_ACTION_NONE; return; } if (try_send_by_token(hijack_size) <= 0) { FREE(&hijack_buff); - TFE_LOG_ERROR(g_pangu_rt->local_logger, "No token is available to send data, profile_id = %d", param->profile_id); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "No token is available to send data, profile_id = %d", param->profile_id); + ctx->action = PX_ACTION_NONE; return; } ctx->inject_sz = hijack_size; - ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_ACTION_HIJACK_SZ]), hijack_size); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_HIJACK])); + ATOMIC_ADD(&(g_proxy_rt->stat_val[STAT_ACTION_HIJACK_SZ]), hijack_size); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_HIJACK])); char cont_len_str[16]; to_write_sess = tfe_http_session_allow_write(session); @@ -2164,7 +2205,7 @@ static int format_insert_rule(int profile_id, struct insert_rule *rule) } static void http_insert(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx) + const unsigned char * body_frag, size_t frag_size, struct proxy_http_ctx * ctx) { struct tfe_http_session * to_write_sess = NULL; char * rewrite_buff = NULL; @@ -2174,15 +2215,15 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ int ratio = http_enforcement_ratio(param->enforcement_ratio); if (ratio != 1) { - TFE_LOG_DEBUG(g_pangu_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); - ctx->action = PG_ACTION_NONE; + TFE_LOG_DEBUG(g_proxy_rt->local_logger, "enforcement ratio:%f", param->enforcement_ratio); + ctx->action = PX_ACTION_NONE; return; } to_write_sess = tfe_http_session_allow_write(session); if (to_write_sess == NULL) //fail to wirte, abandon. { TFE_STREAM_LOG_INFO(stream, "tfe_http_session_allow_write() %s failed.", session->req->req_spec.uri); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } @@ -2198,14 +2239,14 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ int ret=format_insert_rule(param->profile_id, ins_ctx->rule); if (ret<0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Failed to get policy table, profile_id = %d", param->profile_id); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Failed to get policy table, profile_id = %d", param->profile_id); + ctx->action = PX_ACTION_NONE; return; } if (try_send_by_token(ins_ctx->rule->inject_sz) <= 0) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "No token is available to send data, profile_id = %d", param->profile_id); - ctx->action = PG_ACTION_NONE; + TFE_LOG_ERROR(g_proxy_rt->local_logger, "No token is available to send data, profile_id = %d", param->profile_id); + ctx->action = PX_ACTION_NONE; return; } ctx->inject_sz = ins_ctx->rule->inject_sz; @@ -2213,7 +2254,7 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ else { TFE_STREAM_LOG_INFO(stream, "Can only setup insert on REQ/RESP headers, detached."); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } } @@ -2278,8 +2319,8 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ if (rewrite_sz >0) { tfe_http_half_append_body(ins_ctx->replacing, rewrite_buff, rewrite_sz, 0); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_INSERT])); - ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_ACTION_INSERT_SZ]), ctx->inject_sz); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_INSERT])); + ATOMIC_ADD(&(g_proxy_rt->stat_val[STAT_ACTION_INSERT_SZ]), ctx->inject_sz); ins_ctx->actually_inserted=1; } else @@ -2309,7 +2350,7 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_ } void http_element(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, - const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx) + const unsigned char * body_frag, size_t frag_size, struct proxy_http_ctx * ctx) { struct tfe_http_session * to_write_sess = NULL; char * rewrite_buff = NULL; @@ -2324,7 +2365,7 @@ void http_element(const struct tfe_stream * stream, const struct tfe_http_sessio if (to_write_sess == NULL) { TFE_STREAM_LOG_INFO(stream, "tfe_http_session_allow_write() %s failed.", session->req->req_spec.uri); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } @@ -2341,7 +2382,7 @@ void http_element(const struct tfe_stream * stream, const struct tfe_http_sessio else { TFE_STREAM_LOG_INFO(stream, "Can only setup editing on RESP headers, detached."); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; tfe_http_session_detach(session); return; } } @@ -2400,7 +2441,7 @@ void http_element(const struct tfe_stream * stream, const struct tfe_http_sessio if (rewrite_sz >0 ) { tfe_http_half_append_body(edit_ctx->editing, rewrite_buff, rewrite_sz, 0); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_EDIT_ELEMENT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_EDIT_ELEMENT])); edit_ctx->actually_edited=1; } else @@ -2428,14 +2469,14 @@ void http_element(const struct tfe_stream * stream, const struct tfe_http_sessio } static void http_manipulate(const struct tfe_stream * stream, const struct tfe_http_session * session, - enum tfe_http_event events, const unsigned 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 proxy_http_ctx * ctx) { struct policy_action_param *param = ctx->param; if (param == NULL) { - TFE_LOG_ERROR(g_pangu_rt->local_logger, "Failed to get the json format parsed. config_id = %d", + TFE_LOG_ERROR(g_proxy_rt->local_logger, "Failed to get the json format parsed. config_id = %d", ctx->enforce_rules[0].config_id); - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; return; } @@ -2491,8 +2532,8 @@ finish: return fqdn_len; } -enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_http_event events, - const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx, const struct tfe_stream * stream) +enum proxy_action http_scan(const struct tfe_http_session * session, enum tfe_http_event events, + const unsigned char * body_frag, size_t frag_size, struct proxy_http_ctx * ctx, const struct tfe_stream * stream) { void * iterator = NULL; const char * field_val = NULL; @@ -2509,13 +2550,13 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht int str_host_length = get_fqdn_len(str_host); if (str_host != NULL && str_host_length != 0) { - scan_ret = Maat_full_scan_string(g_pangu_rt->maat, g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_FQDN], + scan_ret = Maat_full_scan_string(g_proxy_rt->maat, g_proxy_rt->scan_table_id[PXY_CTRL_HTTP_FQDN], CHARSET_UTF8, str_host, str_host_length, result + hit_cnt, NULL, MAX_SCAN_RESULT - hit_cnt, &(ctx->scan_mid), ctx->thread_id); if (scan_ret > 0) { hit_cnt += scan_ret; } - scan_ret = tfe_scan_fqdn_cat(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_pangu_rt->local_logger, g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_FQDN]); + scan_ret = tfe_scan_fqdn_cat(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_proxy_rt->local_logger, g_proxy_rt->scan_table_id[PXY_CTRL_HTTP_FQDN]); if (scan_ret > 0) { hit_cnt += scan_ret; @@ -2525,7 +2566,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht const char * str_url = session->req->req_spec.url; int str_url_length = (int) (strlen(session->req->req_spec.url)); - scan_ret = Maat_full_scan_string(g_pangu_rt->maat, g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_URL], + scan_ret = Maat_full_scan_string(g_proxy_rt->maat, g_proxy_rt->scan_table_id[PXY_CTRL_HTTP_URL], CHARSET_UTF8, str_url, str_url_length, result + hit_cnt, NULL, MAX_SCAN_RESULT - hit_cnt, &(ctx->scan_mid), ctx->thread_id); if (scan_ret > 0) @@ -2536,7 +2577,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht if ((events & EV_HTTP_REQ_HDR) || (events & EV_HTTP_RESP_HDR)) { - table_id = events & EV_HTTP_REQ_HDR ? g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_REQ_HDR] : g_pangu_rt + table_id = events & EV_HTTP_REQ_HDR ? g_proxy_rt->scan_table_id[PXY_CTRL_HTTP_REQ_HDR] : g_proxy_rt ->scan_table_id[PXY_CTRL_HTTP_RES_HDR]; http_half = events & EV_HTTP_REQ_HDR ? session->req : session->resp; while (hit_cnt < MAX_SCAN_RESULT) @@ -2548,11 +2589,11 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht } const char * str_field_name = http_field_name_to_string(&field_name); - scan_ret = Maat_set_scan_status(g_pangu_rt->maat, &(ctx->scan_mid), MAAT_SET_SCAN_DISTRICT, + scan_ret = Maat_set_scan_status(g_proxy_rt->maat, &(ctx->scan_mid), MAAT_SET_SCAN_DISTRICT, str_field_name, strlen(str_field_name)); assert(scan_ret == 0); - scan_ret = Maat_full_scan_string(g_pangu_rt->maat, table_id, + scan_ret = Maat_full_scan_string(g_proxy_rt->maat, table_id, CHARSET_UTF8, field_val, strlen(field_val), result + hit_cnt, NULL, MAX_SCAN_RESULT - hit_cnt, &(ctx->scan_mid), ctx->thread_id); if (scan_ret > 0) @@ -2565,9 +2606,9 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht if ((events & EV_HTTP_REQ_BODY_BEGIN) | (events & EV_HTTP_RESP_BODY_BEGIN)) { assert(ctx->sp == NULL); - table_id = events & EV_HTTP_REQ_BODY_BEGIN ? g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_REQ_BODY] : g_pangu_rt + table_id = events & EV_HTTP_REQ_BODY_BEGIN ? g_proxy_rt->scan_table_id[PXY_CTRL_HTTP_REQ_BODY] : g_proxy_rt ->scan_table_id[PXY_CTRL_HTTP_RES_BODY]; - ctx->sp = Maat_stream_scan_string_start(g_pangu_rt->maat, table_id, ctx->thread_id); + ctx->sp = Maat_stream_scan_string_start(g_proxy_rt->maat, table_id, ctx->thread_id); } if (body_frag != NULL) @@ -2589,9 +2630,9 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht if (hit_cnt > 0) { ctx->action = decide_ctrl_action(result, hit_cnt, &ctx->enforce_rules, &ctx->n_enforce, &ctx->param); - if (ctx->action == PG_ACTION_WHITELIST) + if (ctx->action == PX_ACTION_WHITELIST) { - TFE_LOG_INFO(g_pangu_rt->local_logger, "Bypass rules matched: url=%s policy id=%d.", + TFE_LOG_INFO(g_proxy_rt->local_logger, "Bypass rules matched: url=%s policy id=%d.", session->req->req_spec.url, ctx->enforce_rules[0].config_id); goto __out; } @@ -2605,7 +2646,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht *p = '\0'; - TFE_LOG_INFO(g_pangu_rt->local_logger, "Multiple rules matched: url=%s num=%lu ids=%s execute=%d.", + TFE_LOG_INFO(g_proxy_rt->local_logger, "Multiple rules matched: url=%s num=%lu ids=%s execute=%d.", session->req->req_spec.url, hit_cnt, buff, ctx->enforce_rules[0].config_id); } } @@ -2615,36 +2656,36 @@ __out: void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, - struct pangu_http_ctx * ctx) + struct proxy_http_ctx * ctx) { - if(ctx->action==PG_ACTION_NONE||ctx->action==PG_ACTION_MONIT) + if(ctx->action==PX_ACTION_NONE||ctx->action==PX_ACTION_MONIT) { //ctx->action changed in http_scan. http_scan(session, events, body_frag, frag_size, ctx, stream); } switch (ctx->action) { - case PG_ACTION_NONE: + case PX_ACTION_NONE: break; - case PG_ACTION_MONIT: + case PX_ACTION_MONIT: //send log on close. break; - case PG_ACTION_REJECT: + case PX_ACTION_REJECT: http_block(stream, session, events, ctx); break; - case PG_ACTION_MANIPULATE: + case PX_ACTION_MANIPULATE: http_manipulate(stream, session, events, body_frag, frag_size, ctx); break; - case PG_ACTION_WHITELIST: + case PX_ACTION_WHITELIST: tfe_http_session_detach(session); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_WHITELSIT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_WHITELSIT])); break; default: assert(0); break; } /* Don't store reqeust/response body when NOT hit or hit whitelist */ - if(ctx->action == PG_ACTION_NONE || ctx->action == PG_ACTION_WHITELIST) + if(ctx->action == PX_ACTION_NONE || ctx->action == PX_ACTION_WHITELIST) { return; } @@ -2667,7 +2708,7 @@ void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_h #define RESUMED_CB_NO_MORE_CALLS 0 #define RESUMED_CB_MORE_CALLS 1 int make_revalidate_request(const struct tfe_stream * stream, const struct tfe_http_session * session, - enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, struct pangu_http_ctx * ctx) + enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, struct proxy_http_ctx * ctx) { assert(ctx->cache_revalidate_req); if(events & EV_HTTP_REQ_BODY_BEGIN) @@ -2692,14 +2733,14 @@ int make_revalidate_request(const struct tfe_stream * stream, const struct tfe_h return RESUMED_CB_MORE_CALLS; } int dummy_resume(const struct tfe_stream * stream, const struct tfe_http_session * session, - enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, struct pangu_http_ctx * ctx) + enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, struct proxy_http_ctx * ctx) { return RESUMED_CB_NO_MORE_CALLS; } static void cache_read_on_succ(future_result_t * result, void * user) { - struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user; + struct proxy_http_ctx * ctx = (struct proxy_http_ctx *)user; const struct cached_meta* meta=NULL; enum cache_query_result_type type=cache_query_result_get_type(result); const unsigned char* data=NULL; @@ -2713,7 +2754,7 @@ static void cache_read_on_succ(future_result_t * result, void * user) ctx->cache_result_declared_sz=meta->content_length; ctx->resumed_cb=dummy_resume; tfe_http_session_resume(ctx->ref_session); - ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_DEC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); ctx->cached_response=tfe_http_session_response_create(ctx->ref_session, 200); tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_TYPE, meta->content_type); @@ -2751,7 +2792,7 @@ static void cache_read_on_succ(future_result_t * result, void * user) ctx->pending_result=PENDING_RESULT_MISS; ctx->resumed_cb=dummy_resume; tfe_http_session_resume(ctx->ref_session); - ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_DEC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); future_destroy(ctx->f_cache_query); ctx->f_cache_query=NULL; break; @@ -2762,14 +2803,14 @@ static void cache_read_on_succ(future_result_t * result, void * user) } static void cache_read_on_fail(enum e_future_error err, const char * what, void * user) { - struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user; + struct proxy_http_ctx * ctx = (struct proxy_http_ctx *)user; future_destroy(ctx->f_cache_query); ctx->f_cache_query=NULL; if(!ctx->cached_response) { tfe_http_session_resume(ctx->ref_session); ctx->resumed_cb=dummy_resume; - ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_DEC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); } else { @@ -2781,12 +2822,12 @@ static void cache_read_on_fail(enum e_future_error err, const char * what, void } static void cache_pend_on_succ(future_result_t * result, void * user) { - struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user; + struct proxy_http_ctx * ctx = (struct proxy_http_ctx *)user; const struct cached_meta* meta=NULL; meta=cache_pending_result_read_meta(result, ctx->cmid); ctx->resumed_cb=dummy_resume; tfe_http_session_resume(ctx->ref_session); - ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_DEC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); future_destroy(ctx->f_cache_pending); ctx->f_cache_pending=NULL; if(meta==NULL) @@ -2828,11 +2869,11 @@ static void cache_pend_on_succ(future_result_t * result, void * user) } static void cache_pend_on_fail(enum e_future_error err, const char * what, void * user) { - struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user; + struct proxy_http_ctx * ctx = (struct proxy_http_ctx *)user; ctx->pending_result=PENDING_RESULT_FOBIDDEN; tfe_http_session_resume(ctx->ref_session); - ATOMIC_DEC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_DEC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); ctx->resumed_cb=dummy_resume; future_destroy(ctx->f_cache_pending); ctx->f_cache_pending=NULL; @@ -2840,21 +2881,21 @@ static void cache_pend_on_fail(enum e_future_error err, const char * what, void return; } -void cache_pend(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx) +void cache_pend(const struct tfe_http_session * session, unsigned int thread_id, struct proxy_http_ctx * ctx) { - if(g_pangu_rt->stat_val[STAT_SUSPENDING]>g_pangu_rt->suspend_max) + if(g_proxy_rt->stat_val[STAT_SUSPENDING]>g_proxy_rt->suspend_max) { ctx->pending_result=PENDING_RESULT_FOBIDDEN; return; } ctx->f_cache_pending=future_create("cache_pend", cache_pend_on_succ, cache_pend_on_fail, ctx); ctx->ref_session=tfe_http_session_allow_write(session); - ctx->pending_result=web_cache_async_pending(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_pending); + ctx->pending_result=web_cache_async_pending(g_proxy_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_pending); switch(ctx->pending_result) { case PENDING_RESULT_REVALIDATE: tfe_http_session_suspend(ctx->ref_session); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); break; case PENDING_RESULT_ALLOWED: case PENDING_RESULT_FOBIDDEN: @@ -2867,19 +2908,19 @@ void cache_pend(const struct tfe_http_session * session, unsigned int thread_id, } return; } -void cache_read(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx) +void cache_read(const struct tfe_http_session * session, unsigned int thread_id, struct proxy_http_ctx * ctx) { - if(g_pangu_rt->stat_val[STAT_SUSPENDING]>g_pangu_rt->suspend_max) + if(g_proxy_rt->stat_val[STAT_SUSPENDING]>g_proxy_rt->suspend_max) { return; } ctx->f_cache_query=future_create("cache_read", cache_read_on_succ, cache_read_on_fail, ctx); - int ret=web_cache_async_read(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_query); + int ret=web_cache_async_read(g_proxy_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_query); if(ret==0) { ctx->ref_session=tfe_http_session_allow_write(session); tfe_http_session_suspend(ctx->ref_session); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_SUSPENDING])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_SUSPENDING])); } else { @@ -2890,12 +2931,12 @@ void cache_read(const struct tfe_http_session * session, unsigned int thread_id, void cache_write(const struct tfe_http_session * session, enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, - unsigned int thread_id, struct pangu_http_ctx * ctx) + unsigned int thread_id, struct proxy_http_ctx * ctx) { if(events & EV_HTTP_RESP_BODY_BEGIN) { - ctx->cache_write_ctx=web_cache_write_start(g_pangu_rt->cache, thread_id, session, &(ctx->cmid)); + ctx->cache_write_ctx=web_cache_write_start(g_proxy_rt->cache, thread_id, session, &(ctx->cmid)); } if(events & EV_HTTP_RESP_BODY_CONT && ctx->cache_write_ctx!=NULL) { @@ -2908,47 +2949,47 @@ void cache_write(const struct tfe_http_session * session, enum tfe_http_event ev } } -void pangu_on_http_begin(const struct tfe_stream * stream, +void proxy_on_http_begin(const struct tfe_stream * stream, const struct tfe_http_session * session, unsigned int thread_id, void ** pme) { - if (!g_pangu_rt->enable_plugin) + if (!g_proxy_rt->enable_plugin) { return; } - struct pangu_http_ctx * ctx = *(struct pangu_http_ctx **) pme; + struct proxy_http_ctx * ctx = *(struct proxy_http_ctx **) pme; struct ipaddr sapp_addr; int hit_cnt = 0, scan_ret=0; assert(ctx == NULL); - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_SESSION])); - ctx = pangu_http_ctx_new(thread_id); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_SESSION])); + ctx = proxy_http_ctx_new(thread_id); struct Maat_rule_t *result = ctx->result; - scan_ret = tfe_scan_subscribe_id(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_pangu_rt->local_logger); + scan_ret = tfe_scan_subscribe_id(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_proxy_rt->local_logger); if(scan_ret>0) { hit_cnt+=scan_ret; } - scan_ret = tfe_scan_ip_location(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_pangu_rt->local_logger, &(ctx->ip_ctx.location_server), &(ctx->ip_ctx.location_client)); + scan_ret = tfe_scan_ip_location(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_proxy_rt->local_logger, &(ctx->ip_ctx.location_server), &(ctx->ip_ctx.location_client)); if(scan_ret>0) { hit_cnt+=scan_ret; } - scan_ret = tfe_scan_ip_asn(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_pangu_rt->local_logger, &(ctx->ip_ctx.asn_server), &(ctx->ip_ctx.asn_client)); + scan_ret = tfe_scan_ip_asn(stream, result, &(ctx->scan_mid), hit_cnt, ctx->thread_id, g_proxy_rt->local_logger, &(ctx->ip_ctx.asn_server), &(ctx->ip_ctx.asn_client)); if(scan_ret>0) { hit_cnt+=scan_ret; } int scan_val=67; - scan_ret=Maat_scan_intval(g_pangu_rt->maat, g_pangu_rt->scan_table_id[PXY_CTRL_APP_ID], scan_val, result+hit_cnt, MAX_SCAN_RESULT-hit_cnt, &(ctx->scan_mid), (int) thread_id); + scan_ret=Maat_scan_intval(g_proxy_rt->maat, g_proxy_rt->scan_table_id[PXY_CTRL_APP_ID], scan_val, result+hit_cnt, MAX_SCAN_RESULT-hit_cnt, &(ctx->scan_mid), (int) thread_id); if(scan_ret>0) { hit_cnt+=scan_ret; } addr_tfe2sapp(stream->addr, &sapp_addr); - scan_ret = Maat_scan_proto_addr(g_pangu_rt->maat, g_pangu_rt->scan_table_id[PXY_CTRL_IP], &sapp_addr, 0, + scan_ret = Maat_scan_proto_addr(g_proxy_rt->maat, g_proxy_rt->scan_table_id[PXY_CTRL_IP], &sapp_addr, 0, result+hit_cnt, MAX_SCAN_RESULT-hit_cnt, &(ctx->scan_mid), (int) thread_id); if(scan_ret>0) { @@ -2964,10 +3005,10 @@ void pangu_on_http_begin(const struct tfe_stream * stream, return; } -static inline int ctx_actually_replaced(struct pangu_http_ctx * ctx) +static inline int ctx_actually_replaced(struct proxy_http_ctx * ctx) { - if(ctx->action == PG_ACTION_MANIPULATE && + if(ctx->action == PX_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_REPLACE && ctx->rep_ctx->actually_replaced==1) { @@ -2979,9 +3020,9 @@ static inline int ctx_actually_replaced(struct pangu_http_ctx * ctx) } } -static inline int ctx_actually_ran_script(struct pangu_http_ctx * ctx) +static inline int ctx_actually_ran_script(struct proxy_http_ctx * ctx) { - if(ctx->action == PG_ACTION_MANIPULATE && + if(ctx->action == PX_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_LUA_SCRIPT && ctx->tsg_ctx->actually_executed==1) { @@ -2993,10 +3034,10 @@ static inline int ctx_actually_ran_script(struct pangu_http_ctx * ctx) } } -static inline int ctx_actually_inserted(struct pangu_http_ctx * ctx) +static inline int ctx_actually_inserted(struct proxy_http_ctx * ctx) { - if(ctx->action == PG_ACTION_MANIPULATE && + if(ctx->action == PX_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_INSERT && ctx->ins_ctx->actually_inserted==1) { @@ -3008,10 +3049,10 @@ static inline int ctx_actually_inserted(struct pangu_http_ctx * ctx) } } -static inline int ctx_actually_edited(struct pangu_http_ctx * ctx) +static inline int ctx_actually_edited(struct proxy_http_ctx * ctx) { - if(ctx->action == PG_ACTION_MANIPULATE && + if(ctx->action == PX_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_ELEMENT && ctx->edit_ctx != NULL && ctx->edit_ctx->actually_edited==1) { @@ -3023,9 +3064,9 @@ static inline int ctx_actually_edited(struct pangu_http_ctx * ctx) } } -static inline int ctx_actually_manipulate(struct pangu_http_ctx * ctx) +static inline int ctx_actually_manipulate(struct proxy_http_ctx * ctx) { - if(ctx->action == PG_ACTION_MANIPULATE && + if(ctx->action == PX_ACTION_MANIPULATE && (ctx->param->action == MA_ACTION_REDIRECT || ctx->param->action == MA_ACTION_HIJACK)&& ctx->manipulate_replaced==1) @@ -3038,23 +3079,23 @@ static inline int ctx_actually_manipulate(struct pangu_http_ctx * ctx) } } -void pangu_on_http_end(const struct tfe_stream * stream, +void proxy_on_http_end(const struct tfe_stream * stream, const struct tfe_http_session * session, unsigned int thread_id, void ** pme) { - if (!g_pangu_rt->enable_plugin) + if (!g_proxy_rt->enable_plugin) { return; } - struct pangu_http_ctx * ctx = *(struct pangu_http_ctx **) pme; + struct proxy_http_ctx * ctx = *(struct proxy_http_ctx **) pme; size_t i=0, j=0; int ret=0; - if(ctx->action == PG_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_REPLACE && ctx->rep_ctx->actually_replaced==0) + if(ctx->action == PX_ACTION_MANIPULATE && ctx->param->action == MA_ACTION_REPLACE && ctx->rep_ctx->actually_replaced==0) { for(i=0; i< ctx->n_enforce; i++) { - if((unsigned char)ctx->enforce_rules[i].action == PG_ACTION_MANIPULATE) + if((unsigned char)ctx->enforce_rules[i].action == PX_ACTION_MANIPULATE) { if(i+1 > ctx->n_enforce) { @@ -3066,66 +3107,66 @@ void pangu_on_http_end(const struct tfe_stream * stream, ctx->n_enforce-=j; if(ctx->n_enforce==0) { - ctx->action = PG_ACTION_NONE; + ctx->action = PX_ACTION_NONE; FREE(&(ctx->enforce_rules)); } } - struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce, + struct proxy_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce, .req_body=ctx->log_req_body, .resp_body=ctx->log_resp_body, .action=0, .inject_sz=ctx->inject_sz, .asn_client=ctx->ip_ctx.asn_client, .asn_server=ctx->ip_ctx.asn_server, .location_client=ctx->ip_ctx.location_client, .location_server=ctx->ip_ctx.location_server}; - if(ctx->action == PG_ACTION_MANIPULATE) + if(ctx->action == PX_ACTION_MANIPULATE) { log_msg.action = ctx->param->action; } - if(ctx->action != PG_ACTION_NONE && + if(ctx->action != PX_ACTION_NONE && (((ctx_actually_replaced(ctx)) || (ctx_actually_inserted(ctx)) || (ctx_actually_edited(ctx)) || - (ctx_actually_manipulate(ctx)) || ctx_actually_ran_script(ctx)) || (ctx->action == PG_ACTION_MONIT || - ctx->action == PG_ACTION_REJECT || ctx->action == PG_ACTION_WHITELIST))) + (ctx_actually_manipulate(ctx)) || ctx_actually_ran_script(ctx)) || (ctx->action == PX_ACTION_MONIT || + ctx->action == PX_ACTION_REJECT || ctx->action == PX_ACTION_WHITELIST))) { - ret=pangu_send_log(g_pangu_rt->send_logger, &log_msg); - ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_LOG_NUM]), ret); + ret=proxy_send_log(g_proxy_rt->send_logger, &log_msg); + ATOMIC_ADD(&(g_proxy_rt->stat_val[STAT_LOG_NUM]), ret); for(i=0; i< ctx->n_enforce; i++) { - if(ctx->enforce_rules[i].action == PG_ACTION_MONIT) + if(ctx->enforce_rules[i].action == PX_ACTION_MONIT) { - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_MONIT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_MONIT])); } } } if(ctx->rep_ctx && ctx->rep_ctx->actually_replaced==1) { - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_REPLACE])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_REPLACE])); } if(ctx->tsg_ctx && ctx->tsg_ctx->actually_executed==1) { - ATOMIC_INC(&(g_pangu_rt->stat_val[STAT_ACTION_RUN_SCRIPT])); + ATOMIC_INC(&(g_proxy_rt->stat_val[STAT_ACTION_RUN_SCRIPT])); } - TFE_LOG_DEBUG(g_pangu_rt->local_logger, "cache %s %s upload=%d", + TFE_LOG_DEBUG(g_proxy_rt->local_logger, "cache %s %s upload=%d", session->req->req_spec.url, cache_pending_result_string(ctx->pending_result), ctx->cache_wirte_result); cache_mid_clear(&(ctx->cmid)); - pangu_http_ctx_free(ctx); + proxy_http_ctx_free(ctx); *pme = NULL; return; } -int pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_session * session, +int proxy_on_http_data(const struct tfe_stream * stream, const struct tfe_http_session * session, enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, unsigned int thread_id, void ** pme) { - if (!g_pangu_rt->enable_plugin) + if (!g_proxy_rt->enable_plugin) { return CALL_NEXT_PLUGIN; } - struct pangu_http_ctx * ctx = *(struct pangu_http_ctx **) pme; + struct proxy_http_ctx * ctx = *(struct proxy_http_ctx **) pme; int ret=0; if(ctx->resumed_cb) { @@ -3139,7 +3180,7 @@ int pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_s enforce_control_policy(stream, session, events, body_frag, frag_size,thread_id, ctx); - if(g_pangu_rt->cache_enabled && ctx->action == PG_ACTION_NONE) + if(g_proxy_rt->cache_enabled && ctx->action == PX_ACTION_NONE) { if(events & EV_HTTP_REQ_HDR) { @@ -3165,17 +3206,17 @@ int pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_s return NO_CALL_NEXT_PLUGIN; } -struct tfe_plugin pangu_http_spec = { +struct tfe_plugin proxy_http_spec = { .symbol=NULL, .type = TFE_PLUGIN_TYPE_BUSINESS, - .on_init = pangu_http_init, + .on_init = proxy_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 + .on_session_begin=proxy_on_http_begin, + .on_session_data=proxy_on_http_data, + .on_session_end=proxy_on_http_end }; -TFE_PLUGIN_REGISTER(pangu_http, pangu_http_spec) +TFE_PLUGIN_REGISTER(proxy_http, proxy_http_spec) diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp similarity index 94% rename from plugin/business/pangu-http/src/pangu_logger.cpp rename to plugin/business/tsg-http/src/tsg_logger.cpp index fc57122..2d0b5aa 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/tsg-http/src/tsg_logger.cpp @@ -5,14 +5,14 @@ #include #include -#include "pangu_logger.h" +#include "tsg_proxy_logger.h" struct json_spec { const char *log_filed_name; enum tfe_http_std_field field_id; }; -struct pangu_logger +struct proxy_logger { int entry_id; unsigned int en_hoslog; @@ -43,17 +43,17 @@ enum _log_action //Bigger action number is prior. __LG_ACTION_MAX }; -struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger) +struct proxy_logger* proxy_log_handle_create(const char* profile, const char* section, void* local_logger) { struct tango_cache_parameter *log_file_upload_para=NULL; - struct pangu_logger* instance=ALLOC(struct pangu_logger,1); + struct proxy_logger* instance=ALLOC(struct proxy_logger,1); instance->local_logger=local_logger; - TFE_LOG_INFO(local_logger,"Pangu log is inititating from %s section %s.", profile, section); + TFE_LOG_INFO(local_logger,"Tsg-Pxy log is inititating from %s section %s.", profile, section); MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0); MESA_load_profile_uint_def(profile, section, "en_hoslog", &instance->en_hoslog, 1); MESA_load_profile_uint_def(profile, section, "en_sendlog", &instance->en_sendlog, 1); - TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE"); + TFE_LOG_INFO(local_logger, "Tsg-Pxy sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE"); if (!instance->en_sendlog) { @@ -65,7 +65,7 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s instance->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER); if (instance->kafka_logger && !instance->kafka_logger->enable) { - TFE_LOG_ERROR(local_logger, "Pangu sendlog ENABLE, but tfe kafka logger DISABLED."); + TFE_LOG_ERROR(local_logger, "Tsg-Pxy sendlog ENABLE, but tfe kafka logger DISABLED."); goto error_out; } @@ -74,7 +74,7 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger); if (log_file_upload_para == NULL) { - TFE_LOG_ERROR(local_logger, "Pangu failed to new cache evbase parameter."); + TFE_LOG_ERROR(local_logger, "Tsg-Pxy failed to new cache evbase parameter."); goto error_out; } instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger); @@ -86,7 +86,7 @@ error_out: return NULL; } -static unsigned int pangu_log_get_fqdn_cat(struct tfe_cmsg *cmsg, unsigned int *category_id_val) +static unsigned int proxy_log_get_fqdn_cat(struct tfe_cmsg *cmsg, unsigned int *category_id_val) { int ret=0; unsigned category_id_num=0; @@ -106,7 +106,7 @@ static unsigned int pangu_log_get_fqdn_cat(struct tfe_cmsg *cmsg, unsigned int * return category_id_num > 8 ? 8 : category_id_num; } -int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) +int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg) { const struct tfe_http_session* http=log_msg->http; const struct tfe_stream_addr* addr=log_msg->stream->addr; @@ -147,7 +147,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) common_obj=cJSON_CreateObject(); cur_time = time(NULL); - cJSON_AddNumberToObject(common_obj, "common_start_time", cur_time); + cJSON_AddNumberToObject(common_obj, "common_start_time", http->start_time); cJSON_AddNumberToObject(common_obj, "common_end_time", cur_time); cJSON_AddStringToObject(common_obj, "http_version", app_proto[http->major_version]); cJSON_AddStringToObject(common_obj, "common_schema_type", "HTTP"); @@ -167,7 +167,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) { cJSON_AddNumberToObject(common_obj, "common_direction", common_direction); //0:域内->域外,1:域外->域内,描述的是CLIENT_IP信息 } - ret = pangu_log_get_fqdn_cat(cmsg, category_id_val); + ret = proxy_log_get_fqdn_cat(cmsg, category_id_val); if (ret>0) { cJSON_AddItemToObject(common_obj, "common_service_category", cJSON_CreateIntArray((const int*)category_id_val, ret)); diff --git a/plugin/business/pangu-http/src/pangu_web_cache.cpp b/plugin/business/tsg-http/src/tsg_web_cache.cpp similarity index 99% rename from plugin/business/pangu-http/src/pangu_web_cache.cpp rename to plugin/business/tsg-http/src/tsg_web_cache.cpp index ab22e07..fdc974b 100644 --- a/plugin/business/pangu-http/src/pangu_web_cache.cpp +++ b/plugin/business/tsg-http/src/tsg_web_cache.cpp @@ -1,5 +1,5 @@ -#include "pangu_web_cache.h" +#include "tsg_proxy_web_cache.h" #include #include diff --git a/plugin/business/pangu-http/src/replace_tool.cpp b/plugin/business/tsg-http/test/replace_tool.cpp similarity index 100% rename from plugin/business/pangu-http/src/replace_tool.cpp rename to plugin/business/tsg-http/test/replace_tool.cpp diff --git a/plugin/business/pangu-http/test_data/facebook_index.html b/plugin/business/tsg-http/test/test_data/facebook_index.html similarity index 100% rename from plugin/business/pangu-http/test_data/facebook_index.html rename to plugin/business/tsg-http/test/test_data/facebook_index.html diff --git a/plugin/business/pangu-http/test_data/google_search_gtest_cnblog.html b/plugin/business/tsg-http/test/test_data/google_search_gtest_cnblog.html similarity index 100% rename from plugin/business/pangu-http/test_data/google_search_gtest_cnblog.html rename to plugin/business/tsg-http/test/test_data/google_search_gtest_cnblog.html diff --git a/plugin/business/pangu-http/test_data/http_session.lua b/plugin/business/tsg-http/test/test_data/http_session.lua similarity index 100% rename from plugin/business/pangu-http/test_data/http_session.lua rename to plugin/business/tsg-http/test/test_data/http_session.lua diff --git a/plugin/business/pangu-http/test_data/index_of__centos.html b/plugin/business/tsg-http/test/test_data/index_of__centos.html similarity index 100% rename from plugin/business/pangu-http/test_data/index_of__centos.html rename to plugin/business/tsg-http/test/test_data/index_of__centos.html diff --git a/plugin/business/pangu-http/src/test_edit_element.cpp b/plugin/business/tsg-http/test/test_edit_element.cpp similarity index 100% rename from plugin/business/pangu-http/src/test_edit_element.cpp rename to plugin/business/tsg-http/test/test_edit_element.cpp diff --git a/plugin/business/pangu-http/src/test_http_lua.cpp b/plugin/business/tsg-http/test/test_http_lua.cpp similarity index 82% rename from plugin/business/pangu-http/src/test_http_lua.cpp rename to plugin/business/tsg-http/test/test_http_lua.cpp index 56c1d33..330b5bf 100644 --- a/plugin/business/pangu-http/src/test_http_lua.cpp +++ b/plugin/business/tsg-http/test/test_http_lua.cpp @@ -46,8 +46,8 @@ struct def_lua_http_headers def_lua_http_head_value[]={{"accept", "text/html", T struct tsg_lua_pattern { - int *script_id; int thread_num; + struct elua_script **elua_ctx; struct tsg_lua_script *lua_script; struct lua_http_headers lua_http_head_list; }; @@ -151,51 +151,10 @@ static int lua_http_default_headers_init(struct def_lua_http_headers *lua_http_h return 0; } -struct tsg_lua_script *tsg_lua_script_new(int lua_is_cache, const char *input_lua_data, size_t input_lua_data_len, int thread_num) +int http_lua_profile_for_test(int profile_id, struct elua_script ***elua_ctx) { - int i=0; - struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1); - - lua_script->lua_is_cache=lua_is_cache; - lua_script->http_lua_handle = http_lua_handle_create(thread_num, "tfe"); - - if(lua_is_cache) - { - for(i=0; iscript_id[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input_lua_data, input_lua_data_len); - } - } - - return lua_script; -} - -void lua_script_handle_destory(struct tsg_lua_script *lua_script) -{ - int i=0; - - for(i=0; i< g_tsg_lua_pattern->thread_num; i++) - { - tsg_destory_lua(lua_script->http_lua_handle[i]); - } - - FREE(&lua_script); -} - -int tsg_lua_pattern_profile_from_path(int profile_id, char **profile_msg, size_t *msg_len, int **script_id, int *timeout) -{ - int ret=0; - size_t input_sz=0; - const char* filename="./test_data/http_session.lua"; - - char *input= tfe_read_file(filename, &input_sz); - - *profile_msg=input; - *msg_len = input_sz; - *script_id = g_tsg_lua_pattern->script_id; - *timeout=1000; - - return ret; + *elua_ctx=g_tsg_lua_pattern->elua_ctx; + return 0; } void lua_http_session_destory(struct tfe_http_session *session) @@ -239,7 +198,6 @@ const struct tfe_http_session *lua_http_session_init() return session; } -#if 0 TEST(TSG_LUA_SCRIPT, Lua_TimeOut) { int ret=0; @@ -254,18 +212,17 @@ TEST(TSG_LUA_SCRIPT, Lua_TimeOut) tsg_ctx.http_req_uri=2; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; clock_gettime(CLOCK_REALTIME, &(start_time)); ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret==ERR_SCRIPT_TIMEOUT); + EXPECT_TRUE(ret!=0); clock_gettime(CLOCK_REALTIME, &(end_time)); printf("take time %lu(s)\n", end_time.tv_sec - start_time.tv_sec); lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session); } -#endif TEST(TSG_LUA_SCRIPT, Req_Uri) { @@ -279,13 +236,14 @@ TEST(TSG_LUA_SCRIPT, Req_Uri) tsg_ctx.http_req_uri=1; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; tsg_ctx.session->req->req_spec.uri = tfe_strdup("forecast"); ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + EXPECT_TRUE(ret==0); - EXPECT_STREQ(tsg_ctx.session->req->req_spec.uri, "team"); + EXPECT_STREQ(tsg_ctx.rewrite_uri,"team"); + FREE(&tsg_ctx.rewrite_uri); lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session); } @@ -300,11 +258,11 @@ TEST(TSG_LUA_SCRIPT, Req_Header) tsg_ctx.events = EV_HTTP_REQ_HDR; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; tsg_ctx.session->req->req_spec.method = TFE_HTTP_METHOD_GET; ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + EXPECT_TRUE(ret==0); const char* user_agent_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_USER_AGENT); EXPECT_TRUE(user_agent_val!=NULL); @@ -328,11 +286,11 @@ TEST(TSG_LUA_SCRIPT, Resp_Header) tsg_ctx.events = EV_HTTP_RESP_HDR; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; tsg_ctx.session->resp->resp_spec.resp_code = 200; ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + EXPECT_TRUE(ret==0); const char* content_type_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_CONT_TYPE); EXPECT_TRUE(content_type_val!=NULL); @@ -352,14 +310,14 @@ TEST(TSG_LUA_SCRIPT, Req_Data) tsg_ctx.events = EV_HTTP_REQ_BODY_END; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; const char *input="This is request data"; tsg_ctx.http_body = evbuffer_new(); evbuffer_add(tsg_ctx.http_body, input, strlen(input)); ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + EXPECT_TRUE(ret==0); ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL); char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1); @@ -383,14 +341,14 @@ TEST(TSG_LUA_SCRIPT, Resq_Data) tsg_ctx.events = EV_HTTP_RESP_BODY_END; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; + lua_script->http_lua_profile = http_lua_profile_for_test; const char *input="This is response data"; tsg_ctx.http_body = evbuffer_new(); evbuffer_add(tsg_ctx.http_body, input, strlen(input)); ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + EXPECT_TRUE(ret==0); ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL); char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1); @@ -414,11 +372,11 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session) tsg_ctx.events = EV_HTTP_RESP_HDR; struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script; - lua_script->http_lua_profile = tsg_lua_pattern_profile_from_path; - tsg_ctx.lua_ctx=http_lua_ctx_new(lua_script, thread_id); + lua_script->http_lua_profile = http_lua_profile_for_test; + tsg_ctx.elua_ctx=http_lua_ctx_new(lua_script, thread_id); - ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.lua_ctx, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx); + EXPECT_TRUE(ret==0); const char* content_type_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_CONT_TYPE); EXPECT_TRUE(content_type_val!=NULL); @@ -429,8 +387,8 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session) const char *user_input="This is response data"; evbuffer_add(tsg_ctx.http_body, user_input, strlen(user_input)); - ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.lua_ctx, thread_id, (void *)&tsg_ctx); - EXPECT_TRUE(ret>0); + ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx); + EXPECT_TRUE(ret==0); EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL); char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1); @@ -440,7 +398,7 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session) evbuffer_free(tsg_ctx.http_body); evbuffer_free(tsg_ctx.http_lua_body); - http_lua_ctx_free(lua_script, thread_id, tsg_ctx.lua_ctx); + http_lua_ctx_free(lua_script, thread_id, tsg_ctx.elua_ctx); lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session); } @@ -452,21 +410,16 @@ int main(int argc, char ** argv) int i=0, thread_num=1; struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1); - lua_script->lua_is_cache=0; - lua_script->http_lua_handle = http_lua_handle_create(thread_num, "tfe"); + http_lua_handle_create(lua_script, thread_num, "tfe"); - if(lua_script->lua_is_cache) + size_t input_sz; + const char* filename="./test_data/http_session.lua"; + char *input= tfe_read_file(filename, &input_sz); + + tsg_lua_pattern->elua_ctx = ALLOC(struct elua_script*, thread_num); + for(i=0; iscript_id = ALLOC(int, thread_num); - - for(i=0; iscript_id[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input, input_sz); - } + tsg_lua_pattern->elua_ctx[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input, input_sz, 1000); } tsg_lua_pattern->lua_script=lua_script; diff --git a/plugin/business/pangu-http/src/test_pattern_replace.cpp b/plugin/business/tsg-http/test/test_pattern_replace.cpp similarity index 100% rename from plugin/business/pangu-http/src/test_pattern_replace.cpp rename to plugin/business/tsg-http/test/test_pattern_replace.cpp diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index 48b4bfe..658625b 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -1117,6 +1117,7 @@ struct http_session_private * hs_private_create(struct http_connection_private * __hs_private->hs_public.req = hf_private_req != NULL ? to_hf_public(hf_private_req) : NULL; __hs_private->hs_public.resp = hf_private_req != NULL ? to_hf_public(hf_private_resp) : NULL; __hs_private->hs_public.session_id = hc_private->session_id_counter++; + __hs_private->hs_public.start_time=time(NULL); /* HS-PRIVATE*/ __hs_private->hc_private = hc_private; diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 2dade0a..c5ea3b3 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -1270,6 +1270,7 @@ static int tfe_half_session_init(struct tfe_h2_session *h2_session, int32_t stre struct tfe_h2_half_private *req = h2_session->req; tfe_session->ops = &http2_session_ops; tfe_session->req = &req->half_public; + tfe_session->start_time=time(NULL); tfe_session->session_id = stream_id; } diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index a661483..a361c16 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -174,7 +174,7 @@ set_property(TARGET rdkafka PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR} set_property(TARGET rdkafka PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR}/MESA) add_library(tsglua SHARED IMPORTED GLOBAL) -set_property(TARGET tsglua PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR}/libtsglua.so) +set_property(TARGET tsglua PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR}/libelua.so) set_property(TARGET tsglua PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR}) add_library(mrzcpd SHARED IMPORTED GLOBAL)