TSG-11849 tfe增加从环境变量中读入处理机ip
TSG-11742 IP Libraries统一使用.分隔地理层级 TSG-10722 日志中开始时间从解析层获取
This commit is contained in:
@@ -268,6 +268,7 @@ struct tfe_http_session
|
|||||||
unsigned int session_id;
|
unsigned int session_id;
|
||||||
short major_version;
|
short major_version;
|
||||||
short minor_version;
|
short minor_version;
|
||||||
|
time_t start_time;
|
||||||
|
|
||||||
struct tfe_http_session_ops * ops;
|
struct tfe_http_session_ops * ops;
|
||||||
struct tfe_http_half * req;
|
struct tfe_http_half * req;
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ extern "C"
|
|||||||
rd_kafka_topic_t *kafka_topic;
|
rd_kafka_topic_t *kafka_topic;
|
||||||
} tfe_kafka_logger_t;
|
} 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,
|
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);
|
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);
|
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
|
#ifdef __cpluscplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
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));
|
tfe_kafka_logger_t *logger = (tfe_kafka_logger_t *)calloc(1, sizeof(tfe_kafka_logger_t));
|
||||||
if (!logger)
|
if (!logger)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -114,15 +115,23 @@ tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, co
|
|||||||
if (!logger->enable)
|
if (!logger->enable)
|
||||||
return logger;
|
return logger;
|
||||||
|
|
||||||
logger->local_ip_num = get_ip_by_eth_name(nic_name);
|
override_sled_ip = getenv("OVERRIDE_SLED_IP");
|
||||||
if (logger->local_ip_num == INADDR_NONE)
|
if(override_sled_ip != NULL)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(local_logger, "Error to get NIC_NAME: %s.", nic_name);
|
strncpy(logger->local_ip_str, override_sled_ip, strlen(override_sled_ip));
|
||||||
free(logger);
|
goto create_kafka;
|
||||||
return NULL;
|
}
|
||||||
}
|
|
||||||
inet_ntop(AF_INET, &(logger->local_ip_num), logger->local_ip_str, sizeof(logger->local_ip_str));
|
|
||||||
|
|
||||||
|
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));
|
strncpy(logger->broker_list, brokerlist, strlen(brokerlist));
|
||||||
logger->kafka_handle = create_kafka_handle(logger->broker_list, sasl_username, sasl_passwd, local_logger);
|
logger->kafka_handle = create_kafka_handle(logger->broker_list, sasl_username, sasl_passwd, local_logger);
|
||||||
if (logger->kafka_handle == NULL)
|
if (logger->kafka_handle == NULL)
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ error_out:
|
|||||||
static tfe_kafka_logger_t *create_kafka_logger(const char *profile, const char *section, void *logger)
|
static tfe_kafka_logger_t *create_kafka_logger(const char *profile, const char *section, void *logger)
|
||||||
{
|
{
|
||||||
int enable = 0;
|
int enable = 0;
|
||||||
char nic_name[64] = {0};
|
char nic_name[TFE_SYMBOL_MAX] = {0};
|
||||||
char brokerlist[TFE_STRING_MAX] = {0};
|
char brokerlist[TFE_STRING_MAX] = {0};
|
||||||
char topic_name[TFE_STRING_MAX] = {0};
|
char topic_name[TFE_STRING_MAX] = {0};
|
||||||
char sasl_username[TFE_STRING_MAX] = {0};
|
char sasl_username[TFE_STRING_MAX] = {0};
|
||||||
|
|||||||
@@ -205,11 +205,11 @@ int tfe_scan_ip_location(const struct tfe_stream *stream, struct Maat_rule_t *re
|
|||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
if(strlen(dst_subdivsion))
|
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
|
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);
|
*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));
|
memset(buff, 0, sizeof(buff));
|
||||||
if(strlen(src_subdivsion))
|
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
|
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);
|
*location_client = tfe_strdup(buff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ tfe.DEBUG "./log/tfe.log.%d(%F)";
|
|||||||
http.DEBUG "./log/http.log.%d(%F)";
|
http.DEBUG "./log/http.log.%d(%F)";
|
||||||
http2.DEBUG "./log/http2.log.%d(%F)";
|
http2.DEBUG "./log/http2.log.%d(%F)";
|
||||||
doh.DEBUG "./log/doh_pxy.log.%d(%F)";
|
doh.DEBUG "./log/doh_pxy.log.%d(%F)";
|
||||||
pangu.DEBUG "./log/pangu_pxy.log.%d(%F)";
|
tsg_http.DEBUG "./log/tsg_http_pxy.log.%d(%F)";
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ if(ENABLE_PLUGIN_DOH)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_PLUGIN_PANGU_HTTP)
|
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()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_PLUGIN_SSL_POLICY)
|
if(ENABLE_PLUGIN_SSL_POLICY)
|
||||||
|
|||||||
@@ -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 ssl_mid_cert_kafka_logger_create(const char *profile, const char *section)
|
||||||
{
|
{
|
||||||
int enable = 0;
|
int enable = 0;
|
||||||
char nic_name[64] = {0};
|
char nic_name[TFE_SYMBOL_MAX] = {0};
|
||||||
char broker_list[TFE_SYMBOL_MAX] = {0};
|
char broker_list[TFE_SYMBOL_MAX] = {0};
|
||||||
char topic_name[TFE_SYMBOL_MAX] = {0};
|
char topic_name[TFE_SYMBOL_MAX] = {0};
|
||||||
char sasl_username[TFE_STRING_MAX] = {0};
|
char sasl_username[TFE_STRING_MAX] = {0};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
add_subdirectory(traffic-mirror)
|
add_subdirectory(traffic-mirror)
|
||||||
add_subdirectory(doh)
|
add_subdirectory(doh)
|
||||||
add_subdirectory(pangu-http)
|
add_subdirectory(tsg-http)
|
||||||
add_subdirectory(ssl-policy)
|
add_subdirectory(ssl-policy)
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -1,713 +0,0 @@
|
|||||||
#include "pattern_replace.h"
|
|
||||||
#include "http_lua.h"
|
|
||||||
|
|
||||||
#include <tfe_utils.h>
|
|
||||||
#include <tfe_http.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
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; i<out_lua_argc; i++)
|
|
||||||
{
|
|
||||||
char *in=out_lua_argv[i].str;
|
|
||||||
size_t in_sz=strlen(out_lua_argv[i].str);
|
|
||||||
if(in == NULL || in_sz ==0 || (sizeof(buff) - (p - buff)) <= 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFE_LOG_DEBUG(tsg_ctx->local_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; i<out_lua_argc; i++)
|
|
||||||
{
|
|
||||||
char *in=out_lua_argv[i].str;
|
|
||||||
size_t in_sz=strlen(out_lua_argv[i].str);
|
|
||||||
if(in == NULL || in_sz ==0 )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFE_LOG_INFO(tsg_ctx->local_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; i<out_lua_argc; i++)
|
|
||||||
{
|
|
||||||
char *in=out_lua_argv[i].str;
|
|
||||||
size_t in_sz=strlen(out_lua_argv[i].str);
|
|
||||||
if(in == NULL || in_sz ==0 )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFE_LOG_ERROR(tsg_ctx->local_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; i<out_lua_argc; i++)
|
|
||||||
{
|
|
||||||
char *in=out_lua_argv[i].str;
|
|
||||||
size_t in_sz=strlen(out_lua_argv[i].str);
|
|
||||||
if(in == NULL || in_sz ==0 )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
evbuffer_add(tsg_ctx->http_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include <event2/buffer.h>
|
|
||||||
|
|
||||||
#include "pattern_replace.h"
|
|
||||||
#include <tfe_http.h>
|
|
||||||
#include <MESA/tsg_lua_interface.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
23
plugin/business/tsg-http/CMakeLists.txt
Normal file
23
plugin/business/tsg-http/CMakeLists.txt
Normal file
@@ -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)
|
||||||
40
plugin/business/tsg-http/include/http_lua.h
Normal file
40
plugin/business/tsg-http/include/http_lua.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <event2/buffer.h>
|
||||||
|
|
||||||
|
#include "pattern_replace.h"
|
||||||
|
#include <tfe_http.h>
|
||||||
|
#include <MESA/elua.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <tfe_http.h>
|
#include <tfe_http.h>
|
||||||
#include <MESA/Maat_rule.h>
|
#include <MESA/Maat_rule.h>
|
||||||
|
|
||||||
struct pangu_log
|
struct proxy_log
|
||||||
{
|
{
|
||||||
const struct tfe_stream *stream;
|
const struct tfe_stream *stream;
|
||||||
const struct tfe_http_session* http;
|
const struct tfe_http_session* http;
|
||||||
@@ -18,11 +18,11 @@ struct pangu_log
|
|||||||
char *location_client;
|
char *location_client;
|
||||||
char *location_server;
|
char *location_server;
|
||||||
};
|
};
|
||||||
struct pangu_logger;
|
struct proxy_logger;
|
||||||
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);
|
||||||
|
|
||||||
//return 0 if SUCCESS, otherwise return -1
|
//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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +39,14 @@ int match_start_indicator(xmlNodePtr parent, char * start_indicator)
|
|||||||
{
|
{
|
||||||
if(parent->properties == NULL)
|
if(parent->properties == NULL)
|
||||||
{
|
{
|
||||||
|
if(parent->name == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(!strcasecmp((char *)parent->name, start_indicator))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +65,30 @@ int match_start_indicator(xmlNodePtr parent, char * start_indicator)
|
|||||||
return 0;
|
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
|
#if 0
|
||||||
int match_string(const char * in, size_t in_sz, char *contained_keyword)
|
int match_string(const char * in, size_t in_sz, char *contained_keyword)
|
||||||
{
|
{
|
||||||
775
plugin/business/tsg-http/src/http_lua.cpp
Normal file
775
plugin/business/tsg-http/src/http_lua.cpp
Normal file
@@ -0,0 +1,775 @@
|
|||||||
|
#include "pattern_replace.h"
|
||||||
|
#include "http_lua.h"
|
||||||
|
|
||||||
|
#include <tfe_utils.h>
|
||||||
|
#include <tfe_http.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
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; i<out_lua_argc; i++)
|
||||||
|
{
|
||||||
|
char *in=out_lua_argv[i].buff;
|
||||||
|
size_t in_sz=out_lua_argv[i].len;
|
||||||
|
if(in == NULL || in_sz ==0 || (sizeof(buff) - (p - buff)) <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
||||||
|
}
|
||||||
|
|
||||||
|
TFE_LOG_DEBUG(tsg_ctx->local_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; i<out_lua_argc; i++)
|
||||||
|
{
|
||||||
|
char *in=out_lua_argv[i].buff;
|
||||||
|
size_t in_sz=out_lua_argv[i].len;
|
||||||
|
if(in == NULL || in_sz ==0 )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
||||||
|
}
|
||||||
|
|
||||||
|
TFE_LOG_INFO(tsg_ctx->local_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; i<out_lua_argc; i++)
|
||||||
|
{
|
||||||
|
char *in=out_lua_argv[i].buff;
|
||||||
|
size_t in_sz=out_lua_argv[i].len;
|
||||||
|
if(in == NULL || in_sz ==0 )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
p += snprintf(p, sizeof(buff) - (p - buff), " %s", in);
|
||||||
|
}
|
||||||
|
|
||||||
|
TFE_LOG_ERROR(tsg_ctx->local_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; i<out_lua_argc; i++)
|
||||||
|
{
|
||||||
|
char *in=out_lua_argv[i].buff;
|
||||||
|
size_t in_sz=strlen(out_lua_argv[i].buff);
|
||||||
|
if(in == NULL || in_sz ==0 )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
evbuffer_add(tsg_ctx->http_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;
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -5,14 +5,14 @@
|
|||||||
#include <tfe_utils.h>
|
#include <tfe_utils.h>
|
||||||
#include <tfe_resource.h>
|
#include <tfe_resource.h>
|
||||||
|
|
||||||
#include "pangu_logger.h"
|
#include "tsg_proxy_logger.h"
|
||||||
|
|
||||||
struct json_spec
|
struct json_spec
|
||||||
{
|
{
|
||||||
const char *log_filed_name;
|
const char *log_filed_name;
|
||||||
enum tfe_http_std_field field_id;
|
enum tfe_http_std_field field_id;
|
||||||
};
|
};
|
||||||
struct pangu_logger
|
struct proxy_logger
|
||||||
{
|
{
|
||||||
int entry_id;
|
int entry_id;
|
||||||
unsigned int en_hoslog;
|
unsigned int en_hoslog;
|
||||||
@@ -43,17 +43,17 @@ enum _log_action //Bigger action number is prior.
|
|||||||
__LG_ACTION_MAX
|
__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 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;
|
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_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_hoslog", &instance->en_hoslog, 1);
|
||||||
MESA_load_profile_uint_def(profile, section, "en_sendlog", &instance->en_sendlog, 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)
|
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);
|
instance->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
|
||||||
if (instance->kafka_logger && !instance->kafka_logger->enable)
|
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;
|
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);
|
log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger);
|
||||||
if (log_file_upload_para == NULL)
|
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;
|
goto error_out;
|
||||||
}
|
}
|
||||||
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);
|
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);
|
||||||
@@ -86,7 +86,7 @@ error_out:
|
|||||||
return NULL;
|
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;
|
int ret=0;
|
||||||
unsigned category_id_num=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;
|
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_http_session* http=log_msg->http;
|
||||||
const struct tfe_stream_addr* addr=log_msg->stream->addr;
|
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();
|
common_obj=cJSON_CreateObject();
|
||||||
cur_time = time(NULL);
|
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_AddNumberToObject(common_obj, "common_end_time", cur_time);
|
||||||
cJSON_AddStringToObject(common_obj, "http_version", app_proto[http->major_version]);
|
cJSON_AddStringToObject(common_obj, "http_version", app_proto[http->major_version]);
|
||||||
cJSON_AddStringToObject(common_obj, "common_schema_type", "HTTP");
|
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信息
|
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)
|
if (ret>0)
|
||||||
{
|
{
|
||||||
cJSON_AddItemToObject(common_obj, "common_service_category", cJSON_CreateIntArray((const int*)category_id_val, ret));
|
cJSON_AddItemToObject(common_obj, "common_service_category", cJSON_CreateIntArray((const int*)category_id_val, ret));
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "pangu_web_cache.h"
|
#include "tsg_proxy_web_cache.h"
|
||||||
#include <tango_cache_pending.h>
|
#include <tango_cache_pending.h>
|
||||||
#include <tango_cache_client.h>
|
#include <tango_cache_client.h>
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ struct def_lua_http_headers def_lua_http_head_value[]={{"accept", "text/html", T
|
|||||||
|
|
||||||
struct tsg_lua_pattern
|
struct tsg_lua_pattern
|
||||||
{
|
{
|
||||||
int *script_id;
|
|
||||||
int thread_num;
|
int thread_num;
|
||||||
|
struct elua_script **elua_ctx;
|
||||||
struct tsg_lua_script *lua_script;
|
struct tsg_lua_script *lua_script;
|
||||||
struct lua_http_headers lua_http_head_list;
|
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;
|
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;
|
*elua_ctx=g_tsg_lua_pattern->elua_ctx;
|
||||||
struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1);
|
return 0;
|
||||||
|
|
||||||
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; i<thread_num; i++)
|
|
||||||
{
|
|
||||||
g_tsg_lua_pattern->script_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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_http_session_destory(struct tfe_http_session *session)
|
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;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
|
TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
@@ -254,18 +212,17 @@ TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
|
|||||||
tsg_ctx.http_req_uri=2;
|
tsg_ctx.http_req_uri=2;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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));
|
clock_gettime(CLOCK_REALTIME, &(start_time));
|
||||||
ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx);
|
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));
|
clock_gettime(CLOCK_REALTIME, &(end_time));
|
||||||
printf("take time %lu(s)\n", end_time.tv_sec - start_time.tv_sec);
|
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);
|
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST(TSG_LUA_SCRIPT, Req_Uri)
|
TEST(TSG_LUA_SCRIPT, Req_Uri)
|
||||||
{
|
{
|
||||||
@@ -279,13 +236,14 @@ TEST(TSG_LUA_SCRIPT, Req_Uri)
|
|||||||
tsg_ctx.http_req_uri=1;
|
tsg_ctx.http_req_uri=1;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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");
|
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);
|
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);
|
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;
|
tsg_ctx.events = EV_HTTP_REQ_HDR;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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;
|
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);
|
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);
|
const char* user_agent_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_USER_AGENT);
|
||||||
EXPECT_TRUE(user_agent_val!=NULL);
|
EXPECT_TRUE(user_agent_val!=NULL);
|
||||||
@@ -328,11 +286,11 @@ TEST(TSG_LUA_SCRIPT, Resp_Header)
|
|||||||
tsg_ctx.events = EV_HTTP_RESP_HDR;
|
tsg_ctx.events = EV_HTTP_RESP_HDR;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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;
|
tsg_ctx.session->resp->resp_spec.resp_code = 200;
|
||||||
|
|
||||||
ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx);
|
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);
|
const char* content_type_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_CONT_TYPE);
|
||||||
EXPECT_TRUE(content_type_val!=NULL);
|
EXPECT_TRUE(content_type_val!=NULL);
|
||||||
@@ -352,14 +310,14 @@ TEST(TSG_LUA_SCRIPT, Req_Data)
|
|||||||
tsg_ctx.events = EV_HTTP_REQ_BODY_END;
|
tsg_ctx.events = EV_HTTP_REQ_BODY_END;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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";
|
const char *input="This is request data";
|
||||||
tsg_ctx.http_body = evbuffer_new();
|
tsg_ctx.http_body = evbuffer_new();
|
||||||
evbuffer_add(tsg_ctx.http_body, input, strlen(input));
|
evbuffer_add(tsg_ctx.http_body, input, strlen(input));
|
||||||
|
|
||||||
ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx);
|
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);
|
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||||
|
|
||||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
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;
|
tsg_ctx.events = EV_HTTP_RESP_BODY_END;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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";
|
const char *input="This is response data";
|
||||||
tsg_ctx.http_body = evbuffer_new();
|
tsg_ctx.http_body = evbuffer_new();
|
||||||
evbuffer_add(tsg_ctx.http_body, input, strlen(input));
|
evbuffer_add(tsg_ctx.http_body, input, strlen(input));
|
||||||
|
|
||||||
ret = execute_lua_script_rule(lua_script, profile_id, NULL, thread_id, (void *)&tsg_ctx);
|
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);
|
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||||
|
|
||||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
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;
|
tsg_ctx.events = EV_HTTP_RESP_HDR;
|
||||||
|
|
||||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
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.lua_ctx=http_lua_ctx_new(lua_script, thread_id);
|
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);
|
ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, 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);
|
const char* content_type_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_CONT_TYPE);
|
||||||
EXPECT_TRUE(content_type_val!=NULL);
|
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";
|
const char *user_input="This is response data";
|
||||||
evbuffer_add(tsg_ctx.http_body, user_input, strlen(user_input));
|
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);
|
ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
|
||||||
EXPECT_TRUE(ret>0);
|
EXPECT_TRUE(ret==0);
|
||||||
EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||||
|
|
||||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
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_body);
|
||||||
evbuffer_free(tsg_ctx.http_lua_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);
|
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;
|
int i=0, thread_num=1;
|
||||||
struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1);
|
struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1);
|
||||||
|
|
||||||
lua_script->lua_is_cache=0;
|
http_lua_handle_create(lua_script, thread_num, "tfe");
|
||||||
lua_script->http_lua_handle = http_lua_handle_create(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; i<thread_num; i++)
|
||||||
{
|
{
|
||||||
size_t input_sz;
|
tsg_lua_pattern->elua_ctx[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input, input_sz, 1000);
|
||||||
const char* filename="./test_data/http_session.lua";
|
|
||||||
char *input= tfe_read_file(filename, &input_sz);
|
|
||||||
|
|
||||||
tsg_lua_pattern->script_id = ALLOC(int, thread_num);
|
|
||||||
|
|
||||||
for(i=0; i<thread_num; i++)
|
|
||||||
{
|
|
||||||
tsg_lua_pattern->script_id[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input, input_sz);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tsg_lua_pattern->lua_script=lua_script;
|
tsg_lua_pattern->lua_script=lua_script;
|
||||||
@@ -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.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.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.session_id = hc_private->session_id_counter++;
|
||||||
|
__hs_private->hs_public.start_time=time(NULL);
|
||||||
|
|
||||||
/* HS-PRIVATE*/
|
/* HS-PRIVATE*/
|
||||||
__hs_private->hc_private = hc_private;
|
__hs_private->hc_private = hc_private;
|
||||||
|
|||||||
@@ -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;
|
struct tfe_h2_half_private *req = h2_session->req;
|
||||||
tfe_session->ops = &http2_session_ops;
|
tfe_session->ops = &http2_session_ops;
|
||||||
tfe_session->req = &req->half_public;
|
tfe_session->req = &req->half_public;
|
||||||
|
tfe_session->start_time=time(NULL);
|
||||||
tfe_session->session_id = stream_id;
|
tfe_session->session_id = stream_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
vendor/CMakeLists.txt
vendored
2
vendor/CMakeLists.txt
vendored
@@ -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)
|
set_property(TARGET rdkafka PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR}/MESA)
|
||||||
|
|
||||||
add_library(tsglua SHARED IMPORTED GLOBAL)
|
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})
|
set_property(TARGET tsglua PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR})
|
||||||
|
|
||||||
add_library(mrzcpd SHARED IMPORTED GLOBAL)
|
add_library(mrzcpd SHARED IMPORTED GLOBAL)
|
||||||
|
|||||||
Reference in New Issue
Block a user