コード例 #1
0
ファイル: main.cpp プロジェクト: BillXu/simple_win
void test_aes()
{
	const int nAESKeyLen = 16;
	unsigned char aesKey[nAESKeyLen + 1] = { 0 };
	RAND_pseudo_bytes((unsigned char*)aesKey, nAESKeyLen);
	std::string strKey((char*)aesKey, 16);
	std::cout << "key:  " << aesKey << std::endl << std::endl;
	std::string strAesKey((char*)aesKey, nAESKeyLen);
	std::string strNaked = "I am cswuyg.....";
	std::cout << "nake:  " << strNaked << std::endl;
	std::string strEncode = Encryption::EncodeAES(strAesKey, strNaked);
	std::cout << "encode:  " << strEncode << std::endl;
	std::string strDecode = Encryption::DecodeAES(strAesKey, strEncode);
	std::cout << "decode  " << strDecode << std::endl << std::endl;
}
コード例 #2
0
int main(int argc, char* argv[])
{
	if ((argc == 2) && (strcmp(argv[1], "-v") == 0)) {
		printf("Server Version: DBProxyServer/%s\n", VERSION);
		printf("Server Build: %s %s\n", __DATE__, __TIME__);
		return 0;
	}

	signal(SIGPIPE, SIG_IGN);
	srand(time(NULL));

	CacheManager* pCacheManager = CacheManager::getInstance(CONFIGFILE_NAME);
	if (!pCacheManager) {
		log("CacheManager init failed");
		return -1;
	}

	CDBManager* pDBManager = CDBManager::getInstance(CONFIGFILE_NAME);
	if (!pDBManager) {
		log("DBManager init failed");
		return -1;
	}

	// 主线程初始化单例,不然在工作线程可能会出现多次初始化
	if (!CAudioModel::getInstance()) {
		return -1;
	}
    
    if (!CGroupMessageModel::getInstance()) {
        return -1;
    }
    
    if (!CGroupModel::getInstance()) {
        return -1;
    }
    
    if (!CMessageModel::getInstance()) {
        return -1;
    }

	if (!CSessionModel::getInstance()) {
		return -1;
	}
    
    if(!CRelationModel::getInstance())
    {
        return -1;
    }
    
    if (!CUserModel::getInstance()) {
        return -1;
    }
    
    if (!CFileModel::getInstance()) {
        return -1;
    }


	CConfigFileReader config_file(CONFIGFILE_NAME);

	char* listen_ip		  = config_file.GetConfigName("ListenIP");
	char* str_listen_port = config_file.GetConfigName("ListenPort");
	char* str_thread_num  = config_file.GetConfigName("ThreadNum");
    char* str_file_site   = config_file.GetConfigName("MsfsSite");
    char* str_aes_key     = config_file.GetConfigName("aesKey");

	if (!listen_ip || !str_listen_port || !str_thread_num || !str_file_site || !str_aes_key) {
		log("missing ListenIP/ListenPort/ThreadNum/MsfsSite/aesKey, exit...");
		return -1;
	}
    
    if(strlen(str_aes_key) != 32)
    {
        log("aes key is invalied");
        return -2;
    }
    string strAesKey(str_aes_key, 32);
    CAes cAes = CAes(strAesKey);
    string strAudio = "[语音]";
    char* pAudioEnc;
    uint32_t nOutLen;
    if(cAes.Encrypt(strAudio.c_str(), strAudio.length(), &pAudioEnc, nOutLen) == 0)
    {
        strAudioEnc.clear();
        strAudioEnc.append(pAudioEnc, nOutLen);
        cAes.Free(pAudioEnc);
    }

	uint16_t listen_port = atoi(str_listen_port);
	uint32_t thread_num = atoi(str_thread_num);
    
    string strFileSite(str_file_site);
    CAudioModel::getInstance()->setUrl(strFileSite);

	int ret = netlib_init();

	if (ret == NETLIB_ERROR)
		return ret;
    
    /// yunfan add 2014.9.28
    // for 603 push
    curl_global_init(CURL_GLOBAL_ALL); //初始化libcurl,CURL_GLOBAL_ALL初始化所有可能的调用
    /// yunfan add end

	init_proxy_conn(thread_num);
    CSyncCenter::getInstance()->init();
    CSyncCenter::getInstance()->startSync();

	CStrExplode listen_ip_list(listen_ip, ';');
	for (uint32_t i = 0; i < listen_ip_list.GetItemCnt(); i++) {
		ret = netlib_listen(listen_ip_list.GetItem(i), listen_port, proxy_serv_callback, NULL);
		if (ret == NETLIB_ERROR)
			return ret;
	}

	printf("server start listen on: %s:%d\n", listen_ip,  listen_port);
	printf("now enter the event loop...\n");
    writePid();
	netlib_eventloop(10);

	return 0;
}