Remove unused files

This commit is contained in:
HuangXin 2018-09-11 11:16:55 +08:00
parent 151307b62e
commit 4418049a24
14 changed files with 0 additions and 7984 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,110 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <zlib.h>
#include "crypto.h"
#define CHUNK_BLOCK (16384)
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
int GZipFileCompress(const char* pInput, const char* pOutput)
{
int ret, isFlush;
unsigned int have;
z_stream strm;
char strPath[256];
unsigned char in[CHUNK_BLOCK];
unsigned char out[CHUNK_BLOCK];
FILE *source, *dest;
if (pInput == NULL)
{
return (Z_ERRNO);
}
if(access(pInput, F_OK) != 0)
{
return (Z_ERRNO);
}
//fprintf(stdout, "in: %s\n", pInput);
source = fopen(pInput, "r+");
memset(strPath, 0, 256);
if (pOutput == NULL || strlen(pOutput) == 0)
{
sprintf(strPath, "%s.gz", pInput);
dest = fopen(strPath, "w+");
//fprintf(stdout, "out: %s\n", strPath);
}
else
{
dest = fopen(pOutput, "w+");
//fprintf(stdout, "out: %s\n", pOutput);
}
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
//ret = deflateInit(&strm, level);
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY);
if (ret != Z_OK)
{
fclose(source);
fclose(dest);
return ret;
}
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK_BLOCK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
fclose(source);
fclose(dest);
return Z_ERRNO;
}
isFlush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK_BLOCK;
strm.next_out = out;
ret = deflate(&strm, isFlush); /* no bad return value */
have = CHUNK_BLOCK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
fclose(source);
fclose(dest);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when last data in file processed */
} while (isFlush != Z_FINISH);
/* clean up and return */
(void)deflateEnd(&strm);
fflush(dest);
fclose(source);
fclose(dest);
return Z_OK;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,289 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/file.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <libconfig.h>
#include "log.h"
#include "libuv_dbus.h"
#include "server_addr.h"
#ifdef PLATFORM_R16
#define DEVICE_CFG_FILE ("/mnt/UDISK/dev.conf")
#else
#define DEVICE_CFG_FILE ("./dev.conf")
#endif
static config_t g_cfgInfo;
void InitCfgToCfgFile(config_t* pCfg)
{
config_setting_t *pRoot, *pSetting, *pGlobalgrp, *pLogGrp, *pSubGrp;
if(pCfg == NULL)
{
return;
}
pRoot = config_root_setting(pCfg);
pGlobalgrp = config_setting_add(pRoot, "Global", CONFIG_TYPE_GROUP);
pSetting = config_setting_add(pGlobalgrp, "ServerMode", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, PUBLISH_MODE);
pLogGrp = config_setting_add(pGlobalgrp, "Log", CONFIG_TYPE_GROUP);
pSetting = config_setting_add(pLogGrp, "Enable", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, TRUE);
pSetting = config_setting_add(pLogGrp, "Level", CONFIG_TYPE_INT);
config_setting_set_format(pSetting, CONFIG_FORMAT_HEX);
config_setting_set_int(pSetting, 0x000003FF);
pSubGrp = config_setting_add(pLogGrp, "LogToEMail", CONFIG_TYPE_GROUP);
pSetting = config_setting_add(pSubGrp, "Enable", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, FALSE);
pSetting = config_setting_add(pSubGrp, "EMail", CONFIG_TYPE_STRING);
config_setting_set_string(pSetting, "pv1_es2@163.com");
pSetting = config_setting_add(pLogGrp, "LogToFile", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, TRUE);
pSetting = config_setting_add(pLogGrp, "LogToServer", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, TRUE);
pSubGrp = config_setting_add(pLogGrp, "LogToUDPServer", CONFIG_TYPE_GROUP);
pSetting = config_setting_add(pSubGrp, "Enable", CONFIG_TYPE_BOOL);
config_setting_set_bool(pSetting, FALSE);
pSetting = config_setting_add(pSubGrp, "UdpServerIp", CONFIG_TYPE_STRING);
config_setting_set_string(pSetting, "10.240.84.163");
pSetting = config_setting_add(pSubGrp, "UdpBasePort", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, 10000);
if(!config_write_file(pCfg, DEVICE_CFG_FILE))
{
LOG_EX(LOG_Error, "Create Configure File %s Error\n", DEVICE_CFG_FILE);
}
}
int CfgGetIntValueV2(const char* pTags, int defValue, int* pErr)
{
char* pSvrMode = NULL;
char cmdBuf[MAX_PATH];
int iValue = defValue;
memset(cmdBuf, 0, MAX_PATH);
sprintf(cmdBuf, "cat %s | grep %s | awk '{print $3}' | cut -d \";\" -f 1",
DEVICE_CFG_FILE,
pTags);
GetShellExecResult(cmdBuf, &pSvrMode);
if(pSvrMode == NULL)
{
if(pErr)
{
*pErr = -ERR_NO_ITEMS;
}
return defValue;
}
iValue = strtol(pSvrMode, NULL, 10);
free(pSvrMode);
if(errno == EINVAL || errno == ERANGE)
{
if(pErr)
{
*pErr = -ERR_STR_CONVERT;
}
return defValue;
}
if(pErr)
{
*pErr = 0;
}
return iValue;
}
int CfgGetIntValueV1(const char* pTags, int defValue, int* pErr)
{
int iValue = defValue;
if(pTags == NULL || strlen(pTags) == 0)
{
if(pErr)
{
*pErr = -ERR_INPUT_PARAMS;
}
return defValue;
}
if(!config_lookup_int(&g_cfgInfo, pTags, &iValue))
{
if(pErr)
{
*pErr = -ERR_READ_FILE;
}
return defValue;
}
*pErr = 0;
return iValue;
}
int CfgGetIntValue(const char* pTags, int defValue)
{
int iValue = defValue;
if(pTags == NULL || strlen(pTags) == 0)
{
return defValue;
}
if(!config_lookup_int(&g_cfgInfo, pTags, &iValue))
{
return defValue;
}
return iValue;
}
void CfgSetIntValue(const char* pTags, int iValue)
{
config_setting_t *pRoot, *pGlobalgrp, *pSet;
LOG_EX(LOG_Debug, "Set: %s --> %d\n", pTags, iValue);
if(pTags == NULL || strlen(pTags) == 0)
{
LOG_EX(LOG_Error, "Input Params error: pTags = [%s]\n", pTags ? pTags : "NULL");
return;
}
pRoot = config_root_setting(&g_cfgInfo);
if(pRoot == NULL)
{
LOG_EX(LOG_Error, "pRoot = NULL\n");
return;
}
pGlobalgrp = config_setting_get_member(pRoot, "Global");
if(pGlobalgrp == NULL)
{
LOG_EX(LOG_Error, "pGlobalgrp = NULL\n");
return;
}
pSet = config_setting_get_member(pGlobalgrp, pTags);
if(!pSet)
{
pSet = config_setting_add(pGlobalgrp, pTags, CONFIG_TYPE_INT);
}
if(pSet == NULL)
{
LOG_EX(LOG_Error, "pSet = NULL\n");
return;
}
config_setting_set_int(pSet, iValue);
if(!config_write_file(&g_cfgInfo, DEVICE_CFG_FILE))
{
LOG_EX(LOG_Error, "Set %s Value Error\n", pTags);
}
}
char* CfgGetStringValue(const char* pTags, char* pDefValue)
{
char* pValue = pDefValue;
if(pTags == NULL || strlen(pTags) == 0)
{
return pDefValue;
}
if(!config_lookup_string(&g_cfgInfo, pTags, (const char**)&pValue))
{
return pDefValue;
}
return pValue;
}
double CfgGetFloatValue(const char* pTags, double defValue)
{
double dValue = defValue;
if(pTags == NULL || strlen(pTags) == 0)
{
return defValue;
}
if(!config_lookup_float(&g_cfgInfo, pTags, &dValue))
{
return defValue;
}
return dValue;
}
int CfgGetBoolValue(const char* pTags, int defValue)
{
int iValue = defValue;
if(pTags == NULL || strlen(pTags) == 0)
{
return defValue;
}
if(!config_lookup_bool(&g_cfgInfo, pTags, &iValue))
{
return defValue;
}
return iValue;
}
void CfgFileInit(void)
{
//config_setting_t *pRoot, *pSetting;
config_init(&g_cfgInfo);
#if 0
config_set_options(&g_cfgInfo,
(CONFIG_OPTION_SEMICOLON_SEPARATORS
| CONFIG_OPTION_COLON_ASSIGNMENT_FOR_GROUPS
| CONFIG_OPTION_OPEN_BRACE_ON_SEPARATE_LINE));
#endif
config_set_tab_width(&g_cfgInfo, 4);
if(access(DEVICE_CFG_FILE, F_OK) != 0)
{
InitCfgToCfgFile(&g_cfgInfo);
}
else if(!config_read_file(&g_cfgInfo, DEVICE_CFG_FILE))
{
LOG_EX(LOG_Error, "Read Configure File %s Error\n", DEVICE_CFG_FILE);
return;
}
}

