⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 license.cpp

📁 跨操作系统的微型中间件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		CHAR strLicenseString[1024];	memset(strLicenseString, 0, 1024);			/*获取K1和K2*/	DES3_Encrypt DES3Encry;	DES3Encry.set_des3_key( m_LicenseSerial );	char des3_k1[9], des3_k2[9];	memset(des3_k1, 0, 9);	memset(des3_k2, 0, 9);	DES3Encry.get_des3_key( (unsigned char*) des3_k1, (unsigned char*) des3_k2 );#ifndef __Win32__	int legal = 0;	for (int i=0; i<NetCardCount; i++)	{		memset(strLicenseString, 0, 1024);		/*将配置项按顺序拼接成字符串*/		strcat(strLicenseString, des3_k1);				strcat(strLicenseString, m_LicenseSerial);				strcat(strLicenseString, strESN);				strcat(strLicenseString, NetCardInfo[i].MacAddr);				strcat(strLicenseString, m_LicenseType);				strcat(strLicenseString, strMaxBandwidth);				strcat(strLicenseString, strMaxConnects);				strcat(strLicenseString, m_StartTime);		strcat(strLicenseString, m_EndTime);		strcat(strLicenseString,strLiveIn);		strcat(strLicenseString, des3_k2);				/*首先进行MD5加密*/		MD5_Check MD5Cal;			BYTE bMD5Result[16] = { 0 };				MD5Cal.GetMD5Result((BYTE*)strLicenseString,							strlen(strLicenseString),							(BYTE*) bMD5Result );				/*然后进行DES3加密*/		unsigned char bDES3Result[16] = { 0 };				DES3Encry.des3_crypt(bMD5Result, bDES3Result);/*先对前8个字节加密1*/		DES3Encry.des3_crypt(bMD5Result + 8, bDES3Result + 8);/*再对后8个字节加密*/				/*将LicenseKey转换成16进制字符*/		static char newLicenseKey[40] = {0};		sprintf( newLicenseKey , "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x"				, bDES3Result[0], bDES3Result[1], bDES3Result[2], bDES3Result[3]				, bDES3Result[4], bDES3Result[5], bDES3Result[6], bDES3Result[7]				, bDES3Result[8], bDES3Result[9], bDES3Result[10], bDES3Result[11]				, bDES3Result[12], bDES3Result[13], bDES3Result[14], bDES3Result[15] );		/*判断License文件的合法性*/		if( !strcmp(m_LicenseKey, newLicenseKey))		{			legal++;			break;		}			}	if (0 == legal)	{		TERMDEBUGMSG(1,"LicenseKey is illegal!\n");		return FALSE;	}#else	//将配置项按顺序拼接成字符串	strcat(strLicenseString, des3_k1);	strcat(strLicenseString, m_LicenseSerial);	strcat(strLicenseString, strESN);	strcat(strLicenseString, m_MAC);	strcat(strLicenseString, m_LicenseType);	strcat(strLicenseString, strMaxBandwidth);	strcat(strLicenseString, strMaxConnects);	strcat(strLicenseString, m_StartTime);	strcat(strLicenseString, m_EndTime);	strcat(strLicenseString,strLiveIn);	strcat(strLicenseString, des3_k2);		// 首先进行MD5加密	MD5_Check MD5Cal;		BYTE bMD5Result[16] = { 0 };		MD5Cal.GetMD5Result( (BYTE*)strLicenseString,					 	 strlen(strLicenseString),						 (BYTE*) bMD5Result );		// 然后进行DES3加密	unsigned char bDES3Result[16] = { 0 };		DES3Encry.des3_crypt(bMD5Result, bDES3Result);// 先对前8个字节加密1	DES3Encry.des3_crypt(bMD5Result + 8, bDES3Result + 8);// 再对后8个字节加密		// 将LicenseKey转换成16进制字符	static char newLicenseKey[40] = {0};	sprintf( newLicenseKey , "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x"					 	 , bDES3Result[0], bDES3Result[1], bDES3Result[2], bDES3Result[3]						 , bDES3Result[4], bDES3Result[5], bDES3Result[6], bDES3Result[7]						 , bDES3Result[8], bDES3Result[9], bDES3Result[10], bDES3Result[11]						 , bDES3Result[12], bDES3Result[13], bDES3Result[14], bDES3Result[15] );	// 判断License文件的合法性	if( strcmp(m_LicenseKey, newLicenseKey))	{		TERMDEBUGMSG(1,"LicenseKey is illegal!\n");		return FALSE;	}#endif		return TRUE;}/*************************************************  Function:     is_allow_access  Description:  是否超过License文件用户限制            Calls:        limit_two() limit_bandwidth() limit_usernum()  Called By:    MS_Service_Handler::handle_input()                Real_Service_Handler::handle_input()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::is_allow_access(){	BOOL bResult = FALSE;	if( 0 != m_MaxBandwidth		&& 0 != m_MaxConnects )	{		bResult = limit_two();	}	else if( 0 != m_MaxBandwidth )	{		bResult = limit_bandwidth();	}	else if( 0 != m_MaxConnects )	{		bResult = limit_usernum();	}//	if( FALSE == bResult )//		g_pPerformance->AddRef_Performance( CPerformance::e_License_Unavailable );	return bResult;}  /*************************************************  Function:     limit_two  Description:  是否超过License文件用户并发数限制和带宽限制            Calls:        limit_two_real() limit_two_media()   Called By:    is_allow_access()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_two(){#if 0	if ( TRUE == EC_Config::is_availably('R'))/*如果设备类型未ES-R,CS-R*/	{		return limit_two_real();	}	else if( TRUE == EC_Config::is_availably('M'))	{		return limit_two_media();	}	return FALSE;#endif	return limit_two_rfss();}#if 0/*************************************************  Function:     limit_two_real  Description:  是否超过License文件用户并发数限制和带宽限制            Called By:    limit_two()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_two_real(){	if( real_user_bandwidth > m_MaxBandwidth*1000		&& real_online_usernum > m_MaxConnects)	{		TERMDEBUGMSG(1,"Current Media stream bandwith:%d concurrent clients:%d Beyond limits,reject new request!",real_user_bandwidth,real_online_usernum);		return FALSE;	}	if( real_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current Media stream bandwith:%d Beyond accredit bandwith,reject new request",real_user_bandwidth);		return FALSE;	}	else if( real_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"concurrent clients:%d beyongd limits,reject new request!",real_online_usernum);		return FALSE;		}	return TRUE;}/*************************************************  Function:     limit_two_media  Description:  是否超过License文件用户并发数限制和带宽限制            Called By:    limit_two()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_two_media(){	if( media_user_bandwidth > m_MaxBandwidth*1000		&& media_online_usernum > m_MaxConnects)	{		TERMDEBUGMSG(1,"Current bandwith:%d concurrent clients:%d beyond limits,reject new request!",media_user_bandwidth,media_online_usernum);		return FALSE;	}	if( media_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current bandwith:%d exceed accredit bandwith,reject new request",media_user_bandwidth);		return FALSE;	}	else if( media_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"Concurrent clients:%d ,reject mew request!",media_online_usernum);		return FALSE;		}	return TRUE;}#endif/*************************************************  Function:     limit_two_rfss  Description:  是否超过License文件用户并发数限制和带宽限制            Called By:    limit_two()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_two_rfss(){	if( rfss_user_bandwidth > m_MaxBandwidth*1000		&& rfss_online_usernum > m_MaxConnects)	{		TERMDEBUGMSG(1,"Current bandwith:%d Concurrent clients:%d Beyong limits, reject new request!",rfss_user_bandwidth,rfss_online_usernum);		return FALSE;	}	if( rfss_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current bandwith:%d Beyong accredit bandwith, reject new request",rfss_user_bandwidth);		return FALSE;	}	else if( rfss_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"Current concurrent clients:%d ,Reject new request!",rfss_online_usernum);		return FALSE;		}	return TRUE;}/*************************************************  Function:     limit_bandwidth  Description:  是否超过License文件用户并发数限制和带宽限制            Calls:        limit_bandwidth_real() limit_bandwidth_media()   Called By:    is_allow_access()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_bandwidth(){#if 0	if ( TRUE == EC_Config::is_availably('R'))/*如果设备类型未ES-R,CS-R*/	{		return limit_bandwidth_real();	}	else if( TRUE == EC_Config::is_availably('M'))	{		return limit_bandwidth_media();	}	return FALSE;#endif	return limit_bandwidth_rfss();}#if 0/*************************************************  Function:     limit_bandwidth_real  Description:  是否超过License文件用户带宽限制       Called By:    limit_bandwidth()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_bandwidth_real(){		if( real_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current bandwith beyond accredit,Location“LicenseMng::limit_bandwidth_real()”4!");	    return FALSE;	}	return TRUE;}/*************************************************  Function:     limit_bandwidth_media  Description:  是否超过License文件用户带宽限制            Calls:        get_PlayerAllocatedBandwidth()  Called By:    limit_bandwidth()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_bandwidth_media(){	if( media_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current bandwith beyond accredit,Location“LicenseMng::limit_bandwidth_media()”4!");	    return FALSE;	}	return TRUE;}#endif/*************************************************  Function:     limit_bandwidth_rfss  Description:  是否超过License文件用户带宽限制            Calls:        get_PlayerAllocatedBandwidth()  Called By:    limit_bandwidth()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_bandwidth_rfss(){	if( rfss_user_bandwidth > m_MaxBandwidth*1000 )	{		TERMDEBUGMSG(1,"Note:Current bandwith beyond accredit,Location“LicenseMng::limit_bandwidth_media()”4!");	    return FALSE;	}	return TRUE;}/*************************************************  Function:     limit_usernum  Description:  是否超过License文件用户并发数限制            Calls:        limit_usernum_real() limit_usernum_media()   Called By:    is_allow_access()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_usernum(){#if 0	if ( TRUE == EC_Config::is_availably('R'))/*如果设备类型未ES-R,CS-R*/	{		return limit_usernum_real();	}	else if( TRUE == EC_Config::is_availably('M'))	{		return limit_usernum_media();	}	return FALSE;#endif	return limit_usernum_rfss();}#if 0/*************************************************  Function:     limit_usernum_real  Description:  是否超过License文件用户并发数限制         Called By:    limit_usernum()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_usernum_real(){	if( real_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"Current concurrent clientsBeyong limits, reject new request!");		return FALSE;		}	return TRUE;}/*************************************************  Function:     limit_usernum_media  Description:  是否超过License文件用户并发数限制             Called By:    limit_usernum()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_usernum_media(){	if( media_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"Current concurrent clientsBeyong limits, reject new request!");		return FALSE;		}	return TRUE;}#endif/*************************************************  Function:     limit_usernum_rfss  Description:  是否超过License文件用户并发数限制             Called By:    limit_usernum()  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::limit_usernum_rfss(){	if( rfss_online_usernum > m_MaxConnects )	{		TERMDEBUGMSG(1,"Current concurrent clientsBeyong limits, reject new request!");		return FALSE;		}	return TRUE;}INT32 LicenseMng::get_streammedia_down_bw(int &down_bw){	down_bw = rfss_user_bandwidth;	return TRUE;}/*************************************************  Function:     get_MAC  Description:  获取MAC地址           Calls:        SendARP() sprintf()  Called By:    ULONG LicenseMng::initialize_license(LicenseConfigFile* cfgfile)  Return:       成功:TRUE/失败:FALSE  *************************************************/BOOL LicenseMng::get_MAC( CHAR* master_ip ){	if( NULL == master_ip )	{		TERMDEBUGMSG(1,"Error:IP is NULL,LocationLicenseMng::get_MAC!");		return FALSE;	}	    	strcpy(m_MAC, MACADDR);	return TRUE;}void TERMDEBUGMSG(int level, const char* msg, ...){	va_list args;	unsigned long curlevel = level;    va_start(args, msg);    printf(msg, args);    va_end (args);	return;}#endif // !defined WIN32

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -