Fix #210: Conference call ends with error message (II)
[siplcs.git] / src / core / sipe-media.c
blob4f4d5fc6f6962957fe9d353e2a76ab67a9869aaf
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 = g_new(struct sdpcandidate, 1);
126 c->foundation = sipe_backend_candidate_get_foundation(candidate);
127 c->component = sipe_backend_candidate_get_component_type(candidate);
128 c->type = sipe_backend_candidate_get_type(candidate);
129 c->protocol = sipe_backend_candidate_get_protocol(candidate);
130 c->ip = sipe_backend_candidate_get_ip(candidate);
131 c->port = sipe_backend_candidate_get_port(candidate);
132 c->base_ip = sipe_backend_candidate_get_base_ip(candidate);
133 c->base_port = sipe_backend_candidate_get_base_port(candidate);
134 c->priority = sipe_backend_candidate_get_priority(candidate);
135 c->username = sipe_backend_candidate_get_username(candidate);
136 c->password = sipe_backend_candidate_get_password(candidate);
138 result = g_slist_insert_sorted(result, c,
139 (GCompareFunc)candidate_sort_cb);
142 return result;
145 static void
146 get_stream_ip_and_ports(GSList *candidates,
147 gchar **ip, guint *rtp_port, guint *rtcp_port,
148 SipeCandidateType type)
150 *ip = 0;
151 *rtp_port = 0;
152 *rtcp_port = 0;
154 for (; candidates; candidates = candidates->next) {
155 struct sdpcandidate *candidate = candidates->data;
157 if (type == SIPE_CANDIDATE_TYPE_ANY || candidate->type == type) {
158 if (!*ip) {
159 *ip = g_strdup(candidate->ip);
160 } else if (!sipe_strequal(*ip, candidate->ip)) {
161 continue;
164 if (candidate->component == SIPE_COMPONENT_RTP) {
165 *rtp_port = candidate->port;
166 } else if (candidate->component == SIPE_COMPONENT_RTCP)
167 *rtcp_port = candidate->port;
170 if (*rtp_port != 0 && *rtcp_port != 0)
171 return;
175 static gint
176 sdpcodec_compare(gconstpointer a, gconstpointer b)
178 return ((const struct sdpcodec *)a)->id -
179 ((const struct sdpcodec *)b)->id;
182 static struct sdpmedia *
183 backend_stream_to_sdpmedia(struct sipe_backend_media *backend_media,
184 struct sipe_backend_stream *backend_stream)
186 struct sdpmedia *media = g_new0(struct sdpmedia, 1);
187 GList *codecs = sipe_backend_get_local_codecs(backend_media,
188 backend_stream);
189 guint rtcp_port = 0;
190 SipeMediaType type;
191 GSList *attributes = NULL;
192 GList *candidates;
193 GList *i;
195 media->name = g_strdup(sipe_backend_stream_get_id(backend_stream));
197 if (sipe_strequal(media->name, "audio"))
198 type = SIPE_MEDIA_AUDIO;
199 else if (sipe_strequal(media->name, "video"))
200 type = SIPE_MEDIA_VIDEO;
201 else {
202 // TODO: incompatible media, should not happen here
203 g_free(media->name);
204 g_free(media);
205 sipe_media_codec_list_free(codecs);
206 return(NULL);
209 // Process codecs
210 for (i = codecs; i; i = i->next) {
211 struct sipe_backend_codec *codec = i->data;
212 struct sdpcodec *c = g_new0(struct sdpcodec, 1);
213 GList *params;
215 c->id = sipe_backend_codec_get_id(codec);
216 c->name = sipe_backend_codec_get_name(codec);
217 c->clock_rate = sipe_backend_codec_get_clock_rate(codec);
218 c->type = type;
220 params = sipe_backend_codec_get_optional_parameters(codec);
221 for (; params; params = params->next) {
222 struct sipnameval *param = params->data;
223 struct sipnameval *copy = g_new0(struct sipnameval, 1);
225 copy->name = g_strdup(param->name);
226 copy->value = g_strdup(param->value);
228 c->parameters = g_slist_append(c->parameters, copy);
231 /* Buggy(?) codecs may report non-unique id (a.k.a. payload
232 * type) that must not appear in SDP messages we send. Thus,
233 * let's ignore any codec having the same id as one we already
234 * have in the converted list. */
235 media->codecs = sipe_utils_slist_insert_unique_sorted(
236 media->codecs, c, sdpcodec_compare,
237 (GDestroyNotify)sdpcodec_free);
240 sipe_media_codec_list_free(codecs);
242 // Process local candidates
243 // If we have established candidate pairs, send them in SDP response.
244 // Otherwise send all available local candidates.
245 candidates = sipe_backend_media_get_active_local_candidates(backend_media,
246 backend_stream);
247 if (!candidates)
248 candidates = sipe_backend_get_local_candidates(backend_media,
249 backend_stream);
251 media->candidates = backend_candidates_to_sdpcandidate(candidates);
253 sipe_media_candidate_list_free(candidates);
255 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
256 &rtcp_port, SIPE_CANDIDATE_TYPE_HOST);
257 // No usable HOST candidates, use any candidate
258 if (media->ip == NULL && media->candidates) {
259 get_stream_ip_and_ports(media->candidates, &media->ip, &media->port,
260 &rtcp_port, SIPE_CANDIDATE_TYPE_ANY);
263 if (sipe_backend_stream_is_held(backend_stream))
264 attributes = sipe_utils_nameval_add(attributes, "inactive", "");
266 if (rtcp_port) {
267 gchar *tmp = g_strdup_printf("%u", rtcp_port);
268 attributes = sipe_utils_nameval_add(attributes, "rtcp", tmp);
269 g_free(tmp);
272 attributes = sipe_utils_nameval_add(attributes, "encryption", "rejected");
274 media->attributes = attributes;
276 // Process remote candidates
277 candidates = sipe_backend_media_get_active_remote_candidates(backend_media,
278 backend_stream);
279 media->remote_candidates = backend_candidates_to_sdpcandidate(candidates);
280 sipe_media_candidate_list_free(candidates);
282 return media;
285 static struct sdpmsg *
286 sipe_media_to_sdpmsg(struct sipe_media_call_private *call_private)
288 struct sipe_backend_media *backend_media = call_private->public.backend_private;
289 struct sdpmsg *msg = g_new0(struct sdpmsg, 1);
290 GSList *streams = sipe_backend_media_get_streams(backend_media);
292 for (; streams; streams = streams->next) {
293 struct sdpmedia *media = backend_stream_to_sdpmedia(backend_media, streams->data);
294 if (media) {
295 msg->media = g_slist_append(msg->media, media);
297 if (msg->ip == NULL)
298 msg->ip = g_strdup(media->ip);
302 msg->media = g_slist_concat(msg->media, call_private->failed_media);
303 call_private->failed_media = NULL;
305 msg->ice_version = call_private->ice_version;
307 return msg;
310 static void
311 sipe_invite_call(struct sipe_core_private *sipe_private, TransCallback tc)
313 gchar *hdr;
314 gchar *contact;
315 gchar *p_preferred_identity = NULL;
316 gchar *body;
317 struct sipe_media_call_private *call_private = sipe_private->media_call;
318 struct sip_session *session;
319 struct sip_dialog *dialog;
320 struct sdpmsg *msg;
321 gboolean add_2007_fallback = FALSE;
323 session = sipe_session_find_call(sipe_private, call_private->with);
324 dialog = session->dialogs->data;
325 add_2007_fallback = dialog->cseq == 0 &&
326 call_private->ice_version == SIPE_ICE_RFC_5245 &&
327 !sipe_strequal(call_private->with, sipe_private->test_call_bot_uri);
329 contact = get_contact(sipe_private);
331 if (sipe_private->uc_line_uri) {
332 gchar *self = sip_uri_self(sipe_private);
333 p_preferred_identity = g_strdup_printf(
334 "P-Preferred-Identity: <%s>, <%s>\r\n",
335 self, sipe_private->uc_line_uri);
336 g_free(self);
339 hdr = g_strdup_printf(
340 "ms-keep-alive: UAC;hop-hop=yes\r\n"
341 "Contact: %s\r\n"
342 "%s"
343 "Content-Type: %s\r\n",
344 contact,
345 p_preferred_identity ? p_preferred_identity : "",
346 add_2007_fallback ?
347 "multipart/alternative;boundary=\"----=_NextPart_000_001E_01CB4397.0B5EB570\""
348 : "application/sdp");
349 g_free(contact);
350 g_free(p_preferred_identity);
352 msg = sipe_media_to_sdpmsg(call_private);
353 body = sdpmsg_to_string(msg);
355 if (add_2007_fallback) {
356 gchar *tmp;
357 tmp = g_strdup_printf(
358 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
359 "Content-Type: application/sdp\r\n"
360 "Content-Transfer-Encoding: 7bit\r\n"
361 "Content-Disposition: session; handling=optional; ms-proxy-2007fallback\r\n"
362 "\r\n"
363 "o=- 0 0 IN IP4 %s\r\n"
364 "s=session\r\n"
365 "c=IN IP4 %s\r\n"
366 "m=audio 0 RTP/AVP\r\n"
367 "\r\n"
368 "------=_NextPart_000_001E_01CB4397.0B5EB570\r\n"
369 "Content-Type: application/sdp\r\n"
370 "Content-Transfer-Encoding: 7bit\r\n"
371 "Content-Disposition: session; handling=optional\r\n"
372 "\r\n"
373 "%s"
374 "\r\n"
375 "------=_NextPart_000_001E_01CB4397.0B5EB570--\r\n",
376 msg->ip, msg->ip, body);
377 g_free(body);
378 body = tmp;
381 sdpmsg_free(msg);
383 dialog->outgoing_invite = sip_transport_invite(sipe_private,
384 hdr,
385 body,
386 dialog,
387 tc);
389 g_free(body);
390 g_free(hdr);
393 static struct sip_dialog *
394 sipe_media_dialog_init(struct sip_session* session, struct sipmsg *msg)
396 gchar *newTag = gentag();
397 const gchar *oldHeader;
398 gchar *newHeader;
399 struct sip_dialog *dialog;
401 oldHeader = sipmsg_find_header(msg, "To");
402 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
403 sipmsg_remove_header_now(msg, "To");
404 sipmsg_add_header_now(msg, "To", newHeader);
405 g_free(newHeader);
407 dialog = sipe_dialog_add(session);
408 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
409 dialog->with = parse_from(sipmsg_find_header(msg, "From"));
410 sipe_dialog_parse(dialog, msg, FALSE);
412 return dialog;
415 static void
416 send_response_with_session_description(struct sipe_media_call_private *call_private, int code, gchar *text)
418 struct sdpmsg *msg = sipe_media_to_sdpmsg(call_private);
419 gchar *body = sdpmsg_to_string(msg);
420 sdpmsg_free(msg);
421 sipmsg_add_header(call_private->invitation, "Content-Type", "application/sdp");
422 sip_transport_response(call_private->sipe_private, call_private->invitation, code, text, body);
423 g_free(body);
426 static gboolean
427 encryption_levels_compatible(struct sdpmsg *msg)
429 GSList *i;
431 for (i = msg->media; i; i = i->next) {
432 const gchar *enc_level;
433 struct sdpmedia *m = i->data;
435 enc_level = sipe_utils_nameval_find(m->attributes, "encryption");
437 // Decline call if peer requires encryption as we don't support it yet.
438 if (sipe_strequal(enc_level, "required"))
439 return FALSE;
442 return TRUE;
445 static gboolean
446 process_invite_call_response(struct sipe_core_private *sipe_private,
447 struct sipmsg *msg,
448 struct transaction *trans);
450 static gboolean
451 update_remote_media(struct sipe_media_call_private* call_private,
452 struct sdpmedia *media)
454 struct sipe_backend_media *backend_media = SIPE_MEDIA_CALL->backend_private;
455 struct sipe_backend_stream *backend_stream;
456 GList *backend_candidates = NULL;
457 GList *backend_codecs = NULL;
458 GSList *i;
459 gboolean result = TRUE;
461 backend_stream = sipe_backend_media_get_stream_by_id(backend_media,
462 media->name);
463 if (media->port == 0) {
464 if (backend_stream)
465 sipe_backend_media_remove_stream(backend_media, backend_stream);
466 return TRUE;
469 if (!backend_stream)
470 return FALSE;
472 for (i = media->codecs; i; i = i->next) {
473 struct sdpcodec *c = i->data;
474 struct sipe_backend_codec *codec;
475 GSList *j;
477 codec = sipe_backend_codec_new(c->id,
478 c->name,
479 c->type,
480 c->clock_rate);
482 for (j = c->parameters; j; j = j->next) {
483 struct sipnameval *attr = j->data;
485 sipe_backend_codec_add_optional_parameter(codec,
486 attr->name,
487 attr->value);
490 backend_codecs = g_list_append(backend_codecs, codec);
493 result = sipe_backend_set_remote_codecs(backend_media,
494 backend_stream,
495 backend_codecs);
496 sipe_media_codec_list_free(backend_codecs);
498 if (result == FALSE) {
499 sipe_backend_media_remove_stream(backend_media, backend_stream);
500 return FALSE;
503 for (i = media->candidates; i; i = i->next) {
504 struct sdpcandidate *c = i->data;
505 struct sipe_backend_candidate *candidate;
506 candidate = sipe_backend_candidate_new(c->foundation,
507 c->component,
508 c->type,
509 c->protocol,
510 c->ip,
511 c->port,
512 c->username,
513 c->password);
514 sipe_backend_candidate_set_priority(candidate, c->priority);
516 backend_candidates = g_list_append(backend_candidates, candidate);
519 sipe_backend_media_add_remote_candidates(backend_media,
520 backend_stream,
521 backend_candidates);
522 sipe_media_candidate_list_free(backend_candidates);
524 if (sipe_utils_nameval_find(media->attributes, "inactive")) {
525 sipe_backend_stream_hold(backend_media, backend_stream, FALSE);
526 } else if (sipe_backend_stream_is_held(backend_stream)) {
527 sipe_backend_stream_unhold(backend_media, backend_stream, FALSE);
530 return TRUE;
533 static void
534 apply_remote_message(struct sipe_media_call_private* call_private,
535 struct sdpmsg* msg)
537 GSList *i;
539 sipe_utils_slist_free_full(call_private->failed_media, (GDestroyNotify)sdpmedia_free);
540 call_private->failed_media = NULL;
542 for (i = msg->media; i; i = i->next) {
543 struct sdpmedia *media = i->data;
544 if (!update_remote_media(call_private, media)) {
545 media->port = 0;
546 call_private->failed_media =
547 g_slist_append(call_private->failed_media, media);
551 /* We need to keep failed medias until response is sent, remove them
552 * from sdpmsg that is to be freed. */
553 for (i = call_private->failed_media; i; i = i->next) {
554 msg->media = g_slist_remove(msg->media, i->data);
557 call_private->encryption_compatible = encryption_levels_compatible(msg);
560 static gboolean
561 call_initialized(struct sipe_media_call *call)
563 GSList *streams =
564 sipe_backend_media_get_streams(call->backend_private);
566 for (; streams; streams = streams->next) {
567 if (!sipe_backend_stream_initialized(call->backend_private,
568 streams->data)) {
569 return FALSE;
573 return TRUE;
576 // Sends an invite response when the call is accepted and local candidates were
577 // prepared, otherwise does nothing. If error response is sent, call_private is
578 // disposed before function returns. Returns true when response was sent.
579 static gboolean
580 send_invite_response_if_ready(struct sipe_media_call_private *call_private)
582 struct sipe_backend_media *backend_media;
584 backend_media = call_private->public.backend_private;
586 if (!sipe_backend_media_accepted(backend_media) ||
587 !call_initialized(&call_private->public))
588 return FALSE;
590 if (!call_private->encryption_compatible) {
591 struct sipe_core_private *sipe_private = call_private->sipe_private;
593 sipmsg_add_header(call_private->invitation, "Warning",
594 "308 lcs.microsoft.com \"Encryption Levels not compatible\"");
595 sip_transport_response(sipe_private,
596 call_private->invitation,
597 488, "Encryption Levels not compatible",
598 NULL);
599 sipe_backend_media_reject(backend_media, FALSE);
600 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
601 _("Unable to establish a call"),
602 _("Encryption settings of peer are incompatible with ours."));
603 } else {
604 send_response_with_session_description(call_private, 200, "OK");
607 return TRUE;
610 static void
611 stream_initialized_cb(struct sipe_media_call *call,
612 struct sipe_backend_stream *stream)
614 if (call_initialized(call)) {
615 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
616 struct sipe_backend_media *backend_private = call->backend_private;
618 if (sipe_backend_media_is_initiator(backend_private, stream)) {
619 sipe_invite_call(call_private->sipe_private,
620 process_invite_call_response);
621 } else if (call_private->smsg) {
622 struct sdpmsg *smsg = call_private->smsg;
623 call_private->smsg = NULL;
625 apply_remote_message(call_private, smsg);
626 send_invite_response_if_ready(call_private);
627 sdpmsg_free(smsg);
632 static void phone_state_publish(struct sipe_core_private *sipe_private)
634 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) {
635 sipe_ocs2007_phone_state_publish(sipe_private);
636 } else {
637 // TODO: OCS 2005 support. Is anyone still using it at all?
641 static void
642 media_end_cb(struct sipe_media_call *call)
644 g_return_if_fail(call);
646 SIPE_MEDIA_CALL_PRIVATE->sipe_private->media_call = NULL;
647 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
648 sipe_media_call_free(SIPE_MEDIA_CALL_PRIVATE);
651 static void
652 call_accept_cb(struct sipe_media_call *call, gboolean local)
654 if (local) {
655 send_invite_response_if_ready(SIPE_MEDIA_CALL_PRIVATE);
657 phone_state_publish(SIPE_MEDIA_CALL_PRIVATE->sipe_private);
660 static void
661 call_reject_cb(struct sipe_media_call *call, gboolean local)
663 if (local) {
664 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
665 sip_transport_response(call_private->sipe_private,
666 call_private->invitation,
667 603, "Decline", NULL);
671 static gboolean
672 sipe_media_send_ack(struct sipe_core_private *sipe_private, struct sipmsg *msg,
673 struct transaction *trans);
675 static void call_hold_cb(struct sipe_media_call *call,
676 gboolean local,
677 SIPE_UNUSED_PARAMETER gboolean state)
679 if (local)
680 sipe_invite_call(SIPE_MEDIA_CALL_PRIVATE->sipe_private,
681 sipe_media_send_ack);
684 static void call_hangup_cb(struct sipe_media_call *call, gboolean local)
686 if (local) {
687 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
688 struct sip_session *session;
689 session = sipe_session_find_call(call_private->sipe_private,
690 call_private->with);
692 if (session) {
693 sipe_session_close(call_private->sipe_private, session);
698 static void
699 error_cb(struct sipe_media_call *call, gchar *message)
701 struct sipe_media_call_private *call_private = SIPE_MEDIA_CALL_PRIVATE;
702 struct sipe_core_private *sipe_private = call_private->sipe_private;
703 gboolean initiator = sipe_backend_media_is_initiator(call->backend_private, NULL);
704 gboolean accepted = sipe_backend_media_accepted(call->backend_private);
706 gchar *title = g_strdup_printf("Call with %s failed", call_private->with);
707 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, message);
708 g_free(title);
710 if (!initiator && !accepted) {
711 sip_transport_response(sipe_private,
712 call_private->invitation,
713 488, "Not Acceptable Here", NULL);
716 sipe_backend_media_hangup(call->backend_private, initiator || accepted);
719 static struct sipe_media_call_private *
720 sipe_media_call_new(struct sipe_core_private *sipe_private,
721 const gchar* with, gboolean initiator, SipeIceVersion ice_version)
723 struct sipe_media_call_private *call_private = g_new0(struct sipe_media_call_private, 1);
724 gchar *cname;
726 call_private->sipe_private = sipe_private;
728 cname = g_strdup(sipe_private->contact + 1);
729 cname[strlen(cname) - 1] = '\0';
731 call_private->public.backend_private = sipe_backend_media_new(SIPE_CORE_PUBLIC,
732 SIPE_MEDIA_CALL,
733 with,
734 initiator);
735 sipe_backend_media_set_cname(call_private->public.backend_private, cname);
737 call_private->ice_version = ice_version;
738 call_private->encryption_compatible = TRUE;
740 call_private->public.stream_initialized_cb = stream_initialized_cb;
741 call_private->public.media_end_cb = media_end_cb;
742 call_private->public.call_accept_cb = call_accept_cb;
743 call_private->public.call_reject_cb = call_reject_cb;
744 call_private->public.call_hold_cb = call_hold_cb;
745 call_private->public.call_hangup_cb = call_hangup_cb;
746 call_private->public.error_cb = error_cb;
748 g_free(cname);
750 return call_private;
753 void sipe_media_hangup(struct sipe_media_call_private *call_private)
755 if (call_private) {
756 sipe_backend_media_hangup(call_private->public.backend_private,
757 FALSE);
761 static void
762 sipe_media_initiate_call(struct sipe_core_private *sipe_private,
763 const char *with, SipeIceVersion ice_version,
764 gboolean with_video)
766 struct sipe_media_call_private *call_private;
767 struct sipe_backend_media *backend_media;
768 struct sipe_backend_media_relays *backend_media_relays;
769 struct sip_session *session;
770 struct sip_dialog *dialog;
772 if (sipe_private->media_call)
773 return;
775 call_private = sipe_media_call_new(sipe_private, with, TRUE, ice_version);
777 session = sipe_session_add_call(sipe_private, with);
778 dialog = sipe_dialog_add(session);
779 dialog->callid = gencallid();
780 dialog->with = g_strdup(session->with);
781 dialog->ourtag = gentag();
783 call_private->with = g_strdup(session->with);
785 backend_media = call_private->public.backend_private;
787 backend_media_relays =
788 sipe_backend_media_relays_convert(sipe_private->media_relays,
789 sipe_private->media_relay_username,
790 sipe_private->media_relay_password);
792 if (!sipe_backend_media_add_stream(backend_media,
793 "audio", with, SIPE_MEDIA_AUDIO,
794 call_private->ice_version, TRUE,
795 backend_media_relays)) {
796 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
797 _("Error occured"),
798 _("Error creating audio stream"));
799 sipe_media_hangup(call_private);
800 sipe_backend_media_relays_free(backend_media_relays);
801 return;
804 if ( with_video
805 && !sipe_backend_media_add_stream(backend_media,
806 "video", with, SIPE_MEDIA_VIDEO,
807 call_private->ice_version, TRUE,
808 backend_media_relays)) {
809 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
810 _("Error occured"),
811 _("Error creating video stream"));
812 sipe_media_hangup(call_private);
813 sipe_backend_media_relays_free(backend_media_relays);
814 return;
817 sipe_private->media_call = call_private;
819 sipe_backend_media_relays_free(backend_media_relays);
821 // Processing continues in stream_initialized_cb
824 void
825 sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
826 const char *with,
827 gboolean with_video)
829 sipe_media_initiate_call(SIPE_CORE_PRIVATE, with,
830 SIPE_ICE_RFC_5245, with_video);
833 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
834 struct sipe_chat_session *chat_session)
836 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
837 struct sipe_backend_media_relays *backend_media_relays;
838 struct sip_session *session;
839 struct sip_dialog *dialog;
840 SipeIceVersion ice_version;
841 gchar **parts;
842 gchar *av_uri;
844 session = sipe_session_find_chat(sipe_private, chat_session);
846 if (sipe_private->media_call || !session)
847 return;
849 session->is_call = TRUE;
851 parts = g_strsplit(chat_session->id, "app:conf:focus:", 2);
852 av_uri = g_strjoinv("app:conf:audio-video:", parts);
853 g_strfreev(parts);
855 ice_version = SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013) ? SIPE_ICE_RFC_5245 :
856 SIPE_ICE_DRAFT_6;
858 sipe_private->media_call = sipe_media_call_new(sipe_private, av_uri,
859 TRUE, ice_version);
861 session = sipe_session_add_call(sipe_private, av_uri);
862 dialog = sipe_dialog_add(session);
863 dialog->callid = gencallid();
864 dialog->with = g_strdup(session->with);
865 dialog->ourtag = gentag();
867 g_free(av_uri);
869 sipe_private->media_call->with = g_strdup(session->with);
871 backend_media_relays =
872 sipe_backend_media_relays_convert(sipe_private->media_relays,
873 sipe_private->media_relay_username,
874 sipe_private->media_relay_password);
876 if (!sipe_backend_media_add_stream(sipe_private->media_call->public.backend_private,
877 "audio", dialog->with,
878 SIPE_MEDIA_AUDIO,
879 sipe_private->media_call->ice_version,
880 TRUE, backend_media_relays)) {
881 sipe_backend_notify_error(sipe_public,
882 _("Error occured"),
883 _("Error creating audio stream"));
884 sipe_media_hangup(sipe_private->media_call);
885 sipe_private->media_call = NULL;
888 sipe_backend_media_relays_free(backend_media_relays);
890 // Processing continues in stream_initialized_cb
893 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public)
895 if (sipe_public) {
896 return SIPE_CORE_PRIVATE->media_call != NULL;
898 return FALSE;
901 static gboolean phone_number_is_valid(const gchar *phone_number)
903 if (!phone_number || sipe_strequal(phone_number, "")) {
904 return FALSE;
907 if (*phone_number == '+') {
908 ++phone_number;
911 while (*phone_number != '\0') {
912 if (!g_ascii_isdigit(*phone_number)) {
913 return FALSE;
915 ++phone_number;
918 return TRUE;
921 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
922 const gchar *phone_number)
924 g_return_if_fail(sipe_public);
926 if (phone_number_is_valid(phone_number)) {
927 gchar *phone_uri = g_strdup_printf("sip:%s@%s;user=phone",
928 phone_number, sipe_public->sip_domain);
930 sipe_core_media_initiate_call(sipe_public, phone_uri, FALSE);
932 g_free(phone_uri);
933 } else {
934 sipe_backend_notify_error(sipe_public,
935 _("Unable to establish a call"),
936 _("Invalid phone number"));
940 void sipe_core_media_test_call(struct sipe_core_public *sipe_public)
942 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
943 if (!sipe_private->test_call_bot_uri) {
944 sipe_backend_notify_error(sipe_public,
945 _("Unable to establish a call"),
946 _("Audio Test Service is not available."));
947 return;
950 sipe_core_media_initiate_call(sipe_public,
951 sipe_private->test_call_bot_uri, FALSE);
954 void
955 process_incoming_invite_call(struct sipe_core_private *sipe_private,
956 struct sipmsg *msg)
958 struct sipe_media_call_private *call_private = sipe_private->media_call;
959 struct sipe_backend_media *backend_media;
960 struct sipe_backend_media_relays *backend_media_relays = NULL;
961 struct sdpmsg *smsg;
962 gboolean has_new_media = FALSE;
963 GSList *i;
965 if (call_private) {
966 char *self;
968 if (!is_media_session_msg(call_private, msg)) {
969 sip_transport_response(sipe_private, msg, 486, "Busy Here", NULL);
970 return;
973 self = sip_uri_self(sipe_private);
974 if (sipe_strequal(call_private->with, self)) {
975 g_free(self);
976 sip_transport_response(sipe_private, msg, 488, "Not Acceptable Here", NULL);
977 return;
979 g_free(self);
982 smsg = sdpmsg_parse_msg(msg->body);
983 if (!smsg) {
984 sip_transport_response(sipe_private, msg,
985 488, "Not Acceptable Here", NULL);
986 sipe_media_hangup(call_private);
987 return;
990 if (!call_private) {
991 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
992 struct sip_session *session;
994 call_private = sipe_media_call_new(sipe_private, with, FALSE, smsg->ice_version);
995 session = sipe_session_add_call(sipe_private, with);
996 sipe_media_dialog_init(session, msg);
998 call_private->with = g_strdup(session->with);
999 sipe_private->media_call = call_private;
1000 g_free(with);
1003 backend_media = call_private->public.backend_private;
1005 if (call_private->invitation)
1006 sipmsg_free(call_private->invitation);
1007 call_private->invitation = sipmsg_copy(msg);
1009 if (smsg->media)
1010 backend_media_relays = sipe_backend_media_relays_convert(
1011 sipe_private->media_relays,
1012 sipe_private->media_relay_username,
1013 sipe_private->media_relay_password);
1015 // Create any new media streams
1016 for (i = smsg->media; i; i = i->next) {
1017 struct sdpmedia *media = i->data;
1018 gchar *id = media->name;
1019 SipeMediaType type;
1021 if ( media->port != 0
1022 && !sipe_backend_media_get_stream_by_id(backend_media, id)) {
1023 gchar *with;
1025 if (sipe_strequal(id, "audio"))
1026 type = SIPE_MEDIA_AUDIO;
1027 else if (sipe_strequal(id, "video"))
1028 type = SIPE_MEDIA_VIDEO;
1029 else
1030 continue;
1032 with = parse_from(sipmsg_find_header(msg, "From"));
1033 sipe_backend_media_add_stream(backend_media, id, with,
1034 type,
1035 smsg->ice_version,
1036 FALSE,
1037 backend_media_relays);
1038 has_new_media = TRUE;
1039 g_free(with);
1043 sipe_backend_media_relays_free(backend_media_relays);
1045 if (has_new_media) {
1046 sdpmsg_free(call_private->smsg);
1047 call_private->smsg = smsg;
1048 sip_transport_response(sipe_private, call_private->invitation,
1049 180, "Ringing", NULL);
1050 // Processing continues in stream_initialized_cb
1051 } else {
1052 apply_remote_message(call_private, smsg);
1053 send_response_with_session_description(call_private, 200, "OK");
1055 sdpmsg_free(smsg);
1059 void process_incoming_cancel_call(struct sipe_core_private *sipe_private,
1060 struct sipmsg *msg)
1062 struct sipe_media_call_private *call_private = sipe_private->media_call;
1064 // We respond to the CANCEL request with 200 OK response and
1065 // with 487 Request Terminated to the remote INVITE in progress.
1066 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1068 if (call_private->invitation) {
1069 sip_transport_response(sipe_private, call_private->invitation,
1070 487, "Request Terminated", NULL);
1073 sipe_media_hangup(call_private);
1076 static gboolean
1077 sipe_media_send_ack(struct sipe_core_private *sipe_private,
1078 struct sipmsg *msg,
1079 struct transaction *trans)
1081 struct sipe_media_call_private *call_private = sipe_private->media_call;
1082 struct sip_session *session;
1083 struct sip_dialog *dialog;
1084 int tmp_cseq;
1086 if (!is_media_session_msg(call_private, msg))
1087 return FALSE;
1089 session = sipe_session_find_call(sipe_private, call_private->with);
1090 dialog = session->dialogs->data;
1091 if (!dialog)
1092 return FALSE;
1094 tmp_cseq = dialog->cseq;
1096 dialog->cseq = sip_transaction_cseq(trans) - 1;
1097 sip_transport_ack(sipe_private, dialog);
1098 dialog->cseq = tmp_cseq;
1100 dialog->outgoing_invite = NULL;
1102 return TRUE;
1105 static gboolean
1106 sipe_media_send_final_ack(struct sipe_core_private *sipe_private,
1107 struct sipmsg *msg,
1108 struct transaction *trans)
1110 if (!sipe_media_send_ack(sipe_private, msg, trans))
1111 return FALSE;
1113 sipe_backend_media_accept(sipe_private->media_call->public.backend_private,
1114 FALSE);
1116 return TRUE;
1119 static void
1120 reinvite_on_candidate_pair_cb(struct sipe_core_public *sipe_public)
1122 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1123 struct sipe_media_call_private *media_call = sipe_private->media_call;
1124 struct sipe_backend_media *backend_media;
1125 GSList *streams;
1127 if (!media_call)
1128 return;
1130 backend_media = media_call->public.backend_private;
1131 streams = sipe_backend_media_get_streams(backend_media);
1133 for (; streams; streams = streams->next) {
1134 struct sipe_backend_stream *s = streams->data;
1135 GList *remote_candidates = sipe_backend_media_get_active_remote_candidates(backend_media, s);
1136 guint components = g_list_length(remote_candidates);
1138 sipe_media_candidate_list_free(remote_candidates);
1140 // We must have candidates for both (RTP + RTCP) components ready
1141 if (components < 2) {
1142 sipe_schedule_mseconds(sipe_private,
1143 "<+media-reinvite-on-candidate-pair>",
1144 NULL,
1145 500,
1146 (sipe_schedule_action) reinvite_on_candidate_pair_cb,
1147 NULL);
1148 return;
1152 sipe_invite_call(sipe_private, sipe_media_send_final_ack);
1155 static gboolean
1156 maybe_retry_call_with_ice_version(struct sipe_core_private *sipe_private,
1157 SipeIceVersion ice_version,
1158 struct transaction *trans)
1160 struct sipe_media_call_private *call_private = sipe_private->media_call;
1162 if (call_private->ice_version != ice_version &&
1163 sip_transaction_cseq(trans) == 1) {
1164 gchar *with = g_strdup(call_private->with);
1165 struct sipe_backend_media *backend_private = call_private->public.backend_private;
1166 gboolean with_video = sipe_backend_media_get_stream_by_id(backend_private, "video") != NULL;
1168 sipe_media_hangup(call_private);
1169 SIPE_DEBUG_INFO("Retrying call with ICEv%d.",
1170 ice_version == SIPE_ICE_DRAFT_6 ? 6 : 19);
1171 sipe_media_initiate_call(sipe_private, with, ice_version,
1172 with_video);
1174 g_free(with);
1175 return TRUE;
1178 return FALSE;
1181 static gboolean
1182 process_invite_call_response(struct sipe_core_private *sipe_private,
1183 struct sipmsg *msg,
1184 struct transaction *trans)
1186 const gchar *with;
1187 struct sipe_media_call_private *call_private = sipe_private->media_call;
1188 struct sip_session *session;
1189 struct sip_dialog *dialog;
1190 struct sdpmsg *smsg;
1192 if (!is_media_session_msg(call_private, msg))
1193 return FALSE;
1195 session = sipe_session_find_call(sipe_private, call_private->with);
1196 dialog = session->dialogs->data;
1198 with = dialog->with;
1200 dialog->outgoing_invite = NULL;
1202 if (msg->response >= 400) {
1203 // Call rejected by remote peer or an error occurred
1204 const gchar *title;
1205 GString *desc = g_string_new("");
1206 gboolean append_responsestr = FALSE;
1208 switch (msg->response) {
1209 case 480: {
1210 title = _("User unavailable");
1212 if (sipmsg_parse_warning(msg, NULL) == 391) {
1213 g_string_append_printf(desc, _("%s does not want to be disturbed"), with);
1214 } else
1215 g_string_append_printf(desc, _("User %s is not available"), with);
1216 break;
1218 case 603:
1219 case 605:
1220 title = _("Call rejected");
1221 g_string_append_printf(desc, _("User %s rejected call"), with);
1222 break;
1223 case 415:
1224 // OCS/Lync really sends response string with 'Mutipart' typo.
1225 if (sipe_strequal(msg->responsestr, "Mutipart mime in content type not supported by Archiving CDR service") &&
1226 maybe_retry_call_with_ice_version(sipe_private, SIPE_ICE_DRAFT_6, trans)) {
1227 return TRUE;
1229 title = _("Unsupported media type");
1230 break;
1231 case 488: {
1232 /* Check for incompatible encryption levels error.
1234 * MS Lync 2010:
1235 * 488 Not Acceptable Here
1236 * ms-client-diagnostics: 52017;reason="Encryption levels dont match"
1238 * older clients (and SIPE itself):
1239 * 488 Encryption Levels not compatible
1241 const gchar *ms_diag = sipmsg_find_header(msg, "ms-client-diagnostics");
1242 SipeIceVersion retry_ice_version = SIPE_ICE_DRAFT_6;
1244 if (sipe_strequal(msg->responsestr, "Encryption Levels not compatible") ||
1245 (ms_diag && g_str_has_prefix(ms_diag, "52017;"))) {
1246 title = _("Unable to establish a call");
1247 g_string_append(desc, _("Encryption settings of peer are incompatible with ours."));
1248 break;
1251 /* Check if this is failed conference using
1252 * ICEv6 with reason "Error parsing SDP" and
1253 * retry using ICEv19. */
1254 ms_diag = sipmsg_find_header(msg, "ms-diagnostics");
1255 if (ms_diag && g_str_has_prefix(ms_diag, "7008;")) {
1256 retry_ice_version = SIPE_ICE_RFC_5245;
1259 if (maybe_retry_call_with_ice_version(sipe_private, retry_ice_version, trans)) {
1260 return TRUE;
1262 // Break intentionally omitted
1264 default:
1265 title = _("Error occured");
1266 g_string_append(desc, _("Unable to establish a call"));
1267 append_responsestr = TRUE;
1268 break;
1271 if (append_responsestr) {
1272 gchar *reason = sipmsg_get_ms_diagnostics_reason(msg);
1274 g_string_append_printf(desc, "\n%d %s",
1275 msg->response, msg->responsestr);
1276 if (reason) {
1277 g_string_append_printf(desc, "\n\n%s", reason);
1278 g_free(reason);
1282 sipe_backend_notify_error(SIPE_CORE_PUBLIC, title, desc->str);
1283 g_string_free(desc, TRUE);
1285 sipe_media_send_ack(sipe_private, msg, trans);
1286 sipe_media_hangup(call_private);
1288 return TRUE;
1291 sipe_dialog_parse(dialog, msg, TRUE);
1292 smsg = sdpmsg_parse_msg(msg->body);
1293 if (!smsg) {
1294 sip_transport_response(sipe_private, msg,
1295 488, "Not Acceptable Here", NULL);
1296 sipe_media_hangup(call_private);
1297 return FALSE;
1300 apply_remote_message(call_private, smsg);
1301 sdpmsg_free(smsg);
1303 sipe_media_send_ack(sipe_private, msg, trans);
1304 reinvite_on_candidate_pair_cb(SIPE_CORE_PUBLIC);
1306 return TRUE;
1309 gboolean is_media_session_msg(struct sipe_media_call_private *call_private,
1310 struct sipmsg *msg)
1312 if (call_private) {
1313 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1314 struct sip_session *session;
1316 session = sipe_session_find_call(call_private->sipe_private,
1317 call_private->with);
1318 if (session) {
1319 struct sip_dialog *dialog = session->dialogs->data;
1320 return sipe_strequal(dialog->callid, callid);
1323 return FALSE;
1326 void sipe_media_handle_going_offline(struct sipe_media_call_private *call_private)
1328 struct sipe_backend_media *backend_private;
1330 backend_private = call_private->public.backend_private;
1332 if ( !sipe_backend_media_is_initiator(backend_private, NULL)
1333 && !sipe_backend_media_accepted(backend_private)) {
1334 sip_transport_response(call_private->sipe_private,
1335 call_private->invitation,
1336 480, "Temporarily Unavailable", NULL);
1337 } else {
1338 struct sip_session *session;
1340 session = sipe_session_find_call(call_private->sipe_private,
1341 call_private->with);
1342 if (session)
1343 sipe_session_close(call_private->sipe_private, session);
1346 sipe_media_hangup(call_private);
1349 gboolean sipe_media_is_conference_call(struct sipe_media_call_private *call_private)
1351 return g_strstr_len(call_private->with, -1, "app:conf:audio-video:") != NULL;
1354 static void
1355 sipe_media_relay_free(struct sipe_media_relay *relay)
1357 g_free(relay->hostname);
1358 if (relay->dns_query)
1359 sipe_backend_dns_query_cancel(relay->dns_query);
1360 g_free(relay);
1363 void
1364 sipe_media_relay_list_free(GSList *list)
1366 for (; list; list = g_slist_delete_link(list, list))
1367 sipe_media_relay_free(list->data);
1370 static void
1371 relay_ip_resolved_cb(struct sipe_media_relay* relay,
1372 const gchar *ip, SIPE_UNUSED_PARAMETER guint port)
1374 gchar *hostname = relay->hostname;
1375 relay->dns_query = NULL;
1377 if (ip && port) {
1378 relay->hostname = g_strdup(ip);
1379 SIPE_DEBUG_INFO("Media relay %s resolved to %s.", hostname, ip);
1380 } else {
1381 relay->hostname = NULL;
1382 SIPE_DEBUG_INFO("Unable to resolve media relay %s.", hostname);
1385 g_free(hostname);
1388 static gboolean
1389 process_get_av_edge_credentials_response(struct sipe_core_private *sipe_private,
1390 struct sipmsg *msg,
1391 SIPE_UNUSED_PARAMETER struct transaction *trans)
1393 g_free(sipe_private->media_relay_username);
1394 g_free(sipe_private->media_relay_password);
1395 sipe_media_relay_list_free(sipe_private->media_relays);
1396 sipe_private->media_relay_username = NULL;
1397 sipe_private->media_relay_password = NULL;
1398 sipe_private->media_relays = NULL;
1400 if (msg->response >= 400) {
1401 SIPE_DEBUG_INFO_NOFORMAT("process_get_av_edge_credentials_response: SERVICE response is not 200. "
1402 "Failed to obtain A/V Edge credentials.");
1403 return FALSE;
1406 if (msg->response == 200) {
1407 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
1409 if (sipe_strequal("OK", sipe_xml_attribute(xn_response, "reasonPhrase"))) {
1410 const sipe_xml *xn_credentials = sipe_xml_child(xn_response, "credentialsResponse/credentials");
1411 const sipe_xml *xn_relays = sipe_xml_child(xn_response, "credentialsResponse/mediaRelayList");
1412 const sipe_xml *item;
1413 GSList *relays = NULL;
1415 item = sipe_xml_child(xn_credentials, "username");
1416 sipe_private->media_relay_username = sipe_xml_data(item);
1417 item = sipe_xml_child(xn_credentials, "password");
1418 sipe_private->media_relay_password = sipe_xml_data(item);
1420 for (item = sipe_xml_child(xn_relays, "mediaRelay"); item; item = sipe_xml_twin(item)) {
1421 struct sipe_media_relay *relay = g_new0(struct sipe_media_relay, 1);
1422 const sipe_xml *node;
1423 gchar *tmp;
1425 node = sipe_xml_child(item, "hostName");
1426 relay->hostname = sipe_xml_data(node);
1428 node = sipe_xml_child(item, "udpPort");
1429 if (node) {
1430 relay->udp_port = atoi(tmp = sipe_xml_data(node));
1431 g_free(tmp);
1434 node = sipe_xml_child(item, "tcpPort");
1435 if (node) {
1436 relay->tcp_port = atoi(tmp = sipe_xml_data(node));
1437 g_free(tmp);
1440 relays = g_slist_append(relays, relay);
1442 relay->dns_query = sipe_backend_dns_query_a(
1443 SIPE_CORE_PUBLIC,
1444 relay->hostname,
1445 relay->udp_port,
1446 (sipe_dns_resolved_cb) relay_ip_resolved_cb,
1447 relay);
1449 SIPE_DEBUG_INFO("Media relay: %s TCP: %d UDP: %d",
1450 relay->hostname,
1451 relay->tcp_port, relay->udp_port);
1454 sipe_private->media_relays = relays;
1457 sipe_xml_free(xn_response);
1460 return TRUE;
1463 void
1464 sipe_media_get_av_edge_credentials(struct sipe_core_private *sipe_private)
1466 // TODO: re-request credentials after duration expires?
1467 const char CRED_REQUEST_XML[] =
1468 "<request requestID=\"%d\" "
1469 "from=\"%s\" "
1470 "version=\"1.0\" "
1471 "to=\"%s\" "
1472 "xmlns=\"http://schemas.microsoft.com/2006/09/sip/mrasp\" "
1473 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
1474 "<credentialsRequest credentialsRequestID=\"%d\">"
1475 "<identity>%s</identity>"
1476 "<location>%s</location>"
1477 "<duration>480</duration>"
1478 "</credentialsRequest>"
1479 "</request>";
1481 int request_id = rand();
1482 gchar *self;
1483 gchar *body;
1485 if (!sipe_private->mras_uri)
1486 return;
1488 self = sip_uri_self(sipe_private);
1490 body = g_strdup_printf(
1491 CRED_REQUEST_XML,
1492 request_id,
1493 self,
1494 sipe_private->mras_uri,
1495 request_id,
1496 self,
1497 SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER) ? "internet" : "intranet");
1498 g_free(self);
1500 sip_transport_service(sipe_private,
1501 sipe_private->mras_uri,
1502 "Content-Type: application/msrtc-media-relay-auth+xml\r\n",
1503 body,
1504 process_get_av_edge_credentials_response);
1506 g_free(body);
1510 Local Variables:
1511 mode: c
1512 c-file-style: "bsd"
1513 indent-tabs-mode: t
1514 tab-width: 8
1515 End: