-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSipClient.cpp
More file actions
176 lines (152 loc) · 5.63 KB
/
SipClient.cpp
File metadata and controls
176 lines (152 loc) · 5.63 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
/*
* 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 <time.h>
#include "Log.h"
#include "RtpThread.h"
#include "MemoryDebug.h"
std::string gstrInviteId;
/**
* @ingroup SipClient
* @brief SIP REGISTER 응답 메시지 수신 이벤트 핸들러
* @param pclsInfo SIP REGISTER 응답 메시지를 전송한 IP-PBX 정보 저장 객체
* @param iStatus SIP REGISTER 응답 코드
*/
void CSipClient::EventRegister( CSipServerInfo * pclsInfo, int iStatus )
{
CLog::Print( LOG_DEBUG, "%s(%d)", __FUNCTION__, iStatus );
printf( "EventRegister(%s) : %d\n", pclsInfo->m_strUserId.c_str(), iStatus );
}
/**
* @ingroup SipClient
* @brief SIP 통화 요청 수신 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param pszFrom SIP From 사용자 아이디
* @param pszTo SIP To 사용자 아이디
* @param pclsRtp RTP 정보 저장 객체
*/
void CSipClient::EventIncomingCall( const char * pszCallId, const char * pszFrom, const char * pszTo, CSipCallRtp * pclsRtp )
{
printf( "EventIncomingCall(%s,%s)\n", pszCallId, pszFrom );
gstrInviteId = pszCallId;
if( pclsRtp )
{
printf( "=> RTP(%s:%d) codec(%d)\n", pclsRtp->m_strIp.c_str(), pclsRtp->m_iPort, pclsRtp->m_iCodec );
m_clsDestRtp = *pclsRtp;
}
}
/**
* @ingroup SipClient
* @brief SIP Ring / Session Progress 수신 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param iSipStatus SIP 응답 코드
* @param pclsRtp RTP 정보 저장 객체
*/
void CSipClient::EventCallRing( const char * pszCallId, int iSipStatus, CSipCallRtp * pclsRtp )
{
printf( "EventCallRing(%s,%d)\n", pszCallId, iSipStatus );
if( pclsRtp )
{
printf( "=> RTP(%s:%d) codec(%d)\n", pclsRtp->m_strIp.c_str(), pclsRtp->m_iPort, pclsRtp->m_iCodec );
}
}
/**
* @ingroup SipClient
* @brief SIP 통화 연결 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param pclsRtp RTP 정보 저장 객체
*/
void CSipClient::EventCallStart( const char * pszCallId, CSipCallRtp * pclsRtp )
{
printf( "EventCallStart(%s)\n", pszCallId );
if( pclsRtp )
{
printf( "=> RTP(%s:%d) codec(%d)\n", pclsRtp->m_strIp.c_str(), pclsRtp->m_iPort, pclsRtp->m_iCodec );
gclsRtpThread.Start( pclsRtp->m_strIp.c_str(), pclsRtp->m_iPort );
}
}
/**
* @ingroup SipClient
* @brief SIP 통화 종료 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param iSipStatus SIP 응답 코드. INVITE 에 대한 오류 응답으로 전화가 종료된 경우, INVITE 의 응답 코드를 저장한다.
*/
void CSipClient::EventCallEnd( const char * pszCallId, int iSipStatus )
{
printf( "EventCallEnd(%s,%d)\n", pszCallId, iSipStatus );
gclsRtpThread.Stop( );
}
/**
* @ingroup SipClient
* @brief SIP ReINVITE 수신 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param pclsRemoteRtp 상대방 RTP 정보 저장 객체
* @param pclsLocalRtp 내 RTP 정보 저장 객체
*/
void CSipClient::EventReInvite( const char * pszCallId, CSipCallRtp * pclsRemoteRtp, CSipCallRtp * pclsLocalRtp )
{
printf( "EventReInvite(%s)\n", pszCallId );
if( pclsRemoteRtp )
{
printf( "=> RTP(%s:%d) codec(%d)\n", pclsRemoteRtp->m_strIp.c_str(), pclsRemoteRtp->m_iPort, pclsRemoteRtp->m_iCodec );
gclsRtpThread.Start( pclsRemoteRtp->m_strIp.c_str(), pclsRemoteRtp->m_iPort );
}
}
/**
* @ingroup SipClient
* @brief Screened / Unscreened Transfer 요청 수신 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param pszReferToCallId 전화가 전달될 SIP Call-ID
* @param bScreenedTransfer Screened Transfer 이면 true 가 입력되고 Unscreened Transfer 이면 false 가 입력된다.
* @returns 요청을 수락하면 true 를 리턴하고 그렇지 않으면 false 를 리턴한다.
*/
bool CSipClient::EventTransfer( const char * pszCallId, const char * pszReferToCallId, bool bScreenedTransfer )
{
printf( "EventTransfer(%s,%s)\n", pszCallId, pszReferToCallId );
return false;
}
/**
* @ingroup SipClient
* @brief Blind Transfer 요청 수신 이벤트 핸들러
* @param pszCallId SIP Call-ID
* @param pszReferToId 전화가 전달될 사용자 아이디
* @returns 요청을 수락하면 true 를 리턴하고 그렇지 않으면 false 를 리턴한다.
*/
bool CSipClient::EventBlindTransfer( const char * pszCallId, const char * pszReferToId )
{
printf( "EventBlindTransfer(%s,%s)\n", pszCallId, pszReferToId );
return false;
}
/**
* @ingroup SipClient
* @brief SIP MESSAGE 수신 이벤트 핸들러
* @param pszFrom SIP 메시지 전송 아이디
* @param pszTo SIP 메시지 수신 아이디
* @param pclsMessage SIP 메시지
* @returns 요청을 수락하면 true 를 리턴하고 그렇지 않으면 false 를 리턴한다.
*/
bool CSipClient::EventMessage( const char * pszFrom, const char * pszTo, CSipMessage * pclsMessage )
{
char szContentType[255];
memset( szContentType, 0, sizeof(szContentType) );
pclsMessage->m_clsContentType.ToString( szContentType, sizeof(szContentType) );
printf( "EventMessage(%s,%s)\n", pszFrom, pszTo );
printf( "content-type[%s]\n", szContentType );
printf( "body[%s]\n", pclsMessage->m_strBody.c_str() );
return true;
}