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 #define ENTITY_VIEW_AUDIO_VIDEO "<msci:entity-view entity=\"audio-video\"/>"
65 #define ENTITY_VIEW_AUDIO_VIDEO
69 * Add Conference request to FocusFactory.
70 * @param focus_factory_uri (%s) Ex.: sip:bob7@boston.local;gruu;opaque=app:conf:focusfactory
71 * @param from (%s) Ex.: sip:bob7@boston.local
72 * @param request_id (%d) Ex.: 1094520
73 * @param conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
74 * @param expiry_time (%s) Ex.: 2009-07-13T17:57:09Z , Default duration: 7 hours
76 #define SIPE_SEND_CONF_ADD \
77 "<?xml version=\"1.0\"?>"\
78 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "\
79 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
85 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"\
86 "<ci:conference-description>"\
88 "<msci:conference-id>%s</msci:conference-id>"\
89 "<msci:expiry-time>%s</msci:expiry-time>"\
90 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"\
91 "</ci:conference-description>"\
92 "<msci:conference-view>"\
93 "<msci:entity-view entity=\"chat\"/>"\
94 ENTITY_VIEW_AUDIO_VIDEO \
95 "</msci:conference-view>"\
96 "</ci:conference-info>"\
101 * AddUser request to Focus.
103 * focus_URI, from, request_id, focus_URI, from, endpoint_GUID
105 #define SIPE_SEND_CONF_ADD_USER \
106 "<?xml version=\"1.0\"?>"\
107 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
113 "<conferenceKeys confEntity=\"%s\"/>"\
114 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"\
116 "<ci:entry>attendee</ci:entry>"\
118 "<ci:endpoint entity=\"{%s}\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"\
124 * ModifyUserRoles request to Focus. Makes user a leader.
125 * @param focus_uri (%s)
127 * @param request_id (%d)
128 * @param focus_uri (%s)
131 #define SIPE_SEND_CONF_MODIFY_USER_ROLES \
132 "<?xml version=\"1.0\"?>"\
133 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
139 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
140 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"\
141 "<entry>presenter</entry>"\
143 "</modifyUserRoles>"\
147 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
148 * @param focus_uri (%s)
150 * @param request_id (%d)
151 * @param focus_uri (%s)
152 * @param locked (%s) "true" or "false" values applicable
154 #define SIPE_SEND_CONF_MODIFY_CONF_LOCK \
155 "<?xml version=\"1.0\"?>"\
156 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
161 "<modifyConferenceLock>"\
162 "<conferenceKeys confEntity=\"%s\"/>"\
163 "<locked>%s</locked>"\
164 "</modifyConferenceLock>"\
168 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
169 * @param focus_uri (%s)
171 * @param request_id (%d)
172 * @param focus_uri (%s)
175 #define SIPE_SEND_CONF_DELETE_USER \
176 "<?xml version=\"1.0\"?>"\
177 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
183 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
188 * Invite counterparty to join conference.
189 * @param focus_uri (%s)
190 * @param subject (%s) of conference
192 #define SIPE_SEND_CONF_INVITE \
193 "<Conferencing version=\"2.0\">"\
194 "<focus-uri>%s</focus-uri>"\
195 "<subject>%s</subject>"\
196 "<im available=\"true\">"\
202 * Generates random GUID.
203 * This method is borrowed from pidgin's msnutils.c
208 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
209 rand() % 0xAAFF + 0x1111,
210 rand() % 0xAAFF + 0x1111,
211 rand() % 0xAAFF + 0x1111,
212 rand() % 0xAAFF + 0x1111,
213 rand() % 0xAAFF + 0x1111,
214 rand() % 0xAAFF + 0x1111,
215 rand() % 0xAAFF + 0x1111,
216 rand() % 0xAAFF + 0x1111);
219 /** Invite us to the focus callback */
221 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
223 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
225 struct sip_session
*session
= NULL
;
226 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
228 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
231 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
236 if (!session
->focus_dialog
) {
237 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
242 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
244 if (msg
->response
>= 200) {
245 /* send ACK to focus */
246 session
->focus_dialog
->cseq
= 0;
247 sip_transport_ack(sipe_private
, session
->focus_dialog
);
248 session
->focus_dialog
->outgoing_invite
= NULL
;
249 session
->focus_dialog
->is_established
= TRUE
;
252 if (msg
->response
>= 400) {
253 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
255 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
256 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
257 _("Failed to join the conference"),
258 reason
? reason
: _("no reason given"));
261 sipe_session_remove(sipe_private
, session
);
264 } else if (msg
->response
== 200) {
265 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
266 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
267 if (sipe_strequal(code
, "success")) {
268 /* subscribe to focus */
269 sipe_subscribe_conference(sipe_private
,
270 session
->chat_session
->id
,
273 if (session
->is_call
)
274 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
275 session
->chat_session
);
278 sipe_xml_free(xn_response
);
286 parse_ocs_focus_uri(const gchar
*uri
)
288 const gchar
*confkey
;
294 // URI can have this prefix if it was typed in by the user
295 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
299 uri_len
= strlen(uri
);
301 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
302 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
306 confkey
= g_strstr_len(uri
, -1, "?");
308 /* TODO: Investigate how conf-key field should be used,
309 * ignoring for now */
310 uri_len
= confkey
- uri
;
313 return g_strndup(uri
, uri_len
);
317 parse_lync_join_url(const gchar
*uri
)
319 gchar
*focus_uri
= NULL
;
326 if (g_str_has_prefix(uri
, "https://")) {
328 } else if (g_str_has_prefix(uri
, "http://")) {
332 parts
= g_strsplit(uri
, "/", 0);
334 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
335 if (parts_count
>= 3) {
336 const gchar
*conference_id
= parts
[parts_count
- 1];
337 const gchar
*organizer_alias
= parts
[parts_count
- 2];
339 gchar
**domain_parts
= g_strsplit(parts
[0], ".", 2);
341 /* we need to drop the first sub-domain from the URL */
342 if (domain_parts
[0] && domain_parts
[1]) {
343 focus_uri
= g_strdup_printf("sip:%s@%s;gruu;opaque=app:conf:focus:id:%s",
349 g_strfreev(domain_parts
);
358 sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
361 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
363 struct sip_session
*session
= NULL
;
365 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
366 uri
? uri
: "<UNDEFINED>",
367 uri_ue
? uri_ue
: "<UNDEFINED>");
369 focus_uri
= parse_ocs_focus_uri(uri_ue
);
371 focus_uri
= parse_lync_join_url(uri_ue
);
375 session
= sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri
);
378 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
380 sipe_backend_notify_error(sipe_public
,
381 _("Failed to join the conference"),
391 /** Create new session with Focus URI */
393 sipe_conf_create(struct sipe_core_private
*sipe_private
,
394 struct sipe_chat_session
*chat_session
,
395 const gchar
*focus_uri
)
401 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
406 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
407 session
->focus_dialog
->callid
= gencallid();
408 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
409 session
->focus_dialog
->endpoint_GUID
= rand_guid();
410 session
->focus_dialog
->ourtag
= gentag();
412 contact
= get_contact(sipe_private
);
413 hdr
= g_strdup_printf(
414 "Supported: ms-sender\r\n"
416 "Content-Type: application/cccp+xml\r\n",
420 /* @TODO put request_id to queue to further compare with incoming one */
421 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
422 self
= sip_uri_self(sipe_private
);
423 body
= g_strdup_printf(
424 SIPE_SEND_CONF_ADD_USER
,
425 session
->focus_dialog
->with
,
427 session
->request_id
++,
428 session
->focus_dialog
->with
,
430 session
->focus_dialog
->endpoint_GUID
);
432 session
->focus_dialog
->outgoing_invite
=
433 sip_transport_invite(sipe_private
,
436 session
->focus_dialog
,
437 process_invite_conf_focus_response
);
441 /* Rejoin existing session? */
443 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
446 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
447 chat_session
->backend
,
449 chat_session
->title
);
456 /** Modify User Role */
458 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
459 struct sip_session
*session
,
466 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
467 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
472 "Content-Type: application/cccp+xml\r\n");
474 /* @TODO put request_id to queue to further compare with incoming one */
475 self
= sip_uri_self(sipe_private
);
476 body
= g_strdup_printf(
477 SIPE_SEND_CONF_MODIFY_USER_ROLES
,
478 session
->focus_dialog
->with
,
480 session
->request_id
++,
481 session
->focus_dialog
->with
,
485 sip_transport_info(sipe_private
,
488 session
->focus_dialog
,
495 * Check conference lock status
497 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
498 struct sipe_chat_session
*chat_session
)
500 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
501 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
504 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
505 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
508 gchar
*self
= sip_uri_self(sipe_private
);
510 /* Only operators are allowed to change the lock status */
511 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
512 status
= session
->locked
?
513 SIPE_CHAT_LOCK_STATUS_LOCKED
:
514 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
525 * Modify Conference Lock
526 * Sends request to Focus.
527 * INFO method is a carrier of application/cccp+xml
530 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
531 struct sipe_chat_session
*chat_session
,
532 const gboolean locked
)
534 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
539 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
542 if (!session
) return;
543 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
544 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
549 "Content-Type: application/cccp+xml\r\n");
551 /* @TODO put request_id to queue to further compare with incoming one */
552 self
= sip_uri_self(sipe_private
);
553 body
= g_strdup_printf(
554 SIPE_SEND_CONF_MODIFY_CONF_LOCK
,
555 session
->focus_dialog
->with
,
557 session
->request_id
++,
558 session
->focus_dialog
->with
,
559 locked
? "true" : "false");
562 sip_transport_info(sipe_private
,
565 session
->focus_dialog
,
571 /** Modify Delete User */
573 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
574 struct sip_session
*session
,
581 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
582 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
587 "Content-Type: application/cccp+xml\r\n");
589 /* @TODO put request_id to queue to further compare with incoming one */
590 self
= sip_uri_self(sipe_private
);
591 body
= g_strdup_printf(
592 SIPE_SEND_CONF_DELETE_USER
,
593 session
->focus_dialog
->with
,
595 session
->request_id
++,
596 session
->focus_dialog
->with
,
600 sip_transport_info(sipe_private
,
603 session
->focus_dialog
,
609 /** Invite counterparty to join conference callback */
611 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
613 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
615 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
617 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
618 dialog
->cseq
= sipmsg_parse_cseq(msg
);
619 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
620 sipe_dialog_parse(dialog
, msg
, TRUE
);
622 if (msg
->response
>= 200) {
623 /* send ACK to counterparty */
625 sip_transport_ack(sipe_private
, dialog
);
626 dialog
->outgoing_invite
= NULL
;
627 dialog
->is_established
= TRUE
;
630 if (msg
->response
>= 400) {
631 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
632 /* @TODO notify user of failure to invite counterparty */
633 sipe_dialog_free(dialog
);
637 if (msg
->response
>= 200) {
638 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
639 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
641 /* close IM session to counterparty */
643 sip_transport_bye(sipe_private
, im_dialog
);
644 sipe_dialog_remove(session
, dialog
->with
);
648 sipe_dialog_free(dialog
);
653 * Invites counterparty to join conference.
656 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
657 struct sip_session
*session
,
663 struct sip_dialog
*dialog
= NULL
;
665 /* It will be short lived special dialog.
666 * Will not be stored in session.
668 dialog
= g_new0(struct sip_dialog
, 1);
669 dialog
->callid
= gencallid();
670 dialog
->with
= g_strdup(who
);
671 dialog
->ourtag
= gentag();
673 contact
= get_contact(sipe_private
);
674 hdr
= g_strdup_printf(
675 "Supported: ms-sender\r\n"
677 "Content-Type: application/ms-conf-invite+xml\r\n",
681 body
= g_strdup_printf(
682 SIPE_SEND_CONF_INVITE
,
683 session
->chat_session
->id
,
684 session
->subject
? session
->subject
: ""
687 sip_transport_invite(sipe_private
,
691 process_invite_conf_response
);
693 sipe_dialog_free(dialog
);
698 /** Create conference callback */
700 process_conf_add_response(struct sipe_core_private
*sipe_private
,
702 struct transaction
*trans
)
704 if (msg
->response
>= 400) {
705 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
706 /* @TODO notify user of failure to create conference */
709 if (msg
->response
== 200) {
710 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
711 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
713 gchar
*who
= trans
->payload
->data
;
714 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
715 struct sip_session
*session
= sipe_conf_create(sipe_private
,
717 sipe_xml_attribute(xn_conference_info
,
720 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
721 session
->chat_session
->id
);
723 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
725 (GCompareFunc
)strcmp
,
728 sipe_xml_free(xn_response
);
735 * Creates conference.
738 sipe_conf_add(struct sipe_core_private
*sipe_private
,
742 gchar
*conference_id
;
746 struct transaction
*trans
;
747 struct sip_dialog
*dialog
= NULL
;
748 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
750 struct transaction_payload
*payload
;
752 contact
= get_contact(sipe_private
);
753 hdr
= g_strdup_printf(
754 "Supported: ms-sender\r\n"
756 "Content-Type: application/cccp+xml\r\n",
760 expiry_time
= sipe_utils_time_to_str(expiry
);
761 self
= sip_uri_self(sipe_private
);
762 conference_id
= genconfid();
763 body
= g_strdup_printf(
765 sipe_private
->focus_factory_uri
,
771 g_free(conference_id
);
774 trans
= sip_transport_service(sipe_private
,
775 sipe_private
->focus_factory_uri
,
778 process_conf_add_response
);
780 payload
= g_new0(struct transaction_payload
, 1);
781 payload
->destroy
= g_free
;
782 payload
->data
= g_strdup(who
);
783 trans
->payload
= payload
;
785 sipe_dialog_free(dialog
);
791 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
796 struct sip_session
*session
;
797 gchar
*newTag
= gentag();
798 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
801 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
803 sipmsg_remove_header_now(msg
, "To");
804 sipmsg_add_header_now(msg
, "To", newHeader
);
807 /* acknowledge invite */
808 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
810 /* add self to conf */
811 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
812 session
->is_call
= audio
;
815 struct conf_accept_ctx
{
818 struct sipe_user_ask_ctx
*ask_ctx
;
822 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
824 g_return_if_fail(ctx
!= NULL
);
826 sipmsg_free(ctx
->msg
);
827 g_free(ctx
->focus_uri
);
832 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
834 sipe_private
->sessions_to_accept
=
835 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
837 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
838 conf_accept_ctx_free(ctx
);
842 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
844 sipe_private
->sessions_to_accept
=
845 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
847 sip_transport_response(sipe_private
,
849 603, "Decline", NULL
);
851 conf_accept_ctx_free(ctx
);
855 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
858 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
859 GSList
*it
= sipe_private
->sessions_to_accept
;
861 struct conf_accept_ctx
*ctx
= it
->data
;
862 const gchar
*callid2
= NULL
;
865 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
867 if (sipe_strequal(callid1
, callid2
)) {
871 sip_transport_response(sipe_private
, ctx
->msg
,
872 487, "Request Terminated", NULL
);
875 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
877 sipe_user_close_ask(ctx
->ask_ctx
);
878 conf_accept_ctx_free(ctx
);
883 sipe_private
->sessions_to_accept
=
884 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
894 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
895 const gchar
*focus_uri
,
897 SipeUserAskCb accept_cb
,
898 SipeUserAskCb decline_cb
)
903 const gchar
*novv_note
;
904 struct conf_accept_ctx
*ctx
;
909 novv_note
= _("\n\nAs this client was not compiled with voice call "
910 "support, if you accept, you will be able to contact "
911 "the other participants only via IM session.");
914 parts
= g_strsplit(focus_uri
, ";", 2);
915 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
917 ask_msg
= g_strdup_printf(_("%s wants to invite you "
918 "to the conference call%s"),
919 alias
? alias
: parts
[0], novv_note
);
924 ctx
= g_new0(struct conf_accept_ctx
, 1);
925 sipe_private
->sessions_to_accept
=
926 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
928 ctx
->focus_uri
= g_strdup(focus_uri
);
929 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
930 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
931 _("Accept"), accept_cb
,
932 _("Decline"), decline_cb
,
939 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
942 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
943 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
944 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
945 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
946 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
948 sipe_xml_free(xn_conferencing
);
950 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
953 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
954 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
955 (SipeUserAskCb
) conf_accept_cb
,
956 (SipeUserAskCb
) conf_decline_cb
);
959 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
968 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
970 struct sip_session
*session
;
971 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
973 sipe_private
->sessions_to_accept
=
974 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
977 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
978 session
->chat_session
);
981 conf_accept_ctx_free(ctx
);
985 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
987 sipe_private
->sessions_to_accept
=
988 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
990 conf_accept_ctx_free(ctx
);
996 sipe_process_conference(struct sipe_core_private
*sipe_private
,
999 sipe_xml
*xn_conference_info
;
1000 const sipe_xml
*node
;
1001 const sipe_xml
*xn_subject
;
1002 const gchar
*focus_uri
;
1003 struct sip_session
*session
;
1004 gboolean just_joined
= FALSE
;
1006 gboolean audio_was_added
= FALSE
;
1009 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1011 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1013 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1014 if (!xn_conference_info
) return;
1016 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1017 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1020 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1024 if (!session
->chat_session
->backend
) {
1025 gchar
*self
= sip_uri_self(sipe_private
);
1028 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1029 session
->chat_session
,
1030 session
->chat_session
->title
,
1033 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1034 * this is to obtain full list of conference participants.
1040 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1041 g_free(session
->subject
);
1042 session
->subject
= sipe_xml_data(xn_subject
);
1043 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1044 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1048 if (!session
->im_mcu_uri
) {
1049 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1051 node
= sipe_xml_twin(node
))
1053 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1055 if (sipe_strequal("chat", purpose
)) {
1057 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1058 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1066 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1067 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1068 const gchar
*state
= sipe_xml_attribute(node
, "state");
1069 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1070 gboolean is_operator
= sipe_strequal(role
, "presenter");
1071 gboolean is_in_im_mcu
= FALSE
;
1072 gchar
*self
= sip_uri_self(sipe_private
);
1074 if (sipe_strequal("deleted", state
)) {
1075 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1076 sipe_backend_chat_remove(session
->chat_session
->backend
,
1081 const sipe_xml
*endpoint
;
1082 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1083 const gchar
*session_type
;
1084 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1085 gboolean connected
= sipe_strequal("connected", status
);
1091 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1093 if (sipe_strequal("chat", session_type
)) {
1094 is_in_im_mcu
= TRUE
;
1095 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1096 sipe_backend_chat_add(session
->chat_session
->backend
,
1098 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1101 sipe_backend_chat_operator(session
->chat_session
->backend
,
1104 } else if (sipe_strequal("audio-video", session_type
)) {
1106 if (!session
->is_call
)
1107 audio_was_added
= TRUE
;
1111 if (!is_in_im_mcu
) {
1112 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1113 sipe_backend_chat_remove(session
->chat_session
->backend
,
1123 if (audio_was_added
) {
1124 session
->is_call
= TRUE
;
1125 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1126 (SipeUserAskCb
) call_accept_cb
,
1127 (SipeUserAskCb
) call_decline_cb
);
1131 /* entity-view, locked */
1132 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1134 node
= sipe_xml_twin(node
)) {
1136 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1138 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1139 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1141 gchar
*locked
= sipe_xml_data(xn_locked
);
1142 gboolean prev_locked
= session
->locked
;
1143 session
->locked
= sipe_strequal(locked
, "true");
1144 if (prev_locked
&& !session
->locked
) {
1145 sipe_user_present_info(sipe_private
, session
,
1146 _("This conference is no longer locked. Additional participants can now join."));
1148 if (!prev_locked
&& session
->locked
) {
1149 sipe_user_present_info(sipe_private
, session
,
1150 _("This conference is locked. Nobody else can join the conference while it is locked."));
1153 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1154 session
->locked
? "TRUE" : "FALSE");
1160 sipe_xml_free(xn_conference_info
);
1162 if (session
->im_mcu_uri
) {
1163 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1165 dialog
= sipe_dialog_add(session
);
1167 dialog
->callid
= g_strdup(session
->callid
);
1168 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1170 /* send INVITE to IM MCU */
1171 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1175 sipe_process_pending_invite_queue(sipe_private
, session
);
1179 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1180 struct sip_session
*session
)
1182 sipe_user_present_info(sipe_private
, session
,
1183 _("You have been disconnected from this conference."));
1184 sipe_backend_chat_close(session
->chat_session
->backend
);
1188 conf_session_close(struct sipe_core_private
*sipe_private
,
1189 struct sip_session
*session
)
1192 /* unsubscribe from focus */
1193 sipe_subscribe_conference(sipe_private
,
1194 session
->chat_session
->id
, TRUE
);
1196 if (session
->focus_dialog
) {
1197 /* send BYE to focus */
1198 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1204 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1207 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1208 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1209 static struct sip_session
*session
;
1211 const sipe_xml
*node
;
1215 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1217 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1222 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1223 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1225 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1228 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1229 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1230 gchar
*uri
= parse_from(tmp
);
1231 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1232 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1233 /* default to error if missing or conversion failed */
1234 if ((error
== 0) || (error
>= 300))
1235 sipe_user_present_message_undelivered(sipe_private
,
1246 sipe_xml_free(xn_imdn
);
1248 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1249 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1250 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1255 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1257 const gchar
*buddy_name
)
1259 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1260 struct sipe_chat_session
*chat_session
= parameter
;
1261 struct sip_session
*session
;
1263 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1264 chat_session
->title
);
1266 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1267 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1270 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1272 const gchar
*buddy_name
)
1274 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1275 struct sipe_chat_session
*chat_session
= parameter
;
1276 struct sip_session
*session
;
1278 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1279 chat_session
->title
);
1281 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1282 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);