diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 4987eca..680f018 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/confingure/prase_config.c b/confingure/prase_config.c index 6363f6e..9854057 100644 --- a/confingure/prase_config.c +++ b/confingure/prase_config.c @@ -108,7 +108,9 @@ static int __get_dev_port_config(config_t *pCfg, DEV_PORT_CONFIG pPortCfg[], int if(config_setting_lookup_string(pSubVal, "backup_dns", (const char **)&pString) == CONFIG_TRUE) { strcpy(pPortCfg[i].wan_conf.static_config.backup_dns, pString); } + break; + case PPPOE_TYPE: pSubVal = config_setting_get_member(pVal, "pppoe"); @@ -123,9 +125,12 @@ static int __get_dev_port_config(config_t *pCfg, DEV_PORT_CONFIG pPortCfg[], int if(config_setting_lookup_string(pSubVal, "password", (const char **)&pString) == CONFIG_TRUE) { strcpy(pPortCfg[i].wan_conf.pppoe_config.password, pString); } + break; + case DHCP_TYPE: break; + default: break; } @@ -276,7 +281,9 @@ static void *__cfg_file_monitor(void *p) if(select(fd + 1, &fds, NULL, NULL, NULL) > 0) { ssize_t len; unsigned int index = 0; + while(((len = read(fd, &buf, MAX_PATH)) < 0) && (errno == EINTR)); //没有读取到事件。 + while(index < len) { event = (struct inotify_event *)(buf + index); //LOG_EX(LOG_Info, "event->mask: 0x%08x\n", event->mask); @@ -296,6 +303,7 @@ static void *__cfg_file_monitor(void *p) default: break; } + //获取事件。 index += sizeof(struct inotify_event) + event->len; //移动index指向下一个事件。 } diff --git a/http/restful.c b/http/restful.c index 720c3cd..7151f68 100644 --- a/http/restful.c +++ b/http/restful.c @@ -94,16 +94,16 @@ int http_post_request(const char *pURL, const char *pPost, OnHttpResponse onResp } #ifdef SKIP_PEER_VERIFICATION - /* - * If you want to connect to a site who isn't using a certificate that is - * signed by one of the certs in the CA bundle you have, you can skip the - * verification of the server's certificate. This makes the connection - * A LOT LESS SECURE. - * - * If you have a CA cert for the server stored someplace else than in the - * default bundle, then the CURLOPT_CAPATH option might come handy for - * you. - */ + /* + * If you want to connect to a site who isn't using a certificate that is + * signed by one of the certs in the CA bundle you have, you can skip the + * verification of the server's certificate. This makes the connection + * A LOT LESS SECURE. + * + * If you have a CA cert for the server stored someplace else than in the + * default bundle, then the CURLOPT_CAPATH option might come handy for + * you. + */ curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, 0L); #else curl_easy_setopt(pCurl, CURLOPT_CAINFO, SSL_CA_FILE); diff --git a/include/json_interface.h b/include/json_interface.h index 7629113..2ac1fd3 100644 --- a/include/json_interface.h +++ b/include/json_interface.h @@ -12,14 +12,14 @@ typedef enum { } JSON_ENGINE_TYPE; typedef struct { - char* pESN; + char *pESN; } AUTH_ZTH_REQ, *PAUTH_ZTH_REQ; typedef struct { - char* status; + char *status; unsigned int iptype; unsigned int ip; - char* code; + char *code; } AUTH_ZTH_RSP, *PAUTH_ZTH_RSP; diff --git a/include/log.h b/include/log.h index 35d4e92..7b53652 100644 --- a/include/log.h +++ b/include/log.h @@ -31,8 +31,7 @@ extern "C" { /** @enum _LOG_LEVEL_ * LOG等级枚举变量 */ -typedef enum -{ +typedef enum { LOG_Fatal = (1u << 0u), LOG_Error = (1u << 1u), LOG_Warn = (1u << 2u), @@ -60,10 +59,10 @@ typedef enum #define DEBUG_FUNCTION_END() #else #define LOG_BUF(level, buf, len, prefix) do { \ - const char* pFmtBuf = format_hex_buf(prefix, DUMP_PREFIX_NONE, 16, 1, buf, len, 1); \ - IHW_LOG(level, "[%s] - %s(%04d): %s", basename_v2(__FILE__), __FUNCTION__, __LINE__, pFmtBuf); \ - free((void*)pFmtBuf); \ -} while(0); + const char* pFmtBuf = format_hex_buf(prefix, DUMP_PREFIX_NONE, 16, 1, buf, len, 1); \ + IHW_LOG(level, "[%s] - %s(%04d): %s", basename_v2(__FILE__), __FUNCTION__, __LINE__, pFmtBuf); \ + free((void*)pFmtBuf); \ + } while(0); /*! \def LOG_EX \brief 系统日志调试宏标识 */ @@ -80,7 +79,7 @@ typedef enum @brief 应用程序编译信息 */ #define APP_BUILD_INFO(appname, appver) (IHW_LOG(LOG_Info, "%s Ver:%s (Build: %s %s GCC Ver:%s) With %d(bits) OS\n", \ - appname, appver, __DATE__, __TIME__, __VERSION__, sizeof(int*) * 8)) + appname, appver, __DATE__, __TIME__, __VERSION__, sizeof(int*) * 8)) /*! @def DEBUG_CODE_LINE @@ -103,11 +102,11 @@ typedef enum * @param level 调试信息开关 * @param pMsg 调试信息内容 */ -void IHW_LOG(unsigned int level, const char* pMsg, ...); -void IHW_LOG_UNTAG(unsigned int level, const char* pMsg, ...); +void IHW_LOG(unsigned int level, const char *pMsg, ...); +void IHW_LOG_UNTAG(unsigned int level, const char *pMsg, ...); -void IHW_LogStrWithoutPrint(unsigned int level, char* pMsg); -void IHW_LogRawString(unsigned int level, char* pMsg); +void IHW_LogStrWithoutPrint(unsigned int level, char *pMsg); +void IHW_LogRawString(unsigned int level, char *pMsg); /** * @brief 设置调试等级 @@ -122,7 +121,7 @@ void IHW_EnableLogLevel(unsigned int level, int iEnable); * @param pPath 系统日志保存路径 * @param bEnable 打开/关闭调试信息 */ -void IHW_InitLOG(const char* pLogTag, const char* pPath, int bEnable); +void IHW_InitLOG(const char *pLogTag, const char *pPath, int bEnable); void IHW_RunLogService(void); @@ -131,28 +130,25 @@ void IHW_RunLogService(void); * @param pPath - 文件路径 * @return int 存在返回 1, 否则返回 0; */ -int IHW_IsFileExist(const char* pPath); +int IHW_IsFileExist(const char *pPath); -char* IHW_bin2hex(char *p, const unsigned char *cp, int count); +char *IHW_bin2hex(char *p, const unsigned char *cp, int count); /* Return the last part of a pathname */ -static inline const char* basename_v2(const char* path) +static inline const char *basename_v2(const char *path) { - const char* tail = strrchr(path, '/'); + const char *tail = strrchr(path, '/'); return tail ? tail + 1 : path; } -static inline int dirname_v2(const char* path, char* dir) +static inline int dirname_v2(const char *path, char *dir) { - const char* tail = strrchr(path, '/'); + const char *tail = strrchr(path, '/'); - if(tail) - { + if(tail) { memcpy(dir, path, tail - path); dir[tail - path] = 0; - } - else - { + } else { strcpy(dir, "./"); } @@ -161,14 +157,14 @@ static inline int dirname_v2(const char* path, char* dir) #endif void IHW_WaitFinishLogout(void); -const char* LogLeveToString(unsigned int lv); +const char *LogLeveToString(unsigned int lv); -const char* format_hex_buf(const char* prefix_str, int prefix_type, - int rowsize, int groupsize, - const void* buf, int len, int ascii); +const char *format_hex_buf(const char *prefix_str, int prefix_type, + int rowsize, int groupsize, + const void *buf, int len, int ascii); #ifndef __KERNEL__ -void print_hex_dump_bytes(const char* prefix_str, int prefix_type, - const void* buf, int len); +void print_hex_dump_bytes(const char *prefix_str, int prefix_type, + const void *buf, int len); #endif diff --git a/include/restful.h b/include/restful.h index b70da2b..dbed218 100644 --- a/include/restful.h +++ b/include/restful.h @@ -5,8 +5,8 @@ #ifndef ZTP_CLIENT_RESTFUL_H #define ZTP_CLIENT_RESTFUL_H -typedef void (*OnHttpResponse)(void* pData, unsigned int size, const char* pReqUrl, - const char* pDlPath, const char* pTaskUuid, int iFinished, void* pUserData); +typedef void (*OnHttpResponse)(void *pData, unsigned int size, const char *pReqUrl, + const char *pDlPath, const char *pTaskUuid, int iFinished, void *pUserData); -int http_post_request(const char *pURL, const char* pPost, OnHttpResponse onRespCb); +int http_post_request(const char *pURL, const char *pPost, OnHttpResponse onRespCb); #endif //ZTP_CLIENT_RESTFUL_H diff --git a/include/ztp_config.h b/include/ztp_config.h index b78d41c..8bea7af 100644 --- a/include/ztp_config.h +++ b/include/ztp_config.h @@ -81,13 +81,13 @@ typedef struct { int total_ports; } DEVICE_CONFIG, *PDEVICE_CONFIG; -int init_configure(const char* pPath); +int init_configure(const char *pPath); -int cfg_get_bool_value(config_t* pCfg, const char* pTags, int defValue); -int cfg_get_int_value(config_t* pCfg, const char* pTags, int defValue); -char* cfg_get_string_value(config_t* pCfg, const char* pTags, char* pDefValue); -double cfg_get_float_value(config_t* pCfg, const char* pTags, double defValue); -int cfg_get_array_int_value(config_t* pCfg, const char *pTags, int* pArray, int* pMaxItem); +int cfg_get_bool_value(config_t *pCfg, const char *pTags, int defValue); +int cfg_get_int_value(config_t *pCfg, const char *pTags, int defValue); +char *cfg_get_string_value(config_t *pCfg, const char *pTags, char *pDefValue); +double cfg_get_float_value(config_t *pCfg, const char *pTags, double defValue); +int cfg_get_array_int_value(config_t *pCfg, const char *pTags, int *pArray, int *pMaxItem); -int load_dev_config(const char* devId); +int load_dev_config(const char *devId); #endif //ZTP_CLIENT_ZTP_CONFIG_H diff --git a/json_engine/json_interface.c b/json_engine/json_interface.c index 33fd27d..ec74376 100644 --- a/json_engine/json_interface.c +++ b/json_engine/json_interface.c @@ -88,8 +88,8 @@ static int __ztp_auth_decode(const char *pJsonS, void **pStruct) static JSON_ENGINE g_jSonEngine[] = { - {JE_AUTH_ZTP, __ztp_auth_encode, __ztp_auth_decode, NULL}, - {JSON_ENGINE_MAX,NULL, NULL, NULL} + {JE_AUTH_ZTP, __ztp_auth_encode, __ztp_auth_decode, NULL}, + {JSON_ENGINE_MAX, NULL, NULL, NULL} }; diff --git a/log/hexdump.c b/log/hexdump.c index dfc0b54..e0357b1 100644 --- a/log/hexdump.c +++ b/log/hexdump.c @@ -15,9 +15,9 @@ static const char hex_asc[] = "0123456789abcdef"; #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] #if 0 -char* IHW_bin2hex(char *p, const unsigned char *cp, int count) +char *IHW_bin2hex(char *p, const unsigned char *cp, int count) { - while (count) { + while(count) { unsigned char c = *cp++; /* put lowercase hex digits */ *p++ = 0x20 | hex_asc[c >> 4]; @@ -37,15 +37,13 @@ char* IHW_bin2hex(char *p, const unsigned char *cp, int count) */ int hex_to_bin(char ch) { - if((ch >= '0') && (ch <= '9')) - { + if((ch >= '0') && (ch <= '9')) { return ch - '0'; } ch = tolower(ch); - if((ch >= 'a') && (ch <= 'f')) - { + if((ch >= 'a') && (ch <= 'f')) { return ch - 'a' + 10; } @@ -94,13 +92,11 @@ void hex_dump_to_buffer(const void *buf, int len, int rowsize, goto nil; } - if(len > rowsize) /* limit to one line at a time */ - { + if(len > rowsize) { /* limit to one line at a time */ len = rowsize; } - if((len % groupsize) != 0) /* no mixed size output */ - { + if((len % groupsize) != 0) { /* no mixed size output */ groupsize = 1; } @@ -112,7 +108,7 @@ void hex_dump_to_buffer(const void *buf, int len, int rowsize, for(j = 0; j < ngroups; j++) lx += snprintf(linebuf + lx, linebuflen - lx, "%s%16.16llx", j ? " " : "", - (long long)*(ptr8 + j)); + (long long) * (ptr8 + j)); ascii_column = 17 * ngroups + 2; break; @@ -171,7 +167,7 @@ void hex_dump_to_buffer(const void *buf, int len, int rowsize, linebuf[lx++] = (char)((isascii(ch) && isprint(ch)) ? ch : '.'); } - nil: +nil: linebuf[lx] = '\0'; } diff --git a/log/log.c b/log/log.c index 528018b..f98c2b4 100644 --- a/log/log.c +++ b/log/log.c @@ -126,6 +126,7 @@ static void __logColorOutput(const char *pColFmt, UT_string *pLog) static void *__logOutputThread(void *p) { UNUSED(p); + while(g_bEnableLog) { int isWriteLog = FALSE; PLOG_ITEM pItem = NULL, pTmp = NULL; @@ -202,6 +203,7 @@ static void *__logOutputThread(void *p) pthread_mutex_unlock(&g_logLock); usleep(1000); + if(g_LogProcessInfo.pLogFile != NULL && isWriteLog) { fflush(g_LogProcessInfo.pLogFile); } @@ -253,6 +255,7 @@ void IHW_InitLOG(const char *pLogTag, const char *pPath, int bEnable) memset(strPath, 0, MAX_PATH * 2); g_LogProcessInfo.pid = getpid(); + if(readlink("/proc/self/exe", strPath, MAX_PATH) == -1) { strcpy(g_LogProcessInfo.exeName, pLogTag); } else { @@ -399,26 +402,37 @@ const char *LogLeveToString(unsigned int lv) switch(lv) { case LOG_Fatal: return "LOG_Fatal"; + case LOG_Error: return "LOG_Error"; + case LOG_Warn: return "LOG_Warn"; + case LOG_Debug: return "LOG_Debug"; + case LOG_Info: return "LOG_Info"; + case LOG_Test: return "LOG_Test"; + case LOG_Call: return "LOG_Call"; + case LOG_Devp: return "LOG_Devp"; + case LOG_Step: return "LOG_Step"; + case LOG_Unknown: return "LOG_Unknown"; + case LOG_All: return "LOG_All"; + case LOG_Close: return "LOG_Close"; diff --git a/ztp_main.c b/ztp_main.c index 3713251..3907838 100644 --- a/ztp_main.c +++ b/ztp_main.c @@ -52,9 +52,11 @@ int main(int argc, char **argv) load_dev_config(ZTP_ESN); #ifdef MONITOR_ZTP_CFG_FILE - while(ret == ERR_OK){ + + while(ret == ERR_OK) { usleep(1000); } + #endif IHW_WaitFinishLogout();