Explorar o código

Z991239-6443 #comment Connector 将 strutil.cpp移至到libtoolkit

80374374 hai 1 mes
pai
achega
687096c13d

+ 1 - 0
Framework/libtoolkit/process_monitor.h

@@ -29,6 +29,7 @@ TOOLKIT_API int process_monitor_start(process_monitor_t *monitor);
 TOOLKIT_API int process_monitor_stop(process_monitor_t *monitor);
 TOOLKIT_API int process_monitor_add(process_monitor_t *monitor, tk_process_t* process);
 TOOLKIT_API int process_monitor_remove(process_monitor_t *monitor, tk_process_t* process);
+TOOLKIT_API int process_monitor_destroy(process_monitor_t* monitor);
 
 #ifdef __cplusplus
 } // extern "C" {

+ 138 - 3
Framework/libtoolkit/strutil.c

@@ -13,6 +13,7 @@
 
 #include <winpr/wtypes.h>
 #include <winpr/string.h>
+#include <winpr/crt.h>
 #include "dbgutil.h"
 #pragma warning(disable : 4311)
 
@@ -1893,7 +1894,6 @@ static char *vasnprintf (char *resultbuf, size_t *lengthp, const char *format, v
 		    *p++ = '6';
 		    *p++ = '4';
 		    break;
-		    *p++ = 'l';
 		    /*FALLTHROUGH*/
 		  case TYPE_LONGINT:
 		  case TYPE_ULONGINT:
@@ -2047,8 +2047,6 @@ static char *vasnprintf (char *resultbuf, size_t *lengthp, const char *format, v
 			    {
 			      if (dp->precision_arg_index >= 0)
 				{
-				  int arg;
-				  
 				  if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
 				    abort ();
 				  arg = a.arg[dp->precision_arg_index].a.a_int;
@@ -2400,3 +2398,140 @@ TOOLKIT_API void str_parse_cmdline (char *cmdstart, char **argv, char *args, int
 		*argv++ = NULL;
 	++*numargs;
 }
+
+TOOLKIT_API void str_get_format_uuid(char* strbuffer, size_t ulen)
+{
+#if defined(_MSC_VER)
+	UUID uuid;
+	size_t uuidlen = 0;
+	RPC_CSTR buf;
+	UuidCreate((UUID*)&uuid);
+	UuidToString((UUID*)&uuid, &buf);
+
+	uuidlen = strlen((const char*)buf);
+	if (uuidlen < ulen) {
+		memcpy(strbuffer, (const char*)buf, uuidlen);
+	}
+
+	RpcStringFree(&buf);
+#else
+	uuid_t uuid;
+	uuid_generate(uuid);
+	uuid_unparse(uuid, strbuffer);
+#endif
+
+}
+
+TOOLKIT_API int str_reset_buffer(void* pbuf, int idata, size_t ulen)
+{
+	int ret = -1;
+	if (pbuf) {
+		memset(pbuf, idata, ulen);
+		ret = 0;
+	}
+
+	return ret;
+}
+
+
+TOOLKIT_API int str_rend_string(char* pSrc, int iflag)
+{
+	int ret = -1;
+	if (pSrc) {
+		char* pindex = pSrc;
+		while (*pindex != iflag) {
+			pindex++;
+		};
+		*pindex = '\0';
+		ret = 0;
+	}
+
+	return ret;
+}
+
+TOOLKIT_API int str_fifter_string(char* pbuf, size_t usize, const char* psrc, const char cflag)
+{
+	int ret = -1;
+	int i = 0;
+	int j = 0;
+	size_t ulen = 0;
+	const char* pindex = psrc;
+	if (NULL == psrc) {
+		return ret;
+	}
+
+	ulen = strlen(psrc);
+	for (i = 0; i < ulen && i < usize; i++) {
+		if (pindex[i] != cflag) {
+			pbuf[j++] = pindex[i];
+		}
+	}
+	if (j == ulen - 2) {
+		ret = 0;
+	}
+
+	return ret;
+}
+
+
+TOOLKIT_API int str_get_interger_netaddr(char* strbuf, size_t ubufszie, const char* szip)
+{
+	int ret = -1;
+
+	unsigned long ulip = 0;
+	if (NULL == strbuf || NULL == szip) {
+		return ret;
+	}
+
+	ulip = inet_addr(szip);
+	_ultoa(ulip, strbuf, 10);
+
+	ret = 0;
+	return ret;
+}
+
+TOOLKIT_API int str_convert_interaddr_strip(char* strbuf, size_t ubufszie, const char* szinter_ip)
+{
+	int ret = -1;
+	char* strip = NULL;
+	struct sockaddr_in addr = { 0 };
+	if (!szinter_ip || !strbuf) {
+		return ret;
+	}
+
+	addr.sin_addr.s_addr = strtoul(szinter_ip, NULL, 10);//inet_addr(config->switch_server);
+	strip = inet_ntoa(addr.sin_addr);
+	if (strip) {
+		size_t ulen = strlen(strip);
+		if (ulen < ubufszie) {
+			memcpy(strbuf, strip, ulen);
+			ret = 0;
+		}
+	}
+
+	return ret;
+}
+
+
+TOOLKIT_API int str_connect_strings(char* strbuf, size_t ulen, const char* psrca, const char* pstr, const char* psrcb)
+{
+	int ret = -1;
+	size_t ulena = 0;
+	size_t ulenb = 0;
+	size_t ulenstr = 0;
+
+	if (!psrca || !psrcb || !pstr) {
+		return ret;
+	}
+
+	ulena = strlen(psrca);
+	ulenb = strlen(psrcb);
+	ulenstr = strlen(pstr);
+
+	if (ulen > ulena + ulenb + ulenstr) {
+		snprintf(strbuf, ulen, "%s%s%s", psrca, pstr, psrcb);
+		ret = 0;
+	}
+
+	return ret;
+}

+ 18 - 1
Framework/libtoolkit/strutil.h

@@ -33,7 +33,7 @@ TOOLKIT_API void* memmem(const void* haystack, size_t haystacklen,
 	const void* needle, size_t needlelen);
 
 TOOLKIT_API char* strcasestr(const char* haystack, const char* needle);
-#endif //NOT _WIN32
+#endif //_WIN32
 
 
 /**
@@ -182,6 +182,23 @@ TOOLKIT_API char *str_xml_escape(const char *src);
 /** parse cmd line */
 TOOLKIT_API void str_parse_cmdline (char *cmdstart,char **argv,char *args,int *numargs,int *numchars);
 
+TOOLKIT_API void str_get_format_uuid(char* strbuffer, size_t ulen);
+
+
+TOOLKIT_API int str_reset_buffer(void* pbuf, int idata, size_t ulen);
+
+TOOLKIT_API int str_rend_string(char* pSrc, int iflag);
+
+TOOLKIT_API int str_fifter_string(char* pbuf, size_t usize, const char* psrc, const char cflag);
+
+TOOLKIT_API int str_get_interger_netaddr(char* strbuf, size_t ubufszie, const char* szip);
+
+TOOLKIT_API int str_convert_interaddr_strip(char* strbuf, size_t ubufszie, const char* szinter_ip);
+
+TOOLKIT_API int str_connect_strings(char* strbuf, size_t ulen, const char* psrca, const char* psrcb, const char* pstr);
+
+#define proxy_copy(pDst, pSrc)		if(pSrc)	{	memcpy(pDst, pSrc, strlen(pSrc));	}
+
 #ifdef __cplusplus
 } // extern "C" {
 #endif

+ 0 - 2
Framework/libtoolkit/win/ioqueue.c

@@ -600,7 +600,6 @@ static void dispatch_network(BOOL ret, DWORD dwBytesTransfer, ioqueue_overlapped
 						overlapped->hevt = NULL;
 						overlapped->recved_bytes += dwBytesTransfer;
 						if (err == 0 && overlapped->recved_bytes < overlapped->total_bytes) {
-							BOOL ret;
 							DWORD left = overlapped->total_bytes - overlapped->recved_bytes;
 							inc_pending_io(handle_ctx);
 							overlapped->base.ov.Internal = 0;
@@ -634,7 +633,6 @@ static void dispatch_network(BOOL ret, DWORD dwBytesTransfer, ioqueue_overlapped
 						overlapped->hevt = NULL;
 						overlapped->sended_bytes += dwBytesTransfer;
 						if (err == 0 && overlapped->sended_bytes < overlapped->total_bytes) {
-							BOOL ret;
 							DWORD left = overlapped->total_bytes - overlapped->sended_bytes;
 							inc_pending_io(handle_ctx);
 							overlapped->base.ov.Internal = 0;

+ 2 - 0
Framework/winpr/include/winpr/crt.h

@@ -155,6 +155,8 @@ extern "C"
 	WINPR_API errno_t _ltoa_s(long value, char* buffer, size_t sizeInCharacters, int radix);
 	WINPR_API char* _itoa(int value, char* buffer, int radix);
 
+	WINPR_API char* _ultoa(unsigned long value, char* pstring, int radix);
+
 	/* Buffer Manipulation */
 
 	WINPR_API errno_t memmove_s(void* dest, size_t numberOfElements, const void* src, size_t count);

+ 30 - 0
Framework/winpr/libwinpr/crt/conversion.c

@@ -105,4 +105,34 @@ char* _itoa(int value, char* buffer, int radix)
 	return buffer;
 }
 
+char* _ultoa(unsigned long value, char* pstring, int radix)
+{
+	char tmp[33] = { 0 };
+	char* tp = tmp;
+	long i;
+	unsigned long v = value;
+	char* sp;
+
+	if (radix > 36 || radix <= 1 || NULL == pstring) {
+		return 0;
+	}
+
+
+	while (v || tp == tmp) {
+		i = v % radix;
+		v = v / radix;
+		if (i < 10)
+			*tp++ = i + '0';
+		else
+			*tp++ = i + 'a' - 10;
+	}
+
+	sp = pstring;
+
+	while (tp > tmp)
+		*sp++ = *--tp;
+	*sp = 0;
+	return pstring;
+}
+
 #endif

+ 1 - 2
Module/mod_counterconnector/CMakeLists.txt

@@ -7,8 +7,6 @@ set(${MODULE_PREFIX}_SRCS
 	ConnectorFSM.cpp
 	mod_counterconnector.h
 	mod_counterconnector.cpp
-	strutil.h
-	strutil.cpp
 	callroute_nodelist.h
 	callroute_nodelist.cpp
 	http_callrouter.h
@@ -19,6 +17,7 @@ set(MOD_VERSION_STRING "0.0.1-dev1")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 
 target_include_directories(${MODULE_NAME} PRIVATE
+	${RVC_TOOLKIT_INCLUDE_DIR}
 	${MODULE_BASE_DIR}/mod_assistantchannel
 	${MODULE_BASE_DIR}/mod_sipphone
 	${MODULE_BASE_DIR}/mod_mediacontroller

+ 5 - 64
Module/mod_counterconnector/ConnectorFSM.cpp

@@ -2,6 +2,9 @@
 #include "ConnectorFSM.h"
 #include "EventCode.h"
 #include "json/json.h"
+#include "strutil.h"
+#include <winpr/crt.h>
+#include <winpr/string.h>
 
 #define RELEASEING_TIMER_INTERVAL	1200
 #define RELEASEING_SIP_TIMER		20000
@@ -391,22 +394,12 @@ static int CStringSplit(char* str, char** result, size_t ucount, const char* del
 {
 	char* ptr = NULL;
 	size_t unum = ucount;
-	//TODO: CrossPlaform  [Gifur@2025730]
-#if defined(RVC_OS_WIN)
 	char* p = strtok_s(str, del, &ptr);
 	while (p != NULL && unum > 0) {
 		*result++ = p;
 		p = strtok_s(NULL, del, &ptr);
 		unum--;
 	}
-#else
-	char* p = strtok_r(str, del, &ptr);
-	while (p != NULL && unum > 0) {
-		*result++ = p;
-		p = strtok_r(NULL, del, &ptr);
-		unum--;
-	}
-#endif //RVC_OS_WIN
 	return ucount - unum;
 }
 
@@ -433,58 +426,6 @@ static int GetCallInfoFromConfig(char* strcallurl, uint32_t ucalllen, char* stra
 	return iRet;
 }
 
-/*无符号长整形转字符型*/
-#if defined(RVC_OS_LINUX)
-namespace
-{
-	//TODO: CrossPlaform  [Gifur@2025730]
-	char* _ultoa(unsigned long value, char* pstring, int radix)
-	{
-		char tmp[33] = { 0 };
-		char* tp = tmp;
-		long i;
-		unsigned long v = value;
-		char* sp;
-
-		if (radix > 36 || radix <= 1 || NULL == pstring) {
-			return 0;
-		}
-
-		while (v || tp == tmp) {
-			i = v % radix;
-			v = v / radix;
-			if (i < 10)
-				*tp++ = i + '0';
-			else
-				*tp++ = i + 'a' - 10;
-		}
-
-		sp = pstring;
-
-		while (tp > tmp)
-			*sp++ = *--tp;
-		*sp = 0;
-		return pstring;
-	}
-}
-#endif //RVC_OS_LINUX
-
-static int get_interger_netaddr(char *strbuf, size_t ubufszie, const char* szip)
-{
-	int ret = -1;
-
-	unsigned long ulip = 0;
-	if (NULL == strbuf || NULL == szip){
-		return ret;
-	}
-
-	ulip = inet_addr(szip);
-	_ultoa(ulip, strbuf, 10);
-
-	ret = 0;
-	return ret;
-}
-
 int ACMCallFSM::ParseDefaultServer(const char* strServer)
 {
 	int iRet = 0;
@@ -877,7 +818,7 @@ void ACMCallFSM::s11_on_entry()
 		callurl_node_t *node = get_no_used_node(m_pCallRouteList);
 
 		char callid_str[64] = { 0 };
-		get_format_uuid(callid_str, 64);
+		str_get_format_uuid(callid_str, 64);
 
 		if (node != NULL){
 			m_LastSipError = MakeCall(node->strcallurl, CSimpleStringA::Format("sip:%s@%s;transport=UDP", node->strnewcallernum, ipstr), 
@@ -899,7 +840,7 @@ void ACMCallFSM::s11_on_entry()
 				snprintf(strserver, MAX_PATH, "%s", m_voipserver[index].c_str());
 				if (0 == GetCallInfoFromConfig(strcallurl, MAX_PATH, strassistip, 32, &iport, strserver)){
 					char strassitinter[32] = {0};
-					get_interger_netaddr(strassitinter, 32, strassistip);
+					str_get_interger_netaddr(strassitinter, 32, strassistip);
 					m_LastSipError = MakeCall(strcallurl, CSimpleStringA::Format("sip:%s#%s@%s;transport=UDP", m_strTerminalId.GetData(), strassitinter, ipstr), 
 						callid_str, m_CallingParam);
 					m_iChanProxyPort[0] = iport;

+ 0 - 23
Module/mod_counterconnector/ConnectorFSM.h

@@ -482,29 +482,6 @@ private:
 	int TranslateState(int innerState);
 	ErrorCodeEnum SetCallState(int state);
 
-	//TODO: CrossPlaform  [Gifur@2025730]
-	void get_format_uuid(char* strbuffer, size_t ulen)
-	{
-#ifdef RVC_OS_WIN
-		UUID uuid;
-		size_t uuidlen = 0;
-		RPC_CSTR buf;
-		UuidCreate((UUID*)&uuid);
-		UuidToString((UUID*)&uuid, &buf);
-
-		uuidlen = strlen((const char*)buf);
-		if (uuidlen < ulen) {
-			memcpy(strbuffer, (const char*)buf, uuidlen);
-		}
-
-		RpcStringFree(&buf);
-#else
-		uuid_t uuid;
-		uuid_generate(uuid);
-		uuid_unparse(uuid, strbuffer);
-#endif
-	}
-
 	//TODO: CrossPlaform IP [Gifur@2025729]
 	ErrorCodeEnum GetLocalIP(char *buff, size_t ulen)
 	{

+ 1 - 1
Module/mod_counterconnector/callroute_nodelist.cpp

@@ -53,7 +53,7 @@ int add_node_to_list(node_list_head_t* plist, const char* newcallernum, const ch
 		int uport = atoi(pstrport);
 
 		memset(psipurl, 0, ulen+1);
-		fifter_string(psipurl, ulen+1, pcallurl, '\'');
+		str_fifter_string(psipurl, ulen+1, pcallurl, '\'');
 
 		ulen = strlen(pstrassistip);
 		pstrip = (char*)malloc(ulen+1);

+ 1 - 1
Module/mod_counterconnector/http_callrouter.cpp

@@ -45,7 +45,7 @@ static int get_http_callnodeinfo(node_info_t* pnode, const char* pcaller_num, co
 		snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s%s@%s", "sip:", "8", paccess_num, strvoiceip);
 	}
 	//new new_caller_id_number=callernum#assist_int_ip
-	get_interger_netaddr(strinterip, RVC_DATALEN, pnode->strassistip);
+	str_get_interger_netaddr(strinterip, RVC_DATALEN, pnode->strassistip);
 	snprintf(pnode->strcallernum, RVC_DATALEN, "%s%s%s", pcaller_num, "#", strinterip);
 
 	iret = 0;

+ 0 - 150
Module/mod_counterconnector/strutil.cpp

@@ -1,150 +0,0 @@
-#include "stdafx.h"
-#include "strutil.h"
-
-int reset_buffer(void* pbuf, int idata, size_t ulen)
-{
-	int ret = -1;
-	if (pbuf){
-		memset(pbuf, idata, ulen);
-		ret = 0;
-	}
-
-	return ret;
-}
-
-
-int rend_string(char* pSrc, int iflag)
-{
-	int ret = -1;
-	if (pSrc){
-		char* pindex = pSrc;
-		while(*pindex != iflag){
-			pindex++;
-		};
-		*pindex = '\0';
-		ret = 0;
-	}
-
-	return ret;
-}
-
-int fifter_string(char*pbuf, size_t usize, const char* psrc, const char cflag)
-{
-	int ret = -1;
-	int i = 0;
-	int j = 0;
-	size_t ulen = 0;
-	const char* pindex = psrc;
-	if (NULL == psrc){
-		return ret;
-	}
-
-	ulen = strlen(psrc);
-	for (i=0; i<ulen && i<usize; i++){
-		if (pindex[i] != cflag){
-			pbuf[j++] = pindex[i];
-		}
-	}
-	if (j == ulen - 2){
-		ret = 0;
-	}
-
-	return ret;
-}
-//TODO: CrossPlaform  [Gifur@2025730]
-#if defined(_MSC_VER)
-#else
-/*无符号长整形转字符型*/
-char* _ultoa(unsigned long value, char* pstring, int radix)
-{
-	char tmp[33] = { 0 };
-	char* tp = tmp;
-	long i;
-	unsigned long v = value;
-	char* sp;
-
-	if (radix > 36 || radix <= 1 || NULL == pstring) {
-		return 0;
-	}
-
-
-	while (v || tp == tmp) {
-		i = v % radix;
-		v = v / radix;
-		if (i < 10)
-			*tp++ = i + '0';
-		else
-			*tp++ = i + 'a' - 10;
-	}
-
-	sp = pstring;
-
-	while (tp > tmp)
-		*sp++ = *--tp;
-	*sp = 0;
-	return pstring;
-}
-
-#endif //_MSC_VER
-
-int get_interger_netaddr(char *strbuf, size_t ubufszie, const char* szip)
-{
-	int ret = -1;
-
-	unsigned long ulip = 0;
-	if (NULL == strbuf || NULL == szip){
-		return ret;
-	}
-
-	ulip = inet_addr(szip);
-	_ultoa(ulip, strbuf, 10);
-
-	ret = 0;
-	return ret;
-}
-
-int convert_interaddr_strip(char *strbuf, size_t ubufszie, const char* szinter_ip)
-{
-	int ret = -1;
-	char* strip = NULL;
-	struct sockaddr_in addr = {0};
-	if (!szinter_ip || !strbuf){
-		return ret;
-	}
-
-	addr.sin_addr.s_addr = strtoul(szinter_ip, NULL, 10);//inet_addr(config->switch_server);
-	strip = inet_ntoa(addr.sin_addr);
-	if (strip){
-		size_t ulen = strlen(strip);
-		if (ulen < ubufszie){
-			memcpy(strbuf, strip, ulen);
-			ret = 0;
-		}
-	}
-
-	return ret;
-}
-
-
-int connect_strings(char* strbuf, size_t ulen, const char* psrca, const char* pstr, const char* psrcb)
-{
-	int ret = -1;
-	size_t ulena = 0;
-	size_t ulenb = 0;
-	size_t ulenstr = 0;
-
-	if(!psrca || !psrcb || !pstr){
-		return ret;
-	}
-
-	ulena = strlen(psrca);
-	ulenb = strlen(psrcb);
-	ulenstr = strlen(pstr);
-
-	if (ulen > ulena + ulenb + ulenstr){
-		snprintf(strbuf, ulen, "%s%s%s", psrca, pstr, psrcb);
-		ret = 0;
-	}
-
-	return ret;
-}

+ 0 - 18
Module/mod_counterconnector/strutil.h

@@ -1,18 +0,0 @@
-#ifndef _STR_UTIL_
-#define _STR_UTIL_
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-#define proxy_copy(pDst, pSrc)		if(pSrc)	{	memcpy(pDst, pSrc, strlen(pSrc));	}
-
-int reset_buffer(void* pbuf, int idata, size_t ulen);
-int rend_string(char* pSrc, int iflag);
-int fifter_string(char*pbuf, size_t usize, const char* psrc, const char cflag);
-int get_interger_netaddr(char *strbuf, size_t ubufszie, const char* szip);
-int convert_interaddr_strip(char *strbuf, size_t ubufszie, const char* szinter_ip);
-int connect_strings(char* strbuf, size_t ulen, const char* psrca, const char* psrcb, const char* pstr);
-
-#endif

+ 2 - 4
Module/mod_guiconsole/guiconsole_define.cpp

@@ -386,8 +386,7 @@ static const std::unordered_map<LogTypeEnum, std::string> logTypeEnumToString =
 	{LogTypeEnum::Log_Warning, "Warning"},
 	{LogTypeEnum::Log_Error, "Error"},
 	{LogTypeEnum::Log_Debug, "Debug"},
-	{LogTypeEnum::Log_Fatal, "Fatal"},
-	{LogTypeEnum::Log_Notify, "Notify"}
+	{LogTypeEnum::Log_Fatal, "Fatal"}
 };
 
 static const std::unordered_map<std::string, LogTypeEnum> stringToLogTypeEnum = {
@@ -396,8 +395,7 @@ static const std::unordered_map<std::string, LogTypeEnum> stringToLogTypeEnum =
 	{"Warning", LogTypeEnum::Log_Warning},
 	{"Error", LogTypeEnum::Log_Error},
 	{"Debug", LogTypeEnum::Log_Debug},
-	{"Fatal", LogTypeEnum::Log_Fatal},
-	{"Notify", LogTypeEnum::Log_Notify}
+	{"Fatal", LogTypeEnum::Log_Fatal}
 };
 
 std::string LogTypeEnumToString(LogTypeEnum logType) {