Fix #258: V&V call gets rejected when IPv6 is enabled (III)
[siplcs.git] / src / core / sipe-media.c
blobd674c5ce49db0992b6a56e7a2f6136131a01fa03
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 *ip = g_strdup(candidate->ip);
171 } else if (!sipe_strequal(*ip, candidate->ip)) {
172 continue;
175 if (candidate->component == SIPE_COMPONENT_RTP) {
176 *rtp_port = candidate->port;
177 } else if (candidate->component == SIPE_COMPONENT_RTCP)
178 *rtcp_port = candidate->port;
181 if (*rtp_port != 0 && *rtcp_port != 0)
182 return;
186 static gint
187 sdpcodec_compare(gconstpointer a, gconstpointer b)
189 return ((const struct sdpcodec *)a)->id -
190 ((const struct sdpcodec *)b)->id;
193 static struct sdpmedia *
194 backend_stream_to_sdpmedia(struct sipe_backend_media *backend_media,
195 struct sipe_backend_stream *backend_stream)
197 struct sdpmedia *media = g_new0(struct sdpmedia, 1);
198 GList *codecs = sipe_backend_get_local_codecs(backend_media,
199 backend_stream);
200 guint rtcp_port = 0;
201 SipeMediaType type;
202 GSList *attributes = NULL;
203 GList *candidates;
204 GList *i;
206 media->name = g_strdup(sipe_backend_stream_get_id(backend_stream));
208 if (sipe_strequal(media->name, "audio"))
209 type = SIPE_MEDIA_AUDIO;
210 else if (sipe_strequal(media->name, "video"))
211 type = SIPE_MEDIA_VIDEO;
212 else {
213 // TODO: incompatible media, should not happen here
214 g_free(media->name);
215 g_free(media);
216 sipe_media_codec_list_free(codecs);
217 return(NULL);
220 // Process codecs
221 for (i = codecs; i; i = i->next) {
222 struct sipe_backend_codec *codec = i->data;
223 struct sdpcodec *c = g_new0(struct sdpcodec, 1);
224 GList *params;
226 c->id = sipe_backend_codec_get_id(codec);
227 c->name = sipe_backend_codec_get_name(codec);
228 c->clock_rate = sipe_backend_codec_get_clock_rate(codec);
229 c->type = type;
231 params = sipe_backend_codec_get_optional_parameters(codec);
232 for (; params; params = params->next) {
233 struct sipnameval *param = params->data;
234 struct sipnameval *copy = g_new0(struct sipnameval, 1);
236 copy->name = g_strdup(param->name);
237 copy->value = g_strdup(param->value);
239 c->parameters = g_slist_append(c->parameters, copy);
242 /* Buggy(?) codecs may report non-unique id (a.k.a. payload
243 * type) that must not appear in SDP messages we send. Thus,
244 * let's ignore any codec having the same id as one we already
245 * have in the converted list. */
246 media->codecs = sipe_utils_slist_insert_unique_sorted(
247 media->codecs, c, sdpcodec_compare,
248 (GDestroyNotify)sdpcodec_free);
251 sipe_media_codec_list_free(codecs);
253 // Process local candidates
254 // If we have established candidate pairs, send them in SDP response.
255 // Otherwise send all available local candidates.
256 candidates = sipe_backend_media_get_active_local_candidates(backend_media,
257 backend_stream);
258 if (!candidates)
259 candidates = sipe_backend_get_local_candidates(backend_media,
260 backend_stream);
262 media->candidates = backend_candidates_to_sdpcandidate(candidates);
264 sipe_media_candidate_list_free(candidates);
266 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
267 &rtcp_port, SIPE_CANDIDATE_TYPE_HOST);
268 // No usable HOST candidates, use any candidate
269 if (media->ip == NULL && media->candidates) {
270 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
271 &rtcp_port, SIPE_CANDIDATE_TYPE_ANY);
274 if (sipe_backend_stream_is_held(backend_stream))
275 attributes = sipe_utils_nameval_add(attributes, "inactive", "");
277 if (rtcp_port) {
278 gchar *tmp = g_strdup_printf("%u", rtcp_port);
279 attributes = sipe_utils_nameval_add(attributes, "rtcp", tmp);
280 g_free(tmp);
283 attributes = sipe_utils_nameval_add(attributes, "encryption", "rejected");
285 media->attributes = attributes;
287 // Process remote candidates
288 candidates = sipe_backend_media_get_active_remote_candidates(backend_media,
289 backend_stream);
290 media->remote_candidates = backend_candidates_to_sdpcandidate(candidates);
291 sipe_media_candidate_list_free(candidates);
293 return media;
296 static struct sdpmsg *
297 sipe_media_to_sdpmsg(struct sipe_media_call_private *call_private)
299 struct sipe_backend_media *backend_media = call_private->public.backend_private;
300 struct sdpmsg *msg = g_new0(struct sdpmsg, 1);
301 GSList *streams = sipe_backend_media_get_streams(backend_media);
303 for (; streams; streams = streams->next) {
304 struct sdpmedia *media = backend_stream_to_sdpmedia(backend_media, streams->data);
305 if (media) {
306 msg->media = g_slist_append(msg->media, media);
308 if (msg->ip == NULL)
309 msg->ip = g_strdup(media->ip);
313 msg->media = g_slist_concat(msg->media, call_private->failed_media);
314 call_private->failed_media = NULL;
316 msg->ice_version = call_private->ice_version;
318 return msg;
321 static void
322 sipe_invite_call(struct sipe_core_private *sipe_private, TransCallback tc)
324 gchar *hdr;
325 gchar *contact;
326 gchar *p_preferred_identity = NULL;
327 gchar *body;
328 struct sipe_media_call_private *call_private = sipe_private->media_call;
329 struct sip_session *session;
330 struct sip_dialog *dialog;
331 struct sdpmsg *msg;
332 gboolean add_2007_fallback = FALSE;
334 session = sipe_session_find_call(sipe_private, call_private->with);
335 dialog = session->dialogs->data;
336 add_2007_fallback = dialog->cseq == 0 &&
337 call_private->ice_version == SIPE_ICE_RFC_5245 &&
338 !sipe_strequal(call_private->with, sipe_private->test_call_bot_uri);
340 contact = get_contact(sipe_private);
342 if (sipe_private->uc_line_uri) {
343 gchar *self = sip_uri_self(sipe_private);
344 p_preferred_identity = g_strdup_printf(
345 "P-Preferred-Identity: <%s>, <%s>\r\n",
346 self, sipe_private->uc_line_uri);
347 g_free(self);
350 hdr = g_strdup_printf(
351 "ms-keep-alive: UAC;hop-hop=yes\r\n"
352 "Contact: %s\r\n"
353 "%s"
354 "Content-Type: %s\r\n",
355 contact,
356 p_preferred_identity ? p_preferred_identity : "",
357 add_2007_fallback ?
358 "multipart/alternative;boundary=\"----=_NextPart_000_001E_01CB4397.0B5EB570\""
359 : "application/sdp");
360 g_free(contact);
361 g_free(p_preferred_identity);
363 msg = sipe_media_to_sdpmsg(call_private);
364 body = sdpmsg_to_string(msg);
366 if (add_2007_fallback) {
367 gchar *tmp;
368 tmp = g_strdup_printf(
369 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
370 "Content-Type: application/sdp\r\n"
371 "Content-Transfer-Encoding: 7bit\r\n"
372 "Content-Disposition: session; handling=optional; ms-proxy-2007fallback\r\n"
373 "\r\n"
374 "o=- 0 0 IN IP4 %s\r\n"
375 "s=session\r\n"
376 "c=IN IP4 %s\r\n"
377 "m=audio 0 RTP/AVP\r\n"
378 "\r\n"
379 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
380 "Content-Type: application/sdp\r\n"
381 "Content-Transfer-Encoding: 7bit\r\n"
382 "Content-Disposition: session; handling=optional\r\n"
383 "\r\n"
384 "%s"
385 "\r\n"
386 "------=_NextPart_000_001E_01CB4397.0B5EB570--\r\n",
387 msg->ip, msg->ip, body);
388 g_free(body);
389 body = tmp;
392 sdpmsg_free(msg);
394 dialog->outgoing_invite = sip_transport_invite(sipe_private,
395 hdr,
396 body,
397 dialog,
398 tc);
400 g_free(body);
401 g_free(hdr);
404 static struct sip_dialog *
405 sipe_media_dialog_init(struct sip_session* session, struct sipmsg *msg)
407 gchar *newTag = gentag();
408 const gchar *oldHeader;
409 gchar *newHeader;
410 struct sip_dialog *dialog;
412 oldHeader = sipmsg_find_header(msg, "To");
413 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
414 sipmsg_remove_header_now(msg, "To");
415 sipmsg_add_header_now(msg, "To", newHeader);
416 g_free(newHeader);
418 dialog = sipe_dialog_add(session);
419 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
420 dialog->with = parse_from(sipmsg_find_header(msg, "From"));
421 sipe_dialog_parse(dialog, msg, FALSE);
423 return dialog;
426 static void
427 send_response_with_session_description(struct sipe_media_call_private *call_private, int code, gchar *text)
429 struct sdpmsg *msg = sipe_media_to_sdpmsg(call_private);
430 gchar *body = sdpmsg_to_string(msg);
431 sdpmsg_free(msg);
432 sipmsg_add_header(call_private->invitation, "Content-Type", "application/sdp");
433 sip_transport_response(call_private->sipe_private, call_private->invitation, code, text, body);
434 g_free(body);
437 static gboolean
438 encryption_levels_compatible(struct sdpmsg *msg)
440 GSList *i;
442 for (i = msg->media; i; i = i->next) {
443 const gchar *enc_level;
444 struct sdpmedia *m = i->data;
446 enc_level = sipe_utils_nameval_find(m->attributes, "encryption");
448 // Decline call if peer requires encryption as we don't support it yet.
449 if (sipe_strequal(enc_level, "required"))
450 return FALSE;
453 return TRUE;
456 static gboolean
457 process_invite_call_response(struct sipe_core_private *sipe_private,
458 struct sipmsg *msg,
459 struct transaction *trans);
461 static gboolean
462 update_remote_media(struct sipe_media_call_private* call_private,
463 struct sdpmedia *media)
465 struct sipe_backend_media *backend_media = SIPE_MEDIA_CALL->backend_private;
466 struct sipe_backend_stream *backend_stream;
467 GList *backend_candidates = NULL;
468 GList *backend_codecs = NULL;
469 GSList *i;
470 gboolean result = TRUE;
472 backend_stream = sipe_backend_media_get_stream_by_id(backend_media,
473 media->name);
474 if (media->port == 0) {
475 if (backend_stream)
476 sipe_backend_media_remove_stream(backend_media, backend_stream);
477 return TRUE;
480 if (!backend_stream)
481 return FALSE;
483 for (i = media->codecs; i; i = i->next) {
484 struct sdpcodec *c = i->data;
485 struct sipe_backend_codec *codec;
486 GSList *j;
488 codec = sipe_backend_codec_new(c->id,
489 c->name,
490 c->type,
491 c->clock_rate);
493 for (j = c->parameters; j; j = j->next) {
494 struct sipnameval *attr = j->data;
496 sipe_backend_codec_add_optional_parameter(codec,
497 attr->name,
498 attr->value);
501 backend_codecs = g_list_append(backend_codecs, codec);
504 result = sipe_backend_set_remote_codecs(backend_media,
505 backend_stream,
506 backend_codecs);
507 sipe_media_codec_list_free(backend_codecs);
509 if (result == FALSE) {
510 sipe_backend_media_remove_stream(backend_media, backend_stream);
511 return FALSE;
514 for (i = media->candidates; i; i = i->next) {
515 struct sdpcandidate *c = i->data;
516 struct sipe_backend_candidate *candidate;
517 candidate = sipe_backend_candidate_new(c->foundation,
518 c->component,
519 c->type,
520 c->protocol,
521 c->ip,
522 c->port,
523 c->username,
524 c->password);
525 sipe_backend_candidate_set_priority(candidate, c->priority);
527 backend_candidates = g_list_append(backend_candidates, candidate);
530 sipe_backend_media_add_remote_candidates(backend_media,
531 backend_stream,
532 backend_candidates);
533 sipe_media_candidate_list_free(backend_candidates);
535 if (sipe_utils_nameval_find(media->attributes, "inactive")) {
536 sipe_backend_stream_hold(backend_media, backend_stream, FALSE);
537 } else if (sipe_backend_stream_is_held(backend_stream)) {
538 sipe_backend_stream_unhold(backend_media, backend_stream, FALSE);
541 return TRUE;
544 static void
545 apply_remote_message(struct sipe_media_call_private* call_private,
546 struct sdpmsg* msg)
548 GSList *i;
550 sipe_utils_slist_free_full(call_private->failed_media, (GDestroyNotify)sdpmedia_free);
551 call_private->failed_media = NULL;
553 for (i = msg->media; i; i = i->next) {
554 struct sdpmedia *media = i->data;
555 if (!update_remote_media(call_private, media)) {
556 media->port = 0;
557 call_private->failed_media =
558 g_slist_append(call_private->failed_media, media);
562 /* We need to keep failed medias until response is sent, remove them
563 * from sdpmsg that is to be freed. */
564 for (i = call_private->failed_media; i; i = i->next) {
565 msg->media = g_slist_remove(msg->media, i->data);
568 call_private->encryption_compatible = encryption_levels_compatible(msg);
571 static gboolean
572 call_initialized(struct sipe_media_call *call)
574 GSList *streams =
575 sipe_backend_media_get_streams(call->backend_private);
577 for (; streams; streams = streams->next) {
578 if (!sipe_backend_stream_initialized(call->backend_private,
579 streams->data)) {
580 return FALSE;
584 return TRUE;
587 // Sends an invite response when the call is accepted and local candidates were
588 // prepared, otherwise does nothing. If error response is sent, call_private is
589 // disposed before function returns. Returns true when response was sent.
590 static gboolean
591 send_invite_response_if_ready(struct sipe_media_call_private *call_private)
593 struct sipe_backend_media *backend_media;
595 backend_media = call_private->public.backend_private;
597 if (!sipe_backend_media_accepted(backend_media) ||
598 !call_initialized(&call_private->public))
599 return FALSE;
601 if (!call_private->encryption_compatible) {
602 struct sipe_core_private *sipe_private = call_private->sipe_private;
604 sipmsg_add_header(call_private->invitation, "Warning",
605 "308 lcs.microsoft.com \"Encryption Levels not compatible\"");
606 sip_transport_response(sipe_private,
607 call_private->invitation,
608 488, "Encryption Levels not compatible",
609 NULL);
610 sipe_backend_media_reject(backend_media, FALSE);
611 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
612 _("Unable to establish a call"),
613 _("Encryption settings of peer are incompatible with ours."));
614 } else {
615 send_response_with_session_description(call_private, 200, "OK");
618 return TRUE;
621 static void
622 stream_initialized_cb(struct sipe_media_call *call,
623 struct sipe_backend_stream *stream)
625 if (call_initialized(call)) {
626 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
627 struct sipe_backend_media *backend_private = call->backend_private;
629 if (sipe_backend_media_is_initiator(backend_private, stream)) {
630 sipe_invite_call(call_private->sipe_private,
631 process_invite_call_response);
632 } else if (call_private->smsg) {
633 struct sdpmsg *smsg = call_private->smsg;
634 call_private->smsg = NULL;
636 apply_remote_message(call_private, smsg);
637 send_invite_response_if_ready(call_private);
638 sdpmsg_free(smsg);
643 static void phone_state_publish(struct sipe_core_private *sipe_private)
645 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) {
646 sipe_ocs2007_phone_state_publish(sipe_private);
647 } else {
648 // TODO: OCS 2005 support. Is anyone still using it at all?
652 static void
653 media_end_cb(struct sipe_media_call *call)
655 g_return_if_fail(call);
657 SIPE_MEDIA_CALL_PRIVATE->sipe_private->media_call = NULL;
658 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
659 sipe_media_call_free(SIPE_MEDIA_CALL_PRIVATE);
662 static void
663 call_accept_cb(struct sipe_media_call *call, gboolean local)
665 if (local) {
666 send_invite_response_if_ready(SIPE_MEDIA_CALL_PRIVATE);
668 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
671 static void
672 call_reject_cb(struct sipe_media_call *call, gboolean local)
674 if (local) {
675 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
676 sip_transport_response(call_private->sipe_private,
677 call_private->invitation,
678 603, "Decline", NULL);
682 static gboolean
683 sipe_media_send_ack(struct sipe_core_private *sipe_private, struct sipmsg *msg,
684 struct transaction *trans);
686 static void call_hold_cb(struct sipe_media_call *call,
687 gboolean local,
688 SIPE_UNUSED_PARAMETER gboolean state)
690 if (local)
691 sipe_invite_call(SIPE_MEDIA_CALL_PRIVATE->sipe_private,
692 sipe_media_send_ack);
695 static void call_hangup_cb(struct sipe_media_call *call, gboolean local)
697 if (local) {
698 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
699 struct sip_session *session;
700 session = sipe_session_find_call(call_private->sipe_private,
701 call_private->with);
703 if (session) {
704 sipe_session_close(call_private->sipe_private, session);
709 static void
710 error_cb(struct sipe_media_call *call, gchar *message)
712 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
713 struct sipe_core_private *sipe_private = call_private->sipe_private;
714 gboolean initiator = sipe_backend_media_is_initiator(call->backend_private, NULL);
715 gboolean accepted = sipe_backend_media_accepted(call->backend_private);
717 gchar *title = g_strdup_printf("Call with %s failed", call_private->with);
718 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, message);
719 g_free(title);
721 if (!initiator && !accepted) {
722 sip_transport_response(sipe_private,
723 call_private->invitation,
724 488, "Not Acceptable Here", NULL);
727 sipe_backend_media_hangup(call->backend_private, initiator || accepted);
730 static struct sipe_media_call_private *
731 sipe_media_call_new(struct sipe_core_private *sipe_private,
732 const gchar* with, gboolean initiator, SipeIceVersion ice_version)
734 struct sipe_media_call_private *call_private = g_new0(struct sipe_media_call_private, 1);
735 gchar *cname;
737 call_private->sipe_private = sipe_private;
739 cname = g_strdup(sipe_private->contact + 1);
740 cname[strlen(cname) - 1] = '\0';
742 call_private->public.backend_private = sipe_backend_media_new(SIPE_CORE_PUBLIC,
743 SIPE_MEDIA_CALL,
744 with,
745 initiator);
746 sipe_backend_media_set_cname(call_private->public.backend_private, cname);
748 call_private->ice_version = ice_version;
749 call_private->encryption_compatible = TRUE;
751 call_private->public.stream_initialized_cb = stream_initialized_cb;
752 call_private->public.media_end_cb = media_end_cb;
753 call_private->public.call_accept_cb = call_accept_cb;
754 call_private->public.call_reject_cb = call_reject_cb;
755 call_private->public.call_hold_cb = call_hold_cb;
756 call_private->public.call_hangup_cb = call_hangup_cb;
757 call_private->public.error_cb = error_cb;
759 g_free(cname);
761 return call_private;
764 void sipe_media_hangup(struct sipe_media_call_private *call_private)
766 if (call_private) {
767 sipe_backend_media_hangup(call_private->public.backend_private,
768 FALSE);
772 static void
773 sipe_media_initiate_call(struct sipe_core_private *sipe_private,
774 const char *with, SipeIceVersion ice_version,
775 gboolean with_video)
777 struct sipe_media_call_private *call_private;
778 struct sipe_backend_media *backend_media;
779 struct sipe_backend_media_relays *backend_media_relays;
780 struct sip_session *session;
781 struct sip_dialog *dialog;
783 if (sipe_private->media_call)
784 return;
786 call_private = sipe_media_call_new(sipe_private, with, TRUE, ice_version);
788 session = sipe_session_add_call(sipe_private, with);
789 dialog = sipe_dialog_add(session);
790 dialog->callid = gencallid();
791 dialog->with = g_strdup(session->with);
792 dialog->ourtag = gentag();
794 call_private->with = g_strdup(session->with);
796 backend_media = call_private->public.backend_private;
798 backend_media_relays =
799 sipe_backend_media_relays_convert(sipe_private->media_relays,
800 sipe_private->media_relay_username,
801 sipe_private->media_relay_password);
803 if (!sipe_backend_media_add_stream(backend_media,
804 "audio", with, SIPE_MEDIA_AUDIO,
805 call_private->ice_version, TRUE,
806 backend_media_relays)) {
807 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
808 _("Error occured"),
809 _("Error creating audio stream"));
810 sipe_media_hangup(call_private);
811 sipe_backend_media_relays_free(backend_media_relays);
812 return;
815 if ( with_video
816 && !sipe_backend_media_add_stream(backend_media,
817 "video", with, SIPE_MEDIA_VIDEO,
818 call_private->ice_version, TRUE,
819 backend_media_relays)) {
820 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
821 _("Error occured"),
822 _("Error creating video stream"));
823 sipe_media_hangup(call_private);
824 sipe_backend_media_relays_free(backend_media_relays);
825 return;
828 sipe_private->media_call = call_private;
830 sipe_backend_media_relays_free(backend_media_relays);
832 // Processing continues in stream_initialized_cb
835 void
836 sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
837 const char *with,
838 gboolean with_video)
840 sipe_media_initiate_call(SIPE_CORE_PRIVATE, with,
841 SIPE_ICE_RFC_5245, with_video);
844 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
845 struct sipe_chat_session *chat_session)
847 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
848 struct sipe_backend_media_relays *backend_media_relays;
849 struct sip_session *session;
850 struct sip_dialog *dialog;
851 SipeIceVersion ice_version;
852 gchar **parts;
853 gchar *av_uri;
855 session = sipe_session_find_chat(sipe_private, chat_session);
857 if (sipe_private->media_call || !session)
858 return;
860 session->is_call = TRUE;
862 parts = g_strsplit(chat_session->id, "app:conf:focus:", 2);
863 av_uri = g_strjoinv("app:conf:audio-video:", parts);
864 g_strfreev(parts);
866 ice_version = SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013) ? SIPE_ICE_RFC_5245 :
867 SIPE_ICE_DRAFT_6;
869 sipe_private->media_call = sipe_media_call_new(sipe_private, av_uri,
870 TRUE, ice_version);
872 session = sipe_session_add_call(sipe_private, av_uri);
873 dialog = sipe_dialog_add(session);
874 dialog->callid = gencallid();
875 dialog->with = g_strdup(session->with);
876 dialog->ourtag = gentag();
878 g_free(av_uri);
880 sipe_private->media_call->with = g_strdup(session->with);
882 backend_media_relays =
883 sipe_backend_media_relays_convert(sipe_private->media_relays,
884 sipe_private->media_relay_username,
885 sipe_private->media_relay_password);
887 if (!sipe_backend_media_add_stream(sipe_private->media_call->public.backend_private,
888 "audio", dialog->with,
889 SIPE_MEDIA_AUDIO,
890 sipe_private->media_call->ice_version,
891 TRUE, backend_media_relays)) {
892 sipe_backend_notify_error(sipe_public,
893 _("Error occured"),
894 _("Error creating audio stream"));
895 sipe_media_hangup(sipe_private->media_call);
896 sipe_private->media_call = NULL;
899 sipe_backend_media_relays_free(backend_media_relays);
901 // Processing continues in stream_initialized_cb
904 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public)
906 if (sipe_public) {
907 return SIPE_CORE_PRIVATE->media_call != NULL;
909 return FALSE;
912 static gboolean phone_number_is_valid(const gchar *phone_number)
914 if (!phone_number || sipe_strequal(phone_number, "")) {
915 return FALSE;
918 if (*phone_number == '+') {
919 ++phone_number;
922 while (*phone_number != '\0') {
923 if (!g_ascii_isdigit(*phone_number)) {
924 return FALSE;
926 ++phone_number;
929 return TRUE;
932 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
933 const gchar *phone_number)
935 g_return_if_fail(sipe_public);
937 if (phone_number_is_valid(phone_number)) {
938 gchar *phone_uri = g_strdup_printf("sip:%s@%s;user=phone",
939 phone_number, sipe_public->sip_domain);
941 sipe_core_media_initiate_call(sipe_public, phone_uri, FALSE);
943 g_free(phone_uri);
944 } else {
945 sipe_backend_notify_error(sipe_public,
946 _("Unable to establish a call"),
947 _("Invalid phone number"));
951 void sipe_core_media_test_call(struct sipe_core_public *sipe_public)
953 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
954 if (!sipe_private->test_call_bot_uri) {
955 sipe_backend_notify_error(sipe_public,
956 _("Unable to establish a call"),
957 _("Audio Test Service is not available."));
958 return;
961 sipe_core_media_initiate_call(sipe_public,
962 sipe_private->test_call_bot_uri, FALSE);
965 void
966 process_incoming_invite_call(struct sipe_core_private *sipe_private,
967 struct sipmsg *msg)
969 struct sipe_media_call_private *call_private = sipe_private->media_call;
970 struct sipe_backend_media *backend_media;
971 struct sipe_backend_media_relays *backend_media_relays = NULL;
972 struct sdpmsg *smsg;
973 gboolean has_new_media = FALSE;
974 GSList *i;
976 if (call_private) {
977 char *self;
979 if (!is_media_session_msg(call_private, msg)) {
980 sip_transport_response(sipe_private, msg, 486, "Busy Here", NULL);
981 return;
984 self = sip_uri_self(sipe_private);
985 if (sipe_strequal(call_private->with, self)) {
986 g_free(self);
987 sip_transport_response(sipe_private, msg, 488, "Not Acceptable Here", NULL);
988 return;
990 g_free(self);
993 smsg = sdpmsg_parse_msg(msg->body);
994 if (!smsg) {
995 sip_transport_response(sipe_private, msg,
996 488, "Not Acceptable Here", NULL);
997 sipe_media_hangup(call_private);
998 return;
1001 if (!call_private) {
1002 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
1003 struct sip_session *session;
1005 call_private = sipe_media_call_new(sipe_private, with, FALSE, smsg->ice_version);
1006 session = sipe_session_add_call(sipe_private, with);
1007 sipe_media_dialog_init(session, msg);
1009 call_private->with = g_strdup(session->with);
1010 sipe_private->media_call = call_private;
1011 g_free(with);
1014 backend_media = call_private->public.backend_private;
1016 if (call_private->invitation)
1017 sipmsg_free(call_private->invitation);
1018 call_private->invitation = sipmsg_copy(msg);
1020 if (smsg->media)
1021 backend_media_relays = sipe_backend_media_relays_convert(
1022 sipe_private->media_relays,
1023 sipe_private->media_relay_username,
1024 sipe_private->media_relay_password);
1026 // Create any new media streams
1027 for (i = smsg->media; i; i = i->next) {
1028 struct sdpmedia *media = i->data;
1029 gchar *id = media->name;
1030 SipeMediaType type;
1032 if ( media->port != 0
1033 && !sipe_backend_media_get_stream_by_id(backend_media, id)) {
1034 gchar *with;
1036 if (sipe_strequal(id, "audio"))
1037 type = SIPE_MEDIA_AUDIO;
1038 else if (sipe_strequal(id, "video"))
1039 type = SIPE_MEDIA_VIDEO;
1040 else
1041 continue;
1043 with = parse_from(sipmsg_find_header(msg, "From"));
1044 sipe_backend_media_add_stream(backend_media, id, with,
1045 type,
1046 smsg->ice_version,
1047 FALSE,
1048 backend_media_relays);
1049 has_new_media = TRUE;
1050 g_free(with);
1054 sipe_backend_media_relays_free(backend_media_relays);
1056 if (has_new_media) {
1057 sdpmsg_free(call_private->smsg);
1058 call_private->smsg = smsg;
1059 sip_transport_response(sipe_private, call_private->invitation,
1060 180, "Ringing", NULL);
1061 // Processing continues in stream_initialized_cb
1062 } else {
1063 apply_remote_message(call_private, smsg);
1064 send_response_with_session_description(call_private, 200, "OK");
1066 sdpmsg_free(smsg);
1070 void process_incoming_cancel_call(struct sipe_core_private *sipe_private,
1071 struct sipmsg *msg)
1073 struct sipe_media_call_private *call_private = sipe_private->media_call;
1075 // We respond to the CANCEL request with 200 OK response and
1076 // with 487 Request Terminated to the remote INVITE in progress.
1077 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1079 if (call_private->invitation) {
1080 sip_transport_response(sipe_private, call_private->invitation,
1081 487, "Request Terminated", NULL);
1084 sipe_media_hangup(call_private);
1087 static gboolean
1088 sipe_media_send_ack(struct sipe_core_private *sipe_private,
1089 struct sipmsg *msg,
1090 struct transaction *trans)
1092 struct sipe_media_call_private *call_private = sipe_private->media_call;
1093 struct sip_session *session;
1094 struct sip_dialog *dialog;
1095 int tmp_cseq;
1097 if (!is_media_session_msg(call_private, msg))
1098 return FALSE;
1100 session = sipe_session_find_call(sipe_private, call_private->with);
1101 dialog = session->dialogs->data;
1102 if (!dialog)
1103 return FALSE;
1105 tmp_cseq = dialog->cseq;
1107 dialog->cseq = sip_transaction_cseq(trans) - 1;
1108 sip_transport_ack(sipe_private, dialog);
1109 dialog->cseq = tmp_cseq;
1111 dialog->outgoing_invite = NULL;
1113 return TRUE;
1116 static gboolean
1117 sipe_media_send_final_ack(struct sipe_core_private *sipe_private,
1118 struct sipmsg *msg,
1119 struct transaction *trans)
1121 if (!sipe_media_send_ack(sipe_private, msg, trans))
1122 return FALSE;
1124 sipe_backend_media_accept(sipe_private->media_call->public.backend_private,
1125 FALSE);
1127 return TRUE;
1130 static void
1131 reinvite_on_candidate_pair_cb(struct sipe_core_public *sipe_public)
1133 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1134 struct sipe_media_call_private *media_call = sipe_private->media_call;
1135 struct sipe_backend_media *backend_media;
1136 GSList *streams;
1138 if (!media_call)
1139 return;
1141 backend_media = media_call->public.backend_private;
1142 streams = sipe_backend_media_get_streams(backend_media);
1144 for (; streams; streams = streams->next) {
1145 struct sipe_backend_stream *s = streams->data;
1146 GList *remote_candidates = sipe_backend_media_get_active_remote_candidates(backend_media, s);
1147 guint components = g_list_length(remote_candidates);
1149 sipe_media_candidate_list_free(remote_candidates);
1151 // We must have candidates for both (RTP + RTCP) components ready
1152 if (components < 2) {
1153 sipe_schedule_mseconds(sipe_private,
1154 "<+media-reinvite-on-candidate-pair>",
1155 NULL,
1156 500,
1157 (sipe_schedule_action) reinvite_on_candidate_pair_cb,
1158 NULL);
1159 return;
1163 sipe_invite_call(sipe_private, sipe_media_send_final_ack);
1166 static gboolean
1167 maybe_retry_call_with_ice_version(struct sipe_core_private *sipe_private,
1168 SipeIceVersion ice_version,
1169 struct transaction *trans)
1171 struct sipe_media_call_private *call_private = sipe_private->media_call;
1173 if (call_private->ice_version != ice_version &&
1174 sip_transaction_cseq(trans) == 1) {
1175 gchar *with = g_strdup(call_private->with);
1176 struct sipe_backend_media *backend_private = call_private->public.backend_private;
1177 gboolean with_video = sipe_backend_media_get_stream_by_id(backend_private, "video") != NULL;
1179 sipe_media_hangup(call_private);
1180 SIPE_DEBUG_INFO("Retrying call with ICEv%d.",
1181 ice_version == SIPE_ICE_DRAFT_6 ? 6 : 19);
1182 sipe_media_initiate_call(sipe_private, with, ice_version,
1183 with_video);
1185 g_free(with);
1186 return TRUE;
1189 return FALSE;
1192 static gboolean
1193 process_invite_call_response(struct sipe_core_private *sipe_private,
1194 struct sipmsg *msg,
1195 struct transaction *trans)
1197 const gchar *with;
1198 struct sipe_media_call_private *call_private = sipe_private->media_call;
1199 struct sip_session *session;
1200 struct sip_dialog *dialog;
1201 struct sdpmsg *smsg;
1203 if (!is_media_session_msg(call_private, msg))
1204 return FALSE;
1206 session = sipe_session_find_call(sipe_private, call_private->with);
1207 dialog = session->dialogs->data;
1209 with = dialog->with;
1211 dialog->outgoing_invite = NULL;
1213 if (msg->response >= 400) {
1214 // Call rejected by remote peer or an error occurred
1215 const gchar *title;
1216 GString *desc = g_string_new("");
1217 gboolean append_responsestr = FALSE;
1219 switch (msg->response) {
1220 case 480: {
1221 title = _("User unavailable");
1223 if (sipmsg_parse_warning(msg, NULL) == 391) {
1224 g_string_append_printf(desc, _("%s does not want to be disturbed"), with);
1225 } else
1226 g_string_append_printf(desc, _("User %s is not available"), with);
1227 break;
1229 case 603:
1230 case 605:
1231 title = _("Call rejected");
1232 g_string_append_printf(desc, _("User %s rejected call"), with);
1233 break;
1234 case 415:
1235 // OCS/Lync really sends response string with 'Mutipart' typo.
1236 if (sipe_strequal(msg->responsestr, "Mutipart mime in content type not supported by Archiving CDR service") &&
1237 maybe_retry_call_with_ice_version(sipe_private, SIPE_ICE_DRAFT_6, trans)) {
1238 return TRUE;
1240 title = _("Unsupported media type");
1241 break;
1242 case 488: {
1243 /* Check for incompatible encryption levels error.
1245 * MS Lync 2010:
1246 * 488 Not Acceptable Here
1247 * ms-client-diagnostics: 52017;reason="Encryption levels dont match"
1249 * older clients (and SIPE itself):
1250 * 488 Encryption Levels not compatible
1252 const gchar *ms_diag = sipmsg_find_header(msg, "ms-client-diagnostics");
1253 SipeIceVersion retry_ice_version = SIPE_ICE_DRAFT_6;
1255 if (sipe_strequal(msg->responsestr, "Encryption Levels not compatible") ||
1256 (ms_diag && g_str_has_prefix(ms_diag, "52017;"))) {
1257 title = _("Unable to establish a call");
1258 g_string_append(desc, _("Encryption settings of peer are incompatible with ours."));
1259 break;
1262 /* Check if this is failed conference using
1263 * ICEv6 with reason "Error parsing SDP" and
1264 * retry using ICEv19. */
1265 ms_diag = sipmsg_find_header(msg, "ms-diagnostics");
1266 if (ms_diag && g_str_has_prefix(ms_diag, "7008;")) {
1267 retry_ice_version = SIPE_ICE_RFC_5245;
1270 if (maybe_retry_call_with_ice_version(sipe_private, retry_ice_version, trans)) {
1271 return TRUE;
1273 // Break intentionally omitted
1275 default:
1276 title = _("Error occured");
1277 g_string_append(desc, _("Unable to establish a call"));
1278 append_responsestr = TRUE;
1279 break;
1282 if (append_responsestr) {
1283 gchar *reason = sipmsg_get_ms_diagnostics_reason(msg);
1285 g_string_append_printf(desc, "\n%d %s",
1286 msg->response, msg->responsestr);
1287 if (reason) {
1288 g_string_append_printf(desc, "\n\n%s", reason);
1289 g_free(reason);
1293 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, desc->str);
1294 g_string_free(desc, TRUE);
1296 sipe_media_send_ack(sipe_private, msg, trans);
1297 sipe_media_hangup(call_private);
1299 return TRUE;
1302 sipe_dialog_parse(dialog, msg, TRUE);
1303 smsg = sdpmsg_parse_msg(msg->body);
1304 if (!smsg) {
1305 sip_transport_response(sipe_private, msg,
1306 488, "Not Acceptable Here", NULL);
1307 sipe_media_hangup(call_private);
1308 return FALSE;
1311 apply_remote_message(call_private, smsg);
1312 sdpmsg_free(smsg);
1314 sipe_media_send_ack(sipe_private, msg, trans);
1315 reinvite_on_candidate_pair_cb(SIPE_CORE_PUBLIC);
1317 return TRUE;
1320 gboolean is_media_session_msg(struct sipe_media_call_private *call_private,
1321 struct sipmsg *msg)
1323 if (call_private) {
1324 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1325 struct sip_session *session;
1327 session = sipe_session_find_call(call_private->sipe_private,
1328 call_private->with);
1329 if (session) {
1330 struct sip_dialog *dialog = session->dialogs->data;
1331 return sipe_strequal(dialog->callid, callid);
1334 return FALSE;
1337 void sipe_media_handle_going_offline(struct sipe_media_call_private *call_private)
1339 struct sipe_backend_media *backend_private;
1341 backend_private = call_private->public.backend_private;
1343 if ( !sipe_backend_media_is_initiator(backend_private, NULL)
1344 && !sipe_backend_media_accepted(backend_private)) {
1345 sip_transport_response(call_private->sipe_private,
1346 call_private->invitation,
1347 480, "Temporarily Unavailable", NULL);
1348 } else {
1349 struct sip_session *session;
1351 session = sipe_session_find_call(call_private->sipe_private,
1352 call_private->with);
1353 if (session)
1354 sipe_session_close(call_private->sipe_private, session);
1357 sipe_media_hangup(call_private);
1360 gboolean sipe_media_is_conference_call(struct sipe_media_call_private *call_private)
1362 return g_strstr_len(call_private->with, -1, "app:conf:audio-video:") != NULL;
1365 static void
1366 sipe_media_relay_free(struct sipe_media_relay *relay)
1368 g_free(relay->hostname);
1369 if (relay->dns_query)
1370 sipe_backend_dns_query_cancel(relay->dns_query);
1371 g_free(relay);
1374 void
1375 sipe_media_relay_list_free(GSList *list)
1377 for (; list; list = g_slist_delete_link(list, list))
1378 sipe_media_relay_free(list->data);
1381 static void
1382 relay_ip_resolved_cb(struct sipe_media_relay* relay,
1383 const gchar *ip, SIPE_UNUSED_PARAMETER guint port)
1385 gchar *hostname = relay->hostname;
1386 relay->dns_query = NULL;
1388 if (ip && port) {
1389 relay->hostname = g_strdup(ip);
1390 SIPE_DEBUG_INFO("Media relay %s resolved to %s.", hostname, ip);
1391 } else {
1392 relay->hostname = NULL;
1393 SIPE_DEBUG_INFO("Unable to resolve media relay %s.", hostname);
1396 g_free(hostname);
1399 static gboolean
1400 process_get_av_edge_credentials_response(struct sipe_core_private *sipe_private,
1401 struct sipmsg *msg,
1402 SIPE_UNUSED_PARAMETER struct transaction *trans)
1404 g_free(sipe_private->media_relay_username);
1405 g_free(sipe_private->media_relay_password);
1406 sipe_media_relay_list_free(sipe_private->media_relays);
1407 sipe_private->media_relay_username = NULL;
1408 sipe_private->media_relay_password = NULL;
1409 sipe_private->media_relays = NULL;
1411 if (msg->response >= 400) {
1412 SIPE_DEBUG_INFO_NOFORMAT("process_get_av_edge_credentials_response: SERVICE response is not 200. "
1413 "Failed to obtain A/V Edge credentials.");
1414 return FALSE;
1417 if (msg->response == 200) {
1418 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
1420 if (sipe_strequal("OK", sipe_xml_attribute(xn_response, "reasonPhrase"))) {
1421 const sipe_xml *xn_credentials = sipe_xml_child(xn_response, "credentialsResponse/credentials");
1422 const sipe_xml *xn_relays = sipe_xml_child(xn_response, "credentialsResponse/mediaRelayList");
1423 const sipe_xml *item;
1424 GSList *relays = NULL;
1426 item = sipe_xml_child(xn_credentials, "username");
1427 sipe_private->media_relay_username = sipe_xml_data(item);
1428 item = sipe_xml_child(xn_credentials, "password");
1429 sipe_private->media_relay_password = sipe_xml_data(item);
1431 for (item = sipe_xml_child(xn_relays, "mediaRelay"); item; item = sipe_xml_twin(item)) {
1432 struct sipe_media_relay *relay = g_new0(struct sipe_media_relay, 1);
1433 const sipe_xml *node;
1434 gchar *tmp;
1436 node = sipe_xml_child(item, "hostName");
1437 relay->hostname = sipe_xml_data(node);
1439 node = sipe_xml_child(item, "udpPort");
1440 if (node) {
1441 relay->udp_port = atoi(tmp = sipe_xml_data(node));
1442 g_free(tmp);
1445 node = sipe_xml_child(item, "tcpPort");
1446 if (node) {
1447 relay->tcp_port = atoi(tmp = sipe_xml_data(node));
1448 g_free(tmp);
1451 relays = g_slist_append(relays, relay);
1453 relay->dns_query = sipe_backend_dns_query_a(
1454 SIPE_CORE_PUBLIC,
1455 relay->hostname,
1456 relay->udp_port,
1457 (sipe_dns_resolved_cb) relay_ip_resolved_cb,
1458 relay);
1460 SIPE_DEBUG_INFO("Media relay: %s TCP: %d UDP: %d",
1461 relay->hostname,
1462 relay->tcp_port, relay->udp_port);
1465 sipe_private->media_relays = relays;
1468 sipe_xml_free(xn_response);
1471 return TRUE;
1474 void
1475 sipe_media_get_av_edge_credentials(struct sipe_core_private *sipe_private)
1477 // TODO: re-request credentials after duration expires?
1478 const char CRED_REQUEST_XML[] =
1479 "<request requestID=\"%d\" "
1480 "from=\"%s\" "
1481 "version=\"1.0\" "
1482 "to=\"%s\" "
1483 "xmlns=\"http://schemas.microsoft.com/2006/09/sip/mrasp\" "
1484 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
1485 "<credentialsRequest credentialsRequestID=\"%d\">"
1486 "<identity>%s</identity>"
1487 "<location>%s</location>"
1488 "<duration>480</duration>"
1489 "</credentialsRequest>"
1490 "</request>";
1492 int request_id = rand();
1493 gchar *self;
1494 gchar *body;
1496 if (!sipe_private->mras_uri)
1497 return;
1499 self = sip_uri_self(sipe_private);
1501 body = g_strdup_printf(
1502 CRED_REQUEST_XML,
1503 request_id,
1504 self,
1505 sipe_private->mras_uri,
1506 request_id,
1507 self,
1508 SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER) ? "internet" : "intranet");
1509 g_free(self);
1511 sip_transport_service(sipe_private,
1512 sipe_private->mras_uri,
1513 "Content-Type: application/msrtc-media-relay-auth+xml\r\n",
1514 body,
1515 process_get_av_edge_credentials_response);
1517 g_free(body);
1521 Local Variables:
1522 mode: c
1523 c-file-style: "bsd"
1524 indent-tabs-mode: t
1525 tab-width: 8
1526 End: