TSG-22707 tfe adapts to maat interface changes

This commit is contained in:
fengweihao
2024-09-29 20:01:49 +08:00
parent a94b7d55b5
commit a032f97535
16 changed files with 909 additions and 1361 deletions

View File

@@ -118,7 +118,7 @@ static cJSON *doh_get_answer_records(struct doh_ctx *ctx, cJSON *object, int qty
return NULL;
}
void doh_action_param_free_cb(int table_id, void **ad, long argl, void *argp)
void doh_action_param_free_cb(const char *table_name, void **ad, long argl, void *argp)
{
if(*ad==NULL)
{
@@ -135,14 +135,14 @@ void doh_action_param_free_cb(int table_id, void **ad, long argl, void *argp)
pthread_mutex_unlock(&(param->lock));
pthread_mutex_destroy(&(param->lock));
if(param->hit_rule.srv_def_large)
FREE(&(param->hit_rule.srv_def_large))
if(param->hit_rule.action_parameter)
FREE(&(param->hit_rule.action_parameter))
FREE(&(param));
return;
}
static void doh_get_cheat_data(long long p_result, int qtype, struct doh_ctx *ctx, const char *str_stream_info)
static void doh_get_cheat_data(uuid_t p_result, int qtype, struct doh_ctx *ctx, const char *str_stream_info)
{
int i;
int answer_size = 0;
@@ -150,28 +150,24 @@ static void doh_get_cheat_data(long long p_result, int qtype, struct doh_ctx *ct
cJSON *item = NULL;
cJSON *object = NULL;
cJSON *answer_array = NULL;
int table_id=0;
table_id=maat_get_table_id(g_doh_conf->maat, "PXY_CTRL_COMPILE_PLUGIN");
if(table_id < 0)
{
return;
}
struct doh_action_param *get_ex_param=(struct doh_action_param *)maat_plugin_table_get_ex_data(g_doh_conf->maat, table_id, (const char *)&p_result, sizeof(p_result));
char result_str[UUID_STRING_SIZE]={0};
uuid_unparse(p_result, result_str);
struct doh_action_param *get_ex_param=(struct doh_action_param *)maat_plugin_table_get_ex_data(g_doh_conf->maat, "PXY_CTRL_RULE_PLUGIN", result_str, strlen(result_str));
if(get_ex_param==NULL)
{
return;
}
struct doh_maat_rule_t *hit_rule = &(get_ex_param->hit_rule);
if(hit_rule==NULL || hit_rule->srv_def_large==NULL)
if(hit_rule==NULL || hit_rule->action_parameter==NULL)
{
goto end;
}
memcpy(ctx->result, hit_rule, sizeof(struct doh_maat_rule_t));
TFE_LOG_INFO(g_doh_conf->local_logger, "%s hit %lld %s", str_stream_info, p_result, hit_rule->srv_def_large);
TFE_LOG_INFO(g_doh_conf->local_logger, "%s hit %s %s", str_stream_info, result_str, hit_rule->action_parameter);
object = cJSON_Parse(hit_rule->srv_def_large);
object = cJSON_Parse(hit_rule->action_parameter);
if (object == NULL)
{
goto end;
@@ -240,26 +236,25 @@ end:
}
}
static long long doh_fetch_rule(long long *result, int result_num)
static int doh_fetch_rule(uuid_t *result, uuid_t p_result, int result_num)
{
int i = 0;
long long p_result = 0;
uuid_clear(p_result);
for (i = 0; i < result_num && i < MAX_SCAN_RESULT; i++)
for (int i = 0; i < result_num && i < MAX_SCAN_RESULT; i++)
{
if (p_result == 0)
if (uuid_is_null(p_result) == 1)
{
p_result = result[i];
uuid_copy(p_result, result[i]);
continue;
}
if (result[i] > p_result)
if(uuid_compare(result[i], p_result) > 0)
{
p_result = result[i];
uuid_copy(p_result, result[i]);
}
}
return p_result;
return 0;
}
static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http_session *session, struct doh_ctx *ctx, char *qname, int qtype)
@@ -268,8 +263,9 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
int scan_ret = 0;
size_t n_hit_result;
struct ipaddr sapp_addr;
long long p_result = 0;
long long result[MAX_SCAN_RESULT];
uuid_t p_result;
uuid_t result[MAX_SCAN_RESULT]={0};
char result_str[UUID_STRING_SIZE]={0};
scan_ret = tfe_scan_subscribe_id(stream, result, ctx->scan_mid, hit_cnt, g_doh_conf->local_logger);
if (scan_ret > 0)
@@ -287,27 +283,29 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
const char *host = session->req->req_spec.host;
if (host)
{
scan_ret = maat_scan_string(g_doh_conf->maat, g_doh_conf->tables[TYPE_HOST].id,host, strlen(host),
scan_ret = maat_scan_string(g_doh_conf->maat, "TSG_OBJ_FQDN", "ATTR_SERVER_FQDN", host, strlen(host),
result + hit_cnt, MAX_SCAN_RESULT - hit_cnt, &n_hit_result, ctx->scan_mid);
if (scan_ret == MAAT_SCAN_HIT)
{
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, Hit host: %s scan ret: %d policy_id: %lld addr: %s",
g_doh_conf->tables[TYPE_HOST].name, host, scan_ret, result[hit_cnt], stream->str_stream_info);
memset(result_str, 0, sizeof(result_str));
uuid_unparse(result[hit_cnt], result_str);
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, Hit host: %s scan ret: %d policy_id: %s addr: %s",
"ATTR_SERVER_FQDN", host, scan_ret, result_str, stream->str_stream_info);
hit_cnt += n_hit_result;
}
else
{
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, NO hit host: %s scan ret: %d addr: %s",
g_doh_conf->tables[TYPE_HOST].name, host, scan_ret, stream->str_stream_info);
"ATTR_SERVER_FQDN", host, scan_ret, stream->str_stream_info);
}
scan_ret = maat_scan_not_logic(g_doh_conf->maat, g_doh_conf->tables[TYPE_HOST].id,
scan_ret = maat_scan_not_logic(g_doh_conf->maat, "TSG_OBJ_FQDN", "ATTR_SERVER_FQDN",
result + hit_cnt, MAX_SCAN_RESULT - hit_cnt, &n_hit_result, ctx->scan_mid);
if (scan_ret == MAAT_SCAN_HIT)
{
hit_cnt += n_hit_result;
}
scan_ret = tfe_scan_fqdn_tags(stream, result, ctx->scan_mid, hit_cnt, g_doh_conf->tables[TYPE_HOST].id, g_doh_conf->local_logger);
scan_ret = tfe_scan_fqdn_tags(stream, result, ctx->scan_mid, hit_cnt, g_doh_conf->local_logger);
if (scan_ret > 0)
{
hit_cnt += scan_ret;
@@ -344,7 +342,7 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
}
// scan appid
long long app_id = 8006;
scan_ret = tfe_scan_app_id(result, ctx->scan_mid, hit_cnt, app_id, g_doh_conf->tables[TYPE_APPID].id);
scan_ret = tfe_scan_app_id(result, ctx->scan_mid, hit_cnt, app_id);
if(scan_ret > 0)
{
hit_cnt += scan_ret;
@@ -355,22 +353,24 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
{
hit_cnt += scan_ret;
}
// scan qname
scan_ret = maat_scan_string(g_doh_conf->maat, g_doh_conf->tables[TYPE_QNAME].id, qname, strlen(qname),
scan_ret = maat_scan_string(g_doh_conf->maat, "TSG_OBJ_FQDN", "ATTR_DOH_QNAME", qname, strlen(qname),
result + hit_cnt, MAX_SCAN_RESULT - hit_cnt, &n_hit_result, ctx->scan_mid);
if (scan_ret == MAAT_SCAN_HIT)
{
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, Hit domain: %s scan ret: %d qtype: %d policy_id: %lld addr: %s",
g_doh_conf->tables[TYPE_QNAME].name, qname, scan_ret, qtype, result[hit_cnt], stream->str_stream_info);
memset(result_str, 0, sizeof(result_str));
uuid_unparse(result[hit_cnt], result_str);
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, Hit domain: %s scan ret: %d qtype: %d policy_id: %s addr: %s",
"ATTR_DOH_QNAME", qname, scan_ret, qtype, result_str, stream->str_stream_info);
hit_cnt += n_hit_result;
}
else
{
TFE_LOG_INFO(g_doh_conf->local_logger, "Scan %s, NO hit domain: %s scan ret: %d addr: %s",
g_doh_conf->tables[TYPE_QNAME].name, qname, scan_ret, stream->str_stream_info);
"ATTR_DOH_QNAME", qname, scan_ret, stream->str_stream_info);
}
scan_ret = maat_scan_not_logic(g_doh_conf->maat, g_doh_conf->tables[TYPE_QNAME].id,
scan_ret = maat_scan_not_logic(g_doh_conf->maat, "TSG_OBJ_FQDN", "ATTR_DOH_QNAME",
result + hit_cnt, MAX_SCAN_RESULT - hit_cnt, &n_hit_result, ctx->scan_mid);
if (scan_ret == MAAT_SCAN_HIT)
{
@@ -379,8 +379,8 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
if (hit_cnt)
{
p_result = doh_fetch_rule(result, hit_cnt);
if (p_result != 0)
doh_fetch_rule(result, p_result, hit_cnt);
if (uuid_is_null(p_result) != 1)
{
ctx->result_num = 1;
ctx->result = ALLOC(struct doh_maat_rule_t, ctx->result_num);
@@ -389,26 +389,6 @@ static void doh_maat_scan(const struct tfe_stream *stream, const struct tfe_http
}
}
static int doh_maat_init(const char *profile, const char *section)
{
g_doh_conf->maat = tfe_get_maat_handle();
MESA_load_profile_string_def(profile, section, "table_appid", g_doh_conf->tables[TYPE_APPID].name, TFE_STRING_MAX, "ATTR_APP_ID");
MESA_load_profile_string_def(profile, section, "table_qname", g_doh_conf->tables[TYPE_QNAME].name, TFE_STRING_MAX, "ATTR_DOH_QNAME");
MESA_load_profile_string_def(profile, section, "table_host", g_doh_conf->tables[TYPE_HOST].name, TFE_STRING_MAX, "ATTR_SERVER_FQDN");
for (int i = 0; i < TYPE_MAX; i++)
{
g_doh_conf->tables[i].id = maat_get_table_id(g_doh_conf->maat, g_doh_conf->tables[i].name);
if (g_doh_conf->tables[i].id < 0)
{
TFE_LOG_ERROR(g_doh_conf->local_logger, "maat_get_table_id failed, table_name: %s", g_doh_conf->tables[i].name);
return -1;
}
}
return 0;
}
static void doh_gc_cb(evutil_socket_t fd, short what, void *arg)
{
int i = 0;
@@ -664,12 +644,6 @@ int doh_on_init(struct tfe_proxy *proxy)
TFE_LOG_ERROR(NULL, "Doh init kafka failed.");
goto error;
}
if (doh_maat_init(profile, "maat") != 0)
{
TFE_LOG_ERROR(NULL, "Doh init maat failed.");
goto error;
}
TFE_LOG_INFO(g_doh_conf->local_logger, "Doh init success.");
success:
@@ -838,7 +812,7 @@ void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx,
}
fieldstat->tags[thread_id][TAG_VSYS_ID].value_longlong = ctx->result->vsys_id;
fieldstat->tags[thread_id][TAG_RULE_ID].value_longlong = ctx->result->config_id;
fieldstat->tags[thread_id][TAG_RULE_ID].value_str = ctx->result->config_uuid_string;
fieldstat->tags[thread_id][TAG_ACTION].value_longlong = 48;
fieldstat->tags[thread_id][TAG_SUB_ACTION].value_str = "redirect";

View File

@@ -8,20 +8,6 @@ struct json_spec
enum tfe_http_std_field field_id;
};
enum _log_action //Bigger action number is prior.
{
LG_ACTION_NONE = 0x00,
LG_ACTION_MONIT = 0x01,
LG_ACTION_FORWARD = 0x02, /* N/A */
LG_ACTION_REJECT = 0x10,
LG_ACTION_DROP = 0x20, /* N/A */
LG_ACTION_MANIPULATE = 0x30,
LG_ACTION_RATELIMIT = 0x40, /* N/A */
LG_ACTION_WHITELIST = 0x60,
LG_ACTION_SHUNT = 0x80,
__LG_ACTION_MAX
};
#define get_time_ms(tv) ((long long)(tv.tv_sec) * 1000 + (long long)(tv.tv_usec) / 1000)
static int get_rr_str2json(cJSON *object, dns_info_t *dns_info, int *dns_sec)
@@ -473,9 +459,9 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
for (size_t i = 0; i < result_num; i++)
{
TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %lld, service: %d, do_log:%d",
TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %s, service: %d, do_log:%d",
http->req->req_spec.url,
result[i].config_id,
result[i].config_uuid_string,
result[i].service_id,
result[i].do_log);
@@ -485,11 +471,11 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
}
cJSON *proxy_rule_list=NULL;
int config_id[1]={0};
char *config_id[1]={0};
per_hit_obj = cJSON_Duplicate(common_obj, 1);
config_id[0]=result[i].config_id;
proxy_rule_list = cJSON_CreateIntArray(config_id, 1);
config_id[0]=result[i].config_uuid_string;
proxy_rule_list = cJSON_CreateStringArray((const char **)config_id, 1);
cJSON_AddItemToObject(per_hit_obj, "proxy_rule_list", proxy_rule_list);
cJSON_AddStringToObject(per_hit_obj, "proxy_action", "redirect");

