6 * Copyright (C) 2010-11 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-media.h"
50 #include "sipe-session.h"
51 #include "sipe-subscriptions.h"
52 #include "sipe-user.h"
53 #include "sipe-utils.h"
58 #define ENTITY_VIEW_AUDIO_VIDEO "<msci:entity-view entity=\"audio-video\"/>"
60 #define ENTITY_VIEW_AUDIO_VIDEO
64 * Add Conference request to FocusFactory.
65 * @param focus_factory_uri (%s) Ex.: sip:bob7@boston.local;gruu;opaque=app:conf:focusfactory
66 * @param from (%s) Ex.: sip:bob7@boston.local
67 * @param request_id (%d) Ex.: 1094520
68 * @param conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
69 * @param expiry_time (%s) Ex.: 2009-07-13T17:57:09Z , Default duration: 7 hours
71 #define SIPE_SEND_CONF_ADD \
72 "<?xml version=\"1.0\"?>"\
73 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "\
74 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
80 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"\
81 "<ci:conference-description>"\
83 "<msci:conference-id>%s</msci:conference-id>"\
84 "<msci:expiry-time>%s</msci:expiry-time>"\
85 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"\
86 "</ci:conference-description>"\
87 "<msci:conference-view>"\
88 "<msci:entity-view entity=\"chat\"/>"\
89 ENTITY_VIEW_AUDIO_VIDEO \
90 "</msci:conference-view>"\
91 "</ci:conference-info>"\
96 * AddUser request to Focus.
98 * focus_URI, from, request_id, focus_URI, from, endpoint_GUID
100 #define SIPE_SEND_CONF_ADD_USER \
101 "<?xml version=\"1.0\"?>"\
102 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
108 "<conferenceKeys confEntity=\"%s\"/>"\
109 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"\
111 "<ci:entry>attendee</ci:entry>"\
113 "<ci:endpoint entity=\"{%s}\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"\
119 * ModifyUserRoles request to Focus. Makes user a leader.
120 * @param focus_uri (%s)
122 * @param request_id (%d)
123 * @param focus_uri (%s)
126 #define SIPE_SEND_CONF_MODIFY_USER_ROLES \
127 "<?xml version=\"1.0\"?>"\
128 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
134 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
135 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"\
136 "<entry>presenter</entry>"\
138 "</modifyUserRoles>"\
142 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
143 * @param focus_uri (%s)
145 * @param request_id (%d)
146 * @param focus_uri (%s)
147 * @param locked (%s) "true" or "false" values applicable
149 #define SIPE_SEND_CONF_MODIFY_CONF_LOCK \
150 "<?xml version=\"1.0\"?>"\
151 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
156 "<modifyConferenceLock>"\
157 "<conferenceKeys confEntity=\"%s\"/>"\
158 "<locked>%s</locked>"\
159 "</modifyConferenceLock>"\
163 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
164 * @param focus_uri (%s)
166 * @param request_id (%d)
167 * @param focus_uri (%s)
170 #define SIPE_SEND_CONF_DELETE_USER \
171 "<?xml version=\"1.0\"?>"\
172 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
178 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
183 * Invite counterparty to join conference.
184 * @param focus_uri (%s)
185 * @param subject (%s) of conference
187 #define SIPE_SEND_CONF_INVITE \
188 "<Conferencing version=\"2.0\">"\
189 "<focus-uri>%s</focus-uri>"\
190 "<subject>%s</subject>"\
191 "<im available=\"true\">"\
197 * Generates random GUID.
198 * This method is borrowed from pidgin's msnutils.c
203 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
204 rand() % 0xAAFF + 0x1111,
205 rand() % 0xAAFF + 0x1111,
206 rand() % 0xAAFF + 0x1111,
207 rand() % 0xAAFF + 0x1111,
208 rand() % 0xAAFF + 0x1111,
209 rand() % 0xAAFF + 0x1111,
210 rand() % 0xAAFF + 0x1111,
211 rand() % 0xAAFF + 0x1111);
215 * @param expires not respected if set to negative value (E.g. -1)
218 sipe_subscribe_conference(struct sipe_core_private
*sipe_private
,
219 struct sip_session
*session
,
222 sipe_subscribe(sipe_private
,
223 session
->chat_session
->id
,
225 "application/conference-info+xml",
226 expires
? "Expires: 0\r\n" : NULL
,
231 /** Invite us to the focus callback */
233 process_invite_conf_focus_response(struct sipe_core_private
*sipe_private
,
235 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
237 struct sip_session
*session
= NULL
;
238 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
240 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
243 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
248 if (!session
->focus_dialog
) {
249 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
254 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
256 if (msg
->response
>= 200) {
257 /* send ACK to focus */
258 session
->focus_dialog
->cseq
= 0;
259 sip_transport_ack(sipe_private
, session
->focus_dialog
);
260 session
->focus_dialog
->outgoing_invite
= NULL
;
261 session
->focus_dialog
->is_established
= TRUE
;
264 if (msg
->response
>= 400) {
265 gchar
*reason
= sipmsg_get_ms_diagnostics_reason(msg
);
267 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
268 sipe_backend_notify_error(_("Failed to join the conference"),
269 reason
? reason
: _("no reason given"));
272 sipe_session_remove(sipe_private
, session
);
275 } else if (msg
->response
== 200) {
276 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
277 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
278 if (sipe_strequal(code
, "success")) {
279 /* subscribe to focus */
280 sipe_subscribe_conference(sipe_private
, session
, FALSE
);
282 if (session
->is_call
)
283 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
284 session
->chat_session
);
287 sipe_xml_free(xn_response
);
295 sipe_core_conf_create(struct sipe_core_public
*sipe_public
,
296 const gchar
*focus_uri
)
299 const gchar
*focus_uri_ue
;
300 struct sip_session
*session
= NULL
;
302 focus_uri_ue
= buf
= sipe_utils_uri_unescape(focus_uri
);
304 // URI can have this prefix if it was typed in by the user
305 if (g_str_has_prefix(focus_uri_ue
, "meet:"))
308 if (!focus_uri_ue
|| !g_str_has_prefix(focus_uri_ue
, "sip:") ||
309 strlen(focus_uri_ue
) == 4 || g_strstr_len(focus_uri_ue
, -1, "%")) {
310 gchar
*error
= g_strdup_printf(_("\"%s\" is not a valid focus URI"),
311 focus_uri
? focus_uri
: "");
312 sipe_backend_notify_error(_("Failed to join the conference"),
316 gchar
*querystr
= g_strstr_len(focus_uri_ue
, -1, "?");
318 /* TODO: Investigate how conf-key field should be used,
319 * ignoring for now */
323 session
= sipe_conf_create(SIPE_CORE_PRIVATE
, NULL
, focus_uri_ue
);
331 /** Create new session with Focus URI */
333 sipe_conf_create(struct sipe_core_private
*sipe_private
,
334 struct sipe_chat_session
*chat_session
,
335 const gchar
*focus_uri
)
341 struct sip_session
*session
= sipe_session_add_chat(sipe_private
,
346 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
347 session
->focus_dialog
->callid
= gencallid();
348 session
->focus_dialog
->with
= g_strdup(session
->chat_session
->id
);
349 session
->focus_dialog
->endpoint_GUID
= rand_guid();
350 session
->focus_dialog
->ourtag
= gentag();
352 contact
= get_contact(sipe_private
);
353 hdr
= g_strdup_printf(
354 "Supported: ms-sender\r\n"
356 "Content-Type: application/cccp+xml\r\n",
360 /* @TODO put request_id to queue to further compare with incoming one */
361 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
362 self
= sip_uri_self(sipe_private
);
363 body
= g_strdup_printf(
364 SIPE_SEND_CONF_ADD_USER
,
365 session
->focus_dialog
->with
,
367 session
->request_id
++,
368 session
->focus_dialog
->with
,
370 session
->focus_dialog
->endpoint_GUID
);
372 session
->focus_dialog
->outgoing_invite
=
373 sip_transport_invite(sipe_private
,
376 session
->focus_dialog
,
377 process_invite_conf_focus_response
);
381 /* Rejoin existing session? */
383 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
386 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC
,
387 chat_session
->backend
,
389 chat_session
->title
);
396 /** Modify User Role */
398 sipe_conf_modify_user_role(struct sipe_core_private
*sipe_private
,
399 struct sip_session
*session
,
406 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
407 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
412 "Content-Type: application/cccp+xml\r\n");
414 /* @TODO put request_id to queue to further compare with incoming one */
415 self
= sip_uri_self(sipe_private
);
416 body
= g_strdup_printf(
417 SIPE_SEND_CONF_MODIFY_USER_ROLES
,
418 session
->focus_dialog
->with
,
420 session
->request_id
++,
421 session
->focus_dialog
->with
,
425 sip_transport_info(sipe_private
,
428 session
->focus_dialog
,
435 * Check conference lock status
437 sipe_chat_lock_status
sipe_core_chat_lock_status(struct sipe_core_public
*sipe_public
,
438 struct sipe_chat_session
*chat_session
)
440 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
441 sipe_chat_lock_status status
= SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED
;
444 (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
)) {
445 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
448 gchar
*self
= sip_uri_self(sipe_private
);
450 /* Only operators are allowed to change the lock status */
451 if (sipe_backend_chat_is_operator(chat_session
->backend
, self
)) {
452 status
= session
->locked
?
453 SIPE_CHAT_LOCK_STATUS_LOCKED
:
454 SIPE_CHAT_LOCK_STATUS_UNLOCKED
;
465 * Modify Conference Lock
466 * Sends request to Focus.
467 * INFO method is a carrier of application/cccp+xml
470 sipe_core_chat_modify_lock(struct sipe_core_public
*sipe_public
,
471 struct sipe_chat_session
*chat_session
,
472 const gboolean locked
)
474 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
479 struct sip_session
*session
= sipe_session_find_chat(sipe_private
,
482 if (!session
) return;
483 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
484 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
489 "Content-Type: application/cccp+xml\r\n");
491 /* @TODO put request_id to queue to further compare with incoming one */
492 self
= sip_uri_self(sipe_private
);
493 body
= g_strdup_printf(
494 SIPE_SEND_CONF_MODIFY_CONF_LOCK
,
495 session
->focus_dialog
->with
,
497 session
->request_id
++,
498 session
->focus_dialog
->with
,
499 locked
? "true" : "false");
502 sip_transport_info(sipe_private
,
505 session
->focus_dialog
,
511 /** Modify Delete User */
513 sipe_conf_delete_user(struct sipe_core_private
*sipe_private
,
514 struct sip_session
*session
,
521 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
522 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
527 "Content-Type: application/cccp+xml\r\n");
529 /* @TODO put request_id to queue to further compare with incoming one */
530 self
= sip_uri_self(sipe_private
);
531 body
= g_strdup_printf(
532 SIPE_SEND_CONF_DELETE_USER
,
533 session
->focus_dialog
->with
,
535 session
->request_id
++,
536 session
->focus_dialog
->with
,
540 sip_transport_info(sipe_private
,
543 session
->focus_dialog
,
549 /** Invite counterparty to join conference callback */
551 process_invite_conf_response(struct sipe_core_private
*sipe_private
,
553 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
555 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
557 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
558 dialog
->cseq
= sipmsg_parse_cseq(msg
);
559 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
560 sipe_dialog_parse(dialog
, msg
, TRUE
);
562 if (msg
->response
>= 200) {
563 /* send ACK to counterparty */
565 sip_transport_ack(sipe_private
, dialog
);
566 dialog
->outgoing_invite
= NULL
;
567 dialog
->is_established
= TRUE
;
570 if (msg
->response
>= 400) {
571 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
572 /* @TODO notify user of failure to invite counterparty */
573 sipe_dialog_free(dialog
);
577 if (msg
->response
>= 200) {
578 struct sip_session
*session
= sipe_session_find_im(sipe_private
, dialog
->with
);
579 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
581 /* close IM session to counterparty */
583 sip_transport_bye(sipe_private
, im_dialog
);
584 sipe_dialog_remove(session
, dialog
->with
);
588 sipe_dialog_free(dialog
);
593 * Invites counterparty to join conference.
596 sipe_invite_conf(struct sipe_core_private
*sipe_private
,
597 struct sip_session
*session
,
603 struct sip_dialog
*dialog
= NULL
;
605 /* It will be short lived special dialog.
606 * Will not be stored in session.
608 dialog
= g_new0(struct sip_dialog
, 1);
609 dialog
->callid
= gencallid();
610 dialog
->with
= g_strdup(who
);
611 dialog
->ourtag
= gentag();
613 contact
= get_contact(sipe_private
);
614 hdr
= g_strdup_printf(
615 "Supported: ms-sender\r\n"
617 "Content-Type: application/ms-conf-invite+xml\r\n",
621 body
= g_strdup_printf(
622 SIPE_SEND_CONF_INVITE
,
623 session
->chat_session
->id
,
624 session
->subject
? session
->subject
: ""
627 sip_transport_invite(sipe_private
,
631 process_invite_conf_response
);
633 sipe_dialog_free(dialog
);
638 /** Create conference callback */
640 process_conf_add_response(struct sipe_core_private
*sipe_private
,
642 struct transaction
*trans
)
644 if (msg
->response
>= 400) {
645 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
646 /* @TODO notify user of failure to create conference */
649 if (msg
->response
== 200) {
650 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
651 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
653 gchar
*who
= trans
->payload
->data
;
654 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
655 struct sip_session
*session
= sipe_conf_create(sipe_private
,
657 sipe_xml_attribute(xn_conference_info
,
660 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
661 session
->chat_session
->id
);
663 session
->pending_invite_queue
= slist_insert_unique_sorted(
664 session
->pending_invite_queue
, g_strdup(who
), (GCompareFunc
)strcmp
);
666 sipe_xml_free(xn_response
);
673 * Creates conference.
676 sipe_conf_add(struct sipe_core_private
*sipe_private
,
680 gchar
*conference_id
;
684 struct transaction
*trans
;
685 struct sip_dialog
*dialog
= NULL
;
686 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
688 struct transaction_payload
*payload
;
690 contact
= get_contact(sipe_private
);
691 hdr
= g_strdup_printf(
692 "Supported: ms-sender\r\n"
694 "Content-Type: application/cccp+xml\r\n",
698 expiry_time
= sipe_utils_time_to_str(expiry
);
699 self
= sip_uri_self(sipe_private
);
700 conference_id
= genconfid();
701 body
= g_strdup_printf(
703 sipe_private
->focus_factory_uri
,
709 g_free(conference_id
);
712 trans
= sip_transport_service(sipe_private
,
713 sipe_private
->focus_factory_uri
,
716 process_conf_add_response
);
718 payload
= g_new0(struct transaction_payload
, 1);
719 payload
->destroy
= g_free
;
720 payload
->data
= g_strdup(who
);
721 trans
->payload
= payload
;
723 sipe_dialog_free(dialog
);
729 accept_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
734 struct sip_session
*session
;
735 gchar
*newTag
= gentag();
736 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
739 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
741 sipmsg_remove_header_now(msg
, "To");
742 sipmsg_add_header_now(msg
, "To", newHeader
);
745 /* acknowledge invite */
746 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
748 /* add self to conf */
749 session
= sipe_conf_create(sipe_private
, NULL
, focus_uri
);
750 session
->is_call
= audio
;
753 struct conf_accept_ctx
{
756 struct sipe_user_ask_ctx
*ask_ctx
;
760 conf_accept_ctx_free(struct conf_accept_ctx
*ctx
)
762 g_return_if_fail(ctx
!= NULL
);
764 sipmsg_free(ctx
->msg
);
765 g_free(ctx
->focus_uri
);
770 conf_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
772 sipe_private
->sessions_to_accept
=
773 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
775 accept_incoming_invite_conf(sipe_private
, ctx
->focus_uri
, TRUE
, ctx
->msg
);
776 conf_accept_ctx_free(ctx
);
780 conf_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
782 sipe_private
->sessions_to_accept
=
783 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
785 sip_transport_response(sipe_private
,
787 603, "Decline", NULL
);
789 conf_accept_ctx_free(ctx
);
793 sipe_conf_cancel_unaccepted(struct sipe_core_private
*sipe_private
,
796 const gchar
*callid1
= msg
? sipmsg_find_header(msg
, "Call-ID") : NULL
;
797 GSList
*it
= sipe_private
->sessions_to_accept
;
799 struct conf_accept_ctx
*ctx
= it
->data
;
800 const gchar
*callid2
= NULL
;
803 callid2
= sipmsg_find_header(ctx
->msg
, "Call-ID");
805 if (sipe_strequal(callid1
, callid2
)) {
809 sip_transport_response(sipe_private
, ctx
->msg
,
810 487, "Request Terminated", NULL
);
813 sip_transport_response(sipe_private
, msg
, 200, "OK", NULL
);
815 sipe_user_close_ask(ctx
->ask_ctx
);
816 conf_accept_ctx_free(ctx
);
821 sipe_private
->sessions_to_accept
=
822 g_slist_delete_link(sipe_private
->sessions_to_accept
, tmp
);
832 ask_accept_voice_conference(struct sipe_core_private
*sipe_private
,
833 const gchar
*focus_uri
,
835 SipeUserAskCb accept_cb
,
836 SipeUserAskCb decline_cb
)
842 struct conf_accept_ctx
*ctx
;
847 novv_note
= _("\n\nAs this client was not compiled with voice call "
848 "support, if you accept, you will be able to contact "
849 "the other participants only via IM session.");
852 parts
= g_strsplit(focus_uri
, ";", 2);
853 alias
= sipe_buddy_get_alias(sipe_private
, parts
[0]);
855 ask_msg
= g_strdup_printf(_("%s wants to invite you "
856 "to the conference call%s"),
857 alias
? alias
: parts
[0], novv_note
);
862 ctx
= g_new0(struct conf_accept_ctx
, 1);
863 sipe_private
->sessions_to_accept
=
864 g_slist_append(sipe_private
->sessions_to_accept
, ctx
);
866 ctx
->focus_uri
= g_strdup(focus_uri
);
867 ctx
->msg
= msg
? sipmsg_copy(msg
) : NULL
;
868 ctx
->ask_ctx
= sipe_user_ask(sipe_private
, ask_msg
,
869 _("Accept"), accept_cb
,
870 _("Decline"), decline_cb
,
877 process_incoming_invite_conf(struct sipe_core_private
*sipe_private
,
880 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
881 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
882 const sipe_xml
*xn_audio
= sipe_xml_child(xn_conferencing
, "audio");
883 gchar
*focus_uri
= sipe_xml_data(xn_focus_uri
);
884 gboolean audio
= sipe_strequal(sipe_xml_attribute(xn_audio
, "available"), "true");
886 sipe_xml_free(xn_conferencing
);
888 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
891 sip_transport_response(sipe_private
, msg
, 180, "Ringing", NULL
);
892 ask_accept_voice_conference(sipe_private
, focus_uri
, msg
,
893 (SipeUserAskCb
) conf_accept_cb
,
894 (SipeUserAskCb
) conf_decline_cb
);
897 accept_incoming_invite_conf(sipe_private
, focus_uri
, FALSE
, msg
);
906 call_accept_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
908 struct sip_session
*session
;
909 session
= sipe_session_find_conference(sipe_private
, ctx
->focus_uri
);
911 sipe_private
->sessions_to_accept
=
912 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
915 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC
,
916 session
->chat_session
);
919 conf_accept_ctx_free(ctx
);
923 call_decline_cb(struct sipe_core_private
*sipe_private
, struct conf_accept_ctx
*ctx
)
925 sipe_private
->sessions_to_accept
=
926 g_slist_remove(sipe_private
->sessions_to_accept
, ctx
);
928 conf_accept_ctx_free(ctx
);
934 sipe_process_conference(struct sipe_core_private
*sipe_private
,
937 sipe_xml
*xn_conference_info
;
938 const sipe_xml
*node
;
939 const sipe_xml
*xn_subject
;
940 const gchar
*focus_uri
;
941 struct sip_session
*session
;
942 gboolean just_joined
= FALSE
;
944 gboolean audio_was_added
= FALSE
;
947 if (msg
->response
!= 0 && msg
->response
!= 200) return;
949 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
951 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
952 if (!xn_conference_info
) return;
954 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
955 session
= sipe_session_find_conference(sipe_private
, focus_uri
);
958 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
962 if (!session
->chat_session
->backend
) {
963 gchar
*self
= sip_uri_self(sipe_private
);
966 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
967 session
->chat_session
,
968 session
->chat_session
->title
,
971 /* @TODO ask for full state (re-subscribe) if it was a partial one -
972 * this is to obtain full list of conference participants.
978 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
979 g_free(session
->subject
);
980 session
->subject
= sipe_xml_data(xn_subject
);
981 sipe_backend_chat_topic(session
->chat_session
->backend
, session
->subject
);
982 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
986 if (!session
->im_mcu_uri
) {
987 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
989 node
= sipe_xml_twin(node
))
991 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
993 if (sipe_strequal("chat", purpose
)) {
995 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
996 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
1004 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
1005 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
1006 const gchar
*state
= sipe_xml_attribute(node
, "state");
1007 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
1008 gboolean is_operator
= sipe_strequal(role
, "presenter");
1009 gboolean is_in_im_mcu
= FALSE
;
1010 gchar
*self
= sip_uri_self(sipe_private
);
1012 if (sipe_strequal("deleted", state
)) {
1013 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1014 sipe_backend_chat_remove(session
->chat_session
->backend
,
1019 const sipe_xml
*endpoint
;
1020 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
1021 const gchar
*session_type
;
1022 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
1023 gboolean connected
= sipe_strequal("connected", status
);
1029 session_type
= sipe_xml_attribute(endpoint
, "session-type");
1031 if (sipe_strequal("chat", session_type
)) {
1032 is_in_im_mcu
= TRUE
;
1033 if (!sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1034 sipe_backend_chat_add(session
->chat_session
->backend
,
1036 !just_joined
&& g_strcasecmp(user_uri
, self
));
1039 sipe_backend_chat_operator(session
->chat_session
->backend
,
1042 } else if (sipe_strequal("audio-video", session_type
)) {
1044 if (!session
->is_call
)
1045 audio_was_added
= TRUE
;
1049 if (!is_in_im_mcu
) {
1050 if (sipe_backend_chat_find(session
->chat_session
->backend
, user_uri
)) {
1051 sipe_backend_chat_remove(session
->chat_session
->backend
,
1061 if (audio_was_added
) {
1062 session
->is_call
= TRUE
;
1063 ask_accept_voice_conference(sipe_private
, focus_uri
, NULL
,
1064 (SipeUserAskCb
) call_accept_cb
,
1065 (SipeUserAskCb
) call_decline_cb
);
1069 /* entity-view, locked */
1070 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
1072 node
= sipe_xml_twin(node
)) {
1074 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
1076 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
1077 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
1079 gchar
*locked
= sipe_xml_data(xn_locked
);
1080 gboolean prev_locked
= session
->locked
;
1081 session
->locked
= sipe_strequal(locked
, "true");
1082 if (prev_locked
&& !session
->locked
) {
1083 sipe_user_present_info(sipe_private
, session
,
1084 _("This conference is no longer locked. Additional participants can now join."));
1086 if (!prev_locked
&& session
->locked
) {
1087 sipe_user_present_info(sipe_private
, session
,
1088 _("This conference is locked. Nobody else can join the conference while it is locked."));
1091 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1092 session
->locked
? "TRUE" : "FALSE");
1098 sipe_xml_free(xn_conference_info
);
1100 if (session
->im_mcu_uri
) {
1101 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
1103 dialog
= sipe_dialog_add(session
);
1105 dialog
->callid
= g_strdup(session
->callid
);
1106 dialog
->with
= g_strdup(session
->im_mcu_uri
);
1108 /* send INVITE to IM MCU */
1109 sipe_im_invite(sipe_private
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
1113 sipe_process_pending_invite_queue(sipe_private
, session
);
1117 sipe_conf_immcu_closed(struct sipe_core_private
*sipe_private
,
1118 struct sip_session
*session
)
1120 sipe_user_present_info(sipe_private
, session
,
1121 _("You have been disconnected from this conference."));
1122 sipe_backend_chat_close(session
->chat_session
->backend
);
1126 conf_session_close(struct sipe_core_private
*sipe_private
,
1127 struct sip_session
*session
)
1130 /* unsubscribe from focus */
1131 sipe_subscribe_conference(sipe_private
, session
, TRUE
);
1133 if (session
->focus_dialog
) {
1134 /* send BYE to focus */
1135 sip_transport_bye(sipe_private
, session
->focus_dialog
);
1141 sipe_process_imdn(struct sipe_core_private
*sipe_private
,
1144 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
1145 const gchar
*callid
= sipmsg_find_header(msg
, "Call-ID");
1146 static struct sip_session
*session
;
1148 const sipe_xml
*node
;
1152 session
= sipe_session_find_chat_or_im(sipe_private
, callid
, with
);
1154 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid
);
1159 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1160 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
1162 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
1165 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
1166 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
1167 gchar
*uri
= parse_from(tmp
);
1168 sipe_user_present_message_undelivered(sipe_private
, session
, -1, -1, uri
, message
);
1173 sipe_xml_free(xn_imdn
);
1175 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
1176 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1177 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));