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
);
148 const sipe_xml
*node
;
149 gchar
*default_region
;
151 if (!sipe_strequal("success", sipe_xml_attribute(xn_response
, "code"))) {
155 node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/mcu-types/mcuType");
156 for (;node
; node
= sipe_xml_twin(node
)) {
157 sipe_private
->conf_mcu_types
=
158 g_slist_append(sipe_private
->conf_mcu_types
,
159 sipe_xml_data(node
));
162 g_hash_table_remove_all(sipe_private
->access_numbers
);
163 node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/pstn-bridging/access-numbers/region");
164 for (;node
; node
= sipe_xml_twin(node
)) {
165 gchar
*name
= g_strdup(sipe_xml_attribute(node
, "name"));
166 gchar
*number
= sipe_xml_data(sipe_xml_child(node
, "access-number/number"));
167 if (name
&& number
) {
168 g_hash_table_insert(sipe_private
->access_numbers
, name
, number
);
172 node
= sipe_xml_child(xn_response
, "getConferencingCapabilities/pstn-bridging/access-numbers/default-region");
173 default_region
= sipe_xml_data(node
);
174 if (default_region
) {
175 sipe_private
->default_access_number
=
176 g_hash_table_lookup(sipe_private
->access_numbers
, default_region
);
178 g_free(default_region
);
180 sipe_xml_free(xn_response
);
187 sipe_conf_get_capabilities(struct sipe_core_private
*sipe_private
)
189 cccp_request(sipe_private
, "SERVICE",
190 sipe_private
->focus_factory_uri
,
192 process_conf_get_capabilities
,
193 "<getConferencingCapabilities />");
197 sipe_conf_supports_mcu_type(struct sipe_core_private
*sipe_private
,
200 return g_slist_find_custom(sipe_private
->conf_mcu_types
, type
,
201 sipe_strcompare
) != NULL
;
205 * Generates random GUID.
206 * This method is borrowed from pidgin's msnutils.c
211 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
212 rand() % 0xAAFF + 0x1111,
213 rand() % 0xAAFF + 0x1111,
214 rand() % 0xAAFF + 0x1111,
215 rand() % 0xAAFF + 0x1111,
216 rand() % 0xAAFF + 0x1111,
217 rand() % 0xAAFF + 0x1111,
218 rand() % 0xAAFF + 0x1111,
219 rand() % 0xAAFF + 0x1111);
222 /** Invite us to the focus callback */
224 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
226 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
228 struct sip_session
*session
= NULL
;
229 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
231 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
234 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
239 if (!session
->focus_dialog
) {
240 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
245 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
247 if (msg
->response
>= 200) {
248 /* send ACK to focus */
249 session
->focus_dialog
->cseq
= 0;
250 sip_transport_ack(sipe_private
, session
->focus_dialog
);
251 session
->focus_dialog
->outgoing_invite
= NULL
;
252 session
->focus_dialog
->is_established
= TRUE
;
255 if (msg
->response
>= 400) {
256 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
258 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
259 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
260 _("Failed to join the conference"),
261 reason
? reason
: _("no reason given"));
264 sipe_session_remove(sipe_private
, session
);
267 } else if (msg
->response
== 200) {
268 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
269 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
270 if (sipe_strequal(code
, "success")) {
271 /* subscribe to focus */
272 sipe_subscribe_conference(sipe_private
,
273 session
->chat_session
->id
,
276 if (session
->is_call
)
277 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
278 session
->chat_session
);
281 sipe_xml_free(xn_response
);
289 parse_ocs_focus_uri(const gchar
*uri
)
291 const gchar
*confkey
;
297 // URI can have this prefix if it was typed in by the user
298 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
302 uri_len
= strlen(uri
);
304 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
305 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
309 confkey
= g_strstr_len(uri
, -1, "?");
311 /* TODO: Investigate how conf-key field should be used,
312 * ignoring for now */
313 uri_len
= confkey
- uri
;
316 return g_strndup(uri
, uri_len
);
320 parse_lync_join_url(const gchar
*uri
)
322 gchar
*focus_uri
= NULL
;
329 if (g_str_has_prefix(uri
, "https://")) {
331 } else if (g_str_has_prefix(uri
, "http://")) {
335 parts
= g_strsplit(uri
, "/", 0);
337 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
338 if (parts_count
>= 3) {
339 const gchar
*conference_id
= parts
[parts_count
- 1];
340 const gchar
*organizer_alias
= parts
[parts_count
- 2];
342 gchar
**domain_parts
= g_strsplit(parts
[0], ".", 2);
344 /* we need to drop the first sub-domain from the URL */
345 if (domain_parts
[0] && domain_parts
[1]) {
346 focus_uri
= g_strdup_printf("sip:%s@%s;gruu;opaque=app:conf:focus:id:%s",
352 g_strfreev(domain_parts
);
360 static void sipe_conf_error(struct sipe_core_private
*sipe_private
,
363 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
365 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
366 _("Failed to join the conference"),
371 static void sipe_conf_lync_url_cb(struct sipe_core_private
*sipe_private
,
373 SIPE_UNUSED_PARAMETER GSList
*headers
,
375 gpointer callback_data
)
377 gchar
*uri
= callback_data
;
379 if (status
!= (guint
) SIPE_HTTP_STATUS_ABORTED
) {
380 gchar
*focus_uri
= NULL
;
384 * Extract focus URI from HTML, e.g.
386 * <a ... href="conf:sip:...ABCDEF%3Frequired..." ... >
388 const gchar
*start
= g_strstr_len(body
,
395 end
= strchr(start
, '"');
398 gchar
*html
= g_strndup(start
,
401 /* decode HTML entities */
402 gchar
*html_unescaped
= sipe_backend_markup_strip_html(html
);
405 if (!is_empty(html_unescaped
)) {
406 gchar
*uri_unescaped
= sipe_utils_uri_unescape(html_unescaped
);
407 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: found focus URI '%s'",
409 focus_uri
= parse_ocs_focus_uri(uri_unescaped
);
410 g_free(uri_unescaped
);
412 g_free(html_unescaped
);
417 /* If we can't find a focus URI then fall back to URL parser */
419 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: no focus URI found. Falling back to parsing Lync URL '%s'",
421 focus_uri
= parse_lync_join_url(uri
);
425 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
428 sipe_conf_error(sipe_private
, uri
);
435 static gboolean
sipe_conf_check_for_lync_url(struct sipe_core_private
*sipe_private
,
438 if (!(g_str_has_prefix(uri
, "https://") ||
439 g_str_has_prefix(uri
, "http://")))
442 /* URL points to a HTML page with the conference focus URI */
443 return(sipe_http_request_get(sipe_private
,
446 sipe_conf_lync_url_cb
,
451 void sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
454 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
455 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
457 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
458 uri
? uri
: "<UNDEFINED>",
459 uri_ue
? uri_ue
: "<UNDEFINED>");
461 /* takes ownership of "uri_ue" if successful */
462 if (!sipe_conf_check_for_lync_url(sipe_private
, uri_ue
)) {
463 gchar
*focus_uri
= parse_ocs_focus_uri(uri_ue
);
466 sipe_conf_create(sipe_private
, NULL
, focus_uri
);
469 sipe_conf_error(sipe_private
, uri
);
476 /** Create new session with Focus URI */
478 sipe_conf_create(struct sipe_core_private
*sipe_private
,
479 struct sipe_chat_session
*chat_session
,
480 const gchar
*focus_uri
)
482 /* addUser request to the focus.
484 * focus_URI, from, endpoint_GUID
486 static const gchar CCCP_ADD_USER
[] =
488 "<conferenceKeys confEntity=\"%s\"/>"
489 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
491 "<ci:entry>attendee</ci:entry>"
493 "<ci:endpoint entity=\"{%s}\" "
494 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
499 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
504 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
505 session
->focus_dialog
->callid
= gencallid();
506 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
507 session
->focus_dialog
->endpoint_GUID
= rand_guid();
508 session
->focus_dialog
->ourtag
= gentag();
510 self
= sip_uri_self(sipe_private
);
511 session
->focus_dialog
->outgoing_invite
=
512 cccp_request(sipe_private
, "INVITE",
513 session
->focus_dialog
->with
, session
->focus_dialog
,
514 process_invite_conf_focus_response
,
516 session
->focus_dialog
->with
, self
,
517 session
->focus_dialog
->endpoint_GUID
);
519 /* Rejoin existing session? */
521 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
524 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
525 chat_session
->backend
,
527 chat_session
->title
);
534 /** Modify User Role */
536 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
537 struct sip_session
*session
,
540 /* modifyUserRoles request to the focus. Makes user a leader.
545 static const gchar CCCP_MODIFY_USER_ROLES
[] =
547 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
548 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
549 "<entry>presenter</entry>"
551 "</modifyUserRoles>";
553 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
554 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
558 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
559 session
->focus_dialog
, NULL
,
560 CCCP_MODIFY_USER_ROLES
,
561 session
->focus_dialog
->with
, who
);
565 * Check conference lock status
567 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
568 struct sipe_chat_session
*chat_session
)
570 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
571 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
574 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
575 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
578 gchar
*self
= sip_uri_self(sipe_private
);
580 /* Only operators are allowed to change the lock status */
581 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
582 status
= session
->locked
?
583 SIPE_CHAT_LOCK_STATUS_LOCKED
:
584 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
595 * Modify Conference Lock
596 * Sends request to Focus.
597 * INFO method is a carrier of application/cccp+xml
600 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
601 struct sipe_chat_session
*chat_session
,
602 const gboolean locked
)
604 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
607 * locked (%s) "true" or "false" values applicable
609 static const gchar CCCP_MODIFY_CONFERENCE_LOCK
[] =
610 "<modifyConferenceLock>"
611 "<conferenceKeys confEntity=\"%s\"/>"
612 "<locked>%s</locked>"
613 "</modifyConferenceLock>";
615 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
617 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
620 if (!session
) return;
621 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
622 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
626 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
627 session
->focus_dialog
, NULL
,
628 CCCP_MODIFY_CONFERENCE_LOCK
,
629 session
->focus_dialog
->with
,
630 locked
? "true" : "false");
633 /** Modify Delete User */
635 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
636 struct sip_session
*session
,
639 /* deleteUser request to the focus. Removes a user from the conference.
644 static const gchar CCCP_DELETE_USER
[] =
646 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
649 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
650 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
654 cccp_request(sipe_private
, "INFO", session
->focus_dialog
->with
,
655 session
->focus_dialog
, NULL
,
657 session
->focus_dialog
->with
, who
);
660 /** Invite counterparty to join conference callback */
662 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
664 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
666 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
668 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
669 dialog
->cseq
= sipmsg_parse_cseq(msg
);
670 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
671 sipe_dialog_parse(dialog
, msg
, TRUE
);
673 if (msg
->response
>= 200) {
674 /* send ACK to counterparty */
676 sip_transport_ack(sipe_private
, dialog
);
677 dialog
->outgoing_invite
= NULL
;
678 dialog
->is_established
= TRUE
;
681 if (msg
->response
>= 400) {
682 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
683 /* @TODO notify user of failure to invite counterparty */
684 sipe_dialog_free(dialog
);
688 if (msg
->response
>= 200) {
689 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
690 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
692 /* close IM session to counterparty */
694 sip_transport_bye(sipe_private
, im_dialog
);
695 sipe_dialog_remove(session
, dialog
->with
);
699 sipe_dialog_free(dialog
);
704 * Invites counterparty to join conference.
707 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
708 struct sip_session
*session
,
714 struct sip_dialog
*dialog
= NULL
;
716 /* It will be short lived special dialog.
717 * Will not be stored in session.
719 dialog
= g_new0(struct sip_dialog
, 1);
720 dialog
->callid
= gencallid();
721 dialog
->with
= g_strdup(who
);
722 dialog
->ourtag
= gentag();
724 contact
= get_contact(sipe_private
);
725 hdr
= g_strdup_printf(
726 "Supported: ms-sender\r\n"
728 "Content-Type: application/ms-conf-invite+xml\r\n",
732 body
= g_strdup_printf(
733 SIPE_SEND_CONF_INVITE
,
734 session
->chat_session
->id
,
735 session
->subject
? session
->subject
: ""
738 sip_transport_invite(sipe_private
,
742 process_invite_conf_response
);
744 sipe_dialog_free(dialog
);
749 /** Create conference callback */
751 process_conf_add_response(struct sipe_core_private
*sipe_private
,
753 struct transaction
*trans
)
755 if (msg
->response
>= 400) {
756 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
757 /* @TODO notify user of failure to create conference */
760 if (msg
->response
== 200) {
761 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
762 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
764 gchar
*who
= trans
->payload
->data
;
765 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
766 struct sip_session
*session
= sipe_conf_create(sipe_private
,
768 sipe_xml_attribute(xn_conference_info
,
771 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
772 session
->chat_session
->id
);
774 session
->pending_invite_queue
= sipe_utils_slist_insert_unique_sorted(session
->pending_invite_queue
,
776 (GCompareFunc
)strcmp
,
779 sipe_xml_free(xn_response
);
786 * Creates conference.
789 sipe_conf_add(struct sipe_core_private
*sipe_private
,
792 gchar
*conference_id
;
793 struct transaction
*trans
;
794 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
796 struct transaction_payload
*payload
;
798 /* addConference request to the focus factory.
800 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
801 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
802 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
804 static const gchar CCCP_ADD_CONFERENCE
[] =
806 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
808 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
809 "<ci:conference-description>"
811 "<msci:conference-id>%s</msci:conference-id>"
812 "<msci:expiry-time>%s</msci:expiry-time>"
813 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
814 "</ci:conference-description>"
815 "<msci:conference-view>%s</msci:conference-view>"
816 "</ci:conference-info>"
819 static const gchar
*DESIRED_MCU_TYPES
[] = {
827 GString
*conference_view
= g_string_new("");
830 for (type
= DESIRED_MCU_TYPES
; *type
; ++type
) {
831 if (sipe_conf_supports_mcu_type(sipe_private
, *type
)) {
832 g_string_append(conference_view
, "<msci:entity-view entity=\"");
833 g_string_append(conference_view
, *type
);
834 g_string_append(conference_view
, "\"/>");
838 expiry_time
= sipe_utils_time_to_str(expiry
);
839 conference_id
= genconfid();
840 trans
= cccp_request(sipe_private
, "SERVICE", sipe_private
->focus_factory_uri
,
841 NULL
, process_conf_add_response
,
843 conference_id
, expiry_time
, conference_view
->str
);
844 g_free(conference_id
);
846 g_string_free(conference_view
, TRUE
);
848 payload
= g_new0(struct transaction_payload
, 1);
849 payload
->destroy
= g_free
;
850 payload
->data
= g_strdup(who
);
851 trans
->payload
= payload
;
855 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
860 struct sip_session
*session
;
861 gchar
*newTag
= gentag();
862 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
865 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
867 sipmsg_remove_header_now(msg
, "To");
868 sipmsg_add_header_now(msg
, "To", newHeader
);
871 /* acknowledge invite */
872 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
874 /* add self to conf */
875 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
876 session
->is_call
= audio
;
879 struct conf_accept_ctx
{
882 struct sipe_user_ask_ctx
*ask_ctx
;
886 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
888 g_return_if_fail(ctx
!= NULL
);
890 sipmsg_free(ctx
->msg
);
891 g_free(ctx
->focus_uri
);
896 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
898 sipe_private
->sessions_to_accept
=
899 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
901 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
902 conf_accept_ctx_free(ctx
);
906 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
908 sipe_private
->sessions_to_accept
=
909 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
911 sip_transport_response(sipe_private
,
913 603, "Decline", NULL
);
915 conf_accept_ctx_free(ctx
);
919 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
922 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
923 GSList
*it
= sipe_private
->sessions_to_accept
;
925 struct conf_accept_ctx
*ctx
= it
->data
;
926 const gchar
*callid2
= NULL
;
929 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
931 if (sipe_strequal(callid1
, callid2
)) {
935 sip_transport_response(sipe_private
, ctx
->msg
,
936 487, "Request Terminated", NULL
);
939 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
941 sipe_user_close_ask(ctx
->ask_ctx
);
942 conf_accept_ctx_free(ctx
);
947 sipe_private
->sessions_to_accept
=
948 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
958 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
959 const gchar
*focus_uri
,
961 SipeUserAskCb accept_cb
,
962 SipeUserAskCb decline_cb
)
967 const gchar
*novv_note
;
968 struct conf_accept_ctx
*ctx
;
973 novv_note
= _("\n\nAs this client was not compiled with voice call "
974 "support, if you accept, you will be able to contact "
975 "the other participants only via IM session.");
978 parts
= g_strsplit(focus_uri
, ";", 2);
979 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
981 ask_msg
= g_strdup_printf(_("%s wants to invite you "
982 "to the conference call%s"),
983 alias
? alias
: parts
[0], novv_note
);
988 ctx
= g_new0(struct conf_accept_ctx
, 1);
989 sipe_private
->sessions_to_accept
=
990 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
992 ctx
->focus_uri
= g_strdup(focus_uri
);
993 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
994 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
995 _("Accept"), accept_cb
,
996 _("Decline"), decline_cb
,
1003 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
1006 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1007 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
1008 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
1009 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
1010 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
1012 sipe_xml_free(xn_conferencing
);
1014 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
1017 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
1018 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
1019 (SipeUserAskCb
) conf_accept_cb
,
1020 (SipeUserAskCb
) conf_decline_cb
);
1023 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
1032 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
1034 struct sip_session
*session
;
1035 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
1037 sipe_private
->sessions_to_accept
=
1038 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
1041 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
1042 session
->chat_session
);
1045 conf_accept_ctx_free(ctx
);
1049 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
1051 sipe_private
->sessions_to_accept
=
1052 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
1054 conf_accept_ctx_free(ctx
);
1060 sipe_process_conference(struct sipe_core_private
*sipe_private
,
1063 sipe_xml
*xn_conference_info
;
1064 const sipe_xml
*node
;
1065 const sipe_xml
*xn_subject
;
1066 const gchar
*focus_uri
;
1067 struct sip_session
*session
;
1068 gboolean just_joined
= FALSE
;
1070 gboolean audio_was_added
= FALSE
;
1073 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1075 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1077 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1078 if (!xn_conference_info
) return;
1080 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1081 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1084 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1088 if (!session
->chat_session
->backend
) {
1089 gchar
*self
= sip_uri_self(sipe_private
);
1092 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1093 session
->chat_session
,
1094 session
->chat_session
->title
,
1097 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1098 * this is to obtain full list of conference participants.
1104 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1105 g_free(session
->subject
);
1106 session
->subject
= sipe_xml_data(xn_subject
);
1107 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1108 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1112 if (!session
->im_mcu_uri
) {
1113 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1115 node
= sipe_xml_twin(node
))
1117 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1119 if (sipe_strequal("chat", purpose
)) {
1121 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1122 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1130 if (!session
->chat_session
->organizer
) {
1131 node
= sipe_xml_child(xn_conference_info
, "conference-description/organizer/display-name");
1133 session
->chat_session
->organizer
= sipe_xml_data(node
);
1138 if (!session
->chat_session
->join_url
) {
1139 node
= sipe_xml_child(xn_conference_info
, "conference-description/join-url");
1141 session
->chat_session
->join_url
= sipe_xml_data(node
);
1145 /* dial-in conference id */
1146 if (!session
->chat_session
->dial_in_conf_id
) {
1147 node
= sipe_xml_child(xn_conference_info
, "conference-description/pstn-access/id");
1149 session
->chat_session
->dial_in_conf_id
= sipe_xml_data(node
);
1154 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1155 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1156 const gchar
*state
= sipe_xml_attribute(node
, "state");
1157 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1158 gboolean is_operator
= sipe_strequal(role
, "presenter");
1159 gboolean is_in_im_mcu
= FALSE
;
1160 gchar
*self
= sip_uri_self(sipe_private
);
1162 if (sipe_strequal("deleted", state
)) {
1163 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1164 sipe_backend_chat_remove(session
->chat_session
->backend
,
1169 const sipe_xml
*endpoint
;
1170 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1171 const gchar
*session_type
;
1172 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1173 gboolean connected
= sipe_strequal("connected", status
);
1179 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1181 if (sipe_strequal("chat", session_type
)) {
1182 is_in_im_mcu
= TRUE
;
1183 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1184 sipe_backend_chat_add(session
->chat_session
->backend
,
1186 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1189 sipe_backend_chat_operator(session
->chat_session
->backend
,
1192 } else if (sipe_strequal("audio-video", session_type
)) {
1194 if (!session
->is_call
)
1195 audio_was_added
= TRUE
;
1199 if (!is_in_im_mcu
) {
1200 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1201 sipe_backend_chat_remove(session
->chat_session
->backend
,
1211 if (audio_was_added
) {
1212 session
->is_call
= TRUE
;
1213 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1214 (SipeUserAskCb
) call_accept_cb
,
1215 (SipeUserAskCb
) call_decline_cb
);
1219 /* entity-view, locked */
1220 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1222 node
= sipe_xml_twin(node
)) {
1224 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1226 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1227 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1229 gchar
*locked
= sipe_xml_data(xn_locked
);
1230 gboolean prev_locked
= session
->locked
;
1231 session
->locked
= sipe_strequal(locked
, "true");
1232 if (prev_locked
&& !session
->locked
) {
1233 sipe_user_present_info(sipe_private
, session
,
1234 _("This conference is no longer locked. Additional participants can now join."));
1236 if (!prev_locked
&& session
->locked
) {
1237 sipe_user_present_info(sipe_private
, session
,
1238 _("This conference is locked. Nobody else can join the conference while it is locked."));
1241 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1242 session
->locked
? "TRUE" : "FALSE");
1248 sipe_xml_free(xn_conference_info
);
1250 if (session
->im_mcu_uri
) {
1251 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1253 dialog
= sipe_dialog_add(session
);
1255 dialog
->callid
= g_strdup(session
->callid
);
1256 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1258 /* send INVITE to IM MCU */
1259 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1263 sipe_process_pending_invite_queue(sipe_private
, session
);
1267 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1268 struct sip_session
*session
)
1270 sipe_user_present_info(sipe_private
, session
,
1271 _("You have been disconnected from this conference."));
1272 sipe_backend_chat_close(session
->chat_session
->backend
);
1276 conf_session_close(struct sipe_core_private
*sipe_private
,
1277 struct sip_session
*session
)
1280 /* unsubscribe from focus */
1281 sipe_subscribe_conference(sipe_private
,
1282 session
->chat_session
->id
, TRUE
);
1284 if (session
->focus_dialog
) {
1285 /* send BYE to focus */
1286 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1292 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1295 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1296 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1297 static struct sip_session
*session
;
1299 const sipe_xml
*node
;
1303 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1305 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1310 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1311 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1313 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1316 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1317 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1318 gchar
*uri
= parse_from(tmp
);
1319 gchar
*status
= sipe_xml_data(sipe_xml_child(node
, "status"));
1320 guint error
= status
? g_ascii_strtoull(status
, NULL
, 10) : 0;
1321 /* default to error if missing or conversion failed */
1322 if ((error
== 0) || (error
>= 300))
1323 sipe_user_present_message_undelivered(sipe_private
,
1334 sipe_xml_free(xn_imdn
);
1336 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1337 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1338 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1343 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1345 const gchar
*buddy_name
)
1347 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1348 struct sipe_chat_session
*chat_session
= parameter
;
1349 struct sip_session
*session
;
1351 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1352 chat_session
->title
);
1354 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1355 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1358 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1360 const gchar
*buddy_name
)
1362 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1363 struct sipe_chat_session
*chat_session
= parameter
;
1364 struct sip_session
*session
;
1366 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1367 chat_session
->title
);
1369 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1370 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);