View File

@@ -41,12 +41,6 @@ enum doh_content_type
DOH_TYPE_UDPWIREFORMAT,
};
struct maat_table
{
int id;
char name[TFE_STRING_MAX];
};
struct doh_conf
{
int enable;
@@ -65,18 +59,19 @@ struct doh_conf
screen_stat_handle_t fs_handle;
struct maat *maat;
struct maat_table tables[TYPE_MAX];
};
struct doh_maat_rule_t
{
long long config_id;
int service_id;
unsigned char do_log;
unsigned char do_blacklist;
unsigned char action;
char *srv_def_large;
int vsys_id;
long long config_id;
uuid_t config_uuid;
char *config_uuid_string;
int service_id;
unsigned char do_log;
unsigned char do_blacklist;
unsigned char action;
char *action_parameter;
};
struct doh_ctx

View File

@@ -11,13 +11,13 @@ 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, char **profile_msg, size_t *msg_len, int *timeout);
int (*http_lua_profile)(char *profile_uuid_str, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout);
};
struct tsg_script_ctx
{
int config_id;
int profile_id;
char *config_uuid_str;
char *profile_uuid_str;
int http_req_uri;
int rewrite_header;
char *rewrite_uri;
@@ -37,6 +37,6 @@ struct elua_context * http_lua_ctx_new(struct tsg_lua_script *lua_script, unsign
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);
size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, char *profile_uuid_str, 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);

