You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
1.7 KiB
C++
134 lines
1.7 KiB
C++
|
1 year ago
|
#include "GeneralModule.h"
|
||
|
|
#include <string.h>
|
||
|
|
#include <iconv.h>
|
||
|
|
|
||
|
|
extern "C" int isnumer(char cChar)
|
||
|
|
{
|
||
|
|
if ((cChar >= 0x30) && (cChar <= 0x39))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
extern "C" int isIpAddr(char * ptr)
|
||
|
|
{
|
||
|
|
size_t iLen;
|
||
|
|
iLen = strlen(ptr);
|
||
|
|
|
||
|
|
if ((iLen<MIN_IPLEN) || (iLen>MAX_IPLEN))
|
||
|
|
{
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int i = 0; i<iLen; i++)
|
||
|
|
{
|
||
|
|
if ((0 == isnumer(ptr[i])) || ('.' == ptr[i]))
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return -2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
extern "C" int isIpAddrAndPort(char * ptr)
|
||
|
|
{
|
||
|
|
int iLen;
|
||
|
|
if (!ptr)
|
||
|
|
{
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
iLen = strlen(ptr);
|
||
|
|
|
||
|
|
if ((iLen<MIN_IPPORTLEN) || (iLen>MAX_IPPORTLEN))
|
||
|
|
{
|
||
|
|
return -2;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int i = 0; i<iLen; i++)
|
||
|
|
{
|
||
|
|
if ((0 == isnumer(ptr[i])) || ('.' == ptr[i]) || (':' == ptr[i]))
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return -3;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 释放内存
|
||
|
|
void SafeDelMemory(void *pNew, BOOL isArray)
|
||
|
|
{
|
||
|
|
if (!pNew)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isArray)
|
||
|
|
{
|
||
|
|
delete[] pNew;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
delete pNew;
|
||
|
|
}
|
||
|
|
pNew = NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
extern "C" void DelHvImage(HvImage &img)
|
||
|
|
{
|
||
|
|
if (!img.pbImgData)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
delete[] img.pbImgData;
|
||
|
|
|
||
|
|
img.pbImgData = NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 编码转换
|
||
|
|
/*
|
||
|
|
int code_convert(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t outlen)
|
||
|
|
{
|
||
|
|
iconv_t cd;
|
||
|
|
int rc;
|
||
|
|
char **pin = &inbuf;
|
||
|
|
char **pout = &outbuf;
|
||
|
|
|
||
|
|
cd = iconv_open(to_charset,from_charset);
|
||
|
|
if (cd==0) return -1;
|
||
|
|
if (iconv(cd,pin,&inlen,pout,&outlen)==-1) return -1;
|
||
|
|
iconv_close(cd);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
// gbk转为utf8
|
||
|
|
/*
|
||
|
|
extern "C" string gbk2utf8(const char *inbuf)
|
||
|
|
{
|
||
|
|
int inlen=strlen(inbuf);
|
||
|
|
string strRet;
|
||
|
|
strRet.resize(inlen*2+2);
|
||
|
|
if(code_convert("gbk","utf-8",const_cast<char *>(inbuf),inlen,&strRet[0],strRet.size()))
|
||
|
|
{
|
||
|
|
return inbuf;
|
||
|
|
}
|
||
|
|
|
||
|
|
return strRet;
|
||
|
|
}
|
||
|
|
*/
|