Skip to content

Commit bc8d383

Browse files
committed
SIP 서버에서 신규 SIP INVITE 를 기존의 SIP INVITE 로 인식하지 않도록 branch 와 Call-ID 를 수정하는 기능을 추가함
1 parent a8634aa commit bc8d383

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

Utility/SipLogAnalysis/SipLogSender/CallMap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void CCallMap::Insert( std::string & strCallId, CSipMessage & clsMessage )
2727
CCallInfo clsCallInfo;
2828

2929
clsMessage.m_clsCallId.ToString( clsCallInfo.m_strRecvCallId );
30+
3031
itVia = clsMessage.m_clsViaList.begin();
3132
if( itVia != clsMessage.m_clsViaList.end() )
3233
{
@@ -42,6 +43,10 @@ void CCallMap::Insert( std::string & strCallId, CSipMessage & clsMessage )
4243
{
4344
m_clsMap.insert( CALL_MAP::value_type( strCallId, clsCallInfo ) );
4445
}
46+
else
47+
{
48+
itMap->second = clsCallInfo;
49+
}
4550
}
4651

4752
bool CCallMap::Select( std::string & strCallId, CCallInfo & clsCallInfo )

Utility/SipLogAnalysis/SipLogSender/ReadLogFile.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
*/
1818

1919
#include "SipLogSender.h"
20+
#include "TimeString.h"
2021
#include "CallMap.h"
2122

23+
#define PRINT_LOG_LEN 100
24+
2225
void ReadLogFile( const char * pszFileName )
2326
{
2427
FILE * fd = fopen( pszFileName, "r" );
@@ -48,6 +51,8 @@ void ReadLogFile( const char * pszFileName )
4851
CSipMessage clsMessage;
4952
std::string strCallId;
5053

54+
clsMessage.Clear();
55+
5156
if( clsMessage.Parse( strSipMessage.c_str(), strSipMessage.length() ) <= 0 )
5257
{
5358
printf( "line(%d) clsMessage.Parse(%s) error\n", iLine, strSipMessage.c_str() );
@@ -59,9 +64,36 @@ void ReadLogFile( const char * pszFileName )
5964

6065
if( bSend == false )
6166
{
67+
// bSend = false 이면 SIP 서비스로 전송한다.
6268
CCallInfo clsCallInfo;
6369

64-
gclsCallMap.Select( strCallId, clsCallInfo );
70+
if( gclsCallMap.Select( strCallId, clsCallInfo ) == false )
71+
{
72+
// SIP 서버로 이미 전송한 후, 2번째 전송하면 transaction 때문에 응용으로 전달되지 않으므로 branch 를 수정한다.
73+
SIP_VIA_LIST::iterator itVia = clsMessage.m_clsViaList.begin();
74+
if( itVia != clsMessage.m_clsViaList.end() )
75+
{
76+
const char * pszBranch = itVia->SelectParamValue( "branch" );
77+
if( pszBranch )
78+
{
79+
char szTime[21];
80+
81+
GetDateTimeString( szTime, sizeof(szTime) );
82+
83+
std::string strBranch = pszBranch;
84+
strBranch.append( szTime );
85+
86+
strCallId.append( szTime );
87+
88+
clsMessage.m_clsCallId.Parse( strCallId.c_str(), strCallId.length() );
89+
90+
itVia->UpdateParam( "branch", strBranch.c_str() );
91+
92+
gclsCallMap.Insert( strCallId, clsMessage );
93+
gclsCallMap.Select( strCallId, clsCallInfo );
94+
}
95+
}
96+
}
6597

6698
if( clsCallInfo.m_strRecvCallId.empty() == false )
6799
{
@@ -73,6 +105,7 @@ void ReadLogFile( const char * pszFileName )
73105
{
74106
itVia->m_strHost = "127.0.0.1";
75107
itVia->m_iPort = giUdpPort;
108+
itVia->m_strTransport = "UDP";
76109

77110
if( clsCallInfo.m_strBranch.empty() == false )
78111
{
@@ -94,9 +127,14 @@ void ReadLogFile( const char * pszFileName )
94127
printf( "line(%d) UdpSend(%s) error\n", iLine, szBuf );
95128
break;
96129
}
130+
131+
printf( "line(%d) UdpSend(%.*s)\n", iLine, PRINT_LOG_LEN, szBuf );
97132
}
98133
else
99134
{
135+
// bSend = true 이면 SIP 서비스에서 수신할 때까지 대기한다.
136+
printf( "line(%d) UdpRecv(%.*s) standby\n", iLine, PRINT_LOG_LEN, strSipMessage.c_str() );
137+
100138
while( 1 )
101139
{
102140
iBufSize = sizeof(szBuf);
@@ -106,6 +144,10 @@ void ReadLogFile( const char * pszFileName )
106144
break;
107145
}
108146

147+
printf( "line(%d) UdpRecv(%.*s)\n", iLine, PRINT_LOG_LEN, szBuf );
148+
149+
clsMessage.Clear();
150+
109151
if( clsMessage.Parse( szBuf, iBufSize ) <= 0 )
110152
{
111153
printf( "line(%d) recv clsMessage.Parse(%s) error\n", iLine, strSipMessage.c_str() );
@@ -129,8 +171,6 @@ void ReadLogFile( const char * pszFileName )
129171
}
130172
}
131173

132-
// bSend = false 이면 SIP 서비스로 전송한다.
133-
// bSend = true 이면 SIP 서비스에서 수신할 때까지 대기한다.
134174
strSipMessage.clear();
135175
}
136176
else
@@ -148,6 +188,10 @@ void ReadLogFile( const char * pszFileName )
148188
else
149189
{
150190
pszPos = strstr( szBuf, "UdpSend" );
191+
if( pszPos == NULL )
192+
{
193+
pszPos = strstr( szBuf, "TcpSend" );
194+
}
151195

152196
if( pszPos )
153197
{
@@ -157,6 +201,10 @@ void ReadLogFile( const char * pszFileName )
157201
{
158202
bSend = false;
159203
pszPos = strstr( szBuf, "UdpRecv" );
204+
if( pszPos == NULL )
205+
{
206+
pszPos = strstr( szBuf, "TcpRecv" );
207+
}
160208
}
161209

162210
if( pszPos )
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SipLogSender
2+
3+
### 개요
4+
5+
* SIP 서버에서 저장한 로그 파일을 읽어서 로그 파일에 저장된 SIP 메시지를 SIP 서버로 전송하는 프로그램
6+
7+
### 개발자 정보
8+
9+
* 이메일 : websearch@naver.com
10+
* 블로그 : http://blog.naver.com/websearch
11+
12+
###
13+
14+
* 사용법
15+
16+
'''
17+
SipLogSender.exe {listen udp port} {sip server udp port} {log filepath}
18+
'''
19+
20+
### 라이선스
21+
22+
* 본 프로젝트의 라이선스는 GPLv3 이고 기업용 라이선스는 websearch@naver.com 으로 문의해 주세요.

0 commit comments

Comments
 (0)