/*********************************************************************
Rhapsody in C : 3.0
Login : daicj
Component : SipProxy
Configuration : ShiHao
Model Element : pkgSIPParser
! Generated Date : Mon, 7, Apr 2003
File Path : SipProxy\ShiHao\pkgSIPParser.c
*********************************************************************/
#ifdef __linux__/*jinshuangxi for linux compile*/
#include <netinet/in.h>
#include <inetlib.h>
#include <errnolib.h>
#endif
#include "p_sip_sipparser.h"
#include "p_sip_util.h"
#include "p_sip_sdpparser.h"
#include "p_sip_macro.h"
#include <assert.h>
#define ERROR_SDPIsTooLong (BYTE)1
#define P_SIP_MSG_LTH (WORD)4096
/*## package pkgP::pkgPSIP::pkgSIPParser */
/*----------------------------------------------------------------------------*/
/* pkgSIPParser.c */
/*----------------------------------------------------------------------------*/
extern void debug_printf( char *pformat, ... );
/* extern DWORD sip_strlcpy( BYTE * dst, BYTE * src, DWORD siz ); */ /* Deletd by sr on 2008-12-01 for pclint */
DWORD g_dwSimB2B = 0;
DWORD g_dwMalFromCheck = 0;
DWORD dwTimeStart;
DWORD dwTimeStop;
DWORD g_dwMemsetSize = 0;
void P_SIP_Memset( void *p, BYTE b, DWORD dwSize )
{
g_dwMemsetSize += dwSize;
memset( p, b, dwSize );
}
DWORD g_dwStrncpySize = 0;
void P_P_SIP_Strncpy( BYTE * dst, BYTE * src, DWORD dwSize )
{
g_dwStrncpySize += dwSize;
P_SIP_strncpy( dst, src, dwSize );
}
/* begin */
void ConvertEscapedToChar( BYTE * pbData, BYTE * pbValue );
BOOL8 Convert2Unescape( BYTE * pbMessage, WORD wMaxLth );
void ConvertCharToEscaped( BYTE * pbData, BYTE bValue );
BOOL8 UrlHeaderConvert2Escape( BYTE * pbMessage, WORD wMaxLth );
BOOL8 UrlPasswordConvert2Escape( BYTE * pbMessage, BYTE bMaxLth );
BOOL8 UrlParamConvert2Escape( BYTE * pbMessage, WORD wMaxLth );
BOOL8 Convert2Unescape( BYTE * pbMessage, WORD wMaxLth )
{
/*#[ operation Convert2Unescape(BYTE*,WORD) */
BYTE bLocation;
BYTE bCount;
BYTE bString[512];
bLocation = 0;
bCount = 0;
while ( ( bLocation < wMaxLth ) && ( pbMessage[bLocation] != 0 ) && ( bCount < wMaxLth - 1 ) )
{
if ( SIP_isEscaped( &pbMessage[bLocation] ) )
{
ConvertEscapedToChar( pbMessage + bLocation, &bString[bCount] );
bLocation += 3;
bCount++;
}
else
{
bString[bCount++] = pbMessage[bLocation++];
}
}
if ( pbMessage[bLocation] == 0 )
{
bString[bCount] = 0;
P_P_SIP_Strncpy( pbMessage, bString, wMaxLth );
return TRUE_B8;
}
else
{
return FALSE_B8;
}
/*#] */
}
void ConvertCharToEscaped( BYTE * pbData, BYTE bValue )
{
/*#[ operation ConvertCharToEscaped(BYTE*,BYTE) */
BYTE bChar;
BYTE wTemp1 = ( bValue & 0xF0 ) >> 4;
BYTE wTemp2 = bValue & 0x0F;
*pbData = '%';
SIP_CharToHex( wTemp1, bChar );
*( pbData + 1 ) = bChar;
SIP_CharToHex( wTemp2, bChar );
*( pbData + 2 ) = bChar;
/*#] */
}
void ConvertEscapedToChar( BYTE * pbData, BYTE * pbValue )
{
/*#[ operation ConvertEscapedToChar(BYTE*,BYTE*) */
BYTE bTemp1 = *( pbData + 1 );
BYTE bTemp2 = *( pbData + 2 );
SIP_convertHexToChar( bTemp1 );
SIP_convertHexToChar( bTemp2 );
*pbValue = (BYTE)(( bTemp1 << 4 ) | ( bTemp2 ));/* CRDCR00424670 zhaosr pclint 08-12-30 */
/*#] */
}
/*CRDCM00149983,modified by shihongsheng,09-05-31*/
BOOL8 UrlUserConvert2Escape( BYTE * pbMessage, WORD wMaxLth )
{
/*#[ operation UrlUserConvert2Escape(BYTE*,BYTE) */
DWORD dwLocation;
DWORD dwCount;
BYTE bString[512];
dwLocation = 0;
dwCount = 0;
while ( ( pbMessage[dwLocation] != 0 ) && ( dwLocation < wMaxLth ) )
{
if ( SIP_isUrlUser( pbMessage[dwLocation] ) )
{
bString[dwCount++] = pbMessage[dwLocation++];
}
else
{
ConvertCharToEscaped( bString + dwCount, pbMessage[dwLocation] );
dwLocation++;
dwCount += 3;
}
}
if ( pbMessage[dwLocation] == 0 )
{
bString[dwCount] = 0;
P_P_SIP_Strncpy( pbMessage, bString, wMaxLth );
return TRUE_B8;
}
else
{
return FALSE_B8;
}
/*#] */
}
/*CRDCM00149983,modified by shihongsheng,09-05-31*/
BOOL8 UrlHeaderConvert2Escape( BYTE * pbMessage, WORD wMaxLth )
{
/*#[ operation UrlHeaderConvert2Escape(BYTE*,BYTE) */
DWORD dwLocation;
DWORD dwCount;
BYTE bString[512];
dwLocation = 0;
dwCount = 0;
while ( ( pbMessage[dwLocation] != 0 ) && ( dwLocation < wMaxLth ) )
{
if ( SIP_isUrlHeader( pbMessage[dwLocation] ) )
{
bString[dwCount++] = pbMessage[dwLocation++];
}
else
{
ConvertCharToEscaped( bString + dwCount, pbMessage[dwLocation] );
dwLocation++;
dwCount += 3;
}
}
if ( pbMessage[dwLocation] == 0 )
{
bString[dwCount] = 0;
P_P_SIP_Strncpy( pbMessage, bString, wMaxLth );
return TRUE_B8;
}
else
{
return FALSE_B8;
}
/*#] */
}
BOOL8 SIP_UrlConvert2Escape( URL * ptUrl )
{
/*#[ operation SIP_UrlConvert2Escape(URL*) */
BYTE bCount;
if ( ptUrl == NULL )
{
return FALSE_B8;
}
if ( ptUrl->bMap[URL_USER_MAP] )
{
UrlUserConvert2Escape( ptUrl->bUser, USER_LTH );
}
if ( ptUrl->bMap[URL_PASSWD_MAP] )
{
UrlPasswordConvert2Escape( ptUrl->bPassword, PASSWORD_LTH );
}
bCount = 0;
while ( bCount < ptUrl->bMap[URL_HEADER_MAP_MAP] )
{
if ( ptUrl->tHeader[bCount].bMap[URL_HEADER_HNAME_MAP] )
{
UrlHeaderConvert2Escape( ptUrl->tHeader[bCount].bHName, HEADER_NAME_LTH );
}
if ( ptUrl->tHeader[bCount].bMap[URL_HEADER_HVALUE_MAP] )
{
UrlHeaderConvert2Escape( ptUrl->tHeader[bCount].bHValue, HEADER_VALUE_LTH );
}
bCount++;
}
bCount = 0;
while ( bCount < ptUrl->bMap[URL_PARAM_MAP] )
{
if ( ptUrl->tParam[bCount].bMap[GENERIC_PARAM_NAME_MAP] )
{
UrlParamConvert2Escape( ptUrl->tParam[bCount].bName, GEN_NAME_LTH );
}
if ( ptUrl->tParam[bCount].bMap[GENERIC_PARAM_VALUE_MAP] )
{
UrlParamConvert2Escape( ptUrl->tParam[bCount].bValue, GEN_NAME_LTH );
}
bCount++;
}
return TRUE_B8;
/*#] */
}
BOOL8 SIP_TelUrlConvert2Escape( TEL_URL * ptTelUrl )
{
/*#[ operation SIP_UrlConvert2Escape(URL*) */
BYTE bCount;
if ( ptTelUrl == NULL )
{
return FALSE_B8;
}
bCount = 0;
while ( bCount < ptTelUrl->bMap[TELURL_HEADER_MAP] )
{
if ( ptTelUrl->tHeader[bCount].bMap[URL_HEADER_HNAME_MAP] )
{
UrlHeaderConvert2Escape( ptTelUrl->tHeader[bCount].bHName, HEADER_NAME_LTH );
}
if ( ptTelUrl->tHeader[bCount].bMap[URL_HEADER_HVALUE_MAP] )
{