media: ignore IPv6 candidates
[siplcs.git] / src / core / sipe-media.c
blob375719aadf501d593514757e0ab572dccd3de43b
1 /**
2 * @file sipe-media.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2014 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2010 Jakub Adam <jakub.adam@ktknet.cz>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include <glib.h>
34 #include "sipe-common.h"
35 #include "sipmsg.h"
36 #include "sip-transport.h"
37 #include "sipe-backend.h"
38 #include "sdpmsg.h"
39 #include "sipe-chat.h"
40 #include "sipe-core.h"
41 #include "sipe-core-private.h"
42 #include "sipe-dialog.h"
43 #include "sipe-media.h"
44 #include "sipe-ocs2007.h"
45 #include "sipe-session.h"
46 #include "sipe-utils.h"
47 #include "sipe-nls.h"
48 #include "sipe-schedule.h"
49 #include "sipe-xml.h"
51 struct sipe_media_call_private {
52 struct sipe_media_call public;
54 /* private part starts here */
55 struct sipe_core_private *sipe_private;
56 gchar *with;
58 struct sipmsg *invitation;
59 SipeIceVersion ice_version;
60 gboolean encryption_compatible;
62 struct sdpmsg *smsg;
63 GSList *failed_media;
65 #define SIPE_MEDIA_CALL ((struct sipe_media_call *) call_private)
66 #define SIPE_MEDIA_CALL_PRIVATE ((struct sipe_media_call_private *) call)
68 static void sipe_media_codec_list_free(GList *codecs)
70 for (; codecs; codecs = g_list_delete_link(codecs, codecs))
71 sipe_backend_codec_free(codecs->data);
74 static void sipe_media_candidate_list_free(GList *candidates)
76 for (; candidates; candidates = g_list_delete_link(candidates, candidates))
77 sipe_backend_candidate_free(candidates->data);
80 static void
81 sipe_media_call_free(struct sipe_media_call_private *call_private)
83 if (call_private) {
84 struct sip_session *session;
85 sipe_backend_media_free(call_private->public.backend_private);
87 session = sipe_session_find_call(call_private->sipe_private,
88 call_private->with);
89 if (session)
90 sipe_session_remove(call_private->sipe_private, session);
92 if (call_private->invitation)
93 sipmsg_free(call_private->invitation);
95 sdpmsg_free(call_private->smsg);
96 sipe_utils_slist_free_full(call_private->failed_media,
97 (GDestroyNotify)sdpmedia_free);
98 g_free(call_private->with);
99 g_free(call_private);
103 static gint
104 candidate_sort_cb(struct sdpcandidate *c1, struct sdpcandidate *c2)
106 int cmp = sipe_strcompare(c1->foundation, c2->foundation);
107 if (cmp == 0) {
108 cmp = sipe_strcompare(c1->username, c2->username);
109 if (cmp == 0)
110 cmp = c1->component - c2->component;
113 return cmp;
116 static GSList *
117 backend_candidates_to_sdpcandidate(GList *candidates)
119 GSList *result = NULL;
120 GList *i;
122 for (i = candidates; i; i = i->next) {
123 struct sipe_backend_candidate *candidate = i->data;
124 struct sdpcandidate *c;
126 gchar *ip = sipe_backend_candidate_get_ip(candidate);
127 gchar *base_ip = sipe_backend_candidate_get_base_ip(candidate);
128 if (is_empty(ip) || strchr(ip, ':') ||
129 (base_ip && strchr(base_ip, ':'))) {
130 /* Ignore IPv6 candidates. */
131 g_free(ip);
132 g_free(base_ip);
133 continue;
136 c = g_new(struct sdpcandidate, 1);
137 c->foundation = sipe_backend_candidate_get_foundation(candidate);
138 c->component = sipe_backend_candidate_get_component_type(candidate);
139 c->type = sipe_backend_candidate_get_type(candidate);
140 c->protocol = sipe_backend_candidate_get_protocol(candidate);
141 c->ip = ip;
142 c->port = sipe_backend_candidate_get_port(candidate);
143 c->base_ip = base_ip;
144 c->base_port = sipe_backend_candidate_get_base_port(candidate);
145 c->priority = sipe_backend_candidate_get_priority(candidate);
146 c->username = sipe_backend_candidate_get_username(candidate);
147 c->password = sipe_backend_candidate_get_password(candidate);
149 result = g_slist_insert_sorted(result, c,
150 (GCompareFunc)candidate_sort_cb);
153 return result;
156 static void
157 get_stream_ip_and_ports(GSList *candidates,
158 gchar **ip, guint *rtp_port, guint *rtcp_port,
159 SipeCandidateType type)
161 *ip = 0;
162 *rtp_port = 0;
163 *rtcp_port = 0;
165 for (; candidates; candidates = candidates->next) {
166 struct sdpcandidate *candidate = candidates->data;
168 if (type == SIPE_CANDIDATE_TYPE_ANY || candidate->type == type) {
169 if (!(*ip ||
170 is_empty(candidate->ip) ||
171 /* reject IPv6 addresses */
172 strchr(candidate->ip, ':'))) {
173 *ip = g_strdup(candidate->ip);
174 } else if (!(*ip && sipe_strequal(*ip, candidate->ip))) {
175 continue;
178 if (candidate->component == SIPE_COMPONENT_RTP) {
179 *rtp_port = candidate->port;
180 } else if (candidate->component == SIPE_COMPONENT_RTCP)
181 *rtcp_port = candidate->port;
184 if (*rtp_port != 0 && *rtcp_port != 0)
185 return;
189 static gint
190 sdpcodec_compare(gconstpointer a, gconstpointer b)
192 return ((const struct sdpcodec *)a)->id -
193 ((const struct sdpcodec *)b)->id;
196 static struct sdpmedia *
197 backend_stream_to_sdpmedia(struct sipe_backend_media *backend_media,
198 struct sipe_backend_stream *backend_stream)
200 struct sdpmedia *media = g_new0(struct sdpmedia, 1);
201 GList *codecs = sipe_backend_get_local_codecs(backend_media,
202 backend_stream);
203 guint rtcp_port = 0;
204 SipeMediaType type;
205 GSList *attributes = NULL;
206 GList *candidates;
207 GList *i;
209 media->name = g_strdup(sipe_backend_stream_get_id(backend_stream));
211 if (sipe_strequal(media->name, "audio"))
212 type = SIPE_MEDIA_AUDIO;
213 else if (sipe_strequal(media->name, "video"))
214 type = SIPE_MEDIA_VIDEO;
215 else {
216 // TODO: incompatible media, should not happen here
217 g_free(media->name);
218 g_free(media);
219 sipe_media_codec_list_free(codecs);
220 return(NULL);
223 // Process codecs
224 for (i = codecs; i; i = i->next) {
225 struct sipe_backend_codec *codec = i->data;
226 struct sdpcodec *c = g_new0(struct sdpcodec, 1);
227 GList *params;
229 c->id = sipe_backend_codec_get_id(codec);
230 c->name = sipe_backend_codec_get_name(codec);
231 c->clock_rate = sipe_backend_codec_get_clock_rate(codec);
232 c->type = type;
234 params = sipe_backend_codec_get_optional_parameters(codec);
235 for (; params; params = params->next) {
236 struct sipnameval *param = params->data;
237 struct sipnameval *copy = g_new0(struct sipnameval, 1);
239 copy->name = g_strdup(param->name);
240 copy->value = g_strdup(param->value);
242 c->parameters = g_slist_append(c->parameters, copy);
245 /* Buggy(?) codecs may report non-unique id (a.k.a. payload
246 * type) that must not appear in SDP messages we send. Thus,
247 * let's ignore any codec having the same id as one we already
248 * have in the converted list. */
249 media->codecs = sipe_utils_slist_insert_unique_sorted(
250 media->codecs, c, sdpcodec_compare,
251 (GDestroyNotify)sdpcodec_free);
254 sipe_media_codec_list_free(codecs);
256 // Process local candidates
257 // If we have established candidate pairs, send them in SDP response.
258 // Otherwise send all available local candidates.
259 candidates = sipe_backend_media_get_active_local_candidates(backend_media,
260 backend_stream);
261 if (!candidates)
262 candidates = sipe_backend_get_local_candidates(backend_media,
263 backend_stream);
265 media->candidates = backend_candidates_to_sdpcandidate(candidates);
267 sipe_media_candidate_list_free(candidates);
269 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
270 &rtcp_port, SIPE_CANDIDATE_TYPE_HOST);
271 // No usable HOST candidates, use any candidate
272 if (media->ip == NULL && media->candidates) {
273 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
274 &rtcp_port, SIPE_CANDIDATE_TYPE_ANY);
277 if (sipe_backend_stream_is_held(backend_stream))
278 attributes = sipe_utils_nameval_add(attributes, "inactive", "");
280 if (rtcp_port) {
281 gchar *tmp = g_strdup_printf("%u", rtcp_port);
282 attributes = sipe_utils_nameval_add(attributes, "rtcp", tmp);
283 g_free(tmp);
286 attributes = sipe_utils_nameval_add(attributes, "encryption", "rejected");
288 media->attributes = attributes;
290 // Process remote candidates
291 candidates = sipe_backend_media_get_active_remote_candidates(backend_media,
292 backend_stream);
293 media->remote_candidates = backend_candidates_to_sdpcandidate(candidates);
294 sipe_media_candidate_list_free(candidates);
296 return media;
299 static struct sdpmsg *
300 sipe_media_to_sdpmsg(struct sipe_media_call_private *call_private)
302 struct sipe_backend_media *backend_media = call_private->public.backend_private;
303 struct sdpmsg *msg = g_new0(struct sdpmsg, 1);
304 GSList *streams = sipe_backend_media_get_streams(backend_media);
306 for (; streams; streams = streams->next) {
307 struct sdpmedia *media = backend_stream_to_sdpmedia(backend_media, streams->data);
308 if (media) {
309 msg->media = g_slist_append(msg->media, media);
311 if (msg->ip == NULL)
312 msg->ip = g_strdup(media->ip);
316 msg->media = g_slist_concat(msg->media, call_private->failed_media);
317 call_private->failed_media = NULL;
319 msg->ice_version = call_private->ice_version;
321 return msg;
324 static void
325 sipe_invite_call(struct sipe_core_private *sipe_private, TransCallback tc)
327 gchar *hdr;
328 gchar *contact;
329 gchar *p_preferred_identity = NULL;
330 gchar *body;
331 struct sipe_media_call_private *call_private = sipe_private->media_call;
332 struct sip_session *session;
333 struct sip_dialog *dialog;
334 struct sdpmsg *msg;
335 gboolean add_2007_fallback = FALSE;
337 session = sipe_session_find_call(sipe_private, call_private->with);
338 dialog = session->dialogs->data;
339 add_2007_fallback = dialog->cseq == 0 &&
340 call_private->ice_version == SIPE_ICE_RFC_5245 &&
341 !sipe_strequal(call_private->with, sipe_private->test_call_bot_uri);
343 contact = get_contact(sipe_private);
345 if (sipe_private->uc_line_uri) {
346 gchar *self = sip_uri_self(sipe_private);
347 p_preferred_identity = g_strdup_printf(
348 "P-Preferred-Identity: <%s>, <%s>\r\n",
349 self, sipe_private->uc_line_uri);
350 g_free(self);
353 hdr = g_strdup_printf(
354 "ms-keep-alive: UAC;hop-hop=yes\r\n"
355 "Contact: %s\r\n"
356 "%s"
357 "Content-Type: %s\r\n",
358 contact,
359 p_preferred_identity ? p_preferred_identity : "",
360 add_2007_fallback ?
361 "multipart/alternative;boundary=\"----=_NextPart_000_001E_01CB4397.0B5EB570\""
362 : "application/sdp");
363 g_free(contact);
364 g_free(p_preferred_identity);
366 msg = sipe_media_to_sdpmsg(call_private);
367 body = sdpmsg_to_string(msg);
369 if (add_2007_fallback) {
370 gchar *tmp;
371 tmp = g_strdup_printf(
372 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
373 "Content-Type: application/sdp\r\n"
374 "Content-Transfer-Encoding: 7bit\r\n"
375 "Content-Disposition: session; handling=optional; ms-proxy-2007fallback\r\n"
376 "\r\n"
377 "o=- 0 0 IN IP4 %s\r\n"
378 "s=session\r\n"
379 "c=IN IP4 %s\r\n"
380 "m=audio 0 RTP/AVP\r\n"
381 "\r\n"
382 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
383 "Content-Type: application/sdp\r\n"
384 "Content-Transfer-Encoding: 7bit\r\n"
385 "Content-Disposition: session; handling=optional\r\n"
386 "\r\n"
387 "%s"
388 "\r\n"
389 "------=_NextPart_000_001E_01CB4397.0B5EB570--\r\n",
390 msg->ip, msg->ip, body);
391 g_free(body);
392 body = tmp;
395 sdpmsg_free(msg);
397 dialog->outgoing_invite = sip_transport_invite(sipe_private,
398 hdr,
399 body,
400 dialog,
401 tc);
403 g_free(body);
404 g_free(hdr);
407 static struct sip_dialog *
408 sipe_media_dialog_init(struct sip_session* session, struct sipmsg *msg)
410 gchar *newTag = gentag();
411 const gchar *oldHeader;
412 gchar *newHeader;
413 struct sip_dialog *dialog;
415 oldHeader = sipmsg_find_header(msg, "To");
416 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
417 sipmsg_remove_header_now(msg, "To");
418 sipmsg_add_header_now(msg, "To", newHeader);
419 g_free(newHeader);
421 dialog = sipe_dialog_add(session);
422 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
423 dialog->with = parse_from(sipmsg_find_header(msg, "From"));
424 sipe_dialog_parse(dialog, msg, FALSE);
426 return dialog;
429 static void
430 send_response_with_session_description(struct sipe_media_call_private *call_private, int code, gchar *text)
432 struct sdpmsg *msg = sipe_media_to_sdpmsg(call_private);
433 gchar *body = sdpmsg_to_string(msg);
434 sdpmsg_free(msg);
435 sipmsg_add_header(call_private->invitation, "Content-Type", "application/sdp");
436 sip_transport_response(call_private->sipe_private, call_private->invitation, code, text, body);
437 g_free(body);
440 static gboolean
441 encryption_levels_compatible(struct sdpmsg *msg)
443 GSList *i;
445 for (i = msg->media; i; i = i->next) {
446 const gchar *enc_level;
447 struct sdpmedia *m = i->data;
449 enc_level = sipe_utils_nameval_find(m->attributes, "encryption");
451 // Decline call if peer requires encryption as we don't support it yet.
452 if (sipe_strequal(enc_level, "required"))
453 return FALSE;
456 return TRUE;
459 static gboolean
460 process_invite_call_response(struct sipe_core_private *sipe_private,
461 struct sipmsg *msg,
462 struct transaction *trans);
464 static gboolean
465 update_remote_media(struct sipe_media_call_private* call_private,
466 struct sdpmedia *media)
468 struct sipe_backend_media *backend_media = SIPE_MEDIA_CALL->backend_private;
469 struct sipe_backend_stream *backend_stream;
470 GList *backend_candidates = NULL;
471 GList *backend_codecs = NULL;
472 GSList *i;
473 gboolean result = TRUE;
475 backend_stream = sipe_backend_media_get_stream_by_id(backend_media,
476 media->name);
477 if (media->port == 0) {
478 if (backend_stream)
479 sipe_backend_media_remove_stream(backend_media, backend_stream);
480 return TRUE;
483 if (!backend_stream)
484 return FALSE;
486 for (i = media->codecs; i; i = i->next) {
487 struct sdpcodec *c = i->data;
488 struct sipe_backend_codec *codec;
489 GSList *j;
491 codec = sipe_backend_codec_new(c->id,
492 c->name,
493 c->type,
494 c->clock_rate);
496 for (j = c->parameters; j; j = j->next) {
497 struct sipnameval *attr = j->data;
499 sipe_backend_codec_add_optional_parameter(codec,
500 attr->name,
501 attr->value);
504 backend_codecs = g_list_append(backend_codecs, codec);
507 result = sipe_backend_set_remote_codecs(backend_media,
508 backend_stream,
509 backend_codecs);
510 sipe_media_codec_list_free(backend_codecs);
512 if (result == FALSE) {
513 sipe_backend_media_remove_stream(backend_media, backend_stream);
514 return FALSE;
517 for (i = media->candidates; i; i = i->next) {
518 struct sdpcandidate *c = i->data;
519 struct sipe_backend_candidate *candidate;
520 candidate = sipe_backend_candidate_new(c->foundation,
521 c->component,
522 c->type,
523 c->protocol,
524 c->ip,
525 c->port,
526 c->username,
527 c->password);
528 sipe_backend_candidate_set_priority(candidate, c->priority);
530 backend_candidates = g_list_append(backend_candidates, candidate);
533 sipe_backend_media_add_remote_candidates(backend_media,
534 backend_stream,
535 backend_candidates);
536 sipe_media_candidate_list_free(backend_candidates);
538 if (sipe_utils_nameval_find(media->attributes, "inactive")) {
539 sipe_backend_stream_hold(backend_media, backend_stream, FALSE);
540 } else if (sipe_backend_stream_is_held(backend_stream)) {
541 sipe_backend_stream_unhold(backend_media, backend_stream, FALSE);
544 return TRUE;
547 static void
548 apply_remote_message(struct sipe_media_call_private* call_private,
549 struct sdpmsg* msg)
551 GSList *i;
553 sipe_utils_slist_free_full(call_private->failed_media, (GDestroyNotify)sdpmedia_free);
554 call_private->failed_media = NULL;
556 for (i = msg->media; i; i = i->next) {
557 struct sdpmedia *media = i->data;
558 if (!update_remote_media(call_private, media)) {
559 media->port = 0;
560 call_private->failed_media =
561 g_slist_append(call_private->failed_media, media);
565 /* We need to keep failed medias until response is sent, remove them
566 * from sdpmsg that is to be freed. */
567 for (i = call_private->failed_media; i; i = i->next) {
568 msg->media = g_slist_remove(msg->media, i->data);
571 call_private->encryption_compatible = encryption_levels_compatible(msg);
574 static gboolean
575 call_initialized(struct sipe_media_call *call)
577 GSList *streams =
578 sipe_backend_media_get_streams(call->backend_private);
580 for (; streams; streams = streams->next) {
581 if (!sipe_backend_stream_initialized(call->backend_private,
582 streams->data)) {
583 return FALSE;
587 return TRUE;
590 // Sends an invite response when the call is accepted and local candidates were
591 // prepared, otherwise does nothing. If error response is sent, call_private is
592 // disposed before function returns. Returns true when response was sent.
593 static gboolean
594 send_invite_response_if_ready(struct sipe_media_call_private *call_private)
596 struct sipe_backend_media *backend_media;
598 backend_media = call_private->public.backend_private;
600 if (!sipe_backend_media_accepted(backend_media) ||
601 !call_initialized(&call_private->public))
602 return FALSE;
604 if (!call_private->encryption_compatible) {
605 struct sipe_core_private *sipe_private = call_private->sipe_private;
607 sipmsg_add_header(call_private->invitation, "Warning",
608 "308 lcs.microsoft.com \"Encryption Levels not compatible\"");
609 sip_transport_response(sipe_private,
610 call_private->invitation,
611 488, "Encryption Levels not compatible",
612 NULL);
613 sipe_backend_media_reject(backend_media, FALSE);
614 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
615 _("Unable to establish a call"),
616 _("Encryption settings of peer are incompatible with ours."));
617 } else {
618 send_response_with_session_description(call_private, 200, "OK");
621 return TRUE;
624 static void
625 stream_initialized_cb(struct sipe_media_call *call,
626 struct sipe_backend_stream *stream)
628 if (call_initialized(call)) {
629 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
630 struct sipe_backend_media *backend_private = call->backend_private;
632 if (sipe_backend_media_is_initiator(backend_private, stream)) {
633 sipe_invite_call(call_private->sipe_private,
634 process_invite_call_response);
635 } else if (call_private->smsg) {
636 struct sdpmsg *smsg = call_private->smsg;
637 call_private->smsg = NULL;
639 apply_remote_message(call_private, smsg);
640 send_invite_response_if_ready(call_private);
641 sdpmsg_free(smsg);
646 static void phone_state_publish(struct sipe_core_private *sipe_private)
648 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) {
649 sipe_ocs2007_phone_state_publish(sipe_private);
650 } else {
651 // TODO: OCS 2005 support. Is anyone still using it at all?
655 static void
656 media_end_cb(struct sipe_media_call *call)
658 g_return_if_fail(call);
660 SIPE_MEDIA_CALL_PRIVATE->sipe_private->media_call = NULL;
661 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
662 sipe_media_call_free(SIPE_MEDIA_CALL_PRIVATE);
665 static void
666 call_accept_cb(struct sipe_media_call *call, gboolean local)
668 if (local) {
669 send_invite_response_if_ready(SIPE_MEDIA_CALL_PRIVATE);
671 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
674 static void
675 call_reject_cb(struct sipe_media_call *call, gboolean local)
677 if (local) {
678 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
679 sip_transport_response(call_private->sipe_private,
680 call_private->invitation,
681 603, "Decline", NULL);
685 static gboolean
686 sipe_media_send_ack(struct sipe_core_private *sipe_private, struct sipmsg *msg,
687 struct transaction *trans);
689 static void call_hold_cb(struct sipe_media_call *call,
690 gboolean local,
691 SIPE_UNUSED_PARAMETER gboolean state)
693 if (local)
694 sipe_invite_call(SIPE_MEDIA_CALL_PRIVATE->sipe_private,
695 sipe_media_send_ack);
698 static void call_hangup_cb(struct sipe_media_call *call, gboolean local)
700 if (local) {
701 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
702 struct sip_session *session;
703 session = sipe_session_find_call(call_private->sipe_private,
704 call_private->with);
706 if (session) {
707 sipe_session_close(call_private->sipe_private, session);
712 static void
713 error_cb(struct sipe_media_call *call, gchar *message)
715 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
716 struct sipe_core_private *sipe_private = call_private->sipe_private;
717 gboolean initiator = sipe_backend_media_is_initiator(call->backend_private, NULL);
718 gboolean accepted = sipe_backend_media_accepted(call->backend_private);
720 gchar *title = g_strdup_printf("Call with %s failed", call_private->with);
721 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, message);
722 g_free(title);
724 if (!initiator && !accepted) {
725 sip_transport_response(sipe_private,
726 call_private->invitation,
727 488, "Not Acceptable Here", NULL);
730 sipe_backend_media_hangup(call->backend_private, initiator || accepted);
733 static struct sipe_media_call_private *
734 sipe_media_call_new(struct sipe_core_private *sipe_private,
735 const gchar* with, gboolean initiator, SipeIceVersion ice_version)
737 struct sipe_media_call_private *call_private = g_new0(struct sipe_media_call_private, 1);
738 gchar *cname;
740 call_private->sipe_private = sipe_private;
742 cname = g_strdup(sipe_private->contact + 1);
743 cname[strlen(cname) - 1] = '\0';
745 call_private->public.backend_private = sipe_backend_media_new(SIPE_CORE_PUBLIC,
746 SIPE_MEDIA_CALL,
747 with,
748 initiator);
749 sipe_backend_media_set_cname(call_private->public.backend_private, cname);
751 call_private->ice_version = ice_version;
752 call_private->encryption_compatible = TRUE;
754 call_private->public.stream_initialized_cb = stream_initialized_cb;
755 call_private->public.media_end_cb = media_end_cb;
756 call_private->public.call_accept_cb = call_accept_cb;
757 call_private->public.call_reject_cb = call_reject_cb;
758 call_private->public.call_hold_cb = call_hold_cb;
759 call_private->public.call_hangup_cb = call_hangup_cb;
760 call_private->public.error_cb = error_cb;
762 g_free(cname);
764 return call_private;
767 void sipe_media_hangup(struct sipe_media_call_private *call_private)
769 if (call_private) {
770 sipe_backend_media_hangup(call_private->public.backend_private,
771 FALSE);
775 static void
776 sipe_media_initiate_call(struct sipe_core_private *sipe_private,
777 const char *with, SipeIceVersion ice_version,
778 gboolean with_video)
780 struct sipe_media_call_private *call_private;
781 struct sipe_backend_media *backend_media;
782 struct sipe_backend_media_relays *backend_media_relays;
783 struct sip_session *session;
784 struct sip_dialog *dialog;
786 if (sipe_private->media_call)
787 return;
789 call_private = sipe_media_call_new(sipe_private, with, TRUE, ice_version);
791 session = sipe_session_add_call(sipe_private, with);
792 dialog = sipe_dialog_add(session);
793 dialog->callid = gencallid();
794 dialog->with = g_strdup(session->with);
795 dialog->ourtag = gentag();
797 call_private->with = g_strdup(session->with);
799 backend_media = call_private->public.backend_private;
801 backend_media_relays =
802 sipe_backend_media_relays_convert(sipe_private->media_relays,
803 sipe_private->media_relay_username,
804 sipe_private->media_relay_password);
806 if (!sipe_backend_media_add_stream(backend_media,
807 "audio", with, SIPE_MEDIA_AUDIO,
808 call_private->ice_version, TRUE,
809 backend_media_relays)) {
810 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
811 _("Error occured"),
812 _("Error creating audio stream"));
813 sipe_media_hangup(call_private);
814 sipe_backend_media_relays_free(backend_media_relays);
815 return;
818 if ( with_video
819 && !sipe_backend_media_add_stream(backend_media,
820 "video", with, SIPE_MEDIA_VIDEO,
821 call_private->ice_version, TRUE,
822 backend_media_relays)) {
823 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
824 _("Error occured"),
825 _("Error creating video stream"));
826 sipe_media_hangup(call_private);
827 sipe_backend_media_relays_free(backend_media_relays);
828 return;
831 sipe_private->media_call = call_private;
833 sipe_backend_media_relays_free(backend_media_relays);
835 // Processing continues in stream_initialized_cb
838 void
839 sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
840 const char *with,
841 gboolean with_video)
843 sipe_media_initiate_call(SIPE_CORE_PRIVATE, with,
844 SIPE_ICE_RFC_5245, with_video);
847 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
848 struct sipe_chat_session *chat_session)
850 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
851 struct sipe_backend_media_relays *backend_media_relays;
852 struct sip_session *session;
853 struct sip_dialog *dialog;
854 SipeIceVersion ice_version;
855 gchar **parts;
856 gchar *av_uri;
858 session = sipe_session_find_chat(sipe_private, chat_session);
860 if (sipe_private->media_call || !session)
861 return;
863 session->is_call = TRUE;
865 parts = g_strsplit(chat_session->id, "app:conf:focus:", 2);
866 av_uri = g_strjoinv("app:conf:audio-video:", parts);
867 g_strfreev(parts);
869 ice_version = SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013) ? SIPE_ICE_RFC_5245 :
870 SIPE_ICE_DRAFT_6;
872 sipe_private->media_call = sipe_media_call_new(sipe_private, av_uri,
873 TRUE, ice_version);
875 session = sipe_session_add_call(sipe_private, av_uri);
876 dialog = sipe_dialog_add(session);
877 dialog->callid = gencallid();
878 dialog->with = g_strdup(session->with);
879 dialog->ourtag = gentag();
881 g_free(av_uri);
883 sipe_private->media_call->with = g_strdup(session->with);
885 backend_media_relays =
886 sipe_backend_media_relays_convert(sipe_private->media_relays,
887 sipe_private->media_relay_username,
888 sipe_private->media_relay_password);
890 if (!sipe_backend_media_add_stream(sipe_private->media_call->public.backend_private,
891 "audio", dialog->with,
892 SIPE_MEDIA_AUDIO,
893 sipe_private->media_call->ice_version,
894 TRUE, backend_media_relays)) {
895 sipe_backend_notify_error(sipe_public,
896 _("Error occured"),
897 _("Error creating audio stream"));
898 sipe_media_hangup(sipe_private->media_call);
899 sipe_private->media_call = NULL;
902 sipe_backend_media_relays_free(backend_media_relays);
904 // Processing continues in stream_initialized_cb
907 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public)
909 if (sipe_public) {
910 return SIPE_CORE_PRIVATE->media_call != NULL;
912 return FALSE;
915 static gboolean phone_number_is_valid(const gchar *phone_number)
917 if (!phone_number || sipe_strequal(phone_number, "")) {
918 return FALSE;
921 if (*phone_number == '+') {
922 ++phone_number;
925 while (*phone_number != '\0') {
926 if (!g_ascii_isdigit(*phone_number)) {
927 return FALSE;
929 ++phone_number;
932 return TRUE;
935 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
936 const gchar *phone_number)
938 g_return_if_fail(sipe_public);
940 if (phone_number_is_valid(phone_number)) {
941 gchar *phone_uri = g_strdup_printf("sip:%s@%s;user=phone",
942 phone_number, sipe_public->sip_domain);
944 sipe_core_media_initiate_call(sipe_public, phone_uri, FALSE);
946 g_free(phone_uri);
947 } else {
948 sipe_backend_notify_error(sipe_public,
949 _("Unable to establish a call"),
950 _("Invalid phone number"));
954 void sipe_core_media_test_call(struct sipe_core_public *sipe_public)
956 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
957 if (!sipe_private->test_call_bot_uri) {
958 sipe_backend_notify_error(sipe_public,
959 _("Unable to establish a call"),
960 _("Audio Test Service is not available."));
961 return;
964 sipe_core_media_initiate_call(sipe_public,
965 sipe_private->test_call_bot_uri, FALSE);
968 void
969 process_incoming_invite_call(struct sipe_core_private *sipe_private,
970 struct sipmsg *msg)
972 struct sipe_media_call_private *call_private = sipe_private->media_call;
973 struct sipe_backend_media *backend_media;
974 struct sipe_backend_media_relays *backend_media_relays = NULL;
975 struct sdpmsg *smsg;
976 gboolean has_new_media = FALSE;
977 GSList *i;
979 if (call_private) {
980 char *self;
982 if (!is_media_session_msg(call_private, msg)) {
983 sip_transport_response(sipe_private, msg, 486, "Busy Here", NULL);
984 return;
987 self = sip_uri_self(sipe_private);
988 if (sipe_strequal(call_private->with, self)) {
989 g_free(self);
990 sip_transport_response(sipe_private, msg, 488, "Not Acceptable Here", NULL);
991 return;
993 g_free(self);
996 smsg = sdpmsg_parse_msg(msg->body);
997 if (!smsg) {
998 sip_transport_response(sipe_private, msg,
999 488, "Not Acceptable Here", NULL);
1000 sipe_media_hangup(call_private);
1001 return;
1004 if (!call_private) {
1005 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
1006 struct sip_session *session;
1008 call_private = sipe_media_call_new(sipe_private, with, FALSE, smsg->ice_version);
1009 session = sipe_session_add_call(sipe_private, with);
1010 sipe_media_dialog_init(session, msg);
1012 call_private->with = g_strdup(session->with);
1013 sipe_private->media_call = call_private;
1014 g_free(with);
1017 backend_media = call_private->public.backend_private;
1019 if (call_private->invitation)
1020 sipmsg_free(call_private->invitation);
1021 call_private->invitation = sipmsg_copy(msg);
1023 if (smsg->media)
1024 backend_media_relays = sipe_backend_media_relays_convert(
1025 sipe_private->media_relays,
1026 sipe_private->media_relay_username,
1027 sipe_private->media_relay_password);
1029 // Create any new media streams
1030 for (i = smsg->media; i; i = i->next) {
1031 struct sdpmedia *media = i->data;
1032 gchar *id = media->name;
1033 SipeMediaType type;
1035 if ( media->port != 0
1036 && !sipe_backend_media_get_stream_by_id(backend_media, id)) {
1037 gchar *with;
1039 if (sipe_strequal(id, "audio"))
1040 type = SIPE_MEDIA_AUDIO;
1041 else if (sipe_strequal(id, "video"))
1042 type = SIPE_MEDIA_VIDEO;
1043 else
1044 continue;
1046 with = parse_from(sipmsg_find_header(msg, "From"));
1047 sipe_backend_media_add_stream(backend_media, id, with,
1048 type,
1049 smsg->ice_version,
1050 FALSE,
1051 backend_media_relays);
1052 has_new_media = TRUE;
1053 g_free(with);
1057 sipe_backend_media_relays_free(backend_media_relays);
1059 if (has_new_media) {
1060 sdpmsg_free(call_private->smsg);
1061 call_private->smsg = smsg;
1062 sip_transport_response(sipe_private, call_private->invitation,
1063 180, "Ringing", NULL);
1064 // Processing continues in stream_initialized_cb
1065 } else {
1066 apply_remote_message(call_private, smsg);
1067 send_response_with_session_description(call_private, 200, "OK");
1069 sdpmsg_free(smsg);
1073 void process_incoming_cancel_call(struct sipe_core_private *sipe_private,
1074 struct sipmsg *msg)
1076 struct sipe_media_call_private *call_private = sipe_private->media_call;
1078 // We respond to the CANCEL request with 200 OK response and
1079 // with 487 Request Terminated to the remote INVITE in progress.
1080 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1082 if (call_private->invitation) {
1083 sip_transport_response(sipe_private, call_private->invitation,
1084 487, "Request Terminated", NULL);
1087 sipe_media_hangup(call_private);
1090 static gboolean
1091 sipe_media_send_ack(struct sipe_core_private *sipe_private,
1092 struct sipmsg *msg,
1093 struct transaction *trans)
1095 struct sipe_media_call_private *call_private = sipe_private->media_call;
1096 struct sip_session *session;
1097 struct sip_dialog *dialog;
1098 int tmp_cseq;
1100 if (!is_media_session_msg(call_private, msg))
1101 return FALSE;
1103 session = sipe_session_find_call(sipe_private, call_private->with);
1104 dialog = session->dialogs->data;
1105 if (!dialog)
1106 return FALSE;
1108 tmp_cseq = dialog->cseq;
1110 dialog->cseq = sip_transaction_cseq(trans) - 1;
1111 sip_transport_ack(sipe_private, dialog);
1112 dialog->cseq = tmp_cseq;
1114 dialog->outgoing_invite = NULL;
1116 return TRUE;
1119 static gboolean
1120 sipe_media_send_final_ack(struct sipe_core_private *sipe_private,
1121 struct sipmsg *msg,
1122 struct transaction *trans)
1124 if (!sipe_media_send_ack(sipe_private, msg, trans))
1125 return FALSE;
1127 sipe_backend_media_accept(sipe_private->media_call->public.backend_private,
1128 FALSE);
1130 return TRUE;
1133 static void
1134 reinvite_on_candidate_pair_cb(struct sipe_core_public *sipe_public)
1136 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1137 struct sipe_media_call_private *media_call = sipe_private->media_call;
1138 struct sipe_backend_media *backend_media;
1139 GSList *streams;
1141 if (!media_call)
1142 return;
1144 backend_media = media_call->public.backend_private;
1145 streams = sipe_backend_media_get_streams(backend_media);
1147 for (; streams; streams = streams->next) {
1148 struct sipe_backend_stream *s = streams->data;
1149 GList *remote_candidates = sipe_backend_media_get_active_remote_candidates(backend_media, s);
1150 guint components = g_list_length(remote_candidates);
1152 sipe_media_candidate_list_free(remote_candidates);
1154 // We must have candidates for both (RTP + RTCP) components ready
1155 if (components < 2) {
1156 sipe_schedule_mseconds(sipe_private,
1157 "<+media-reinvite-on-candidate-pair>",
1158 NULL,
1159 500,
1160 (sipe_schedule_action) reinvite_on_candidate_pair_cb,
1161 NULL);
1162 return;
1166 sipe_invite_call(sipe_private, sipe_media_send_final_ack);
1169 static gboolean
1170 maybe_retry_call_with_ice_version(struct sipe_core_private *sipe_private,
1171 SipeIceVersion ice_version,
1172 struct transaction *trans)
1174 struct sipe_media_call_private *call_private = sipe_private->media_call;
1176 if (call_private->ice_version != ice_version &&
1177 sip_transaction_cseq(trans) == 1) {
1178 gchar *with = g_strdup(call_private->with);
1179 struct sipe_backend_media *backend_private = call_private->public.backend_private;
1180 gboolean with_video = sipe_backend_media_get_stream_by_id(backend_private, "video") != NULL;
1182 sipe_media_hangup(call_private);
1183 SIPE_DEBUG_INFO("Retrying call with ICEv%d.",
1184 ice_version == SIPE_ICE_DRAFT_6 ? 6 : 19);
1185 sipe_media_initiate_call(sipe_private, with, ice_version,
1186 with_video);
1188 g_free(with);
1189 return TRUE;
1192 return FALSE;
1195 static gboolean
1196 process_invite_call_response(struct sipe_core_private *sipe_private,
1197 struct sipmsg *msg,
1198 struct transaction *trans)
1200 const gchar *with;
1201 struct sipe_media_call_private *call_private = sipe_private->media_call;
1202 struct sip_session *session;
1203 struct sip_dialog *dialog;
1204 struct sdpmsg *smsg;
1206 if (!is_media_session_msg(call_private, msg))
1207 return FALSE;
1209 session = sipe_session_find_call(sipe_private, call_private->with);
1210 dialog = session->dialogs->data;
1212 with = dialog->with;
1214 dialog->outgoing_invite = NULL;
1216 if (msg->response >= 400) {
1217 // Call rejected by remote peer or an error occurred
1218 const gchar *title;
1219 GString *desc = g_string_new("");
1220 gboolean append_responsestr = FALSE;
1222 switch (msg->response) {
1223 case 480: {
1224 title = _("User unavailable");
1226 if (sipmsg_parse_warning(msg, NULL) == 391) {
1227 g_string_append_printf(desc, _("%s does not want to be disturbed"), with);
1228 } else
1229 g_string_append_printf(desc, _("User %s is not available"), with);
1230 break;
1232 case 603:
1233 case 605:
1234 title = _("Call rejected");
1235 g_string_append_printf(desc, _("User %s rejected call"), with);
1236 break;
1237 case 415:
1238 // OCS/Lync really sends response string with 'Mutipart' typo.
1239 if (sipe_strequal(msg->responsestr, "Mutipart mime in content type not supported by Archiving CDR service") &&
1240 maybe_retry_call_with_ice_version(sipe_private, SIPE_ICE_DRAFT_6, trans)) {
1241 return TRUE;
1243 title = _("Unsupported media type");
1244 break;
1245 case 488: {
1246 /* Check for incompatible encryption levels error.
1248 * MS Lync 2010:
1249 * 488 Not Acceptable Here
1250 * ms-client-diagnostics: 52017;reason="Encryption levels dont match"
1252 * older clients (and SIPE itself):
1253 * 488 Encryption Levels not compatible
1255 const gchar *ms_diag = sipmsg_find_header(msg, "ms-client-diagnostics");
1256 SipeIceVersion retry_ice_version = SIPE_ICE_DRAFT_6;
1258 if (sipe_strequal(msg->responsestr, "Encryption Levels not compatible") ||
1259 (ms_diag && g_str_has_prefix(ms_diag, "52017;"))) {
1260 title = _("Unable to establish a call");
1261 g_string_append(desc, _("Encryption settings of peer are incompatible with ours."));
1262 break;
1265 /* Check if this is failed conference using
1266 * ICEv6 with reason "Error parsing SDP" and
1267 * retry using ICEv19. */
1268 ms_diag = sipmsg_find_header(msg, "ms-diagnostics");
1269 if (ms_diag && g_str_has_prefix(ms_diag, "7008;")) {
1270 retry_ice_version = SIPE_ICE_RFC_5245;
1273 if (maybe_retry_call_with_ice_version(sipe_private, retry_ice_version, trans)) {
1274 return TRUE;
1276 // Break intentionally omitted
1278 default:
1279 title = _("Error occured");
1280 g_string_append(desc, _("Unable to establish a call"));
1281 append_responsestr = TRUE;
1282 break;
1285 if (append_responsestr) {
1286 gchar *reason = sipmsg_get_ms_diagnostics_reason(msg);
1288 g_string_append_printf(desc, "\n%d %s",
1289 msg->response, msg->responsestr);
1290 if (reason) {
1291 g_string_append_printf(desc, "\n\n%s", reason);
1292 g_free(reason);
1296 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, desc->str);
1297 g_string_free(desc, TRUE);
1299 sipe_media_send_ack(sipe_private, msg, trans);
1300 sipe_media_hangup(call_private);
1302 return TRUE;
1305 sipe_dialog_parse(dialog, msg, TRUE);
1306 smsg = sdpmsg_parse_msg(msg->body);
1307 if (!smsg) {
1308 sip_transport_response(sipe_private, msg,
1309 488, "Not Acceptable Here", NULL);
1310 sipe_media_hangup(call_private);
1311 return FALSE;
1314 apply_remote_message(call_private, smsg);
1315 sdpmsg_free(smsg);
1317 sipe_media_send_ack(sipe_private, msg, trans);
1318 reinvite_on_candidate_pair_cb(SIPE_CORE_PUBLIC);
1320 return TRUE;
1323 gboolean is_media_session_msg(struct sipe_media_call_private *call_private,
1324 struct sipmsg *msg)
1326 if (call_private) {
1327 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1328 struct sip_session *session;
1330 session = sipe_session_find_call(call_private->sipe_private,
1331 call_private->with);
1332 if (session) {
1333 struct sip_dialog *dialog = session->dialogs->data;
1334 return sipe_strequal(dialog->callid, callid);
1337 return FALSE;
1340 void sipe_media_handle_going_offline(struct sipe_media_call_private *call_private)
1342 struct sipe_backend_media *backend_private;
1344 backend_private = call_private->public.backend_private;
1346 if ( !sipe_backend_media_is_initiator(backend_private, NULL)
1347 && !sipe_backend_media_accepted(backend_private)) {
1348 sip_transport_response(call_private->sipe_private,
1349 call_private->invitation,
1350 480, "Temporarily Unavailable", NULL);
1351 } else {
1352 struct sip_session *session;
1354 session = sipe_session_find_call(call_private->sipe_private,
1355 call_private->with);
1356 if (session)
1357 sipe_session_close(call_private->sipe_private, session);
1360 sipe_media_hangup(call_private);
1363 gboolean sipe_media_is_conference_call(struct sipe_media_call_private *call_private)
1365 return g_strstr_len(call_private->with, -1, "app:conf:audio-video:") != NULL;
1368 static void
1369 sipe_media_relay_free(struct sipe_media_relay *relay)
1371 g_free(relay->hostname);
1372 if (relay->dns_query)
1373 sipe_backend_dns_query_cancel(relay->dns_query);
1374 g_free(relay);
1377 void
1378 sipe_media_relay_list_free(GSList *list)
1380 for (; list; list = g_slist_delete_link(list, list))
1381 sipe_media_relay_free(list->data);
1384 static void
1385 relay_ip_resolved_cb(struct sipe_media_relay* relay,
1386 const gchar *ip, SIPE_UNUSED_PARAMETER guint port)
1388 gchar *hostname = relay->hostname;
1389 relay->dns_query = NULL;
1391 if (ip && port) {
1392 relay->hostname = g_strdup(ip);
1393 SIPE_DEBUG_INFO("Media relay %s resolved to %s.", hostname, ip);
1394 } else {
1395 relay->hostname = NULL;
1396 SIPE_DEBUG_INFO("Unable to resolve media relay %s.", hostname);
1399 g_free(hostname);
1402 static gboolean
1403 process_get_av_edge_credentials_response(struct sipe_core_private *sipe_private,
1404 struct sipmsg *msg,
1405 SIPE_UNUSED_PARAMETER struct transaction *trans)
1407 g_free(sipe_private->media_relay_username);
1408 g_free(sipe_private->media_relay_password);
1409 sipe_media_relay_list_free(sipe_private->media_relays);
1410 sipe_private->media_relay_username = NULL;
1411 sipe_private->media_relay_password = NULL;
1412 sipe_private->media_relays = NULL;
1414 if (msg->response >= 400) {
1415 SIPE_DEBUG_INFO_NOFORMAT("process_get_av_edge_credentials_response: SERVICE response is not 200. "
1416 "Failed to obtain A/V Edge credentials.");
1417 return FALSE;
1420 if (msg->response == 200) {
1421 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
1423 if (sipe_strequal("OK", sipe_xml_attribute(xn_response, "reasonPhrase"))) {
1424 const sipe_xml *xn_credentials = sipe_xml_child(xn_response, "credentialsResponse/credentials");
1425 const sipe_xml *xn_relays = sipe_xml_child(xn_response, "credentialsResponse/mediaRelayList");
1426 const sipe_xml *item;
1427 GSList *relays = NULL;
1429 item = sipe_xml_child(xn_credentials, "username");
1430 sipe_private->media_relay_username = sipe_xml_data(item);
1431 item = sipe_xml_child(xn_credentials, "password");
1432 sipe_private->media_relay_password = sipe_xml_data(item);
1434 for (item = sipe_xml_child(xn_relays, "mediaRelay"); item; item = sipe_xml_twin(item)) {
1435 struct sipe_media_relay *relay = g_new0(struct sipe_media_relay, 1);
1436 const sipe_xml *node;
1437 gchar *tmp;
1439 node = sipe_xml_child(item, "hostName");
1440 relay->hostname = sipe_xml_data(node);
1442 node = sipe_xml_child(item, "udpPort");
1443 if (node) {
1444 relay->udp_port = atoi(tmp = sipe_xml_data(node));
1445 g_free(tmp);
1448 node = sipe_xml_child(item, "tcpPort");
1449 if (node) {
1450 relay->tcp_port = atoi(tmp = sipe_xml_data(node));
1451 g_free(tmp);
1454 relays = g_slist_append(relays, relay);
1456 relay->dns_query = sipe_backend_dns_query_a(
1457 SIPE_CORE_PUBLIC,
1458 relay->hostname,
1459 relay->udp_port,
1460 (sipe_dns_resolved_cb) relay_ip_resolved_cb,
1461 relay);
1463 SIPE_DEBUG_INFO("Media relay: %s TCP: %d UDP: %d",
1464 relay->hostname,
1465 relay->tcp_port, relay->udp_port);
1468 sipe_private->media_relays = relays;
1471 sipe_xml_free(xn_response);
1474 return TRUE;
1477 void
1478 sipe_media_get_av_edge_credentials(struct sipe_core_private *sipe_private)
1480 // TODO: re-request credentials after duration expires?
1481 const char CRED_REQUEST_XML[] =
1482 "<request requestID=\"%d\" "
1483 "from=\"%s\" "
1484 "version=\"1.0\" "
1485 "to=\"%s\" "
1486 "xmlns=\"http://schemas.microsoft.com/2006/09/sip/mrasp\" "
1487 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
1488 "<credentialsRequest credentialsRequestID=\"%d\">"
1489 "<identity>%s</identity>"
1490 "<location>%s</location>"
1491 "<duration>480</duration>"
1492 "</credentialsRequest>"
1493 "</request>";
1495 int request_id = rand();
1496 gchar *self;
1497 gchar *body;
1499 if (!sipe_private->mras_uri)
1500 return;
1502 self = sip_uri_self(sipe_private);
1504 body = g_strdup_printf(
1505 CRED_REQUEST_XML,
1506 request_id,
1507 self,
1508 sipe_private->mras_uri,
1509 request_id,
1510 self,
1511 SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER) ? "internet" : "intranet");
1512 g_free(self);
1514 sip_transport_service(sipe_private,
1515 sipe_private->mras_uri,
1516 "Content-Type: application/msrtc-media-relay-auth+xml\r\n",
1517 body,
1518 process_get_av_edge_credentials_response);
1520 g_free(body);
1524 Local Variables:
1525 mode: c
1526 c-file-style: "bsd"
1527 indent-tabs-mode: t
1528 tab-width: 8
1529 End: