sdp_offans.c
9.5 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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
eXosip - This is the eXtended osip library.
Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
eXosip 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 2 of the License, or
(at your option) any later version.
eXosip 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
In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.
You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.
*/
#include "eXosip2.h"
sdp_message_t *_eXosip_get_remote_sdp(osip_transaction_t *invite_tr);
sdp_message_t *_eXosip_get_local_sdp(osip_transaction_t *invite_tr);
sdp_message_t *eXosip_get_remote_sdp_from_tid(struct eXosip_t *excontext, int tid) {
eXosip_dialog_t *jd = NULL;
eXosip_call_t *jc = NULL;
osip_transaction_t *tr = NULL;
if (tid > 0) {
_eXosip_call_transaction_find(excontext, tid, &jc, &jd, &tr);
}
if (jc == NULL) {
OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, "[eXosip] no call here\n"));
return NULL;
}
if (tr == NULL)
return NULL;
return _eXosip_get_remote_sdp(tr);
}
sdp_message_t *eXosip_get_local_sdp_from_tid(struct eXosip_t *excontext, int tid) {
eXosip_dialog_t *jd = NULL;
eXosip_call_t *jc = NULL;
osip_transaction_t *tr = NULL;
if (tid > 0) {
_eXosip_call_transaction_find(excontext, tid, &jc, &jd, &tr);
}
if (jc == NULL) {
OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, "[eXosip] no call here\n"));
return NULL;
}
if (tr == NULL)
return NULL;
return _eXosip_get_local_sdp(tr);
}
sdp_message_t *eXosip_get_remote_sdp(struct eXosip_t *excontext, int jid) {
eXosip_dialog_t *jd = NULL;
eXosip_call_t *jc = NULL;
osip_transaction_t *invite_tr = NULL;
if (jid > 0) {
_eXosip_call_dialog_find(excontext, jid, &jc, &jd);
}
if (jc == NULL) {
OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, "[eXosip] no call here\n"));
return NULL;
}
invite_tr = _eXosip_find_last_invite(jc, jd);
if (invite_tr == NULL)
return NULL;
return _eXosip_get_remote_sdp(invite_tr);
}
sdp_message_t *eXosip_get_previous_local_sdp(struct eXosip_t *excontext, int jid) {
eXosip_dialog_t *jd = NULL;
eXosip_call_t *jc = NULL;
osip_transaction_t *invite_tr = NULL;
if (jid > 0) {
_eXosip_call_dialog_find(excontext, jid, &jc, &jd);
}
if (jc == NULL) {
OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, "[eXosip] no call here\n"));
return NULL;
}
invite_tr = _eXosip_find_last_invite(jc, jd);
if (invite_tr == NULL)
return NULL;
invite_tr = _eXosip_find_previous_invite(jc, jd, invite_tr);
if (invite_tr == NULL)
return NULL;
return _eXosip_get_local_sdp(invite_tr);
}
sdp_message_t *eXosip_get_local_sdp(struct eXosip_t *excontext, int jid) {
eXosip_dialog_t *jd = NULL;
eXosip_call_t *jc = NULL;
osip_transaction_t *invite_tr = NULL;
if (jid > 0) {
_eXosip_call_dialog_find(excontext, jid, &jc, &jd);
}
if (jc == NULL) {
OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, "[eXosip] no call here\n"));
return NULL;
}
invite_tr = _eXosip_find_last_invite(jc, jd);
if (invite_tr == NULL)
return NULL;
return _eXosip_get_local_sdp(invite_tr);
}
sdp_message_t *_eXosip_get_remote_sdp(osip_transaction_t *invite_tr) {
if (invite_tr == NULL)
return NULL;
if (invite_tr->ctx_type == IST || invite_tr->ctx_type == NIST) {
sdp_message_t *sdp;
sdp = eXosip_get_sdp_info(invite_tr->orig_request);
if (sdp == NULL) {
sdp = eXosip_get_sdp_info(invite_tr->ack);
}
return sdp;
}
if (invite_tr->ctx_type == ICT || invite_tr->ctx_type == NICT)
return eXosip_get_sdp_info(invite_tr->last_response);
return NULL;
}
sdp_message_t *_eXosip_get_local_sdp(osip_transaction_t *invite_tr) {
if (invite_tr == NULL)
return NULL;
if (invite_tr->ctx_type == IST || invite_tr->ctx_type == NIST)
return eXosip_get_sdp_info(invite_tr->last_response);
if (invite_tr->ctx_type == ICT || invite_tr->ctx_type == NICT) {
sdp_message_t *sdp;
sdp = eXosip_get_sdp_info(invite_tr->orig_request);
if (sdp == NULL) {
sdp = eXosip_get_sdp_info(invite_tr->ack);
}
return sdp;
}
return NULL;
}
sdp_message_t *eXosip_get_sdp_info(osip_message_t *message) {
osip_content_type_t *ctt;
sdp_message_t *sdp;
osip_body_t *oldbody;
osip_list_iterator_t it;
if (message == NULL)
return NULL;
/* get content-type info */
ctt = osip_message_get_content_type(message);
if (ctt == NULL)
return NULL; /* previous message was not correct or empty */
if (ctt->type == NULL || ctt->subtype == NULL)
return NULL;
if (osip_strcasecmp(ctt->type, "application") == 0 && osip_strcasecmp(ctt->subtype, "sdp") == 0) {
int i;
oldbody = (osip_body_t *) osip_list_get_first(&message->bodies, &it);
if (oldbody == NULL)
return NULL;
sdp_message_init(&sdp);
i = sdp_message_parse(sdp, oldbody->body);
if (i == 0)
return sdp;
sdp_message_free(sdp);
return NULL;
}
if (osip_strcasecmp(ctt->type, "multipart") != 0)
return NULL;
oldbody = (osip_body_t *) osip_list_get_first(&message->bodies, &it);
while (oldbody != NULL) {
int i;
ctt = oldbody->content_type;
if (ctt == NULL) {
oldbody = (osip_body_t *) osip_list_get_next(&it);
continue;
}
if (osip_strcasecmp(ctt->type, "application") != 0 || osip_strcasecmp(ctt->subtype, "sdp") != 0) {
oldbody = (osip_body_t *) osip_list_get_next(&it);
continue;
}
sdp_message_init(&sdp);
i = sdp_message_parse(sdp, oldbody->body);
if (i == 0)
return sdp;
sdp_message_free(sdp);
return NULL;
}
return NULL;
}
sdp_connection_t *eXosip_get_audio_connection(sdp_message_t *sdp) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, "audio") == 0)
break;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
if (med == NULL)
return NULL; /* no audio stream */
if (osip_list_eol(&med->c_connections, 0))
return sdp->c_connection;
/* just return the first one... */
return (sdp_connection_t *) osip_list_get(&med->c_connections, 0);
}
sdp_media_t *eXosip_get_audio_media(sdp_message_t *sdp) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, "audio") == 0)
return med;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
return NULL;
}
sdp_connection_t *eXosip_get_video_connection(sdp_message_t *sdp) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, "video") == 0)
break;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
if (med == NULL)
return NULL; /* no video stream */
if (osip_list_eol(&med->c_connections, 0))
return sdp->c_connection;
/* just return the first one... */
return (sdp_connection_t *) osip_list_get(&med->c_connections, 0);
}
sdp_media_t *eXosip_get_video_media(sdp_message_t *sdp) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, "video") == 0)
return med;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
return NULL;
}
sdp_connection_t *eXosip_get_connection(sdp_message_t *sdp, const char *media) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, media) == 0)
break;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
if (med == NULL)
return NULL; /* no video stream */
if (osip_list_eol(&med->c_connections, 0))
return sdp->c_connection;
/* just return the first one... */
return (sdp_connection_t *) osip_list_get(&med->c_connections, 0);
}
sdp_media_t *eXosip_get_media(sdp_message_t *sdp, const char *media) {
int pos = 0;
sdp_media_t *med = (sdp_media_t *) osip_list_get(&sdp->m_medias, 0);
while (med != NULL) {
if (med->m_media != NULL && osip_strcasecmp(med->m_media, media) == 0)
return med;
pos++;
med = (sdp_media_t *) osip_list_get(&sdp->m_medias, pos);
}
return NULL;
}