View File

@ -1,104 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "log.h"
#include "smart_sound.h"
#include "crypto.h"
#include "libuv_dbus.h"
int EvpAESEncrypto(unsigned char* pInBuf,
int iSize,
unsigned char* pOutBuf,
int* pOutSize,
unsigned char* pKey)
{
int enBytes = 0;
EVP_CIPHER_CTX ctx;
//int decDataLen = 0;
if(!pInBuf || !pOutBuf || !pOutSize || !pKey)
{
return -ERR_INPUT_PARAMS;
}
*pOutSize = 0;
//decDataLen = ((iSize + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
EVP_CIPHER_CTX_init(&ctx);
if(EVP_EncryptInit_ex(&ctx, EVP_aes_128_ecb(), NULL, pKey, NULL) == 0)
{
LOG_EX(LOG_Error, "EVP_EncryptInit_ex Error\n");
return -ERR_EVP_INIT_KEY;
}
if(EVP_EncryptUpdate(&ctx, pOutBuf, &enBytes, pInBuf, iSize) == 0)
{
LOG_EX(LOG_Error, "EVP_EncryptUpdate Error\n");
return -ERR_EVP_UPDATE;
}
pOutBuf += enBytes;
pInBuf += enBytes;
*pOutSize += enBytes;
if(EVP_EncryptFinal_ex(&ctx, pOutBuf, &enBytes) == 0)
{
LOG_EX(LOG_Error, "EVP_EncryptFinal_ex Error\n");
return -ERR_EVP_FINALE;
}
*pOutSize += enBytes;
EVP_CIPHER_CTX_cleanup(&ctx);
return 0;
}
int EvpAESDecrypto(unsigned char* pInBuf,
int iSize,
unsigned char* pOutBuf,
int* pOutSize,
unsigned char* pKey)
{
int deBytes = 0;
EVP_CIPHER_CTX ctx;
if(!pInBuf || !pOutBuf || !pOutSize || !pKey)
{
return -ERR_INPUT_PARAMS;
}
EVP_CIPHER_CTX_init(&ctx);
*pOutSize = 0;
if(EVP_DecryptInit_ex(&ctx, EVP_aes_128_ecb(), NULL, pKey, NULL) == 0)
{
LOG_EX(LOG_Error, "EVP_DecryptInit_ex Error\n");
return -ERR_EVP_INIT_KEY;
}
if(EVP_DecryptUpdate(&ctx, pOutBuf, &deBytes, pInBuf, iSize) == 0)
{
LOG_EX(LOG_Error, "EVP_EncryptUpdate Error\n");
return -ERR_EVP_UPDATE;
}
pOutBuf += deBytes;
pInBuf += deBytes;
*pOutSize += deBytes;
if(EVP_DecryptFinal_ex(&ctx, pOutBuf, &deBytes) == 0)
{
LOG_EX(LOG_Error, "EVP_EncryptFinal_ex Error\n");
return -ERR_EVP_FINALE;
}
*pOutSize += deBytes;
EVP_CIPHER_CTX_cleanup(&ctx);
return 0;
}

View File

