forked from YeeYoungHan/cppsipstack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSipClientMain.cpp
More file actions
198 lines (165 loc) · 5.16 KB
/
Copy pathSipClientMain.cpp
File metadata and controls
198 lines (165 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (C) 2012 Yee Young Han <websearch@naver.com> (http://blog.naver.com/websearch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SipClient.h"
#include "Log.h"
#include "MemoryDebug.h"
extern std::string gstrInviteId;
/**
* @ingroup SipClient
* @brief
* @param argc
* @param argv
* @returns
*/
int main( int argc, char * argv[] )
{
if( argc < 4 )
{
printf( "[Usage] %s {sip server ip} {user id} {password} {local port} {tcp}\n", argv[0] );
return 0;
}
char * pszServerIp = argv[1];
char * pszUserId = argv[2];
char * pszPassWord = argv[3];
int iLocalPort = 10000;
ESipTransport eTransport = E_SIP_UDP;
int iServerPort = SIP_UDP_PORT;
if( argc >= 5 )
{
iLocalPort = atoi( argv[4] );
}
if( argc >= 6 )
{
if( !strcasecmp( argv[5], "tcp" ) )
{
eTransport = E_SIP_TCP;
}
else if( !strcasecmp( argv[5], "tls" ) )
{
#ifndef USE_TLS
printf( "TLS function is not supported. please compile with USE_TLS define\n" );
return 0;
#endif
eTransport = E_SIP_TLS;
iServerPort = SIP_TLS_PORT;
}
}
#ifdef WIN32
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );
CLog::SetDirectory( "c:\\temp\\sipclient" );
CLog::SetLevel( LOG_NETWORK | LOG_DEBUG | LOG_INFO );
#endif
CSipUserAgent clsUserAgent;
CSipServerInfo clsServerInfo;
CSipStackSetup clsSetup;
CSipClient clsSipClient;
clsServerInfo.m_strIp = pszServerIp;
clsServerInfo.m_strUserId = pszUserId;
clsServerInfo.m_strPassWord = pszPassWord;
clsServerInfo.m_eTransport = eTransport;
clsServerInfo.m_iPort = iServerPort;
//clsServerInfo.m_iNatTimeout = 10;
// N개의 IP주소를 사용하는 호스트에서는 SIP 프로토콜로 사용할 IP주소를 직접 입력해 주세요.
// Vmware 등을 사용하는 경우 N개의 IP주소가 호스트에 존재합니다.
GetLocalIp( clsSetup.m_strLocalIp );
// 클라이언트가 SIP 통신에 사용할 포트 번호를 넣어 주세요.
clsSetup.m_iLocalUdpPort = iLocalPort;
if( eTransport == E_SIP_TCP )
{
clsSetup.m_iLocalTcpPort = iLocalPort;
clsSetup.m_iTcpCallBackThreadCount = 2;
}
else if( eTransport == E_SIP_TLS )
{
clsSetup.m_iLocalTlsPort = iLocalPort;
clsSetup.m_strCertFile = "C:\\OpenProject\\CppSipStack\\trunk\\SipClient\\SipServer.pem";
}
// UDP 수신 쓰레드의 기본 개수는 1개이다. 이를 수정하려면 CSipStackSetup.m_iUdpThreadCount 를 수정하면 된다.
clsUserAgent.InsertRegisterInfo( clsServerInfo );
if( clsUserAgent.Start( clsSetup, &clsSipClient ) == false )
{
printf( "sip stack start error\n" );
return 0;
}
char szCommand[1024];
int iLen;
memset( szCommand, 0, sizeof(szCommand) );
while( fgets( szCommand, sizeof(szCommand), stdin ) )
{
if( szCommand[0] == 'Q' || szCommand[0] == 'q' ) break;
iLen = (int)strlen(szCommand);
if( iLen >= 2 && szCommand[iLen-2] == '\r' )
{
szCommand[iLen-2] = '\0';
}
else if( iLen >= 1 && szCommand[iLen-1] == '\n' )
{
szCommand[iLen-1] = '\0';
}
if( szCommand[0] == 'C' || szCommand[0] == 'c' )
{
CSipCallRtp clsRtp;
CSipCallRoute clsRoute;
// QQQ: RTP 수신 IP/Port/Codec 를 넣어 주세요.
clsRtp.m_strIp = clsSetup.m_strLocalIp;
clsRtp.m_iPort = 2000;
clsRtp.m_iCodec = 0;
clsRoute.m_strDestIp = pszServerIp;
clsRoute.m_iDestPort = iServerPort;
clsRoute.m_eTransport = eTransport;
clsUserAgent.StartCall( pszUserId, szCommand + 2, &clsRtp, &clsRoute, gstrInviteId );
}
else if( szCommand[0] == 'e' || szCommand[0] == 's' )
{
clsUserAgent.StopCall( gstrInviteId.c_str() );
gstrInviteId.clear();
}
else if( szCommand[0] == 'a' )
{
CSipCallRtp clsRtp;
// QQQ: RTP 수신 IP/Port/Codec 를 넣어 주세요.
clsRtp.m_strIp = clsSetup.m_strLocalIp;
clsRtp.m_iPort = 2000;
clsRtp.m_iCodec = 0;
clsUserAgent.AcceptCall( gstrInviteId.c_str(), &clsRtp );
}
else if( szCommand[0] == 'm' )
{
CSipCallRoute clsRoute;
clsRoute.m_strDestIp = pszServerIp;
clsRoute.m_iDestPort = 5060;
clsRoute.m_eTransport = eTransport;
clsUserAgent.SendSms( pszUserId, szCommand + 2, "hello", &clsRoute );
}
else if( szCommand[0] == 'i' )
{
CMonitorString strBuf;
clsUserAgent.m_clsSipStack.GetString( strBuf );
printf( "%s", strBuf.GetString() );
}
memset( szCommand, 0, sizeof(szCommand) );
}
if( gstrInviteId.empty() == false )
{
clsUserAgent.StopCall( gstrInviteId.c_str() );
}
sleep(2);
clsUserAgent.Stop();
clsUserAgent.Final();
return 0;
}