summaryrefslogtreecommitdiffstats
path: root/bindings/_common/SipEvent.cxx
blob: cc8a8eb0c02a7ea5450c0d3a7fe364acdd3b0b2c (plain)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO 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.
*
* DOUBANGO 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 DOUBANGO.
*
*/
#include "SipEvent.h"
#include "SipSession.h"
#include "SipMessage.h"

#include "SipStack.h"


#define takeOwnership_Implement(cls, name, session) \
name##Session* cls##Event::take##session##Ownership() const \
{ \
	if(this->sipevent && this->sipevent->ss /*&& !tsip_ssession_have_ownership(this->sipevent->ss)*/){ \
		SipStack* stack = this->getStack(); \
		if(stack){ \
			/* The constructor will call take_ownerhip() */ \
			return new name##Session(stack, this->sipevent->ss); \
		} \
	} \
	return tsk_null; \
} \
 
/* ======================== SipEvent ========================*/
SipEvent::SipEvent(const tsip_event_t *_sipevent)
{
    this->sipevent = _sipevent;
    if(_sipevent) {
        this->sipmessage = new SipMessage(_sipevent->sipmessage);
    }
    else {
        this->sipmessage = tsk_null;
    }
}

SipEvent::~SipEvent()
{
    if(this->sipmessage) {
        delete this->sipmessage;
    }
}

short SipEvent::getCode() const
{
    return this->sipevent->code;
}

const char* SipEvent::getPhrase() const
{
    return this->sipevent->phrase;
}

const SipSession* SipEvent::getBaseSession() const
{
    const void* userdata = tsip_ssession_get_userdata(this->sipevent->ss);
    if(userdata) {
        return dyn_cast<const SipSession*>((const SipSession*)userdata);
    }
    return tsk_null;
}

const SipMessage* SipEvent::getSipMessage() const
{
    return this->sipmessage;
}

SipStack* SipEvent::getStack()const
{
    const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss);
    const void* userdata;
    if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) {
        return dyn_cast<SipStack*>((SipStack*)userdata);
    }
    return tsk_null;
}


/* ======================== DialogEvent ========================*/
DialogEvent::DialogEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent) { }

DialogEvent::~DialogEvent() { }


/* ======================== DialogEvent ========================*/
StackEvent::StackEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent) { }

StackEvent::~StackEvent() { }


/* ======================== InviteEvent ========================*/
InviteEvent::InviteEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

InviteEvent::~InviteEvent()
{
}

tsip_invite_event_type_t InviteEvent::getType() const
{
    return TSIP_INVITE_EVENT(this->sipevent)->type;
}

twrap_media_type_t InviteEvent::getMediaType() const
{
    // Ignore Mixed session (both audio/video and MSRP) as specified by GSMA RCS.
    if (this->sipevent && this->sipevent->ss) {
        tmedia_type_t type = tsip_ssession_get_mediatype(this->sipevent->ss);
        if ((type & tmedia_msrp) == tmedia_msrp) {
            return twrap_media_msrp;
        }
        else {
            return twrap_get_wrapped_media_type(type);
        }
    }
    return twrap_media_none;
}

const InviteSession* InviteEvent::getSession() const
{
    return dyn_cast<const InviteSession*>(this->getBaseSession());
}

takeOwnership_Implement(Invite, Call, CallSession);
takeOwnership_Implement(Invite, Msrp, MsrpSession);

/* ======================== MessagingEvent ========================*/
MessagingEvent::MessagingEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

MessagingEvent::~MessagingEvent()
{
}

tsip_message_event_type_t MessagingEvent::getType() const
{
    return TSIP_MESSAGE_EVENT(this->sipevent)->type;
}

const MessagingSession* MessagingEvent::getSession() const
{
    return dyn_cast<const MessagingSession*>(this->getBaseSession());
}

takeOwnership_Implement(Messaging, Messaging, Session);


/* ======================== InfoEvent ========================*/
InfoEvent::InfoEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

InfoEvent::~InfoEvent()
{
}

tsip_info_event_type_t InfoEvent::getType() const
{
    return TSIP_INFO_EVENT(this->sipevent)->type;
}

const InfoSession* InfoEvent::getSession() const
{
    return dyn_cast<const InfoSession*>(this->getBaseSession());
}

takeOwnership_Implement(Info, Info, Session);



/* ======================== OptionsEvent ========================*/
OptionsEvent::OptionsEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

OptionsEvent::~OptionsEvent()
{
}

tsip_options_event_type_t OptionsEvent::getType() const
{
    return TSIP_OPTIONS_EVENT(this->sipevent)->type;
}

const OptionsSession* OptionsEvent::getSession() const
{
    return dyn_cast<const OptionsSession*>(this->getBaseSession());
}

takeOwnership_Implement(Options, Options, Session);


/* ======================== PublicationEvent ========================*/
PublicationEvent::PublicationEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

PublicationEvent::~PublicationEvent()
{
}

tsip_publish_event_type_t PublicationEvent::getType() const
{
    return TSIP_PUBLISH_EVENT(this->sipevent)->type;
}

const PublicationSession* PublicationEvent::getSession() const
{
    return dyn_cast<const PublicationSession*>(this->getBaseSession());
}

takeOwnership_Implement(Publication, Publication, Session);


/* ======================== RegistrationEvent ========================*/
RegistrationEvent::RegistrationEvent(const tsip_event_t *_sipevent)
    :SipEvent(_sipevent)
{
}

RegistrationEvent::~RegistrationEvent()
{
}

tsip_register_event_type_t RegistrationEvent::getType() const
{
    return TSIP_REGISTER_EVENT(this->sipevent)->type;
}

const RegistrationSession* RegistrationEvent::getSession() const
{
    return dyn_cast<const RegistrationSession*>(this->getBaseSession());
}

takeOwnership_Implement(Registration, Registration, Session);


/* ======================== SubscriptionEvent ========================*/
SubscriptionEvent::SubscriptionEvent(const tsip_event_t *sipevent)
    :SipEvent(sipevent)
{
}

SubscriptionEvent::~SubscriptionEvent()
{
}

tsip_subscribe_event_type_t SubscriptionEvent::getType() const
{
    return TSIP_SUBSCRIBE_EVENT(this->sipevent)->type;
}

const SubscriptionSession* SubscriptionEvent::getSession() const
{
    return dyn_cast<const SubscriptionSession*>(this->getBaseSession());
}

takeOwnership_Implement(Subscription, Subscription, Session);
OpenPOWER on IntegriCloud