@ -1,158 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "log.h"
#include "crypto.h"
const char* EvpBase64Encode(const char* pSrc)
{
EVP_ENCODE_CTX ctx;
int enSize = 0;
int sLen, size;
char* pEncode = NULL;
if(pSrc == NULL || strlen(pSrc) == 0)
{
return (NULL);
}
sLen = strlen(pSrc);
size = ((sLen / 3) * 4) + 4 + (sLen / 64) + sLen % 64;
pEncode = (char*)malloc(size);
memset(pEncode, 0, size);
EVP_EncodeInit(&ctx);
EVP_EncodeUpdate(&ctx, pEncode, &enSize, pSrc, strlen(pSrc));
EVP_EncodeFinal(&ctx, pEncode + enSize, &enSize);
// fprintf(stdout, "Src: \n[%s]\n", pSrc);
// fprintf(stdout, "Base64(%d --> %d | %d) Bytes: \n[%s]\n", sLen, size, strlen(pEncode), pEncode);
return pEncode;
}
const char* EvpBase64Decode(const char* pBase64)
{
EVP_ENCODE_CTX ctx;
int enSize = 0;
int size = 0;
char *pDecode = NULL;
if(pBase64 == NULL || strlen(pBase64) == 0)
{
return (NULL);
}
size = strlen(pBase64);
pDecode = (char*)malloc(size);
memset(pDecode, 0, size);
EVP_DecodeInit(&ctx);
EVP_DecodeUpdate(&ctx, pDecode, &enSize, pBase64, strlen(pBase64));
EVP_DecodeFinal(&ctx, pDecode + enSize, &enSize);
// fprintf(stdout, "Decode(%d --> %d) Bytes: \n[%s]\n", size, strlen(pDecode), pDecode);
return pDecode;
}
const char* EvpBase64EncodeNoAlign(const char* pSrc)
{
int size, sLen;
char* pEncode = NULL;
if(pSrc == NULL || strlen(pSrc) == 0)
{
return (NULL);
}
sLen = strlen(pSrc);
size = ((sLen / 3) * 4) + 4 + (sLen / 64) + sLen % 64;
pEncode = (char*)malloc(size);
memset(pEncode, 0, size);
EVP_EncodeBlock(pEncode, (const unsigned char *)pSrc, sLen);
// fprintf(stdout, "Src: \n[%s]\n", pSrc);
// fprintf(stdout, "Base64(%d --> %d | %d) Bytes: \n[%s]\n", sLen, size, strlen(pEncode), pEncode);
return pEncode;
}
const char* EvpBase64EncodeNoAlignV2(unsigned char* pSrc, int sLen)
{
int size;
char* pEncode = NULL;
if(pSrc == NULL || sLen <= 0)
{
return (NULL);
}
size = ((sLen / 3) * 4) + 4 + (sLen / 64) + sLen % 64;
pEncode = (char*)malloc(size);
memset(pEncode, 0, size);
EVP_EncodeBlock(pEncode, (const unsigned char *)pSrc, sLen);
// fprintf(stdout, "Src: \n[%s]\n", pSrc);
// fprintf(stdout, "Base64(%d --> %d | %d) Bytes: \n[%s]\n", sLen, size, strlen(pEncode), pEncode);
return pEncode;
}
const char* EvpBase64DecodeNoAlign(const char *pBase64)
{
int size = 0;
char *pDecode = NULL;
if(pBase64 == NULL || strlen(pBase64) == 0)
{
return (NULL);
}
size = strlen(pBase64);
pDecode = (char*)malloc(size);
memset(pDecode, 0, size);
//CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
EVP_DecodeBlock(pDecode, (const unsigned char *)pBase64, size);
//CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
// fprintf(stdout, "Decode(%d --> %d) Bytes: \n[%s]\n", size, strlen(pDecode), pDecode);
return pDecode;
}
unsigned char* EvpBase64DecodeNoAlignV2(const char *pBase64, int* pOutSize)
{
int size = 0;
unsigned char *pDecode = NULL;
if(pBase64 == NULL || strlen(pBase64) == 0)
{
return (NULL);
}
size = strlen(pBase64);
pDecode = (char*)malloc(size);
memset(pDecode, 0, size);
//CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
size = EVP_DecodeBlock(pDecode, (const unsigned char *)pBase64, size);
//CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
// fprintf(stdout, "Decode(%d --> %d) Bytes: \n[%s]\n", size, strlen(pDecode), pDecode);
if(pOutSize)
{
*pOutSize = size;
}
return (pDecode);
}

View File

@ -1,187 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "log.h"
#include "smart_sound.h"
#include "crypto.h"
#include "libuv_dbus.h"
static uv_mutex_t *pEvpMutex = NULL;
typedef struct
{
CRYPTO_TYPE type;
unsigned char* pInData;
int iInSize;
unsigned char* pOutData;
unsigned char pKey[EVP_MAX_KEY_LENGTH + 1];
OnEVPCrypto onEvpEventCb;
} CRYPT_TASK_PARAMS, *PCRYPT_TASK_PARAMS;
static void FreeEVPWorkCb(uv_work_t* pWork, int status)
{
PCRYPT_TASK_PARAMS pTask = (PCRYPT_TASK_PARAMS)pWork->data;
free(pTask->pInData);
free(pTask);
free(pWork);
}
static void OnEVPWorkCb(uv_work_t* pWork)
{
PCRYPT_TASK_PARAMS pTask = (PCRYPT_TASK_PARAMS)pWork->data;
int iOutSize = 0;
int iError = 0;
switch(pTask->type)
{
case CRYPTO_AES_ENCRYPT:
iError = EvpAESEncrypto(pTask->pInData,
pTask->iInSize,
pTask->pOutData,
&iOutSize,
pTask->pKey);
break;
case CRYPTO_AES_DECRYPT:
iError = EvpAESDecrypto(pTask->pInData,
pTask->iInSize,
pTask->pOutData,
&iOutSize,
pTask->pKey);
break;
case CRYPTO_BASE64_ENCODE:
pTask->pOutData = (unsigned char*)EvpBase64Encode((const char*)pTask->pInData);
iOutSize = strlen((char*)pTask->pOutData);
break;
case CRYPTO_BASE64_DECODE:
pTask->pOutData = (unsigned char*)EvpBase64Decode((const char*)pTask->pInData);
iOutSize = strlen((char*)pTask->pOutData);
break;
case CRYPTO_MD5_FILE:
pTask->pOutData = (unsigned char*)EvpMD5HashFile((const char*)pTask->pInData);
iOutSize = strlen((char*)pTask->pOutData);
break;
default:
iError = -ERR_UNSUP_EVP_TYPE;
}
if(iError != 0)
{
pTask->onEvpEventCb(pTask->type, pTask->pOutData, 0, pTask->pInData, iError);
}
else
{
pTask->onEvpEventCb(pTask->type, pTask->pOutData, iOutSize, pTask->pInData, 0);
}
}
int EvpAddCryptoTask(CRYPTO_TYPE type,
unsigned char* pInBuf,
int iSize,
unsigned char* pOutBuf,
char* pKey,
OnEVPCrypto onEvpCryptCb)
{
uv_work_t* puvWork = NULL;
PCRYPT_TASK_PARAMS pTask = NULL;
PLIBUV_DBUS_PARAMS pContext = DBusLibuvGetRuntime();
if(!pContext || !onEvpCryptCb)
{
return -ERR_INPUT_PARAMS;
}
if(type == CRYPTO_AES_ENCRYPT || type == CRYPTO_AES_DECRYPT)
{
if(pKey == NULL || pOutBuf == NULL)
{
return -ERR_INPUT_PARAMS;
}
switch(strlen(pKey) * 8)
{
case 128:
case 192:
case 256:
break;
default:
return -ERR_EVP_KEY_SIZE;
}
}
else if(type == CRYPTO_MD5_FILE)
{
uv_fs_t uvFs;
if(uv_fs_access(pContext->pLoop, &uvFs, (const char*)pInBuf, F_OK, NULL) != 0)
{
return -ERR_FILE_NOT_EXISTS;
}
}
pTask = (PCRYPT_TASK_PARAMS)malloc(sizeof(CRYPT_TASK_PARAMS));
puvWork = (uv_work_t*)malloc(sizeof(uv_work_t));
puvWork->data = (void*)pTask;
pTask->type = type;
pTask->pInData = (unsigned char*)malloc(iSize + 1);
pTask->iInSize = iSize;
pTask->pOutData = pOutBuf;
pTask->onEvpEventCb = onEvpCryptCb;
memset(pTask->pInData, 0, iSize + 1);
memset(pTask->pKey, 0, EVP_MAX_KEY_LENGTH + 1);
if(pKey)
{
strncpy(pTask->pKey, pKey, EVP_MAX_KEY_LENGTH);
}
memcpy(pTask->pInData, pInBuf, iSize);
uv_queue_work(pContext->pLoop, puvWork, OnEVPWorkCb, FreeEVPWorkCb);
return 0;
}
static void __evpLockCb(int mode, int n, const char *pFile, int line)
{
if(n >= CRYPTO_num_locks())
{
return;
}
if(mode & CRYPTO_LOCK)
{
uv_mutex_lock(&pEvpMutex[n]);
}
else
{
uv_mutex_unlock(&pEvpMutex[n]);
}
}
static unsigned long __evpIdCb(void)
{
return ((unsigned long)uv_thread_self());
}
void EvpSystemInit(void)
{
int i = 0;
pEvpMutex = (uv_mutex_t *)malloc(CRYPTO_num_locks() * sizeof(uv_mutex_t));
for(i = 0; i < CRYPTO_num_locks(); i++)
{
uv_mutex_init(&pEvpMutex[i]);
}
CRYPTO_set_id_callback(__evpIdCb);
CRYPTO_set_locking_callback(__evpLockCb);
}

