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"
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
);
337 void sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
340 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
343 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
344 uri
? uri
: "<UNDEFINED>",
345 uri_ue
? uri_ue
: "<UNDEFINED>");
347 focus_uri
= parse_ocs_focus_uri(uri_ue
);
349 focus_uri
= parse_lync_join_url(uri_ue
);
353 sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri
);
356 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
358 sipe_backend_notify_error(sipe_public
,
359 _("Failed to join the conference"),
367 /** Create new session with Focus URI */
369 sipe_conf_create(struct sipe_core_private
*sipe_private
,
370 struct sipe_chat_session
*chat_session
,
371 const gchar
*focus_uri
)
373 /* addUser request to the focus.
375 * focus_URI, from, endpoint_GUID
377 static const gchar CCCP_ADD_USER
[] =
379 "<conferenceKeys confEntity=\"%s\"/>"
380 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
382 "<ci:entry>attendee</ci:entry>"
384 "<ci:endpoint entity=\"{%s}\" "
385 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
390 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
395 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
396 session
->focus_dialog
->callid
= gencallid();
397 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
398 session
->focus_dialog
->endpoint_GUID
= rand_guid();
399 session
->focus_dialog
->ourtag
= gentag();
401 self
= sip_uri_self(sipe_private
);
402 session
->focus_dialog
->outgoing_invite
=
403 cccp_request(sipe_private
, "INVITE",
404 session
->focus_dialog
->with
, session
->focus_dialog
,
405 process_invite_conf_focus_response
,
407 session
->focus_dialog
->with
, self
,
408 session
->focus_dialog
->endpoint_GUID
);
410 /* Rejoin existing session? */
412 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
415 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
416 chat_session
->backend
,
418 chat_session
->title
);
425 /** Modify User Role */
427 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
428 struct sip_session
*session
,
431 /* modifyUserRoles request to the focus. Makes user a leader.
436 static const gchar CCCP_MODIFY_USER_ROLES
[] =
438 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
439 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
440 "<entry>presenter</entry>"
442 "</modifyUserRoles>";
444 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
445 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
449 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
450 session
->focus_dialog
, NULL
,
451 CCCP_MODIFY_USER_ROLES
,
452 session
->focus_dialog
->with
, who
);
456 * Check conference lock status
458 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
459 struct sipe_chat_session
*chat_session
)
461 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
462 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
465 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
466 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
469 gchar
*self
= sip_uri_self(sipe_private
);
471 /* Only operators are allowed to change the lock status */
472 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
473 status
= session
->locked
?
474 SIPE_CHAT_LOCK_STATUS_LOCKED
:
475 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
486 * Modify Conference Lock
487 * Sends request to Focus.
488 * INFO method is a carrier of application/cccp+xml
491 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
492 struct sipe_chat_session
*chat_session
,
493 const gboolean locked
)
495 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
498 * locked (%s) "true" or "false" values applicable
500 static const gchar CCCP_MODIFY_CONFERENCE_LOCK
[] =
501 "<modifyConferenceLock>"
502 "<conferenceKeys confEntity=\"%s\"/>"
503 "<locked>%s</locked>"
504 "</modifyConferenceLock>";
506 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
508 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
511 if (!session
) return;
512 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
513 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
517 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
518 session
->focus_dialog
, NULL
,
519 CCCP_MODIFY_CONFERENCE_LOCK
,
520 session
->focus_dialog
->with
,
521 locked
? "true" : "false");
524 /** Modify Delete User */
526 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
527 struct sip_session
*session
,
530 /* deleteUser request to the focus. Removes a user from the conference.
535 static const gchar CCCP_DELETE_USER
[] =
537 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
540 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
541 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
545 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
546 session
->focus_dialog
, NULL
,
548 session
->focus_dialog
->with
, who
);
551 /** Invite counterparty to join conference callback */
553 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
555 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
557 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
559 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
560 dialog
->cseq
= sipmsg_parse_cseq(msg
);
561 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
562 sipe_dialog_parse(dialog
, msg
, TRUE
);
564 if (msg
->response
>= 200) {
565 /* send ACK to counterparty */
567 sip_transport_ack(sipe_private
, dialog
);
568 dialog
->outgoing_invite
= NULL
;
569 dialog
->is_established
= TRUE
;
572 if (msg
->response
>= 400) {
573 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
574 /* @TODO notify user of failure to invite counterparty */
575 sipe_dialog_free(dialog
);
579 if (msg
->response
>= 200) {
580 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
581 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
583 /* close IM session to counterparty */
585 sip_transport_bye(sipe_private
, im_dialog
);
586 sipe_dialog_remove(session
, dialog
->with
);
590 sipe_dialog_free(dialog
);
595 * Invites counterparty to join conference.
598 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
599 struct sip_session
*session
,
605 struct sip_dialog
*dialog
= NULL
;
607 /* It will be short lived special dialog.
608 * Will not be stored in session.
610 dialog
= g_new0(struct sip_dialog
, 1);
611 dialog
->callid
= gencallid();
612 dialog
->with
= g_strdup(who
);
613 dialog
->ourtag
= gentag();
615 contact
= get_contact(sipe_private
);
616 hdr
= g_strdup_printf(
617 "Supported: ms-sender\r\n"
619 "Content-Type: application/ms-conf-invite+xml\r\n",
623 body
= g_strdup_printf(
624 SIPE_SEND_CONF_INVITE
,
625 session
->chat_session
->id
,
626 session
->subject
? session
->subject
: ""
629 sip_transport_invite(sipe_private
,
633 process_invite_conf_response
);
635 sipe_dialog_free(dialog
);
640 /** Create conference callback */
642 process_conf_add_response(struct sipe_core_private
*sipe_private
,
644 struct transaction
*trans
)
646 if (msg
->response
>= 400) {
647 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
648 /* @TODO notify user of failure to create conference */
651 if (msg
->response
== 200) {
652 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
653 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
655 gchar
*who
= trans
->payload
->data
;
656 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
657 struct sip_session
*session
= sipe_conf_create(sipe_private
,
659 sipe_xml_attribute(xn_conference_info
,
662 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
663 session
->chat_session
->id
);
665 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
667 (GCompareFunc
)strcmp
,
670 sipe_xml_free(xn_response
);
677 * Creates conference.
680 sipe_conf_add(struct sipe_core_private
*sipe_private
,
683 gchar
*conference_id
;
684 struct transaction
*trans
;
685 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
687 struct transaction_payload
*payload
;
689 /* addConference request to the focus factory.
691 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
692 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
693 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
695 static const gchar CCCP_ADD_CONFERENCE
[] =
697 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
699 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
700 "<ci:conference-description>"
702 "<msci:conference-id>%s</msci:conference-id>"
703 "<msci:expiry-time>%s</msci:expiry-time>"
704 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
705 "</ci:conference-description>"
706 "<msci:conference-view>%s</msci:conference-view>"
707 "</ci:conference-info>"
710 static const gchar
*DESIRED_MCU_TYPES
[] = {
718 GString
*conference_view
= g_string_new("");
721 for (type
= DESIRED_MCU_TYPES
; *type
; ++type
) {
722 if (sipe_conf_supports_mcu_type(sipe_private
, *type
)) {
723 g_string_append(conference_view
, "<msci:entity-view entity=\"");
724 g_string_append(conference_view
, *type
);
725 g_string_append(conference_view
, "\"/>");
729 expiry_time
= sipe_utils_time_to_str(expiry
);
730 conference_id
= genconfid();
731 trans
= cccp_request(sipe_private
, "SERVICE", sipe_private
->focus_factory_uri
,
732 NULL
, process_conf_add_response
,
734 conference_id
, expiry_time
, conference_view
->str
);
735 g_free(conference_id
);
737 g_string_free(conference_view
, TRUE
);
739 payload
= g_new0(struct transaction_payload
, 1);
740 payload
->destroy
= g_free
;
741 payload
->data
= g_strdup(who
);
742 trans
->payload
= payload
;
746 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
751 struct sip_session
*session
;
752 gchar
*newTag
= gentag();
753 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
756 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
758 sipmsg_remove_header_now(msg
, "To");
759 sipmsg_add_header_now(msg
, "To", newHeader
);
762 /* acknowledge invite */
763 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
765 /* add self to conf */
766 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
767 session
->is_call
= audio
;
770 struct conf_accept_ctx
{
773 struct sipe_user_ask_ctx
*ask_ctx
;
777 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
779 g_return_if_fail(ctx
!= NULL
);
781 sipmsg_free(ctx
->msg
);
782 g_free(ctx
->focus_uri
);
787 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
789 sipe_private
->sessions_to_accept
=
790 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
792 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
793 conf_accept_ctx_free(ctx
);
797 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
799 sipe_private
->sessions_to_accept
=
800 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
802 sip_transport_response(sipe_private
,
804 603, "Decline", NULL
);
806 conf_accept_ctx_free(ctx
);
810 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
813 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
814 GSList
*it
= sipe_private
->sessions_to_accept
;
816 struct conf_accept_ctx
*ctx
= it
->data
;
817 const gchar
*callid2
= NULL
;
820 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
822 if (sipe_strequal(callid1
, callid2
)) {
826 sip_transport_response(sipe_private
, ctx
->msg
,
827 487, "Request Terminated", NULL
);
830 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
832 sipe_user_close_ask(ctx
->ask_ctx
);
833 conf_accept_ctx_free(ctx
);
838 sipe_private
->sessions_to_accept
=
839 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
849 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
850 const gchar
*focus_uri
,
852 SipeUserAskCb accept_cb
,
853 SipeUserAskCb decline_cb
)
858 const gchar
*novv_note
;
859 struct conf_accept_ctx
*ctx
;
864 novv_note
= _("\n\nAs this client was not compiled with voice call "
865 "support, if you accept, you will be able to contact "
866 "the other participants only via IM session.");
869 parts
= g_strsplit(focus_uri
, ";", 2);
870 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
872 ask_msg
= g_strdup_printf(_("%s wants to invite you "
873 "to the conference call%s"),
874 alias
? alias
: parts
[0], novv_note
);
879 ctx
= g_new0(struct conf_accept_ctx
, 1);
880 sipe_private
->sessions_to_accept
=
881 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
883 ctx
->focus_uri
= g_strdup(focus_uri
);
884 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
885 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
886 _("Accept"), accept_cb
,
887 _("Decline"), decline_cb
,
894 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
897 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
898 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
899 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
900 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
901 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
903 sipe_xml_free(xn_conferencing
);
905 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
908 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
909 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
910 (SipeUserAskCb
) conf_accept_cb
,
911 (SipeUserAskCb
) conf_decline_cb
);
914 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
923 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
925 struct sip_session
*session
;
926 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
928 sipe_private
->sessions_to_accept
=
929 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
932 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
933 session
->chat_session
);
936 conf_accept_ctx_free(ctx
);
940 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
942 sipe_private
->sessions_to_accept
=
943 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
945 conf_accept_ctx_free(ctx
);
951 sipe_process_conference(struct sipe_core_private
*sipe_private
,
954 sipe_xml
*xn_conference_info
;
955 const sipe_xml
*node
;
956 const sipe_xml
*xn_subject
;
957 const gchar
*focus_uri
;
958 struct sip_session
*session
;
959 gboolean just_joined
= FALSE
;
961 gboolean audio_was_added
= FALSE
;
964 if (msg
->response
!= 0 && msg
->response
!= 200) return;
966 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
968 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
969 if (!xn_conference_info
) return;
971 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
972 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
975 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
979 if (!session
->chat_session
->backend
) {
980 gchar
*self
= sip_uri_self(sipe_private
);
983 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
984 session
->chat_session
,
985 session
->chat_session
->title
,
988 /* @TODO ask for full state (re-subscribe) if it was a partial one -
989 * this is to obtain full list of conference participants.
995 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
996 g_free(session
->subject
);
997 session
->subject
= sipe_xml_data(xn_subject
);
998 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
999 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1003 if (!session
->im_mcu_uri
) {
1004 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1006 node
= sipe_xml_twin(node
))
1008 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1010 if (sipe_strequal("chat", purpose
)) {
1012 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1013 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1021 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1022 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1023 const gchar
*state
= sipe_xml_attribute(node
, "state");
1024 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1025 gboolean is_operator
= sipe_strequal(role
, "presenter");
1026 gboolean is_in_im_mcu
= FALSE
;
1027 gchar
*self
= sip_uri_self(sipe_private
);
1029 if (sipe_strequal("deleted", state
)) {
1030 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1031 sipe_backend_chat_remove(session
->chat_session
->backend
,
1036 const sipe_xml
*endpoint
;
1037 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1038 const gchar
*session_type
;
1039 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1040 gboolean connected
= sipe_strequal("connected", status
);
1046 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1048 if (sipe_strequal("chat", session_type
)) {
1049 is_in_im_mcu
= TRUE
;
1050 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1051 sipe_backend_chat_add(session
->chat_session
->backend
,
1053 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1056 sipe_backend_chat_operator(session
->chat_session
->backend
,
1059 } else if (sipe_strequal("audio-video", session_type
)) {
1061 if (!session
->is_call
)
1062 audio_was_added
= TRUE
;
1066 if (!is_in_im_mcu
) {
1067 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1068 sipe_backend_chat_remove(session
->chat_session
->backend
,
1078 if (audio_was_added
) {
1079 session
->is_call
= TRUE
;
1080 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1081 (SipeUserAskCb
) call_accept_cb
,
1082 (SipeUserAskCb
) call_decline_cb
);
1086 /* entity-view, locked */
1087 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1089 node
= sipe_xml_twin(node
)) {
1091 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1093 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1094 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1096 gchar
*locked
= sipe_xml_data(xn_locked
);
1097 gboolean prev_locked
= session
->locked
;
1098 session
->locked
= sipe_strequal(locked
, "true");
1099 if (prev_locked
&& !session
->locked
) {
1100 sipe_user_present_info(sipe_private
, session
,
1101 _("This conference is no longer locked. Additional participants can now join."));
1103 if (!prev_locked
&& session
->locked
) {
1104 sipe_user_present_info(sipe_private
, session
,
1105 _("This conference is locked. Nobody else can join the conference while it is locked."));
1108 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1109 session
->locked
? "TRUE" : "FALSE");
1115 sipe_xml_free(xn_conference_info
);
1117 if (session
->im_mcu_uri
) {
1118 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1120 dialog
= sipe_dialog_add(session
);
1122 dialog
->callid
= g_strdup(session
->callid
);
1123 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1125 /* send INVITE to IM MCU */
1126 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1130 sipe_process_pending_invite_queue(sipe_private
, session
);
1134 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1135 struct sip_session
*session
)
1137 sipe_user_present_info(sipe_private
, session
,
1138 _("You have been disconnected from this conference."));
1139 sipe_backend_chat_close(session
->chat_session
->backend
);
1143 conf_session_close(struct sipe_core_private
*sipe_private
,
1144 struct sip_session
*session
)
1147 /* unsubscribe from focus */
1148 sipe_subscribe_conference(sipe_private
,
1149 session
->chat_session
->id
, TRUE
);
1151 if (session
->focus_dialog
) {
1152 /* send BYE to focus */
1153 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1159 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1162 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1163 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1164 static struct sip_session
*session
;
1166 const sipe_xml
*node
;
1170 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1172 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1177 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1178 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1180 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1183 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1184 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1185 gchar
*uri
= parse_from(tmp
);
1186 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1187 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1188 /* default to error if missing or conversion failed */
1189 if ((error
== 0) || (error
>= 300))
1190 sipe_user_present_message_undelivered(sipe_private
,
1201 sipe_xml_free(xn_imdn
);
1203 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1204 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1205 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1210 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1212 const gchar
*buddy_name
)
1214 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1215 struct sipe_chat_session
*chat_session
= parameter
;
1216 struct sip_session
*session
;
1218 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1219 chat_session
->title
);
1221 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1222 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1225 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1227 const gchar
*buddy_name
)
1229 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1230 struct sipe_chat_session
*chat_session
= parameter
;
1231 struct sip_session
*session
;
1233 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1234 chat_session
->title
);
1236 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1237 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);