6 * Copyright (C) 2010-2015 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Documentation references:
28 * Microsoft DevNet: [MS-CONFIM]: Centralized Conference Control Protocol:
29 * Instant Messaging Extensions
30 * <http://msdn.microsoft.com/en-us/library/cc431500%28v=office.12%29.aspx>
44 #include "sipe-common.h"
46 #include "sip-transport.h"
47 #include "sipe-backend.h"
48 #include "sipe-buddy.h"
49 #include "sipe-chat.h"
50 #include "sipe-conf.h"
51 #include "sipe-core.h"
52 #include "sipe-core-private.h"
53 #include "sipe-dialog.h"
54 #include "sipe-http.h"
57 #include "sipe-session.h"
58 #include "sipe-subscriptions.h"
59 #include "sipe-user.h"
60 #include "sipe-utils.h"
64 * Invite counterparty to join conference.
65 * @param focus_uri (%s)
66 * @param subject (%s) of conference
68 #define SIPE_SEND_CONF_INVITE \
69 "<Conferencing version=\"2.0\">"\
70 "<focus-uri>%s</focus-uri>"\
71 "<subject>%s</subject>"\
72 "<im available=\"true\">"\
77 static struct transaction
*
78 cccp_request(struct sipe_core_private
*sipe_private
, const gchar
*method
,
79 const gchar
*with
, struct sip_dialog
*dialog
,
80 TransCallback callback
, const gchar
*body
, ...)
86 gchar
*self
= sip_uri_self(sipe_private
);
90 struct transaction
*trans
;
92 headers
= g_strdup_printf(
93 "Supported: ms-sender\r\n"
95 "Content-Type: application/cccp+xml\r\n",
96 sipe_private
->contact
);
98 /* TODO: put request_id to queue to further compare with incoming one */
99 request
= g_strdup_printf(
100 "<?xml version=\"1.0\"?>"
101 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "
102 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "
111 sipe_private
->cccp_request_id
++,
115 va_start(args
, body
);
116 request_body
= g_strdup_vprintf(request
, args
);
121 trans
= sip_transport_request(sipe_private
,
131 g_free(request_body
);
137 process_conf_get_capabilities(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
139 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
141 if (msg
->response
>= 400) {
142 SIPE_DEBUG_INFO_NOFORMAT("process_conf_get_capabilities: "
143 "getConferencingCapabilities failed.");
146 if (msg
->response
== 200) {
147 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
149 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code"))) {
150 const sipe_xml
*node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/mcu-types/mcuType");
151 for (;node
; node
= sipe_xml_twin(node
)) {
152 sipe_private
->conf_mcu_types
=
153 g_slist_append(sipe_private
->conf_mcu_types
,
154 sipe_xml_data(node
));
158 sipe_xml_free(xn_response
);
165 sipe_conf_get_capabilities(struct sipe_core_private
*sipe_private
)
167 cccp_request(sipe_private
, "SERVICE",
168 sipe_private
->focus_factory_uri
,
170 process_conf_get_capabilities
,
171 "<getConferencingCapabilities />");
175 sipe_conf_supports_mcu_type(struct sipe_core_private
*sipe_private
,
178 return g_slist_find_custom(sipe_private
->conf_mcu_types
, type
,
179 sipe_strcompare
) != NULL
;
183 * Generates random GUID.
184 * This method is borrowed from pidgin's msnutils.c
189 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
190 rand() % 0xAAFF + 0x1111,
191 rand() % 0xAAFF + 0x1111,
192 rand() % 0xAAFF + 0x1111,
193 rand() % 0xAAFF + 0x1111,
194 rand() % 0xAAFF + 0x1111,
195 rand() % 0xAAFF + 0x1111,
196 rand() % 0xAAFF + 0x1111,
197 rand() % 0xAAFF + 0x1111);
200 /** Invite us to the focus callback */
202 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
204 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
206 struct sip_session
*session
= NULL
;
207 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
209 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
212 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
217 if (!session
->focus_dialog
) {
218 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
223 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
225 if (msg
->response
>= 200) {
226 /* send ACK to focus */
227 session
->focus_dialog
->cseq
= 0;
228 sip_transport_ack(sipe_private
, session
->focus_dialog
);
229 session
->focus_dialog
->outgoing_invite
= NULL
;
230 session
->focus_dialog
->is_established
= TRUE
;
233 if (msg
->response
>= 400) {
234 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
236 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
237 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
238 _("Failed to join the conference"),
239 reason
? reason
: _("no reason given"));
242 sipe_session_remove(sipe_private
, session
);
245 } else if (msg
->response
== 200) {
246 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
247 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
248 if (sipe_strequal(code
, "success")) {
249 /* subscribe to focus */
250 sipe_subscribe_conference(sipe_private
,
251 session
->chat_session
->id
,
254 if (session
->is_call
)
255 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
256 session
->chat_session
);
259 sipe_xml_free(xn_response
);
267 parse_ocs_focus_uri(const gchar
*uri
)
269 const gchar
*confkey
;
275 // URI can have this prefix if it was typed in by the user
276 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
280 uri_len
= strlen(uri
);
282 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
283 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
287 confkey
= g_strstr_len(uri
, -1, "?");
289 /* TODO: Investigate how conf-key field should be used,
290 * ignoring for now */
291 uri_len
= confkey
- uri
;
294 return g_strndup(uri
, uri_len
);
298 parse_lync_join_url(const gchar
*uri
)
300 gchar
*focus_uri
= NULL
;
307 if (g_str_has_prefix(uri
, "https://")) {
309 } else if (g_str_has_prefix(uri
, "http://")) {
313 parts
= g_strsplit(uri
, "/", 0);
315 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
316 if (parts_count
>= 3) {
317 const gchar
*conference_id
= parts
[parts_count
- 1];
318 const gchar
*organizer_alias
= parts
[parts_count
- 2];
320 gchar
**domain_parts
= g_strsplit(parts
[0], ".", 2);
322 /* we need to drop the first sub-domain from the URL */
323 if (domain_parts
[0] && domain_parts
[1]) {
324 focus_uri
= g_strdup_printf("sip:%s@%s;gruu;opaque=app:conf:focus:id:%s",
330 g_strfreev(domain_parts
);
338 static void sipe_conf_error(struct sipe_core_private
*sipe_private
,
341 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
343 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
344 _("Failed to join the conference"),
349 static void sipe_conf_lync_url_cb(struct sipe_core_private
*sipe_private
,
350 SIPE_UNUSED_PARAMETER guint status
,
351 SIPE_UNUSED_PARAMETER GSList
*headers
,
352 SIPE_UNUSED_PARAMETER
const gchar
*body
,
353 gpointer callback_data
)
355 gchar
*uri
= callback_data
;
356 gchar
*focus_uri
= parse_lync_join_url(uri
);
359 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
362 sipe_conf_error(sipe_private
, uri
);
368 static gboolean
sipe_conf_check_for_lync_url(struct sipe_core_private
*sipe_private
,
371 if (!(g_str_has_prefix(uri
, "https://") ||
372 g_str_has_prefix(uri
, "http://")))
375 /* URL points to a HTML page with the conference focus URI */
376 return(sipe_http_request_get(sipe_private
,
379 sipe_conf_lync_url_cb
,
384 void sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
387 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
388 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
390 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
391 uri
? uri
: "<UNDEFINED>",
392 uri_ue
? uri_ue
: "<UNDEFINED>");
394 /* takes ownership of "uri_ue" if successful */
395 if (!sipe_conf_check_for_lync_url(sipe_private
, uri_ue
)) {
396 gchar
*focus_uri
= parse_ocs_focus_uri(uri_ue
);
399 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
402 sipe_conf_error(sipe_private
, uri
);
409 /** Create new session with Focus URI */
411 sipe_conf_create(struct sipe_core_private
*sipe_private
,
412 struct sipe_chat_session
*chat_session
,
413 const gchar
*focus_uri
)
415 /* addUser request to the focus.
417 * focus_URI, from, endpoint_GUID
419 static const gchar CCCP_ADD_USER
[] =
421 "<conferenceKeys confEntity=\"%s\"/>"
422 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
424 "<ci:entry>attendee</ci:entry>"
426 "<ci:endpoint entity=\"{%s}\" "
427 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
432 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
437 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
438 session
->focus_dialog
->callid
= gencallid();
439 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
440 session
->focus_dialog
->endpoint_GUID
= rand_guid();
441 session
->focus_dialog
->ourtag
= gentag();
443 self
= sip_uri_self(sipe_private
);
444 session
->focus_dialog
->outgoing_invite
=
445 cccp_request(sipe_private
, "INVITE",
446 session
->focus_dialog
->with
, session
->focus_dialog
,
447 process_invite_conf_focus_response
,
449 session
->focus_dialog
->with
, self
,
450 session
->focus_dialog
->endpoint_GUID
);
452 /* Rejoin existing session? */
454 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
457 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
458 chat_session
->backend
,
460 chat_session
->title
);
467 /** Modify User Role */
469 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
470 struct sip_session
*session
,
473 /* modifyUserRoles request to the focus. Makes user a leader.
478 static const gchar CCCP_MODIFY_USER_ROLES
[] =
480 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
481 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
482 "<entry>presenter</entry>"
484 "</modifyUserRoles>";
486 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
487 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
491 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
492 session
->focus_dialog
, NULL
,
493 CCCP_MODIFY_USER_ROLES
,
494 session
->focus_dialog
->with
, who
);
498 * Check conference lock status
500 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
501 struct sipe_chat_session
*chat_session
)
503 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
504 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
507 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
508 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
511 gchar
*self
= sip_uri_self(sipe_private
);
513 /* Only operators are allowed to change the lock status */
514 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
515 status
= session
->locked
?
516 SIPE_CHAT_LOCK_STATUS_LOCKED
:
517 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
528 * Modify Conference Lock
529 * Sends request to Focus.
530 * INFO method is a carrier of application/cccp+xml
533 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
534 struct sipe_chat_session
*chat_session
,
535 const gboolean locked
)
537 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
540 * locked (%s) "true" or "false" values applicable
542 static const gchar CCCP_MODIFY_CONFERENCE_LOCK
[] =
543 "<modifyConferenceLock>"
544 "<conferenceKeys confEntity=\"%s\"/>"
545 "<locked>%s</locked>"
546 "</modifyConferenceLock>";
548 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
550 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
553 if (!session
) return;
554 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
555 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
559 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
560 session
->focus_dialog
, NULL
,
561 CCCP_MODIFY_CONFERENCE_LOCK
,
562 session
->focus_dialog
->with
,
563 locked
? "true" : "false");
566 /** Modify Delete User */
568 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
569 struct sip_session
*session
,
572 /* deleteUser request to the focus. Removes a user from the conference.
577 static const gchar CCCP_DELETE_USER
[] =
579 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
582 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
583 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
587 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
588 session
->focus_dialog
, NULL
,
590 session
->focus_dialog
->with
, who
);
593 /** Invite counterparty to join conference callback */
595 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
597 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
599 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
601 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
602 dialog
->cseq
= sipmsg_parse_cseq(msg
);
603 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
604 sipe_dialog_parse(dialog
, msg
, TRUE
);
606 if (msg
->response
>= 200) {
607 /* send ACK to counterparty */
609 sip_transport_ack(sipe_private
, dialog
);
610 dialog
->outgoing_invite
= NULL
;
611 dialog
->is_established
= TRUE
;
614 if (msg
->response
>= 400) {
615 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
616 /* @TODO notify user of failure to invite counterparty */
617 sipe_dialog_free(dialog
);
621 if (msg
->response
>= 200) {
622 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
623 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
625 /* close IM session to counterparty */
627 sip_transport_bye(sipe_private
, im_dialog
);
628 sipe_dialog_remove(session
, dialog
->with
);
632 sipe_dialog_free(dialog
);
637 * Invites counterparty to join conference.
640 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
641 struct sip_session
*session
,
647 struct sip_dialog
*dialog
= NULL
;
649 /* It will be short lived special dialog.
650 * Will not be stored in session.
652 dialog
= g_new0(struct sip_dialog
, 1);
653 dialog
->callid
= gencallid();
654 dialog
->with
= g_strdup(who
);
655 dialog
->ourtag
= gentag();
657 contact
= get_contact(sipe_private
);
658 hdr
= g_strdup_printf(
659 "Supported: ms-sender\r\n"
661 "Content-Type: application/ms-conf-invite+xml\r\n",
665 body
= g_strdup_printf(
666 SIPE_SEND_CONF_INVITE
,
667 session
->chat_session
->id
,
668 session
->subject
? session
->subject
: ""
671 sip_transport_invite(sipe_private
,
675 process_invite_conf_response
);
677 sipe_dialog_free(dialog
);
682 /** Create conference callback */
684 process_conf_add_response(struct sipe_core_private
*sipe_private
,
686 struct transaction
*trans
)
688 if (msg
->response
>= 400) {
689 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
690 /* @TODO notify user of failure to create conference */
693 if (msg
->response
== 200) {
694 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
695 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
697 gchar
*who
= trans
->payload
->data
;
698 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
699 struct sip_session
*session
= sipe_conf_create(sipe_private
,
701 sipe_xml_attribute(xn_conference_info
,
704 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
705 session
->chat_session
->id
);
707 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
709 (GCompareFunc
)strcmp
,
712 sipe_xml_free(xn_response
);
719 * Creates conference.
722 sipe_conf_add(struct sipe_core_private
*sipe_private
,
725 gchar
*conference_id
;
726 struct transaction
*trans
;
727 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
729 struct transaction_payload
*payload
;
731 /* addConference request to the focus factory.
733 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
734 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
735 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
737 static const gchar CCCP_ADD_CONFERENCE
[] =
739 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
741 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
742 "<ci:conference-description>"
744 "<msci:conference-id>%s</msci:conference-id>"
745 "<msci:expiry-time>%s</msci:expiry-time>"
746 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
747 "</ci:conference-description>"
748 "<msci:conference-view>%s</msci:conference-view>"
749 "</ci:conference-info>"
752 static const gchar
*DESIRED_MCU_TYPES
[] = {
760 GString
*conference_view
= g_string_new("");
763 for (type
= DESIRED_MCU_TYPES
; *type
; ++type
) {
764 if (sipe_conf_supports_mcu_type(sipe_private
, *type
)) {
765 g_string_append(conference_view
, "<msci:entity-view entity=\"");
766 g_string_append(conference_view
, *type
);
767 g_string_append(conference_view
, "\"/>");
771 expiry_time
= sipe_utils_time_to_str(expiry
);
772 conference_id
= genconfid();
773 trans
= cccp_request(sipe_private
, "SERVICE", sipe_private
->focus_factory_uri
,
774 NULL
, process_conf_add_response
,
776 conference_id
, expiry_time
, conference_view
->str
);
777 g_free(conference_id
);
779 g_string_free(conference_view
, TRUE
);
781 payload
= g_new0(struct transaction_payload
, 1);
782 payload
->destroy
= g_free
;
783 payload
->data
= g_strdup(who
);
784 trans
->payload
= payload
;
788 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
793 struct sip_session
*session
;
794 gchar
*newTag
= gentag();
795 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
798 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
800 sipmsg_remove_header_now(msg
, "To");
801 sipmsg_add_header_now(msg
, "To", newHeader
);
804 /* acknowledge invite */
805 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
807 /* add self to conf */
808 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
809 session
->is_call
= audio
;
812 struct conf_accept_ctx
{
815 struct sipe_user_ask_ctx
*ask_ctx
;
819 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
821 g_return_if_fail(ctx
!= NULL
);
823 sipmsg_free(ctx
->msg
);
824 g_free(ctx
->focus_uri
);
829 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
831 sipe_private
->sessions_to_accept
=
832 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
834 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
835 conf_accept_ctx_free(ctx
);
839 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
841 sipe_private
->sessions_to_accept
=
842 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
844 sip_transport_response(sipe_private
,
846 603, "Decline", NULL
);
848 conf_accept_ctx_free(ctx
);
852 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
855 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
856 GSList
*it
= sipe_private
->sessions_to_accept
;
858 struct conf_accept_ctx
*ctx
= it
->data
;
859 const gchar
*callid2
= NULL
;
862 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
864 if (sipe_strequal(callid1
, callid2
)) {
868 sip_transport_response(sipe_private
, ctx
->msg
,
869 487, "Request Terminated", NULL
);
872 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
874 sipe_user_close_ask(ctx
->ask_ctx
);
875 conf_accept_ctx_free(ctx
);
880 sipe_private
->sessions_to_accept
=
881 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
891 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
892 const gchar
*focus_uri
,
894 SipeUserAskCb accept_cb
,
895 SipeUserAskCb decline_cb
)
900 const gchar
*novv_note
;
901 struct conf_accept_ctx
*ctx
;
906 novv_note
= _("\n\nAs this client was not compiled with voice call "
907 "support, if you accept, you will be able to contact "
908 "the other participants only via IM session.");
911 parts
= g_strsplit(focus_uri
, ";", 2);
912 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
914 ask_msg
= g_strdup_printf(_("%s wants to invite you "
915 "to the conference call%s"),
916 alias
? alias
: parts
[0], novv_note
);
921 ctx
= g_new0(struct conf_accept_ctx
, 1);
922 sipe_private
->sessions_to_accept
=
923 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
925 ctx
->focus_uri
= g_strdup(focus_uri
);
926 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
927 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
928 _("Accept"), accept_cb
,
929 _("Decline"), decline_cb
,
936 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
939 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
940 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
941 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
942 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
943 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
945 sipe_xml_free(xn_conferencing
);
947 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
950 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
951 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
952 (SipeUserAskCb
) conf_accept_cb
,
953 (SipeUserAskCb
) conf_decline_cb
);
956 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
965 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
967 struct sip_session
*session
;
968 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
970 sipe_private
->sessions_to_accept
=
971 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
974 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
975 session
->chat_session
);
978 conf_accept_ctx_free(ctx
);
982 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
984 sipe_private
->sessions_to_accept
=
985 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
987 conf_accept_ctx_free(ctx
);
993 sipe_process_conference(struct sipe_core_private
*sipe_private
,
996 sipe_xml
*xn_conference_info
;
997 const sipe_xml
*node
;
998 const sipe_xml
*xn_subject
;
999 const gchar
*focus_uri
;
1000 struct sip_session
*session
;
1001 gboolean just_joined
= FALSE
;
1003 gboolean audio_was_added
= FALSE
;
1006 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1008 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1010 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1011 if (!xn_conference_info
) return;
1013 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1014 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1017 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1021 if (!session
->chat_session
->backend
) {
1022 gchar
*self
= sip_uri_self(sipe_private
);
1025 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1026 session
->chat_session
,
1027 session
->chat_session
->title
,
1030 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1031 * this is to obtain full list of conference participants.
1037 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1038 g_free(session
->subject
);
1039 session
->subject
= sipe_xml_data(xn_subject
);
1040 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1041 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1045 if (!session
->im_mcu_uri
) {
1046 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1048 node
= sipe_xml_twin(node
))
1050 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1052 if (sipe_strequal("chat", purpose
)) {
1054 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1055 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1063 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1064 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1065 const gchar
*state
= sipe_xml_attribute(node
, "state");
1066 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1067 gboolean is_operator
= sipe_strequal(role
, "presenter");
1068 gboolean is_in_im_mcu
= FALSE
;
1069 gchar
*self
= sip_uri_self(sipe_private
);
1071 if (sipe_strequal("deleted", state
)) {
1072 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1073 sipe_backend_chat_remove(session
->chat_session
->backend
,
1078 const sipe_xml
*endpoint
;
1079 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1080 const gchar
*session_type
;
1081 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1082 gboolean connected
= sipe_strequal("connected", status
);
1088 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1090 if (sipe_strequal("chat", session_type
)) {
1091 is_in_im_mcu
= TRUE
;
1092 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1093 sipe_backend_chat_add(session
->chat_session
->backend
,
1095 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1098 sipe_backend_chat_operator(session
->chat_session
->backend
,
1101 } else if (sipe_strequal("audio-video", session_type
)) {
1103 if (!session
->is_call
)
1104 audio_was_added
= TRUE
;
1108 if (!is_in_im_mcu
) {
1109 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1110 sipe_backend_chat_remove(session
->chat_session
->backend
,
1120 if (audio_was_added
) {
1121 session
->is_call
= TRUE
;
1122 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1123 (SipeUserAskCb
) call_accept_cb
,
1124 (SipeUserAskCb
) call_decline_cb
);
1128 /* entity-view, locked */
1129 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1131 node
= sipe_xml_twin(node
)) {
1133 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1135 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1136 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1138 gchar
*locked
= sipe_xml_data(xn_locked
);
1139 gboolean prev_locked
= session
->locked
;
1140 session
->locked
= sipe_strequal(locked
, "true");
1141 if (prev_locked
&& !session
->locked
) {
1142 sipe_user_present_info(sipe_private
, session
,
1143 _("This conference is no longer locked. Additional participants can now join."));
1145 if (!prev_locked
&& session
->locked
) {
1146 sipe_user_present_info(sipe_private
, session
,
1147 _("This conference is locked. Nobody else can join the conference while it is locked."));
1150 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1151 session
->locked
? "TRUE" : "FALSE");
1157 sipe_xml_free(xn_conference_info
);
1159 if (session
->im_mcu_uri
) {
1160 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1162 dialog
= sipe_dialog_add(session
);
1164 dialog
->callid
= g_strdup(session
->callid
);
1165 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1167 /* send INVITE to IM MCU */
1168 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1172 sipe_process_pending_invite_queue(sipe_private
, session
);
1176 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1177 struct sip_session
*session
)
1179 sipe_user_present_info(sipe_private
, session
,
1180 _("You have been disconnected from this conference."));
1181 sipe_backend_chat_close(session
->chat_session
->backend
);
1185 conf_session_close(struct sipe_core_private
*sipe_private
,
1186 struct sip_session
*session
)
1189 /* unsubscribe from focus */
1190 sipe_subscribe_conference(sipe_private
,
1191 session
->chat_session
->id
, TRUE
);
1193 if (session
->focus_dialog
) {
1194 /* send BYE to focus */
1195 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1201 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1204 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1205 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1206 static struct sip_session
*session
;
1208 const sipe_xml
*node
;
1212 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1214 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1219 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1220 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1222 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1225 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1226 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1227 gchar
*uri
= parse_from(tmp
);
1228 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1229 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1230 /* default to error if missing or conversion failed */
1231 if ((error
== 0) || (error
>= 300))
1232 sipe_user_present_message_undelivered(sipe_private
,
1243 sipe_xml_free(xn_imdn
);
1245 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1246 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1247 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1252 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1254 const gchar
*buddy_name
)
1256 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1257 struct sipe_chat_session
*chat_session
= parameter
;
1258 struct sip_session
*session
;
1260 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1261 chat_session
->title
);
1263 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1264 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1267 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1269 const gchar
*buddy_name
)
1271 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1272 struct sipe_chat_session
*chat_session
= parameter
;
1273 struct sip_session
*session
;
1275 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1276 chat_session
->title
);
1278 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1279 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);