View File

@@ -5,13 +5,14 @@
struct log_rule_t
{
long long config_id;
int vsys_id;
uuid_t config_uuid;
char *config_uuid_string;
int service_id;
unsigned char do_log;
unsigned char do_blacklist;
unsigned char action;
char *srv_def_large;
int vsys_id;
char *action_parameter;
};
struct proxy_log

View File

@@ -125,7 +125,7 @@ static int http_lua_log_debug(struct elua_vm *vm)
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);
TFE_LOG_DEBUG(tsg_ctx->local_logger, "policy_id:%s, profile_id:%s, message:%20s", tsg_ctx->config_uuid_str, tsg_ctx->profile_uuid_str, buff);
http_free_params(out_lua_argv);
return 1;
@@ -161,7 +161,7 @@ static int http_lua_log_info(struct elua_vm *vm)
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);
TFE_LOG_INFO(tsg_ctx->local_logger, "policy_id:%s, profile_id:%s, message:%s", tsg_ctx->config_uuid_str, tsg_ctx->profile_uuid_str, buff);
http_free_params(out_lua_argv);
return 1;
@@ -197,7 +197,7 @@ static int http_lua_log_error(struct elua_vm *vm)
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);
TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%s, profile_id:%s, message:%s", tsg_ctx->config_uuid_str, tsg_ctx->profile_uuid_str, buff);
http_free_params(out_lua_argv);
return 1;
@@ -683,7 +683,7 @@ static int http_lua_get_body(struct elua_vm *vm)
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");
TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%s, profile_id:%s, message:%s", tsg_ctx->config_uuid_str, tsg_ctx->profile_uuid_str, "Can't to get req/resp body data");
return 0;
}
@@ -829,14 +829,14 @@ finish:
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)
size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, char *profile_uuid_str, struct elua_context *elua_ctx, unsigned int thread_id, void *user_data)
{
int ret=0;
char *profile_msg=NULL;
size_t msg_len=0; int timeout=0;
struct elua_script **escript=NULL;
ret=lua_script->http_lua_profile(profile_id, &escript, &profile_msg, &msg_len, &timeout);
ret=lua_script->http_lua_profile(profile_uuid_str, &escript, &profile_msg, &msg_len, &timeout);
if(ret<0)
{
return ret;
@@ -856,7 +856,7 @@ size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id
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]));
TFE_LOG_ERROR(tsg_ctx->local_logger, "policy_id:%s, profile_id:%s, error_code:%d, error: %s", tsg_ctx->config_uuid_str, tsg_ctx->profile_uuid_str, ret, elua_get_last_error_string(lua_script->http_lua_handle[thread_id]));
}
}
if(profile_msg != NULL)

