6 * Copyright (C) 2010-2015 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Documentation references:
28 * Microsoft DevNet: [MS-CONFIM]: Centralized Conference Control Protocol:
29 * Instant Messaging Extensions
30 * <http://msdn.microsoft.com/en-us/library/cc431500%28v=office.12%29.aspx>
44 #include "sipe-common.h"
46 #include "sip-transport.h"
47 #include "sipe-backend.h"
48 #include "sipe-buddy.h"
49 #include "sipe-chat.h"
50 #include "sipe-conf.h"
51 #include "sipe-core.h"
52 #include "sipe-core-private.h"
53 #include "sipe-dialog.h"
54 #include "sipe-http.h"
57 #include "sipe-session.h"
58 #include "sipe-subscriptions.h"
59 #include "sipe-user.h"
60 #include "sipe-utils.h"
64 * Invite counterparty to join conference.
65 * @param focus_uri (%s)
66 * @param subject (%s) of conference
68 #define SIPE_SEND_CONF_INVITE \
69 "<Conferencing version=\"2.0\">"\
70 "<focus-uri>%s</focus-uri>"\
71 "<subject>%s</subject>"\
72 "<im available=\"true\">"\
77 static struct transaction
*
78 cccp_request(struct sipe_core_private
*sipe_private
, const gchar
*method
,
79 const gchar
*with
, struct sip_dialog
*dialog
,
80 TransCallback callback
, const gchar
*body
, ...)
86 gchar
*self
= sip_uri_self(sipe_private
);
90 struct transaction
*trans
;
92 headers
= g_strdup_printf(
93 "Supported: ms-sender\r\n"
95 "Content-Type: application/cccp+xml\r\n",
96 sipe_private
->contact
);
98 /* TODO: put request_id to queue to further compare with incoming one */
99 request
= g_strdup_printf(
100 "<?xml version=\"1.0\"?>"
101 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "
102 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "
111 sipe_private
->cccp_request_id
++,
115 va_start(args
, body
);
116 request_body
= g_strdup_vprintf(request
, args
);
121 trans
= sip_transport_request(sipe_private
,
131 g_free(request_body
);
137 process_conf_get_capabilities(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
139 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
141 if (msg
->response
>= 400) {
142 SIPE_DEBUG_INFO_NOFORMAT("process_conf_get_capabilities: "
143 "getConferencingCapabilities failed.");
146 if (msg
->response
== 200) {
147 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
149 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code"))) {
150 const sipe_xml
*node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/mcu-types/mcuType");
151 for (;node
; node
= sipe_xml_twin(node
)) {
152 sipe_private
->conf_mcu_types
=
153 g_slist_append(sipe_private
->conf_mcu_types
,
154 sipe_xml_data(node
));
158 sipe_xml_free(xn_response
);
165 sipe_conf_get_capabilities(struct sipe_core_private
*sipe_private
)
167 cccp_request(sipe_private
, "SERVICE",
168 sipe_private
->focus_factory_uri
,
170 process_conf_get_capabilities
,
171 "<getConferencingCapabilities />");
175 sipe_conf_supports_mcu_type(struct sipe_core_private
*sipe_private
,
178 return g_slist_find_custom(sipe_private
->conf_mcu_types
, type
,
179 sipe_strcompare
) != NULL
;
183 * Generates random GUID.
184 * This method is borrowed from pidgin's msnutils.c
189 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
190 rand() % 0xAAFF + 0x1111,
191 rand() % 0xAAFF + 0x1111,
192 rand() % 0xAAFF + 0x1111,
193 rand() % 0xAAFF + 0x1111,
194 rand() % 0xAAFF + 0x1111,
195 rand() % 0xAAFF + 0x1111,
196 rand() % 0xAAFF + 0x1111,
197 rand() % 0xAAFF + 0x1111);
200 /** Invite us to the focus callback */
202 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
204 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
206 struct sip_session
*session
= NULL
;
207 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
209 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
212 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
217 if (!session
->focus_dialog
) {
218 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
223 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
225 if (msg
->response
>= 200) {
226 /* send ACK to focus */
227 session
->focus_dialog
->cseq
= 0;
228 sip_transport_ack(sipe_private
, session
->focus_dialog
);
229 session
->focus_dialog
->outgoing_invite
= NULL
;
230 session
->focus_dialog
->is_established
= TRUE
;
233 if (msg
->response
>= 400) {
234 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
236 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
237 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
238 _("Failed to join the conference"),
239 reason
? reason
: _("no reason given"));
242 sipe_session_remove(sipe_private
, session
);
245 } else if (msg
->response
== 200) {
246 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
247 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
248 if (sipe_strequal(code
, "success")) {
249 /* subscribe to focus */
250 sipe_subscribe_conference(sipe_private
,
251 session
->chat_session
->id
,
254 if (session
->is_call
)
255 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
256 session
->chat_session
);
259 sipe_xml_free(xn_response
);
267 parse_ocs_focus_uri(const gchar
*uri
)
269 const gchar
*confkey
;
275 // URI can have this prefix if it was typed in by the user
276 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
280 uri_len
= strlen(uri
);
282 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
283 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
287 confkey
= g_strstr_len(uri
, -1, "?");
289 /* TODO: Investigate how conf-key field should be used,
290 * ignoring for now */
291 uri_len
= confkey
- uri
;
294 return g_strndup(uri
, uri_len
);
298 parse_lync_join_url(const gchar
*uri
)
300 gchar
*focus_uri
= NULL
;
307 if (g_str_has_prefix(uri
, "https://")) {
309 } else if (g_str_has_prefix(uri
, "http://")) {
313 parts
= g_strsplit(uri
, "/", 0);
315 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
316 if (parts_count
>= 3) {
317 const gchar
*conference_id
= parts
[parts_count
- 1];
318 const gchar
*organizer_alias
= parts
[parts_count
- 2];
320 gchar
**domain_parts
= g_strsplit(parts
[0], ".", 2);
322 /* we need to drop the first sub-domain from the URL */
323 if (domain_parts
[0] && domain_parts
[1]) {
324 focus_uri
= g_strdup_printf("sip:%s@%s;gruu;opaque=app:conf:focus:id:%s",
330 g_strfreev(domain_parts
);
338 static void sipe_conf_error(struct sipe_core_private
*sipe_private
,
341 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
343 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
344 _("Failed to join the conference"),
349 static void sipe_conf_lync_url_cb(struct sipe_core_private
*sipe_private
,
351 SIPE_UNUSED_PARAMETER GSList
*headers
,
353 gpointer callback_data
)
355 gchar
*uri
= callback_data
;
357 if (status
!= (guint
) SIPE_HTTP_STATUS_ABORTED
) {
358 gchar
*focus_uri
= NULL
;
362 * Extract focus URI from HTML, e.g.
364 * <a ... href="conf:sip:...ABCDEF%3Frequired..." ... >
366 const gchar
*start
= g_strstr_len(body
,
373 end
= strchr(start
, '"');
376 gchar
*html
= g_strndup(start
,
379 /* decode HTML entities */
380 gchar
*html_unescaped
= sipe_backend_markup_strip_html(html
);
383 if (!is_empty(html_unescaped
)) {
384 gchar
*uri_unescaped
= sipe_utils_uri_unescape(html_unescaped
);
385 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: found focus URI '%s'",
387 focus_uri
= parse_ocs_focus_uri(uri_unescaped
);
388 g_free(uri_unescaped
);
390 g_free(html_unescaped
);
395 /* If we can't find a focus URI then fall back to URL parser */
397 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: no focus URI found. Falling back to parsing Lync URL '%s'",
399 focus_uri
= parse_lync_join_url(uri
);
403 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
406 sipe_conf_error(sipe_private
, uri
);
413 static gboolean
sipe_conf_check_for_lync_url(struct sipe_core_private
*sipe_private
,
416 if (!(g_str_has_prefix(uri
, "https://") ||
417 g_str_has_prefix(uri
, "http://")))
420 /* URL points to a HTML page with the conference focus URI */
421 return(sipe_http_request_get(sipe_private
,
424 sipe_conf_lync_url_cb
,
429 void sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
432 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
433 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
435 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
436 uri
? uri
: "<UNDEFINED>",
437 uri_ue
? uri_ue
: "<UNDEFINED>");
439 /* takes ownership of "uri_ue" if successful */
440 if (!sipe_conf_check_for_lync_url(sipe_private
, uri_ue
)) {
441 gchar
*focus_uri
= parse_ocs_focus_uri(uri_ue
);
444 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
447 sipe_conf_error(sipe_private
, uri
);
454 /** Create new session with Focus URI */
456 sipe_conf_create(struct sipe_core_private
*sipe_private
,
457 struct sipe_chat_session
*chat_session
,
458 const gchar
*focus_uri
)
460 /* addUser request to the focus.
462 * focus_URI, from, endpoint_GUID
464 static const gchar CCCP_ADD_USER
[] =
466 "<conferenceKeys confEntity=\"%s\"/>"
467 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
469 "<ci:entry>attendee</ci:entry>"
471 "<ci:endpoint entity=\"{%s}\" "
472 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
477 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
482 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
483 session
->focus_dialog
->callid
= gencallid();
484 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
485 session
->focus_dialog
->endpoint_GUID
= rand_guid();
486 session
->focus_dialog
->ourtag
= gentag();
488 self
= sip_uri_self(sipe_private
);
489 session
->focus_dialog
->outgoing_invite
=
490 cccp_request(sipe_private
, "INVITE",
491 session
->focus_dialog
->with
, session
->focus_dialog
,
492 process_invite_conf_focus_response
,
494 session
->focus_dialog
->with
, self
,
495 session
->focus_dialog
->endpoint_GUID
);
497 /* Rejoin existing session? */
499 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
502 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
503 chat_session
->backend
,
505 chat_session
->title
);
512 /** Modify User Role */
514 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
515 struct sip_session
*session
,
518 /* modifyUserRoles request to the focus. Makes user a leader.
523 static const gchar CCCP_MODIFY_USER_ROLES
[] =
525 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
526 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
527 "<entry>presenter</entry>"
529 "</modifyUserRoles>";
531 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
532 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
536 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
537 session
->focus_dialog
, NULL
,
538 CCCP_MODIFY_USER_ROLES
,
539 session
->focus_dialog
->with
, who
);
543 * Check conference lock status
545 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
546 struct sipe_chat_session
*chat_session
)
548 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
549 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
552 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
553 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
556 gchar
*self
= sip_uri_self(sipe_private
);
558 /* Only operators are allowed to change the lock status */
559 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
560 status
= session
->locked
?
561 SIPE_CHAT_LOCK_STATUS_LOCKED
:
562 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
573 * Modify Conference Lock
574 * Sends request to Focus.
575 * INFO method is a carrier of application/cccp+xml
578 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
579 struct sipe_chat_session
*chat_session
,
580 const gboolean locked
)
582 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
585 * locked (%s) "true" or "false" values applicable
587 static const gchar CCCP_MODIFY_CONFERENCE_LOCK
[] =
588 "<modifyConferenceLock>"
589 "<conferenceKeys confEntity=\"%s\"/>"
590 "<locked>%s</locked>"
591 "</modifyConferenceLock>";
593 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
595 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
598 if (!session
) return;
599 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
600 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
604 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
605 session
->focus_dialog
, NULL
,
606 CCCP_MODIFY_CONFERENCE_LOCK
,
607 session
->focus_dialog
->with
,
608 locked
? "true" : "false");
611 /** Modify Delete User */
613 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
614 struct sip_session
*session
,
617 /* deleteUser request to the focus. Removes a user from the conference.
622 static const gchar CCCP_DELETE_USER
[] =
624 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
627 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
628 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
632 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
633 session
->focus_dialog
, NULL
,
635 session
->focus_dialog
->with
, who
);
638 /** Invite counterparty to join conference callback */
640 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
642 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
644 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
646 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
647 dialog
->cseq
= sipmsg_parse_cseq(msg
);
648 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
649 sipe_dialog_parse(dialog
, msg
, TRUE
);
651 if (msg
->response
>= 200) {
652 /* send ACK to counterparty */
654 sip_transport_ack(sipe_private
, dialog
);
655 dialog
->outgoing_invite
= NULL
;
656 dialog
->is_established
= TRUE
;
659 if (msg
->response
>= 400) {
660 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
661 /* @TODO notify user of failure to invite counterparty */
662 sipe_dialog_free(dialog
);
666 if (msg
->response
>= 200) {
667 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
668 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
670 /* close IM session to counterparty */
672 sip_transport_bye(sipe_private
, im_dialog
);
673 sipe_dialog_remove(session
, dialog
->with
);
677 sipe_dialog_free(dialog
);
682 * Invites counterparty to join conference.
685 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
686 struct sip_session
*session
,
692 struct sip_dialog
*dialog
= NULL
;
694 /* It will be short lived special dialog.
695 * Will not be stored in session.
697 dialog
= g_new0(struct sip_dialog
, 1);
698 dialog
->callid
= gencallid();
699 dialog
->with
= g_strdup(who
);
700 dialog
->ourtag
= gentag();
702 contact
= get_contact(sipe_private
);
703 hdr
= g_strdup_printf(
704 "Supported: ms-sender\r\n"
706 "Content-Type: application/ms-conf-invite+xml\r\n",
710 body
= g_strdup_printf(
711 SIPE_SEND_CONF_INVITE
,
712 session
->chat_session
->id
,
713 session
->subject
? session
->subject
: ""
716 sip_transport_invite(sipe_private
,
720 process_invite_conf_response
);
722 sipe_dialog_free(dialog
);
727 /** Create conference callback */
729 process_conf_add_response(struct sipe_core_private
*sipe_private
,
731 struct transaction
*trans
)
733 if (msg
->response
>= 400) {
734 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
735 /* @TODO notify user of failure to create conference */
738 if (msg
->response
== 200) {
739 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
740 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
742 gchar
*who
= trans
->payload
->data
;
743 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
744 struct sip_session
*session
= sipe_conf_create(sipe_private
,
746 sipe_xml_attribute(xn_conference_info
,
749 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
750 session
->chat_session
->id
);
752 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
754 (GCompareFunc
)strcmp
,
757 sipe_xml_free(xn_response
);
764 * Creates conference.
767 sipe_conf_add(struct sipe_core_private
*sipe_private
,
770 gchar
*conference_id
;
771 struct transaction
*trans
;
772 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
774 struct transaction_payload
*payload
;
776 /* addConference request to the focus factory.
778 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
779 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
780 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
782 static const gchar CCCP_ADD_CONFERENCE
[] =
784 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
786 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
787 "<ci:conference-description>"
789 "<msci:conference-id>%s</msci:conference-id>"
790 "<msci:expiry-time>%s</msci:expiry-time>"
791 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
792 "</ci:conference-description>"
793 "<msci:conference-view>%s</msci:conference-view>"
794 "</ci:conference-info>"
797 static const gchar
*DESIRED_MCU_TYPES
[] = {
805 GString
*conference_view
= g_string_new("");
808 for (type
= DESIRED_MCU_TYPES
; *type
; ++type
) {
809 if (sipe_conf_supports_mcu_type(sipe_private
, *type
)) {
810 g_string_append(conference_view
, "<msci:entity-view entity=\"");
811 g_string_append(conference_view
, *type
);
812 g_string_append(conference_view
, "\"/>");
816 expiry_time
= sipe_utils_time_to_str(expiry
);
817 conference_id
= genconfid();
818 trans
= cccp_request(sipe_private
, "SERVICE", sipe_private
->focus_factory_uri
,
819 NULL
, process_conf_add_response
,
821 conference_id
, expiry_time
, conference_view
->str
);
822 g_free(conference_id
);
824 g_string_free(conference_view
, TRUE
);
826 payload
= g_new0(struct transaction_payload
, 1);
827 payload
->destroy
= g_free
;
828 payload
->data
= g_strdup(who
);
829 trans
->payload
= payload
;
833 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
838 struct sip_session
*session
;
839 gchar
*newTag
= gentag();
840 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
843 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
845 sipmsg_remove_header_now(msg
, "To");
846 sipmsg_add_header_now(msg
, "To", newHeader
);
849 /* acknowledge invite */
850 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
852 /* add self to conf */
853 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
854 session
->is_call
= audio
;
857 struct conf_accept_ctx
{
860 struct sipe_user_ask_ctx
*ask_ctx
;
864 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
866 g_return_if_fail(ctx
!= NULL
);
868 sipmsg_free(ctx
->msg
);
869 g_free(ctx
->focus_uri
);
874 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
876 sipe_private
->sessions_to_accept
=
877 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
879 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
880 conf_accept_ctx_free(ctx
);
884 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
886 sipe_private
->sessions_to_accept
=
887 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
889 sip_transport_response(sipe_private
,
891 603, "Decline", NULL
);
893 conf_accept_ctx_free(ctx
);
897 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
900 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
901 GSList
*it
= sipe_private
->sessions_to_accept
;
903 struct conf_accept_ctx
*ctx
= it
->data
;
904 const gchar
*callid2
= NULL
;
907 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
909 if (sipe_strequal(callid1
, callid2
)) {
913 sip_transport_response(sipe_private
, ctx
->msg
,
914 487, "Request Terminated", NULL
);
917 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
919 sipe_user_close_ask(ctx
->ask_ctx
);
920 conf_accept_ctx_free(ctx
);
925 sipe_private
->sessions_to_accept
=
926 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
936 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
937 const gchar
*focus_uri
,
939 SipeUserAskCb accept_cb
,
940 SipeUserAskCb decline_cb
)
945 const gchar
*novv_note
;
946 struct conf_accept_ctx
*ctx
;
951 novv_note
= _("\n\nAs this client was not compiled with voice call "
952 "support, if you accept, you will be able to contact "
953 "the other participants only via IM session.");
956 parts
= g_strsplit(focus_uri
, ";", 2);
957 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
959 ask_msg
= g_strdup_printf(_("%s wants to invite you "
960 "to the conference call%s"),
961 alias
? alias
: parts
[0], novv_note
);
966 ctx
= g_new0(struct conf_accept_ctx
, 1);
967 sipe_private
->sessions_to_accept
=
968 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
970 ctx
->focus_uri
= g_strdup(focus_uri
);
971 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
972 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
973 _("Accept"), accept_cb
,
974 _("Decline"), decline_cb
,
981 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
984 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
985 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
986 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
987 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
988 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
990 sipe_xml_free(xn_conferencing
);
992 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
995 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
996 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
997 (SipeUserAskCb
) conf_accept_cb
,
998 (SipeUserAskCb
) conf_decline_cb
);
1001 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
1010 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
1012 struct sip_session
*session
;
1013 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
1015 sipe_private
->sessions_to_accept
=
1016 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
1019 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
1020 session
->chat_session
);
1023 conf_accept_ctx_free(ctx
);
1027 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
1029 sipe_private
->sessions_to_accept
=
1030 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
1032 conf_accept_ctx_free(ctx
);
1038 sipe_process_conference(struct sipe_core_private
*sipe_private
,
1041 sipe_xml
*xn_conference_info
;
1042 const sipe_xml
*node
;
1043 const sipe_xml
*xn_subject
;
1044 const gchar
*focus_uri
;
1045 struct sip_session
*session
;
1046 gboolean just_joined
= FALSE
;
1048 gboolean audio_was_added
= FALSE
;
1051 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1053 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1055 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1056 if (!xn_conference_info
) return;
1058 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1059 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1062 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1066 if (!session
->chat_session
->backend
) {
1067 gchar
*self
= sip_uri_self(sipe_private
);
1070 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1071 session
->chat_session
,
1072 session
->chat_session
->title
,
1075 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1076 * this is to obtain full list of conference participants.
1082 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1083 g_free(session
->subject
);
1084 session
->subject
= sipe_xml_data(xn_subject
);
1085 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1086 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1090 if (!session
->im_mcu_uri
) {
1091 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1093 node
= sipe_xml_twin(node
))
1095 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1097 if (sipe_strequal("chat", purpose
)) {
1099 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1100 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1108 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1109 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1110 const gchar
*state
= sipe_xml_attribute(node
, "state");
1111 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1112 gboolean is_operator
= sipe_strequal(role
, "presenter");
1113 gboolean is_in_im_mcu
= FALSE
;
1114 gchar
*self
= sip_uri_self(sipe_private
);
1116 if (sipe_strequal("deleted", state
)) {
1117 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1118 sipe_backend_chat_remove(session
->chat_session
->backend
,
1123 const sipe_xml
*endpoint
;
1124 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1125 const gchar
*session_type
;
1126 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1127 gboolean connected
= sipe_strequal("connected", status
);
1133 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1135 if (sipe_strequal("chat", session_type
)) {
1136 is_in_im_mcu
= TRUE
;
1137 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1138 sipe_backend_chat_add(session
->chat_session
->backend
,
1140 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1143 sipe_backend_chat_operator(session
->chat_session
->backend
,
1146 } else if (sipe_strequal("audio-video", session_type
)) {
1148 if (!session
->is_call
)
1149 audio_was_added
= TRUE
;
1153 if (!is_in_im_mcu
) {
1154 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1155 sipe_backend_chat_remove(session
->chat_session
->backend
,
1165 if (audio_was_added
) {
1166 session
->is_call
= TRUE
;
1167 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1168 (SipeUserAskCb
) call_accept_cb
,
1169 (SipeUserAskCb
) call_decline_cb
);
1173 /* entity-view, locked */
1174 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1176 node
= sipe_xml_twin(node
)) {
1178 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1180 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1181 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1183 gchar
*locked
= sipe_xml_data(xn_locked
);
1184 gboolean prev_locked
= session
->locked
;
1185 session
->locked
= sipe_strequal(locked
, "true");
1186 if (prev_locked
&& !session
->locked
) {
1187 sipe_user_present_info(sipe_private
, session
,
1188 _("This conference is no longer locked. Additional participants can now join."));
1190 if (!prev_locked
&& session
->locked
) {
1191 sipe_user_present_info(sipe_private
, session
,
1192 _("This conference is locked. Nobody else can join the conference while it is locked."));
1195 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1196 session
->locked
? "TRUE" : "FALSE");
1202 sipe_xml_free(xn_conference_info
);
1204 if (session
->im_mcu_uri
) {
1205 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1207 dialog
= sipe_dialog_add(session
);
1209 dialog
->callid
= g_strdup(session
->callid
);
1210 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1212 /* send INVITE to IM MCU */
1213 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1217 sipe_process_pending_invite_queue(sipe_private
, session
);
1221 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1222 struct sip_session
*session
)
1224 sipe_user_present_info(sipe_private
, session
,
1225 _("You have been disconnected from this conference."));
1226 sipe_backend_chat_close(session
->chat_session
->backend
);
1230 conf_session_close(struct sipe_core_private
*sipe_private
,
1231 struct sip_session
*session
)
1234 /* unsubscribe from focus */
1235 sipe_subscribe_conference(sipe_private
,
1236 session
->chat_session
->id
, TRUE
);
1238 if (session
->focus_dialog
) {
1239 /* send BYE to focus */
1240 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1246 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1249 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1250 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1251 static struct sip_session
*session
;
1253 const sipe_xml
*node
;
1257 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1259 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1264 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1265 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1267 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1270 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1271 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1272 gchar
*uri
= parse_from(tmp
);
1273 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1274 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1275 /* default to error if missing or conversion failed */
1276 if ((error
== 0) || (error
>= 300))
1277 sipe_user_present_message_undelivered(sipe_private
,
1288 sipe_xml_free(xn_imdn
);
1290 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1291 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1292 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1297 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1299 const gchar
*buddy_name
)
1301 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1302 struct sipe_chat_session
*chat_session
= parameter
;
1303 struct sip_session
*session
;
1305 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1306 chat_session
->title
);
1308 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1309 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1312 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1314 const gchar
*buddy_name
)
1316 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1317 struct sipe_chat_session
*chat_session
= parameter
;
1318 struct sip_session
*session
;
1320 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1321 chat_session
->title
);
1323 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1324 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);