1717 */
1818
1919#include " SipLogSender.h"
20+ #include " TimeString.h"
2021#include " CallMap.h"
2122
23+ #define PRINT_LOG_LEN 100
24+
2225void 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 )
0 commit comments