File diff suppressed because it is too large Load Diff

View File

@@ -356,21 +356,21 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
}
int j=0, enable_monit=0;
int monit_config_id[16]={0};
char *monit_config_id[16]={0};
for(size_t i=0; i<log_msg->result_num; i++)
{
if(log_msg->result[i].action == LG_ACTION_MONIT)
{
monit_config_id[j]=log_msg->result[i].config_id;
monit_config_id[j]=log_msg->result[i].config_uuid_string;
j++;
}
}
for(size_t i=0; i<log_msg->result_num; i++)
{
TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %lld, service: %d, do_log:%d",
TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %s, service: %d, do_log:%d",
http->req->req_spec.url,
log_msg->result[i].config_id,
log_msg->result[i].config_uuid_string,
log_msg->result[i].service_id,
log_msg->result[i].do_log);
@@ -385,17 +385,17 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
}
cJSON *proxy_rule_list=NULL;
int config_id[1]={0};
char *config_id[1]={0};
per_hit_obj=cJSON_Duplicate(common_obj, 1);
if(log_msg->result[i].action == LG_ACTION_MONIT)
{
proxy_rule_list = cJSON_CreateIntArray(monit_config_id, j);
proxy_rule_list = cJSON_CreateStringArray((const char **)monit_config_id, j);
enable_monit=1;
}
else
{
config_id[0]=log_msg->result[i].config_id;
proxy_rule_list = cJSON_CreateIntArray(config_id, 1);
config_id[0]=log_msg->result[i].config_uuid_string;
proxy_rule_list = cJSON_CreateStringArray((const char **)config_id, 1);
}
cJSON_AddItemToObject(per_hit_obj, "proxy_rule_list", proxy_rule_list);
cJSON_AddNumberToObject(per_hit_obj, "vsys_id", log_msg->result[i].vsys_id);

