summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/business/chaining-policy/src/chaining_policy.cpp1
-rw-r--r--plugin/business/doh/src/dns.cpp2
-rw-r--r--plugin/business/doh/src/doh.cpp2
-rw-r--r--plugin/business/doh/src/logger.cpp2
-rw-r--r--plugin/business/tsg-http/include/http_lua.h2
-rw-r--r--plugin/business/tsg-http/src/http_lua.cpp14
-rw-r--r--plugin/business/tsg-http/src/tsg_http.cpp24
-rw-r--r--plugin/business/tsg-http/src/tsg_logger.cpp2
-rw-r--r--plugin/business/tsg-http/src/tsg_web_cache.cpp6
-rw-r--r--plugin/business/tsg-http/test/test_http_lua.cpp42
-rw-r--r--plugin/protocol/http2/src/http2_stream.cpp2
11 files changed, 65 insertions, 34 deletions
diff --git a/plugin/business/chaining-policy/src/chaining_policy.cpp b/plugin/business/chaining-policy/src/chaining_policy.cpp
index 9d9cf02..ffd3852 100644
--- a/plugin/business/chaining-policy/src/chaining_policy.cpp
+++ b/plugin/business/chaining-policy/src/chaining_policy.cpp
@@ -33,7 +33,6 @@ static void chaining_param_new_cb(const char *table_name, int table_id, const ch
{
cJSON *json = NULL;
cJSON *item = NULL;
- cJSON *element = NULL;
size_t user_region_offset = 0;
size_t user_region_len = 0;
struct chaining_param *param = NULL;
diff --git a/plugin/business/doh/src/dns.cpp b/plugin/business/doh/src/dns.cpp
index 5db09f7..b29c42e 100644
--- a/plugin/business/doh/src/dns.cpp
+++ b/plugin/business/doh/src/dns.cpp
@@ -199,7 +199,7 @@ static void get_rr_type_nsec3(char **ptr, nsec3_t *nsec3, char *end)
}
// unused
-static int get_rr_signer(u_char **ptr, u_char *buf, int buflen, char *end)
+__attribute__((unused))static int get_rr_signer(u_char **ptr, u_char *buf, int buflen, char *end)
{
u_char *p = NULL;
int len = 0, i = 0;
diff --git a/plugin/business/doh/src/doh.cpp b/plugin/business/doh/src/doh.cpp
index bba3aab..500f577 100644
--- a/plugin/business/doh/src/doh.cpp
+++ b/plugin/business/doh/src/doh.cpp
@@ -915,9 +915,9 @@ void doh_on_end(const struct tfe_stream *stream, const struct tfe_http_session *
int ret = doh_send_log(g_doh_conf, session, stream, ctx);
if (ret > 0)
{
- doh_send_metric_log(stream, ctx, thread_id);
ATOMIC_ADD(&(g_doh_conf->stat_val[STAT_LOG_NUM]), ret);
}
+ doh_send_metric_log(stream, ctx, thread_id);
}
doh_ctx_free(ctx);
diff --git a/plugin/business/doh/src/logger.cpp b/plugin/business/doh/src/logger.cpp
index 6cb1d6b..88526de 100644
--- a/plugin/business/doh/src/logger.cpp
+++ b/plugin/business/doh/src/logger.cpp
@@ -451,7 +451,7 @@ 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: %d, service: %d, do_log:%d",
+ TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %lld, service: %d, do_log:%d",
http->req->req_spec.url,
result[i].config_id,
result[i].service_id,
diff --git a/plugin/business/tsg-http/include/http_lua.h b/plugin/business/tsg-http/include/http_lua.h
index 060fcec..545166e 100644
--- a/plugin/business/tsg-http/include/http_lua.h
+++ b/plugin/business/tsg-http/include/http_lua.h
@@ -11,7 +11,7 @@ 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);
+ int (*http_lua_profile)(int profile_id, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout);
};
struct tsg_script_ctx
diff --git a/plugin/business/tsg-http/src/http_lua.cpp b/plugin/business/tsg-http/src/http_lua.cpp
index 05cbb1f..aba6204 100644
--- a/plugin/business/tsg-http/src/http_lua.cpp
+++ b/plugin/business/tsg-http/src/http_lua.cpp
@@ -824,14 +824,21 @@ finish:
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;
+ 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);
+ ret=lua_script->http_lua_profile(profile_id, &escript, &profile_msg, &msg_len, &timeout);
if(ret<0)
{
return ret;
}
+ if(*escript == NULL)
+ {
+ escript[thread_id]=http_lua_map_cache_script(lua_script->http_lua_handle[thread_id], profile_msg, msg_len, timeout);
+ }
+
const char *input="tfe";
size_t input_len=strlen(input);
@@ -844,6 +851,11 @@ size_t execute_lua_script_rule(struct tsg_lua_script *lua_script, int profile_id
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]));
}
}
+ if(profile_msg != NULL)
+ {
+ FREE(&profile_msg);
+ }
+
return ret;
}
diff --git a/plugin/business/tsg-http/src/tsg_http.cpp b/plugin/business/tsg-http/src/tsg_http.cpp
index dbbcd94..4d8a287 100644
--- a/plugin/business/tsg-http/src/tsg_http.cpp
+++ b/plugin/business/tsg-http/src/tsg_http.cpp
@@ -683,7 +683,6 @@ void policy_action_param_new(const char *table_name, int table_id, const char* k
}
*ad=param;
TFE_LOG_INFO(g_proxy_rt->local_logger, "Add ctrl policy: %lld", config_id);
-error_out:
cJSON_Delete(json);
return;
}
@@ -890,15 +889,8 @@ void ma_lua_profile_table_new_cb(const char *table_name, int table_id, const cha
return;
}
- int i=0, thread_num = g_proxy_rt->thread_num;
- struct tsg_lua_script *lua_script = &(g_proxy_rt->lua_script);
-
+ int thread_num = g_proxy_rt->thread_num;
ply_profile->escript_ctx = ALLOC(struct elua_script *, thread_num);
- for(i=0; i<thread_num; i++)
- {
- ply_profile->escript_ctx[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], ply_profile->profile_msg, ply_profile->msg_len, timeout);
- }
-
TFE_LOG_INFO(g_proxy_rt->local_logger, "Policy table add success %d", profile_id);
*ad = ply_profile;
@@ -933,7 +925,12 @@ void ma_profile_table_free_cb(int table_id, void **ad, long argl, void *argp)
int i=0;
for(i=0; i<g_proxy_rt->thread_num; i++)
{
- elua_cleanup_script(ply_obj->escript_ctx[i]);
+ if(ply_obj->escript_ctx[i])
+ {
+ elua_cleanup_script(ply_obj->escript_ctx[i]);
+ FREE(&ply_obj->escript_ctx[i]);
+ ply_obj->escript_ctx[i]=NULL;
+ }
}
free(ply_obj->escript_ctx);
ply_obj->escript_ctx=NULL;
@@ -1686,7 +1683,7 @@ static int http_enforcement_ratio(float enforcement_ratio)
return 0;
}
-int http_lua_profile(int profile_id, struct elua_script ***elua_ctx)
+int http_lua_profile(int profile_id, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout)
{
int ret = 0;
@@ -1698,6 +1695,9 @@ int http_lua_profile(int profile_id, struct elua_script ***elua_ctx)
}
*elua_ctx=lua_profile->escript_ctx;
+ *profile_msg=tfe_strdup(lua_profile->profile_msg);
+ *msg_len=lua_profile->msg_len;
+ *timeout=lua_profile->timeout;
ma_profile_table_free(lua_profile);
lua_profile = NULL;
return ret;
@@ -2178,7 +2178,7 @@ static void http_block(const struct tfe_stream * stream, const struct tfe_http_s
int profile_id = param->profile_id;
char *message = param->message;
- if (resp_code <= 0 || profile_id < 0){
+ if (profile_id < 0){
TFE_LOG_ERROR(g_proxy_rt->local_logger, "Invalid block rule %lld", ctx->enforce_rules[0].config_id);
ctx->action = PX_ACTION_NONE;
return;
diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp
index b438d3a..55b098d 100644
--- a/plugin/business/tsg-http/src/tsg_logger.cpp
+++ b/plugin/business/tsg-http/src/tsg_logger.cpp
@@ -346,7 +346,7 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
for(size_t i=0; i<log_msg->result_num; i++)
{
- TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %d, service: %d, do_log:%d",
+ TFE_LOG_DEBUG(handle->local_logger, "URL: %s, policy_id: %lld, service: %d, do_log:%d",
http->req->req_spec.url,
log_msg->result[i].config_id,
log_msg->result[i].service_id,
diff --git a/plugin/business/tsg-http/src/tsg_web_cache.cpp b/plugin/business/tsg-http/src/tsg_web_cache.cpp
index 0011ad9..1f63d55 100644
--- a/plugin/business/tsg-http/src/tsg_web_cache.cpp
+++ b/plugin/business/tsg-http/src/tsg_web_cache.cpp
@@ -1247,14 +1247,14 @@ void cache_write_future_ctx_free(struct cache_write_future_ctx* ctx)
static void wrap_cache_write_on_succ(future_result_t * result, void * user)
{
struct cache_write_future_ctx* ctx=(struct cache_write_future_ctx*)user;
- TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload success: %s path: %s elapse: %d",
+ TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload success: %s path: %s elapse: %ld",
ctx->url, ctx->upload_path, time(NULL)-ctx->start);
cache_write_future_ctx_free(ctx);
}
static void wrap_cache_write_on_fail(enum e_future_error err, const char * what, void * user)
{
struct cache_write_future_ctx* ctx=(struct cache_write_future_ctx*)user;
- TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload failed: %s %s lapse: %d", ctx->url, what, time(NULL)-ctx->start);
+ TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload failed: %s %s lapse: %ld", ctx->url, what, time(NULL)-ctx->start);
ATOMIC_INC(&(ctx->ref_handle->stat_val[STAT_CACHE_WRITE_ERR]));
cache_write_future_ctx_free(ctx);
}
@@ -1316,7 +1316,7 @@ struct cache_write_context* web_cache_write_start(struct cache_handle* handle, u
)
{
ATOMIC_INC(&(handle->stat_val[STAT_CACHE_WRITE_FORBIDEN]));
- TFE_LOG_DEBUG(handle->logger, "cache write forbiden: %s, bypass:%d, cont_len:%lld, has_cookie:%d, is_html:%d",
+ TFE_LOG_DEBUG(handle->logger, "cache write forbiden: %s, bypass:%d, cont_len:%zu, has_cookie:%d, is_html:%d",
session->req->req_spec.url,
_mid->shall_bypass,
content_len,
diff --git a/plugin/business/tsg-http/test/test_http_lua.cpp b/plugin/business/tsg-http/test/test_http_lua.cpp
index 330b5bf..bf99e46 100644
--- a/plugin/business/tsg-http/test/test_http_lua.cpp
+++ b/plugin/business/tsg-http/test/test_http_lua.cpp
@@ -151,9 +151,17 @@ 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)
+int http_lua_profile_for_test(int profile_id, 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";
+ char *input= tfe_read_file(filename, &input_sz);
+
+ *profile_msg=tfe_strdup(input);
+ *msg_len=input_sz;
+ *timeout=1000;
*elua_ctx=g_tsg_lua_pattern->elua_ctx;
+ FREE(&input);
return 0;
}
@@ -221,6 +229,9 @@ TEST(TSG_LUA_SCRIPT, Lua_TimeOut)
clock_gettime(CLOCK_REALTIME, &(end_time));
printf("take time %lu(s)\n", end_time.tv_sec - start_time.tv_sec);
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -244,6 +255,9 @@ TEST(TSG_LUA_SCRIPT, Req_Uri)
EXPECT_STREQ(tsg_ctx.rewrite_uri,"team");
FREE(&tsg_ctx.rewrite_uri);
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -272,6 +286,9 @@ TEST(TSG_LUA_SCRIPT, Req_Header)
EXPECT_TRUE(x_tg_val!=NULL);
EXPECT_STREQ(x_tg_val, "tfe");
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -296,6 +313,9 @@ TEST(TSG_LUA_SCRIPT, Resp_Header)
EXPECT_TRUE(content_type_val!=NULL);
EXPECT_STREQ(content_type_val, "utf8");
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -327,6 +347,9 @@ TEST(TSG_LUA_SCRIPT, Req_Data)
evbuffer_free(tsg_ctx.http_body);
evbuffer_free(tsg_ctx.http_lua_body);
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -358,6 +381,9 @@ TEST(TSG_LUA_SCRIPT, Resq_Data)
evbuffer_free(tsg_ctx.http_body);
evbuffer_free(tsg_ctx.http_lua_body);
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -398,6 +424,9 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
evbuffer_free(tsg_ctx.http_body);
evbuffer_free(tsg_ctx.http_lua_body);
+ elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
+ FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
+ g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
http_lua_ctx_free(lua_script, thread_id, tsg_ctx.elua_ctx);
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
}
@@ -407,21 +436,12 @@ int main(int argc, char ** argv)
struct tsg_lua_pattern *tsg_lua_pattern = ALLOC(struct tsg_lua_pattern, 1);
TAILQ_INIT(&tsg_lua_pattern->lua_http_head_list.lua_http_field_list);
- int i=0, thread_num=1;
+ int thread_num=1;
struct tsg_lua_script *lua_script=ALLOC(struct tsg_lua_script, 1);
http_lua_handle_create(lua_script, thread_num, "tfe");
- 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++)
- {
- tsg_lua_pattern->elua_ctx[i]=http_lua_map_cache_script(lua_script->http_lua_handle[i], input, input_sz, 1000);
- }
-
tsg_lua_pattern->lua_script=lua_script;
tsg_lua_pattern->thread_num=thread_num;
g_tsg_lua_pattern = tsg_lua_pattern;
diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp
index c5ea3b3..c96e0fa 100644
--- a/plugin/protocol/http2/src/http2_stream.cpp
+++ b/plugin/protocol/http2/src/http2_stream.cpp
@@ -1099,7 +1099,7 @@ static int http2_submit_frame_goaway(struct tfe_h2_stream *connection, const ngh
}
finish:
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit goaway, stream_id:%d, action:%d, errod_code:%d, data:%.*s", connection->tf_stream->str_stream_info,
- dir, goaway->last_stream_id, connection->stream_action, goaway->error_code, goaway->opaque_data_len, goaway->opaque_data);
+ dir, goaway->last_stream_id, connection->stream_action, goaway->error_code, (int)goaway->opaque_data_len, goaway->opaque_data);
connection->goaway = 1;
connection->stream_action = stream_action;
return 0;