View File

@ -1,156 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include "log.h"
#include "crypto.h"
#include "libuv_dbus.h"
const char* EvpMD5HashFile(const char* pFileName)
{
int rdSize = 0;
int fd, size;
uint8_t md5[EVP_MAX_MD_SIZE];
uint8_t buf[1024];
EVP_MD_CTX ctx;
char* pString = NULL;
memset(md5, 0, EVP_MAX_MD_SIZE);
EVP_MD_CTX_init(&ctx);
EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
fd = open(pFileName, O_RDONLY);
if(fd == -1)
{
LOG_EX(LOG_Error, "Open File \'%s\' error\n", pFileName);
return NULL;
}
do
{
rdSize = read(fd, buf, 1024);
if(rdSize > 0)
{
EVP_DigestUpdate(&ctx, buf, rdSize);
}
} while(rdSize > 0);
close(fd);
EVP_DigestFinal_ex(&ctx, md5, &rdSize);
EVP_MD_CTX_cleanup(&ctx);
size = rdSize * 2 + 1;
pString = (char*)malloc(size);
memset(pString, 0, size);
IHW_bin2hex(pString, md5, rdSize);
// print_hex_dump_bytes("MD5_", DUMP_PREFIX_ADDRESS, md5, rdSize);
// fprintf(stdout, "MD5: [%s]\n", pString);
return (const char*)pString;
}
int EvpMD5HashFileV2(const char* pFileName, unsigned char md5[16])
{
int rdSize = 0;
int fd;
uint8_t buf[1024];
EVP_MD_CTX ctx;
//char* pString = NULL;
memset(md5, 0, 16);
EVP_MD_CTX_init(&ctx);
EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
fd = open(pFileName, O_RDONLY);
if(fd == -1)
{
LOG_EX(LOG_Error, "Open File %s error\n", pFileName);
return (-ERR_OPEN_FILE);
}
do
{
rdSize = read(fd, buf, 1024);
EVP_DigestUpdate(&ctx, buf, rdSize);
} while(rdSize > 0);
close(fd);
EVP_DigestFinal_ex(&ctx, md5, &rdSize);
EVP_MD_CTX_cleanup(&ctx);
// print_hex_dump_bytes("MD5_", DUMP_PREFIX_ADDRESS, md5, rdSize);
// fprintf(stdout, "MD5: [%s]\n", pString);
return 0;
}
int EvpMD5HashBuf(const unsigned char* pBuf, int iBufLen, unsigned char* pOutBuf, int* pOutSize)
{
EVP_MD_CTX ctx;
if(pBuf == NULL || pOutBuf == NULL)
{
return (-ERR_INPUT_PARAMS);
}
memset(pOutBuf, 0, EVP_MAX_MD_SIZE);
EVP_MD_CTX_init(&ctx);
EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
EVP_DigestUpdate(&ctx, pBuf, iBufLen);
EVP_DigestFinal_ex(&ctx, pOutBuf, &iBufLen);
EVP_MD_CTX_cleanup(&ctx);
if(pOutSize)
{
*pOutSize = iBufLen;
}
//print_hex_dump_bytes("MD5_", DUMP_PREFIX_ADDRESS, pOutBuf, iBufLen);
return 0;
}
const char* EvpMD5HashBufV2(const unsigned char* pBuf, int iBufLen)
{
int size = 0;
EVP_MD_CTX ctx;
uint8_t md5[EVP_MAX_MD_SIZE];
char* pString = NULL;
if(pBuf == NULL || iBufLen <= 0)
{
return NULL;
}
memset(md5, 0, EVP_MAX_MD_SIZE);
EVP_MD_CTX_init(&ctx);
EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
EVP_DigestUpdate(&ctx, pBuf, iBufLen);
EVP_DigestFinal_ex(&ctx, md5, &iBufLen);
EVP_MD_CTX_cleanup(&ctx);
//print_hex_dump_bytes("MD5_", DUMP_PREFIX_ADDRESS, pOutBuf, iBufLen);
size = iBufLen * 2 + 1;
pString = (char*)malloc(size);
memset(pString, 0, size);
IHW_bin2hex(pString, md5, iBufLen);
// print_hex_dump_bytes("MD5_", DUMP_PREFIX_ADDRESS, md5, rdSize);
// fprintf(stdout, "MD5: [%s]\n", pString);
return (const char*)pString;
}

View File

