Updated to release 1.7.0
[siplcs.git] / src / sipe-conf.c
blobe4d91ca1320516bac58aee9b1381f2d3143bd4aa
1 /**
2 * @file sipe-conf.c
4 * pidgin-sipe
6 * Copyright (C) 2009 pier11 <pier11@operamail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <string.h>
25 #include <glib.h>
27 #include "debug.h"
29 #include "sipe.h"
30 #include "sipe-chat.h"
31 #include "sipe-conf.h"
32 #include "sipe-dialog.h"
33 #include "sipe-nls.h"
34 #include "sipe-session.h"
35 #include "sipe-utils.h"
37 /**
38 * Add Conference request to FocusFactory.
39 * @param focus_factory_uri (%s) Ex.: sip:bob7@boston.local;gruu;opaque=app:conf:focusfactory
40 * @param from (%s) Ex.: sip:bob7@boston.local
41 * @param request_id (%d) Ex.: 1094520
42 * @param conference_id (%s) Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
43 * @param expiry_time (%s) Ex.: 2009-07-13T17:57:09Z , Default duration: 7 hours
45 #define SIPE_SEND_CONF_ADD \
46 "<?xml version=\"1.0\"?>"\
47 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" "\
48 "xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
49 "C3PVersion=\"1\" "\
50 "to=\"%s\" "\
51 "from=\"%s\" "\
52 "requestId=\"%d\">"\
53 "<addConference>"\
54 "<ci:conference-info xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\">"\
55 "<ci:conference-description>"\
56 "<ci:subject/>"\
57 "<msci:conference-id>%s</msci:conference-id>"\
58 "<msci:expiry-time>%s</msci:expiry-time>"\
59 "<msci:admission-policy>openAuthenticated</msci:admission-policy>"\
60 "</ci:conference-description>"\
61 "<msci:conference-view>"\
62 "<msci:entity-view entity=\"chat\"/>"\
63 "</msci:conference-view>"\
64 "</ci:conference-info>"\
65 "</addConference>"\
66 "</request>"
68 /**
69 * AddUser request to Focus.
70 * Params:
71 * focus_URI, from, request_id, focus_URI, from, endpoint_GUID
73 #define SIPE_SEND_CONF_ADD_USER \
74 "<?xml version=\"1.0\"?>"\
75 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
76 "C3PVersion=\"1\" "\
77 "to=\"%s\" "\
78 "from=\"%s\" "\
79 "requestId=\"%d\">"\
80 "<addUser>"\
81 "<conferenceKeys confEntity=\"%s\"/>"\
82 "<ci:user xmlns:ci=\"urn:ietf:params:xml:ns:conference-info\" entity=\"%s\">"\
83 "<ci:roles>"\
84 "<ci:entry>attendee</ci:entry>"\
85 "</ci:roles>"\
86 "<ci:endpoint entity=\"{%s}\" xmlns:msci=\"http://schemas.microsoft.com/rtc/2005/08/confinfoextensions\"/>"\
87 "</ci:user>"\
88 "</addUser>"\
89 "</request>"
91 /**
92 * ModifyUserRoles request to Focus. Makes user a leader.
93 * @param focus_uri (%s)
94 * @param from (%s)
95 * @param request_id (%d)
96 * @param focus_uri (%s)
97 * @param who (%s)
99 #define SIPE_SEND_CONF_MODIFY_USER_ROLES \
100 "<?xml version=\"1.0\"?>"\
101 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
102 "C3PVersion=\"1\" "\
103 "to=\"%s\" "\
104 "from=\"%s\" "\
105 "requestId=\"%d\">"\
106 "<modifyUserRoles>"\
107 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
108 "<user-roles xmlns=\"urn:ietf:params:xml:ns:conference-info\">"\
109 "<entry>presenter</entry>"\
110 "</user-roles>"\
111 "</modifyUserRoles>"\
112 "</request>"
115 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
116 * @param focus_uri (%s)
117 * @param from (%s)
118 * @param request_id (%d)
119 * @param focus_uri (%s)
120 * @param locked (%s) "true" or "false" values applicable
122 #define SIPE_SEND_CONF_MODIFY_CONF_LOCK \
123 "<?xml version=\"1.0\"?>"\
124 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
125 "C3PVersion=\"1\" "\
126 "to=\"%s\" "\
127 "from=\"%s\" "\
128 "requestId=\"%d\">"\
129 "<modifyConferenceLock>"\
130 "<conferenceKeys confEntity=\"%s\"/>"\
131 "<locked>%s</locked>"\
132 "</modifyConferenceLock>"\
133 "</request>"
136 * ModifyConferenceLock request to Focus. Locks/unlocks conference.
137 * @param focus_uri (%s)
138 * @param from (%s)
139 * @param request_id (%d)
140 * @param focus_uri (%s)
141 * @param who (%s)
143 #define SIPE_SEND_CONF_DELETE_USER \
144 "<?xml version=\"1.0\"?>"\
145 "<request xmlns=\"urn:ietf:params:xml:ns:cccp\" xmlns:mscp=\"http://schemas.microsoft.com/rtc/2005/08/cccpextensions\" "\
146 "C3PVersion=\"1\" "\
147 "to=\"%s\" "\
148 "from=\"%s\" "\
149 "requestId=\"%d\">"\
150 "<deleteUser>"\
151 "<userKeys confEntity=\"%s\" userEntity=\"%s\"/>"\
152 "</deleteUser>"\
153 "</request>"
156 * Invite counterparty to join conference.
157 * @param focus_uri (%s)
158 * @param subject (%s) of conference
160 #define SIPE_SEND_CONF_INVITE \
161 "<Conferencing version=\"2.0\">"\
162 "<focus-uri>%s</focus-uri>"\
163 "<subject>%s</subject>"\
164 "<im available=\"true\">"\
165 "<first-im/>"\
166 "</im>"\
167 "</Conferencing>"
170 * Generates random GUID.
171 * This method is borrowed from pidgin's msnutils.c
173 static char *
174 rand_guid()
176 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
177 rand() % 0xAAFF + 0x1111,
178 rand() % 0xAAFF + 0x1111,
179 rand() % 0xAAFF + 0x1111,
180 rand() % 0xAAFF + 0x1111,
181 rand() % 0xAAFF + 0x1111,
182 rand() % 0xAAFF + 0x1111,
183 rand() % 0xAAFF + 0x1111,
184 rand() % 0xAAFF + 0x1111);
188 * @param expires not respected if set to negative value (E.g. -1)
190 static void
191 sipe_subscribe_conference(struct sipe_account_data *sip,
192 struct sip_session *session,
193 const int expires)
195 gchar *expires_hdr = (expires >= 0) ? g_strdup_printf("Expires: %d\r\n", expires) : g_strdup("");
196 gchar *contact = get_contact(sip);
197 gchar *hdr = g_strdup_printf(
198 "Event: conference\r\n"
199 "%s"
200 "Accept: application/conference-info+xml\r\n"
201 "Supported: com.microsoft.autoextend\r\n"
202 "Supported: ms-benotify\r\n"
203 "Proxy-Require: ms-benotify\r\n"
204 "Supported: ms-piggyback-first-notify\r\n"
205 "Contact: %s\r\n",
206 expires_hdr,
207 contact);
208 g_free(expires_hdr);
209 g_free(contact);
211 send_sip_request(sip->gc,
212 "SUBSCRIBE",
213 session->focus_uri,
214 session->focus_uri,
215 hdr,
217 NULL,
218 process_subscribe_response);
219 g_free(hdr);
222 /** Invite us to the focus callback */
223 static gboolean
224 process_invite_conf_focus_response(struct sipe_account_data *sip,
225 struct sipmsg *msg,
226 SIPE_UNUSED_PARAMETER struct transaction *trans)
228 struct sip_session *session = NULL;
229 char *focus_uri = parse_from(sipmsg_find_header(msg, "To"));
231 session = sipe_session_find_conference(sip, focus_uri);
233 if (!session) {
234 purple_debug_info("sipe", "process_invite_conf_focus_response: unable to find conf session with focus=%s\n", focus_uri);
235 g_free(focus_uri);
236 return FALSE;
239 if (!session->focus_dialog) {
240 purple_debug_info("sipe", "process_invite_conf_focus_response: session's focus_dialog is NULL\n");
241 g_free(focus_uri);
242 return FALSE;
245 sipe_dialog_parse(session->focus_dialog, msg, TRUE);
247 if (msg->response >= 200) {
248 /* send ACK to focus */
249 session->focus_dialog->cseq = 0;
250 send_sip_request(sip->gc, "ACK", session->focus_dialog->with, session->focus_dialog->with, NULL, NULL, session->focus_dialog, NULL);
251 session->focus_dialog->outgoing_invite = NULL;
252 session->focus_dialog->is_established = TRUE;
255 if (msg->response >= 400) {
256 purple_debug_info("sipe", "process_invite_conf_focus_response: INVITE response is not 200. Failed to join focus.\n");
257 /* @TODO notify user of failure to join focus */
258 sipe_session_remove(sip, session);
259 g_free(focus_uri);
260 return FALSE;
261 } else if (msg->response == 200) {
262 xmlnode *xn_response = xmlnode_from_str(msg->body, msg->bodylen);
263 const gchar *code = xmlnode_get_attrib(xn_response, "code");
264 if (!strcmp(code, "success")) {
265 /* subscribe to focus */
266 sipe_subscribe_conference(sip, session, -1);
268 xmlnode_free(xn_response);
271 g_free(focus_uri);
272 return TRUE;
275 /** Invite us to the focus */
276 void
277 sipe_invite_conf_focus(struct sipe_account_data *sip,
278 struct sip_session *session)
280 gchar *hdr;
281 gchar *contact;
282 gchar *body;
283 gchar *self;
285 if (session->focus_dialog && session->focus_dialog->is_established) {
286 purple_debug_info("sipe", "session with %s already has a dialog open\n", session->focus_uri);
287 return;
290 if(!session->focus_dialog) {
291 session->focus_dialog = g_new0(struct sip_dialog, 1);
292 session->focus_dialog->callid = gencallid();
293 session->focus_dialog->with = g_strdup(session->focus_uri);
294 session->focus_dialog->endpoint_GUID = rand_guid();
296 if (!(session->focus_dialog->ourtag)) {
297 session->focus_dialog->ourtag = gentag();
300 contact = get_contact(sip);
301 hdr = g_strdup_printf(
302 "Supported: ms-sender\r\n"
303 "Contact: %s\r\n"
304 "Content-Type: application/cccp+xml\r\n",
305 contact);
306 g_free(contact);
308 /* @TODO put request_id to queue to further compare with incoming one */
309 /* focus_URI, from, request_id, focus_URI, from, endpoint_GUID */
310 self = sip_uri_self(sip);
311 body = g_strdup_printf(
312 SIPE_SEND_CONF_ADD_USER,
313 session->focus_dialog->with,
314 self,
315 session->request_id++,
316 session->focus_dialog->with,
317 self,
318 session->focus_dialog->endpoint_GUID);
319 g_free(self);
321 session->focus_dialog->outgoing_invite = send_sip_request(sip->gc,
322 "INVITE",
323 session->focus_dialog->with,
324 session->focus_dialog->with,
325 hdr,
326 body,
327 session->focus_dialog,
328 process_invite_conf_focus_response);
329 g_free(body);
330 g_free(hdr);
333 /** Modify User Role */
334 void
335 sipe_conf_modify_user_role(struct sipe_account_data *sip,
336 struct sip_session *session,
337 const gchar* who)
339 gchar *hdr;
340 gchar *body;
341 gchar *self;
343 if (!session->focus_dialog || !session->focus_dialog->is_established) {
344 purple_debug_info("sipe", "sipe_conf_modify_user_role: no dialog with focus, exiting.\n");
345 return;
348 hdr = g_strdup(
349 "Content-Type: application/cccp+xml\r\n");
351 /* @TODO put request_id to queue to further compare with incoming one */
352 self = sip_uri_self(sip);
353 body = g_strdup_printf(
354 SIPE_SEND_CONF_MODIFY_USER_ROLES,
355 session->focus_dialog->with,
356 self,
357 session->request_id++,
358 session->focus_dialog->with,
359 who);
360 g_free(self);
362 send_sip_request(sip->gc,
363 "INFO",
364 session->focus_dialog->with,
365 session->focus_dialog->with,
366 hdr,
367 body,
368 session->focus_dialog,
369 NULL);
370 g_free(body);
371 g_free(hdr);
374 /** Modify Conference Lock */
375 void
376 sipe_conf_modify_conference_lock(struct sipe_account_data *sip,
377 struct sip_session *session,
378 const gboolean locked)
380 gchar *hdr;
381 gchar *body;
382 gchar *self;
384 if (!session->focus_dialog || !session->focus_dialog->is_established) {
385 purple_debug_info("sipe", "sipe_conf_modify_conference_lock: no dialog with focus, exiting.\n");
386 return;
389 hdr = g_strdup(
390 "Content-Type: application/cccp+xml\r\n");
392 /* @TODO put request_id to queue to further compare with incoming one */
393 self = sip_uri_self(sip);
394 body = g_strdup_printf(
395 SIPE_SEND_CONF_MODIFY_CONF_LOCK,
396 session->focus_dialog->with,
397 self,
398 session->request_id++,
399 session->focus_dialog->with,
400 locked ? "true" : "false");
401 g_free(self);
403 send_sip_request(sip->gc,
404 "INFO",
405 session->focus_dialog->with,
406 session->focus_dialog->with,
407 hdr,
408 body,
409 session->focus_dialog,
410 NULL);
411 g_free(body);
412 g_free(hdr);
415 /** Modify Delete User */
416 void
417 sipe_conf_delete_user(struct sipe_account_data *sip,
418 struct sip_session *session,
419 const gchar* who)
421 gchar *hdr;
422 gchar *body;
423 gchar *self;
425 if (!session->focus_dialog || !session->focus_dialog->is_established) {
426 purple_debug_info("sipe", "sipe_conf_delete_user: no dialog with focus, exiting.\n");
427 return;
430 hdr = g_strdup(
431 "Content-Type: application/cccp+xml\r\n");
433 /* @TODO put request_id to queue to further compare with incoming one */
434 self = sip_uri_self(sip);
435 body = g_strdup_printf(
436 SIPE_SEND_CONF_DELETE_USER,
437 session->focus_dialog->with,
438 self,
439 session->request_id++,
440 session->focus_dialog->with,
441 who);
442 g_free(self);
444 send_sip_request(sip->gc,
445 "INFO",
446 session->focus_dialog->with,
447 session->focus_dialog->with,
448 hdr,
449 body,
450 session->focus_dialog,
451 NULL);
452 g_free(body);
453 g_free(hdr);
456 /** Invite counterparty to join conference callback */
457 static gboolean
458 process_invite_conf_response(struct sipe_account_data *sip,
459 struct sipmsg *msg,
460 SIPE_UNUSED_PARAMETER struct transaction *trans)
462 struct sip_dialog *dialog = g_new0(struct sip_dialog, 1);
464 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
465 dialog->cseq = parse_cseq(sipmsg_find_header(msg, "CSeq"));
466 dialog->with = parse_from(sipmsg_find_header(msg, "To"));
467 sipe_dialog_parse(dialog, msg, TRUE);
469 if (msg->response >= 200) {
470 /* send ACK to counterparty */
471 dialog->cseq--;
472 send_sip_request(sip->gc, "ACK", dialog->with, dialog->with, NULL, NULL, dialog, NULL);
473 dialog->outgoing_invite = NULL;
474 dialog->is_established = TRUE;
477 if (msg->response >= 400) {
478 purple_debug_info("sipe", "process_invite_conf_response: INVITE response is not 200. Failed to invite %s.\n", dialog->with);
479 /* @TODO notify user of failure to invite counterparty */
480 sipe_dialog_free(dialog);
481 return FALSE;
484 if (msg->response >= 200) {
485 struct sip_session *session = sipe_session_find_im(sip, dialog->with);
486 struct sip_dialog *im_dialog = sipe_dialog_find(session, dialog->with);
488 /* close IM session to counterparty */
489 if (im_dialog) {
490 send_sip_request(sip->gc, "BYE", im_dialog->with, im_dialog->with, NULL, NULL, im_dialog, NULL);
491 sipe_dialog_remove(session, dialog->with);
495 sipe_dialog_free(dialog);
496 return TRUE;
500 * Invites counterparty to join conference.
502 void
503 sipe_invite_conf(struct sipe_account_data *sip,
504 struct sip_session *session,
505 const gchar* who)
507 gchar *hdr;
508 gchar *contact;
509 gchar *body;
510 struct sip_dialog *dialog = NULL;
512 /* It will be short lived special dialog.
513 * Will not be stored in session.
515 dialog = g_new0(struct sip_dialog, 1);
516 dialog->callid = gencallid();
517 dialog->with = g_strdup(who);
518 dialog->ourtag = gentag();
520 contact = get_contact(sip);
521 hdr = g_strdup_printf(
522 "Supported: ms-sender\r\n"
523 "Contact: %s\r\n"
524 "Content-Type: application/ms-conf-invite+xml\r\n",
525 contact);
526 g_free(contact);
528 body = g_strdup_printf(
529 SIPE_SEND_CONF_INVITE,
530 session->focus_uri,
531 session->subject ? session->subject : ""
534 send_sip_request( sip->gc,
535 "INVITE",
536 dialog->with,
537 dialog->with,
538 hdr,
539 body,
540 dialog,
541 process_invite_conf_response);
543 sipe_dialog_free(dialog);
544 g_free(body);
545 g_free(hdr);
548 /** Create conference callback */
549 static gboolean
550 process_conf_add_response(struct sipe_account_data *sip,
551 struct sipmsg *msg,
552 struct transaction *trans)
554 if (msg->response >= 400) {
555 purple_debug_info("sipe", "process_conf_add_response: SERVICE response is not 200. Failed to create conference.\n");
556 /* @TODO notify user of failure to create conference */
557 return FALSE;
559 if (msg->response == 200) {
560 xmlnode *xn_response = xmlnode_from_str(msg->body, msg->bodylen);
561 if (!strcmp("success", xmlnode_get_attrib(xn_response, "code")))
563 gchar *who = trans->payload->data;
564 struct sip_session *session;
565 xmlnode *xn_conference_info = xmlnode_get_descendant(xn_response, "addConference", "conference-info", NULL);
567 session = sipe_session_add_chat(sip);
568 session->is_multiparty = FALSE;
569 session->focus_uri = g_strdup(xmlnode_get_attrib(xn_conference_info, "entity"));
570 purple_debug_info("sipe", "process_conf_add_response: session->focus_uri=%s\n",
571 session->focus_uri ? session->focus_uri : "");
573 session->pending_invite_queue = slist_insert_unique_sorted(
574 session->pending_invite_queue, g_strdup(who), (GCompareFunc)strcmp);
576 /* add self to conf */
577 sipe_invite_conf_focus(sip, session);
579 xmlnode_free(xn_response);
582 return TRUE;
586 * Creates conference.
588 void
589 sipe_conf_add(struct sipe_account_data *sip,
590 const gchar* who)
592 gchar *hdr;
593 gchar *conference_id;
594 gchar *contact;
595 gchar *body;
596 gchar *self;
597 struct transaction *trans;
598 struct sip_dialog *dialog = NULL;
599 time_t expiry = time(NULL) + 7*60*60; /* 7 hours */
600 const char *expiry_time;
601 struct transaction_payload *payload;
603 contact = get_contact(sip);
604 hdr = g_strdup_printf(
605 "Supported: ms-sender\r\n"
606 "Contact: %s\r\n"
607 "Content-Type: application/cccp+xml\r\n",
608 contact);
609 g_free(contact);
611 expiry_time = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", gmtime(&expiry));
612 self = sip_uri_self(sip);
613 conference_id = genconfid();
614 body = g_strdup_printf(
615 SIPE_SEND_CONF_ADD,
616 sip->focus_factory_uri,
617 self,
618 rand(),
619 conference_id,
620 expiry_time);
621 g_free(conference_id);
622 g_free(self);
624 trans = send_sip_request( sip->gc,
625 "SERVICE",
626 sip->focus_factory_uri,
627 sip->focus_factory_uri,
628 hdr,
629 body,
630 NULL,
631 process_conf_add_response);
633 payload = g_new0(struct transaction_payload, 1);
634 payload->destroy = g_free;
635 payload->data = g_strdup(who);
636 trans->payload = payload;
638 sipe_dialog_free(dialog);
639 g_free(body);
640 g_free(hdr);
643 void
644 process_incoming_invite_conf(struct sipe_account_data *sip,
645 struct sipmsg *msg)
647 struct sip_session *session = NULL;
648 struct sip_dialog *dialog = NULL;
649 xmlnode *xn_conferencing = xmlnode_from_str(msg->body, msg->bodylen);
650 xmlnode *xn_focus_uri = xmlnode_get_child(xn_conferencing, "focus-uri");
651 char *focus_uri = xmlnode_get_data(xn_focus_uri);
653 xmlnode_free(xn_conferencing);
655 /* send OK */
656 purple_debug_info("sipe", "We have received invitation to Conference. Focus URI=%s\n", focus_uri);
657 send_sip_response(sip->gc, msg, 200, "OK", NULL);
659 session = sipe_session_add_chat(sip);
660 session->focus_uri = focus_uri;
661 session->is_multiparty = FALSE;
663 /* temporary dialog with invitor */
664 dialog = g_new0(struct sip_dialog, 1);
665 dialog->callid = g_strdup(sipmsg_find_header(msg, "Call-ID"));
666 dialog->cseq = parse_cseq(sipmsg_find_header(msg, "CSeq"));
667 dialog->with = parse_from(sipmsg_find_header(msg, "From"));
668 sipe_dialog_parse(dialog, msg, FALSE);
670 /* send BYE to invitor */
671 send_sip_request(sip->gc, "BYE", dialog->with, dialog->with, NULL, NULL, dialog, NULL);
672 sipe_dialog_free(dialog);
674 /* add self to conf */
675 sipe_invite_conf_focus(sip, session);
678 void
679 sipe_process_conference(struct sipe_account_data *sip,
680 struct sipmsg *msg)
682 xmlnode *xn_conference_info;
683 xmlnode *node;
684 xmlnode *xn_subject;
685 const gchar *focus_uri;
686 struct sip_session *session;
687 gboolean just_joined = FALSE;
689 if (msg->response != 0 && msg->response != 200) return;
691 if (msg->bodylen == 0 || msg->body == NULL || strcmp(sipmsg_find_header(msg, "Event"), "conference")) return;
693 xn_conference_info = xmlnode_from_str(msg->body, msg->bodylen);
694 if (!xn_conference_info) return;
696 focus_uri = xmlnode_get_attrib(xn_conference_info, "entity");
697 session = sipe_session_find_conference(sip, focus_uri);
699 if (!session) {
700 purple_debug_info("sipe", "sipe_process_conference: unable to find conf session with focus=%s\n", focus_uri);
701 return;
704 if (session->focus_uri && !session->conv) {
705 gchar *chat_title = sipe_chat_get_name(session->focus_uri);
706 gchar *self = sip_uri_self(sip);
707 /* can't be find by chat id as it won't survive acc reinstantation */
708 PurpleConversation *conv = NULL;
710 if (chat_title) {
711 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
712 chat_title,
713 sip->account);
715 /* to be able to rejoin existing chat/window */
716 if (conv && !purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv))) {
717 PURPLE_CONV_CHAT(conv)->left = TRUE;
719 /* create prpl chat */
720 session->conv = serv_got_joined_chat(sip->gc, session->chat_id, chat_title);
721 session->chat_title = chat_title;
722 purple_conv_chat_set_nick(PURPLE_CONV_CHAT(session->conv), self);
723 just_joined = TRUE;
724 /* @TODO ask for full state (re-subscribe) if it was a partial one -
725 * this is to obtain full list of conference participants.
727 g_free(self);
730 /* subject */
731 if ((xn_subject = xmlnode_get_descendant(xn_conference_info, "conference-description", "subject", NULL))) {
732 g_free(session->subject);
733 session->subject = xmlnode_get_data(xn_subject);
734 purple_conv_chat_set_topic(PURPLE_CONV_CHAT(session->conv), NULL, session->subject);
735 purple_debug_info("sipe", "sipe_process_conference: subject=%s\n", session->subject ? session->subject : "");
738 /* IM MCU URI */
739 if (!session->im_mcu_uri) {
740 for (node = xmlnode_get_descendant(xn_conference_info, "conference-description", "conf-uris", "entry", NULL);
741 node;
742 node = xmlnode_get_next_twin(node))
744 gchar *purpose = xmlnode_get_data(xmlnode_get_child(node, "purpose"));
746 if (purpose && !strcmp("chat", purpose)) {
747 g_free(purpose);
748 session->im_mcu_uri = xmlnode_get_data(xmlnode_get_child(node, "uri"));
749 purple_debug_info("sipe", "sipe_process_conference: im_mcu_uri=%s\n", session->im_mcu_uri);
750 break;
752 g_free(purpose);
756 /* users */
757 for (node = xmlnode_get_descendant(xn_conference_info, "users", "user", NULL); node; node = xmlnode_get_next_twin(node)) {
758 xmlnode *endpoint = NULL;
759 const gchar *user_uri = xmlnode_get_attrib(node, "entity");
760 const gchar *state = xmlnode_get_attrib(node, "state");
761 gchar *role = xmlnode_get_data(xmlnode_get_descendant(node, "roles", "entry", NULL));
762 PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE;
763 PurpleConvChat *chat = PURPLE_CONV_CHAT(session->conv);
764 gboolean is_in_im_mcu = FALSE;
765 gchar *self = sip_uri_self(sip);
767 if (role && !strcmp(role, "presenter")) {
768 flags |= PURPLE_CBFLAGS_OP;
771 if (!strcmp("deleted", state)) {
772 if (purple_conv_chat_find_user(chat, user_uri)) {
773 purple_conv_chat_remove_user(chat, user_uri, NULL /* reason */);
775 } else {
776 /* endpoints */
777 for (endpoint = xmlnode_get_child(node, "endpoint"); endpoint; endpoint = xmlnode_get_next_twin(endpoint)) {
778 if (!strcmp("chat", xmlnode_get_attrib(endpoint, "session-type"))) {
779 gchar *status = xmlnode_get_data(xmlnode_get_child(endpoint, "status"));
780 if (!strcmp("connected", status)) {
781 is_in_im_mcu = TRUE;
782 if (!purple_conv_chat_find_user(chat, user_uri)) {
783 purple_conv_chat_add_user(chat, user_uri, NULL, flags,
784 !just_joined && g_strcasecmp(user_uri, self));
785 } else {
786 purple_conv_chat_user_set_flags(chat, user_uri, flags);
789 g_free(status);
790 break;
793 if (!is_in_im_mcu) {
794 if (purple_conv_chat_find_user(chat, user_uri)) {
795 purple_conv_chat_remove_user(chat, user_uri, NULL /* reason */);
799 g_free(role);
800 g_free(self);
803 /* entity-view, locked */
804 for (node = xmlnode_get_descendant(xn_conference_info, "conference-view", "entity-view", NULL);
805 node;
806 node = xmlnode_get_next_twin(node)) {
808 xmlnode *xn_type = xmlnode_get_descendant(node, "entity-state", "media", "entry", "type", NULL);
809 gchar *tmp;
810 if (xn_type && !strcmp("chat", (tmp = xmlnode_get_data(xn_type)))) {
811 xmlnode *xn_locked = xmlnode_get_descendant(node, "entity-state", "locked", NULL);
812 if (xn_locked) {
813 gchar *locked = xmlnode_get_data(xn_locked);
814 gboolean prev_locked = session->locked;
815 session->locked = (locked && !strcmp(locked, "true")) ? TRUE : FALSE;
816 if (prev_locked && !session->locked) {
817 sipe_present_info(sip, session,
818 _("This conference is no longer locked. Additional participants can now join."));
820 if (!prev_locked && session->locked) {
821 sipe_present_info(sip, session,
822 _("This conference is locked. Nobody else can join the conference while it is locked."));
825 purple_debug_info("sipe", "sipe_process_conference: session->locked=%s\n",
826 session->locked ? "TRUE" : "FALSE");
827 g_free(locked);
829 g_free(tmp);
832 xmlnode_free(xn_conference_info);
834 if (session->im_mcu_uri) {
835 struct sip_dialog *dialog = sipe_dialog_find(session, session->im_mcu_uri);
836 if (!dialog) {
837 dialog = sipe_dialog_add(session);
839 dialog->callid = g_strdup(session->callid);
840 dialog->with = g_strdup(session->im_mcu_uri);
842 /* send INVITE to IM MCU */
843 sipe_invite(sip, session, dialog->with, NULL, NULL, FALSE);
847 sipe_process_pending_invite_queue(sip, session);
850 void
851 sipe_conf_immcu_closed(struct sipe_account_data *sip,
852 struct sip_session *session)
854 sipe_present_info(sip, session,
855 _("You have been disconnected from this conference."));
856 purple_conv_chat_clear_users(PURPLE_CONV_CHAT(session->conv));
859 void
860 conf_session_close(struct sipe_account_data *sip,
861 struct sip_session *session)
863 if (session) {
864 /* unsubscribe from focus */
865 sipe_subscribe_conference(sip, session, 0);
867 if (session->focus_dialog) {
868 /* send BYE to focus */
869 send_sip_request(sip->gc,
870 "BYE",
871 session->focus_dialog->with,
872 session->focus_dialog->with,
873 NULL,
874 NULL,
875 session->focus_dialog,
876 NULL);
881 void
882 sipe_process_imdn(struct sipe_account_data *sip,
883 struct sipmsg *msg)
885 gchar *with = parse_from(sipmsg_find_header(msg, "From"));
886 gchar *call_id = sipmsg_find_header(msg, "Call-ID");
887 static struct sip_session *session;
888 xmlnode *xn_imdn;
889 xmlnode *node;
890 gchar *message_id;
891 gchar *message;
893 session = sipe_session_find_chat_by_callid(sip, call_id);
894 if (!session) {
895 session = sipe_session_find_im(sip, with);
897 if (!session) {
898 purple_debug_info("sipe", "sipe_process_imdn: unable to find conf session with call_id=%s\n", call_id);
899 g_free(with);
900 return;
903 xn_imdn = xmlnode_from_str(msg->body, msg->bodylen);
904 message_id = xmlnode_get_data(xmlnode_get_child(xn_imdn, "message-id"));
906 message = g_hash_table_lookup(session->conf_unconfirmed_messages, message_id);
908 /* recipient */
909 for (node = xmlnode_get_child(xn_imdn, "recipient"); node; node = xmlnode_get_next_twin(node)) {
910 gchar *tmp = parse_from(xmlnode_get_attrib(node, "uri"));
911 gchar *uri = parse_from(tmp);
912 sipe_present_message_undelivered_err(sip, session, -1, uri, message);
913 g_free(tmp);
914 g_free(uri);
917 xmlnode_free(xn_imdn);
919 g_hash_table_remove(session->conf_unconfirmed_messages, message_id);
920 purple_debug_info("sipe", "sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)\n",
921 message_id, g_hash_table_size(session->conf_unconfirmed_messages));
922 g_free(message_id);
923 g_free(with);
928 Local Variables:
929 mode: c
930 c-file-style: "bsd"
931 indent-tabs-mode: t
932 tab-width: 8
933 End: