6 * Copyright (C) 2010-12 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);
211 * @param expires not respected if set to negative value (E.g. -1)
214 sipe_subscribe_conference(struct sipe_core_private
*sipe_private
,
215 struct sip_session
*session
,
218 sipe_subscribe(sipe_private
,
219 session
->chat_session
->id
,
221 "application/conference-info+xml",
222 expires
? "Expires: 0\r\n" : NULL
,
227 /** Invite us to the focus callback */
229 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
231 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
233 struct sip_session
*session
= NULL
;
234 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
236 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
239 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
244 if (!session
->focus_dialog
) {
245 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
250 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
252 if (msg
->response
>= 200) {
253 /* send ACK to focus */
254 session
->focus_dialog
->cseq
= 0;
255 sip_transport_ack(sipe_private
, session
->focus_dialog
);
256 session
->focus_dialog
->outgoing_invite
= NULL
;
257 session
->focus_dialog
->is_established
= TRUE
;
260 if (msg
->response
>= 400) {
261 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
263 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
264 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
265 _("Failed to join the conference"),
266 reason
? reason
: _("no reason given"));
269 sipe_session_remove(sipe_private
, session
);
272 } else if (msg
->response
== 200) {
273 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
274 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
275 if (sipe_strequal(code
, "success")) {
276 /* subscribe to focus */
277 sipe_subscribe_conference(sipe_private
, session
, FALSE
);
279 if (session
->is_call
)
280 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
281 session
->chat_session
);
284 sipe_xml_free(xn_response
);
292 parse_ocs_focus_uri(const gchar
*uri
)
294 const gchar
*confkey
;
300 // URI can have this prefix if it was typed in by the user
301 if (g_str_has_prefix(uri
, "meet:") || g_str_has_prefix(uri
, "conf:")) {
305 uri_len
= strlen(uri
);
307 if (!uri
|| !g_str_has_prefix(uri
, "sip:") ||
308 uri_len
== 4 || g_strstr_len(uri
, -1, "%")) {
312 confkey
= g_strstr_len(uri
, -1, "?");
314 /* TODO: Investigate how conf-key field should be used,
315 * ignoring for now */
316 uri_len
= confkey
- uri
;
319 return g_strndup(uri
, uri_len
);
323 parse_lync_join_url(const gchar
*uri
)
325 gchar
*focus_uri
= NULL
;
332 if (g_str_has_prefix(uri
, "https://")) {
334 } else if (g_str_has_prefix(uri
, "http://")) {
338 parts
= g_strsplit(uri
, "/", 0);
340 for (parts_count
= 0; parts
[parts_count
]; ++parts_count
);
341 if (parts_count
>= 3) {
342 gchar
*base_url
= parts
[0];
343 gchar
*conference_id
= parts
[parts_count
- 1];
344 gchar
*organizer_alias
= parts
[parts_count
- 2];
346 gchar
**url_parts
= g_strsplit(base_url
, ".", 0);
347 int url_parts_count
= 0;
348 for (url_parts_count
= 0; url_parts
[url_parts_count
]; ++url_parts_count
);
350 if (url_parts_count
>= 3) {
351 focus_uri
= g_strdup_printf("sip:%s@%s.%s;gruu;opaque=app:conf:focus:id:%s",
353 url_parts
[url_parts_count
- 2], url_parts
[url_parts_count
- 1],
357 g_strfreev(url_parts
);
366 sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
369 gchar
*uri_ue
= sipe_utils_uri_unescape(uri
);
371 struct sip_session
*session
= NULL
;
373 focus_uri
= parse_ocs_focus_uri(uri_ue
);
375 focus_uri
= parse_lync_join_url(uri_ue
);
379 session
= sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri
);
382 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid conference URI"),
384 sipe_backend_notify_error(sipe_public
,
385 _("Failed to join the conference"),
395 /** Create new session with Focus URI */
397 sipe_conf_create(struct sipe_core_private
*sipe_private
,
398 struct sipe_chat_session
*chat_session
,
399 const gchar
*focus_uri
)
405 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
410 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
411 session
->focus_dialog
->callid
= gencallid();
412 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
413 session
->focus_dialog
->endpoint_GUID
= rand_guid();
414 session
->focus_dialog
->ourtag
= gentag();
416 contact
= get_contact(sipe_private
);
417 hdr
= g_strdup_printf(
418 "Supported: ms-sender\r\n"
420 "Content-Type: application/cccp+xml\r\n",
424 /* @TODO put request_id to queue to further compare with incoming one */
425 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
426 self
= sip_uri_self(sipe_private
);
427 body
= g_strdup_printf(
428 SIPE_SEND_CONF_ADD_USER
,
429 session
->focus_dialog
->with
,
431 session
->request_id
++,
432 session
->focus_dialog
->with
,
434 session
->focus_dialog
->endpoint_GUID
);
436 session
->focus_dialog
->outgoing_invite
=
437 sip_transport_invite(sipe_private
,
440 session
->focus_dialog
,
441 process_invite_conf_focus_response
);
445 /* Rejoin existing session? */
447 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
450 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
451 chat_session
->backend
,
453 chat_session
->title
);
460 /** Modify User Role */
462 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
463 struct sip_session
*session
,
470 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
471 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
476 "Content-Type: application/cccp+xml\r\n");
478 /* @TODO put request_id to queue to further compare with incoming one */
479 self
= sip_uri_self(sipe_private
);
480 body
= g_strdup_printf(
481 SIPE_SEND_CONF_MODIFY_USER_ROLES
,
482 session
->focus_dialog
->with
,
484 session
->request_id
++,
485 session
->focus_dialog
->with
,
489 sip_transport_info(sipe_private
,
492 session
->focus_dialog
,
499 * Check conference lock status
501 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
502 struct sipe_chat_session
*chat_session
)
504 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
505 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
508 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
509 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
512 gchar
*self
= sip_uri_self(sipe_private
);
514 /* Only operators are allowed to change the lock status */
515 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
516 status
= session
->locked
?
517 SIPE_CHAT_LOCK_STATUS_LOCKED
:
518 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
529 * Modify Conference Lock
530 * Sends request to Focus.
531 * INFO method is a carrier of application/cccp+xml
534 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
535 struct sipe_chat_session
*chat_session
,
536 const gboolean locked
)
538 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
543 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
546 if (!session
) return;
547 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
548 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
553 "Content-Type: application/cccp+xml\r\n");
555 /* @TODO put request_id to queue to further compare with incoming one */
556 self
= sip_uri_self(sipe_private
);
557 body
= g_strdup_printf(
558 SIPE_SEND_CONF_MODIFY_CONF_LOCK
,
559 session
->focus_dialog
->with
,
561 session
->request_id
++,
562 session
->focus_dialog
->with
,
563 locked
? "true" : "false");
566 sip_transport_info(sipe_private
,
569 session
->focus_dialog
,
575 /** Modify Delete User */
577 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
578 struct sip_session
*session
,
585 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
586 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
591 "Content-Type: application/cccp+xml\r\n");
593 /* @TODO put request_id to queue to further compare with incoming one */
594 self
= sip_uri_self(sipe_private
);
595 body
= g_strdup_printf(
596 SIPE_SEND_CONF_DELETE_USER
,
597 session
->focus_dialog
->with
,
599 session
->request_id
++,
600 session
->focus_dialog
->with
,
604 sip_transport_info(sipe_private
,
607 session
->focus_dialog
,
613 /** Invite counterparty to join conference callback */
615 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
617 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
619 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
621 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
622 dialog
->cseq
= sipmsg_parse_cseq(msg
);
623 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
624 sipe_dialog_parse(dialog
, msg
, TRUE
);
626 if (msg
->response
>= 200) {
627 /* send ACK to counterparty */
629 sip_transport_ack(sipe_private
, dialog
);
630 dialog
->outgoing_invite
= NULL
;
631 dialog
->is_established
= TRUE
;
634 if (msg
->response
>= 400) {
635 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
636 /* @TODO notify user of failure to invite counterparty */
637 sipe_dialog_free(dialog
);
641 if (msg
->response
>= 200) {
642 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
643 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
645 /* close IM session to counterparty */
647 sip_transport_bye(sipe_private
, im_dialog
);
648 sipe_dialog_remove(session
, dialog
->with
);
652 sipe_dialog_free(dialog
);
657 * Invites counterparty to join conference.
660 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
661 struct sip_session
*session
,
667 struct sip_dialog
*dialog
= NULL
;
669 /* It will be short lived special dialog.
670 * Will not be stored in session.
672 dialog
= g_new0(struct sip_dialog
, 1);
673 dialog
->callid
= gencallid();
674 dialog
->with
= g_strdup(who
);
675 dialog
->ourtag
= gentag();
677 contact
= get_contact(sipe_private
);
678 hdr
= g_strdup_printf(
679 "Supported: ms-sender\r\n"
681 "Content-Type: application/ms-conf-invite+xml\r\n",
685 body
= g_strdup_printf(
686 SIPE_SEND_CONF_INVITE
,
687 session
->chat_session
->id
,
688 session
->subject
? session
->subject
: ""
691 sip_transport_invite(sipe_private
,
695 process_invite_conf_response
);
697 sipe_dialog_free(dialog
);
702 /** Create conference callback */
704 process_conf_add_response(struct sipe_core_private
*sipe_private
,
706 struct transaction
*trans
)
708 if (msg
->response
>= 400) {
709 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
710 /* @TODO notify user of failure to create conference */
713 if (msg
->response
== 200) {
714 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
715 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
717 gchar
*who
= trans
->payload
->data
;
718 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
719 struct sip_session
*session
= sipe_conf_create(sipe_private
,
721 sipe_xml_attribute(xn_conference_info
,
724 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
725 session
->chat_session
->id
);
727 session
->pending_invite_queue
= slist_insert_unique_sorted(
728 session
->pending_invite_queue
, g_strdup(who
), (GCompareFunc
)strcmp
);
730 sipe_xml_free(xn_response
);
737 * Creates conference.
740 sipe_conf_add(struct sipe_core_private
*sipe_private
,
744 gchar
*conference_id
;
748 struct transaction
*trans
;
749 struct sip_dialog
*dialog
= NULL
;
750 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
752 struct transaction_payload
*payload
;
754 contact
= get_contact(sipe_private
);
755 hdr
= g_strdup_printf(
756 "Supported: ms-sender\r\n"
758 "Content-Type: application/cccp+xml\r\n",
762 expiry_time
= sipe_utils_time_to_str(expiry
);
763 self
= sip_uri_self(sipe_private
);
764 conference_id
= genconfid();
765 body
= g_strdup_printf(
767 sipe_private
->focus_factory_uri
,
773 g_free(conference_id
);
776 trans
= sip_transport_service(sipe_private
,
777 sipe_private
->focus_factory_uri
,
780 process_conf_add_response
);
782 payload
= g_new0(struct transaction_payload
, 1);
783 payload
->destroy
= g_free
;
784 payload
->data
= g_strdup(who
);
785 trans
->payload
= payload
;
787 sipe_dialog_free(dialog
);
793 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
798 struct sip_session
*session
;
799 gchar
*newTag
= gentag();
800 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
803 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
805 sipmsg_remove_header_now(msg
, "To");
806 sipmsg_add_header_now(msg
, "To", newHeader
);
809 /* acknowledge invite */
810 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
812 /* add self to conf */
813 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
814 session
->is_call
= audio
;
817 struct conf_accept_ctx
{
820 struct sipe_user_ask_ctx
*ask_ctx
;
824 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
826 g_return_if_fail(ctx
!= NULL
);
828 sipmsg_free(ctx
->msg
);
829 g_free(ctx
->focus_uri
);
834 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
836 sipe_private
->sessions_to_accept
=
837 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
839 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
840 conf_accept_ctx_free(ctx
);
844 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
846 sipe_private
->sessions_to_accept
=
847 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
849 sip_transport_response(sipe_private
,
851 603, "Decline", NULL
);
853 conf_accept_ctx_free(ctx
);
857 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
860 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
861 GSList
*it
= sipe_private
->sessions_to_accept
;
863 struct conf_accept_ctx
*ctx
= it
->data
;
864 const gchar
*callid2
= NULL
;
867 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
869 if (sipe_strequal(callid1
, callid2
)) {
873 sip_transport_response(sipe_private
, ctx
->msg
,
874 487, "Request Terminated", NULL
);
877 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
879 sipe_user_close_ask(ctx
->ask_ctx
);
880 conf_accept_ctx_free(ctx
);
885 sipe_private
->sessions_to_accept
=
886 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
896 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
897 const gchar
*focus_uri
,
899 SipeUserAskCb accept_cb
,
900 SipeUserAskCb decline_cb
)
905 const gchar
*novv_note
;
906 struct conf_accept_ctx
*ctx
;
911 novv_note
= _("\n\nAs this client was not compiled with voice call "
912 "support, if you accept, you will be able to contact "
913 "the other participants only via IM session.");
916 parts
= g_strsplit(focus_uri
, ";", 2);
917 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
919 ask_msg
= g_strdup_printf(_("%s wants to invite you "
920 "to the conference call%s"),
921 alias
? alias
: parts
[0], novv_note
);
926 ctx
= g_new0(struct conf_accept_ctx
, 1);
927 sipe_private
->sessions_to_accept
=
928 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
930 ctx
->focus_uri
= g_strdup(focus_uri
);
931 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
932 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
933 _("Accept"), accept_cb
,
934 _("Decline"), decline_cb
,
941 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
944 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
945 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
946 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
947 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
948 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
950 sipe_xml_free(xn_conferencing
);
952 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
955 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
956 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
957 (SipeUserAskCb
) conf_accept_cb
,
958 (SipeUserAskCb
) conf_decline_cb
);
961 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
970 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
972 struct sip_session
*session
;
973 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
975 sipe_private
->sessions_to_accept
=
976 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
979 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
980 session
->chat_session
);
983 conf_accept_ctx_free(ctx
);
987 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
989 sipe_private
->sessions_to_accept
=
990 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
992 conf_accept_ctx_free(ctx
);
998 sipe_process_conference(struct sipe_core_private
*sipe_private
,
1001 sipe_xml
*xn_conference_info
;
1002 const sipe_xml
*node
;
1003 const sipe_xml
*xn_subject
;
1004 const gchar
*focus_uri
;
1005 struct sip_session
*session
;
1006 gboolean just_joined
= FALSE
;
1008 gboolean audio_was_added
= FALSE
;
1011 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1013 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
1015 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1016 if (!xn_conference_info
) return;
1018 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
1019 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
1022 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
1026 if (!session
->chat_session
->backend
) {
1027 gchar
*self
= sip_uri_self(sipe_private
);
1030 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1031 session
->chat_session
,
1032 session
->chat_session
->title
,
1035 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1036 * this is to obtain full list of conference participants.
1042 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
1043 g_free(session
->subject
);
1044 session
->subject
= sipe_xml_data(xn_subject
);
1045 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
1046 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
1050 if (!session
->im_mcu_uri
) {
1051 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
1053 node
= sipe_xml_twin(node
))
1055 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
1057 if (sipe_strequal("chat", purpose
)) {
1059 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
1060 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1068 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1069 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1070 const gchar
*state
= sipe_xml_attribute(node
, "state");
1071 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1072 gboolean is_operator
= sipe_strequal(role
, "presenter");
1073 gboolean is_in_im_mcu
= FALSE
;
1074 gchar
*self
= sip_uri_self(sipe_private
);
1076 if (sipe_strequal("deleted", state
)) {
1077 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1078 sipe_backend_chat_remove(session
->chat_session
->backend
,
1083 const sipe_xml
*endpoint
;
1084 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1085 const gchar
*session_type
;
1086 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1087 gboolean connected
= sipe_strequal("connected", status
);
1093 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1095 if (sipe_strequal("chat", session_type
)) {
1096 is_in_im_mcu
= TRUE
;
1097 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1098 sipe_backend_chat_add(session
->chat_session
->backend
,
1100 !just_joined
&& g_ascii_strcasecmp(user_uri
, self
));
1103 sipe_backend_chat_operator(session
->chat_session
->backend
,
1106 } else if (sipe_strequal("audio-video", session_type
)) {
1108 if (!session
->is_call
)
1109 audio_was_added
= TRUE
;
1113 if (!is_in_im_mcu
) {
1114 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1115 sipe_backend_chat_remove(session
->chat_session
->backend
,
1125 if (audio_was_added
) {
1126 session
->is_call
= TRUE
;
1127 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1128 (SipeUserAskCb
) call_accept_cb
,
1129 (SipeUserAskCb
) call_decline_cb
);
1133 /* entity-view, locked */
1134 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1136 node
= sipe_xml_twin(node
)) {
1138 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1140 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1141 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1143 gchar
*locked
= sipe_xml_data(xn_locked
);
1144 gboolean prev_locked
= session
->locked
;
1145 session
->locked
= sipe_strequal(locked
, "true");
1146 if (prev_locked
&& !session
->locked
) {
1147 sipe_user_present_info(sipe_private
, session
,
1148 _("This conference is no longer locked. Additional participants can now join."));
1150 if (!prev_locked
&& session
->locked
) {
1151 sipe_user_present_info(sipe_private
, session
,
1152 _("This conference is locked. Nobody else can join the conference while it is locked."));
1155 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1156 session
->locked
? "TRUE" : "FALSE");
1162 sipe_xml_free(xn_conference_info
);
1164 if (session
->im_mcu_uri
) {
1165 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1167 dialog
= sipe_dialog_add(session
);
1169 dialog
->callid
= g_strdup(session
->callid
);
1170 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1172 /* send INVITE to IM MCU */
1173 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1177 sipe_process_pending_invite_queue(sipe_private
, session
);
1181 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1182 struct sip_session
*session
)
1184 sipe_user_present_info(sipe_private
, session
,
1185 _("You have been disconnected from this conference."));
1186 sipe_backend_chat_close(session
->chat_session
->backend
);
1190 conf_session_close(struct sipe_core_private
*sipe_private
,
1191 struct sip_session
*session
)
1194 /* unsubscribe from focus */
1195 sipe_subscribe_conference(sipe_private
, session
, TRUE
);
1197 if (session
->focus_dialog
) {
1198 /* send BYE to focus */
1199 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1205 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1208 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1209 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1210 static struct sip_session
*session
;
1212 const sipe_xml
*node
;
1216 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1218 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1223 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1224 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1226 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1229 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1230 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1231 gchar
*uri
= parse_from(tmp
);
1232 sipe_user_present_message_undelivered(sipe_private
, session
, -1, -1, uri
, message
);
1237 sipe_xml_free(xn_imdn
);
1239 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1240 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1241 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));
1246 void sipe_core_conf_make_leader(struct sipe_core_public
*sipe_public
,
1248 const gchar
*buddy_name
)
1250 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1251 struct sipe_chat_session
*chat_session
= parameter
;
1252 struct sip_session
*session
;
1254 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1255 chat_session
->title
);
1257 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1258 sipe_conf_modify_user_role(sipe_private
, session
, buddy_name
);
1261 void sipe_core_conf_remove_from(struct sipe_core_public
*sipe_public
,
1263 const gchar
*buddy_name
)
1265 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1266 struct sipe_chat_session
*chat_session
= parameter
;
1267 struct sip_session
*session
;
1269 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1270 chat_session
->title
);
1272 session
= sipe_session_find_chat(sipe_private
, chat_session
);
1273 sipe_conf_delete_user(sipe_private
, session
, buddy_name
);