@ -1,197 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include "log.h"
#include "libuv_dbus.h"
typedef struct
{
MODULE_NAME modName;
uint32_t hTm[MODULE_MAX];
int isDaemonWork[MODULE_MAX];
int isConnected[MODULE_MAX];
OnDaemonMsg pOnHeartLostCb;
} HEART_DAEMON, *PHEART_DAEMON;
uint32_t g_hblTout = HEART_LOST_DELAY; ///< nano second: heart lost timeout, default 1s
static uv_loop_t *g_DeamonLoop;
static uv_idle_t g_uvDeamonIdle;
static HEART_DAEMON g_heartDaemon;
static unsigned int g_Cnt = 0;
static int timerExpire(uint32_t tm, uint32_t tExp)
{
uint32_t now = LIBUV_CURRENT_TIME_MS();
int64_t diff = now - tm;
if(tm == 0 || tExp == 0)
{
return 0;
}
if(diff > tExp * 1000)
{
return 0;
}
else if(diff >= tExp)
{
return 1;
}
return (0);
}
static void RunPingSvr(void)
{
int ret = 0;
unsigned int tm = LIBUV_CURRENT_TIME_MS();
PING_MSG pMsg;
struct timeval tv;
gettimeofday(&tv, NULL);
pMsg.PING = (double)tm / 1000;
pMsg.tmSec = tv.tv_sec;
pMsg.tmMSec = tv.tv_usec;
ret = DBusJsonBoardcastCommand(NULL, 0xFFFFFFFF, CMD_MISC_PING, JSON_ENGINE_PING, &pMsg, FALSE);
if(ret != 0)
{
LOG_EX(LOG_Error, "DBus boardcast message error: %d\n", ret);
}
}
void HeartDaemonHblCheck(void)
{
if(g_heartDaemon.modName != MODULE_CONTROLLER)
{
if(g_heartDaemon.isDaemonWork[MODULE_CONTROLLER] && timerExpire(g_heartDaemon.hTm[MODULE_CONTROLLER], g_hblTout))
{
g_heartDaemon.pOnHeartLostCb(MODULE_CONTROLLER, TRUE);
g_heartDaemon.hTm[MODULE_CONTROLLER] = 0;
g_heartDaemon.isConnected[MODULE_CONTROLLER] = FALSE;
}
}
else
{
int i;
for(i = 0; i < MODULE_MAX; i++)
{
if(g_heartDaemon.isDaemonWork[i]
&& i != MODULE_CONTROLLER
&& timerExpire(g_heartDaemon.hTm[i], g_hblTout))
{
g_heartDaemon.pOnHeartLostCb(i, TRUE);
g_heartDaemon.hTm[i] = 0;
g_heartDaemon.isConnected[i] = FALSE;
}
}
}
}
void HeartDaemonUpgrade(int iWatcher)
{
if(iWatcher >= MODULE_MAX)
{
return;
}
if(g_heartDaemon.hTm[iWatcher] == 0)
{
if(g_heartDaemon.modName == MODULE_CONTROLLER)
{
g_heartDaemon.pOnHeartLostCb(iWatcher, FALSE);
}
else if(iWatcher == MODULE_CONTROLLER)
{
g_heartDaemon.pOnHeartLostCb(iWatcher, FALSE);
}
g_heartDaemon.isConnected[iWatcher] = TRUE;
RunPingSvr();
}
g_heartDaemon.hTm[iWatcher] = LIBUV_CURRENT_TIME_MS();
}
static int __isSendPingOnTime(void)
{
static unsigned int tmPre = 0;
unsigned int tm = LIBUV_CURRENT_TIME_MS();
unsigned int tmOut = HEART_SEND_DELAY;
if(g_heartDaemon.modName != MODULE_CONTROLLER
&& g_heartDaemon.isConnected[MODULE_CONTROLLER] == FALSE)
{
tmOut = 5000;
}
if(tmPre != 0 && tm - tmPre < tmOut)
{
return (FALSE);
}
tmPre = tm;
return (TRUE);
}
static void __uvIdleCb(uv_idle_t* phuvIdle)
{
if(DBusLibuvGetRuntime()->onHblCb
&& __isSendPingOnTime())
{
RunPingSvr();
}
HeartDaemonHblCheck();
sleep(1);
}
static void __uvThreadDaemon(void *pParams)
{
g_DeamonLoop = uv_loop_new();
uv_idle_init(g_DeamonLoop, &g_uvDeamonIdle);
uv_idle_start(&g_uvDeamonIdle, __uvIdleCb);
uv_run(g_DeamonLoop, UV_RUN_DEFAULT);
pthread_detach(pthread_self());
}
void HeartDaemonInit(MODULE_NAME mod, int msHblTout, OnDaemonMsg cb)
{
uv_thread_t uvDaemonThread;
int i;
memset(&g_heartDaemon, 0, sizeof(HEART_DAEMON));
if(msHblTout > 0)
{
g_hblTout = msHblTout;
}
g_heartDaemon.modName = mod;
for(i = 0; i < MODULE_MAX; i++)
{
if(mod == MODULE_CONTROLLER)
{
g_heartDaemon.isDaemonWork[i] = (g_pModInfoTable[i].modName != MODULE_CONTROLLER) ? TRUE : FALSE;
}
else
{
g_heartDaemon.isDaemonWork[i] = (g_pModInfoTable[i].modName == MODULE_CONTROLLER) ? TRUE : FALSE;
}
g_heartDaemon.isConnected[i] = FALSE;
}
g_heartDaemon.pOnHeartLostCb = cb;
uv_thread_create(&uvDaemonThread, __uvThreadDaemon, NULL);
}

View File

