summaryrefslogtreecommitdiff
path: root/plugin/business/tsg-http/src/tsg_logger.cpp
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2024-08-16 11:57:20 +0800
committerfengweihao <[email protected]>2024-08-16 11:57:20 +0800
commitc2c20d33108dbe35e4ee1f98b7ed956d27cfc710 (patch)
treea67d6cbfa075b1a7e1f97b2ab52d956949a81b67 /plugin/business/tsg-http/src/tsg_logger.cpp
parent88e6b0ae9bee35e5b39c6cf25a7f53c0217c584f (diff)
TSG-22093 Manipulation支持Library Tag相关策略的扫描与日志发送
Diffstat (limited to 'plugin/business/tsg-http/src/tsg_logger.cpp')
-rw-r--r--plugin/business/tsg-http/src/tsg_logger.cpp90
1 files changed, 41 insertions, 49 deletions
diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp
index b3a324b..2a699af 100644
--- a/plugin/business/tsg-http/src/tsg_logger.cpp
+++ b/plugin/business/tsg-http/src/tsg_logger.cpp
@@ -110,44 +110,6 @@ struct proxy_logger* proxy_log_handle_create(const char* profile, const char* se
return instance;
}
-static int get_ip_client_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj)
-{
- unsigned int i=0, j=0;
- char opt_val[128]={0}; uint16_t opt_out_size;
- const char *client_geo_area_map[] = {"client_country","client_super_administrative_area","client_administrative_area","client_sub_administrative_area"};
-
- for(i=TFE_CMSG_SRC_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2)
- {
- memset(opt_val, 0, sizeof(opt_val));
- int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0)
- {
- cJSON_AddStringToObject(per_hit_obj, client_geo_area_map[j], opt_val);
- }
- j++;
- }
- return 0;
-}
-
-static int get_ip_server_geolocation(struct tfe_cmsg * cmsg, cJSON *per_hit_obj)
-{
- unsigned int i=0, j=0;
- char opt_val[128]={0}; uint16_t opt_out_size;
- const char *server_geo_area_map[] = {"server_country","server_super_administrative_area","server_administrative_area","server_sub_administrative_area"};
-
- for(i=TFE_CMSG_DST_REGION_STR; i <= TFE_CMSG_DST_SUBDIVISION_STR; i+=2)
- {
- memset(opt_val, 0, sizeof(opt_val));
- int ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)i, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
- if (ret == 0)
- {
- cJSON_AddStringToObject(per_hit_obj, server_geo_area_map[j], opt_val);
- }
- j++;
- }
- return 0;
-}
-
int proxy_add_host_to_object(cJSON *common_obj, const char *req_spec_host)
{
unsigned int port;
@@ -159,6 +121,29 @@ int proxy_add_host_to_object(cJSON *common_obj, const char *req_spec_host)
return 0;
}
+int tags_line_to_json_array(cJSON *per_hit_obj, const char *tags_key, char *opt_val)
+{
+ if(per_hit_obj == NULL || tags_key == NULL || opt_val == NULL)
+ {
+ return 0;
+ }
+
+ char *opt_val_tmp = strdup(opt_val);
+ cJSON *tags_array = cJSON_CreateArray();
+
+ char *token = strtok(opt_val_tmp, ",");
+ while (token != NULL)
+ {
+ while (*token == ' ') token++;
+ cJSON_AddItemToArray(tags_array, cJSON_CreateString(token));
+ token = strtok(NULL, ",");
+ }
+ cJSON_AddItemToObject(per_hit_obj, tags_key, tags_array);
+
+ FREE(&opt_val_tmp)
+ return 1;
+}
+
int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
{
const struct tfe_http_session* http=log_msg->http;
@@ -412,19 +397,26 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
}
if (cmsg!=NULL)
{
- uint64_t src_asn=0, dst_asn=0;
- ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_SRC_ASN_VAL, (unsigned char *)&src_asn, sizeof(src_asn), &opt_out_size);
- if (ret == 0)
- {
- cJSON_AddNumberToObject(per_hit_obj, "client_asn", src_asn);
- }
- ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_DST_ASN_VAL, (unsigned char *)&dst_asn, sizeof(dst_asn), &opt_out_size);
- if (ret == 0)
+ char opt_val[128]={0}; uint16_t opt_out_size;
+ ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)64, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
+ if (ret == 0 && strlen(opt_val) > 0)
+ {
+ tags_line_to_json_array(per_hit_obj, "client_ip_tags", opt_val);
+ }
+
+ memset(opt_val, 0, sizeof(opt_val));
+ ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)65, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
+ if (ret == 0 && strlen(opt_val) > 0)
+ {
+ tags_line_to_json_array(per_hit_obj, "server_ip_tags", opt_val);
+ }
+
+ memset(opt_val, 0, sizeof(opt_val));
+ ret = tfe_cmsg_get_value(cmsg, (enum tfe_cmsg_tlv_type)63, (unsigned char *)opt_val, sizeof(opt_val), &opt_out_size);
+ if (ret == 0 && strlen(opt_val) > 0)
{
- cJSON_AddNumberToObject(per_hit_obj, "server_asn", dst_asn);
+ tags_line_to_json_array(per_hit_obj, "server_fqdn_tags", opt_val);
}
- get_ip_client_geolocation(cmsg, per_hit_obj);
- get_ip_server_geolocation(cmsg, per_hit_obj);
}
log_payload = cJSON_PrintUnformatted(per_hit_obj);