6 * Copyright (C) 2010-2013 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
35 #include "sipe-common.h"
37 #include "sip-transport.h"
38 #include "sipe-backend.h"
39 #include "sipe-buddy.h"
40 #include "sipe-chat.h"
41 #include "sipe-conf.h"
42 #include "sipe-core.h"
43 #include "sipe-core-private.h"
44 #include "sipe-dialog.h"
47 #include "sipe-session.h"
48 #include "sipe-subscriptions.h"
49 #include "sipe-user.h"
50 #include "sipe-utils.h"
54 #define ENTITY_VIEW_AUDIO_VIDEO "<msci:entity-view entity=\"audio-video\"/>"
56 #define ENTITY_VIEW_AUDIO_VIDEO
60 * Add Conference request to FocusFactory.
61 * @param focus_factory_uri (%s) Ex.: sip:bob7@boston.local;gruu;opaque=app:conf:focusfactory
62 * @param from (%s) Ex.: sip:bob7@boston.local
63 * @param request_id (%d) Ex.: 1094520
64 * @param conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
65 * @param expiry_time (%s) Ex.: 2009-07-13T17:57:09Z , Default duration: 7 hours
67 #define SIPE_SEND_CONF_ADD \
68 "<?xml version=\"1.0\"?>"\
69 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "\
70 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
76 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"\
77 "<ci:conference-description>"\
79 "<msci:conference-id>%s</msci:conference-id>"\
80 "<msci:expiry-time>%s</msci:expiry-time>"\
81 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"\
82 "</ci:conference-description>"\
83 "<msci:conference-view>"\
84 "<msci:entity-view entity=\"chat\"/>"\
85 ENTITY_VIEW_AUDIO_VIDEO \
86 "</msci:conference-view>"\
87 "</ci:conference-info>"\
92 * AddUser request to Focus.
94 * focus_URI, from, request_id, focus_URI, from, endpoint_GUID
96 #define SIPE_SEND_CONF_ADD_USER \
97 "<?xml version=\"1.0\"?>"\
98 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
104 "<conferenceKeys confEntity=\"%s\"/>"\
105 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"\
107 "<ci:entry>attendee</ci:entry>"\
109 "<ci:endpoint entity=\"{%s}\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"\
115 * ModifyUserRoles request to Focus. Makes user a leader.
116 * @param focus_uri (%s)
118 * @param request_id (%d)
119 * @param focus_uri (%s)
122 #define SIPE_SEND_CONF_MODIFY_USER_ROLES \
123 "<?xml version=\"1.0\"?>"\
124 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
130 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
131 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"\
132 "<entry>presenter</entry>"\
134 "</modifyUserRoles>"\
138 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
139 * @param focus_uri (%s)
141 * @param request_id (%d)
142 * @param focus_uri (%s)
143 * @param locked (%s) "true" or "false" values applicable
145 #define SIPE_SEND_CONF_MODIFY_CONF_LOCK \
146 "<?xml version=\"1.0\"?>"\
147 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
152 "<modifyConferenceLock>"\
153 "<conferenceKeys confEntity=\"%s\"/>"\
154 "<locked>%s</locked>"\
155 "</modifyConferenceLock>"\
159 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
160 * @param focus_uri (%s)
162 * @param request_id (%d)
163 * @param focus_uri (%s)
166 #define SIPE_SEND_CONF_DELETE_USER \
167 "<?xml version=\"1.0\"?>"\
168 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
174 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
179 * Invite counterparty to join conference.
180 * @param focus_uri (%s)
181 * @param subject (%s) of conference
183 #define SIPE_SEND_CONF_INVITE \
184 "<Conferencing version=\"2.0\">"\
185 "<focus-uri>%s</focus-uri>"\
186 "<subject>%s</subject>"\
187 "<im available=\"true\">"\
193 * Generates random GUID.
194 * This method is borrowed from pidgin's msnutils.c
199 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
200 rand() % 0xAAFF + 0x1111,
201 rand() % 0xAAFF + 0x1111,
202 rand() % 0xAAFF + 0x1111,
203 rand() % 0xAAFF + 0x1111,
204 rand() % 0xAAFF + 0x1111,
205 rand() % 0xAAFF + 0x1111,
206 rand() % 0xAAFF + 0x1111,
207 rand() % 0xAAFF + 0x1111);
210 /** Invite us to the focus callback */
212 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
214 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
216 struct sip_session
*session
= NULL
;
217 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
219 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
222 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
227 if (!session
->focus_dialog
) {
228 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
233 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
235 if (msg
->response
>= 200) {
236 /* send ACK to focus */
237 session
->focus_dialog
->cseq
= 0;
238 sip_transport_ack(sipe_private
, session
->focus_dialog
);
239 session
->focus_dialog
->outgoing_invite
= NULL
;
240 session
->focus_dialog
->is_established
= TRUE
;
243 if (msg
->response
>= 400) {
244 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
246 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
247 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
248 _("Failed to join the conference"),
249 reason
? reason
: _("no reason given"));
252 sipe_session_remove(sipe_private
, session
);
255 } else if (msg
->response
== 200) {
256 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
257 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
258 if (sipe_strequal(code
, "success")) {
259 /* subscribe to focus */
260 sipe_subscribe_conference(sipe_private
,
261 session
->chat_session
->id
,
264 if (session
->is_call
)
265 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
266 session
->chat_session
);
269 sipe_xml_free(xn_response
);
277 parse_ocs_focus_uri(const gchar
*uri
)
279 const gchar
*confkey
;
285 // URI can have this prefix if it was typed in by the user
286 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
290 uri_len
= strlen(uri
);
292 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
293 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
297 confkey
= g_strstr_len(uri
, -1, "?");
299 /* TODO: Investigate how conf-key field should be used,
300 * ignoring for now */
301 uri_len
= confkey
- uri
;
304 return g_strndup(uri
, uri_len
);
308 parse_lync_join_url(const gchar
*uri
)
310 gchar
*focus_uri
= NULL
;
317 if (g_str_has_prefix(uri
, "https://")) {
319 } else if (g_str_has_prefix(uri
, "http://")) {
323 parts
= g_strsplit(uri
, "/", 0);
325 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
326 if (parts_count
>= 3) {
327 gchar
*base_url
= parts
[0];
328 gchar
*conference_id
= parts
[parts_count
- 1];
329 gchar
*organizer_alias
= parts
[parts_count
- 2];
331 gchar
**url_parts
= g_strsplit(base_url
, ".", 0);
332 int url_parts_count
= 0;
333 for (url_parts_count
= 0; url_parts
[url_parts_count
]; ++url_parts_count
);
335 if (url_parts_count
>= 3) {
336 focus_uri
= g_strdup_printf("sip:%s@%s.%s;gruu;opaque=app:conf:focus:id:%s",
338 url_parts
[url_parts_count
- 2], url_parts
[url_parts_count
- 1],
342 g_strfreev(url_parts
);
351 sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
354 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
356 struct sip_session
*session
= NULL
;
358 focus_uri
= parse_ocs_focus_uri(uri_ue
);
360 focus_uri
= parse_lync_join_url(uri_ue
);
364 session
= sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri
);
367 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
369 sipe_backend_notify_error(sipe_public
,
370 _("Failed to join the conference"),
380 /** Create new session with Focus URI */
382 sipe_conf_create(struct sipe_core_private
*sipe_private
,
383 struct sipe_chat_session
*chat_session
,
384 const gchar
*focus_uri
)
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 contact
= get_contact(sipe_private
);
402 hdr
= g_strdup_printf(
403 "Supported: ms-sender\r\n"
405 "Content-Type: application/cccp+xml\r\n",
409 /* @TODO put request_id to queue to further compare with incoming one */
410 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
411 self
= sip_uri_self(sipe_private
);
412 body
= g_strdup_printf(
413 SIPE_SEND_CONF_ADD_USER
,
414 session
->focus_dialog
->with
,
416 session
->request_id
++,
417 session
->focus_dialog
->with
,
419 session
->focus_dialog
->endpoint_GUID
);
421 session
->focus_dialog
->outgoing_invite
=
422 sip_transport_invite(sipe_private
,
425 session
->focus_dialog
,
426 process_invite_conf_focus_response
);
430 /* Rejoin existing session? */
432 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
435 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
436 chat_session
->backend
,
438 chat_session
->title
);
445 /** Modify User Role */
447 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
448 struct sip_session
*session
,
455 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
456 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
461 "Content-Type: application/cccp+xml\r\n");
463 /* @TODO put request_id to queue to further compare with incoming one */
464 self
= sip_uri_self(sipe_private
);
465 body
= g_strdup_printf(
466 SIPE_SEND_CONF_MODIFY_USER_ROLES
,
467 session
->focus_dialog
->with
,
469 session
->request_id
++,
470 session
->focus_dialog
->with
,
474 sip_transport_info(sipe_private
,
477 session
->focus_dialog
,
484 * Check conference lock status
486 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
487 struct sipe_chat_session
*chat_session
)
489 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
490 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
493 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
494 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
497 gchar
*self
= sip_uri_self(sipe_private
);
499 /* Only operators are allowed to change the lock status */
500 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
501 status
= session
->locked
?
502 SIPE_CHAT_LOCK_STATUS_LOCKED
:
503 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
514 * Modify Conference Lock
515 * Sends request to Focus.
516 * INFO method is a carrier of application/cccp+xml
519 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
520 struct sipe_chat_session
*chat_session
,
521 const gboolean locked
)
523 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
528 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
531 if (!session
) return;
532 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
533 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
538 "Content-Type: application/cccp+xml\r\n");
540 /* @TODO put request_id to queue to further compare with incoming one */
541 self
= sip_uri_self(sipe_private
);
542 body
= g_strdup_printf(
543 SIPE_SEND_CONF_MODIFY_CONF_LOCK
,
544 session
->focus_dialog
->with
,
546 session
->request_id
++,
547 session
->focus_dialog
->with
,
548 locked
? "true" : "false");
551 sip_transport_info(sipe_private
,
554 session
->focus_dialog
,
560 /** Modify Delete User */
562 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
563 struct sip_session
*session
,
570 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
571 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
576 "Content-Type: application/cccp+xml\r\n");
578 /* @TODO put request_id to queue to further compare with incoming one */
579 self
= sip_uri_self(sipe_private
);
580 body
= g_strdup_printf(
581 SIPE_SEND_CONF_DELETE_USER
,
582 session
->focus_dialog
->with
,
584 session
->request_id
++,
585 session
->focus_dialog
->with
,
589 sip_transport_info(sipe_private
,
592 session
->focus_dialog
,
598 /** Invite counterparty to join conference callback */
600 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
602 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
604 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
606 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
607 dialog
->cseq
= sipmsg_parse_cseq(msg
);
608 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
609 sipe_dialog_parse(dialog
, msg
, TRUE
);
611 if (msg
->response
>= 200) {
612 /* send ACK to counterparty */
614 sip_transport_ack(sipe_private
, dialog
);
615 dialog
->outgoing_invite
= NULL
;
616 dialog
->is_established
= TRUE
;
619 if (msg
->response
>= 400) {
620 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
621 /* @TODO notify user of failure to invite counterparty */
622 sipe_dialog_free(dialog
);
626 if (msg
->response
>= 200) {
627 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
628 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
630 /* close IM session to counterparty */
632 sip_transport_bye(sipe_private
, im_dialog
);
633 sipe_dialog_remove(session
, dialog
->with
);
637 sipe_dialog_free(dialog
);
642 * Invites counterparty to join conference.
645 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
646 struct sip_session
*session
,
652 struct sip_dialog
*dialog
= NULL
;
654 /* It will be short lived special dialog.
655 * Will not be stored in session.
657 dialog
= g_new0(struct sip_dialog
, 1);
658 dialog
->callid
= gencallid();
659 dialog
->with
= g_strdup(who
);
660 dialog
->ourtag
= gentag();
662 contact
= get_contact(sipe_private
);
663 hdr
= g_strdup_printf(
664 "Supported: ms-sender\r\n"
666 "Content-Type: application/ms-conf-invite+xml\r\n",
670 body
= g_strdup_printf(
671 SIPE_SEND_CONF_INVITE
,
672 session
->chat_session
->id
,
673 session
->subject
? session
->subject
: ""
676 sip_transport_invite(sipe_private
,
680 process_invite_conf_response
);
682 sipe_dialog_free(dialog
);
687 /** Create conference callback */
689 process_conf_add_response(struct sipe_core_private
*sipe_private
,
691 struct transaction
*trans
)
693 if (msg
->response
>= 400) {
694 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
695 /* @TODO notify user of failure to create conference */
698 if (msg
->response
== 200) {
699 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
700 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
702 gchar
*who
= trans
->payload
->data
;
703 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
704 struct sip_session
*session
= sipe_conf_create(sipe_private
,
706 sipe_xml_attribute(xn_conference_info
,
709 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
710 session
->chat_session
->id
);
712 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
714 (GCompareFunc
)strcmp
,
717 sipe_xml_free(xn_response
);
724 * Creates conference.
727 sipe_conf_add(struct sipe_core_private
*sipe_private
,
731 gchar
*conference_id
;
735 struct transaction
*trans
;
736 struct sip_dialog
*dialog
= NULL
;
737 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
739 struct transaction_payload
*payload
;
741 contact
= get_contact(sipe_private
);
742 hdr
= g_strdup_printf(
743 "Supported: ms-sender\r\n"
745 "Content-Type: application/cccp+xml\r\n",
749 expiry_time
= sipe_utils_time_to_str(expiry
);
750 self
= sip_uri_self(sipe_private
);
751 conference_id
= genconfid();
752 body
= g_strdup_printf(
754 sipe_private
->focus_factory_uri
,
760 g_free(conference_id
);
763 trans
= sip_transport_service(sipe_private
,
764 sipe_private
->focus_factory_uri
,
767 process_conf_add_response
);
769 payload
= g_new0(struct transaction_payload
, 1);
770 payload
->destroy
= g_free
;
771 payload
->data
= g_strdup(who
);
772 trans
->payload
= payload
;
774 sipe_dialog_free(dialog
);
780 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
785 struct sip_session
*session
;
786 gchar
*newTag
= gentag();
787 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
790 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
792 sipmsg_remove_header_now(msg
, "To");
793 sipmsg_add_header_now(msg
, "To", newHeader
);
796 /* acknowledge invite */
797 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
799 /* add self to conf */
800 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
801 session
->is_call
= audio
;
804 struct conf_accept_ctx
{
807 struct sipe_user_ask_ctx
*ask_ctx
;
811 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
813 g_return_if_fail(ctx
!= NULL
);
815 sipmsg_free(ctx
->msg
);
816 g_free(ctx
->focus_uri
);
821 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
823 sipe_private
->sessions_to_accept
=
824 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
826 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
827 conf_accept_ctx_free(ctx
);
831 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
833 sipe_private
->sessions_to_accept
=
834 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
836 sip_transport_response(sipe_private
,
838 603, "Decline", NULL
);
840 conf_accept_ctx_free(ctx
);
844 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
847 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
848 GSList
*it
= sipe_private
->sessions_to_accept
;
850 struct conf_accept_ctx
*ctx
= it
->data
;
851 const gchar
*callid2
= NULL
;
854 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
856 if (sipe_strequal(callid1
, callid2
)) {
860 sip_transport_response(sipe_private
, ctx
->msg
,
861 487, "Request Terminated", NULL
);
864 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
866 sipe_user_close_ask(ctx
->ask_ctx
);
867 conf_accept_ctx_free(ctx
);
872 sipe_private
->sessions_to_accept
=
873 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
883 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
884 const gchar
*focus_uri
,
886 SipeUserAskCb accept_cb
,
887 SipeUserAskCb decline_cb
)
892 const gchar
*novv_note
;
893 struct conf_accept_ctx
*ctx
;
898 novv_note
= _("\n\nAs this client was not compiled with voice call "
899 "support, if you accept, you will be able to contact "
900 "the other participants only via IM session.");
903 parts
= g_strsplit(focus_uri
, ";", 2);
904 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
906 ask_msg
= g_strdup_printf(_("%s wants to invite you "
907 "to the conference call%s"),
908 alias
? alias
: parts
[0], novv_note
);
913 ctx
= g_new0(struct conf_accept_ctx
, 1);
914 sipe_private
->sessions_to_accept
=
915 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
917 ctx
->focus_uri
= g_strdup(focus_uri
);
918 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
919 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
920 _("Accept"), accept_cb
,
921 _("Decline"), decline_cb
,
928 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
931 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
932 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
933 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
934 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
935 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
937 sipe_xml_free(xn_conferencing
);
939 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
942 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
943 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
944 (SipeUserAskCb
) conf_accept_cb
,
945 (SipeUserAskCb
) conf_decline_cb
);
948 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
957 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
959 struct sip_session
*session
;
960 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
962 sipe_private
->sessions_to_accept
=
963 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
966 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
967 session
->chat_session
);
970 conf_accept_ctx_free(ctx
);
974 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
976 sipe_private
->sessions_to_accept
=
977 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
979 conf_accept_ctx_free(ctx
);
985 sipe_process_conference(struct sipe_core_private
*sipe_private
,
988 sipe_xml
*xn_conference_info
;
989 const sipe_xml
*node
;
990 const sipe_xml
*xn_subject
;
991 const gchar
*focus_uri
;
992 struct sip_session
*session
;
993 gboolean just_joined
= FALSE
;
995 gboolean audio_was_added
= FALSE
;
998 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1000 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1002 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1003 if (!xn_conference_info
) return;
1005 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1006 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1009 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1013 if (!session
->chat_session
->backend
) {
1014 gchar
*self
= sip_uri_self(sipe_private
);
1017 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1018 session
->chat_session
,
1019 session
->chat_session
->title
,
1022 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1023 * this is to obtain full list of conference participants.
1029 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1030 g_free(session
->subject
);
1031 session
->subject
= sipe_xml_data(xn_subject
);
1032 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1033 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1037 if (!session
->im_mcu_uri
) {
1038 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1040 node
= sipe_xml_twin(node
))
1042 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1044 if (sipe_strequal("chat", purpose
)) {
1046 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1047 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1055 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1056 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1057 const gchar
*state
= sipe_xml_attribute(node
, "state");
1058 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1059 gboolean is_operator
= sipe_strequal(role
, "presenter");
1060 gboolean is_in_im_mcu
= FALSE
;
1061 gchar
*self
= sip_uri_self(sipe_private
);
1063 if (sipe_strequal("deleted", state
)) {
1064 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1065 sipe_backend_chat_remove(session
->chat_session
->backend
,
1070 const sipe_xml
*endpoint
;
1071 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1072 const gchar
*session_type
;
1073 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1074 gboolean connected
= sipe_strequal("connected", status
);
1080 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1082 if (sipe_strequal("chat", session_type
)) {
1083 is_in_im_mcu
= TRUE
;
1084 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1085 sipe_backend_chat_add(session
->chat_session
->backend
,
1087 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1090 sipe_backend_chat_operator(session
->chat_session
->backend
,
1093 } else if (sipe_strequal("audio-video", session_type
)) {
1095 if (!session
->is_call
)
1096 audio_was_added
= TRUE
;
1100 if (!is_in_im_mcu
) {
1101 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1102 sipe_backend_chat_remove(session
->chat_session
->backend
,
1112 if (audio_was_added
) {
1113 session
->is_call
= TRUE
;
1114 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1115 (SipeUserAskCb
) call_accept_cb
,
1116 (SipeUserAskCb
) call_decline_cb
);
1120 /* entity-view, locked */
1121 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1123 node
= sipe_xml_twin(node
)) {
1125 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1127 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1128 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1130 gchar
*locked
= sipe_xml_data(xn_locked
);
1131 gboolean prev_locked
= session
->locked
;
1132 session
->locked
= sipe_strequal(locked
, "true");
1133 if (prev_locked
&& !session
->locked
) {
1134 sipe_user_present_info(sipe_private
, session
,
1135 _("This conference is no longer locked. Additional participants can now join."));
1137 if (!prev_locked
&& session
->locked
) {
1138 sipe_user_present_info(sipe_private
, session
,
1139 _("This conference is locked. Nobody else can join the conference while it is locked."));
1142 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1143 session
->locked
? "TRUE" : "FALSE");
1149 sipe_xml_free(xn_conference_info
);
1151 if (session
->im_mcu_uri
) {
1152 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1154 dialog
= sipe_dialog_add(session
);
1156 dialog
->callid
= g_strdup(session
->callid
);
1157 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1159 /* send INVITE to IM MCU */
1160 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1164 sipe_process_pending_invite_queue(sipe_private
, session
);
1168 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1169 struct sip_session
*session
)
1171 sipe_user_present_info(sipe_private
, session
,
1172 _("You have been disconnected from this conference."));
1173 sipe_backend_chat_close(session
->chat_session
->backend
);
1177 conf_session_close(struct sipe_core_private
*sipe_private
,
1178 struct sip_session
*session
)
1181 /* unsubscribe from focus */
1182 sipe_subscribe_conference(sipe_private
,
1183 session
->chat_session
->id
, TRUE
);
1185 if (session
->focus_dialog
) {
1186 /* send BYE to focus */
1187 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1193 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1196 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1197 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1198 static struct sip_session
*session
;
1200 const sipe_xml
*node
;
1204 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1206 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1211 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1212 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1214 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1217 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1218 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1219 gchar
*uri
= parse_from(tmp
);
1220 sipe_user_present_message_undelivered(sipe_private
, session
, -1, -1, uri
, message
);
1225 sipe_xml_free(xn_imdn
);
1227 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1228 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1229 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1234 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1236 const gchar
*buddy_name
)
1238 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1239 struct sipe_chat_session
*chat_session
= parameter
;
1240 struct sip_session
*session
;
1242 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1243 chat_session
->title
);
1245 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1246 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1249 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1251 const gchar
*buddy_name
)
1253 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1254 struct sipe_chat_session
*chat_session
= parameter
;
1255 struct sip_session
*session
;
1257 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1258 chat_session
->title
);
1260 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1261 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);