conf: fix focus URI search with SfB
[siplcs.git] / src / core / sipe-conf.c
blob8186c7b02ce9d56caf55f87c247469e73d343702
1 /**
2 * @file sipe-conf.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2017 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
25 /**
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>
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <stdlib.h>
39 #include <string.h>
40 #include <time.h>
42 #include <glib.h>
44 #include "sipe-common.h"
45 #include "sipmsg.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"
55 #include "sipe-im.h"
56 #include "sipe-nls.h"
57 #include "sipe-session.h"
58 #include "sipe-subscriptions.h"
59 #include "sipe-user.h"
60 #include "sipe-utils.h"
61 #include "sipe-xml.h"
63 /**
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\">"\
73 "<first-im/>"\
74 "</im>"\
75 "</Conferencing>"
77 static gboolean
78 sipe_conf_check_for_lync_url(struct sipe_core_private *sipe_private,
79 gchar *uri);
81 static struct transaction *
82 cccp_request(struct sipe_core_private *sipe_private, const gchar *method,
83 const gchar *with, struct sip_dialog *dialog,
84 TransCallback callback, const gchar *body, ...)
86 gchar *headers;
87 gchar *request;
88 gchar *request_body;
90 gchar *self = sip_uri_self(sipe_private);
92 va_list args;
94 struct transaction *trans;
96 headers = g_strdup_printf(
97 "Supported: ms-sender\r\n"
98 "Contact: %s\r\n"
99 "Content-Type: application/cccp+xml\r\n",
100 sipe_private->contact);
102 /* TODO: put request_id to queue to further compare with incoming one */
103 request = g_strdup_printf(
104 "<?xml version=\"1.0\"?>"
105 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "
106 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "
107 "C3PVersion=\"1\" "
108 "to=\"%s\" "
109 "from=\"%s\" "
110 "requestId=\"%d\">"
111 "%s"
112 "</request>",
113 with,
114 self,
115 sipe_private->cccp_request_id++,
116 body);
117 g_free(self);
119 va_start(args, body);
120 request_body = g_strdup_vprintf(request, args);
121 va_end(args);
123 g_free(request);
125 trans = sip_transport_request(sipe_private,
126 method,
127 with,
128 with,
129 headers,
130 request_body,
131 dialog,
132 callback);
134 g_free(headers);
135 g_free(request_body);
137 return trans;
140 static gboolean
141 process_conf_get_capabilities(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private,
142 struct sipmsg *msg,
143 SIPE_UNUSED_PARAMETER struct transaction *trans)
145 if (msg->response >= 400) {
146 SIPE_DEBUG_INFO_NOFORMAT("process_conf_get_capabilities: "
147 "getConferencingCapabilities failed.");
148 return FALSE;
150 if (msg->response == 200) {
151 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
152 const sipe_xml *node;
153 gchar *default_region;
155 if (!sipe_strequal("success", sipe_xml_attribute(xn_response, "code"))) {
156 return TRUE;
159 node = sipe_xml_child(xn_response, "getConferencingCapabilities/mcu-types/mcuType");
160 for (;node; node = sipe_xml_twin(node)) {
161 sipe_private->conf_mcu_types =
162 g_slist_append(sipe_private->conf_mcu_types,
163 sipe_xml_data(node));
166 g_hash_table_remove_all(sipe_private->access_numbers);
167 node = sipe_xml_child(xn_response, "getConferencingCapabilities/pstn-bridging/access-numbers/region");
168 for (;node; node = sipe_xml_twin(node)) {
169 gchar *name = g_strdup(sipe_xml_attribute(node, "name"));
170 gchar *number = sipe_xml_data(sipe_xml_child(node, "access-number/number"));
171 if (name && number) {
172 g_hash_table_insert(sipe_private->access_numbers, name, number);
176 node = sipe_xml_child(xn_response, "getConferencingCapabilities/pstn-bridging/access-numbers/default-region");
177 default_region = sipe_xml_data(node);
178 if (default_region) {
179 sipe_private->default_access_number =
180 g_hash_table_lookup(sipe_private->access_numbers, default_region);
182 g_free(default_region);
184 sipe_xml_free(xn_response);
187 return TRUE;
190 void
191 sipe_conf_get_capabilities(struct sipe_core_private *sipe_private)
193 cccp_request(sipe_private, "SERVICE",
194 sipe_private->focus_factory_uri,
195 NULL,
196 process_conf_get_capabilities,
197 "<getConferencingCapabilities />");
200 gboolean
201 sipe_conf_supports_mcu_type(struct sipe_core_private *sipe_private,
202 const gchar *type)
204 return g_slist_find_custom(sipe_private->conf_mcu_types, type,
205 sipe_strcompare) != NULL;
209 * Generates random GUID.
210 * This method is borrowed from pidgin's msnutils.c
212 static char *
213 rand_guid()
215 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
216 rand() % 0xAAFF + 0x1111,
217 rand() % 0xAAFF + 0x1111,
218 rand() % 0xAAFF + 0x1111,
219 rand() % 0xAAFF + 0x1111,
220 rand() % 0xAAFF + 0x1111,
221 rand() % 0xAAFF + 0x1111,
222 rand() % 0xAAFF + 0x1111,
223 rand() % 0xAAFF + 0x1111);
226 /** Invite us to the focus callback */
227 static gboolean
228 process_invite_conf_focus_response(struct sipe_core_private *sipe_private,
229 struct sipmsg *msg,
230 SIPE_UNUSED_PARAMETER struct transaction *trans)
232 struct sip_session *session = NULL;
233 char *focus_uri = parse_from(sipmsg_find_header(msg, "To"));
235 session = sipe_session_find_conference(sipe_private, focus_uri);
237 if (!session) {
238 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri);
239 g_free(focus_uri);
240 return FALSE;
243 if (!session->focus_dialog) {
244 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
245 g_free(focus_uri);
246 return FALSE;
249 sipe_dialog_parse(session->focus_dialog, msg, TRUE);
251 if (msg->response >= 200) {
252 /* send ACK to focus */
253 session->focus_dialog->cseq = 0;
254 sip_transport_ack(sipe_private, session->focus_dialog);
255 session->focus_dialog->outgoing_invite = NULL;
256 session->focus_dialog->is_established = TRUE;
259 if (msg->response >= 400) {
260 gchar *reason = sipmsg_get_ms_diagnostics_reason(msg);
262 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
263 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
264 _("Failed to join the conference"),
265 reason ? reason : _("no reason given"));
266 g_free(reason);
268 sipe_session_remove(sipe_private, session);
269 g_free(focus_uri);
270 return FALSE;
271 } else if (msg->response == 200) {
272 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
273 const gchar *code = sipe_xml_attribute(xn_response, "code");
274 if (sipe_strequal(code, "success")) {
275 /* subscribe to focus */
276 sipe_subscribe_conference(sipe_private,
277 session->chat_session->id,
278 FALSE);
279 #ifdef HAVE_VV
280 if (session->is_call)
281 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC,
282 session->chat_session);
283 #endif
285 sipe_xml_free(xn_response);
288 g_free(focus_uri);
289 return TRUE;
292 static gchar *
293 parse_ocs_focus_uri(const gchar *uri)
295 const gchar *confkey;
296 size_t uri_len;
298 if (!uri)
299 return NULL;
301 // URI can have this prefix if it was typed in by the user
302 if (g_str_has_prefix(uri, "meet:") || g_str_has_prefix(uri, "conf:")) {
303 uri += 5;
306 uri_len = strlen(uri);
308 if (!uri || !g_str_has_prefix(uri, "sip:") ||
309 uri_len == 4 || g_strstr_len(uri, -1, "%")) {
310 return NULL;
313 confkey = g_strstr_len(uri, -1, "?");
314 if (confkey) {
315 /* TODO: Investigate how conf-key field should be used,
316 * ignoring for now */
317 uri_len = confkey - uri;
320 return g_strndup(uri, uri_len);
323 static gchar *
324 extract_uri_from_html(const gchar *body,
325 const gchar *prefix,
326 guint prefix_skip_chars)
328 gchar *uri = NULL;
329 const gchar *start = g_strstr_len(body, -1, prefix);
331 if (start) {
332 const gchar *end;
334 start += prefix_skip_chars;
335 end = strchr(start, '"');
337 if (end) {
338 gchar *html = g_strndup(start, end - start);
340 /* decode HTML entities */
341 gchar *html_unescaped = sipe_backend_markup_strip_html(html);
342 g_free(html);
344 if (!is_empty(html_unescaped)) {
345 uri = sipe_utils_uri_unescape(html_unescaped);
348 g_free(html_unescaped);
352 return uri;
355 static void sipe_conf_lync_url_cb(struct sipe_core_private *sipe_private,
356 guint status,
357 SIPE_UNUSED_PARAMETER GSList *headers,
358 const gchar *body,
359 gpointer callback_data)
361 gchar *uri = callback_data;
363 if (status != (guint) SIPE_HTTP_STATUS_ABORTED) {
364 gchar *focus_uri = NULL;
366 if (body) {
368 * Extract focus URI from HTML, e.g.
370 * <a ... href="conf&#58;sip&#58;...ABCDEF&#37;3Frequired..." ... >
372 gchar *uri = extract_uri_from_html(body, "href=\"conf", 6);
373 focus_uri = parse_ocs_focus_uri(uri);
374 g_free(uri);
377 if (focus_uri) {
378 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: found focus URI"
379 " '%s'", focus_uri);
381 sipe_conf_create(sipe_private, NULL, focus_uri);
382 g_free(focus_uri);
383 } else {
385 * If present, domainOwnerJoinLauncherUrl redirects to
386 * a page from where we still may extract the focus URI.
388 gchar *launcher_url = NULL;
389 static const gchar *launcher_url_prefix[] = {
390 "var domainOwnerJoinLauncherUrl = \"",
391 "sb-data-domainOwnerJoinLauncherUrl=\"",
392 NULL
394 const gchar **p;
396 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: no focus URI "
397 "found from URL '%s'", uri);
399 for (p = launcher_url_prefix; !launcher_url && *p; ++p) {
400 launcher_url = extract_uri_from_html(body,
402 strlen(*p));
405 if (launcher_url &&
406 sipe_conf_check_for_lync_url(sipe_private, launcher_url)) {
407 SIPE_DEBUG_INFO("sipe_conf_lync_url_cb: retrying with URL '%s'",
408 launcher_url);
409 /* Ownership taken by sipe_conf_check_for_lync_url() */
410 launcher_url = NULL;
411 } else {
412 gchar *error;
414 error = g_strdup_printf(_("Can't find a conference URI on this page:\n\n%s"),
415 uri);
417 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
418 _("Failed to join the conference"),
419 error);
420 g_free(error);
423 g_free(launcher_url);
427 g_free(uri);
430 static gboolean sipe_conf_check_for_lync_url(struct sipe_core_private *sipe_private,
431 gchar *uri)
433 if (!(g_str_has_prefix(uri, "https://") ||
434 g_str_has_prefix(uri, "http://")))
435 return(FALSE);
437 /* URL points to a HTML page with the conference focus URI */
438 return(sipe_http_request_get(sipe_private,
439 uri,
440 NULL,
441 sipe_conf_lync_url_cb,
442 uri)
443 != NULL);
446 static void sipe_conf_uri_error(struct sipe_core_private *sipe_private,
447 const gchar *uri)
449 gchar *error = g_strdup_printf(_("\"%s\" is not a valid conference URI"),
450 uri ? uri : "");
451 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
452 _("Failed to join the conference"),
453 error);
454 g_free(error);
457 void sipe_core_conf_create(struct sipe_core_public *sipe_public,
458 const gchar *uri,
459 const gchar *organizer,
460 const gchar *meeting_id)
462 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
464 /* SIP URI or HTTP URL */
465 if (uri) {
466 gchar *uri_ue = sipe_utils_uri_unescape(uri);
468 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
469 uri,
470 uri_ue ? uri_ue : "<UNDEFINED>");
472 /* takes ownership of "uri_ue" if successful */
473 if (!sipe_conf_check_for_lync_url(sipe_private, uri_ue)) {
474 gchar *focus_uri = parse_ocs_focus_uri(uri_ue);
476 if (focus_uri) {
477 sipe_conf_create(sipe_private, NULL, focus_uri);
478 g_free(focus_uri);
479 } else
480 sipe_conf_uri_error(sipe_private, uri);
482 g_free(uri_ue);
485 /* Organizer email and meeting ID */
486 } else if (organizer && meeting_id) {
487 gchar *tmp = g_strdup_printf("sip:%s;gruu;opaque=app:conf:focus:id:%s",
488 organizer, meeting_id);
489 gchar *focus_uri = parse_ocs_focus_uri(tmp);
491 SIPE_DEBUG_INFO("sipe_core_conf_create: organizer '%s' meeting ID '%s'",
492 organizer,
493 meeting_id);
495 if (focus_uri) {
496 sipe_conf_create(sipe_private, NULL, focus_uri);
497 g_free(focus_uri);
498 } else
499 sipe_conf_uri_error(sipe_private, tmp);
500 g_free(tmp);
502 } else {
503 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
504 _("Failed to join the conference"),
505 _("Incomplete conference information provided"));
509 /** Create new session with Focus URI */
510 struct sip_session *
511 sipe_conf_create(struct sipe_core_private *sipe_private,
512 struct sipe_chat_session *chat_session,
513 const gchar *focus_uri)
515 /* addUser request to the focus.
517 * focus_URI, from, endpoint_GUID
519 static const gchar CCCP_ADD_USER[] =
520 "<addUser>"
521 "<conferenceKeys confEntity=\"%s\"/>"
522 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
523 "<ci:roles>"
524 "<ci:entry>attendee</ci:entry>"
525 "</ci:roles>"
526 "<ci:endpoint entity=\"{%s}\" "
527 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
528 "</ci:user>"
529 "</addUser>";
531 gchar *self;
532 struct sip_session *session = sipe_session_add_chat(sipe_private,
533 chat_session,
534 FALSE,
535 focus_uri);
537 session->focus_dialog = g_new0(struct sip_dialog, 1);
538 session->focus_dialog->callid = gencallid();
539 session->focus_dialog->with = g_strdup(session->chat_session->id);
540 session->focus_dialog->endpoint_GUID = rand_guid();
541 session->focus_dialog->ourtag = gentag();
543 self = sip_uri_self(sipe_private);
544 session->focus_dialog->outgoing_invite =
545 cccp_request(sipe_private, "INVITE",
546 session->focus_dialog->with, session->focus_dialog,
547 process_invite_conf_focus_response,
548 CCCP_ADD_USER,
549 session->focus_dialog->with, self,
550 session->focus_dialog->endpoint_GUID);
552 /* Rejoin existing session? */
553 if (chat_session) {
554 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
555 chat_session->title,
556 chat_session->id);
557 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC,
558 chat_session->backend,
559 self,
560 chat_session->title);
562 g_free(self);
564 return(session);
567 /** Modify User Role */
568 void
569 sipe_conf_modify_user_role(struct sipe_core_private *sipe_private,
570 struct sip_session *session,
571 const gchar* who)
573 /* modifyUserRoles request to the focus. Makes user a leader.
575 * focus_uri (%s)
576 * who (%s)
578 static const gchar CCCP_MODIFY_USER_ROLES[] =
579 "<modifyUserRoles>"
580 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
581 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
582 "<entry>presenter</entry>"
583 "</user-roles>"
584 "</modifyUserRoles>";
586 if (!session->focus_dialog || !session->focus_dialog->is_established) {
587 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
588 return;
591 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
592 session->focus_dialog, NULL,
593 CCCP_MODIFY_USER_ROLES,
594 session->focus_dialog->with, who);
598 * Check conference lock status
600 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
601 struct sipe_chat_session *chat_session)
603 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
604 sipe_chat_lock_status status = SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED;
606 if (chat_session &&
607 (chat_session->type == SIPE_CHAT_TYPE_CONFERENCE)) {
608 struct sip_session *session = sipe_session_find_chat(sipe_private,
609 chat_session);
610 if (session) {
611 gchar *self = sip_uri_self(sipe_private);
613 /* Only operators are allowed to change the lock status */
614 if (sipe_backend_chat_is_operator(chat_session->backend, self)) {
615 status = session->locked ?
616 SIPE_CHAT_LOCK_STATUS_LOCKED :
617 SIPE_CHAT_LOCK_STATUS_UNLOCKED;
620 g_free(self);
624 return(status);
628 * Modify Conference Lock
629 * Sends request to Focus.
630 * INFO method is a carrier of application/cccp+xml
632 void
633 sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
634 struct sipe_chat_session *chat_session,
635 const gboolean locked)
637 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
639 * focus_uri (%s)
640 * locked (%s) "true" or "false" values applicable
642 static const gchar CCCP_MODIFY_CONFERENCE_LOCK[] =
643 "<modifyConferenceLock>"
644 "<conferenceKeys confEntity=\"%s\"/>"
645 "<locked>%s</locked>"
646 "</modifyConferenceLock>";
648 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
650 struct sip_session *session = sipe_session_find_chat(sipe_private,
651 chat_session);
653 if (!session) return;
654 if (!session->focus_dialog || !session->focus_dialog->is_established) {
655 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
656 return;
659 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
660 session->focus_dialog, NULL,
661 CCCP_MODIFY_CONFERENCE_LOCK,
662 session->focus_dialog->with,
663 locked ? "true" : "false");
666 /** Modify Delete User */
667 void
668 sipe_conf_delete_user(struct sipe_core_private *sipe_private,
669 struct sip_session *session,
670 const gchar* who)
672 /* deleteUser request to the focus. Removes a user from the conference.
674 * focus_uri (%s)
675 * who (%s)
677 static const gchar CCCP_DELETE_USER[] =
678 "<deleteUser>"
679 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
680 "</deleteUser>";
682 if (!session->focus_dialog || !session->focus_dialog->is_established) {
683 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
684 return;
687 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
688 session->focus_dialog, NULL,
689 CCCP_DELETE_USER,
690 session->focus_dialog->with, who);
693 void
694 sipe_conf_announce_audio_mute_state(struct sipe_core_private *sipe_private,
695 struct sip_session *session,
696 gboolean is_muted)
698 // See [MS-CONFAV] 3.2.5.4 and 4.3
699 static const gchar CCCP_MODIFY_ENDPOINT_MEDIA[] =
700 "<modifyEndpointMedia mscp:mcuUri=\"%s\""
701 " xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\">"
702 "<mediaKeys confEntity=\"%s\" userEntity=\"%s\""
703 " endpointEntity=\"%s\" mediaId=\"%d\"/>"
704 "<ci:media"
705 " xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" id=\"%d\">"
706 "<ci:type>audio</ci:type>"
707 "<ci:status>%s</ci:status>"
708 "<media-ingress-filter"
709 " xmlns=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
710 "%s"
711 "</media-ingress-filter>"
712 "</ci:media>"
713 "</modifyEndpointMedia>";
715 gchar *mcu_uri = sipe_conf_build_uri(session->focus_dialog->with,
716 "audio-video");
717 gchar *self = sip_uri_self(sipe_private);
719 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
720 session->focus_dialog, NULL,
721 CCCP_MODIFY_ENDPOINT_MEDIA,
722 mcu_uri, session->focus_dialog->with, self,
723 session->audio_video_entity,
724 session->audio_media_id, session->audio_media_id,
725 is_muted ? "recvonly" : "sendrecv",
726 is_muted ? "block" : "unblock");
728 g_free(mcu_uri);
729 g_free(self);
732 /** Invite counterparty to join conference callback */
733 static gboolean
734 process_invite_conf_response(struct sipe_core_private *sipe_private,
735 struct sipmsg *msg,
736 SIPE_UNUSED_PARAMETER struct transaction *trans)
738 struct sip_dialog *dialog = g_new0(struct sip_dialog, 1);
740 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
741 dialog->cseq = sipmsg_parse_cseq(msg);
742 dialog->with = parse_from(sipmsg_find_header(msg, "To"));
743 sipe_dialog_parse(dialog, msg, TRUE);
745 if (msg->response >= 200) {
746 /* send ACK to counterparty */
747 dialog->cseq--;
748 sip_transport_ack(sipe_private, dialog);
749 dialog->outgoing_invite = NULL;
750 dialog->is_established = TRUE;
753 if (msg->response >= 400) {
754 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog->with);
755 /* @TODO notify user of failure to invite counterparty */
756 sipe_dialog_free(dialog);
757 return FALSE;
760 if (msg->response >= 200) {
761 struct sip_session *session = sipe_session_find_im(sipe_private, dialog->with);
762 struct sip_dialog *im_dialog = sipe_dialog_find(session, dialog->with);
764 /* close IM session to counterparty */
765 if (im_dialog) {
766 sip_transport_bye(sipe_private, im_dialog);
767 sipe_dialog_remove(session, dialog->with);
771 sipe_dialog_free(dialog);
772 return TRUE;
776 * Invites counterparty to join conference.
778 void
779 sipe_invite_conf(struct sipe_core_private *sipe_private,
780 struct sip_session *session,
781 const gchar* who)
783 gchar *hdr;
784 gchar *contact;
785 gchar *body;
786 struct sip_dialog *dialog = NULL;
788 /* It will be short lived special dialog.
789 * Will not be stored in session.
791 dialog = g_new0(struct sip_dialog, 1);
792 dialog->callid = gencallid();
793 dialog->with = g_strdup(who);
794 dialog->ourtag = gentag();
796 contact = get_contact(sipe_private);
797 hdr = g_strdup_printf(
798 "Supported: ms-sender\r\n"
799 "Contact: %s\r\n"
800 "Content-Type: application/ms-conf-invite+xml\r\n",
801 contact);
802 g_free(contact);
804 body = g_strdup_printf(
805 SIPE_SEND_CONF_INVITE,
806 session->chat_session->id,
807 session->subject ? session->subject : ""
810 sip_transport_invite(sipe_private,
811 hdr,
812 body,
813 dialog,
814 process_invite_conf_response);
816 sipe_dialog_free(dialog);
817 g_free(body);
818 g_free(hdr);
821 /** Create conference callback */
822 static gboolean
823 process_conf_add_response(struct sipe_core_private *sipe_private,
824 struct sipmsg *msg,
825 struct transaction *trans)
827 if (msg->response >= 400) {
828 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
829 /* @TODO notify user of failure to create conference */
830 return FALSE;
832 if (msg->response == 200) {
833 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
834 if (sipe_strequal("success", sipe_xml_attribute(xn_response, "code")))
836 gchar *who = trans->payload->data;
837 const sipe_xml *xn_conference_info = sipe_xml_child(xn_response, "addConference/conference-info");
838 struct sip_session *session = sipe_conf_create(sipe_private,
839 NULL,
840 sipe_xml_attribute(xn_conference_info,
841 "entity"));
843 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
844 session->chat_session->id);
846 session->pending_invite_queue = sipe_utils_slist_insert_unique_sorted(session->pending_invite_queue,
847 g_strdup(who),
848 (GCompareFunc)strcmp,
849 g_free);
851 sipe_xml_free(xn_response);
854 return TRUE;
858 * Creates conference.
860 void
861 sipe_conf_add(struct sipe_core_private *sipe_private,
862 const gchar* who)
864 gchar *conference_id;
865 struct transaction *trans;
866 time_t expiry = time(NULL) + 7*60*60; /* 7 hours */
867 char *expiry_time;
869 /* addConference request to the focus factory.
871 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
872 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
873 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
875 static const gchar CCCP_ADD_CONFERENCE[] =
876 "<addConference>"
877 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
878 "entity=\"\" "
879 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
880 "<ci:conference-description>"
881 "<ci:subject/>"
882 "<msci:conference-id>%s</msci:conference-id>"
883 "<msci:expiry-time>%s</msci:expiry-time>"
884 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
885 "</ci:conference-description>"
886 "<msci:conference-view>%s</msci:conference-view>"
887 "</ci:conference-info>"
888 "</addConference>";
890 static const gchar *DESIRED_MCU_TYPES[] = {
891 "chat",
892 #ifdef HAVE_VV
893 "audio-video",
894 #endif
895 #ifdef HAVE_APPSHARE
896 "applicationsharing",
897 #endif
898 NULL
901 GString *conference_view = g_string_new("");
902 const gchar **type;
904 for (type = DESIRED_MCU_TYPES; *type; ++type ) {
905 if (sipe_conf_supports_mcu_type(sipe_private, *type)) {
906 g_string_append(conference_view, "<msci:entity-view entity=\"");
907 g_string_append(conference_view, *type);
908 g_string_append(conference_view, "\"/>");
912 expiry_time = sipe_utils_time_to_str(expiry);
913 conference_id = genconfid();
914 trans = cccp_request(sipe_private, "SERVICE", sipe_private->focus_factory_uri,
915 NULL, process_conf_add_response,
916 CCCP_ADD_CONFERENCE,
917 conference_id, expiry_time, conference_view->str);
918 g_free(conference_id);
919 g_free(expiry_time);
920 g_string_free(conference_view, TRUE);
922 if (trans) {
923 struct transaction_payload *payload = g_new0(struct transaction_payload, 1);
925 payload->destroy = g_free;
926 payload->data = g_strdup(who);
927 trans->payload = payload;
931 static void
932 accept_incoming_invite_conf(struct sipe_core_private *sipe_private,
933 gchar *focus_uri,
934 gboolean audio,
935 struct sipmsg *msg)
937 struct sip_session *session;
938 gchar *newTag = gentag();
939 const gchar *oldHeader = sipmsg_find_header(msg, "To");
940 gchar *newHeader;
942 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
943 g_free(newTag);
944 sipmsg_remove_header_now(msg, "To");
945 sipmsg_add_header_now(msg, "To", newHeader);
946 g_free(newHeader);
948 /* acknowledge invite */
949 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
951 /* add self to conf */
952 session = sipe_conf_create(sipe_private, NULL, focus_uri);
953 session->is_call = audio;
956 struct conf_accept_ctx {
957 gchar *focus_uri;
958 struct sipmsg *msg;
959 struct sipe_user_ask_ctx *ask_ctx;
961 SipeUserAskCb accept_cb;
962 SipeUserAskCb decline_cb;
964 gpointer user_data;
967 static void
968 conf_accept_ctx_free(struct conf_accept_ctx *ctx)
970 g_return_if_fail(ctx != NULL);
972 sipmsg_free(ctx->msg);
973 g_free(ctx->focus_uri);
974 g_free(ctx);
977 static void
978 conf_accept_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
980 accept_incoming_invite_conf(sipe_private, ctx->focus_uri, TRUE, ctx->msg);
983 static void
984 conf_decline_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
986 sip_transport_response(sipe_private,
987 ctx->msg,
988 603, "Decline", NULL);
991 void
992 sipe_conf_cancel_unaccepted(struct sipe_core_private *sipe_private,
993 struct sipmsg *msg)
995 const gchar *callid1 = msg ? sipmsg_find_header(msg, "Call-ID") : NULL;
996 GSList *it = sipe_private->sessions_to_accept;
997 while (it) {
998 struct conf_accept_ctx *ctx = it->data;
999 const gchar *callid2 = NULL;
1001 if (msg && ctx->msg)
1002 callid2 = sipmsg_find_header(ctx->msg, "Call-ID");
1004 if (sipe_strequal(callid1, callid2)) {
1005 GSList *tmp;
1007 if (ctx->msg)
1008 sip_transport_response(sipe_private, ctx->msg,
1009 487, "Request Terminated", NULL);
1011 if (msg)
1012 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1014 sipe_user_close_ask(ctx->ask_ctx);
1015 conf_accept_ctx_free(ctx);
1017 tmp = it;
1018 it = it->next;
1020 sipe_private->sessions_to_accept =
1021 g_slist_delete_link(sipe_private->sessions_to_accept, tmp);
1023 if (callid1)
1024 break;
1025 } else
1026 it = it->next;
1030 static void
1031 accept_invitation_cb(struct sipe_core_private *sipe_private, gpointer data)
1033 struct conf_accept_ctx *ctx = data;
1035 sipe_private->sessions_to_accept =
1036 g_slist_remove(sipe_private->sessions_to_accept, ctx);
1038 if (ctx->accept_cb) {
1039 ctx->accept_cb(sipe_private, ctx);
1042 conf_accept_ctx_free(ctx);
1045 static void
1046 decline_invitation_cb(struct sipe_core_private *sipe_private, gpointer data)
1048 struct conf_accept_ctx *ctx = data;
1050 sipe_private->sessions_to_accept =
1051 g_slist_remove(sipe_private->sessions_to_accept, ctx);
1053 if (ctx->decline_cb) {
1054 ctx->decline_cb(sipe_private, ctx);
1057 conf_accept_ctx_free(ctx);
1060 static void
1061 ask_accept_invitation(struct sipe_core_private *sipe_private,
1062 const gchar *focus_uri,
1063 const gchar *question,
1064 struct sipmsg *msg,
1065 SipeUserAskCb accept_cb,
1066 SipeUserAskCb decline_cb,
1067 gpointer user_data)
1069 gchar **parts;
1070 gchar *alias;
1071 gchar *question_str;
1072 struct conf_accept_ctx *ctx;
1074 parts = g_strsplit(focus_uri, ";", 2);
1075 alias = sipe_buddy_get_alias(sipe_private, parts[0]);
1077 question_str = g_strdup_printf("%s %s", alias ? alias : parts[0], question);
1079 g_free(alias);
1080 g_strfreev(parts);
1082 ctx = g_new0(struct conf_accept_ctx, 1);
1083 sipe_private->sessions_to_accept =
1084 g_slist_append(sipe_private->sessions_to_accept, ctx);
1086 ctx->focus_uri = g_strdup(focus_uri);
1087 ctx->msg = msg ? sipmsg_copy(msg) : NULL;
1088 ctx->accept_cb = accept_cb;
1089 ctx->decline_cb = decline_cb;
1090 ctx->user_data = user_data;
1091 ctx->ask_ctx = sipe_user_ask(sipe_private, question_str,
1092 _("Accept"), accept_invitation_cb,
1093 _("Decline"), decline_invitation_cb,
1094 ctx);
1096 g_free(question_str);
1099 static void
1100 ask_accept_voice_conference(struct sipe_core_private *sipe_private,
1101 const gchar *focus_uri,
1102 struct sipmsg *msg,
1103 SipeUserAskCb accept_cb,
1104 SipeUserAskCb decline_cb)
1106 gchar *question;
1107 const gchar *novv_note;
1109 #ifdef HAVE_VV
1110 novv_note = "";
1111 #else
1112 novv_note = _("\n\nAs this client was not compiled with voice call "
1113 "support, if you accept, you will be able to contact "
1114 "the other participants only via IM session.");
1115 #endif
1117 question = g_strdup_printf(_("wants to invite you "
1118 "to a conference call%s"), novv_note);
1120 ask_accept_invitation(sipe_private, focus_uri, question, msg,
1121 accept_cb, decline_cb, NULL);
1123 g_free(question);
1126 void
1127 process_incoming_invite_conf(struct sipe_core_private *sipe_private,
1128 struct sipmsg *msg)
1130 sipe_xml *xn_conferencing = sipe_xml_parse(msg->body, msg->bodylen);
1131 const sipe_xml *xn_focus_uri = sipe_xml_child(xn_conferencing, "focus-uri");
1132 const sipe_xml *xn_audio = sipe_xml_child(xn_conferencing, "audio");
1133 gchar *focus_uri = sipe_xml_data(xn_focus_uri);
1134 gboolean audio = sipe_strequal(sipe_xml_attribute(xn_audio, "available"), "true");
1136 sipe_xml_free(xn_conferencing);
1138 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri);
1140 if (audio) {
1141 sip_transport_response(sipe_private, msg, 180, "Ringing", NULL);
1142 ask_accept_voice_conference(sipe_private, focus_uri, msg,
1143 (SipeUserAskCb) conf_accept_cb,
1144 (SipeUserAskCb) conf_decline_cb);
1146 } else {
1147 accept_incoming_invite_conf(sipe_private, focus_uri, FALSE, msg);
1150 g_free(focus_uri);
1153 #ifdef HAVE_VV
1155 static void
1156 process_conference_av_endpoint(const sipe_xml *endpoint,
1157 const gchar *user_uri,
1158 const gchar *self_uri,
1159 struct sip_session *session)
1161 const sipe_xml *media;
1162 const gchar *new_entity;
1164 if (!sipe_strequal(user_uri, self_uri)) {
1165 /* We are interested only in our own endpoint data. */
1166 return;
1169 new_entity = sipe_xml_attribute(endpoint, "entity");
1170 if (!sipe_strequal(session->audio_video_entity, new_entity)) {
1171 g_free(session->audio_video_entity);
1172 session->audio_video_entity = g_strdup(new_entity);
1175 session->audio_media_id = 0;
1177 media = sipe_xml_child(endpoint, "media");
1178 for (; media; media = sipe_xml_twin(media)) {
1179 gchar *type = sipe_xml_data(sipe_xml_child(media, "type"));
1181 if (sipe_strequal(type, "audio")) {
1182 session->audio_media_id =
1183 sipe_xml_int_attribute(media, "id", 0);
1186 g_free(type);
1188 if (session->audio_media_id != 0) {
1189 break;
1194 static void
1195 call_accept_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
1197 struct sip_session *session;
1198 session = sipe_session_find_conference(sipe_private, ctx->focus_uri);
1200 if (session) {
1201 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC,
1202 session->chat_session);
1206 #ifdef HAVE_APPSHARE
1207 gboolean
1208 sipe_core_conf_is_viewing_appshare(struct sipe_core_public *sipe_public,
1209 struct sipe_chat_session *chat_session)
1211 if (chat_session) {
1212 gchar *mcu_uri;
1213 GList *calls;
1215 mcu_uri = sipe_conf_build_uri(chat_session->id, "applicationsharing");
1216 calls = g_hash_table_get_values(SIPE_CORE_PRIVATE->media_calls);
1218 for (; calls; calls = g_list_delete_link(calls, calls)) {
1219 struct sipe_media_call *call = calls->data;
1220 if (sipe_strequal(call->with, mcu_uri)) {
1221 break;
1225 g_free(mcu_uri);
1227 if (calls != NULL) {
1228 g_list_free(calls);
1229 return TRUE;
1233 return FALSE;
1236 static gboolean
1237 process_conference_appshare_endpoint(const sipe_xml *endpoint)
1239 gboolean presentation_added = FALSE;
1240 const sipe_xml *media;
1242 for (media = sipe_xml_child(endpoint, "media");
1243 media && !presentation_added;
1244 media = sipe_xml_twin(media)) {
1245 gchar *type;
1246 gchar *media_state;
1247 gchar *status;
1249 type = sipe_xml_data(sipe_xml_child(media, "type"));
1250 media_state = sipe_xml_data(sipe_xml_child(media, "media-state"));
1251 status = sipe_xml_data(sipe_xml_child(media, "status"));
1253 if (sipe_strequal(type, "applicationsharing") &&
1254 sipe_strequal(media_state, "connected") &&
1255 sipe_strequal(status, "sendonly")) {
1256 presentation_added = TRUE;
1259 g_free(type);
1260 g_free(media_state);
1261 g_free(status);
1264 return(presentation_added);
1266 #endif // HAVE_APPSHARE
1267 #endif // HAVE_VV
1269 void
1270 sipe_process_conference(struct sipe_core_private *sipe_private,
1271 struct sipmsg *msg)
1273 sipe_xml *xn_conference_info;
1274 const sipe_xml *node;
1275 const sipe_xml *xn_subject;
1276 const gchar *focus_uri;
1277 struct sip_session *session;
1278 gboolean just_joined = FALSE;
1279 #ifdef HAVE_VV
1280 gboolean audio_was_added = FALSE;
1281 #ifdef HAVE_APPSHARE
1282 gboolean presentation_was_added = FALSE;
1283 #endif
1284 #endif // HAVE_VV
1286 if (msg->response != 0 && msg->response != 200) return;
1288 if (msg->bodylen == 0 || msg->body == NULL || !sipe_strequal(sipmsg_find_header(msg, "Event"), "conference")) return;
1290 xn_conference_info = sipe_xml_parse(msg->body, msg->bodylen);
1291 if (!xn_conference_info) return;
1293 focus_uri = sipe_xml_attribute(xn_conference_info, "entity");
1294 session = sipe_session_find_conference(sipe_private, focus_uri);
1296 if (!session) {
1297 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri);
1298 return;
1301 if (!session->chat_session->backend) {
1302 gchar *self = sip_uri_self(sipe_private);
1304 /* create chat */
1305 session->chat_session->backend = sipe_backend_chat_create(SIPE_CORE_PUBLIC,
1306 session->chat_session,
1307 session->chat_session->title,
1308 self);
1309 just_joined = TRUE;
1310 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1311 * this is to obtain full list of conference participants.
1313 g_free(self);
1316 /* subject */
1317 if ((xn_subject = sipe_xml_child(xn_conference_info, "conference-description/subject"))) {
1318 g_free(session->subject);
1319 session->subject = sipe_xml_data(xn_subject);
1320 sipe_backend_chat_topic(session->chat_session->backend, session->subject);
1321 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session->subject ? session->subject : "");
1324 /* IM MCU URI */
1325 if (!session->im_mcu_uri) {
1326 for (node = sipe_xml_child(xn_conference_info, "conference-description/conf-uris/entry");
1327 node;
1328 node = sipe_xml_twin(node))
1330 gchar *purpose = sipe_xml_data(sipe_xml_child(node, "purpose"));
1332 if (sipe_strequal("chat", purpose)) {
1333 g_free(purpose);
1334 session->im_mcu_uri = sipe_xml_data(sipe_xml_child(node, "uri"));
1335 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session->im_mcu_uri);
1336 break;
1338 g_free(purpose);
1342 /* organizer */
1343 if (!session->chat_session->organizer) {
1344 node = sipe_xml_child(xn_conference_info, "conference-description/organizer/display-name");
1345 if (node) {
1346 session->chat_session->organizer = sipe_xml_data(node);
1350 /* join URL */
1351 if (!session->chat_session->join_url) {
1352 node = sipe_xml_child(xn_conference_info, "conference-description/join-url");
1353 if (node) {
1354 session->chat_session->join_url = sipe_xml_data(node);
1358 /* dial-in conference id */
1359 if (!session->chat_session->dial_in_conf_id) {
1360 node = sipe_xml_child(xn_conference_info, "conference-description/pstn-access/id");
1361 if (node) {
1362 session->chat_session->dial_in_conf_id = sipe_xml_data(node);
1366 /* users */
1367 for (node = sipe_xml_child(xn_conference_info, "users/user"); node; node = sipe_xml_twin(node)) {
1368 const gchar *user_uri = sipe_xml_attribute(node, "entity");
1369 const gchar *state = sipe_xml_attribute(node, "state");
1370 gchar *role = sipe_xml_data(sipe_xml_child(node, "roles/entry"));
1371 gboolean is_operator = sipe_strequal(role, "presenter");
1372 gboolean is_in_im_mcu = FALSE;
1373 gchar *self = sip_uri_self(sipe_private);
1375 if (sipe_strequal("deleted", state)) {
1376 if (sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1377 sipe_backend_chat_remove(session->chat_session->backend,
1378 user_uri);
1380 } else {
1381 /* endpoints */
1382 const sipe_xml *endpoint;
1383 for (endpoint = sipe_xml_child(node, "endpoint"); endpoint; endpoint = sipe_xml_twin(endpoint)) {
1384 const gchar *session_type;
1385 gchar *status = sipe_xml_data(sipe_xml_child(endpoint, "status"));
1386 gboolean connected = sipe_strequal("connected", status);
1387 g_free(status);
1389 if (!connected)
1390 continue;
1392 session_type = sipe_xml_attribute(endpoint, "session-type");
1394 if (sipe_strequal("chat", session_type)) {
1395 is_in_im_mcu = TRUE;
1396 if (!sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1397 sipe_backend_chat_add(session->chat_session->backend,
1398 user_uri,
1399 !just_joined && g_ascii_strcasecmp(user_uri, self));
1401 if (is_operator) {
1402 sipe_backend_chat_operator(session->chat_session->backend,
1403 user_uri);
1405 } else if (sipe_strequal("audio-video", session_type)) {
1406 #ifdef HAVE_VV
1407 if (!session->is_call)
1408 audio_was_added = TRUE;
1409 process_conference_av_endpoint(endpoint,
1410 user_uri,
1411 self,
1412 session);
1413 #endif
1414 } else if (sipe_strequal("applicationsharing", session_type)) {
1415 #ifdef HAVE_APPSHARE
1416 if (!sipe_core_conf_is_viewing_appshare(SIPE_CORE_PUBLIC,
1417 session->chat_session)) {
1418 presentation_was_added = process_conference_appshare_endpoint(endpoint);
1420 #endif
1423 if (!is_in_im_mcu) {
1424 if (sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1425 sipe_backend_chat_remove(session->chat_session->backend,
1426 user_uri);
1430 g_free(role);
1431 g_free(self);
1434 #ifdef HAVE_VV
1435 if (audio_was_added) {
1436 session->is_call = TRUE;
1437 ask_accept_voice_conference(sipe_private, focus_uri, NULL,
1438 (SipeUserAskCb) call_accept_cb,
1439 NULL);
1441 #ifdef HAVE_APPSHARE
1442 if (presentation_was_added) {
1443 sipe_core_appshare_connect_conference(SIPE_CORE_PUBLIC,
1444 session->chat_session,
1445 TRUE);
1447 #endif
1448 #endif // HAVE_VV
1450 /* entity-view, locked */
1451 for (node = sipe_xml_child(xn_conference_info, "conference-view/entity-view");
1452 node;
1453 node = sipe_xml_twin(node)) {
1455 const sipe_xml *xn_type = sipe_xml_child(node, "entity-state/media/entry/type");
1456 gchar *tmp = NULL;
1457 if (xn_type && sipe_strequal("chat", (tmp = sipe_xml_data(xn_type)))) {
1458 const sipe_xml *xn_locked = sipe_xml_child(node, "entity-state/locked");
1459 if (xn_locked) {
1460 gchar *locked = sipe_xml_data(xn_locked);
1461 gboolean prev_locked = session->locked;
1462 session->locked = sipe_strequal(locked, "true");
1463 if (prev_locked && !session->locked) {
1464 sipe_user_present_info(sipe_private, session,
1465 _("This conference is no longer locked. Additional participants can now join."));
1467 if (!prev_locked && session->locked) {
1468 sipe_user_present_info(sipe_private, session,
1469 _("This conference is locked. Nobody else can join the conference while it is locked."));
1472 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1473 session->locked ? "TRUE" : "FALSE");
1474 g_free(locked);
1477 g_free(tmp);
1479 sipe_xml_free(xn_conference_info);
1481 if (session->im_mcu_uri) {
1482 struct sip_dialog *dialog = sipe_dialog_find(session, session->im_mcu_uri);
1483 if (!dialog) {
1484 dialog = sipe_dialog_add(session);
1486 dialog->callid = g_strdup(session->callid);
1487 dialog->with = g_strdup(session->im_mcu_uri);
1489 /* send INVITE to IM MCU */
1490 sipe_im_invite(sipe_private, session, dialog->with, NULL, NULL, NULL, FALSE);
1494 sipe_process_pending_invite_queue(sipe_private, session);
1497 void
1498 sipe_conf_immcu_closed(struct sipe_core_private *sipe_private,
1499 struct sip_session *session)
1501 sipe_user_present_info(sipe_private, session,
1502 _("You have been disconnected from this conference."));
1503 sipe_backend_chat_close(session->chat_session->backend);
1506 void
1507 conf_session_close(struct sipe_core_private *sipe_private,
1508 struct sip_session *session)
1510 if (session) {
1511 /* unsubscribe from focus */
1512 sipe_subscribe_conference(sipe_private,
1513 session->chat_session->id, TRUE);
1515 if (session->focus_dialog) {
1516 /* send BYE to focus */
1517 sip_transport_bye(sipe_private, session->focus_dialog);
1522 void
1523 sipe_process_imdn(struct sipe_core_private *sipe_private,
1524 struct sipmsg *msg)
1526 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
1527 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1528 static struct sip_session *session;
1529 sipe_xml *xn_imdn;
1530 const sipe_xml *node;
1531 gchar *message_id;
1532 gchar *message;
1534 session = sipe_session_find_chat_or_im(sipe_private, callid, with);
1535 if (!session) {
1536 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid);
1537 g_free(with);
1538 return;
1541 xn_imdn = sipe_xml_parse(msg->body, msg->bodylen);
1542 message_id = sipe_xml_data(sipe_xml_child(xn_imdn, "message-id"));
1544 message = g_hash_table_lookup(session->conf_unconfirmed_messages, message_id);
1546 /* recipient */
1547 for (node = sipe_xml_child(xn_imdn, "recipient"); node; node = sipe_xml_twin(node)) {
1548 gchar *tmp = parse_from(sipe_xml_attribute(node, "uri"));
1549 gchar *uri = parse_from(tmp);
1550 gchar *status = sipe_xml_data(sipe_xml_child(node, "status"));
1551 guint error = status ? g_ascii_strtoull(status, NULL, 10) : 0;
1552 /* default to error if missing or conversion failed */
1553 if ((error == 0) || (error >= 300))
1554 sipe_user_present_message_undelivered(sipe_private,
1555 session,
1556 error,
1558 uri,
1559 message);
1560 g_free(status);
1561 g_free(tmp);
1562 g_free(uri);
1565 sipe_xml_free(xn_imdn);
1567 g_hash_table_remove(session->conf_unconfirmed_messages, message_id);
1568 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1569 message_id, g_hash_table_size(session->conf_unconfirmed_messages));
1570 g_free(message_id);
1571 g_free(with);
1574 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
1575 gpointer parameter,
1576 const gchar *buddy_name)
1578 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1579 struct sipe_chat_session *chat_session = parameter;
1580 struct sip_session *session;
1582 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1583 chat_session->title);
1585 session = sipe_session_find_chat(sipe_private, chat_session);
1586 sipe_conf_modify_user_role(sipe_private, session, buddy_name);
1589 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
1590 gpointer parameter,
1591 const gchar *buddy_name)
1593 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1594 struct sipe_chat_session *chat_session = parameter;
1595 struct sip_session *session;
1597 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1598 chat_session->title);
1600 session = sipe_session_find_chat(sipe_private, chat_session);
1601 sipe_conf_delete_user(sipe_private, session, buddy_name);
1604 gchar *
1605 sipe_conf_build_uri(const gchar *focus_uri, const gchar *session_type)
1607 gchar **parts = g_strsplit(focus_uri, ":focus:", 2);
1608 gchar *result = NULL;
1610 if (g_strv_length(parts) == 2) {
1611 result = g_strconcat(parts[0], ":", session_type, ":", parts[1],
1612 NULL);
1615 g_strfreev(parts);
1616 return result;
1619 static gchar *
1620 access_numbers_info(struct sipe_core_public *sipe_public)
1622 GString *result = g_string_new("");
1624 #if GLIB_CHECK_VERSION(2,16,0)
1625 GList *keys = g_hash_table_get_keys(SIPE_CORE_PRIVATE->access_numbers);
1626 keys = g_list_sort(keys, (GCompareFunc)g_strcmp0);
1628 for (; keys; keys = g_list_delete_link(keys, keys)) {
1629 gchar *value;
1630 value = g_hash_table_lookup(SIPE_CORE_PRIVATE->access_numbers,
1631 keys->data);
1633 g_string_append(result, keys->data);
1634 g_string_append(result, "&nbsp;&nbsp;&nbsp;&nbsp;");
1635 g_string_append(result, value);
1636 g_string_append(result, "<br/>");
1638 #else
1639 (void)sipe_public; /* keep compiler happy */
1640 #endif
1642 return g_string_free(result, FALSE);
1645 gchar *
1646 sipe_core_conf_entry_info(struct sipe_core_public *sipe_public,
1647 struct sipe_chat_session *chat_session)
1649 gchar *access_info = access_numbers_info(sipe_public);
1650 gchar *result = g_strdup_printf(
1651 "<b><font size=\"+1\">%s</font></b><br/>"
1652 "<b>%s:</b> %s<br/>"
1653 "<b>%s:</b> %s<br/>"
1654 "<br/>"
1655 "<b>%s:</b><br/>"
1656 "%s<br/>"
1657 "<br/>"
1658 "<b>%s:</b> %s<br/>"
1659 "<br/>"
1660 "<b><font size=\"+1\">%s</font></b><br/>"
1661 "%s",
1662 _("Dial-in info"),
1663 _("Number"),
1664 SIPE_CORE_PRIVATE->default_access_number ? SIPE_CORE_PRIVATE->default_access_number : "",
1665 _("Conference ID"),
1666 chat_session->dial_in_conf_id ? chat_session->dial_in_conf_id : "",
1667 _("Meeting link"),
1668 chat_session->join_url ? chat_session->join_url : "",
1669 _("Organizer"),
1670 chat_session->organizer ? chat_session->organizer : "",
1671 _("Alternative dial-in numbers"),
1672 access_info);
1674 g_free(access_info);
1676 return result;
1680 Local Variables:
1681 mode: c
1682 c-file-style: "bsd"
1683 indent-tabs-mode: t
1684 tab-width: 8
1685 End: