6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "conversation.h"
37 #include "sipe-common.h"
40 #include "sipe-backend.h"
41 #include "sipe-chat.h"
42 #include "sipe-conf.h"
43 #include "sipe-dialog.h"
45 #include "sipe-session.h"
46 #include "sipe-utils.h"
51 * Add Conference request to FocusFactory.
52 * @param focus_factory_uri (%s) Ex.: sip:bob7@boston.local;gruu;opaque=app:conf:focusfactory
53 * @param from (%s) Ex.: sip:bob7@boston.local
54 * @param request_id (%d) Ex.: 1094520
55 * @param conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
56 * @param expiry_time (%s) Ex.: 2009-07-13T17:57:09Z , Default duration: 7 hours
58 #define SIPE_SEND_CONF_ADD \
59 "<?xml version=\"1.0\"?>"\
60 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "\
61 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
67 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"\
68 "<ci:conference-description>"\
70 "<msci:conference-id>%s</msci:conference-id>"\
71 "<msci:expiry-time>%s</msci:expiry-time>"\
72 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"\
73 "</ci:conference-description>"\
74 "<msci:conference-view>"\
75 "<msci:entity-view entity=\"chat\"/>"\
76 "</msci:conference-view>"\
77 "</ci:conference-info>"\
82 * AddUser request to Focus.
84 * focus_URI, from, request_id, focus_URI, from, endpoint_GUID
86 #define SIPE_SEND_CONF_ADD_USER \
87 "<?xml version=\"1.0\"?>"\
88 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
94 "<conferenceKeys confEntity=\"%s\"/>"\
95 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"\
97 "<ci:entry>attendee</ci:entry>"\
99 "<ci:endpoint entity=\"{%s}\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"\
105 * ModifyUserRoles request to Focus. Makes user a leader.
106 * @param focus_uri (%s)
108 * @param request_id (%d)
109 * @param focus_uri (%s)
112 #define SIPE_SEND_CONF_MODIFY_USER_ROLES \
113 "<?xml version=\"1.0\"?>"\
114 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
120 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
121 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"\
122 "<entry>presenter</entry>"\
124 "</modifyUserRoles>"\
128 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
129 * @param focus_uri (%s)
131 * @param request_id (%d)
132 * @param focus_uri (%s)
133 * @param locked (%s) "true" or "false" values applicable
135 #define SIPE_SEND_CONF_MODIFY_CONF_LOCK \
136 "<?xml version=\"1.0\"?>"\
137 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
142 "<modifyConferenceLock>"\
143 "<conferenceKeys confEntity=\"%s\"/>"\
144 "<locked>%s</locked>"\
145 "</modifyConferenceLock>"\
149 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
150 * @param focus_uri (%s)
152 * @param request_id (%d)
153 * @param focus_uri (%s)
156 #define SIPE_SEND_CONF_DELETE_USER \
157 "<?xml version=\"1.0\"?>"\
158 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
164 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
169 * Invite counterparty to join conference.
170 * @param focus_uri (%s)
171 * @param subject (%s) of conference
173 #define SIPE_SEND_CONF_INVITE \
174 "<Conferencing version=\"2.0\">"\
175 "<focus-uri>%s</focus-uri>"\
176 "<subject>%s</subject>"\
177 "<im available=\"true\">"\
183 * Generates random GUID.
184 * This method is borrowed from pidgin's msnutils.c
189 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
190 rand() % 0xAAFF + 0x1111,
191 rand() % 0xAAFF + 0x1111,
192 rand() % 0xAAFF + 0x1111,
193 rand() % 0xAAFF + 0x1111,
194 rand() % 0xAAFF + 0x1111,
195 rand() % 0xAAFF + 0x1111,
196 rand() % 0xAAFF + 0x1111,
197 rand() % 0xAAFF + 0x1111);
201 * @param expires not respected if set to negative value (E.g. -1)
204 sipe_subscribe_conference(struct sipe_account_data
*sip
,
205 struct sip_session
*session
,
208 gchar
*expires_hdr
= (expires
>= 0) ? g_strdup_printf("Expires: %d\r\n", expires
) : g_strdup("");
209 gchar
*contact
= get_contact(sip
);
210 gchar
*hdr
= g_strdup_printf(
211 "Event: conference\r\n"
213 "Accept: application/conference-info+xml\r\n"
214 "Supported: com.microsoft.autoextend\r\n"
215 "Supported: ms-benotify\r\n"
216 "Proxy-Require: ms-benotify\r\n"
217 "Supported: ms-piggyback-first-notify\r\n"
224 send_sip_request(sip
->gc
,
231 process_subscribe_response
);
235 /** Invite us to the focus callback */
237 process_invite_conf_focus_response(struct sipe_account_data
*sip
,
239 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
241 struct sip_session
*session
= NULL
;
242 char *focus_uri
= parse_from(sipmsg_find_header(msg
, "To"));
244 session
= sipe_session_find_conference(sip
, focus_uri
);
247 SIPE_DEBUG_INFO("process_invite_conf_focus_response: unable to find conf session with focus=%s", focus_uri
);
252 if (!session
->focus_dialog
) {
253 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: session's focus_dialog is NULL");
258 sipe_dialog_parse(session
->focus_dialog
, msg
, TRUE
);
260 if (msg
->response
>= 200) {
261 /* send ACK to focus */
262 session
->focus_dialog
->cseq
= 0;
263 send_sip_request(sip
->gc
, "ACK", session
->focus_dialog
->with
, session
->focus_dialog
->with
, NULL
, NULL
, session
->focus_dialog
, NULL
);
264 session
->focus_dialog
->outgoing_invite
= NULL
;
265 session
->focus_dialog
->is_established
= TRUE
;
268 if (msg
->response
>= 400) {
269 SIPE_DEBUG_INFO_NOFORMAT("process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.");
270 /* @TODO notify user of failure to join focus */
271 sipe_session_remove(sip
, session
);
274 } else if (msg
->response
== 200) {
275 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
276 const gchar
*code
= sipe_xml_attribute(xn_response
, "code");
277 if (sipe_strequal(code
, "success")) {
278 /* subscribe to focus */
279 sipe_subscribe_conference(sip
, session
, -1);
281 sipe_xml_free(xn_response
);
288 /** Invite us to the focus */
290 sipe_invite_conf_focus(struct sipe_account_data
*sip
,
291 struct sip_session
*session
)
298 if (session
->focus_dialog
&& session
->focus_dialog
->is_established
) {
299 SIPE_DEBUG_INFO("session with %s already has a dialog open", session
->focus_uri
);
303 if(!session
->focus_dialog
) {
304 session
->focus_dialog
= g_new0(struct sip_dialog
, 1);
305 session
->focus_dialog
->callid
= gencallid();
306 session
->focus_dialog
->with
= g_strdup(session
->focus_uri
);
307 session
->focus_dialog
->endpoint_GUID
= rand_guid();
309 if (!(session
->focus_dialog
->ourtag
)) {
310 session
->focus_dialog
->ourtag
= gentag();
313 contact
= get_contact(sip
);
314 hdr
= g_strdup_printf(
315 "Supported: ms-sender\r\n"
317 "Content-Type: application/cccp+xml\r\n",
321 /* @TODO put request_id to queue to further compare with incoming one */
322 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
323 self
= sip_uri_self(sip
);
324 body
= g_strdup_printf(
325 SIPE_SEND_CONF_ADD_USER
,
326 session
->focus_dialog
->with
,
328 session
->request_id
++,
329 session
->focus_dialog
->with
,
331 session
->focus_dialog
->endpoint_GUID
);
334 session
->focus_dialog
->outgoing_invite
= send_sip_request(sip
->gc
,
336 session
->focus_dialog
->with
,
337 session
->focus_dialog
->with
,
340 session
->focus_dialog
,
341 process_invite_conf_focus_response
);
346 /** Modify User Role */
348 sipe_conf_modify_user_role(struct sipe_account_data
*sip
,
349 struct sip_session
*session
,
356 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
357 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_user_role: no dialog with focus, exiting.");
362 "Content-Type: application/cccp+xml\r\n");
364 /* @TODO put request_id to queue to further compare with incoming one */
365 self
= sip_uri_self(sip
);
366 body
= g_strdup_printf(
367 SIPE_SEND_CONF_MODIFY_USER_ROLES
,
368 session
->focus_dialog
->with
,
370 session
->request_id
++,
371 session
->focus_dialog
->with
,
375 send_sip_request(sip
->gc
,
377 session
->focus_dialog
->with
,
378 session
->focus_dialog
->with
,
381 session
->focus_dialog
,
387 /** Modify Conference Lock */
389 sipe_conf_modify_conference_lock(struct sipe_account_data
*sip
,
390 struct sip_session
*session
,
391 const gboolean locked
)
397 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
398 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_modify_conference_lock: no dialog with focus, exiting.");
403 "Content-Type: application/cccp+xml\r\n");
405 /* @TODO put request_id to queue to further compare with incoming one */
406 self
= sip_uri_self(sip
);
407 body
= g_strdup_printf(
408 SIPE_SEND_CONF_MODIFY_CONF_LOCK
,
409 session
->focus_dialog
->with
,
411 session
->request_id
++,
412 session
->focus_dialog
->with
,
413 locked
? "true" : "false");
416 send_sip_request(sip
->gc
,
418 session
->focus_dialog
->with
,
419 session
->focus_dialog
->with
,
422 session
->focus_dialog
,
428 /** Modify Delete User */
430 sipe_conf_delete_user(struct sipe_account_data
*sip
,
431 struct sip_session
*session
,
438 if (!session
->focus_dialog
|| !session
->focus_dialog
->is_established
) {
439 SIPE_DEBUG_INFO_NOFORMAT("sipe_conf_delete_user: no dialog with focus, exiting.");
444 "Content-Type: application/cccp+xml\r\n");
446 /* @TODO put request_id to queue to further compare with incoming one */
447 self
= sip_uri_self(sip
);
448 body
= g_strdup_printf(
449 SIPE_SEND_CONF_DELETE_USER
,
450 session
->focus_dialog
->with
,
452 session
->request_id
++,
453 session
->focus_dialog
->with
,
457 send_sip_request(sip
->gc
,
459 session
->focus_dialog
->with
,
460 session
->focus_dialog
->with
,
463 session
->focus_dialog
,
469 /** Invite counterparty to join conference callback */
471 process_invite_conf_response(struct sipe_account_data
*sip
,
473 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
475 struct sip_dialog
*dialog
= g_new0(struct sip_dialog
, 1);
477 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
478 dialog
->cseq
= parse_cseq(sipmsg_find_header(msg
, "CSeq"));
479 dialog
->with
= parse_from(sipmsg_find_header(msg
, "To"));
480 sipe_dialog_parse(dialog
, msg
, TRUE
);
482 if (msg
->response
>= 200) {
483 /* send ACK to counterparty */
485 send_sip_request(sip
->gc
, "ACK", dialog
->with
, dialog
->with
, NULL
, NULL
, dialog
, NULL
);
486 dialog
->outgoing_invite
= NULL
;
487 dialog
->is_established
= TRUE
;
490 if (msg
->response
>= 400) {
491 SIPE_DEBUG_INFO("process_invite_conf_response: INVITE response is not 200. Failed to invite %s.", dialog
->with
);
492 /* @TODO notify user of failure to invite counterparty */
493 sipe_dialog_free(dialog
);
497 if (msg
->response
>= 200) {
498 struct sip_session
*session
= sipe_session_find_im(sip
, dialog
->with
);
499 struct sip_dialog
*im_dialog
= sipe_dialog_find(session
, dialog
->with
);
501 /* close IM session to counterparty */
503 send_sip_request(sip
->gc
, "BYE", im_dialog
->with
, im_dialog
->with
, NULL
, NULL
, im_dialog
, NULL
);
504 sipe_dialog_remove(session
, dialog
->with
);
508 sipe_dialog_free(dialog
);
513 * Invites counterparty to join conference.
516 sipe_invite_conf(struct sipe_account_data
*sip
,
517 struct sip_session
*session
,
523 struct sip_dialog
*dialog
= NULL
;
525 /* It will be short lived special dialog.
526 * Will not be stored in session.
528 dialog
= g_new0(struct sip_dialog
, 1);
529 dialog
->callid
= gencallid();
530 dialog
->with
= g_strdup(who
);
531 dialog
->ourtag
= gentag();
533 contact
= get_contact(sip
);
534 hdr
= g_strdup_printf(
535 "Supported: ms-sender\r\n"
537 "Content-Type: application/ms-conf-invite+xml\r\n",
541 body
= g_strdup_printf(
542 SIPE_SEND_CONF_INVITE
,
544 session
->subject
? session
->subject
: ""
547 send_sip_request( sip
->gc
,
554 process_invite_conf_response
);
556 sipe_dialog_free(dialog
);
561 /** Create conference callback */
563 process_conf_add_response(struct sipe_account_data
*sip
,
565 struct transaction
*trans
)
567 if (msg
->response
>= 400) {
568 SIPE_DEBUG_INFO_NOFORMAT("process_conf_add_response: SERVICE response is not 200. Failed to create conference.");
569 /* @TODO notify user of failure to create conference */
572 if (msg
->response
== 200) {
573 sipe_xml
*xn_response
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
574 if (sipe_strequal("success", sipe_xml_attribute(xn_response
, "code")))
576 gchar
*who
= trans
->payload
->data
;
577 struct sip_session
*session
;
578 const sipe_xml
*xn_conference_info
= sipe_xml_child(xn_response
, "addConference/conference-info");
580 session
= sipe_session_add_chat(sip
);
581 session
->is_multiparty
= FALSE
;
582 session
->focus_uri
= g_strdup(sipe_xml_attribute(xn_conference_info
, "entity"));
583 SIPE_DEBUG_INFO("process_conf_add_response: session->focus_uri=%s",
584 session
->focus_uri
? session
->focus_uri
: "");
586 session
->pending_invite_queue
= slist_insert_unique_sorted(
587 session
->pending_invite_queue
, g_strdup(who
), (GCompareFunc
)strcmp
);
589 /* add self to conf */
590 sipe_invite_conf_focus(sip
, session
);
592 sipe_xml_free(xn_response
);
599 * Creates conference.
602 sipe_conf_add(struct sipe_account_data
*sip
,
606 gchar
*conference_id
;
610 struct transaction
*trans
;
611 struct sip_dialog
*dialog
= NULL
;
612 time_t expiry
= time(NULL
) + 7*60*60; /* 7 hours */
614 struct transaction_payload
*payload
;
616 contact
= get_contact(sip
);
617 hdr
= g_strdup_printf(
618 "Supported: ms-sender\r\n"
620 "Content-Type: application/cccp+xml\r\n",
624 expiry_time
= sipe_utils_time_to_str(expiry
);
625 self
= sip_uri_self(sip
);
626 conference_id
= genconfid();
627 body
= g_strdup_printf(
629 sip
->focus_factory_uri
,
635 g_free(conference_id
);
638 trans
= send_sip_request( sip
->gc
,
640 sip
->focus_factory_uri
,
641 sip
->focus_factory_uri
,
645 process_conf_add_response
);
647 payload
= g_new0(struct transaction_payload
, 1);
648 payload
->destroy
= g_free
;
649 payload
->data
= g_strdup(who
);
650 trans
->payload
= payload
;
652 sipe_dialog_free(dialog
);
658 process_incoming_invite_conf(struct sipe_account_data
*sip
,
661 struct sip_session
*session
= NULL
;
662 struct sip_dialog
*dialog
= NULL
;
663 sipe_xml
*xn_conferencing
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
664 const sipe_xml
*xn_focus_uri
= sipe_xml_child(xn_conferencing
, "focus-uri");
665 char *focus_uri
= sipe_xml_data(xn_focus_uri
);
666 gchar
*newTag
= gentag();
667 const gchar
*oldHeader
= sipmsg_find_header(msg
, "To");
670 sipe_xml_free(xn_conferencing
);
673 SIPE_DEBUG_INFO("We have received invitation to Conference. Focus URI=%s", focus_uri
);
675 newHeader
= g_strdup_printf("%s;tag=%s", oldHeader
, newTag
);
676 sipmsg_remove_header_now(msg
, "To");
677 sipmsg_add_header_now(msg
, "To", newHeader
);
680 /* temporary dialog with invitor */
681 /* take data before 'msg' will be modified by send_sip_response */
682 dialog
= g_new0(struct sip_dialog
, 1);
683 dialog
->callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
684 dialog
->cseq
= parse_cseq(sipmsg_find_header(msg
, "CSeq"));
685 dialog
->with
= parse_from(sipmsg_find_header(msg
, "From"));
686 sipe_dialog_parse(dialog
, msg
, FALSE
);
688 send_sip_response(sip
->gc
, msg
, 200, "OK", NULL
);
690 session
= sipe_session_add_chat(sip
);
691 session
->focus_uri
= focus_uri
;
692 session
->is_multiparty
= FALSE
;
694 /* send BYE to invitor */
695 send_sip_request(sip
->gc
, "BYE", dialog
->with
, dialog
->with
, NULL
, NULL
, dialog
, NULL
);
696 sipe_dialog_free(dialog
);
698 /* add self to conf */
699 sipe_invite_conf_focus(sip
, session
);
703 sipe_process_conference(struct sipe_account_data
*sip
,
706 sipe_xml
*xn_conference_info
;
707 const sipe_xml
*node
;
708 const sipe_xml
*xn_subject
;
709 const gchar
*focus_uri
;
710 struct sip_session
*session
;
711 gboolean just_joined
= FALSE
;
713 if (msg
->response
!= 0 && msg
->response
!= 200) return;
715 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| !sipe_strequal(sipmsg_find_header(msg
, "Event"), "conference")) return;
717 xn_conference_info
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
718 if (!xn_conference_info
) return;
720 focus_uri
= sipe_xml_attribute(xn_conference_info
, "entity");
721 session
= sipe_session_find_conference(sip
, focus_uri
);
724 SIPE_DEBUG_INFO("sipe_process_conference: unable to find conf session with focus=%s", focus_uri
);
728 if (session
->focus_uri
&& !session
->conv
) {
729 gchar
*chat_title
= sipe_chat_get_name(session
->focus_uri
);
730 gchar
*self
= sip_uri_self(sip
);
731 /* can't be find by chat id as it won't survive acc reinstantation */
732 PurpleConversation
*conv
= NULL
;
735 conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT
,
739 /* to be able to rejoin existing chat/window */
740 if (conv
&& !purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv
))) {
741 PURPLE_CONV_CHAT(conv
)->left
= TRUE
;
743 /* create prpl chat */
744 session
->conv
= serv_got_joined_chat(sip
->gc
, session
->chat_id
, chat_title
);
745 session
->chat_title
= chat_title
;
746 purple_conv_chat_set_nick(PURPLE_CONV_CHAT(session
->conv
), self
);
748 /* @TODO ask for full state (re-subscribe) if it was a partial one -
749 * this is to obtain full list of conference participants.
755 if ((xn_subject
= sipe_xml_child(xn_conference_info
, "conference-description/subject"))) {
756 g_free(session
->subject
);
757 session
->subject
= sipe_xml_data(xn_subject
);
758 purple_conv_chat_set_topic(PURPLE_CONV_CHAT(session
->conv
), NULL
, session
->subject
);
759 SIPE_DEBUG_INFO("sipe_process_conference: subject=%s", session
->subject
? session
->subject
: "");
763 if (!session
->im_mcu_uri
) {
764 for (node
= sipe_xml_child(xn_conference_info
, "conference-description/conf-uris/entry");
766 node
= sipe_xml_twin(node
))
768 gchar
*purpose
= sipe_xml_data(sipe_xml_child(node
, "purpose"));
770 if (sipe_strequal("chat", purpose
)) {
772 session
->im_mcu_uri
= sipe_xml_data(sipe_xml_child(node
, "uri"));
773 SIPE_DEBUG_INFO("sipe_process_conference: im_mcu_uri=%s", session
->im_mcu_uri
);
781 for (node
= sipe_xml_child(xn_conference_info
, "users/user"); node
; node
= sipe_xml_twin(node
)) {
782 const gchar
*user_uri
= sipe_xml_attribute(node
, "entity");
783 const gchar
*state
= sipe_xml_attribute(node
, "state");
784 gchar
*role
= sipe_xml_data(sipe_xml_child(node
, "roles/entry"));
785 PurpleConvChatBuddyFlags flags
= PURPLE_CBFLAGS_NONE
;
786 PurpleConvChat
*chat
= PURPLE_CONV_CHAT(session
->conv
);
787 gboolean is_in_im_mcu
= FALSE
;
788 gchar
*self
= sip_uri_self(sip
);
790 if (sipe_strequal(role
, "presenter")) {
791 flags
|= PURPLE_CBFLAGS_OP
;
794 if (sipe_strequal("deleted", state
)) {
795 if (purple_conv_chat_find_user(chat
, user_uri
)) {
796 purple_conv_chat_remove_user(chat
, user_uri
, NULL
/* reason */);
800 const sipe_xml
*endpoint
;
801 for (endpoint
= sipe_xml_child(node
, "endpoint"); endpoint
; endpoint
= sipe_xml_twin(endpoint
)) {
802 if (sipe_strequal("chat", sipe_xml_attribute(endpoint
, "session-type"))) {
803 gchar
*status
= sipe_xml_data(sipe_xml_child(endpoint
, "status"));
804 if (sipe_strequal("connected", status
)) {
806 if (!purple_conv_chat_find_user(chat
, user_uri
)) {
807 purple_conv_chat_add_user(chat
, user_uri
, NULL
, flags
,
808 !just_joined
&& g_strcasecmp(user_uri
, self
));
810 purple_conv_chat_user_set_flags(chat
, user_uri
, flags
);
818 if (purple_conv_chat_find_user(chat
, user_uri
)) {
819 purple_conv_chat_remove_user(chat
, user_uri
, NULL
/* reason */);
827 /* entity-view, locked */
828 for (node
= sipe_xml_child(xn_conference_info
, "conference-view/entity-view");
830 node
= sipe_xml_twin(node
)) {
832 const sipe_xml
*xn_type
= sipe_xml_child(node
, "entity-state/media/entry/type");
834 if (xn_type
&& sipe_strequal("chat", (tmp
= sipe_xml_data(xn_type
)))) {
835 const sipe_xml
*xn_locked
= sipe_xml_child(node
, "entity-state/locked");
837 gchar
*locked
= sipe_xml_data(xn_locked
);
838 gboolean prev_locked
= session
->locked
;
839 session
->locked
= sipe_strequal(locked
, "true");
840 if (prev_locked
&& !session
->locked
) {
841 sipe_present_info(sip
, session
,
842 _("This conference is no longer locked. Additional participants can now join."));
844 if (!prev_locked
&& session
->locked
) {
845 sipe_present_info(sip
, session
,
846 _("This conference is locked. Nobody else can join the conference while it is locked."));
849 SIPE_DEBUG_INFO("sipe_process_conference: session->locked=%s",
850 session
->locked
? "TRUE" : "FALSE");
856 sipe_xml_free(xn_conference_info
);
858 if (session
->im_mcu_uri
) {
859 struct sip_dialog
*dialog
= sipe_dialog_find(session
, session
->im_mcu_uri
);
861 dialog
= sipe_dialog_add(session
);
863 dialog
->callid
= g_strdup(session
->callid
);
864 dialog
->with
= g_strdup(session
->im_mcu_uri
);
866 /* send INVITE to IM MCU */
867 sipe_invite(sip
, session
, dialog
->with
, NULL
, NULL
, NULL
, FALSE
);
871 sipe_process_pending_invite_queue(sip
, session
);
875 sipe_conf_immcu_closed(struct sipe_account_data
*sip
,
876 struct sip_session
*session
)
878 sipe_present_info(sip
, session
,
879 _("You have been disconnected from this conference."));
880 purple_conv_chat_clear_users(PURPLE_CONV_CHAT(session
->conv
));
884 conf_session_close(struct sipe_account_data
*sip
,
885 struct sip_session
*session
)
888 /* unsubscribe from focus */
889 sipe_subscribe_conference(sip
, session
, 0);
891 if (session
->focus_dialog
) {
892 /* send BYE to focus */
893 send_sip_request(sip
->gc
,
895 session
->focus_dialog
->with
,
896 session
->focus_dialog
->with
,
899 session
->focus_dialog
,
906 sipe_process_imdn(struct sipe_account_data
*sip
,
909 gchar
*with
= parse_from(sipmsg_find_header(msg
, "From"));
910 const gchar
*call_id
= sipmsg_find_header(msg
, "Call-ID");
911 static struct sip_session
*session
;
913 const sipe_xml
*node
;
917 session
= sipe_session_find_chat_by_callid(sip
, call_id
);
919 session
= sipe_session_find_im(sip
, with
);
922 SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with call_id=%s", call_id
);
927 xn_imdn
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
928 message_id
= sipe_xml_data(sipe_xml_child(xn_imdn
, "message-id"));
930 message
= g_hash_table_lookup(session
->conf_unconfirmed_messages
, message_id
);
933 for (node
= sipe_xml_child(xn_imdn
, "recipient"); node
; node
= sipe_xml_twin(node
)) {
934 gchar
*tmp
= parse_from(sipe_xml_attribute(node
, "uri"));
935 gchar
*uri
= parse_from(tmp
);
936 sipe_present_message_undelivered_err(sip
, session
, -1, -1, uri
, message
);
941 sipe_xml_free(xn_imdn
);
943 g_hash_table_remove(session
->conf_unconfirmed_messages
, message_id
);
944 SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)",
945 message_id
, g_hash_table_size(session
->conf_unconfirmed_messages
));