diff options
Diffstat (limited to 'common/src/tfe_resource.cpp')
| -rw-r--r-- | common/src/tfe_resource.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/common/src/tfe_resource.cpp b/common/src/tfe_resource.cpp index 1cb61ff..c1b6e71 100644 --- a/common/src/tfe_resource.cpp +++ b/common/src/tfe_resource.cpp @@ -14,9 +14,11 @@ struct maat_table_info int id; const char *name; }; + static Maat_feather_t static_maat = NULL; static tfe_kafka_logger_t *kafka_logger = NULL; static char *device_id = NULL; +static char *data_center=NULL; static Maat_feather_t create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger) { @@ -231,6 +233,61 @@ finish: return (char *)device_def_id; } +static char* create_data_center(const char *profile, const char *section, void *logger) +{ + int i =0; + char *data_cneter=NULL; + char accept_tag_key[TFE_PATH_MAX] = {0}; + char accept_path[TFE_PATH_MAX] = {0}, accept_tags[TFE_STRING_MAX] = {0}; + + MESA_load_profile_string_def(profile, section, "accept_path", accept_path, sizeof(accept_path), ""); + if(strlen(accept_path) > 0) + { + MESA_load_profile_string_def(accept_path, "maat", "ACCEPT_TAGS", accept_tags, sizeof(accept_tags), ""); + } + if(strlen(accept_tags) <= 0) + { + return NULL; + } + MESA_load_profile_string_def(profile, section, "accept_tag_key", accept_tag_key, sizeof(accept_tag_key), "data_center"); + + cJSON *object=cJSON_Parse(accept_tags); + if(object == NULL) + { + return NULL; + } + cJSON *array=cJSON_GetObjectItem(object, "tags"); + if(array==NULL && array->type!=cJSON_Array) + { + TFE_LOG_ERROR(logger, "Invalid tags parameter: %s invalid json format", accept_tags); + goto finish; + } + + for(i=0; i<cJSON_GetArraySize(array); i++) + { + cJSON *item=cJSON_GetArrayItem(array, i); + if(!item) + { + continue; + } + cJSON *tag_item=cJSON_GetObjectItem(item, "tag"); + if(tag_item && tag_item->valuestring!=NULL && + (memcmp(accept_tag_key, tag_item->valuestring, strlen(accept_tag_key)))==0) + { + cJSON *sub_item=cJSON_GetObjectItem(item, "value"); + if(sub_item && sub_item->valuestring!=NULL) + { + data_cneter = tfe_strdup(sub_item->valuestring); + TFE_LOG_INFO(logger, "tfe data center : %s", data_cneter); + } + } + } + +finish: + cJSON_Delete(object); + return data_cneter; +} + static struct maat_table_info maat_pub_tables[TABLE_TYPE_MAX] = { {0, "TSG_SECURITY_SOURCE_ASN"}, {0, "TSG_SECURITY_DESTINATION_ASN"}, @@ -271,6 +328,8 @@ int tfe_bussiness_resouce_init() device_id = cerate_device_id(profile_path, "kafka", g_default_logger); + data_center = create_data_center(profile_path, "MAAT", g_default_logger); + if (register_maat_table()) { return -1; @@ -289,6 +348,8 @@ void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type) return kafka_logger; case DEVICE_ID: return device_id; + case DATA_CENTER: + return data_center; default: return NULL; } |