View File

@@ -163,10 +163,11 @@ static int lua_http_default_headers_init(struct def_lua_http_headers *lua_http_h
return 0;
}
int http_lua_profile_for_test(int profile_id, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout)
int http_lua_profile_for_test(char *profile_id_str, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout)
{
size_t input_sz;
const char *filename[]= {"./test_data/http_session.lua", "./test_data/header_filter_by_lua.lua"};
int profile_id=atoi(profile_id_str);
char *input= tfe_read_file(filename[profile_id], &input_sz);
*profile_msg=tfe_strdup(input);
@@ -221,7 +222,8 @@ const struct tfe_http_session *lua_http_session_init()
TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
struct timespec start_time, end_time;
@@ -235,7 +237,7 @@ TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret!=0);
clock_gettime(CLOCK_REALTIME, &(end_time));
@@ -250,7 +252,8 @@ TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
TEST(TSG_LUA_SCRIPT, Req_Uri)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx, 0, sizeof(tsg_ctx));
@@ -262,7 +265,7 @@ TEST(TSG_LUA_SCRIPT, Req_Uri)
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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
EXPECT_STREQ(tsg_ctx.rewrite_uri,"team");
@@ -276,7 +279,8 @@ TEST(TSG_LUA_SCRIPT, Req_Uri)
TEST(TSG_LUA_SCRIPT, Req_Header)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx, 0, sizeof(tsg_ctx));
@@ -287,7 +291,7 @@ TEST(TSG_LUA_SCRIPT, Req_Header)
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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
const char* user_agent_val=tfe_http_std_field_read(tsg_ctx.session->resp, TFE_HTTP_USER_AGENT);
@@ -307,7 +311,8 @@ TEST(TSG_LUA_SCRIPT, Req_Header)
TEST(TSG_LUA_SCRIPT, Resp_Header)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
@@ -318,7 +323,7 @@ TEST(TSG_LUA_SCRIPT, Resp_Header)
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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, 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);
@@ -334,7 +339,8 @@ TEST(TSG_LUA_SCRIPT, Resp_Header)
TEST(TSG_LUA_SCRIPT, Req_Data)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
@@ -348,7 +354,7 @@ TEST(TSG_LUA_SCRIPT, Req_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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
@@ -372,7 +378,8 @@ TEST(TSG_LUA_SCRIPT, Req_Data)
TEST(TSG_LUA_SCRIPT, Resq_Data)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
@@ -386,7 +393,7 @@ TEST(TSG_LUA_SCRIPT, Resq_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);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, NULL, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
@@ -410,7 +417,8 @@ TEST(TSG_LUA_SCRIPT, Resq_Data)
TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
{
int ret=0;
int profile_id=0,thread_id=0;
int thread_id=0;
const char *profile_id_str = "0";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
@@ -421,7 +429,7 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
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.elua_ctx, thread_id, (void *)&tsg_ctx);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, 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);
@@ -433,7 +441,7 @@ 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.elua_ctx, thread_id, (void *)&tsg_ctx);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL);
@@ -458,7 +466,8 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
TEST(TSG_LUA_SCRIPT, Lua_Http_Header_Filter)
{
int ret=0;
int profile_id=1,thread_id=0;
int thread_id=0;
const char *profile_id_str = "1";
struct tsg_script_ctx tsg_ctx;
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
@@ -471,7 +480,7 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Header_Filter)
lua_http_headers_clear();
tsg_ctx.replacing=tsg_ctx.session->resp;
ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
EXPECT_TRUE(ret==0);
const char *server_type_val=tfe_http_std_field_read(tsg_ctx.replacing, TFE_HTTP_SERVER);
@@ -489,7 +498,7 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Header_Filter)
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.elua_ctx, thread_id, (void *)&tsg_ctx);
ret = execute_lua_script_rule(lua_script, (char *)profile_id_str, 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);