lync: add missing _ready() call for HTTP requests
[siplcs.git] / src / core / sipe-conf.c
blob6056da1978ff95c8ca77a3a9766c8dcb9d1ab89d
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 (GCompareFunc)g_strcmp0) != 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 struct sipe_http_request *request;
435 if (!(g_str_has_prefix(uri, "https://") ||
436 g_str_has_prefix(uri, "http://")))
437 return(FALSE);
439 /* URL points to a HTML page with the conference focus URI */
440 request = sipe_http_request_get(sipe_private,
441 uri,
442 NULL,
443 sipe_conf_lync_url_cb,
444 uri);
446 if (request) {
447 sipe_http_request_ready(request);
448 return(TRUE);
451 return(FALSE);
454 static void sipe_conf_uri_error(struct sipe_core_private *sipe_private,
455 const gchar *uri)
457 gchar *error = g_strdup_printf(_("\"%s\" is not a valid conference URI"),
458 uri ? uri : "");
459 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
460 _("Failed to join the conference"),
461 error);
462 g_free(error);
465 void sipe_core_conf_create(struct sipe_core_public *sipe_public,
466 const gchar *uri,
467 const gchar *organizer,
468 const gchar *meeting_id)
470 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
472 /* SIP URI or HTTP URL */
473 if (uri) {
474 gchar *uri_ue = sipe_utils_uri_unescape(uri);
476 SIPE_DEBUG_INFO("sipe_core_conf_create: URI '%s' unescaped '%s'",
477 uri,
478 uri_ue ? uri_ue : "<UNDEFINED>");
480 /* takes ownership of "uri_ue" if successful */
481 if (!sipe_conf_check_for_lync_url(sipe_private, uri_ue)) {
482 gchar *focus_uri = parse_ocs_focus_uri(uri_ue);
484 if (focus_uri) {
485 sipe_conf_create(sipe_private, NULL, focus_uri);
486 g_free(focus_uri);
487 } else
488 sipe_conf_uri_error(sipe_private, uri);
490 g_free(uri_ue);
493 /* Organizer email and meeting ID */
494 } else if (organizer && meeting_id) {
495 gchar *tmp = g_strdup_printf("sip:%s;gruu;opaque=app:conf:focus:id:%s",
496 organizer, meeting_id);
497 gchar *focus_uri = parse_ocs_focus_uri(tmp);
499 SIPE_DEBUG_INFO("sipe_core_conf_create: organizer '%s' meeting ID '%s'",
500 organizer,
501 meeting_id);
503 if (focus_uri) {
504 sipe_conf_create(sipe_private, NULL, focus_uri);
505 g_free(focus_uri);
506 } else
507 sipe_conf_uri_error(sipe_private, tmp);
508 g_free(tmp);
510 } else {
511 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
512 _("Failed to join the conference"),
513 _("Incomplete conference information provided"));
517 /** Create new session with Focus URI */
518 struct sip_session *
519 sipe_conf_create(struct sipe_core_private *sipe_private,
520 struct sipe_chat_session *chat_session,
521 const gchar *focus_uri)
523 /* addUser request to the focus.
525 * focus_URI, from, endpoint_GUID
527 static const gchar CCCP_ADD_USER[] =
528 "<addUser>"
529 "<conferenceKeys confEntity=\"%s\"/>"
530 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"
531 "<ci:roles>"
532 "<ci:entry>attendee</ci:entry>"
533 "</ci:roles>"
534 "<ci:endpoint entity=\"{%s}\" "
535 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"
536 "</ci:user>"
537 "</addUser>";
539 gchar *self;
540 struct sip_session *session = sipe_session_add_chat(sipe_private,
541 chat_session,
542 FALSE,
543 focus_uri);
545 session->focus_dialog = g_new0(struct sip_dialog, 1);
546 session->focus_dialog->callid = gencallid();
547 session->focus_dialog->with = g_strdup(session->chat_session->id);
548 session->focus_dialog->endpoint_GUID = rand_guid();
549 session->focus_dialog->ourtag = gentag();
551 self = sip_uri_self(sipe_private);
552 session->focus_dialog->outgoing_invite =
553 cccp_request(sipe_private, "INVITE",
554 session->focus_dialog->with, session->focus_dialog,
555 process_invite_conf_focus_response,
556 CCCP_ADD_USER,
557 session->focus_dialog->with, self,
558 session->focus_dialog->endpoint_GUID);
560 /* Rejoin existing session? */
561 if (chat_session) {
562 SIPE_DEBUG_INFO("sipe_conf_create: rejoin '%s' (%s)",
563 chat_session->title,
564 chat_session->id);
565 sipe_backend_chat_rejoin(SIPE_CORE_PUBLIC,
566 chat_session->backend,
567 self,
568 chat_session->title);
570 g_free(self);
572 return(session);
575 /** Modify User Role */
576 void
577 sipe_conf_modify_user_role(struct sipe_core_private *sipe_private,
578 struct sip_session *session,
579 const gchar* who)
581 /* modifyUserRoles request to the focus. Makes user a leader.
583 * focus_uri (%s)
584 * who (%s)
586 static const gchar CCCP_MODIFY_USER_ROLES[] =
587 "<modifyUserRoles>"
588 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
589 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"
590 "<entry>presenter</entry>"
591 "</user-roles>"
592 "</modifyUserRoles>";
594 if (!session->focus_dialog || !session->focus_dialog->is_established) {
595 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
596 return;
599 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
600 session->focus_dialog, NULL,
601 CCCP_MODIFY_USER_ROLES,
602 session->focus_dialog->with, who);
606 * Check conference lock status
608 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
609 struct sipe_chat_session *chat_session)
611 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
612 sipe_chat_lock_status status = SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED;
614 if (chat_session &&
615 (chat_session->type == SIPE_CHAT_TYPE_CONFERENCE)) {
616 struct sip_session *session = sipe_session_find_chat(sipe_private,
617 chat_session);
618 if (session) {
619 gchar *self = sip_uri_self(sipe_private);
621 /* Only operators are allowed to change the lock status */
622 if (sipe_backend_chat_is_operator(chat_session->backend, self)) {
623 status = session->locked ?
624 SIPE_CHAT_LOCK_STATUS_LOCKED :
625 SIPE_CHAT_LOCK_STATUS_UNLOCKED;
628 g_free(self);
632 return(status);
636 * Modify Conference Lock
637 * Sends request to Focus.
638 * INFO method is a carrier of application/cccp+xml
640 void
641 sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
642 struct sipe_chat_session *chat_session,
643 const gboolean locked)
645 /* modifyConferenceLock request to the focus. Locks/unlocks conference.
647 * focus_uri (%s)
648 * locked (%s) "true" or "false" values applicable
650 static const gchar CCCP_MODIFY_CONFERENCE_LOCK[] =
651 "<modifyConferenceLock>"
652 "<conferenceKeys confEntity=\"%s\"/>"
653 "<locked>%s</locked>"
654 "</modifyConferenceLock>";
656 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
658 struct sip_session *session = sipe_session_find_chat(sipe_private,
659 chat_session);
661 if (!session) return;
662 if (!session->focus_dialog || !session->focus_dialog->is_established) {
663 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
664 return;
667 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
668 session->focus_dialog, NULL,
669 CCCP_MODIFY_CONFERENCE_LOCK,
670 session->focus_dialog->with,
671 locked ? "true" : "false");
674 /** Modify Delete User */
675 void
676 sipe_conf_delete_user(struct sipe_core_private *sipe_private,
677 struct sip_session *session,
678 const gchar* who)
680 /* deleteUser request to the focus. Removes a user from the conference.
682 * focus_uri (%s)
683 * who (%s)
685 static const gchar CCCP_DELETE_USER[] =
686 "<deleteUser>"
687 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"
688 "</deleteUser>";
690 if (!session->focus_dialog || !session->focus_dialog->is_established) {
691 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
692 return;
695 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
696 session->focus_dialog, NULL,
697 CCCP_DELETE_USER,
698 session->focus_dialog->with, who);
701 void
702 sipe_conf_announce_audio_mute_state(struct sipe_core_private *sipe_private,
703 struct sip_session *session,
704 gboolean is_muted)
706 // See [MS-CONFAV] 3.2.5.4 and 4.3
707 static const gchar CCCP_MODIFY_ENDPOINT_MEDIA[] =
708 "<modifyEndpointMedia mscp:mcuUri=\"%s\""
709 " xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\">"
710 "<mediaKeys confEntity=\"%s\" userEntity=\"%s\""
711 " endpointEntity=\"%s\" mediaId=\"%d\"/>"
712 "<ci:media"
713 " xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" id=\"%d\">"
714 "<ci:type>audio</ci:type>"
715 "<ci:status>%s</ci:status>"
716 "<media-ingress-filter"
717 " xmlns=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
718 "%s"
719 "</media-ingress-filter>"
720 "</ci:media>"
721 "</modifyEndpointMedia>";
723 gchar *mcu_uri = sipe_conf_build_uri(session->focus_dialog->with,
724 "audio-video");
725 gchar *self = sip_uri_self(sipe_private);
727 cccp_request(sipe_private, "INFO", session->focus_dialog->with,
728 session->focus_dialog, NULL,
729 CCCP_MODIFY_ENDPOINT_MEDIA,
730 mcu_uri, session->focus_dialog->with, self,
731 session->audio_video_entity,
732 session->audio_media_id, session->audio_media_id,
733 is_muted ? "recvonly" : "sendrecv",
734 is_muted ? "block" : "unblock");
736 g_free(mcu_uri);
737 g_free(self);
740 /** Invite counterparty to join conference callback */
741 static gboolean
742 process_invite_conf_response(struct sipe_core_private *sipe_private,
743 struct sipmsg *msg,
744 SIPE_UNUSED_PARAMETER struct transaction *trans)
746 struct sip_dialog *dialog = g_new0(struct sip_dialog, 1);
748 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
749 dialog->cseq = sipmsg_parse_cseq(msg);
750 dialog->with = parse_from(sipmsg_find_header(msg, "To"));
751 sipe_dialog_parse(dialog, msg, TRUE);
753 if (msg->response >= 200) {
754 /* send ACK to counterparty */
755 dialog->cseq--;
756 sip_transport_ack(sipe_private, dialog);
757 dialog->outgoing_invite = NULL;
758 dialog->is_established = TRUE;
761 if (msg->response >= 400) {
762 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog->with);
763 /* @TODO notify user of failure to invite counterparty */
764 sipe_dialog_free(dialog);
765 return FALSE;
768 if (msg->response >= 200) {
769 struct sip_session *session = sipe_session_find_im(sipe_private, dialog->with);
770 struct sip_dialog *im_dialog = sipe_dialog_find(session, dialog->with);
772 /* close IM session to counterparty */
773 if (im_dialog) {
774 sip_transport_bye(sipe_private, im_dialog);
775 sipe_dialog_remove(session, dialog->with);
779 sipe_dialog_free(dialog);
780 return TRUE;
784 * Invites counterparty to join conference.
786 void
787 sipe_invite_conf(struct sipe_core_private *sipe_private,
788 struct sip_session *session,
789 const gchar* who)
791 gchar *hdr;
792 gchar *contact;
793 gchar *body;
794 struct sip_dialog *dialog = NULL;
796 /* It will be short lived special dialog.
797 * Will not be stored in session.
799 dialog = g_new0(struct sip_dialog, 1);
800 dialog->callid = gencallid();
801 dialog->with = g_strdup(who);
802 dialog->ourtag = gentag();
804 contact = get_contact(sipe_private);
805 hdr = g_strdup_printf(
806 "Supported: ms-sender\r\n"
807 "Contact: %s\r\n"
808 "Content-Type: application/ms-conf-invite+xml\r\n",
809 contact);
810 g_free(contact);
812 body = g_strdup_printf(
813 SIPE_SEND_CONF_INVITE,
814 session->chat_session->id,
815 session->subject ? session->subject : ""
818 sip_transport_invite(sipe_private,
819 hdr,
820 body,
821 dialog,
822 process_invite_conf_response);
824 sipe_dialog_free(dialog);
825 g_free(body);
826 g_free(hdr);
829 /** Create conference callback */
830 static gboolean
831 process_conf_add_response(struct sipe_core_private *sipe_private,
832 struct sipmsg *msg,
833 struct transaction *trans)
835 if (msg->response >= 400) {
836 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
837 /* @TODO notify user of failure to create conference */
838 return FALSE;
840 if (msg->response == 200) {
841 sipe_xml *xn_response = sipe_xml_parse(msg->body, msg->bodylen);
842 if (sipe_strequal("success", sipe_xml_attribute(xn_response, "code")))
844 gchar *who = trans->payload->data;
845 const sipe_xml *xn_conference_info = sipe_xml_child(xn_response, "addConference/conference-info");
846 struct sip_session *session = sipe_conf_create(sipe_private,
847 NULL,
848 sipe_xml_attribute(xn_conference_info,
849 "entity"));
851 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
852 session->chat_session->id);
854 session->pending_invite_queue = sipe_utils_slist_insert_unique_sorted(session->pending_invite_queue,
855 g_strdup(who),
856 (GCompareFunc)strcmp,
857 g_free);
859 sipe_xml_free(xn_response);
862 return TRUE;
866 * Creates conference.
868 void
869 sipe_conf_add(struct sipe_core_private *sipe_private,
870 const gchar* who)
872 gchar *conference_id;
873 struct transaction *trans;
874 time_t expiry = time(NULL) + 7*60*60; /* 7 hours */
875 char *expiry_time;
877 /* addConference request to the focus factory.
879 * conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
880 * expiry_time (%s) Ex.: 2009-07-13T17:57:09Z
881 * conference_view (%s) Ex.: <msci:entity-view entity="chat"/>
883 static const gchar CCCP_ADD_CONFERENCE[] =
884 "<addConference>"
885 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" "
886 "entity=\"\" "
887 "xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"
888 "<ci:conference-description>"
889 "<ci:subject/>"
890 "<msci:conference-id>%s</msci:conference-id>"
891 "<msci:expiry-time>%s</msci:expiry-time>"
892 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"
893 "</ci:conference-description>"
894 "<msci:conference-view>%s</msci:conference-view>"
895 "</ci:conference-info>"
896 "</addConference>";
898 static const gchar *DESIRED_MCU_TYPES[] = {
899 "chat",
900 #ifdef HAVE_VV
901 "audio-video",
902 #endif
903 #ifdef HAVE_APPSHARE
904 "applicationsharing",
905 #endif
906 NULL
909 GString *conference_view = g_string_new("");
910 const gchar **type;
912 for (type = DESIRED_MCU_TYPES; *type; ++type ) {
913 if (sipe_conf_supports_mcu_type(sipe_private, *type)) {
914 g_string_append(conference_view, "<msci:entity-view entity=\"");
915 g_string_append(conference_view, *type);
916 g_string_append(conference_view, "\"/>");
920 expiry_time = sipe_utils_time_to_str(expiry);
921 conference_id = genconfid();
922 trans = cccp_request(sipe_private, "SERVICE", sipe_private->focus_factory_uri,
923 NULL, process_conf_add_response,
924 CCCP_ADD_CONFERENCE,
925 conference_id, expiry_time, conference_view->str);
926 g_free(conference_id);
927 g_free(expiry_time);
928 g_string_free(conference_view, TRUE);
930 if (trans) {
931 struct transaction_payload *payload = g_new0(struct transaction_payload, 1);
933 payload->destroy = g_free;
934 payload->data = g_strdup(who);
935 trans->payload = payload;
939 static void
940 accept_incoming_invite_conf(struct sipe_core_private *sipe_private,
941 gchar *focus_uri,
942 gboolean audio,
943 struct sipmsg *msg)
945 struct sip_session *session;
946 gchar *newTag = gentag();
947 const gchar *oldHeader = sipmsg_find_header(msg, "To");
948 gchar *newHeader;
950 newHeader = g_strdup_printf("%s;tag=%s", oldHeader, newTag);
951 g_free(newTag);
952 sipmsg_remove_header_now(msg, "To");
953 sipmsg_add_header_now(msg, "To", newHeader);
954 g_free(newHeader);
956 /* acknowledge invite */
957 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
959 /* add self to conf */
960 session = sipe_conf_create(sipe_private, NULL, focus_uri);
961 session->is_call = audio;
964 struct conf_accept_ctx {
965 gchar *focus_uri;
966 struct sipmsg *msg;
967 struct sipe_user_ask_ctx *ask_ctx;
969 SipeUserAskCb accept_cb;
970 SipeUserAskCb decline_cb;
972 gpointer user_data;
975 static void
976 conf_accept_ctx_free(struct conf_accept_ctx *ctx)
978 g_return_if_fail(ctx != NULL);
980 sipmsg_free(ctx->msg);
981 g_free(ctx->focus_uri);
982 g_free(ctx);
985 static void
986 conf_accept_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
988 accept_incoming_invite_conf(sipe_private, ctx->focus_uri, TRUE, ctx->msg);
991 static void
992 conf_decline_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
994 sip_transport_response(sipe_private,
995 ctx->msg,
996 603, "Decline", NULL);
999 void
1000 sipe_conf_cancel_unaccepted(struct sipe_core_private *sipe_private,
1001 struct sipmsg *msg)
1003 const gchar *callid1 = msg ? sipmsg_find_header(msg, "Call-ID") : NULL;
1004 GSList *it = sipe_private->sessions_to_accept;
1005 while (it) {
1006 struct conf_accept_ctx *ctx = it->data;
1007 const gchar *callid2 = NULL;
1009 if (msg && ctx->msg)
1010 callid2 = sipmsg_find_header(ctx->msg, "Call-ID");
1012 if (sipe_strequal(callid1, callid2)) {
1013 GSList *tmp;
1015 if (ctx->msg)
1016 sip_transport_response(sipe_private, ctx->msg,
1017 487, "Request Terminated", NULL);
1019 if (msg)
1020 sip_transport_response(sipe_private, msg, 200, "OK", NULL);
1022 sipe_user_close_ask(ctx->ask_ctx);
1023 conf_accept_ctx_free(ctx);
1025 tmp = it;
1026 it = it->next;
1028 sipe_private->sessions_to_accept =
1029 g_slist_delete_link(sipe_private->sessions_to_accept, tmp);
1031 if (callid1)
1032 break;
1033 } else
1034 it = it->next;
1038 static void
1039 accept_invitation_cb(struct sipe_core_private *sipe_private, gpointer data)
1041 struct conf_accept_ctx *ctx = data;
1043 sipe_private->sessions_to_accept =
1044 g_slist_remove(sipe_private->sessions_to_accept, ctx);
1046 if (ctx->accept_cb) {
1047 ctx->accept_cb(sipe_private, ctx);
1050 conf_accept_ctx_free(ctx);
1053 static void
1054 decline_invitation_cb(struct sipe_core_private *sipe_private, gpointer data)
1056 struct conf_accept_ctx *ctx = data;
1058 sipe_private->sessions_to_accept =
1059 g_slist_remove(sipe_private->sessions_to_accept, ctx);
1061 if (ctx->decline_cb) {
1062 ctx->decline_cb(sipe_private, ctx);
1065 conf_accept_ctx_free(ctx);
1068 static void
1069 ask_accept_invitation(struct sipe_core_private *sipe_private,
1070 const gchar *focus_uri,
1071 const gchar *question,
1072 struct sipmsg *msg,
1073 SipeUserAskCb accept_cb,
1074 SipeUserAskCb decline_cb,
1075 gpointer user_data)
1077 gchar **parts;
1078 gchar *alias;
1079 gchar *question_str;
1080 struct conf_accept_ctx *ctx;
1082 parts = g_strsplit(focus_uri, ";", 2);
1083 alias = sipe_buddy_get_alias(sipe_private, parts[0]);
1085 question_str = g_strdup_printf("%s %s", alias ? alias : parts[0], question);
1087 g_free(alias);
1088 g_strfreev(parts);
1090 ctx = g_new0(struct conf_accept_ctx, 1);
1091 sipe_private->sessions_to_accept =
1092 g_slist_append(sipe_private->sessions_to_accept, ctx);
1094 ctx->focus_uri = g_strdup(focus_uri);
1095 ctx->msg = msg ? sipmsg_copy(msg) : NULL;
1096 ctx->accept_cb = accept_cb;
1097 ctx->decline_cb = decline_cb;
1098 ctx->user_data = user_data;
1099 ctx->ask_ctx = sipe_user_ask(sipe_private, question_str,
1100 _("Accept"), accept_invitation_cb,
1101 _("Decline"), decline_invitation_cb,
1102 ctx);
1104 g_free(question_str);
1107 static void
1108 ask_accept_voice_conference(struct sipe_core_private *sipe_private,
1109 const gchar *focus_uri,
1110 struct sipmsg *msg,
1111 SipeUserAskCb accept_cb,
1112 SipeUserAskCb decline_cb)
1114 gchar *question;
1115 const gchar *novv_note;
1117 #ifdef HAVE_VV
1118 novv_note = "";
1119 #else
1120 novv_note = _("\n\nAs this client was not compiled with voice call "
1121 "support, if you accept, you will be able to contact "
1122 "the other participants only via IM session.");
1123 #endif
1125 question = g_strdup_printf(_("wants to invite you "
1126 "to a conference call%s"), novv_note);
1128 ask_accept_invitation(sipe_private, focus_uri, question, msg,
1129 accept_cb, decline_cb, NULL);
1131 g_free(question);
1134 void
1135 process_incoming_invite_conf(struct sipe_core_private *sipe_private,
1136 struct sipmsg *msg)
1138 sipe_xml *xn_conferencing = sipe_xml_parse(msg->body, msg->bodylen);
1139 const sipe_xml *xn_focus_uri = sipe_xml_child(xn_conferencing, "focus-uri");
1140 const sipe_xml *xn_audio = sipe_xml_child(xn_conferencing, "audio");
1141 gchar *focus_uri = sipe_xml_data(xn_focus_uri);
1142 gboolean audio = sipe_strequal(sipe_xml_attribute(xn_audio, "available"), "true");
1144 sipe_xml_free(xn_conferencing);
1146 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri);
1148 if (audio) {
1149 sip_transport_response(sipe_private, msg, 180, "Ringing", NULL);
1150 ask_accept_voice_conference(sipe_private, focus_uri, msg,
1151 (SipeUserAskCb) conf_accept_cb,
1152 (SipeUserAskCb) conf_decline_cb);
1154 } else {
1155 accept_incoming_invite_conf(sipe_private, focus_uri, FALSE, msg);
1158 g_free(focus_uri);
1161 #ifdef HAVE_VV
1163 static void
1164 process_conference_av_endpoint(const sipe_xml *endpoint,
1165 const gchar *user_uri,
1166 const gchar *self_uri,
1167 struct sip_session *session)
1169 const sipe_xml *media;
1170 const gchar *new_entity;
1172 if (!sipe_strequal(user_uri, self_uri)) {
1173 /* We are interested only in our own endpoint data. */
1174 return;
1177 new_entity = sipe_xml_attribute(endpoint, "entity");
1178 if (!sipe_strequal(session->audio_video_entity, new_entity)) {
1179 g_free(session->audio_video_entity);
1180 session->audio_video_entity = g_strdup(new_entity);
1183 session->audio_media_id = 0;
1185 media = sipe_xml_child(endpoint, "media");
1186 for (; media; media = sipe_xml_twin(media)) {
1187 gchar *type = sipe_xml_data(sipe_xml_child(media, "type"));
1189 if (sipe_strequal(type, "audio")) {
1190 session->audio_media_id =
1191 sipe_xml_int_attribute(media, "id", 0);
1194 g_free(type);
1196 if (session->audio_media_id != 0) {
1197 break;
1202 static void
1203 call_accept_cb(struct sipe_core_private *sipe_private, struct conf_accept_ctx *ctx)
1205 struct sip_session *session;
1206 session = sipe_session_find_conference(sipe_private, ctx->focus_uri);
1208 if (session) {
1209 sipe_core_media_connect_conference(SIPE_CORE_PUBLIC,
1210 session->chat_session);
1214 #ifdef HAVE_APPSHARE
1215 gboolean
1216 sipe_core_conf_is_viewing_appshare(struct sipe_core_public *sipe_public,
1217 struct sipe_chat_session *chat_session)
1219 if (chat_session) {
1220 gchar *mcu_uri;
1221 GList *calls;
1223 mcu_uri = sipe_conf_build_uri(chat_session->id, "applicationsharing");
1224 calls = g_hash_table_get_values(SIPE_CORE_PRIVATE->media_calls);
1226 for (; calls; calls = g_list_delete_link(calls, calls)) {
1227 struct sipe_media_call *call = calls->data;
1228 if (sipe_strequal(call->with, mcu_uri)) {
1229 break;
1233 g_free(mcu_uri);
1235 if (calls != NULL) {
1236 g_list_free(calls);
1237 return TRUE;
1241 return FALSE;
1244 static gboolean
1245 process_conference_appshare_endpoint(const sipe_xml *endpoint)
1247 gboolean presentation_added = FALSE;
1248 const sipe_xml *media;
1250 for (media = sipe_xml_child(endpoint, "media");
1251 media && !presentation_added;
1252 media = sipe_xml_twin(media)) {
1253 gchar *type;
1254 gchar *media_state;
1255 gchar *status;
1257 type = sipe_xml_data(sipe_xml_child(media, "type"));
1258 media_state = sipe_xml_data(sipe_xml_child(media, "media-state"));
1259 status = sipe_xml_data(sipe_xml_child(media, "status"));
1261 if (sipe_strequal(type, "applicationsharing") &&
1262 sipe_strequal(media_state, "connected") &&
1263 sipe_strequal(status, "sendonly")) {
1264 presentation_added = TRUE;
1267 g_free(type);
1268 g_free(media_state);
1269 g_free(status);
1272 return(presentation_added);
1274 #endif // HAVE_APPSHARE
1275 #endif // HAVE_VV
1277 void
1278 sipe_process_conference(struct sipe_core_private *sipe_private,
1279 struct sipmsg *msg)
1281 sipe_xml *xn_conference_info;
1282 const sipe_xml *node;
1283 const sipe_xml *xn_subject;
1284 const gchar *focus_uri;
1285 struct sip_session *session;
1286 gboolean just_joined = FALSE;
1287 #ifdef HAVE_VV
1288 gboolean audio_was_added = FALSE;
1289 #ifdef HAVE_APPSHARE
1290 gboolean presentation_was_added = FALSE;
1291 #endif
1292 #endif // HAVE_VV
1294 if (msg->response != 0 && msg->response != 200) return;
1296 if (msg->bodylen == 0 || msg->body == NULL || !sipe_strequal(sipmsg_find_header(msg, "Event"), "conference")) return;
1298 xn_conference_info = sipe_xml_parse(msg->body, msg->bodylen);
1299 if (!xn_conference_info) return;
1301 focus_uri = sipe_xml_attribute(xn_conference_info, "entity");
1302 session = sipe_session_find_conference(sipe_private, focus_uri);
1304 if (!session) {
1305 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri);
1306 return;
1309 if (!session->chat_session->backend) {
1310 gchar *self = sip_uri_self(sipe_private);
1312 /* create chat */
1313 session->chat_session->backend = sipe_backend_chat_create(SIPE_CORE_PUBLIC,
1314 session->chat_session,
1315 session->chat_session->title,
1316 self);
1317 just_joined = TRUE;
1318 /* @TODO ask for full state (re-subscribe) if it was a partial one -
1319 * this is to obtain full list of conference participants.
1321 g_free(self);
1324 /* subject */
1325 if ((xn_subject = sipe_xml_child(xn_conference_info, "conference-description/subject"))) {
1326 g_free(session->subject);
1327 session->subject = sipe_xml_data(xn_subject);
1328 sipe_backend_chat_topic(session->chat_session->backend, session->subject);
1329 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session->subject ? session->subject : "");
1332 /* IM MCU URI */
1333 if (!session->im_mcu_uri) {
1334 for (node = sipe_xml_child(xn_conference_info, "conference-description/conf-uris/entry");
1335 node;
1336 node = sipe_xml_twin(node))
1338 gchar *purpose = sipe_xml_data(sipe_xml_child(node, "purpose"));
1340 if (sipe_strequal("chat", purpose)) {
1341 g_free(purpose);
1342 session->im_mcu_uri = sipe_xml_data(sipe_xml_child(node, "uri"));
1343 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session->im_mcu_uri);
1344 break;
1346 g_free(purpose);
1350 /* organizer */
1351 if (!session->chat_session->organizer) {
1352 node = sipe_xml_child(xn_conference_info, "conference-description/organizer/display-name");
1353 if (node) {
1354 session->chat_session->organizer = sipe_xml_data(node);
1358 /* join URL */
1359 if (!session->chat_session->join_url) {
1360 node = sipe_xml_child(xn_conference_info, "conference-description/join-url");
1361 if (node) {
1362 session->chat_session->join_url = sipe_xml_data(node);
1366 /* dial-in conference id */
1367 if (!session->chat_session->dial_in_conf_id) {
1368 node = sipe_xml_child(xn_conference_info, "conference-description/pstn-access/id");
1369 if (node) {
1370 session->chat_session->dial_in_conf_id = sipe_xml_data(node);
1374 /* users */
1375 for (node = sipe_xml_child(xn_conference_info, "users/user"); node; node = sipe_xml_twin(node)) {
1376 const gchar *user_uri = sipe_xml_attribute(node, "entity");
1377 const gchar *state = sipe_xml_attribute(node, "state");
1378 gchar *role = sipe_xml_data(sipe_xml_child(node, "roles/entry"));
1379 gboolean is_operator = sipe_strequal(role, "presenter");
1380 gboolean is_in_im_mcu = FALSE;
1381 gchar *self = sip_uri_self(sipe_private);
1383 if (sipe_strequal("deleted", state)) {
1384 if (sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1385 sipe_backend_chat_remove(session->chat_session->backend,
1386 user_uri);
1388 } else {
1389 /* endpoints */
1390 const sipe_xml *endpoint;
1391 for (endpoint = sipe_xml_child(node, "endpoint"); endpoint; endpoint = sipe_xml_twin(endpoint)) {
1392 const gchar *session_type;
1393 gchar *status = sipe_xml_data(sipe_xml_child(endpoint, "status"));
1394 gboolean connected = sipe_strequal("connected", status);
1395 g_free(status);
1397 if (!connected)
1398 continue;
1400 session_type = sipe_xml_attribute(endpoint, "session-type");
1402 if (sipe_strequal("chat", session_type)) {
1403 is_in_im_mcu = TRUE;
1404 if (!sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1405 sipe_backend_chat_add(session->chat_session->backend,
1406 user_uri,
1407 !just_joined && g_ascii_strcasecmp(user_uri, self));
1409 if (is_operator) {
1410 sipe_backend_chat_operator(session->chat_session->backend,
1411 user_uri);
1413 } else if (sipe_strequal("audio-video", session_type)) {
1414 #ifdef HAVE_VV
1415 if (!session->is_call)
1416 audio_was_added = TRUE;
1417 process_conference_av_endpoint(endpoint,
1418 user_uri,
1419 self,
1420 session);
1421 #endif
1422 } else if (sipe_strequal("applicationsharing", session_type)) {
1423 #ifdef HAVE_APPSHARE
1424 if (!sipe_core_conf_is_viewing_appshare(SIPE_CORE_PUBLIC,
1425 session->chat_session)) {
1426 presentation_was_added = process_conference_appshare_endpoint(endpoint);
1428 #endif
1431 if (!is_in_im_mcu) {
1432 if (sipe_backend_chat_find(session->chat_session->backend, user_uri)) {
1433 sipe_backend_chat_remove(session->chat_session->backend,
1434 user_uri);
1438 g_free(role);
1439 g_free(self);
1442 #ifdef HAVE_VV
1443 if (audio_was_added) {
1444 session->is_call = TRUE;
1445 ask_accept_voice_conference(sipe_private, focus_uri, NULL,
1446 (SipeUserAskCb) call_accept_cb,
1447 NULL);
1449 #ifdef HAVE_APPSHARE
1450 if (presentation_was_added) {
1451 sipe_core_appshare_connect_conference(SIPE_CORE_PUBLIC,
1452 session->chat_session,
1453 TRUE);
1455 #endif
1456 #endif // HAVE_VV
1458 /* entity-view, locked */
1459 for (node = sipe_xml_child(xn_conference_info, "conference-view/entity-view");
1460 node;
1461 node = sipe_xml_twin(node)) {
1463 const sipe_xml *xn_type = sipe_xml_child(node, "entity-state/media/entry/type");
1464 gchar *tmp = NULL;
1465 if (xn_type && sipe_strequal("chat", (tmp = sipe_xml_data(xn_type)))) {
1466 const sipe_xml *xn_locked = sipe_xml_child(node, "entity-state/locked");
1467 if (xn_locked) {
1468 gchar *locked = sipe_xml_data(xn_locked);
1469 gboolean prev_locked = session->locked;
1470 session->locked = sipe_strequal(locked, "true");
1471 if (prev_locked && !session->locked) {
1472 sipe_user_present_info(sipe_private, session,
1473 _("This conference is no longer locked. Additional participants can now join."));
1475 if (!prev_locked && session->locked) {
1476 sipe_user_present_info(sipe_private, session,
1477 _("This conference is locked. Nobody else can join the conference while it is locked."));
1480 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
1481 session->locked ? "TRUE" : "FALSE");
1482 g_free(locked);
1485 g_free(tmp);
1487 sipe_xml_free(xn_conference_info);
1489 if (session->im_mcu_uri) {
1490 struct sip_dialog *dialog = sipe_dialog_find(session, session->im_mcu_uri);
1491 if (!dialog) {
1492 dialog = sipe_dialog_add(session);
1494 dialog->callid = g_strdup(session->callid);
1495 dialog->with = g_strdup(session->im_mcu_uri);
1497 /* send INVITE to IM MCU */
1498 sipe_im_invite(sipe_private, session, dialog->with, NULL, NULL, NULL, FALSE);
1502 sipe_process_pending_invite_queue(sipe_private, session);
1505 void
1506 sipe_conf_immcu_closed(struct sipe_core_private *sipe_private,
1507 struct sip_session *session)
1509 sipe_user_present_info(sipe_private, session,
1510 _("You have been disconnected from this conference."));
1511 sipe_backend_chat_close(session->chat_session->backend);
1514 void
1515 conf_session_close(struct sipe_core_private *sipe_private,
1516 struct sip_session *session)
1518 if (session) {
1519 /* unsubscribe from focus */
1520 sipe_subscribe_conference(sipe_private,
1521 session->chat_session->id, TRUE);
1523 if (session->focus_dialog) {
1524 /* send BYE to focus */
1525 sip_transport_bye(sipe_private, session->focus_dialog);
1530 void
1531 sipe_process_imdn(struct sipe_core_private *sipe_private,
1532 struct sipmsg *msg)
1534 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
1535 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1536 static struct sip_session *session;
1537 sipe_xml *xn_imdn;
1538 const sipe_xml *node;
1539 gchar *message_id;
1540 gchar *message;
1542 session = sipe_session_find_chat_or_im(sipe_private, callid, with);
1543 if (!session) {
1544 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid);
1545 g_free(with);
1546 return;
1549 xn_imdn = sipe_xml_parse(msg->body, msg->bodylen);
1550 message_id = sipe_xml_data(sipe_xml_child(xn_imdn, "message-id"));
1552 message = g_hash_table_lookup(session->conf_unconfirmed_messages, message_id);
1554 /* recipient */
1555 for (node = sipe_xml_child(xn_imdn, "recipient"); node; node = sipe_xml_twin(node)) {
1556 gchar *tmp = parse_from(sipe_xml_attribute(node, "uri"));
1557 gchar *uri = parse_from(tmp);
1558 gchar *status = sipe_xml_data(sipe_xml_child(node, "status"));
1559 guint error = status ? g_ascii_strtoull(status, NULL, 10) : 0;
1560 /* default to error if missing or conversion failed */
1561 if ((error == 0) || (error >= 300))
1562 sipe_user_present_message_undelivered(sipe_private,
1563 session,
1564 error,
1566 uri,
1567 message);
1568 g_free(status);
1569 g_free(tmp);
1570 g_free(uri);
1573 sipe_xml_free(xn_imdn);
1575 g_hash_table_remove(session->conf_unconfirmed_messages, message_id);
1576 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
1577 message_id, g_hash_table_size(session->conf_unconfirmed_messages));
1578 g_free(message_id);
1579 g_free(with);
1582 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
1583 gpointer parameter,
1584 const gchar *buddy_name)
1586 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1587 struct sipe_chat_session *chat_session = parameter;
1588 struct sip_session *session;
1590 SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s",
1591 chat_session->title);
1593 session = sipe_session_find_chat(sipe_private, chat_session);
1594 sipe_conf_modify_user_role(sipe_private, session, buddy_name);
1597 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
1598 gpointer parameter,
1599 const gchar *buddy_name)
1601 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
1602 struct sipe_chat_session *chat_session = parameter;
1603 struct sip_session *session;
1605 SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s",
1606 chat_session->title);
1608 session = sipe_session_find_chat(sipe_private, chat_session);
1609 sipe_conf_delete_user(sipe_private, session, buddy_name);
1612 gchar *
1613 sipe_conf_build_uri(const gchar *focus_uri, const gchar *session_type)
1615 gchar **parts = g_strsplit(focus_uri, ":focus:", 2);
1616 gchar *result = NULL;
1618 if (g_strv_length(parts) == 2) {
1619 result = g_strconcat(parts[0], ":", session_type, ":", parts[1],
1620 NULL);
1623 g_strfreev(parts);
1624 return result;
1627 static gchar *
1628 access_numbers_info(struct sipe_core_public *sipe_public)
1630 GString *result = g_string_new("");
1631 GList *keys = g_hash_table_get_keys(SIPE_CORE_PRIVATE->access_numbers);
1632 keys = g_list_sort(keys, (GCompareFunc)g_strcmp0);
1634 for (; keys; keys = g_list_delete_link(keys, keys)) {
1635 gchar *value;
1636 value = g_hash_table_lookup(SIPE_CORE_PRIVATE->access_numbers,
1637 keys->data);
1639 g_string_append(result, keys->data);
1640 g_string_append(result, "&nbsp;&nbsp;&nbsp;&nbsp;");
1641 g_string_append(result, value);
1642 g_string_append(result, "<br/>");
1645 return g_string_free(result, FALSE);
1648 gchar *
1649 sipe_core_conf_entry_info(struct sipe_core_public *sipe_public,
1650 struct sipe_chat_session *chat_session)
1652 gchar *access_info = access_numbers_info(sipe_public);
1653 gchar *result = g_strdup_printf(
1654 "<b><font size=\"+1\">%s</font></b><br/>"
1655 "<b>%s:</b> %s<br/>"
1656 "<b>%s:</b> %s<br/>"
1657 "<br/>"
1658 "<b>%s:</b><br/>"
1659 "%s<br/>"
1660 "<br/>"
1661 "<b>%s:</b> %s<br/>"
1662 "<br/>"
1663 "<b><font size=\"+1\">%s</font></b><br/>"
1664 "%s",
1665 _("Dial-in info"),
1666 _("Number"),
1667 SIPE_CORE_PRIVATE->default_access_number ? SIPE_CORE_PRIVATE->default_access_number : "",
1668 _("Conference ID"),
1669 chat_session->dial_in_conf_id ? chat_session->dial_in_conf_id : "",
1670 _("Meeting link"),
1671 chat_session->join_url ? chat_session->join_url : "",
1672 _("Organizer"),
1673 chat_session->organizer ? chat_session->organizer : "",
1674 _("Alternative dial-in numbers"),
1675 access_info);
1677 g_free(access_info);
1679 return result;
1683 Local Variables:
1684 mode: c
1685 c-file-style: "bsd"
1686 indent-tabs-mode: t
1687 tab-width: 8
1688 End: