123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- #include "log_producer_config.h"
- #include "sds.h"
- #include <string.h>
- #include <stdlib.h>
- #include "inner_log.h"
- dbg_callback g_callback;
- static void _copy_config_string(const char* value, sds* src_value)
- {
- int strLen;
- if (value == NULL || src_value == NULL)
- {
- return;
- }
- strLen = strlen(value);
- if (*src_value == NULL)
- {
- *src_value = sdsnewEmpty(strLen);
- }
- else {
- sdsfree(*src_value);
- }
- *src_value = sdscpylen(*src_value, value, strLen);
- }
- static void _set_default_producer_config(log_producer_config* pConfig)
- {
- pConfig->enableGuarder = 0;
- pConfig->tokenFun = NULL;
- pConfig->sendThreadCount = 2;
- pConfig->sendThreadWaitMs = 100;
- pConfig->logBytesPerPackage = MAX_LOG_COUNT * 1024;
- pConfig->logCountPerPackage = 5;
- pConfig->maxBufferBytes = 64 * 1024 * 1024;
- pConfig->connectTimeoutSec = 10;
- pConfig->sendTimeoutSec = 15;
- pConfig->destroySenderWaitTimeoutSec = 1;
- pConfig->destroyFlusherWaitTimeoutSec = 1;
- pConfig->compressType = 0;
- pConfig->ntpTimeOffset = 0;
- pConfig->using_https = 0;
- pConfig->usePersistent = 1;
- pConfig->openDB = 0;
- pConfig->maxPersistentLogCount = 5*10000;
- pConfig->usePersistentEncrypt = 2;
- pConfig->useMemoryType = 0;
- pConfig->debugMode = 0;
- _copy_config_string("RVC_LOG_SDK_25846", &pConfig->PersistentEncryptPassword);
- }
- log_producer_config* create_log_producer_config()
- {
- log_producer_config* pConfig = (log_producer_config*)malloc(sizeof(log_producer_config));
- memset(pConfig, 0, sizeof(log_producer_config));
- _set_default_producer_config(pConfig);
- return pConfig;
- }
- void destroy_log_producer_config(log_producer_config* pConfig)
- {
- if (pConfig->endpoint != NULL)
- {
- sdsfree(pConfig->endpoint);
- }
- if (pConfig->skyeye_user_topic != NULL)
- {
- sdsfree(pConfig->skyeye_user_topic);
- }
- if (pConfig->skyeye_sys_topic != NULL)
- {
- sdsfree(pConfig->skyeye_sys_topic);
- }
- if (pConfig->beidou_topic != NULL)
- {
- sdsfree(pConfig->beidou_topic);
- }
- if (pConfig->business_user_topic != NULL)
- {
- sdsfree(pConfig->business_user_topic);
- }
- if (pConfig->business_sys_topic != NULL)
- {
- sdsfree(pConfig->business_sys_topic);
- }
- if (pConfig->vtmweb_topic != NULL)
- {
- sdsfree(pConfig->vtmweb_topic);
- }
- if (pConfig->persistentFilePath != NULL)
- {
- sdsfree(pConfig->persistentFilePath);
- }
- if (pConfig->PersistentEncryptPassword != NULL)
- {
- sdsfree(pConfig->PersistentEncryptPassword);
- }
- if (pConfig->skyeyeServName != NULL)
- {
- sdsfree(pConfig->skyeyeServName);
- }
- if (pConfig->skyeyeCmptId != NULL)
- {
- sdsfree(pConfig->skyeyeCmptId);
- }
- if (pConfig->skyeyeCmptName != NULL)
- {
- sdsfree(pConfig->skyeyeCmptName);
- }
- if (pConfig->skyeyeTerminalNo != NULL)
- {
- sdsfree(pConfig->skyeyeTerminalNo);
- }
- if (pConfig->skyeyeVersion != NULL)
- {
- sdsfree(pConfig->skyeyeVersion);
- }
- if (pConfig->skyeyeSn != NULL)
- {
- sdsfree(pConfig->skyeyeSn);
- }
- if (pConfig->skyeyeItem != NULL)
- {
- sdsfree(pConfig->skyeyeItem);
- }
- if (pConfig->skyeyeItem != NULL)
- {
- sdsfree(pConfig->skyeyeItem);
- }
- if (pConfig->skyeyeEntityName != NULL)
- {
- sdsfree(pConfig->skyeyeEntityName);
- }
- if (pConfig->unitedAppName != NULL)
- {
- sdsfree(pConfig->unitedAppName);
- }
- if (pConfig->unitedVersion != NULL)
- {
- sdsfree(pConfig->unitedVersion);
- }
- if (pConfig->unitedDeployUnitId != NULL)
- {
- sdsfree(pConfig->unitedDeployUnitId);
- }
- if (pConfig->unitedServiceUnitId != NULL)
- {
- sdsfree(pConfig->unitedServiceUnitId);
- }
- free(pConfig);
- }
- #ifdef LOG_PRODUCER_DEBUG
- void log_producer_config_print(log_producer_config* pConfig, FILE* file)
- {
- fprintf(file, "endpoint : %s\n", pConfig->endpoint);
- fprintf(file, "project : %s\n", pConfig->project);
- fprintf(file, "logstore : %s\n", pConfig->logstore);
- fprintf(file, "accessKeyId : %s\n", pConfig->accessKeyId);
- fprintf(file, "accessKey : %s\n", pConfig->accessKey);
- fprintf(file, "configName : %s\n", pConfig->configName);
- fprintf(file, "topic : %s\n", pConfig->topic);
- fprintf(file, "logLevel : %d\n", pConfig->logLevel);
- fprintf(file, "packageTimeoutInMS : %d\n", pConfig->packageTimeoutInMS);
- fprintf(file, "logCountPerPackage : %d\n", pConfig->logCountPerPackage);
- fprintf(file, "logBytesPerPackage : %d\n", pConfig->logBytesPerPackage);
- fprintf(file, "maxBufferBytes : %d\n", pConfig->maxBufferBytes);
- fprintf(file, "tags: \n");
- int32_t i = 0;
- for (i = 0; i < pConfig->tagCount; ++i)
- {
- fprintf(file, "tag key : %s, value : %s \n", pConfig->tags[i].key, pConfig->tags[i].value);
- }
- }
- #endif
- void log_producer_config_set_packet_log_count(log_producer_config* config, int32_t log_count)
- {
- if (config == NULL || log_count < 0)
- {
- return;
- }
- if (log_count > MAX_LOG_COUNT) {
- log_count = MAX_LOG_COUNT;
- }
- config->logCountPerPackage = log_count;
- }
- void log_producer_config_set_packet_log_bytes(log_producer_config* config, int32_t log_bytes)
- {
- if (config == NULL || log_bytes < 0)
- {
- return;
- }
- config->logBytesPerPackage = log_bytes;
- }
- void log_producer_config_set_max_buffer_limit(log_producer_config* config, int64_t max_buffer_bytes)
- {
- if (config == NULL || max_buffer_bytes < 0)
- {
- return;
- }
- config->maxBufferBytes = max_buffer_bytes;
- }
- void log_producer_config_set_send_thread_count(log_producer_config* config, int32_t thread_count)
- {
- if (config == NULL || thread_count < 0)
- {
- return;
- }
- config->sendThreadCount = thread_count;
- }
- void log_producer_config_set_connect_timeout_sec(log_producer_config* config, int32_t connect_timeout_sec)
- {
- if (config == NULL || connect_timeout_sec <= 0)
- {
- return;
- }
- config->connectTimeoutSec = connect_timeout_sec;
- }
- void log_producer_config_set_send_timeout_sec(log_producer_config* config, int32_t send_timeout_sec)
- {
- if (config == NULL || send_timeout_sec <= 0)
- {
- return;
- }
- config->sendTimeoutSec = send_timeout_sec;
- }
- void log_producer_config_set_destroy_flusher_wait_sec(log_producer_config* config, int32_t destroy_flusher_wait_sec)
- {
- if (config == NULL || destroy_flusher_wait_sec <= 0)
- {
- return;
- }
- config->destroyFlusherWaitTimeoutSec = destroy_flusher_wait_sec;
- }
- void log_producer_config_set_destroy_sender_wait_sec(log_producer_config* config, int32_t destroy_sender_wait_sec)
- {
- if (config == NULL || destroy_sender_wait_sec <= 0)
- {
- return;
- }
- config->destroySenderWaitTimeoutSec = destroy_sender_wait_sec;
- }
- void log_producer_config_set_compress_type(log_producer_config* config, int32_t compress_type)
- {
- if (config == NULL || compress_type < 0 || compress_type > 1)
- {
- return;
- }
- config->compressType = compress_type;
- }
- void log_producer_config_set_ntp_time_offset(log_producer_config* config, int32_t ntp_time_offset)
- {
- if (config == NULL)
- {
- return;
- }
- config->ntpTimeOffset = ntp_time_offset;
- }
- void log_producer_config_set_enable_guard(log_producer_config* config, int enable) {
- if (config == NULL)
- return;
- config->enableGuarder = enable;
- }
- void log_producer_config_set_tokenCallBack(log_producer_config* config, Log_GetTokenCallBack fun)
- {
- if (config == NULL)
- return;
- config->tokenFun = fun;
- }
- void log_producer_config_set_skyeye_servname(log_producer_config* config, char* servname) {
- _copy_config_string(servname, &config->skyeyeServName);
- }
- void log_producer_config_set_skyeye_cmptId(log_producer_config* config, char* cmptId) {
- _copy_config_string(cmptId, &config->skyeyeCmptId);
- }
- void log_producer_config_set_skyeye_cmptname(log_producer_config* config, char* cmptname) {
- _copy_config_string(cmptname, &config->skyeyeCmptName);
- }
- void log_producer_config_set_skyeye_terminalNo(log_producer_config* config, char* terminalNo) {
- _copy_config_string(terminalNo, &config->skyeyeTerminalNo);
- }
- void log_producer_config_set_skyeye_version(log_producer_config* config, char* version) {
- _copy_config_string(version, &config->skyeyeVersion);
- }
- void log_producer_config_set_skyeye_sn(log_producer_config* config, char* sn) {
- _copy_config_string(sn, &config->skyeyeSn);
- }
- void log_producer_config_set_skyeye_item(log_producer_config* config, char* item) {
- _copy_config_string(item, &config->skyeyeItem);
- }
- void log_producer_config_set_skyeye_entityname(log_producer_config* config, char* entityname) {
- _copy_config_string(entityname, &config->skyeyeEntityName);
- }
- void log_producer_config_set_united_appname(log_producer_config* config, char* appname) {
- _copy_config_string(appname, &config->unitedAppName);
- }
- void log_producer_config_set_united_version(log_producer_config* config, char* version) {
- _copy_config_string(version, &config->unitedVersion);
- }
- void log_producer_config_set_united_needArchived(log_producer_config* config, int needArchived) {
- config->unitedNeedArchived = needArchived;
- }
- void log_producer_config_set_united_deployUnitId(log_producer_config* config, char* deployUnitId) {
- _copy_config_string(deployUnitId, &config->unitedDeployUnitId);
- }
- void log_producer_config_set_united_serviceUnitId(log_producer_config* config, char* serviceUnitId) {
- _copy_config_string(serviceUnitId, &config->unitedServiceUnitId);
- }
- void log_producer_config_get_upload_info(unsigned long* t_upload_TerminalSys_Suc, unsigned long* t_upload_TerminalUser_Suc,
- unsigned long* t_upload_BussinessSys_Suc, unsigned long* t_upload_BussinessUser_Suc, unsigned long* t_upload_beidou_Suc,
- unsigned long* t_upload_TerminalSys_Err, unsigned long* t_upload_TerminalUser_Err,
- unsigned long* t_upload_BussinessSys_Err, unsigned long* t_upload_BussinessUser_Err, unsigned long* t_upload_beidou_Err)
- {
- *t_upload_TerminalSys_Suc = g_upload_TerminalSys_Suc;
- *t_upload_TerminalUser_Suc = g_upload_TerminalUser_Suc;
- *t_upload_BussinessSys_Suc = g_upload_BussinessSys_Suc;
- *t_upload_BussinessUser_Suc = g_upload_BussinessUser_Suc;
- *t_upload_beidou_Suc = g_upload_beidou_Suc;
- *t_upload_TerminalSys_Err = g_upload_TerminalSys_Err;
- *t_upload_TerminalUser_Err = g_upload_TerminalUser_Err;
- *t_upload_BussinessSys_Err = g_upload_BussinessSys_Err;
- *t_upload_BussinessUser_Err = g_upload_BussinessUser_Err;
- *t_upload_beidou_Err = g_upload_beidou_Err;
- }
- LOG_EXPORT void log_producer_config_set_dbgFun(dbg_callback t_callback)
- {
- g_callback = t_callback;
- }
- void log_producer_config_set_send_thread_wait_ms(log_producer_config* config, int32_t ts)
- {
- config->sendThreadWaitMs = ts;
- }
- void log_producer_config_set_endpoint(log_producer_config* config, const char* endpoint)
- {
- if (strlen(endpoint) < 8) {
- return;
- }
- if (strncmp(endpoint, "http://", 7) == 0)
- {
- endpoint += 7;
- }
- else if (strncmp(endpoint, "https://", 8) == 0)
- {
- config->using_https = 1;
- endpoint += 8;
- }
- _copy_config_string(endpoint, &config->endpoint);
- }
- void log_producer_config_set_skyeye_user_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->skyeye_user_topic);
- }
- void log_producer_config_set_skyeye_sys_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->skyeye_sys_topic);
- }
- void log_producer_config_set_business_user_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->business_user_topic);
- }
- void log_producer_config_set_business_sys_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->business_sys_topic);
- }
- void log_producer_config_set_vtmweb_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->vtmweb_topic);
- }
- void log_producer_config_set_beidou_topic(log_producer_config* config, const char* topic)
- {
- _copy_config_string(topic, &config->beidou_topic);
- }
- int log_producer_config_is_valid(log_producer_config* config)
- {
- if (config == NULL)
- {
- aos_error_log((LB, "invalid producer config"));
- return 0;
- }
- if (config->enableGuarder && config->endpoint == NULL)
- {
- aos_error_log((LB, "invalid producer config destination params"));
- return 0;
- }
- if (config->enableGuarder && (config->skyeyeTerminalNo == NULL || config->skyeyeSn == NULL))
- {
- aos_error_log((LB, "invalid producer skyeye TerminalNo config params"));
- return 0;
- }
- if (config->skyeyeServName == NULL || config->skyeyeCmptId == NULL ||
- config->skyeyeCmptName == NULL ||
- config->skyeyeVersion == NULL ||
- config->skyeyeItem == NULL || config->skyeyeEntityName == NULL)
- {
- aos_error_log((LB, "invalid producer skyeye config params"));
- return 0;
- }
-
- if (config->unitedAppName == NULL || config->unitedVersion == NULL || config->unitedDeployUnitId == NULL || config->unitedServiceUnitId == NULL)
- {
- aos_error_log((LB, "invalid producer united config params"));
- return 0;
- }
-
- if (config->maxBufferBytes < 0 || config->logCountPerPackage < 0 || config->logBytesPerPackage < 0)
- {
- aos_error_log((LB, "invalid producer config log merge and buffer params"));
- return 0;
- }
- if (config->usePersistent)
- {
- if (config->persistentFilePath == NULL || config->maxPersistentLogCount <= 0)
- {
- aos_error_log((LB, "invalid producer persistent config params"));
- return 0;
- }
- if (config->usePersistentEncrypt) {
- if (config->PersistentEncryptPassword == NULL)
- {
- aos_error_log((LB, "invalid producer persistent password config params"));
- return 0;
- }
- }
- }
- return 1;
- }
- void log_producer_config_set_using_http(log_producer_config* config, int32_t using_https)
- {
- if (config == NULL || using_https < 0)
- {
- return;
- }
- config->using_https = using_https;
- }
- int log_producer_persistent_config_is_enabled(log_producer_config* config)
- {
- if (config == NULL)
- {
- aos_error_log((LB, "invalid producer config"));
- return 0;
- }
- if (config->usePersistent == 0)
- {
- return 0;
- }
- return 1;
- }
- void log_producer_config_set_persistent(log_producer_config* config,
- int32_t persistent)
- {
- if (config == NULL)
- return;
- config->usePersistent = persistent;
- }
- void log_producer_config_set_openDb(log_producer_config* config, int32_t openDB)
- {
- if (config == NULL)
- return;
- config->openDB = openDB;
- }
- void log_producer_config_set_persistent_encrypt(log_producer_config* config, int32_t enable) {
- if (config == NULL)
- return;
- config->usePersistentEncrypt = enable;
- }
- void log_producer_config_set_persistent_encrypt_password(log_producer_config* config, char* password) {
- if (config == NULL)
- return;
- _copy_config_string(password, &config->PersistentEncryptPassword);
- }
- void log_producer_config_set_persistent_file_path(log_producer_config* config,
- const char* file_path)
- {
- if (config == NULL)
- return;
- _copy_config_string(file_path, &config->persistentFilePath);
- }
- void log_producer_config_set_persistent_max_log_count(log_producer_config* config,
- int32_t max_log_count)
- {
- if (config == NULL)
- return;
- config->maxPersistentLogCount = max_log_count;
- }
- LOG_EXPORT void log_producer_config_switch_debug_mode(log_producer_config* config, int32_t switch_on)
- {
- if (config == NULL)
- return;
- config->debugMode = switch_on;
- }
- LOG_EXPORT void log_producer_config_memory_deal_type(log_producer_config* config, int32_t memory_deal_type)
- {
- if (config == NULL)
- return;
- config->useMemoryType = memory_deal_type;
- }
|