@ -1,181 +0,0 @@
#ifndef PLATFORM_CPU
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <uthash/utlist.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#if defined(PLATFORM_R16) || defined (PLATFORM_CPU) || defined(PLATFORM_R311)
#include "log.h"
#include "libuv_dbus.h"
#include "boardlink_iot.h"
#else
#include <uvdbus/log.h>
#include <uvdbus/libuv_dbus.h>
#include <uvdbus/boardlink_iot.h>
#endif
#define BL_IOT_PROTO (30)
#define BL_MSG_BUF_MAX (1024 * 4)
static int g_nlSock = -1;
static unsigned char g_MsgSendBuf[BL_MSG_BUF_MAX];
static BlMsgCb g_blMsgCb = NULL;
static void __recvMsgThread(void *pParam)
{
unsigned char msgBuf[BL_MSG_BUF_MAX];
struct iovec iov = {msgBuf, BL_MSG_BUF_MAX};
struct nlmsghdr *pMsgHdr;
struct sockaddr_nl fromAddr;
struct msghdr msgHdr = {&fromAddr, sizeof(fromAddr), &iov, 1, NULL, 0, 0};;
memset(&fromAddr, 0, sizeof(fromAddr));
fromAddr.nl_family = AF_NETLINK;
fromAddr.nl_pid = 0;
fromAddr.nl_groups = 0;
while(TRUE)
{
int len = recvmsg(g_nlSock, &msgHdr, 0);
if(len > 0)
{
for(pMsgHdr = (struct nlmsghdr *)msgBuf;
NLMSG_OK(pMsgHdr, len);
pMsgHdr = NLMSG_NEXT(pMsgHdr, len))
{
if(pMsgHdr->nlmsg_type == NLMSG_DONE)
{
continue;
}
else if(pMsgHdr->nlmsg_type == NLMSG_ERROR)
{
continue;
}
else
{
PBL_IOT_MSG pMsg = (PBL_IOT_MSG)NLMSG_DATA(pMsgHdr);
//LOG_EX(LOG_Debug, "Recv Message: %s\n", NLMSG_DATA(pMsgHdr));
print_hex_dump_bytes("Msg", 0, pMsg, BL_IOT_MSG_LEN(pMsg->msglen));
if(g_blMsgCb)
{
g_blMsgCb(pMsg);
}
}
}
}
usleep(1000);
}
pthread_detach(pthread_self());
}
static int __nlCreateSocket(void)
{
struct sockaddr_nl srcAddr;
g_nlSock = socket(AF_NETLINK, SOCK_RAW, BL_IOT_PROTO);
if(g_nlSock == -1)
{
LOG_EX(LOG_Error, "Create netlink socker error: %s\n", strerror(errno));
return -ERR_CREATE_SOCKET;
}
memset(&srcAddr, 0, sizeof(srcAddr));
srcAddr.nl_family = AF_NETLINK;
srcAddr.nl_pid = getpid();
srcAddr.nl_groups = 0;
if(bind(g_nlSock, (struct sockaddr*)&srcAddr, sizeof(srcAddr)) < 0)
{
LOG_EX(LOG_Error, "Bind netlink socket failed: %s", strerror(errno));
close(g_nlSock);
return -ERR_BIND_SOCKET;
}
return 0;
}
static int __sendMessage(unsigned char* pData, unsigned int len)
{
struct iovec iov;
struct sockaddr_nl dstAddr;
struct nlmsghdr* pMsgHdr = (struct nlmsghdr*)g_MsgSendBuf;
struct msghdr msgHdr = {&dstAddr, sizeof(dstAddr), &iov, 1, NULL, 0, 0};
memset(&dstAddr, 0, sizeof(struct sockaddr_nl));
dstAddr.nl_family = AF_NETLINK;
dstAddr.nl_pid = 0;
dstAddr.nl_groups = 0;
memset(pMsgHdr, 0, BL_MSG_BUF_MAX);
pMsgHdr->nlmsg_len = len;
pMsgHdr->nlmsg_pid = getpid();
pMsgHdr->nlmsg_flags = 0;
memcpy(NLMSG_DATA(pMsgHdr), pData, len);
iov.iov_base = pMsgHdr;
iov.iov_len = NLMSG_SPACE(BL_MSG_BUF_MAX);
return sendmsg(g_nlSock, &msgHdr, 0);
}
int BL_SendBLMsg(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len)
{
BL_IOT_MSG blMsg;
memset(&blMsg, 0, sizeof(BL_IOT_MSG));
blMsg.msgType = msgType;
blMsg.msglen = len;
strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS);
if(pData && len > 0)
{
memcpy(blMsg.msgData, pData, len);
}
return __sendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(len));
}
int BL_SendBLMsgTo(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len, unsigned char dstMac[ETH_ALEN])
{
BL_IOT_MSG blMsg;
memset(&blMsg, 0, sizeof(BL_IOT_MSG));
blMsg.msgType = msgType;
blMsg.msglen = len;
memcpy(blMsg.dstMac, dstMac, ETH_ALEN);
strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS);
if(pData && len > 0)
{
memcpy(blMsg.msgData, pData, len);
}
return __sendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(len));
}
int BL_Init(BlMsgCb cbOnMsg)
{
int ret = 0;
uv_thread_t uvRecvThread;
ret = __nlCreateSocket();
if(ret != 0)
{
return ret;
}
g_blMsgCb = cbOnMsg;
uv_thread_create(&uvRecvThread, __recvMsgThread, NULL);
return 0;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,347 +0,0 @@
#ifdef ENABLE_COUNT_DEBUG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <uv.h>
#include <dbus/dbus.h>
#include <errno.h>
#include <time.h>
#include <limits.h>
#include <sqlite3.h>
#include <uthash/uthash.h>
#include <uthash/utlist.h>
#include <uthash/utstring.h>
#include "log.h"
#include "libuv_dbus.h"
#define LOG_SAVE_TIME (1000)
typedef struct
{
long long maxValue;
long long minValue;
long long avgValue;
} STATISTICAL_VALUE, *PSTATISTICAL_VALUE;
typedef struct
{
long long curVaule;
long long tolValue;
unsigned int tolCount;
STATISTICAL_VALUE cVal;
} CSTATISTICAL_INFO, *PSTATISTICAL_INFO;
typedef struct
{
char* pMonName;
unsigned long nCount;
CSTATISTICAL_INFO nCstInfo;
uv_rwlock_t rwLock;
uv_timer_t logTimer;
unsigned int logTime;
UT_hash_handle hh; ///< UT Hash handle
} MONITOR_INFO, *PMONITOR_INFO;
static uv_rwlock_t g_uvMonRwLock;
static PMONITOR_INFO g_MonTbl = NULL;
static uv_loop_t* g_MonLogLoop = NULL;
static void __uvMonLogProc(void *pParams)
{
RunUVLoop(g_MonLogLoop);
while(TRUE)
{
usleep(1000);
}
pthread_detach(pthread_self());
}
static void __logMonTimerProc(uv_timer_t* pTimer)
{
PMONITOR_INFO pInfo = (PMONITOR_INFO)pTimer->data;
if(pInfo && (pInfo->nCount + pInfo->nCstInfo.tolCount > 0))
{
UT_string* pMsg = NULL;
utstring_new(pMsg);
uv_rwlock_rdlock(&pInfo->rwLock);
utstring_printf(pMsg, "%s Statistical Information:\n", pInfo->pMonName);
//LOG_EX(LOG_Debug, "%s Statistical Information:\n", pInfo->pMonName);
if(pInfo->nCount)
{
UT_string* pMsgCount = NULL;
utstring_new(pMsgCount);
utstring_printf(pMsgCount, " Total Count = %lu\n", pInfo->nCount);
utstring_concat(pMsg, pMsgCount);
utstring_free(pMsgCount);
//LOG_EX(LOG_Debug, " Total Count = %u\n", pInfo->nCount);
}
if(pInfo->nCstInfo.tolCount > 0)
{
UT_string* pMsgStat = NULL;
utstring_new(pMsgStat);
utstring_printf(pMsgStat, " Max Value = %lld\n"
" Min Value = %lld\n"
" Avg Value = %lld\n"
" ---- Statistical by total %lld of %u times\n",
pInfo->nCstInfo.cVal.maxValue,
pInfo->nCstInfo.cVal.minValue,
pInfo->nCstInfo.cVal.avgValue,
pInfo->nCstInfo.tolValue,
pInfo->nCstInfo.tolCount);
utstring_concat(pMsg, pMsgStat);
utstring_free(pMsgStat);
#if 0
LOG_EX(LOG_Debug, " Max Value = %lld\n", pInfo->nCstInfo.cVal.maxValue);
LOG_EX(LOG_Debug, " Min Value = %lld\n", pInfo->nCstInfo.cVal.minValue);
LOG_EX(LOG_Debug, " Avg Value = %lld\n", pInfo->nCstInfo.cVal.avgValue);
LOG_EX(LOG_Debug, " ---- Statistical by total %lld of %u times\n",
pInfo->nCstInfo.tolValue, pInfo->nCstInfo.tolCount);
#endif
}
LOG_EX(LOG_Debug, "%s", utstring_body(pMsg));
uv_rwlock_rdunlock(&pInfo->rwLock);
utstring_free(pMsg);
}
}
int MonitorInit(void)
{
uv_thread_t uvMonLogThread;
g_MonLogLoop = uv_loop_new();
uv_rwlock_init(&g_uvMonRwLock);
uv_thread_create(&uvMonLogThread, __uvMonLogProc, NULL);
return 0;
}
int MonAddNewItem(const char* pName, int logSaveTime)
{
PMONITOR_INFO pInfo;
if(pName == NULL || strlen(pName) == 0)
{
return -ERR_INPUT_PARAMS;
}
uv_rwlock_rdlock(&g_uvMonRwLock);
HASH_FIND_STR(g_MonTbl, pName, pInfo);
uv_rwlock_rdunlock(&g_uvMonRwLock);
if(pInfo != NULL)
{
return -ERR_CFG_ITEM_EXIST;
}
pInfo = (PMONITOR_INFO)malloc(sizeof(MONITOR_INFO));
if(pInfo == NULL)
{
return -ERR_MALLOC_MEMORY;
}
memset(pInfo, 0, sizeof(MONITOR_INFO));
pInfo->nCstInfo.cVal.minValue = INT_MAX;
pInfo->logTime = logSaveTime;
pInfo->pMonName = strdup(pName);
if(pInfo->logTime > 0)
{
pInfo->logTimer.data = pInfo;
uv_timer_init(g_MonLogLoop, &pInfo->logTimer);
uv_timer_start(&pInfo->logTimer, __logMonTimerProc, pInfo->logTime, pInfo->logTime);
}
else
{
pInfo->logTime = 0;
}
uv_rwlock_init(&pInfo->rwLock);
uv_rwlock_wrlock(&g_uvMonRwLock);
HASH_ADD_STR(g_MonTbl, pMonName, pInfo);
uv_rwlock_wrunlock(&g_uvMonRwLock);
return 0;
}
int MonIncreaseCount(const char* pName)
{
PMONITOR_INFO pInfo;
if(pName == NULL || strlen(pName) == 0)
{
return -ERR_INPUT_PARAMS;
}
uv_rwlock_rdlock(&g_uvMonRwLock);
HASH_FIND_STR(g_MonTbl, pName, pInfo);
uv_rwlock_rdunlock(&g_uvMonRwLock);
if(pInfo == NULL)
{
return -ERR_CFG_NOITEM;
}
uv_rwlock_wrlock(&pInfo->rwLock);
pInfo->nCount++;
uv_rwlock_wrunlock(&pInfo->rwLock);
return 0;
}
int MonDiffStatistical(const char* pName, long long newVal)
{
PMONITOR_INFO pInfo;
if(pName == NULL || strlen(pName) == 0)
{
return -ERR_INPUT_PARAMS;
}
uv_rwlock_rdlock(&g_uvMonRwLock);
HASH_FIND_STR(g_MonTbl, pName, pInfo);
uv_rwlock_rdunlock(&g_uvMonRwLock);
if(pInfo == NULL)
{
return -ERR_CFG_NOITEM;
}
uv_rwlock_wrlock(&pInfo->rwLock);
if(pInfo->nCstInfo.curVaule != 0)
{
long long diffValue = newVal - pInfo->nCstInfo.curVaule;
pInfo->nCstInfo.tolValue += diffValue;
pInfo->nCstInfo.tolCount++;
if(pInfo->nCstInfo.tolCount > 10)
{
pInfo->nCstInfo.cVal.avgValue = pInfo->nCstInfo.tolValue / pInfo->nCstInfo.tolCount;
if(pInfo->nCstInfo.cVal.maxValue < diffValue)
{
pInfo->nCstInfo.cVal.maxValue = diffValue;
}
if(pInfo->nCstInfo.cVal.minValue > diffValue)
{
pInfo->nCstInfo.cVal.minValue = diffValue;
}
}
}
pInfo->nCstInfo.curVaule = newVal;
uv_rwlock_wrunlock(&pInfo->rwLock);
//fprintf(stdout, "%s value %lld diffValue %lld\n", pName, newVal, diffValue);
return 0;
}
int MonUpgradeStatistical(const char* pName, long newVal)
{
PMONITOR_INFO pInfo;
if(pName == NULL || strlen(pName) == 0)
{
return -ERR_INPUT_PARAMS;
}
uv_rwlock_rdlock(&g_uvMonRwLock);
HASH_FIND_STR(g_MonTbl, pName, pInfo);
uv_rwlock_rdunlock(&g_uvMonRwLock);
if(pInfo == NULL)
{
return -ERR_CFG_NOITEM;
}
uv_rwlock_wrlock(&pInfo->rwLock);
pInfo->nCstInfo.curVaule = newVal;
pInfo->nCstInfo.tolValue += newVal;
pInfo->nCstInfo.tolCount++;
pInfo->nCstInfo.cVal.avgValue = pInfo->nCstInfo.tolValue / pInfo->nCstInfo.tolCount;
if(pInfo->nCstInfo.cVal.maxValue < newVal)
{
pInfo->nCstInfo.cVal.maxValue = newVal;
}
if(pInfo->nCstInfo.cVal.minValue > newVal)
{
pInfo->nCstInfo.cVal.minValue = newVal;
}
uv_rwlock_wrunlock(&pInfo->rwLock);
//fprintf(stdout, "%s value %ld\n", pName, newVal);
return 0;
}
int MonItemLogout(const char* pName)
{
PMONITOR_INFO pInfo;
if(pName == NULL || strlen(pName) == 0)
{
return -ERR_INPUT_PARAMS;
}
uv_rwlock_rdlock(&g_uvMonRwLock);
HASH_FIND_STR(g_MonTbl, pName, pInfo);
uv_rwlock_rdunlock(&g_uvMonRwLock);
if(pInfo == NULL)
{
return -ERR_CFG_NOITEM;
}
if(pInfo->nCount + pInfo->nCstInfo.tolCount == 0)
{
LOG_EX(LOG_Debug, "%s Statistical Unchanged\n", pInfo->pMonName);
return 0;
}
uv_rwlock_rdlock(&pInfo->rwLock);
LOG_EX(LOG_Debug, "%s Statistical Information:\n", pInfo->pMonName);
if(pInfo->nCount)
{
LOG_EX(LOG_Debug, " Total Count = %u\n", pInfo->nCount);
}
if(pInfo->nCstInfo.tolCount > 0)
{
LOG_EX(LOG_Debug, " Max Value = %lld\n", pInfo->nCstInfo.cVal.maxValue);
LOG_EX(LOG_Debug, " Min Value = %lld\n", pInfo->nCstInfo.cVal.minValue);
LOG_EX(LOG_Debug, " Avg Value = %lld\n", pInfo->nCstInfo.cVal.avgValue);
LOG_EX(LOG_Debug, " ---- Statistical by total %lld of %u times\n",
pInfo->nCstInfo.tolValue, pInfo->nCstInfo.tolCount);
}
uv_rwlock_rdunlock(&pInfo->rwLock);
return 0;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,235 +0,0 @@
#include "server_addr.h"
#include "log.h"
#include "config_engine.h"
#include "libuv_dbus.h"
const char* g_ServerModuleStr[] =
{
"YUNXIN_MODULE",
"VOICE_MODULE",
"VOICE_AI_MODULE",
"SERVER_MODULE",
"LOG_MODULE",
"MARK_POINT_MODULE",
"TTS_MODULE",
"DC_MODULE",
"UNKNOWN_MODULE"
};
const char* g_ServerModeStr[] =
{
"DEV_MODE",
"TEST_MODE",
"PUBLISH_MODE",
"PUBLISH_PREBUILD",
"UNKNOWN_MODE"
};
const char* g_KeyMapStr[] =
{
"VOICE_APP_KEY",
"VOICE_APP_SECRET",
"UNKNOWN_KEYMAP"
};
const char* SvrModuleStr(SERVER_MODULE_TYPE module)
{
return g_ServerModuleStr[module];
}
const char* SvrModeStr(SERVER_MODE_TYPE mode)
{
return g_ServerModeStr[mode];
}
const char* g_VoiceKeyMap[VOICE_MAX][MAX_MODE] = {
{ // VOICE_APP_KEY
"vbox-dev",
"vbox-dev",
"vbox-online",
"vbox-online",
},
{ // VOICE_APP_SECRET
"b1ec33c03df80ea3035bc9ccaa4af09c",
"b1ec33c03df80ea3035bc9ccaa4af09c",
"8714d6de1c83f21dda5fc9a905a59ac1",
"8714d6de1c83f21dda5fc9a905a59ac1",
},
};
const char* g_ServerAddr[MAX_MODULE][MAX_MODE] = {
{ // YUNXIN_MODULE
"2e37bc56a9b7ec3f6b8f41f60b81eb92",
"2e37bc56a9b7ec3f6b8f41f60b81eb92",
"dbb00213c23ea3709aae12ceb4c4e54e",
"7fc939cdb26ec2fa343b7c47a0617190",
},
{ // VOICE_MODULE
"ws://vbox-test.netease.com/netty/websocket",
"ws://vbox-test.netease.com/netty3/websocket",
"wss://vbox-asr.3.163.com/websocket",
"ws://vbox-test.netease.com/asr/websocket",
},
{ // VOICE_AI_MODULE
"http://api.multimedia.netease.com/imgtest/yqbot31_8686/",
"http://api.multimedia.netease.com/imgtest/yqbot29_8686/",
"https://vbox-smart.3.163.com/ ",
"http://api.multimedia.netease.com/imgtest/yqbot30_8888/",
},
{ // SERVER_MODULE
"http://api.multimedia.netease.com/imgtest/yqbot27_7677/",
"http://api.multimedia.netease.com/imgtest/yqbot31_7676/",
"https://vbox-server.3.163.com/",
"http://api.multimedia.netease.com/imgtest/yqbot22_7678/",
},
{ // LOG_MODULE
"http://vbox-log-test.netease.com/logCollectDev/vbox/logCollect/uploadLog",
"http://vbox-log-test.netease.com/logCollect/vbox/logCollect/uploadLog",
"https://vbox-log.3.163.com/vbox/logCollect/uploadLog",
"http://vbox-log-test.netease.com/logCollectOnline/vbox/logCollect/uploadLog",
},
{ // MARK_POINT_MODULE
"http://vbox-log-test.netease.com/buriedDev/vbox/log/add",
"http://vbox-log-test.netease.com/buriedTest/vbox/log/add",
"https://vbox-log.3.163.com/vbox/log/add",
"http://vbox-log-test.netease.com/buriedOnline/vbox/log/add",
},
{ // TTS_MODULE
"http://api.openai.netease.com/vbox-tts-dev/vbox/tts/transform",
"http://api.openai.netease.com/vbox-tts-test/vbox/tts/transform",
"https://vbox-tts.3.163.com/vbox/tts/transform",
"http://api.openai.netease.com/vbox-tts-online/vbox/tts/transform",
},
{ // DC_MODULE
"http://api.multimedia.netease.com/imgtest/yqbot27_7677/vbox/uploadFile",
"http://api.multimedia.netease.com/imgtest/yqbot31_7676/vbox/uploadFile",
"https://vbox-server.3.163.com/vbox/uploadFile",
"http://api.multimedia.netease.com/imgtest/yqbot22_7678/vbox/uploadFile",
},
};
static unsigned int g_SvrMode = PUBLISH_MODE;
void DumpCurServerAddr(const char* pTags)
{
if(pTags && strlen(pTags) > 0)
{
LOG_EX2(LOG_Info, "%s\t Current Server Mode: %s\n", pTags, SvrModeStr(g_SvrMode));
}
else
{
LOG_EX2(LOG_Info, "Current Server Mode: %s\n", SvrModeStr(g_SvrMode));
}
#if 0
LOG_EX2(LOG_Info, "Voice Key = [%s], Secret = [%s]\n",
GetCurVoiceKeyValue(VOICE_APP_KEY), GetCurVoiceKeyValue(VOICE_APP_SECRET));
LOG_EX2(LOG_Info, "--------------------------------------------------------"
"----------------------------------------------\n");
LOG_EX2(LOG_Info, "| Module | "
"Server URL |\n");
LOG_EX2(LOG_Info, "--------------------------------------------------------"
"----------------------------------------------\n");
for(int i = 0; i < MAX_MODULE; i++)
{
LOG_EX2(LOG_Info, "| %-17s | %-78s |\n", SvrModuleStr(i), GetCurServerAddr(i));
}
LOG_EX2(LOG_Info, "--------------------------------------------------------"
"----------------------------------------------\n");
#endif
}
SERVER_MODE_TYPE GetCurrentServerMode(void)
{
return g_SvrMode;
}
void SetCurrentServerMode(SERVER_MODE_TYPE mode)
{
if(mode >= 0 && mode < MAX_MODE)
{
if(g_SvrMode != mode)
{
LOG_EX(LOG_Debug, "Change server mode from %s(%d) to %s(%d)\n",
g_ServerModeStr[g_SvrMode], g_SvrMode, g_ServerModeStr[mode], mode);
g_SvrMode = mode;
CfgSetIntValue("ServerMode", mode);
}
else
{
LOG_EX(LOG_Warn, "Current mode is %s(%d) yet\n", g_ServerModeStr[mode], mode);
}
}
else
{
LOG_EX(LOG_Error, "Unknown Mode: %d, current mode: %s(%d)\n",
mode, g_ServerModeStr[g_SvrMode], g_SvrMode);
}
}
char* GetCurServerAddr(SERVER_MODULE_TYPE module)
{
if(module >= 0 && module < MAX_MODULE)
{
return (char*)g_ServerAddr[module][g_SvrMode];
}
else
{
LOG_EX(LOG_Error, "Unknown Module: %s(%d)\n", g_ServerModuleStr[module], module);
return "";
}
}
char* GetCurVoiceKeyValue(VOICE_KEYMAP_TYPE keyMap)
{
if(keyMap >= 0 && keyMap < VOICE_MAX)
{
return (char*)g_VoiceKeyMap[keyMap][g_SvrMode];
}
else
{
LOG_EX(LOG_Error, "Unknown KeyMap Type: %s(%d)\n", g_KeyMapStr[keyMap], keyMap);
return "";
}
}
static PDBUS_MSG_PACK __dusOnMsg(uv_loop_t* pLoop, DBusConnection* pConn, PDBUS_MSG_PACK pMsg)
{
return NULL;
}
static void uvLoopProc(void *pParams)
{
RunUVLoop(GetDBusDefaultLoop());
pthread_detach(pthread_self());
}
void ServerManagerInit(void)
{
int ret = 0;
uv_thread_t uvThread;
LOG_EX(LOG_Warn, "+++++++++++++++++++++++System Uninit\n");
DBusConnection* pBus = DBusWithLibuvInit(GetDBusDefaultLoop(),
g_pModInfoTable[MODULE_SKINS].modAliase,
__dusOnMsg,
NULL,
NULL, //KeyEventCb,
&ret);
if(pBus == NULL)
{
LOG_EX(LOG_Error, "DBusWithLibuvInit Error: %d\n", ret);
return;
}
uv_thread_create(&uvThread, uvLoopProc, NULL);
}