media: notification when conference calls not supported
[siplcs.git] / src / core / sipe-media.c
blobd5f31af1bc15fa77a84c08c5ca79215237d3f2b9
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-conf.h"
41 #include "sipe-core.h"
42 #include "sipe-core-private.h"
43 #include "sipe-dialog.h"
44 #include "sipe-media.h"
45 #include "sipe-ocs2007.h"
46 #include "sipe-session.h"
47 #include "sipe-utils.h"
48 #include "sipe-nls.h"
49 #include "sipe-schedule.h"
50 #include "sipe-xml.h"
52 struct sipe_media_call_private {
53 struct sipe_media_call public;
55 /* private part starts here */
56 struct sipe_core_private *sipe_private;
57 gchar *with;
59 struct sipmsg *invitation;
60 SipeIceVersion ice_version;
61 gboolean encryption_compatible;
63 struct sdpmsg *smsg;
64 GSList *failed_media;
66 #define SIPE_MEDIA_CALL ((struct sipe_media_call *) call_private)
67 #define SIPE_MEDIA_CALL_PRIVATE ((struct sipe_media_call_private *) call)
69 static void sipe_media_codec_list_free(GList *codecs)
71 for (; codecs; codecs = g_list_delete_link(codecs, codecs))
72 sipe_backend_codec_free(codecs->data);
75 static void sipe_media_candidate_list_free(GList *candidates)
77 for (; candidates; candidates = g_list_delete_link(candidates, candidates))
78 sipe_backend_candidate_free(candidates->data);
81 static void
82 sipe_media_call_free(struct sipe_media_call_private *call_private)
84 if (call_private) {
85 struct sip_session *session;
86 sipe_backend_media_free(call_private->public.backend_private);
88 session = sipe_session_find_call(call_private->sipe_private,
89 call_private->with);
90 if (session)
91 sipe_session_remove(call_private->sipe_private, session);
93 if (call_private->invitation)
94 sipmsg_free(call_private->invitation);
96 sdpmsg_free(call_private->smsg);
97 sipe_utils_slist_free_full(call_private->failed_media,
98 (GDestroyNotify)sdpmedia_free);
99 g_free(call_private->with);
100 g_free(call_private);
104 static gint
105 candidate_sort_cb(struct sdpcandidate *c1, struct sdpcandidate *c2)
107 int cmp = sipe_strcompare(c1->foundation, c2->foundation);
108 if (cmp == 0) {
109 cmp = sipe_strcompare(c1->username, c2->username);
110 if (cmp == 0)
111 cmp = c1->component - c2->component;
114 return cmp;
117 static GSList *
118 backend_candidates_to_sdpcandidate(GList *candidates)
120 GSList *result = NULL;
121 GList *i;
123 for (i = candidates; i; i = i->next) {
124 struct sipe_backend_candidate *candidate = i->data;
125 struct sdpcandidate *c = g_new(struct sdpcandidate, 1);
127 c->foundation = sipe_backend_candidate_get_foundation(candidate);
128 c->component = sipe_backend_candidate_get_component_type(candidate);
129 c->type = sipe_backend_candidate_get_type(candidate);
130 c->protocol = sipe_backend_candidate_get_protocol(candidate);
131 c->ip = sipe_backend_candidate_get_ip(candidate);
132 c->port = sipe_backend_candidate_get_port(candidate);
133 c->base_ip = sipe_backend_candidate_get_base_ip(candidate);
134 c->base_port = sipe_backend_candidate_get_base_port(candidate);
135 c->priority = sipe_backend_candidate_get_priority(candidate);
136 c->username = sipe_backend_candidate_get_username(candidate);
137 c->password = sipe_backend_candidate_get_password(candidate);
139 result = g_slist_insert_sorted(result, c,
140 (GCompareFunc)candidate_sort_cb);
143 return result;
146 static void
147 get_stream_ip_and_ports(GSList *candidates,
148 gchar **ip, guint *rtp_port, guint *rtcp_port,
149 SipeCandidateType type)
151 *ip = 0;
152 *rtp_port = 0;
153 *rtcp_port = 0;
155 for (; candidates; candidates = candidates->next) {
156 struct sdpcandidate *candidate = candidates->data;
158 if (type == SIPE_CANDIDATE_TYPE_ANY || candidate->type == type) {
159 if (!*ip) {
160 *ip = g_strdup(candidate->ip);
161 } else if (!sipe_strequal(*ip, candidate->ip)) {
162 continue;
165 if (candidate->component == SIPE_COMPONENT_RTP) {
166 *rtp_port = candidate->port;
167 } else if (candidate->component == SIPE_COMPONENT_RTCP)
168 *rtcp_port = candidate->port;
171 if (*rtp_port != 0 && *rtcp_port != 0)
172 return;
176 static gint
177 sdpcodec_compare(gconstpointer a, gconstpointer b)
179 return ((const struct sdpcodec *)a)->id -
180 ((const struct sdpcodec *)b)->id;
183 static struct sdpmedia *
184 backend_stream_to_sdpmedia(struct sipe_backend_media *backend_media,
185 struct sipe_backend_stream *backend_stream)
187 struct sdpmedia *media = g_new0(struct sdpmedia, 1);
188 GList *codecs = sipe_backend_get_local_codecs(backend_media,
189 backend_stream);
190 guint rtcp_port = 0;
191 SipeMediaType type;
192 GSList *attributes = NULL;
193 GList *candidates;
194 GList *i;
196 media->name = g_strdup(sipe_backend_stream_get_id(backend_stream));
198 if (sipe_strequal(media->name, "audio"))
199 type = SIPE_MEDIA_AUDIO;
200 else if (sipe_strequal(media->name, "video"))
201 type = SIPE_MEDIA_VIDEO;
202 else {
203 // TODO: incompatible media, should not happen here
204 g_free(media->name);
205 g_free(media);
206 sipe_media_codec_list_free(codecs);
207 return(NULL);
210 // Process codecs
211 for (i = codecs; i; i = i->next) {
212 struct sipe_backend_codec *codec = i->data;
213 struct sdpcodec *c = g_new0(struct sdpcodec, 1);
214 GList *params;
216 c->id = sipe_backend_codec_get_id(codec);
217 c->name = sipe_backend_codec_get_name(codec);
218 c->clock_rate = sipe_backend_codec_get_clock_rate(codec);
219 c->type = type;
221 params = sipe_backend_codec_get_optional_parameters(codec);
222 for (; params; params = params->next) {
223 struct sipnameval *param = params->data;
224 struct sipnameval *copy = g_new0(struct sipnameval, 1);
226 copy->name = g_strdup(param->name);
227 copy->value = g_strdup(param->value);
229 c->parameters = g_slist_append(c->parameters, copy);
232 /* Buggy(?) codecs may report non-unique id (a.k.a. payload
233 * type) that must not appear in SDP messages we send. Thus,
234 * let's ignore any codec having the same id as one we already
235 * have in the converted list. */
236 media->codecs = sipe_utils_slist_insert_unique_sorted(
237 media->codecs, c, sdpcodec_compare,
238 (GDestroyNotify)sdpcodec_free);
241 sipe_media_codec_list_free(codecs);
243 // Process local candidates
244 // If we have established candidate pairs, send them in SDP response.
245 // Otherwise send all available local candidates.
246 candidates = sipe_backend_media_get_active_local_candidates(backend_media,
247 backend_stream);
248 if (!candidates)
249 candidates = sipe_backend_get_local_candidates(backend_media,
250 backend_stream);
252 media->candidates = backend_candidates_to_sdpcandidate(candidates);
254 sipe_media_candidate_list_free(candidates);
256 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
257 &rtcp_port, SIPE_CANDIDATE_TYPE_HOST);
258 // No usable HOST candidates, use any candidate
259 if (media->ip == NULL && media->candidates) {
260 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
261 &rtcp_port, SIPE_CANDIDATE_TYPE_ANY);
264 if (sipe_backend_stream_is_held(backend_stream))
265 attributes = sipe_utils_nameval_add(attributes, "inactive", "");
267 if (rtcp_port) {
268 gchar *tmp = g_strdup_printf("%u", rtcp_port);
269 attributes = sipe_utils_nameval_add(attributes, "rtcp", tmp);
270 g_free(tmp);
273 attributes = sipe_utils_nameval_add(attributes, "encryption", "rejected");
275 media->attributes = attributes;
277 // Process remote candidates
278 candidates = sipe_backend_media_get_active_remote_candidates(backend_media,
279 backend_stream);
280 media->remote_candidates = backend_candidates_to_sdpcandidate(candidates);
281 sipe_media_candidate_list_free(candidates);
283 return media;
286 static struct sdpmsg *
287 sipe_media_to_sdpmsg(struct sipe_media_call_private *call_private)
289 struct sipe_backend_media *backend_media = call_private->public.backend_private;
290 struct sdpmsg *msg = g_new0(struct sdpmsg, 1);
291 GSList *streams = sipe_backend_media_get_streams(backend_media);
293 for (; streams; streams = streams->next) {
294 struct sdpmedia *media = backend_stream_to_sdpmedia(backend_media, streams->data);
295 if (media) {
296 msg->media = g_slist_append(msg->media, media);
298 if (msg->ip == NULL)
299 msg->ip = g_strdup(media->ip);
303 msg->media = g_slist_concat(msg->media, call_private->failed_media);
304 call_private->failed_media = NULL;
306 msg->ice_version = call_private->ice_version;
308 return msg;
311 static void
312 sipe_invite_call(struct sipe_core_private *sipe_private, TransCallback tc)
314 gchar *hdr;
315 gchar *contact;
316 gchar *p_preferred_identity = NULL;
317 gchar *body;
318 struct sipe_media_call_private *call_private = sipe_private->media_call;
319 struct sip_session *session;
320 struct sip_dialog *dialog;
321 struct sdpmsg *msg;
322 gboolean add_2007_fallback = FALSE;
324 session = sipe_session_find_call(sipe_private, call_private->with);
325 dialog = session->dialogs->data;
326 add_2007_fallback = dialog->cseq == 0 &&
327 call_private->ice_version == SIPE_ICE_RFC_5245 &&
328 !sipe_strequal(call_private->with, sipe_private->test_call_bot_uri);
330 contact = get_contact(sipe_private);
332 if (sipe_private->uc_line_uri) {
333 gchar *self = sip_uri_self(sipe_private);
334 p_preferred_identity = g_strdup_printf(
335 "P-Preferred-Identity: <%s>, <%s>\r\n",
336 self, sipe_private->uc_line_uri);
337 g_free(self);
340 hdr = g_strdup_printf(
341 "ms-keep-alive: UAC;hop-hop=yes\r\n"
342 "Contact: %s\r\n"
343 "%s"
344 "Content-Type: %s\r\n",
345 contact,
346 p_preferred_identity ? p_preferred_identity : "",
347 add_2007_fallback ?
348 "multipart/alternative;boundary=\"----=_NextPart_000_001E_01CB4397.0B5EB570\""
349 : "application/sdp");
350 g_free(contact);
351 g_free(p_preferred_identity);
353 msg = sipe_media_to_sdpmsg(call_private);
354 body = sdpmsg_to_string(msg);
356 if (add_2007_fallback) {
357 gchar *tmp;
358 tmp = g_strdup_printf(
359 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
360 "Content-Type: application/sdp\r\n"
361 "Content-Transfer-Encoding: 7bit\r\n"
362 "Content-Disposition: session; handling=optional; ms-proxy-2007fallback\r\n"
363 "\r\n"
364 "o=- 0 0 IN IP4 %s\r\n"
365 "s=session\r\n"
366 "c=IN IP4 %s\r\n"
367 "m=audio 0 RTP/AVP\r\n"
368 "\r\n"
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\r\n"
373 "\r\n"
374 "%s"
375 "\r\n"
376 "------=_NextPart_000_001E_01CB4397.0B5EB570--\r\n",
377 msg->ip, msg->ip, body);
378 g_free(body);
379 body = tmp;
382 sdpmsg_free(msg);
384 dialog->outgoing_invite = sip_transport_invite(sipe_private,
385 hdr,
386 body,
387 dialog,
388 tc);
390 g_free(body);
391 g_free(hdr);
394 static struct sip_dialog *
395 sipe_media_dialog_init(struct sip_session* session, struct sipmsg *msg)
397 gchar *newTag = gentag();
398 const gchar *oldHeader;
399 gchar *newHeader;
400 struct sip_dialog *dialog;
402 oldHeader = sipmsg_find_header(msg, "To");
403 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
404 sipmsg_remove_header_now(msg, "To");
405 sipmsg_add_header_now(msg, "To", newHeader);
406 g_free(newHeader);
408 dialog = sipe_dialog_add(session);
409 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
410 dialog->with = parse_from(sipmsg_find_header(msg, "From"));
411 sipe_dialog_parse(dialog, msg, FALSE);
413 return dialog;
416 static void
417 send_response_with_session_description(struct sipe_media_call_private *call_private, int code, gchar *text)
419 struct sdpmsg *msg = sipe_media_to_sdpmsg(call_private);
420 gchar *body = sdpmsg_to_string(msg);
421 sdpmsg_free(msg);
422 sipmsg_add_header(call_private->invitation, "Content-Type", "application/sdp");
423 sip_transport_response(call_private->sipe_private, call_private->invitation, code, text, body);
424 g_free(body);
427 static gboolean
428 encryption_levels_compatible(struct sdpmsg *msg)
430 GSList *i;
432 for (i = msg->media; i; i = i->next) {
433 const gchar *enc_level;
434 struct sdpmedia *m = i->data;
436 enc_level = sipe_utils_nameval_find(m->attributes, "encryption");
438 // Decline call if peer requires encryption as we don't support it yet.
439 if (sipe_strequal(enc_level, "required"))
440 return FALSE;
443 return TRUE;
446 static gboolean
447 process_invite_call_response(struct sipe_core_private *sipe_private,
448 struct sipmsg *msg,
449 struct transaction *trans);
451 static gboolean
452 update_remote_media(struct sipe_media_call_private* call_private,
453 struct sdpmedia *media)
455 struct sipe_backend_media *backend_media = SIPE_MEDIA_CALL->backend_private;
456 struct sipe_backend_stream *backend_stream;
457 GList *backend_candidates = NULL;
458 GList *backend_codecs = NULL;
459 GSList *i;
460 gboolean result = TRUE;
462 backend_stream = sipe_backend_media_get_stream_by_id(backend_media,
463 media->name);
464 if (media->port == 0) {
465 if (backend_stream)
466 sipe_backend_media_remove_stream(backend_media, backend_stream);
467 return TRUE;
470 if (!backend_stream)
471 return FALSE;
473 for (i = media->codecs; i; i = i->next) {
474 struct sdpcodec *c = i->data;
475 struct sipe_backend_codec *codec;
476 GSList *j;
478 codec = sipe_backend_codec_new(c->id,
479 c->name,
480 c->type,
481 c->clock_rate);
483 for (j = c->parameters; j; j = j->next) {
484 struct sipnameval *attr = j->data;
486 sipe_backend_codec_add_optional_parameter(codec,
487 attr->name,
488 attr->value);
491 backend_codecs = g_list_append(backend_codecs, codec);
494 result = sipe_backend_set_remote_codecs(backend_media,
495 backend_stream,
496 backend_codecs);
497 sipe_media_codec_list_free(backend_codecs);
499 if (result == FALSE) {
500 sipe_backend_media_remove_stream(backend_media, backend_stream);
501 return FALSE;
504 for (i = media->candidates; i; i = i->next) {
505 struct sdpcandidate *c = i->data;
506 struct sipe_backend_candidate *candidate;
507 candidate = sipe_backend_candidate_new(c->foundation,
508 c->component,
509 c->type,
510 c->protocol,
511 c->ip,
512 c->port,
513 c->username,
514 c->password);
515 sipe_backend_candidate_set_priority(candidate, c->priority);
517 backend_candidates = g_list_append(backend_candidates, candidate);
520 sipe_backend_media_add_remote_candidates(backend_media,
521 backend_stream,
522 backend_candidates);
523 sipe_media_candidate_list_free(backend_candidates);
525 if (sipe_utils_nameval_find(media->attributes, "inactive")) {
526 sipe_backend_stream_hold(backend_media, backend_stream, FALSE);
527 } else if (sipe_backend_stream_is_held(backend_stream)) {
528 sipe_backend_stream_unhold(backend_media, backend_stream, FALSE);
531 return TRUE;
534 static void
535 apply_remote_message(struct sipe_media_call_private* call_private,
536 struct sdpmsg* msg)
538 GSList *i;
540 sipe_utils_slist_free_full(call_private->failed_media, (GDestroyNotify)sdpmedia_free);
541 call_private->failed_media = NULL;
543 for (i = msg->media; i; i = i->next) {
544 struct sdpmedia *media = i->data;
545 if (!update_remote_media(call_private, media)) {
546 media->port = 0;
547 call_private->failed_media =
548 g_slist_append(call_private->failed_media, media);
552 /* We need to keep failed medias until response is sent, remove them
553 * from sdpmsg that is to be freed. */
554 for (i = call_private->failed_media; i; i = i->next) {
555 msg->media = g_slist_remove(msg->media, i->data);
558 call_private->encryption_compatible = encryption_levels_compatible(msg);
561 static gboolean
562 call_initialized(struct sipe_media_call *call)
564 GSList *streams =
565 sipe_backend_media_get_streams(call->backend_private);
567 for (; streams; streams = streams->next) {
568 if (!sipe_backend_stream_initialized(call->backend_private,
569 streams->data)) {
570 return FALSE;
574 return TRUE;
577 // Sends an invite response when the call is accepted and local candidates were
578 // prepared, otherwise does nothing. If error response is sent, call_private is
579 // disposed before function returns. Returns true when response was sent.
580 static gboolean
581 send_invite_response_if_ready(struct sipe_media_call_private *call_private)
583 struct sipe_backend_media *backend_media;
585 backend_media = call_private->public.backend_private;
587 if (!sipe_backend_media_accepted(backend_media) ||
588 !call_initialized(&call_private->public))
589 return FALSE;
591 if (!call_private->encryption_compatible) {
592 struct sipe_core_private *sipe_private = call_private->sipe_private;
594 sipmsg_add_header(call_private->invitation, "Warning",
595 "308 lcs.microsoft.com \"Encryption Levels not compatible\"");
596 sip_transport_response(sipe_private,
597 call_private->invitation,
598 488, "Encryption Levels not compatible",
599 NULL);
600 sipe_backend_media_reject(backend_media, FALSE);
601 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
602 _("Unable to establish a call"),
603 _("Encryption settings of peer are incompatible with ours."));
604 } else {
605 send_response_with_session_description(call_private, 200, "OK");
608 return TRUE;
611 static void
612 stream_initialized_cb(struct sipe_media_call *call,
613 struct sipe_backend_stream *stream)
615 if (call_initialized(call)) {
616 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
617 struct sipe_backend_media *backend_private = call->backend_private;
619 if (sipe_backend_media_is_initiator(backend_private, stream)) {
620 sipe_invite_call(call_private->sipe_private,
621 process_invite_call_response);
622 } else if (call_private->smsg) {
623 struct sdpmsg *smsg = call_private->smsg;
624 call_private->smsg = NULL;
626 apply_remote_message(call_private, smsg);
627 send_invite_response_if_ready(call_private);
628 sdpmsg_free(smsg);
633 static void phone_state_publish(struct sipe_core_private *sipe_private)
635 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) {
636 sipe_ocs2007_phone_state_publish(sipe_private);
637 } else {
638 // TODO: OCS 2005 support. Is anyone still using it at all?
642 static void
643 media_end_cb(struct sipe_media_call *call)
645 g_return_if_fail(call);
647 SIPE_MEDIA_CALL_PRIVATE->sipe_private->media_call = NULL;
648 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
649 sipe_media_call_free(SIPE_MEDIA_CALL_PRIVATE);
652 static void
653 call_accept_cb(struct sipe_media_call *call, gboolean local)
655 if (local) {
656 send_invite_response_if_ready(SIPE_MEDIA_CALL_PRIVATE);
658 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
661 static void
662 call_reject_cb(struct sipe_media_call *call, gboolean local)
664 if (local) {
665 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
666 sip_transport_response(call_private->sipe_private,
667 call_private->invitation,
668 603, "Decline", NULL);
672 static gboolean
673 sipe_media_send_ack(struct sipe_core_private *sipe_private, struct sipmsg *msg,
674 struct transaction *trans);
676 static void call_hold_cb(struct sipe_media_call *call,
677 gboolean local,
678 SIPE_UNUSED_PARAMETER gboolean state)
680 if (local)
681 sipe_invite_call(SIPE_MEDIA_CALL_PRIVATE->sipe_private,
682 sipe_media_send_ack);
685 static void call_hangup_cb(struct sipe_media_call *call, gboolean local)
687 if (local) {
688 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
689 struct sip_session *session;
690 session = sipe_session_find_call(call_private->sipe_private,
691 call_private->with);
693 if (session) {
694 sipe_session_close(call_private->sipe_private, session);
699 static void
700 error_cb(struct sipe_media_call *call, gchar *message)
702 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
703 struct sipe_core_private *sipe_private = call_private->sipe_private;
704 gboolean initiator = sipe_backend_media_is_initiator(call->backend_private, NULL);
705 gboolean accepted = sipe_backend_media_accepted(call->backend_private);
707 gchar *title = g_strdup_printf("Call with %s failed", call_private->with);
708 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, message);
709 g_free(title);
711 if (!initiator && !accepted) {
712 sip_transport_response(sipe_private,
713 call_private->invitation,
714 488, "Not Acceptable Here", NULL);
717 sipe_backend_media_hangup(call->backend_private, initiator || accepted);
720 static struct sipe_media_call_private *
721 sipe_media_call_new(struct sipe_core_private *sipe_private,
722 const gchar* with, gboolean initiator, SipeIceVersion ice_version)
724 struct sipe_media_call_private *call_private = g_new0(struct sipe_media_call_private, 1);
725 gchar *cname;
727 call_private->sipe_private = sipe_private;
729 cname = g_strdup(sipe_private->contact + 1);
730 cname[strlen(cname) - 1] = '\0';
732 call_private->public.backend_private = sipe_backend_media_new(SIPE_CORE_PUBLIC,
733 SIPE_MEDIA_CALL,
734 with,
735 initiator);
736 sipe_backend_media_set_cname(call_private->public.backend_private, cname);
738 call_private->ice_version = ice_version;
739 call_private->encryption_compatible = TRUE;
741 call_private->public.stream_initialized_cb = stream_initialized_cb;
742 call_private->public.media_end_cb = media_end_cb;
743 call_private->public.call_accept_cb = call_accept_cb;
744 call_private->public.call_reject_cb = call_reject_cb;
745 call_private->public.call_hold_cb = call_hold_cb;
746 call_private->public.call_hangup_cb = call_hangup_cb;
747 call_private->public.error_cb = error_cb;
749 g_free(cname);
751 return call_private;
754 void sipe_media_hangup(struct sipe_media_call_private *call_private)
756 if (call_private) {
757 sipe_backend_media_hangup(call_private->public.backend_private,
758 FALSE);
762 static void
763 sipe_media_initiate_call(struct sipe_core_private *sipe_private,
764 const char *with, SipeIceVersion ice_version,
765 gboolean with_video)
767 struct sipe_media_call_private *call_private;
768 struct sipe_backend_media *backend_media;
769 struct sipe_backend_media_relays *backend_media_relays;
770 struct sip_session *session;
771 struct sip_dialog *dialog;
773 if (sipe_private->media_call)
774 return;
776 call_private = sipe_media_call_new(sipe_private, with, TRUE, ice_version);
778 session = sipe_session_add_call(sipe_private, with);
779 dialog = sipe_dialog_add(session);
780 dialog->callid = gencallid();
781 dialog->with = g_strdup(session->with);
782 dialog->ourtag = gentag();
784 call_private->with = g_strdup(session->with);
786 backend_media = call_private->public.backend_private;
788 backend_media_relays =
789 sipe_backend_media_relays_convert(sipe_private->media_relays,
790 sipe_private->media_relay_username,
791 sipe_private->media_relay_password);
793 if (!sipe_backend_media_add_stream(backend_media,
794 "audio", with, SIPE_MEDIA_AUDIO,
795 call_private->ice_version, TRUE,
796 backend_media_relays)) {
797 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
798 _("Error occured"),
799 _("Error creating audio stream"));
800 sipe_media_hangup(call_private);
801 sipe_backend_media_relays_free(backend_media_relays);
802 return;
805 if ( with_video
806 && !sipe_backend_media_add_stream(backend_media,
807 "video", with, SIPE_MEDIA_VIDEO,
808 call_private->ice_version, TRUE,
809 backend_media_relays)) {
810 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
811 _("Error occured"),
812 _("Error creating video stream"));
813 sipe_media_hangup(call_private);
814 sipe_backend_media_relays_free(backend_media_relays);
815 return;
818 sipe_private->media_call = call_private;
820 sipe_backend_media_relays_free(backend_media_relays);
822 // Processing continues in stream_initialized_cb
825 void
826 sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
827 const char *with,
828 gboolean with_video)
830 sipe_media_initiate_call(SIPE_CORE_PRIVATE, with,
831 SIPE_ICE_RFC_5245, with_video);
834 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
835 struct sipe_chat_session *chat_session)
837 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
838 struct sipe_backend_media_relays *backend_media_relays;
839 struct sip_session *session;
840 struct sip_dialog *dialog;
841 SipeIceVersion ice_version;
842 gchar **parts;
843 gchar *av_uri;
845 if (!sipe_conf_supports_mcu_type(sipe_private, "audio-video")) {
846 sipe_backend_notify_error(sipe_public, _("Join conference call"),
847 _("Conference calls are not supported on this server."));
848 return;
851 session = sipe_session_find_chat(sipe_private, chat_session);
853 if (sipe_private->media_call || !session)
854 return;
856 session->is_call = TRUE;
858 parts = g_strsplit(chat_session->id, "app:conf:focus:", 2);
859 av_uri = g_strjoinv("app:conf:audio-video:", parts);
860 g_strfreev(parts);
862 ice_version = SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013) ? SIPE_ICE_RFC_5245 :
863 SIPE_ICE_DRAFT_6;
865 sipe_private->media_call = sipe_media_call_new(sipe_private, av_uri,
866 TRUE, ice_version);
868 session = sipe_session_add_call(sipe_private, av_uri);
869 dialog = sipe_dialog_add(session);
870 dialog->callid = gencallid();
871 dialog->with = g_strdup(session->with);
872 dialog->ourtag = gentag();
874 g_free(av_uri);
876 sipe_private->media_call->with = g_strdup(session->with);
878 backend_media_relays =
879 sipe_backend_media_relays_convert(sipe_private->media_relays,
880 sipe_private->media_relay_username,
881 sipe_private->media_relay_password);
883 if (!sipe_backend_media_add_stream(sipe_private->media_call->public.backend_private,
884 "audio", dialog->with,
885 SIPE_MEDIA_AUDIO,
886 sipe_private->media_call->ice_version,
887 TRUE, backend_media_relays)) {
888 sipe_backend_notify_error(sipe_public,
889 _("Error occured"),
890 _("Error creating audio stream"));
891 sipe_media_hangup(sipe_private->media_call);
892 sipe_private->media_call = NULL;
895 sipe_backend_media_relays_free(backend_media_relays);
897 // Processing continues in stream_initialized_cb
900 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public)
902 if (sipe_public) {
903 return SIPE_CORE_PRIVATE->media_call != NULL;
905 return FALSE;
908 static gboolean phone_number_is_valid(const gchar *phone_number)
910 if (!phone_number || sipe_strequal(phone_number, "")) {
911 return FALSE;
914 if (*phone_number == '+') {
915 ++phone_number;
918 while (*phone_number != '\0') {
919 if (!g_ascii_isdigit(*phone_number)) {
920 return FALSE;
922 ++phone_number;
925 return TRUE;
928 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
929 const gchar *phone_number)
931 g_return_if_fail(sipe_public);
933 if (phone_number_is_valid(phone_number)) {
934 gchar *phone_uri = g_strdup_printf("sip:%s@%s;user=phone",
935 phone_number, sipe_public->sip_domain);
937 sipe_core_media_initiate_call(sipe_public, phone_uri, FALSE);
939 g_free(phone_uri);
940 } else {
941 sipe_backend_notify_error(sipe_public,
942 _("Unable to establish a call"),
943 _("Invalid phone number"));
947 void sipe_core_media_test_call(struct sipe_core_public *sipe_public)
949 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
950 if (!sipe_private->test_call_bot_uri) {
951 sipe_backend_notify_error(sipe_public,
952 _("Unable to establish a call"),
953 _("Audio Test Service is not available."));
954 return;
957 sipe_core_media_initiate_call(sipe_public,
958 sipe_private->test_call_bot_uri, FALSE);
961 void
962 process_incoming_invite_call(struct sipe_core_private *sipe_private,
963 struct sipmsg *msg)
965 struct sipe_media_call_private *call_private = sipe_private->media_call;
966 struct sipe_backend_media *backend_media;
967 struct sipe_backend_media_relays *backend_media_relays = NULL;
968 struct sdpmsg *smsg;
969 gboolean has_new_media = FALSE;
970 GSList *i;
972 if (call_private) {
973 char *self;
975 if (!is_media_session_msg(call_private, msg)) {
976 sip_transport_response(sipe_private, msg, 486, "Busy Here", NULL);
977 return;
980 self = sip_uri_self(sipe_private);
981 if (sipe_strequal(call_private->with, self)) {
982 g_free(self);
983 sip_transport_response(sipe_private, msg, 488, "Not Acceptable Here", NULL);
984 return;
986 g_free(self);
989 smsg = sdpmsg_parse_msg(msg->body);
990 if (!smsg) {
991 sip_transport_response(sipe_private, msg,
992 488, "Not Acceptable Here", NULL);
993 sipe_media_hangup(call_private);
994 return;
997 if (!call_private) {
998 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
999 struct sip_session *session;
1001 call_private = sipe_media_call_new(sipe_private, with, FALSE, smsg->ice_version);
1002 session = sipe_session_add_call(sipe_private, with);
1003 sipe_media_dialog_init(session, msg);
1005 call_private->with = g_strdup(session->with);
1006 sipe_private->media_call = call_private;
1007 g_free(with);
1010 backend_media = call_private->public.backend_private;
1012 if (call_private->invitation)
1013 sipmsg_free(call_private->invitation);
1014 call_private->invitation = sipmsg_copy(msg);
1016 if (smsg->media)
1017 backend_media_relays = sipe_backend_media_relays_convert(
1018 sipe_private->media_relays,
1019 sipe_private->media_relay_username,
1020 sipe_private->media_relay_password);
1022 // Create any new media streams
1023 for (i = smsg->media; i; i = i->next) {
1024 struct sdpmedia *media = i->data;
1025 gchar *id = media->name;
1026 SipeMediaType type;
1028 if ( media->port != 0
1029 && !sipe_backend_media_get_stream_by_id(backend_media, id)) {
1030 gchar *with;
1032 if (sipe_strequal(id, "audio"))
1033 type = SIPE_MEDIA_AUDIO;
1034 else if (sipe_strequal(id, "video"))
1035 type = SIPE_MEDIA_VIDEO;
1036 else
1037 continue;
1039 with = parse_from(sipmsg_find_header(msg, "From"));
1040 sipe_backend_media_add_stream(backend_media, id, with,
1041 type,
1042 smsg->ice_version,
1043 FALSE,
1044 backend_media_relays);
1045 has_new_media = TRUE;
1046 g_free(with);
1050 sipe_backend_media_relays_free(backend_media_relays);
1052 if (has_new_media) {
1053 sdpmsg_free(call_private->smsg);
1054 call_private->smsg = smsg;
1055 sip_transport_response(sipe_private, call_private->invitation,
1056 180, "Ringing", NULL);
1057 // Processing continues in stream_initialized_cb
1058 } else {
1059 apply_remote_message(call_private, smsg);
1060 send_response_with_session_description(call_private, 200, "OK");
1062 sdpmsg_free(smsg);
1066 void process_incoming_cancel_call(struct sipe_core_private *sipe_private,
1067 struct sipmsg *msg)
1069 struct sipe_media_call_private *call_private = sipe_private->media_call;
1071 // We respond to the CANCEL request with 200 OK response and
1072 // with 487 Request Terminated to the remote INVITE in progress.
1073 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1075 if (call_private->invitation) {
1076 sip_transport_response(sipe_private, call_private->invitation,
1077 487, "Request Terminated", NULL);
1080 sipe_media_hangup(call_private);
1083 static gboolean
1084 sipe_media_send_ack(struct sipe_core_private *sipe_private,
1085 struct sipmsg *msg,
1086 struct transaction *trans)
1088 struct sipe_media_call_private *call_private = sipe_private->media_call;
1089 struct sip_session *session;
1090 struct sip_dialog *dialog;
1091 int tmp_cseq;
1093 if (!is_media_session_msg(call_private, msg))
1094 return FALSE;
1096 session = sipe_session_find_call(sipe_private, call_private->with);
1097 dialog = session->dialogs->data;
1098 if (!dialog)
1099 return FALSE;
1101 tmp_cseq = dialog->cseq;
1103 dialog->cseq = sip_transaction_cseq(trans) - 1;
1104 sip_transport_ack(sipe_private, dialog);
1105 dialog->cseq = tmp_cseq;
1107 dialog->outgoing_invite = NULL;
1109 return TRUE;
1112 static gboolean
1113 sipe_media_send_final_ack(struct sipe_core_private *sipe_private,
1114 struct sipmsg *msg,
1115 struct transaction *trans)
1117 if (!sipe_media_send_ack(sipe_private, msg, trans))
1118 return FALSE;
1120 sipe_backend_media_accept(sipe_private->media_call->public.backend_private,
1121 FALSE);
1123 return TRUE;
1126 static void
1127 reinvite_on_candidate_pair_cb(struct sipe_core_public *sipe_public)
1129 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1130 struct sipe_media_call_private *media_call = sipe_private->media_call;
1131 struct sipe_backend_media *backend_media;
1132 GSList *streams;
1134 if (!media_call)
1135 return;
1137 backend_media = media_call->public.backend_private;
1138 streams = sipe_backend_media_get_streams(backend_media);
1140 for (; streams; streams = streams->next) {
1141 struct sipe_backend_stream *s = streams->data;
1142 GList *remote_candidates = sipe_backend_media_get_active_remote_candidates(backend_media, s);
1143 guint components = g_list_length(remote_candidates);
1145 sipe_media_candidate_list_free(remote_candidates);
1147 // We must have candidates for both (RTP + RTCP) components ready
1148 if (components < 2) {
1149 sipe_schedule_mseconds(sipe_private,
1150 "<+media-reinvite-on-candidate-pair>",
1151 NULL,
1152 500,
1153 (sipe_schedule_action) reinvite_on_candidate_pair_cb,
1154 NULL);
1155 return;
1159 sipe_invite_call(sipe_private, sipe_media_send_final_ack);
1162 static gboolean
1163 maybe_retry_call_with_ice_version(struct sipe_core_private *sipe_private,
1164 SipeIceVersion ice_version,
1165 struct transaction *trans)
1167 struct sipe_media_call_private *call_private = sipe_private->media_call;
1169 if (call_private->ice_version != ice_version &&
1170 sip_transaction_cseq(trans) == 1) {
1171 gchar *with = g_strdup(call_private->with);
1172 struct sipe_backend_media *backend_private = call_private->public.backend_private;
1173 gboolean with_video = sipe_backend_media_get_stream_by_id(backend_private, "video") != NULL;
1175 sipe_media_hangup(call_private);
1176 SIPE_DEBUG_INFO("Retrying call with ICEv%d.",
1177 ice_version == SIPE_ICE_DRAFT_6 ? 6 : 19);
1178 sipe_media_initiate_call(sipe_private, with, ice_version,
1179 with_video);
1181 g_free(with);
1182 return TRUE;
1185 return FALSE;
1188 static gboolean
1189 process_invite_call_response(struct sipe_core_private *sipe_private,
1190 struct sipmsg *msg,
1191 struct transaction *trans)
1193 const gchar *with;
1194 struct sipe_media_call_private *call_private = sipe_private->media_call;
1195 struct sip_session *session;
1196 struct sip_dialog *dialog;
1197 struct sdpmsg *smsg;
1199 if (!is_media_session_msg(call_private, msg))
1200 return FALSE;
1202 session = sipe_session_find_call(sipe_private, call_private->with);
1203 dialog = session->dialogs->data;
1205 with = dialog->with;
1207 dialog->outgoing_invite = NULL;
1209 if (msg->response >= 400) {
1210 // Call rejected by remote peer or an error occurred
1211 const gchar *title;
1212 GString *desc = g_string_new("");
1213 gboolean append_responsestr = FALSE;
1215 switch (msg->response) {
1216 case 480: {
1217 title = _("User unavailable");
1219 if (sipmsg_parse_warning(msg, NULL) == 391) {
1220 g_string_append_printf(desc, _("%s does not want to be disturbed"), with);
1221 } else
1222 g_string_append_printf(desc, _("User %s is not available"), with);
1223 break;
1225 case 603:
1226 case 605:
1227 title = _("Call rejected");
1228 g_string_append_printf(desc, _("User %s rejected call"), with);
1229 break;
1230 case 415:
1231 // OCS/Lync really sends response string with 'Mutipart' typo.
1232 if (sipe_strequal(msg->responsestr, "Mutipart mime in content type not supported by Archiving CDR service") &&
1233 maybe_retry_call_with_ice_version(sipe_private, SIPE_ICE_DRAFT_6, trans)) {
1234 return TRUE;
1236 title = _("Unsupported media type");
1237 break;
1238 case 488: {
1239 /* Check for incompatible encryption levels error.
1241 * MS Lync 2010:
1242 * 488 Not Acceptable Here
1243 * ms-client-diagnostics: 52017;reason="Encryption levels dont match"
1245 * older clients (and SIPE itself):
1246 * 488 Encryption Levels not compatible
1248 const gchar *ms_diag = sipmsg_find_header(msg, "ms-client-diagnostics");
1249 SipeIceVersion retry_ice_version = SIPE_ICE_DRAFT_6;
1251 if (sipe_strequal(msg->responsestr, "Encryption Levels not compatible") ||
1252 (ms_diag && g_str_has_prefix(ms_diag, "52017;"))) {
1253 title = _("Unable to establish a call");
1254 g_string_append(desc, _("Encryption settings of peer are incompatible with ours."));
1255 break;
1258 /* Check if this is failed conference using
1259 * ICEv6 with reason "Error parsing SDP" and
1260 * retry using ICEv19. */
1261 ms_diag = sipmsg_find_header(msg, "ms-diagnostics");
1262 if (ms_diag && g_str_has_prefix(ms_diag, "7008;")) {
1263 retry_ice_version = SIPE_ICE_RFC_5245;
1266 if (maybe_retry_call_with_ice_version(sipe_private, retry_ice_version, trans)) {
1267 return TRUE;
1269 // Break intentionally omitted
1271 default:
1272 title = _("Error occured");
1273 g_string_append(desc, _("Unable to establish a call"));
1274 append_responsestr = TRUE;
1275 break;
1278 if (append_responsestr) {
1279 gchar *reason = sipmsg_get_ms_diagnostics_reason(msg);
1281 g_string_append_printf(desc, "\n%d %s",
1282 msg->response, msg->responsestr);
1283 if (reason) {
1284 g_string_append_printf(desc, "\n\n%s", reason);
1285 g_free(reason);
1289 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, desc->str);
1290 g_string_free(desc, TRUE);
1292 sipe_media_send_ack(sipe_private, msg, trans);
1293 sipe_media_hangup(call_private);
1295 return TRUE;
1298 sipe_dialog_parse(dialog, msg, TRUE);
1299 smsg = sdpmsg_parse_msg(msg->body);
1300 if (!smsg) {
1301 sip_transport_response(sipe_private, msg,
1302 488, "Not Acceptable Here", NULL);
1303 sipe_media_hangup(call_private);
1304 return FALSE;
1307 apply_remote_message(call_private, smsg);
1308 sdpmsg_free(smsg);
1310 sipe_media_send_ack(sipe_private, msg, trans);
1311 reinvite_on_candidate_pair_cb(SIPE_CORE_PUBLIC);
1313 return TRUE;
1316 gboolean is_media_session_msg(struct sipe_media_call_private *call_private,
1317 struct sipmsg *msg)
1319 if (call_private) {
1320 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1321 struct sip_session *session;
1323 session = sipe_session_find_call(call_private->sipe_private,
1324 call_private->with);
1325 if (session) {
1326 struct sip_dialog *dialog = session->dialogs->data;
1327 return sipe_strequal(dialog->callid, callid);
1330 return FALSE;
1333 void sipe_media_handle_going_offline(struct sipe_media_call_private *call_private)
1335 struct sipe_backend_media *backend_private;
1337 backend_private = call_private->public.backend_private;
1339 if ( !sipe_backend_media_is_initiator(backend_private, NULL)
1340 && !sipe_backend_media_accepted(backend_private)) {
1341 sip_transport_response(call_private->sipe_private,
1342 call_private->invitation,
1343 480, "Temporarily Unavailable", NULL);
1344 } else {
1345 struct sip_session *session;
1347 session = sipe_session_find_call(call_private->sipe_private,
1348 call_private->with);
1349 if (session)
1350 sipe_session_close(call_private->sipe_private, session);
1353 sipe_media_hangup(call_private);
1356 gboolean sipe_media_is_conference_call(struct sipe_media_call_private *call_private)
1358 return g_strstr_len(call_private->with, -1, "app:conf:audio-video:") != NULL;
1361 static void
1362 sipe_media_relay_free(struct sipe_media_relay *relay)
1364 g_free(relay->hostname);
1365 if (relay->dns_query)
1366 sipe_backend_dns_query_cancel(relay->dns_query);
1367 g_free(relay);
1370 void
1371 sipe_media_relay_list_free(GSList *list)
1373 for (; list; list = g_slist_delete_link(list, list))
1374 sipe_media_relay_free(list->data);
1377 static void
1378 relay_ip_resolved_cb(struct sipe_media_relay* relay,
1379 const gchar *ip, SIPE_UNUSED_PARAMETER guint port)
1381 gchar *hostname = relay->hostname;
1382 relay->dns_query = NULL;
1384 if (ip && port) {
1385 relay->hostname = g_strdup(ip);
1386 SIPE_DEBUG_INFO("Media relay %s resolved to %s.", hostname, ip);
1387 } else {
1388 relay->hostname = NULL;
1389 SIPE_DEBUG_INFO("Unable to resolve media relay %s.", hostname);
1392 g_free(hostname);
1395 static gboolean
1396 process_get_av_edge_credentials_response(struct sipe_core_private *sipe_private,
1397 struct sipmsg *msg,
1398 SIPE_UNUSED_PARAMETER struct transaction *trans)
1400 g_free(sipe_private->media_relay_username);
1401 g_free(sipe_private->media_relay_password);
1402 sipe_media_relay_list_free(sipe_private->media_relays);
1403 sipe_private->media_relay_username = NULL;
1404 sipe_private->media_relay_password = NULL;
1405 sipe_private->media_relays = NULL;
1407 if (msg->response >= 400) {
1408 SIPE_DEBUG_INFO_NOFORMAT("process_get_av_edge_credentials_response: SERVICE response is not 200. "
1409 "Failed to obtain A/V Edge credentials.");
1410 return FALSE;
1413 if (msg->response == 200) {
1414 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
1416 if (sipe_strequal("OK", sipe_xml_attribute(xn_response, "reasonPhrase"))) {
1417 const sipe_xml *xn_credentials = sipe_xml_child(xn_response, "credentialsResponse/credentials");
1418 const sipe_xml *xn_relays = sipe_xml_child(xn_response, "credentialsResponse/mediaRelayList");
1419 const sipe_xml *item;
1420 GSList *relays = NULL;
1422 item = sipe_xml_child(xn_credentials, "username");
1423 sipe_private->media_relay_username = sipe_xml_data(item);
1424 item = sipe_xml_child(xn_credentials, "password");
1425 sipe_private->media_relay_password = sipe_xml_data(item);
1427 for (item = sipe_xml_child(xn_relays, "mediaRelay"); item; item = sipe_xml_twin(item)) {
1428 struct sipe_media_relay *relay = g_new0(struct sipe_media_relay, 1);
1429 const sipe_xml *node;
1430 gchar *tmp;
1432 node = sipe_xml_child(item, "hostName");
1433 relay->hostname = sipe_xml_data(node);
1435 node = sipe_xml_child(item, "udpPort");
1436 if (node) {
1437 relay->udp_port = atoi(tmp = sipe_xml_data(node));
1438 g_free(tmp);
1441 node = sipe_xml_child(item, "tcpPort");
1442 if (node) {
1443 relay->tcp_port = atoi(tmp = sipe_xml_data(node));
1444 g_free(tmp);
1447 relays = g_slist_append(relays, relay);
1449 relay->dns_query = sipe_backend_dns_query_a(
1450 SIPE_CORE_PUBLIC,
1451 relay->hostname,
1452 relay->udp_port,
1453 (sipe_dns_resolved_cb) relay_ip_resolved_cb,
1454 relay);
1456 SIPE_DEBUG_INFO("Media relay: %s TCP: %d UDP: %d",
1457 relay->hostname,
1458 relay->tcp_port, relay->udp_port);
1461 sipe_private->media_relays = relays;
1464 sipe_xml_free(xn_response);
1467 return TRUE;
1470 void
1471 sipe_media_get_av_edge_credentials(struct sipe_core_private *sipe_private)
1473 // TODO: re-request credentials after duration expires?
1474 const char CRED_REQUEST_XML[] =
1475 "<request requestID=\"%d\" "
1476 "from=\"%s\" "
1477 "version=\"1.0\" "
1478 "to=\"%s\" "
1479 "xmlns=\"http://schemas.microsoft.com/2006/09/sip/mrasp\" "
1480 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
1481 "<credentialsRequest credentialsRequestID=\"%d\">"
1482 "<identity>%s</identity>"
1483 "<location>%s</location>"
1484 "<duration>480</duration>"
1485 "</credentialsRequest>"
1486 "</request>";
1488 int request_id = rand();
1489 gchar *self;
1490 gchar *body;
1492 if (!sipe_private->mras_uri)
1493 return;
1495 self = sip_uri_self(sipe_private);
1497 body = g_strdup_printf(
1498 CRED_REQUEST_XML,
1499 request_id,
1500 self,
1501 sipe_private->mras_uri,
1502 request_id,
1503 self,
1504 SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER) ? "internet" : "intranet");
1505 g_free(self);
1507 sip_transport_service(sipe_private,
1508 sipe_private->mras_uri,
1509 "Content-Type: application/msrtc-media-relay-auth+xml\r\n",
1510 body,
1511 process_get_av_edge_credentials_response);
1513 g_free(body);
1517 Local Variables:
1518 mode: c
1519 c-file-style: "bsd"
1520 indent-tabs-mode: t
1521 tab-width: 8
1522 End: