6 * Copyright (C) 2010-2014 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"
56 #include "sipe-session.h"
57 #include "sipe-subscriptions.h"
58 #include "sipe-user.h"
59 #include "sipe-utils.h"
63 * Invite counterparty to join conference.
64 * @param focus_uri (%s)
65 * @param subject (%s) of conference
67 #define SIPE_SEND_CONF_INVITE \
68 "<Conferencing version=\"2.0\">"\
69 "<focus-uri>%s</focus-uri>"\
70 "<subject>%s</subject>"\
71 "<im available=\"true\">"\
76 static struct transaction
*
77 cccp_request(struct sipe_core_private
*sipe_private
, const gchar
*method
,
78 const gchar
*with
, struct sip_dialog
*dialog
,
79 TransCallback callback
, const gchar
*body
, ...)
85 gchar
*self
= sip_uri_self(sipe_private
);
89 struct transaction
*trans
;
91 headers
= g_strdup_printf(
92 "Supported: ms-sender\r\n"
94 "Content-Type: application/cccp+xml\r\n",
95 sipe_private
->contact
);
97 /* TODO: put request_id to queue to further compare with incoming one */
98 request
= g_strdup_printf(
99 "<?xml version=\"1.0\"?>"
100 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "
101 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "
110 sipe_private
->cccp_request_id
++,
114 va_start(args
, body
);
115 request_body
= g_strdup_vprintf(request
, args
);
120 trans
= sip_transport_request(sipe_private
,
130 g_free(request_body
);
136 process_conf_get_capabilities(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
138 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
140 if (msg
->response
>= 400) {
141 SIPE_DEBUG_INFO_NOFORMAT("process_conf_get_capabilities: "
142 "getConferencingCapabilities failed.");
145 if (msg
->response
== 200) {
146 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
148 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code"))) {
149 const sipe_xml
*node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/mcu-types/mcuType");
150 for (;node
; node
= sipe_xml_twin(node
)) {
151 sipe_private
->conf_mcu_types
=
152 g_slist_append(sipe_private
->conf_mcu_types
,
153 sipe_xml_data(node
));
157 sipe_xml_free(xn_response
);
164 sipe_conf_get_capabilities(struct sipe_core_private
*sipe_private
)
166 cccp_request(sipe_private
, "SERVICE",
167 sipe_private
->focus_factory_uri
,
169 process_conf_get_capabilities
,
170 "<getConferencingCapabilities />");
174 sipe_conf_supports_mcu_type(struct sipe_core_private
*sipe_private
,
177 return g_slist_find_custom(sipe_private
->conf_mcu_types
, type
,
178 sipe_strcompare
) != NULL
;
182 * Generates random GUID.
183 * This method is borrowed from pidgin's msnutils.c
188 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
189 rand() % 0xAAFF + 0x1111,
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);
199 /** Invite us to the focus callback */
201 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
203 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
205 struct sip_session
*session
= NULL
;
206 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
208 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
211 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
216 if (!session
->focus_dialog
) {
217 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
222 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
224 if (msg
->response
>= 200) {
225 /* send ACK to focus */
226 session
->focus_dialog
->cseq
= 0;
227 sip_transport_ack(sipe_private
, session
->focus_dialog
);
228 session
->focus_dialog
->outgoing_invite
= NULL
;
229 session
->focus_dialog
->is_established
= TRUE
;
232 if (msg
->response
>= 400) {
233 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
235 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
236 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
237 _("Failed to join the conference"),
238 reason
? reason
: _("no reason given"));
241 sipe_session_remove(sipe_private
, session
);
244 } else if (msg
->response
== 200) {
245 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
246 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
247 if (sipe_strequal(code
, "success")) {
248 /* subscribe to focus */
249 sipe_subscribe_conference(sipe_private
,
250 session
->chat_session
->id
,
253 if (session
->is_call
)
254 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
255 session
->chat_session
);
258 sipe_xml_free(xn_response
);
266 parse_ocs_focus_uri(const gchar
*uri
)
268 const gchar
*confkey
;
274 // URI can have this prefix if it was typed in by the user
275 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
279 uri_len
= strlen(uri
);
281 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
282 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
286 confkey
= g_strstr_len(uri
, -1, "?");
288 /* TODO: Investigate how conf-key field should be used,
289 * ignoring for now */
290 uri_len
= confkey
- uri
;
293 return g_strndup(uri
, uri_len
);
297 parse_lync_join_url(const gchar
*uri
)
299 gchar
*focus_uri
= NULL
;
306 if (g_str_has_prefix(uri
, "https://")) {
308 } else if (g_str_has_prefix(uri
, "http://")) {
312 parts
= g_strsplit(uri
, "/", 0);
314 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
315 if (parts_count
>= 3) {
316 const gchar
*conference_id
= parts
[parts_count
- 1];
317 const gchar
*organizer_alias
= parts
[parts_count
- 2];
319 gchar
**domain_parts
= g_strsplit(parts
[0], ".", 2);
321 /* we need to drop the first sub-domain from the URL */
322 if (domain_parts
[0] && domain_parts
[1]) {
323 focus_uri
= g_strdup_printf("sip:%s@%s;gruu;opaque=app:conf:focus:id:%s",
329 g_strfreev(domain_parts
);
338 sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
341 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
343 struct sip_session
*session
= NULL
;
345 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
346 uri
? uri
: "<UNDEFINED>",
347 uri_ue
? uri_ue
: "<UNDEFINED>");
349 focus_uri
= parse_ocs_focus_uri(uri_ue
);
351 focus_uri
= parse_lync_join_url(uri_ue
);
355 session
= sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri
);
358 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
360 sipe_backend_notify_error(sipe_public
,
361 _("Failed to join the conference"),
371 /** Create new session with Focus URI */
373 sipe_conf_create(struct sipe_core_private
*sipe_private
,
374 struct sipe_chat_session
*chat_session
,
375 const gchar
*focus_uri
)
377 /* addUser request to the focus.
379 * focus_URI, from, endpoint_GUID
381 static const gchar CCCP_ADD_USER
[] =
383 "<conferenceKeys confEntity=\"%s\"/>"
384 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
386 "<ci:entry>attendee</ci:entry>"
388 "<ci:endpoint entity=\"{%s}\" "
389 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
394 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
399 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
400 session
->focus_dialog
->callid
= gencallid();
401 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
402 session
->focus_dialog
->endpoint_GUID
= rand_guid();
403 session
->focus_dialog
->ourtag
= gentag();
405 self
= sip_uri_self(sipe_private
);
406 session
->focus_dialog
->outgoing_invite
=
407 cccp_request(sipe_private
, "INVITE",
408 session
->focus_dialog
->with
, session
->focus_dialog
,
409 process_invite_conf_focus_response
,
411 session
->focus_dialog
->with
, self
,
412 session
->focus_dialog
->endpoint_GUID
);
414 /* Rejoin existing session? */
416 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
419 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
420 chat_session
->backend
,
422 chat_session
->title
);
429 /** Modify User Role */
431 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
432 struct sip_session
*session
,
435 /* modifyUserRoles request to the focus. Makes user a leader.
440 static const gchar CCCP_MODIFY_USER_ROLES
[] =
442 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
443 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
444 "<entry>presenter</entry>"
446 "</modifyUserRoles>";
448 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
449 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
453 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
454 session
->focus_dialog
, NULL
,
455 CCCP_MODIFY_USER_ROLES
,
456 session
->focus_dialog
->with
, who
);
460 * Check conference lock status
462 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
463 struct sipe_chat_session
*chat_session
)
465 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
466 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
469 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
470 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
473 gchar
*self
= sip_uri_self(sipe_private
);
475 /* Only operators are allowed to change the lock status */
476 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
477 status
= session
->locked
?
478 SIPE_CHAT_LOCK_STATUS_LOCKED
:
479 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
490 * Modify Conference Lock
491 * Sends request to Focus.
492 * INFO method is a carrier of application/cccp+xml
495 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
496 struct sipe_chat_session
*chat_session
,
497 const gboolean locked
)
499 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
502 * locked (%s) "true" or "false" values applicable
504 static const gchar CCCP_MODIFY_CONFERENCE_LOCK
[] =
505 "<modifyConferenceLock>"
506 "<conferenceKeys confEntity=\"%s\"/>"
507 "<locked>%s</locked>"
508 "</modifyConferenceLock>";
510 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
512 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
515 if (!session
) return;
516 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
517 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
521 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
522 session
->focus_dialog
, NULL
,
523 CCCP_MODIFY_CONFERENCE_LOCK
,
524 session
->focus_dialog
->with
,
525 locked
? "true" : "false");
528 /** Modify Delete User */
530 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
531 struct sip_session
*session
,
534 /* deleteUser request to the focus. Removes a user from the conference.
539 static const gchar CCCP_DELETE_USER
[] =
541 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
544 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
545 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
549 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
550 session
->focus_dialog
, NULL
,
552 session
->focus_dialog
->with
, who
);
555 /** Invite counterparty to join conference callback */
557 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
559 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
561 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
563 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
564 dialog
->cseq
= sipmsg_parse_cseq(msg
);
565 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
566 sipe_dialog_parse(dialog
, msg
, TRUE
);
568 if (msg
->response
>= 200) {
569 /* send ACK to counterparty */
571 sip_transport_ack(sipe_private
, dialog
);
572 dialog
->outgoing_invite
= NULL
;
573 dialog
->is_established
= TRUE
;
576 if (msg
->response
>= 400) {
577 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
578 /* @TODO notify user of failure to invite counterparty */
579 sipe_dialog_free(dialog
);
583 if (msg
->response
>= 200) {
584 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
585 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
587 /* close IM session to counterparty */
589 sip_transport_bye(sipe_private
, im_dialog
);
590 sipe_dialog_remove(session
, dialog
->with
);
594 sipe_dialog_free(dialog
);
599 * Invites counterparty to join conference.
602 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
603 struct sip_session
*session
,
609 struct sip_dialog
*dialog
= NULL
;
611 /* It will be short lived special dialog.
612 * Will not be stored in session.
614 dialog
= g_new0(struct sip_dialog
, 1);
615 dialog
->callid
= gencallid();
616 dialog
->with
= g_strdup(who
);
617 dialog
->ourtag
= gentag();
619 contact
= get_contact(sipe_private
);
620 hdr
= g_strdup_printf(
621 "Supported: ms-sender\r\n"
623 "Content-Type: application/ms-conf-invite+xml\r\n",
627 body
= g_strdup_printf(
628 SIPE_SEND_CONF_INVITE
,
629 session
->chat_session
->id
,
630 session
->subject
? session
->subject
: ""
633 sip_transport_invite(sipe_private
,
637 process_invite_conf_response
);
639 sipe_dialog_free(dialog
);
644 /** Create conference callback */
646 process_conf_add_response(struct sipe_core_private
*sipe_private
,
648 struct transaction
*trans
)
650 if (msg
->response
>= 400) {
651 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
652 /* @TODO notify user of failure to create conference */
655 if (msg
->response
== 200) {
656 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
657 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
659 gchar
*who
= trans
->payload
->data
;
660 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
661 struct sip_session
*session
= sipe_conf_create(sipe_private
,
663 sipe_xml_attribute(xn_conference_info
,
666 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
667 session
->chat_session
->id
);
669 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
671 (GCompareFunc
)strcmp
,
674 sipe_xml_free(xn_response
);
681 * Creates conference.
684 sipe_conf_add(struct sipe_core_private
*sipe_private
,
687 gchar
*conference_id
;
688 struct transaction
*trans
;
689 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
691 struct transaction_payload
*payload
;
693 /* addConference request to the focus factory.
695 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
696 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
697 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
699 static const gchar CCCP_ADD_CONFERENCE
[] =
701 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
703 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
704 "<ci:conference-description>"
706 "<msci:conference-id>%s</msci:conference-id>"
707 "<msci:expiry-time>%s</msci:expiry-time>"
708 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
709 "</ci:conference-description>"
710 "<msci:conference-view>%s</msci:conference-view>"
711 "</ci:conference-info>"
714 static const gchar
*DESIRED_MCU_TYPES
[] = {
722 GString
*conference_view
= g_string_new("");
725 for (type
= DESIRED_MCU_TYPES
; *type
; ++type
) {
726 if (sipe_conf_supports_mcu_type(sipe_private
, *type
)) {
727 g_string_append(conference_view
, "<msci:entity-view entity=\"");
728 g_string_append(conference_view
, *type
);
729 g_string_append(conference_view
, "\"/>");
733 expiry_time
= sipe_utils_time_to_str(expiry
);
734 conference_id
= genconfid();
735 trans
= cccp_request(sipe_private
, "SERVICE", sipe_private
->focus_factory_uri
,
736 NULL
, process_conf_add_response
,
738 conference_id
, expiry_time
, conference_view
->str
);
739 g_free(conference_id
);
741 g_string_free(conference_view
, TRUE
);
743 payload
= g_new0(struct transaction_payload
, 1);
744 payload
->destroy
= g_free
;
745 payload
->data
= g_strdup(who
);
746 trans
->payload
= payload
;
750 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
755 struct sip_session
*session
;
756 gchar
*newTag
= gentag();
757 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
760 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
762 sipmsg_remove_header_now(msg
, "To");
763 sipmsg_add_header_now(msg
, "To", newHeader
);
766 /* acknowledge invite */
767 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
769 /* add self to conf */
770 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
771 session
->is_call
= audio
;
774 struct conf_accept_ctx
{
777 struct sipe_user_ask_ctx
*ask_ctx
;
781 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
783 g_return_if_fail(ctx
!= NULL
);
785 sipmsg_free(ctx
->msg
);
786 g_free(ctx
->focus_uri
);
791 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
793 sipe_private
->sessions_to_accept
=
794 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
796 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
797 conf_accept_ctx_free(ctx
);
801 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
803 sipe_private
->sessions_to_accept
=
804 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
806 sip_transport_response(sipe_private
,
808 603, "Decline", NULL
);
810 conf_accept_ctx_free(ctx
);
814 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
817 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
818 GSList
*it
= sipe_private
->sessions_to_accept
;
820 struct conf_accept_ctx
*ctx
= it
->data
;
821 const gchar
*callid2
= NULL
;
824 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
826 if (sipe_strequal(callid1
, callid2
)) {
830 sip_transport_response(sipe_private
, ctx
->msg
,
831 487, "Request Terminated", NULL
);
834 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
836 sipe_user_close_ask(ctx
->ask_ctx
);
837 conf_accept_ctx_free(ctx
);
842 sipe_private
->sessions_to_accept
=
843 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
853 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
854 const gchar
*focus_uri
,
856 SipeUserAskCb accept_cb
,
857 SipeUserAskCb decline_cb
)
862 const gchar
*novv_note
;
863 struct conf_accept_ctx
*ctx
;
868 novv_note
= _("\n\nAs this client was not compiled with voice call "
869 "support, if you accept, you will be able to contact "
870 "the other participants only via IM session.");
873 parts
= g_strsplit(focus_uri
, ";", 2);
874 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
876 ask_msg
= g_strdup_printf(_("%s wants to invite you "
877 "to the conference call%s"),
878 alias
? alias
: parts
[0], novv_note
);
883 ctx
= g_new0(struct conf_accept_ctx
, 1);
884 sipe_private
->sessions_to_accept
=
885 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
887 ctx
->focus_uri
= g_strdup(focus_uri
);
888 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
889 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
890 _("Accept"), accept_cb
,
891 _("Decline"), decline_cb
,
898 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
901 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
902 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
903 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
904 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
905 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
907 sipe_xml_free(xn_conferencing
);
909 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
912 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
913 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
914 (SipeUserAskCb
) conf_accept_cb
,
915 (SipeUserAskCb
) conf_decline_cb
);
918 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
927 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
929 struct sip_session
*session
;
930 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
932 sipe_private
->sessions_to_accept
=
933 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
936 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
937 session
->chat_session
);
940 conf_accept_ctx_free(ctx
);
944 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
946 sipe_private
->sessions_to_accept
=
947 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
949 conf_accept_ctx_free(ctx
);
955 sipe_process_conference(struct sipe_core_private
*sipe_private
,
958 sipe_xml
*xn_conference_info
;
959 const sipe_xml
*node
;
960 const sipe_xml
*xn_subject
;
961 const gchar
*focus_uri
;
962 struct sip_session
*session
;
963 gboolean just_joined
= FALSE
;
965 gboolean audio_was_added
= FALSE
;
968 if (msg
->response
!= 0 && msg
->response
!= 200) return;
970 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
972 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
973 if (!xn_conference_info
) return;
975 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
976 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
979 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
983 if (!session
->chat_session
->backend
) {
984 gchar
*self
= sip_uri_self(sipe_private
);
987 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
988 session
->chat_session
,
989 session
->chat_session
->title
,
992 /* @TODO ask for full state (re-subscribe) if it was a partial one -
993 * this is to obtain full list of conference participants.
999 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1000 g_free(session
->subject
);
1001 session
->subject
= sipe_xml_data(xn_subject
);
1002 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1003 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1007 if (!session
->im_mcu_uri
) {
1008 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1010 node
= sipe_xml_twin(node
))
1012 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1014 if (sipe_strequal("chat", purpose
)) {
1016 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1017 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1025 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1026 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1027 const gchar
*state
= sipe_xml_attribute(node
, "state");
1028 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1029 gboolean is_operator
= sipe_strequal(role
, "presenter");
1030 gboolean is_in_im_mcu
= FALSE
;
1031 gchar
*self
= sip_uri_self(sipe_private
);
1033 if (sipe_strequal("deleted", state
)) {
1034 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1035 sipe_backend_chat_remove(session
->chat_session
->backend
,
1040 const sipe_xml
*endpoint
;
1041 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1042 const gchar
*session_type
;
1043 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1044 gboolean connected
= sipe_strequal("connected", status
);
1050 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1052 if (sipe_strequal("chat", session_type
)) {
1053 is_in_im_mcu
= TRUE
;
1054 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1055 sipe_backend_chat_add(session
->chat_session
->backend
,
1057 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1060 sipe_backend_chat_operator(session
->chat_session
->backend
,
1063 } else if (sipe_strequal("audio-video", session_type
)) {
1065 if (!session
->is_call
)
1066 audio_was_added
= TRUE
;
1070 if (!is_in_im_mcu
) {
1071 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1072 sipe_backend_chat_remove(session
->chat_session
->backend
,
1082 if (audio_was_added
) {
1083 session
->is_call
= TRUE
;
1084 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1085 (SipeUserAskCb
) call_accept_cb
,
1086 (SipeUserAskCb
) call_decline_cb
);
1090 /* entity-view, locked */
1091 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1093 node
= sipe_xml_twin(node
)) {
1095 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1097 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1098 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1100 gchar
*locked
= sipe_xml_data(xn_locked
);
1101 gboolean prev_locked
= session
->locked
;
1102 session
->locked
= sipe_strequal(locked
, "true");
1103 if (prev_locked
&& !session
->locked
) {
1104 sipe_user_present_info(sipe_private
, session
,
1105 _("This conference is no longer locked. Additional participants can now join."));
1107 if (!prev_locked
&& session
->locked
) {
1108 sipe_user_present_info(sipe_private
, session
,
1109 _("This conference is locked. Nobody else can join the conference while it is locked."));
1112 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1113 session
->locked
? "TRUE" : "FALSE");
1119 sipe_xml_free(xn_conference_info
);
1121 if (session
->im_mcu_uri
) {
1122 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1124 dialog
= sipe_dialog_add(session
);
1126 dialog
->callid
= g_strdup(session
->callid
);
1127 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1129 /* send INVITE to IM MCU */
1130 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1134 sipe_process_pending_invite_queue(sipe_private
, session
);
1138 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1139 struct sip_session
*session
)
1141 sipe_user_present_info(sipe_private
, session
,
1142 _("You have been disconnected from this conference."));
1143 sipe_backend_chat_close(session
->chat_session
->backend
);
1147 conf_session_close(struct sipe_core_private
*sipe_private
,
1148 struct sip_session
*session
)
1151 /* unsubscribe from focus */
1152 sipe_subscribe_conference(sipe_private
,
1153 session
->chat_session
->id
, TRUE
);
1155 if (session
->focus_dialog
) {
1156 /* send BYE to focus */
1157 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1163 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1166 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1167 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1168 static struct sip_session
*session
;
1170 const sipe_xml
*node
;
1174 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1176 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1181 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1182 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1184 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1187 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1188 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1189 gchar
*uri
= parse_from(tmp
);
1190 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1191 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1192 /* default to error if missing or conversion failed */
1193 if ((error
== 0) || (error
>= 300))
1194 sipe_user_present_message_undelivered(sipe_private
,
1205 sipe_xml_free(xn_imdn
);
1207 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1208 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1209 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1214 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1216 const gchar
*buddy_name
)
1218 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1219 struct sipe_chat_session
*chat_session
= parameter
;
1220 struct sip_session
*session
;
1222 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1223 chat_session
->title
);
1225 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1226 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1229 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1231 const gchar
*buddy_name
)
1233 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1234 struct sipe_chat_session
*chat_session
= parameter
;
1235 struct sip_session
*session
;
1237 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1238 chat_session
->title
);
1240 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1241 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);