libgaim/protocols/novell/novell.c

changeset 14254
77edc7a6191a
parent 14253
b63ebf84c42b
child 14312
6ce4512aa9a8
equal deleted inserted replaced
14253:b63ebf84c42b 14254:77edc7a6191a
1 /*
2 * novell.c
3 *
4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21 #include "internal.h"
22 #include "accountopt.h"
23 #include "debug.h"
24 #include "prpl.h"
25 #include "server.h"
26 #include "nmuser.h"
27 #include "notify.h"
28 #include "util.h"
29 #include "sslconn.h"
30 #include "request.h"
31 #include "network.h"
32 #include "privacy.h"
33 #include "status.h"
34 #include "version.h"
35
36 #define DEFAULT_PORT 8300
37 #define NOVELL_CONNECT_STEPS 4
38 #define NM_ROOT_FOLDER_NAME "GroupWise Messenger"
39
40 #define NOVELL_STATUS_TYPE_AVAILABLE "available"
41 #define NOVELL_STATUS_TYPE_AWAY "away"
42 #define NOVELL_STATUS_TYPE_BUSY "busy"
43 #define NOVELL_STATUS_TYPE_OFFLINE "offline"
44 #define NOVELL_STATUS_TYPE_IDLE "idle"
45 #define NOVELL_STATUS_TYPE_APPEAR_OFFLINE "appearoffline"
46
47 static GaimPlugin *my_protocol = NULL;
48
49 static gboolean
50 _is_disconnect_error(NMERR_T err);
51
52 static gboolean
53 _check_for_disconnect(NMUser * user, NMERR_T err);
54
55 static void
56 _send_message(NMUser * user, NMMessage * message);
57
58 static void
59 _update_buddy_status(NMUser *user, GaimBuddy * buddy, int status, int gmt);
60
61 static void
62 _remove_gaim_buddies(NMUser * user);
63
64 static void
65 _add_contacts_to_gaim_blist(NMUser * user, NMFolder * folder);
66
67 static void
68 _add_gaim_buddies(NMUser * user);
69
70 static void
71 _sync_contact_list(NMUser *user);
72
73 static void
74 _sync_privacy_lists(NMUser *user);
75
76 static void
77 _show_info(GaimConnection * gc, NMUserRecord * user_record);
78
79 const char *
80 _get_conference_name(int id);
81
82 /*******************************************************************************
83 * Response callbacks
84 *******************************************************************************/
85
86 /* Handle login response */
87 static void
88 _login_resp_cb(NMUser * user, NMERR_T ret_code,
89 gpointer resp_data, gpointer user_data)
90 {
91 GaimConnection *gc;
92 const char *alias;
93 NMERR_T rc;
94
95 if (user == NULL)
96 return;
97
98 gc = gaim_account_get_connection(user->client_data);
99 if (gc == NULL)
100 return;
101
102 if (ret_code == NM_OK) {
103
104 /* Set alias for user if not set (use Full Name) */
105 alias = gaim_account_get_alias(user->client_data);
106 if (alias == NULL || *alias == '\0') {
107 alias = nm_user_record_get_full_name(user->user_record);
108
109 if (alias)
110 gaim_account_set_alias(user->client_data, alias);
111 }
112
113 /* Tell Gaim that we are connected */
114 gaim_connection_set_state(gc, GAIM_CONNECTED);
115
116 _sync_contact_list(user);
117
118 rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL,
119 NULL);
120 _check_for_disconnect(user, rc);
121
122 } else {
123
124 char *err = g_strdup_printf(_("Login failed (%s)."),
125 nm_error_to_string (ret_code));
126
127 /* Don't attempt to auto-reconnect if our password
128 * was invalid.
129 */
130 if (ret_code == NMERR_AUTHENTICATION_FAILED ||
131 ret_code == NMERR_CREDENTIALS_MISSING ||
132 ret_code == NMERR_PASSWORD_INVALID) {
133 gc->wants_to_die = TRUE;
134 }
135 gaim_connection_error(gc, err);
136 g_free(err);
137 }
138 }
139
140 /* Handle getstatus response*/
141 static void
142 _get_status_resp_cb(NMUser * user, NMERR_T ret_code,
143 gpointer resp_data, gpointer user_data)
144 {
145 GaimBuddy *buddy;
146 GSList *buddies;
147 GSList *bnode;
148 NMUserRecord *user_record = (NMUserRecord *) resp_data;
149 int status;
150
151 if (user == NULL || user_record == NULL)
152 return;
153
154 if (ret_code == NM_OK) {
155
156 /* Find all Gaim buddies and update their statuses */
157 const char *name = nm_user_record_get_display_id(user_record);
158
159 if (name) {
160 buddies = gaim_find_buddies((GaimAccount *) user->client_data, name);
161 for (bnode = buddies; bnode; bnode = bnode->next) {
162 buddy = (GaimBuddy *) bnode->data;
163 if (buddy) {
164 status = nm_user_record_get_status(user_record);
165 _update_buddy_status(user, buddy, status, time(0));
166 }
167 }
168 g_slist_free(buddies);
169 }
170
171 } else {
172
173 gaim_debug(GAIM_DEBUG_INFO, "novell",
174 "_get_status_resp_cb(): rc = 0x%X\n", ret_code);
175
176 }
177 }
178
179 /* Show an error if the rename failed */
180 static void
181 _rename_contact_resp_cb(NMUser * user, NMERR_T ret_code,
182 gpointer resp_data, gpointer user_data)
183 {
184 if (ret_code != NM_OK) {
185 gaim_debug(GAIM_DEBUG_INFO, "novell",
186 "_rename_contact_resp_cb(): rc = 0x%X\n", ret_code);
187 }
188 }
189
190 /* Handle the getdetails response and send the message */
191 static void
192 _get_details_resp_send_msg(NMUser * user, NMERR_T ret_code,
193 gpointer resp_data, gpointer user_data)
194 {
195 GaimConversation *gconv;
196 GaimConnection *gc;
197 NMUserRecord *user_record = NULL;
198 NMContact *cntct = NULL;
199 NMConference *conf;
200 NMMessage *msg = user_data;
201 const char *dn = NULL;
202 const char *name;
203
204 if (user == NULL || msg == NULL)
205 return;
206
207 if (ret_code == NM_OK) {
208 user_record = (NMUserRecord *) resp_data;
209 if (user_record) {
210
211 /* Set the title for the conversation */
212 /* XXX - Should this be GAIM_CONV_TYPE_IM? */
213 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY,
214 nm_user_record_get_display_id(user_record),
215 (GaimAccount *) user->client_data);
216 if (gconv) {
217
218 dn = nm_user_record_get_dn(user_record);
219 if (dn) {
220 cntct = nm_find_contact(user, dn);
221 }
222
223 if (cntct) {
224 gaim_conversation_set_title(gconv,
225 nm_contact_get_display_name(cntct));
226 } else {
227
228 /* Not in the contact list, try to user full name */
229 name = (char *) nm_user_record_get_full_name(user_record);
230 if (name)
231 gaim_conversation_set_title(gconv, name);
232 }
233 }
234
235 /* Add the user record to particpant list */
236 conf = nm_message_get_conference(msg);
237 if (conf) {
238 nm_conference_add_participant(conf, user_record);
239 _send_message(user, msg);
240 }
241 }
242
243 } else {
244
245 gc = gaim_account_get_connection(user->client_data);
246 if (gc != NULL) {
247 char *err = g_strdup_printf(_("Unable to send message."
248 " Could not get details for user (%s)."),
249 nm_error_to_string (ret_code));
250
251 gaim_notify_error(gc, NULL, err, NULL);
252 g_free(err);
253 }
254
255 if (msg)
256 nm_release_message(msg);
257 }
258 }
259
260 /* Set up the new GaimBuddy based on the response from getdetails */
261 static void
262 _get_details_resp_setup_buddy(NMUser * user, NMERR_T ret_code,
263 gpointer resp_data, gpointer user_data)
264 {
265 NMUserRecord *user_record;
266 NMContact *contact;
267 GaimBuddy *buddy;
268 const char *alias;
269 NMERR_T rc = NM_OK;
270
271 if (user == NULL || resp_data == NULL || user_data == NULL)
272 return;
273
274 contact = user_data;
275
276 if (ret_code == NM_OK) {
277 user_record = resp_data;
278
279 buddy = nm_contact_get_data(contact);
280
281 nm_contact_set_user_record(contact, user_record);
282
283 /* Set the display id */
284 gaim_blist_rename_buddy(buddy,
285 nm_user_record_get_display_id(user_record));
286
287 alias = gaim_buddy_get_alias(buddy);
288 if (alias == NULL || *alias == '\0' || (strcmp(alias, buddy->name) == 0)) {
289 gaim_blist_alias_buddy(buddy,
290 nm_user_record_get_full_name(user_record));
291
292 /* Tell the server about the new display name */
293 rc = nm_send_rename_contact(user, contact,
294 nm_user_record_get_full_name(user_record),
295 NULL, NULL);
296 _check_for_disconnect(user, rc);
297
298 }
299
300
301 /* Get initial status for the buddy */
302 rc = nm_send_get_status(user, resp_data, _get_status_resp_cb, NULL);
303 _check_for_disconnect(user, rc);
304
305 /* nm_release_contact(contact);*/
306
307 }
308
309 if (contact)
310 nm_release_contact(contact);
311 }
312
313 /* Add the new contact into the GaimBuddy list */
314 static void
315 _create_contact_resp_cb(NMUser * user, NMERR_T ret_code,
316 gpointer resp_data, gpointer user_data)
317 {
318 NMContact *tmp_contact = (NMContact *) user_data;
319 NMContact *new_contact = NULL;
320 NMFolder *folder = NULL;
321 GaimGroup *group;
322 GaimBuddy *buddy;
323 const char *folder_name = NULL;
324 NMERR_T rc = NM_OK;
325
326 if (user == NULL)
327 return;
328
329 if (ret_code == NM_OK) {
330
331 new_contact = (NMContact *) resp_data;
332 if (new_contact == NULL || tmp_contact == NULL)
333 return;
334
335 /* Get the userid and folder name for the new contact */
336 folder = nm_find_folder_by_id(user,
337 nm_contact_get_parent_id(new_contact));
338 if (folder) {
339 folder_name = nm_folder_get_name(folder);
340 }
341
342 if (folder_name == NULL || *folder_name == '\0')
343 folder_name = NM_ROOT_FOLDER_NAME;
344
345 /* Re-add the buddy now that we got the okay from the server */
346 if (folder_name && (group = gaim_find_group(folder_name))) {
347
348 const char *alias = nm_contact_get_display_name(tmp_contact);
349 const char *display_id = nm_contact_get_display_id(new_contact);
350
351 if (display_id == NULL)
352 display_id = nm_contact_get_dn(new_contact);
353
354 if (alias && strcmp(alias, display_id)) {
355
356 /* The user requested an alias, tell the server about it. */
357 rc = nm_send_rename_contact(user, new_contact, alias,
358 _rename_contact_resp_cb, NULL);
359 _check_for_disconnect(user, rc);
360
361 } else {
362
363 alias = "";
364
365 }
366
367 /* Add it to the gaim buddy list if it is not there */
368 buddy = gaim_find_buddy_in_group(user->client_data, display_id, group);
369 if (buddy == NULL) {
370 buddy = gaim_buddy_new(user->client_data, display_id, alias);
371 gaim_blist_add_buddy(buddy, NULL, group, NULL);
372 }
373
374 /* Save the new buddy as part of the contact object */
375 nm_contact_set_data(new_contact, (gpointer) buddy);
376
377 /* We need details for the user before we can setup the
378 * new Gaim buddy. We always call this because the
379 * 'createcontact' response fields do not always contain
380 * everything that we need.
381 */
382 nm_contact_add_ref(new_contact);
383
384 rc = nm_send_get_details(user, nm_contact_get_dn(new_contact),
385 _get_details_resp_setup_buddy, new_contact);
386 _check_for_disconnect(user, rc);
387
388 }
389
390 } else {
391 GaimConnection *gc = gaim_account_get_connection(user->client_data);
392 const char *name = nm_contact_get_dn(tmp_contact);
393 char *err;
394
395 err =
396 g_strdup_printf(_("Unable to add %s to your buddy list (%s)."),
397 name, nm_error_to_string (ret_code));
398 gaim_notify_error(gc, NULL, err, NULL);
399 g_free(err);
400
401 }
402
403 if (tmp_contact)
404 nm_release_contact(tmp_contact);
405 }
406
407 /* Show an error if we failed to send the message */
408 static void
409 _send_message_resp_cb(NMUser * user, NMERR_T ret_code,
410 gpointer resp_data, gpointer user_data)
411 {
412 GaimConnection *gc;
413 char *err = NULL;
414
415 if (user == NULL)
416 return;
417
418 if (ret_code != NM_OK) {
419 gc = gaim_account_get_connection(user->client_data);
420
421 /* TODO: Improve this! message to who or for what conference? */
422 err = g_strdup_printf(_("Unable to send message (%s)."),
423 nm_error_to_string (ret_code));
424 gaim_notify_error(gc, NULL, err, NULL);
425 g_free(err);
426 }
427 }
428
429 /* Show an error if the remove failed */
430 static void
431 _remove_contact_resp_cb(NMUser * user, NMERR_T ret_code,
432 gpointer resp_data, gpointer user_data)
433 {
434 if (ret_code != NM_OK) {
435 /* TODO: Display an error? */
436
437 gaim_debug(GAIM_DEBUG_INFO, "novell",
438 "_remove_contact_resp_cb(): rc = 0x%x\n", ret_code);
439 }
440 }
441
442 /* Show an error if the remove failed */
443 static void
444 _remove_folder_resp_cb(NMUser * user, NMERR_T ret_code,
445 gpointer resp_data, gpointer user_data)
446 {
447 if (ret_code != NM_OK) {
448 /* TODO: Display an error? */
449
450 gaim_debug(GAIM_DEBUG_INFO, "novell",
451 "_remove_folder_resp_cb(): rc = 0x%x\n", ret_code);
452 }
453 }
454
455 /* Show an error if the move failed */
456 static void
457 _move_contact_resp_cb(NMUser * user, NMERR_T ret_code,
458 gpointer resp_data, gpointer user_data)
459 {
460 if (ret_code != NM_OK) {
461 /* TODO: Display an error? */
462
463 gaim_debug(GAIM_DEBUG_INFO, "novell",
464 "_move_contact_resp_cb(): rc = 0x%x\n", ret_code);
465 }
466 }
467
468 /* Show an error if the rename failed */
469 static void
470 _rename_folder_resp_cb(NMUser * user, NMERR_T ret_code,
471 gpointer resp_data, gpointer user_data)
472 {
473 if (ret_code != NM_OK) {
474 /* TODO: Display an error? */
475
476 gaim_debug(GAIM_DEBUG_INFO, "novell",
477 "_rename_folder_resp_cb(): rc = 0x%x\n", ret_code);
478 }
479 }
480
481 static void
482 _sendinvite_resp_cb(NMUser *user, NMERR_T ret_code,
483 gpointer resp_data, gpointer user_data)
484 {
485 char *err;
486 GaimConnection *gc;
487
488 if (user == NULL)
489 return;
490
491 if (ret_code != NM_OK) {
492 gc = gaim_account_get_connection(user->client_data);
493 err = g_strdup_printf(_("Unable to invite user (%s)."), nm_error_to_string(ret_code));
494 gaim_notify_error(gc, NULL, err, NULL);
495 g_free(err);
496
497 gaim_debug(GAIM_DEBUG_INFO, "novell",
498 "_sendinvite_resp_cb(): rc = 0x%x\n", ret_code);
499 }
500
501 }
502
503 /* If the createconf was successful attempt to send the message,
504 * otherwise display an error message to the user.
505 */
506 static void
507 _createconf_resp_send_msg(NMUser * user, NMERR_T ret_code,
508 gpointer resp_data, gpointer user_data)
509 {
510 NMConference *conf;
511 NMMessage *msg = user_data;
512
513 if (user == NULL || msg == NULL)
514 return;
515
516 if (ret_code == NM_OK) {
517 _send_message(user, msg);
518 } else {
519
520 if ((conf = nm_message_get_conference(msg))) {
521
522 GaimConnection *gc = gaim_account_get_connection(user->client_data);
523 const char *name = NULL;
524 char *err;
525 NMUserRecord *ur;
526
527 ur = nm_conference_get_participant(conf, 0);
528 if (ur)
529 name = nm_user_record_get_userid(ur);
530
531 if (name)
532 err = g_strdup_printf(_("Unable to send message to %s."
533 " Could not create the conference (%s)."),
534 name,
535 nm_error_to_string (ret_code));
536 else
537 err = g_strdup_printf(_("Unable to send message."
538 " Could not create the conference (%s)."),
539 nm_error_to_string (ret_code));
540
541 gaim_notify_error(gc, NULL, err, NULL);
542 g_free(err);
543 }
544
545 if (msg)
546 nm_release_message(msg);
547 }
548 }
549
550 /* Move contact to newly created folder */
551 static void
552 _create_folder_resp_move_contact(NMUser * user, NMERR_T ret_code,
553 gpointer resp_data, gpointer user_data)
554 {
555 NMContact *contact = user_data;
556 NMFolder *new_folder;
557 char *folder_name = resp_data;
558 NMERR_T rc = NM_OK;
559
560 if (user == NULL || folder_name == NULL || contact == NULL) {
561
562 if (folder_name)
563 g_free(folder_name);
564
565 return;
566 }
567
568 if (ret_code == NM_OK || ret_code == NMERR_DUPLICATE_FOLDER) {
569 new_folder = nm_find_folder(user, folder_name);
570 if (new_folder) {
571
572 /* Tell the server to move the contact to the new folder */
573 /* rc = nm_send_move_contact(user, contact, new_folder,
574 _move_contact_resp_cb, NULL); */
575
576 rc = nm_send_create_contact(user, new_folder, contact,
577 NULL, NULL);
578
579 _check_for_disconnect(user, rc);
580
581 }
582 } else {
583 GaimConnection *gc = gaim_account_get_connection(user->client_data);
584 char *err = g_strdup_printf(_("Unable to move user %s"
585 " to folder %s in the server side list."
586 " Error while creating folder (%s)."),
587 nm_contact_get_dn(contact),
588 folder_name,
589 nm_error_to_string (ret_code));
590
591 gaim_notify_error(gc, NULL, err, NULL);
592 g_free(err);
593 }
594
595 if (folder_name)
596 g_free(folder_name);
597 }
598
599 /* Add contact to newly create folder */
600 static void
601 _create_folder_resp_add_contact(NMUser * user, NMERR_T ret_code,
602 gpointer resp_data, gpointer user_data)
603 {
604 NMContact *contact = (NMContact *) user_data;
605 NMFolder *folder;
606 char *folder_name = (char *) resp_data;
607 NMERR_T rc = NM_OK;
608
609 if (user == NULL || folder_name == NULL || contact == NULL) {
610
611 if (contact)
612 nm_release_contact(contact);
613
614 if (folder_name)
615 g_free(folder_name);
616
617 return;
618 }
619
620 if (ret_code == NM_OK || ret_code == NMERR_DUPLICATE_FOLDER) {
621 folder = nm_find_folder(user, folder_name);
622 if (folder) {
623
624 rc = nm_send_create_contact(user, folder, contact,
625 _create_contact_resp_cb, contact);
626 _check_for_disconnect(user, rc);
627 }
628 } else {
629 GaimConnection *gc = gaim_account_get_connection(user->client_data);
630 const char *name = nm_contact_get_dn(contact);
631 char *err =
632 g_strdup_printf(_("Unable to add %s to your buddy list."
633 " Error creating folder in server side list (%s)."),
634 name, nm_error_to_string (ret_code));
635
636 gaim_notify_error(gc, NULL, err, NULL);
637
638 nm_release_contact(contact);
639 g_free(err);
640 }
641
642 g_free(folder_name);
643 }
644
645 static void
646 _join_conf_resp_cb(NMUser * user, NMERR_T ret_code,
647 gpointer resp_data, gpointer user_data)
648 {
649 GaimConversation *chat;
650 GaimConnection *gc;
651 NMUserRecord *ur;
652 NMConference *conference = user_data;
653 const char *name, *conf_name;
654 int i, count;
655
656 if (user == NULL || conference == NULL)
657 return;
658
659 gc = gaim_account_get_connection(user->client_data);
660
661 if (ret_code == NM_OK) {
662 conf_name = _get_conference_name(++user->conference_count);
663 chat = serv_got_joined_chat(gc, user->conference_count, conf_name);
664 if (chat) {
665
666 nm_conference_set_data(conference, (gpointer) chat);
667
668 count = nm_conference_get_participant_count(conference);
669 for (i = 0; i < count; i++) {
670 ur = nm_conference_get_participant(conference, i);
671 if (ur) {
672 name = nm_user_record_get_display_id(ur);
673 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL,
674 GAIM_CBFLAGS_NONE, TRUE);
675 }
676 }
677 }
678 }
679 }
680
681 /* Show info returned by getdetails */
682 static void
683 _get_details_resp_show_info(NMUser * user, NMERR_T ret_code,
684 gpointer resp_data, gpointer user_data)
685 {
686 GaimConnection *gc;
687 NMUserRecord *user_record;
688 char *name;
689 char *err;
690
691 if (user == NULL)
692 return;
693
694 name = user_data;
695
696 if (ret_code == NM_OK) {
697 user_record = (NMUserRecord *) resp_data;
698 if (user_record) {
699 _show_info(gaim_account_get_connection(user->client_data),
700 user_record);
701 }
702 } else {
703 gc = gaim_account_get_connection(user->client_data);
704 err =
705 g_strdup_printf(_("Could not get details for user %s (%s)."),
706 name, nm_error_to_string (ret_code));
707 gaim_notify_error(gc, NULL, err, NULL);
708 g_free(err);
709 }
710
711 if (name)
712 g_free(name);
713 }
714
715 /* Handle get details response add to privacy list */
716 static void
717 _get_details_resp_add_privacy_item(NMUser *user, NMERR_T ret_code,
718 gpointer resp_data, gpointer user_data)
719 {
720 GaimConnection *gc;
721 NMUserRecord *user_record = resp_data;
722 char *err;
723 gboolean allowed = GPOINTER_TO_INT(user_data);
724 const char *display_id;
725
726 if (user == NULL)
727 return;
728
729 gc = gaim_account_get_connection(user->client_data);
730 display_id = nm_user_record_get_display_id(user_record);
731
732 if (ret_code == NM_OK) {
733
734 if (allowed) {
735
736 if (!g_slist_find_custom(gc->account->permit,
737 display_id, (GCompareFunc)nm_utf8_strcasecmp)) {
738 gaim_privacy_permit_add(gc->account, display_id, TRUE);
739 }
740
741 } else {
742
743 if (!g_slist_find_custom(gc->account->permit,
744 display_id, (GCompareFunc)nm_utf8_strcasecmp)) {
745 gaim_privacy_deny_add(gc->account, display_id, TRUE);
746 }
747 }
748
749 } else {
750
751 err = g_strdup_printf(_("Unable to add user to privacy list (%s)."),
752 nm_error_to_string(ret_code));
753 gaim_notify_error(gc, NULL, err, NULL);
754 g_free(err);
755
756 }
757 }
758
759 /* Handle response to create privacy item request */
760 static void
761 _create_privacy_item_deny_resp_cb(NMUser *user, NMERR_T ret_code,
762 gpointer resp_data, gpointer user_data)
763 {
764 GaimConnection *gc;
765 NMUserRecord *user_record;
766 char *who = user_data;
767 char *err;
768 NMERR_T rc = NM_OK;
769 const char *display_id = NULL;
770
771 if (user == NULL)
772 return;
773
774 gc = gaim_account_get_connection(user->client_data);
775
776 if (ret_code == NM_OK) {
777
778 user_record = nm_find_user_record(user, who);
779 if (user_record)
780 display_id = nm_user_record_get_display_id(user_record);
781
782 if (display_id) {
783
784 if (!g_slist_find_custom(gc->account->deny,
785 display_id, (GCompareFunc)nm_utf8_strcasecmp)) {
786
787 gaim_privacy_deny_add(gc->account, display_id, TRUE);
788 }
789
790 } else {
791 rc = nm_send_get_details(user, who,
792 _get_details_resp_add_privacy_item,
793 (gpointer)FALSE);
794 _check_for_disconnect(user, rc);
795 }
796 } else {
797
798 err = g_strdup_printf(_("Unable to add %s to deny list (%s)."),
799 who, nm_error_to_string(ret_code));
800 gaim_notify_error(gc, NULL, err, NULL);
801 g_free(err);
802
803 }
804
805 if (who)
806 g_free(who);
807
808 }
809
810 /* Handle response to create privacy item request */
811 static void
812 _create_privacy_item_permit_resp_cb(NMUser *user, NMERR_T ret_code,
813 gpointer resp_data, gpointer user_data)
814 {
815 GaimConnection *gc;
816 NMUserRecord *user_record;
817 char *who = user_data;
818 char *err;
819 NMERR_T rc = NM_OK;
820 const char *display_id = NULL;
821
822 if (user == NULL)
823 return;
824
825 gc = gaim_account_get_connection(user->client_data);
826
827 if (ret_code == NM_OK) {
828
829 user_record = nm_find_user_record(user, who);
830 if (user_record)
831 display_id = nm_user_record_get_display_id(user_record);
832
833 if (display_id) {
834
835 if (!g_slist_find_custom(gc->account->permit,
836 display_id,
837 (GCompareFunc)nm_utf8_strcasecmp)) {
838
839 gaim_privacy_permit_add(gc->account, display_id, TRUE);
840 }
841
842 } else {
843 rc = nm_send_get_details(user, who,
844 _get_details_resp_add_privacy_item,
845 (gpointer)TRUE);
846 _check_for_disconnect(user, rc);
847 }
848
849 } else {
850
851 err = g_strdup_printf(_("Unable to add %s to permit list (%s)."), who,
852 nm_error_to_string(ret_code));
853 gaim_notify_error(gc, NULL, err, NULL);
854 g_free(err);
855
856 }
857
858 if (who)
859 g_free(who);
860 }
861
862 static void
863 _get_details_send_privacy_create(NMUser *user, NMERR_T ret_code,
864 gpointer resp_data, gpointer user_data)
865 {
866 NMERR_T rc = NM_OK;
867 GaimConnection *gc;
868 NMUserRecord *user_record = resp_data;
869 char *err;
870 gboolean allowed = GPOINTER_TO_INT(user_data);
871 const char *dn, *display_id;
872
873 if (user == NULL)
874 return;
875
876 gc = gaim_account_get_connection(user->client_data);
877 dn = nm_user_record_get_dn(user_record);
878 display_id = nm_user_record_get_display_id(user_record);
879
880 if (ret_code == NM_OK) {
881
882 if (allowed) {
883 rc = nm_send_create_privacy_item(user, dn, TRUE,
884 _create_privacy_item_permit_resp_cb,
885 g_strdup(display_id));
886 _check_for_disconnect(user, rc);
887
888 } else {
889 rc = nm_send_create_privacy_item(user, dn, FALSE,
890 _create_privacy_item_deny_resp_cb,
891 g_strdup(display_id));
892 _check_for_disconnect(user, rc);
893 }
894
895 } else {
896
897 err = g_strdup_printf(_("Unable to add user to privacy list (%s)."),
898 nm_error_to_string(ret_code));
899 gaim_notify_error(gc, NULL, err, NULL);
900 g_free(err);
901
902 }
903 }
904
905 static void
906 _remove_privacy_item_resp_cb(NMUser *user, NMERR_T ret_code,
907 gpointer resp_data, gpointer user_data)
908 {
909 GaimConnection *gc;
910 char *who = user_data;
911 char *err;
912
913 if (user == NULL)
914 return;
915
916 if (ret_code != NM_OK) {
917
918 gc = gaim_account_get_connection(user->client_data);
919 err = g_strdup_printf(_("Unable to remove %s from privacy list (%s)."), who,
920 nm_error_to_string(ret_code));
921 gaim_notify_error(gc, NULL, err, NULL);
922 g_free(err);
923 }
924
925 if (who)
926 g_free(who);
927 }
928
929 static void
930 _set_privacy_default_resp_cb(NMUser *user, NMERR_T ret_code,
931 gpointer resp_data, gpointer user_data)
932 {
933 GaimConnection *gc;
934 char *err;
935
936 if (user == NULL)
937 return;
938
939 if (ret_code != NM_OK) {
940
941 gc = gaim_account_get_connection(user->client_data);
942 err = g_strdup_printf(_("Unable to change server side privacy settings (%s)."),
943 nm_error_to_string(ret_code));
944 gaim_notify_error(gc, NULL, err, NULL);
945 g_free(err);
946
947 }
948 }
949
950 /* Handle get details response add to privacy list */
951 static void
952 _get_details_resp_send_invite(NMUser *user, NMERR_T ret_code,
953 gpointer resp_data, gpointer user_data)
954 {
955 NMERR_T rc = NM_OK;
956 GaimConnection *gc;
957 NMUserRecord *user_record = resp_data;
958 char *err;
959 GSList *cnode;
960 NMConference *conference;
961 gpointer chat;
962 long id = (long) user_data;
963
964 if (user == NULL)
965 return;
966
967 gc = gaim_account_get_connection(user->client_data);
968
969 if (ret_code == NM_OK) {
970
971 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {
972 conference = cnode->data;
973 if (conference && (chat = nm_conference_get_data(conference))) {
974 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) {
975 rc = nm_send_conference_invite(user, conference, user_record,
976 NULL, _sendinvite_resp_cb, NULL);
977 _check_for_disconnect(user, rc);
978 break;
979 }
980 }
981 }
982
983 } else {
984
985 err = g_strdup_printf(_("Unable to invite user (%s)."), nm_error_to_string(ret_code));
986 gaim_notify_error(gc, NULL, err, NULL);
987 g_free(err);
988
989 }
990 }
991
992 static void
993 _createconf_resp_send_invite(NMUser * user, NMERR_T ret_code,
994 gpointer resp_data, gpointer user_data)
995 {
996 NMERR_T rc = NM_OK;
997 NMConference *conference = resp_data;
998 NMUserRecord *user_record = user_data;
999 GaimConnection *gc;
1000 char *err;
1001
1002 if (user == NULL)
1003 return;
1004
1005
1006
1007 if (ret_code == NM_OK) {
1008 rc = nm_send_conference_invite(user, conference, user_record,
1009 NULL, _sendinvite_resp_cb, NULL);
1010 _check_for_disconnect(user, rc);
1011 } else {
1012 err = g_strdup_printf(_("Unable to create conference (%s)."), nm_error_to_string(ret_code));
1013 gc = gaim_account_get_connection(user->client_data);
1014 gaim_notify_error(gc, NULL, err, NULL);
1015 g_free(err);
1016 }
1017 }
1018
1019 /*******************************************************************************
1020 * Helper functions
1021 ******************************************************************************/
1022
1023 static char *
1024 _user_agent_string()
1025 {
1026
1027 #if !defined(_WIN32)
1028
1029 const char *sysname = "";
1030 const char *release = "";
1031 struct utsname u;
1032
1033 if (uname(&u) == 0) {
1034 sysname = u.sysname;
1035 release = u.release;
1036 } else {
1037 sysname = "Linux";
1038 release = "Unknown";
1039 }
1040
1041 return g_strdup_printf("Gaim/%s (%s; %s)", VERSION, sysname, release);
1042
1043 #else
1044
1045 const char *sysname = "";
1046 OSVERSIONINFO os_info;
1047 SYSTEM_INFO sys_info;
1048
1049 os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1050 GetVersionEx(&os_info);
1051 GetSystemInfo(&sys_info);
1052
1053 if (os_info.dwPlatformId == VER_PLATFORM_WIN32_NT) {
1054 switch (os_info.dwMajorVersion) {
1055 case 3:
1056 case 4:
1057 sysname = "Windows NT";
1058 break;
1059 case 5:
1060 switch (os_info.dwMinorVersion) {
1061 case 0:
1062 sysname = "Windows 2000";
1063 break;
1064 case 1:
1065 sysname = "Windows XP";
1066 break;
1067 case 2:
1068 sysname = "Windows Server 2003";
1069 break;
1070 default:
1071 sysname = "Windows";
1072 break;
1073 }
1074 break;
1075 default:
1076 sysname = "Windows";
1077 break;
1078 }
1079
1080 } else if (os_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
1081 switch (os_info.dwMinorVersion) {
1082 case 0:
1083 sysname = "Windows 95";
1084 break;
1085 case 10:
1086 sysname = "Windows 98";
1087 break;
1088 case 90:
1089 sysname = "Windows ME";
1090 break;
1091 default:
1092 sysname = "Windows";
1093 break;
1094 }
1095 } else {
1096 sysname = "Windows";
1097 }
1098
1099 return g_strdup_printf("Gaim/%s (%s; %ld.%ld)", VERSION, sysname,
1100 os_info.dwMajorVersion, os_info.dwMinorVersion);
1101
1102 #endif
1103
1104
1105 }
1106
1107 static gboolean
1108 _is_disconnect_error(NMERR_T err)
1109 {
1110 return (err == NMERR_TCP_WRITE ||
1111 err == NMERR_TCP_READ || err == NMERR_PROTOCOL);
1112 }
1113
1114 static gboolean
1115 _check_for_disconnect(NMUser * user, NMERR_T err)
1116 {
1117 GaimConnection *gc = gaim_account_get_connection(user->client_data);
1118
1119 if (_is_disconnect_error(err)) {
1120
1121 gaim_connection_error(gc, _("Error communicating with server."
1122 " Closing connection."));
1123 return TRUE;
1124
1125 }
1126
1127 return FALSE;
1128 }
1129
1130 /* Check to see if the conference is instantiated, if so send the message.
1131 * If not send the create conference -- the response handler for the createconf
1132 * will call this function again.
1133 */
1134 static void
1135 _send_message(NMUser * user, NMMessage * message)
1136 {
1137 NMConference *conf;
1138 NMERR_T rc = NM_OK;
1139
1140 conf = nm_message_get_conference(message);
1141 if (conf) {
1142 /* We have a conference make sure that the
1143 server knows about it already. */
1144 if (nm_conference_is_instantiated(conf)) {
1145
1146 /* We have everything that we need...finally! */
1147 rc = nm_send_message(user, message, _send_message_resp_cb);
1148 _check_for_disconnect(user, rc);
1149
1150 nm_release_message(message);
1151
1152 } else {
1153 rc = nm_send_create_conference(user, conf, _createconf_resp_send_msg, message);
1154 _check_for_disconnect(user, rc);
1155 }
1156 }
1157 }
1158
1159 /*
1160 * Update the status of the given buddy in the Gaim buddy list
1161 */
1162 static void
1163 _update_buddy_status(NMUser *user, GaimBuddy * buddy, int novellstatus, int gmt)
1164 {
1165 GaimAccount *account;
1166 const char *status_id;
1167 const char *text = NULL;
1168 const char *dn;
1169 int idle = 0;
1170 gboolean loggedin = TRUE;
1171
1172 account = buddy->account;
1173
1174 switch (novellstatus) {
1175 case NM_STATUS_AVAILABLE:
1176 status_id = NOVELL_STATUS_TYPE_AVAILABLE;
1177 break;
1178 case NM_STATUS_AWAY:
1179 status_id = NOVELL_STATUS_TYPE_AWAY;
1180 break;
1181 case NM_STATUS_BUSY:
1182 status_id = NOVELL_STATUS_TYPE_BUSY;
1183 break;
1184 case NM_STATUS_OFFLINE:
1185 status_id = NOVELL_STATUS_TYPE_OFFLINE;
1186 loggedin = FALSE;
1187 break;
1188 case NM_STATUS_AWAY_IDLE:
1189 status_id = NOVELL_STATUS_TYPE_AWAY;
1190 idle = gmt;
1191 break;
1192 default:
1193 status_id = NOVELL_STATUS_TYPE_OFFLINE;
1194 loggedin = FALSE;
1195 break;
1196 }
1197
1198 /* Get status text for the user */
1199 dn = nm_lookup_dn(user, buddy->name);
1200 if (dn) {
1201 NMUserRecord *user_record = nm_find_user_record(user, dn);
1202 if (user_record) {
1203 text = nm_user_record_get_status_text(user_record);
1204 }
1205 }
1206
1207 gaim_prpl_got_user_status(account, buddy->name, status_id,
1208 "message", text, NULL);
1209 gaim_prpl_got_user_idle(account, buddy->name,
1210 (novellstatus == NM_STATUS_AWAY_IDLE), idle);
1211 }
1212
1213 /* Iterate through the cached Gaim buddy list and remove buddies
1214 * that are not in the server side list.
1215 */
1216 static void
1217 _remove_gaim_buddies(NMUser *user)
1218 {
1219 GaimBlistNode *gnode;
1220 GaimBlistNode *cnode;
1221 GaimBlistNode *bnode;
1222 GaimGroup *group;
1223 GaimBuddy *buddy;
1224 GaimBuddyList *blist;
1225 GSList *rem_list = NULL;
1226 GSList *l;
1227 NMFolder *folder = NULL;
1228 const char *gname = NULL;
1229
1230 if ((blist = gaim_get_blist())) {
1231 for (gnode = blist->root; gnode; gnode = gnode->next) {
1232 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
1233 continue;
1234 group = (GaimGroup *) gnode;
1235 for (cnode = gnode->child; cnode; cnode = cnode->next) {
1236 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
1237 continue;
1238 for (bnode = cnode->child; bnode; bnode = bnode->next) {
1239 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
1240 continue;
1241 buddy = (GaimBuddy *) bnode;
1242 if (buddy->account == user->client_data) {
1243 gname = group->name;
1244 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0)
1245 gname = "";
1246 folder = nm_find_folder(user, gname);
1247 if (folder == NULL ||
1248 !nm_folder_find_contact_by_display_id(folder, buddy->name)) {
1249 rem_list = g_slist_append(rem_list, buddy);
1250 }
1251 }
1252 }
1253 }
1254 }
1255
1256 if (rem_list) {
1257 for (l = rem_list; l; l = l->next) {
1258 gaim_blist_remove_buddy(l->data);
1259 }
1260 g_slist_free(rem_list);
1261 }
1262 }
1263 }
1264
1265 /* Add all of the contacts in the given folder to the Gaim buddy list */
1266 static void
1267 _add_contacts_to_gaim_blist(NMUser * user, NMFolder * folder)
1268 {
1269 NMUserRecord *user_record = NULL;
1270 NMContact *contact = NULL;
1271 GaimBuddy *buddy = NULL;
1272 GaimGroup *group;
1273 NMERR_T cnt = 0, i;
1274 const char *text = NULL;
1275 const char *name = NULL;
1276 const char *fname = NULL;
1277 int status = 0;
1278
1279 /* If this is the root folder give it a name. Gaim does not have the concept of
1280 * a root folder.
1281 */
1282 fname = nm_folder_get_name(folder);
1283 if (fname == NULL || *fname == '\0') {
1284 fname = NM_ROOT_FOLDER_NAME;
1285 }
1286
1287 /* Does the Gaim group exist already? */
1288 group = gaim_find_group(fname);
1289 if (group == NULL) {
1290 group = gaim_group_new(fname);
1291 gaim_blist_add_group(group, NULL);
1292 }
1293
1294 /* Get each contact for this folder */
1295 cnt = nm_folder_get_contact_count(folder);
1296 for (i = 0; i < cnt; i++) {
1297 contact = nm_folder_get_contact(folder, i);
1298 if (contact) {
1299
1300 name = nm_contact_get_display_id(contact);
1301 if (name) {
1302
1303 buddy = gaim_find_buddy_in_group(user->client_data, name, group);
1304 if (buddy == NULL) {
1305 /* Add it to the gaim buddy list */
1306 buddy = gaim_buddy_new(user->client_data,
1307 name,
1308 nm_contact_get_display_name(contact));
1309
1310 gaim_blist_add_buddy(buddy, NULL, group, NULL);
1311 }
1312
1313 /* Set the initial status for the buddy */
1314 user_record = nm_contact_get_user_record(contact);
1315 if (user_record) {
1316 status = nm_user_record_get_status(user_record);
1317 text = nm_user_record_get_status_text(user_record);
1318 }
1319 _update_buddy_status(user, buddy, status, time(0));
1320
1321 /* Save the new buddy as part of the contact object */
1322 nm_contact_set_data(contact, (gpointer) buddy);
1323 }
1324
1325 } else {
1326 /* NULL contact. This should not happen, but
1327 * let's break out of the loop.
1328 */
1329 break;
1330 }
1331 }
1332 }
1333
1334 /* Add all of the server side contacts to the Gaim buddy list. */
1335 static void
1336 _add_gaim_buddies(NMUser * user)
1337 {
1338 int cnt = 0, i;
1339 NMFolder *root_folder = NULL;
1340 NMFolder *folder = NULL;
1341
1342 root_folder = nm_get_root_folder(user);
1343 if (root_folder) {
1344
1345 /* Add sub-folders and contacts to sub-folders...
1346 * iterate throught the sub-folders in reverse order
1347 * because Gaim adds the folders to the front -- so we
1348 * want to add the first folder last
1349 */
1350 cnt = nm_folder_get_subfolder_count(root_folder);
1351 for (i = cnt-1; i >= 0; i--) {
1352 folder = nm_folder_get_subfolder(root_folder, i);
1353 if (folder) {
1354 _add_contacts_to_gaim_blist(user, folder);
1355 }
1356 }
1357
1358 /* Add contacts for the root folder */
1359 _add_contacts_to_gaim_blist(user, root_folder);
1360 }
1361 }
1362
1363 static void
1364 _sync_contact_list(NMUser *user)
1365 {
1366 /* Remove all buddies from the local list that are
1367 * not in the server side list and add all buddies
1368 * from the server side list that are not in
1369 * the local list
1370 */
1371 _remove_gaim_buddies(user);
1372 _add_gaim_buddies(user);
1373 user->clist_synched = TRUE;
1374 }
1375
1376 static void
1377 _sync_privacy_lists(NMUser *user)
1378 {
1379 GSList *node = NULL, *rem_list = NULL;
1380 GaimConnection *gc;
1381 const char *name, *dn;
1382 NMUserRecord *user_record;
1383
1384 if (user == NULL)
1385 return;
1386
1387 gc = gaim_account_get_connection(user->client_data);
1388 if (gc == NULL)
1389 return;
1390
1391 /* Set the Gaim privacy setting */
1392 if (user->default_deny) {
1393 if (user->allow_list == NULL) {
1394 gc->account->perm_deny = GAIM_PRIVACY_DENY_ALL;
1395 } else {
1396 gc->account->perm_deny = GAIM_PRIVACY_ALLOW_USERS;
1397 }
1398 } else {
1399 if (user->deny_list == NULL) {
1400 gc->account->perm_deny = GAIM_PRIVACY_ALLOW_ALL;
1401 } else {
1402 gc->account->perm_deny = GAIM_PRIVACY_DENY_USERS;
1403 }
1404 }
1405
1406 /* Add stuff */
1407 for (node = user->allow_list; node; node = node->next) {
1408 user_record = nm_find_user_record(user, (char *)node->data);
1409 if (user_record)
1410 name = nm_user_record_get_display_id(user_record);
1411 else
1412 name =(char *)node->data;
1413
1414 if (!g_slist_find_custom(gc->account->permit,
1415 name, (GCompareFunc)nm_utf8_strcasecmp)) {
1416 gaim_privacy_permit_add(gc->account, name , TRUE);
1417 }
1418 }
1419
1420 for (node = user->deny_list; node; node = node->next) {
1421 user_record = nm_find_user_record(user, (char *)node->data);
1422 if (user_record)
1423 name = nm_user_record_get_display_id(user_record);
1424 else
1425 name =(char *)node->data;
1426
1427 if (!g_slist_find_custom(gc->account->deny,
1428 name, (GCompareFunc)nm_utf8_strcasecmp)) {
1429 gaim_privacy_deny_add(gc->account, name, TRUE);
1430 }
1431 }
1432
1433
1434 /* Remove stuff */
1435 for (node = gc->account->permit; node; node = node->next) {
1436 dn = nm_lookup_dn(user, (char *)node->data);
1437 if (dn != NULL &&
1438 !g_slist_find_custom(user->allow_list,
1439 dn, (GCompareFunc)nm_utf8_strcasecmp)) {
1440 rem_list = g_slist_append(rem_list, node->data);
1441 }
1442 }
1443
1444 if (rem_list) {
1445 for (node = rem_list; node; node = node->next) {
1446 gaim_privacy_permit_remove(gc->account, (char *)node->data, TRUE);
1447 }
1448 g_free(rem_list);
1449 rem_list = NULL;
1450 }
1451
1452 for (node = gc->account->deny; node; node = node->next) {
1453 dn = nm_lookup_dn(user, (char *)node->data);
1454 if (dn != NULL &&
1455 !g_slist_find_custom(user->deny_list,
1456 dn, (GCompareFunc)nm_utf8_strcasecmp)) {
1457 rem_list = g_slist_append(rem_list, node->data);
1458 }
1459 }
1460
1461 if (rem_list) {
1462 for (node = rem_list; node; node = node->next) {
1463 gaim_privacy_deny_remove(gc->account, (char *)node->data, TRUE);
1464 }
1465 g_slist_free(rem_list);
1466 }
1467 }
1468
1469 /* Map known property tags to user-friendly strings */
1470 static const char *
1471 _map_property_tag(const char *tag)
1472 {
1473 if (tag == NULL) return NULL;
1474
1475 if (strcmp(tag, "telephoneNumber") == 0)
1476 return _("Telephone Number");
1477 else if (strcmp(tag, "L") == 0)
1478 return _("Location");
1479 else if (strcmp(tag, "OU") == 0)
1480 return _("Department");
1481 else if (strcmp(tag, "personalTitle") == 0)
1482 return _("Personal Title");
1483 else if (strcmp(tag, "Title") == 0)
1484 return _("Title");
1485 else if (strcmp(tag, "mailstop") == 0)
1486 return _("Mailstop");
1487 else if (strcmp(tag, "Internet EMail Address") == 0)
1488 return _("E-Mail Address");
1489 else
1490 return tag;
1491 }
1492
1493 /* Display a dialog box showing the properties for the given user record */
1494 static void
1495 _show_info(GaimConnection * gc, NMUserRecord * user_record)
1496 {
1497 GString *info_text;
1498 int count, i;
1499 NMProperty *property;
1500 const char *tag, *value;
1501
1502 info_text = g_string_new("");
1503
1504 tag = _("User ID");
1505 value = nm_user_record_get_userid(user_record);
1506 if (value) {
1507 g_string_append_printf(info_text, "<b>%s:</b> %s<br>", tag, value);
1508 }
1509
1510 /* tag = _("DN");
1511 value = nm_user_record_get_dn(user_record);
1512 if (value) {
1513 g_string_append_printf(info_text, "<b>%s:</b> %s<br>",
1514 tag, value);
1515 }
1516 */
1517
1518 tag = _("Full name");
1519 value = nm_user_record_get_full_name(user_record);
1520 if (value) {
1521 g_string_append_printf(info_text, "<b>%s:</b> %s<br>", tag, value);
1522 }
1523
1524 count = nm_user_record_get_property_count(user_record);
1525 for (i = 0; i < count; i++) {
1526 property = nm_user_record_get_property(user_record, i);
1527 if (property) {
1528 tag = _map_property_tag(nm_property_get_tag(property));
1529 value = nm_property_get_value(property);
1530 if (tag && value) {
1531 g_string_append_printf(info_text, "<b>%s:</b> %s<br>",
1532 tag, value);
1533 }
1534 nm_release_property(property);
1535 }
1536 }
1537
1538 gaim_notify_userinfo(gc, nm_user_record_get_userid(user_record),
1539 info_text->str, NULL, NULL);
1540
1541 g_string_free(info_text, TRUE);
1542 }
1543
1544 /* Send a join conference, the first item in the parms list is the
1545 * NMUser object and the second item is the conference to join.
1546 * This callback is passed to gaim_request_action when we ask the
1547 * user if they want to join the conference.
1548 */
1549 static void
1550 _join_conference_cb(GSList * parms)
1551 {
1552 NMUser *user;
1553 NMConference *conference;
1554 NMERR_T rc = NM_OK;
1555
1556 if (parms == NULL || g_slist_length(parms) != 2)
1557 return;
1558
1559 user = g_slist_nth_data(parms, 0);
1560 conference = g_slist_nth_data(parms, 1);
1561
1562 if (user && conference) {
1563 rc = nm_send_join_conference(user, conference,
1564 _join_conf_resp_cb, conference);
1565 _check_for_disconnect(user, rc);
1566 }
1567
1568 g_slist_free(parms);
1569 }
1570
1571 /* Send a reject conference, the first item in the parms list is the
1572 * NMUser object and the second item is the conference to reject.
1573 * This callback is passed to gaim_request_action when we ask the
1574 * user if they want to joing the conference.
1575 */
1576 static void
1577 _reject_conference_cb(GSList * parms)
1578 {
1579 NMUser *user;
1580 NMConference *conference;
1581 NMERR_T rc = NM_OK;
1582
1583 if (parms == NULL || g_slist_length(parms) != 2)
1584 return;
1585
1586 user = g_slist_nth_data(parms, 0);
1587 conference = g_slist_nth_data(parms, 1);
1588
1589 if (user && conference) {
1590 rc = nm_send_reject_conference(user, conference, NULL, NULL);
1591 _check_for_disconnect(user, rc);
1592 }
1593
1594 g_slist_free(parms);
1595 }
1596
1597 static void
1598 _initiate_conference_cb(GaimBlistNode *node, gpointer ignored)
1599 {
1600 GaimBuddy *buddy;
1601 GaimConnection *gc;
1602
1603 NMUser *user;
1604 const char *conf_name;
1605 GaimConversation *chat = NULL;
1606 NMUserRecord *user_record;
1607 NMConference *conference;
1608
1609 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
1610
1611 buddy = (GaimBuddy *) node;
1612 gc = gaim_account_get_connection(buddy->account);
1613
1614 user = gc->proto_data;
1615 if (user == NULL)
1616 return;
1617
1618 /* We should already have a userrecord for the buddy */
1619 user_record = nm_find_user_record(user, buddy->name);
1620 if (user_record == NULL)
1621 return;
1622
1623 conf_name = _get_conference_name(++user->conference_count);
1624 chat = serv_got_joined_chat(gc, user->conference_count, conf_name);
1625 if (chat) {
1626
1627 conference = nm_create_conference(NULL);
1628 nm_conference_set_data(conference, (gpointer) chat);
1629 nm_send_create_conference(user, conference, _createconf_resp_send_invite, user_record);
1630 nm_release_conference(conference);
1631 }
1632 }
1633
1634 const char *
1635 _get_conference_name(int id)
1636 {
1637 static char *name = NULL;
1638
1639 if (name)
1640 g_free(name);
1641
1642 name = g_strdup_printf(_("GroupWise Conference %d"), id);
1643
1644 return name;
1645 }
1646
1647 static void
1648 _show_privacy_locked_error(GaimConnection *gc, NMUser *user)
1649 {
1650 char *err;
1651
1652 err = g_strdup_printf(_("Unable to change server side privacy settings (%s)."),
1653 nm_error_to_string(NMERR_ADMIN_LOCKED));
1654 gaim_notify_error(gc, NULL, err, NULL);
1655 g_free(err);
1656 }
1657
1658 /*******************************************************************************
1659 * Connect and recv callbacks
1660 ******************************************************************************/
1661
1662 static void
1663 novell_ssl_connect_error(GaimSslConnection * gsc,
1664 GaimSslErrorType error, gpointer data)
1665 {
1666 gaim_connection_error((GaimConnection *)data,
1667 _("Unable to make SSL connection to server."));
1668 }
1669
1670 static void
1671 novell_ssl_recv_cb(gpointer data, GaimSslConnection * gsc,
1672 GaimInputCondition condition)
1673 {
1674 GaimConnection *gc = data;
1675 NMUser *user;
1676 NMERR_T rc;
1677
1678 if (gc == NULL)
1679 return;
1680
1681 user = gc->proto_data;
1682 if (user == NULL)
1683 return;
1684
1685 rc = nm_process_new_data(user);
1686 if (rc != NM_OK) {
1687
1688 if (_is_disconnect_error(rc)) {
1689
1690 gaim_connection_error(gc,
1691 _("Error communicating with server."
1692 " Closing connection."));
1693 } else {
1694 gaim_debug(GAIM_DEBUG_INFO, "novell",
1695 "Error processing event or response (%d).\n", rc);
1696 }
1697 }
1698 }
1699
1700 static void
1701 novell_ssl_connected_cb(gpointer data, GaimSslConnection * gsc,
1702 GaimInputCondition cond)
1703 {
1704 GaimConnection *gc = data;
1705 NMUser *user;
1706 NMConn *conn;
1707 NMERR_T rc = 0;
1708 const char *pwd = NULL;
1709 const char *my_addr = NULL;
1710 char *ua = NULL;
1711
1712 if (gc == NULL || gsc == NULL)
1713 return;
1714
1715 user = gc->proto_data;
1716 if ((user == NULL) || (conn = user->conn) == NULL)
1717 return;
1718
1719 conn->ssl_conn = g_new0(NMSSLConn, 1);
1720 conn->ssl_conn->data = gsc;
1721 conn->ssl_conn->read = (nm_ssl_read_cb) gaim_ssl_read;
1722 conn->ssl_conn->write = (nm_ssl_write_cb) gaim_ssl_write;
1723
1724 gaim_connection_update_progress(gc, _("Authenticating..."),
1725 2, NOVELL_CONNECT_STEPS);
1726
1727 my_addr = gaim_network_get_my_ip(gsc->fd);
1728 pwd = gaim_connection_get_password(gc);
1729 ua = _user_agent_string();
1730
1731 rc = nm_send_login(user, pwd, my_addr, ua, _login_resp_cb, NULL);
1732 if (rc == NM_OK) {
1733 conn->connected = TRUE;
1734 gaim_ssl_input_add(gsc, novell_ssl_recv_cb, gc);
1735 } else {
1736 gaim_connection_error(gc, _("Unable to connect to server."));
1737 }
1738
1739 gaim_connection_update_progress(gc, _("Waiting for response..."),
1740 3, NOVELL_CONNECT_STEPS);
1741
1742 g_free(ua);
1743 }
1744
1745 /*******************************************************************************
1746 * Event callback and event handlers
1747 ******************************************************************************/
1748
1749 static void
1750 _evt_receive_message(NMUser * user, NMEvent * event)
1751 {
1752 NMUserRecord *user_record = NULL;
1753 NMContact *contact = NULL;
1754 GaimConversation *gconv;
1755 NMConference *conference;
1756 GaimMessageFlags flags;
1757 char *text = NULL;
1758
1759 text = g_markup_escape_text(nm_event_get_text(event), -1);
1760
1761 conference = nm_event_get_conference(event);
1762 if (conference) {
1763
1764 GaimConversation *chat = nm_conference_get_data(conference);
1765
1766 /* Is this a single person 'conversation' or a conference? */
1767 if (chat == NULL && nm_conference_get_participant_count(conference) == 1) {
1768
1769 user_record = nm_find_user_record(user, nm_event_get_source(event));
1770 if (user_record) {
1771
1772 flags = 0;
1773 if (nm_event_get_type(event) == NMEVT_RECEIVE_AUTOREPLY)
1774 flags |= GAIM_MESSAGE_AUTO_RESP;
1775
1776 serv_got_im(gaim_account_get_connection(user->client_data),
1777 nm_user_record_get_display_id(user_record),
1778 text, flags,
1779 nm_event_get_gmt(event));
1780
1781 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
1782 nm_user_record_get_display_id(user_record),
1783 (GaimAccount *) user->client_data);
1784 if (gconv) {
1785
1786 contact = nm_find_contact(user, nm_event_get_source(event));
1787 if (contact) {
1788
1789 gaim_conversation_set_title(
1790 gconv, nm_contact_get_display_name(contact));
1791
1792
1793 } else {
1794
1795 const char *name =
1796 nm_user_record_get_full_name(user_record);
1797
1798 if (name == NULL)
1799 name = nm_user_record_get_userid(user_record);
1800
1801 gaim_conversation_set_title(gconv, name);
1802 }
1803
1804 }
1805
1806 } else {
1807 /* this should not happen, see the event code.
1808 * the event code will get the contact details from
1809 * the server if it does not have them before calling
1810 * the event callback.
1811 */
1812 }
1813
1814 } else if (chat) {
1815
1816 /* get the contact for send if we have one */
1817 NMContact *contact = nm_find_contact(user,
1818 nm_event_get_source(event));
1819
1820 /* get the user record for the sender */
1821 user_record = nm_find_user_record(user, nm_event_get_source(event));
1822 if (user_record) {
1823 const char *name = nm_contact_get_display_name(contact);
1824
1825 if (name == NULL) {
1826 name = nm_user_record_get_full_name(user_record);
1827 if (name == NULL)
1828 name = nm_user_record_get_display_id(user_record);
1829 }
1830
1831 serv_got_chat_in(gaim_account_get_connection(user->client_data),
1832 gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)),
1833 name, 0, text, nm_event_get_gmt(event));
1834 }
1835 }
1836 }
1837
1838 g_free(text);
1839 }
1840
1841 static void
1842 _evt_conference_left(NMUser * user, NMEvent * event)
1843 {
1844 GaimConversation *chat;
1845 NMConference *conference;
1846
1847 conference = nm_event_get_conference(event);
1848 if (conference) {
1849 chat = nm_conference_get_data(conference);
1850 if (chat) {
1851 NMUserRecord *ur = nm_find_user_record(user,
1852 nm_event_get_source(event));
1853
1854 if (ur)
1855 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat),
1856 nm_user_record_get_display_id(ur),
1857 NULL);
1858 }
1859 }
1860 }
1861
1862 static void
1863 _evt_conference_invite_notify(NMUser * user, NMEvent * event)
1864 {
1865 GaimConversation *gconv;
1866 NMConference *conference;
1867 NMUserRecord *user_record = NULL;
1868 char *str = NULL;
1869
1870 user_record = nm_find_user_record(user, nm_event_get_source(event));
1871 conference = nm_event_get_conference(event);
1872 if (user_record && conference) {
1873 gconv = nm_conference_get_data(conference);
1874 str = g_strdup_printf(_("%s has been invited to this conversation."),
1875 nm_user_record_get_display_id(user_record));
1876 gaim_conversation_write(gconv, NULL, str,
1877 GAIM_MESSAGE_SYSTEM, time(NULL));
1878 g_free(str);
1879 }
1880 }
1881
1882 static void
1883 _evt_conference_invite(NMUser * user, NMEvent * event)
1884 {
1885 NMUserRecord *ur;
1886 GaimConnection *gc;
1887 GSList *parms = NULL;
1888 const char *title = NULL;
1889 const char *secondary = NULL;
1890 const char *name = NULL;
1891 char *primary = NULL;
1892 time_t gmt;
1893
1894 ur = nm_find_user_record(user, nm_event_get_source(event));
1895 if (ur)
1896 name = nm_user_record_get_full_name(ur);
1897
1898 if (name == NULL)
1899 name = nm_event_get_source(event);
1900
1901 gmt = nm_event_get_gmt(event);
1902 title = _("Invitation to Conversation");
1903 primary = g_strdup_printf(_("Invitation from: %s\n\nSent: %s"),
1904 name, gaim_date_format_full(localtime(&gmt)));
1905 secondary = _("Would you like to join the conversation?");
1906
1907 /* Set up parms list for the callbacks
1908 * We need to send the NMUser object and
1909 * the NMConference object to the callbacks
1910 */
1911 parms = NULL;
1912 parms = g_slist_append(parms, user);
1913 parms = g_slist_append(parms, nm_event_get_conference(event));
1914
1915 /* Prompt the user */
1916 gc = gaim_account_get_connection(user->client_data);
1917 gaim_request_action(gc, title, primary, secondary,
1918 GAIM_DEFAULT_ACTION_NONE, parms, 2,
1919 _("Yes"), G_CALLBACK(_join_conference_cb),
1920 _("No"), G_CALLBACK(_reject_conference_cb));
1921
1922 g_free(primary);
1923 }
1924
1925
1926 static void
1927 _evt_conference_joined(NMUser * user, NMEvent * event)
1928 {
1929 GaimConversation *chat = NULL;
1930 GaimConnection *gc;
1931 NMConference *conference = NULL;
1932 NMUserRecord *ur = NULL;
1933 const char *name;
1934 const char *conf_name;
1935
1936 gc = gaim_account_get_connection(user->client_data);
1937 if (gc == NULL)
1938 return;
1939
1940 conference = nm_event_get_conference(event);
1941 if (conference) {
1942 chat = nm_conference_get_data(conference);
1943 if (nm_conference_get_participant_count(conference) == 2 && chat == NULL) {
1944 ur = nm_conference_get_participant(conference, 0);
1945 if (ur) {
1946 conf_name = _get_conference_name(++user->conference_count);
1947 chat =
1948 serv_got_joined_chat(gc, user->conference_count, conf_name);
1949 if (chat) {
1950
1951 nm_conference_set_data(conference, (gpointer) chat);
1952
1953 name = nm_user_record_get_display_id(ur);
1954 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL,
1955 GAIM_CBFLAGS_NONE, TRUE);
1956
1957 }
1958 }
1959 }
1960
1961 if (chat != NULL) {
1962 ur = nm_find_user_record(user, nm_event_get_source(event));
1963 if (ur) {
1964 name = nm_user_record_get_display_id(ur);
1965 if (!gaim_conv_chat_find_user(GAIM_CONV_CHAT(chat), name)) {
1966 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL,
1967 GAIM_CBFLAGS_NONE, TRUE);
1968 }
1969 }
1970 }
1971 }
1972 }
1973
1974 static void
1975 _evt_status_change(NMUser * user, NMEvent * event)
1976 {
1977 GaimBuddy *buddy = NULL;
1978 GSList *buddies;
1979 GSList *bnode;
1980 NMUserRecord *user_record;
1981 const char *display_id;
1982 int status;
1983
1984 user_record = nm_event_get_user_record(event);
1985 if (user_record) {
1986
1987 /* Retrieve new status */
1988 status = nm_user_record_get_status(user_record);
1989
1990 /* Update status for buddy in all folders */
1991 display_id = nm_user_record_get_display_id(user_record);
1992 buddies = gaim_find_buddies(user->client_data, display_id);
1993 for (bnode = buddies; bnode; bnode = bnode->next) {
1994 buddy = (GaimBuddy *) bnode->data;
1995 if (buddy) {
1996 _update_buddy_status(user, buddy, status, nm_event_get_gmt(event));
1997 }
1998 }
1999
2000 g_slist_free(buddies);
2001
2002 }
2003 }
2004
2005 static void
2006 _evt_user_disconnect(NMUser * user, NMEvent * event)
2007 {
2008 GaimConnection *gc;
2009
2010 gc = gaim_account_get_connection((GaimAccount *) user->client_data);
2011 if (gc)
2012 gaim_connection_error(gc, _("You have been logged out because you"
2013 " logged in at another workstation."));
2014 }
2015
2016 static void
2017 _evt_user_typing(NMUser * user, NMEvent * event)
2018 {
2019 GaimConnection *gc;
2020 NMUserRecord *user_record = NULL;
2021
2022 gc = gaim_account_get_connection((GaimAccount *) user->client_data);
2023 if (gc) {
2024 user_record = nm_find_user_record(user, nm_event_get_source(event));
2025 if (user_record) {
2026 serv_got_typing(gc, nm_user_record_get_display_id(user_record),
2027 30, GAIM_TYPING);
2028 }
2029 }
2030 }
2031
2032 static void
2033 _evt_user_not_typing(NMUser * user, NMEvent * event)
2034 {
2035 GaimConnection *gc;
2036 NMUserRecord *user_record;
2037
2038 gc = gaim_account_get_connection((GaimAccount *) user->client_data);
2039 if (gc) {
2040 user_record = nm_find_user_record(user, nm_event_get_source(event));
2041 if (user_record) {
2042 serv_got_typing_stopped(gc,
2043 nm_user_record_get_display_id(user_record));
2044 }
2045 }
2046 }
2047
2048 static void
2049 _evt_undeliverable_status(NMUser * user, NMEvent * event)
2050 {
2051 NMUserRecord *ur;
2052 GaimConversation *gconv;
2053 char *str;
2054
2055 ur = nm_find_user_record(user, nm_event_get_source(event));
2056 if (ur) {
2057 /* XXX - Should this be GAIM_CONV_TYPE_IM? */
2058 gconv =
2059 gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY,
2060 nm_user_record_get_display_id(ur),
2061 user->client_data);
2062 if (gconv) {
2063 const char *name = nm_user_record_get_full_name(ur);
2064
2065 if (name == NULL) {
2066 name = nm_user_record_get_display_id(ur);
2067 }
2068 str = g_strdup_printf(_("%s appears to be offline and did not receive"
2069 " the message that you just sent."), name);
2070 gaim_conversation_write(gconv, NULL, str,
2071 GAIM_MESSAGE_SYSTEM, time(NULL));
2072 g_free(str);
2073 }
2074 }
2075 }
2076
2077 static void
2078 _event_callback(NMUser * user, NMEvent * event)
2079 {
2080 if (user == NULL || event == NULL)
2081 return;
2082
2083 switch (nm_event_get_type(event)) {
2084 case NMEVT_STATUS_CHANGE:
2085 _evt_status_change(user, event);
2086 break;
2087 case NMEVT_RECEIVE_AUTOREPLY:
2088 case NMEVT_RECEIVE_MESSAGE:
2089 _evt_receive_message(user, event);
2090 break;
2091 case NMEVT_USER_DISCONNECT:
2092 _evt_user_disconnect(user, event);
2093 break;
2094 case NMEVT_USER_TYPING:
2095 _evt_user_typing(user, event);
2096 break;
2097 case NMEVT_USER_NOT_TYPING:
2098 _evt_user_not_typing(user, event);
2099 break;
2100 case NMEVT_SERVER_DISCONNECT:
2101 /* Nothing to do? */
2102 break;
2103 case NMEVT_INVALID_RECIPIENT:
2104 break;
2105 case NMEVT_UNDELIVERABLE_STATUS:
2106 _evt_undeliverable_status(user, event);
2107 break;
2108 case NMEVT_CONFERENCE_INVITE_NOTIFY:
2109 /* Someone else has been invited to join a
2110 * conference that we are currently a part of
2111 */
2112 _evt_conference_invite_notify(user, event);
2113 break;
2114 case NMEVT_CONFERENCE_INVITE:
2115 /* We have been invited to join a conference */
2116 _evt_conference_invite(user, event);
2117 break;
2118 case NMEVT_CONFERENCE_JOINED:
2119 /* Some one has joined a conference that we
2120 * are a part of
2121 */
2122 _evt_conference_joined(user, event);
2123 break;
2124 case NMEVT_CONFERENCE_LEFT:
2125 /* Someone else has left a conference that we
2126 * are currently a part of
2127 */
2128 _evt_conference_left(user, event);
2129 break;
2130 default:
2131 gaim_debug(GAIM_DEBUG_INFO, "novell",
2132 "_event_callback(): unhandled event, %d\n",
2133 nm_event_get_type(event));
2134 break;
2135 }
2136 }
2137
2138 /*******************************************************************************
2139 * Prpl Ops
2140 ******************************************************************************/
2141
2142 static void
2143 novell_login(GaimAccount * account)
2144 {
2145 GaimConnection *gc;
2146 NMUser *user = NULL;
2147 const char *server;
2148 const char *name;
2149 int port;
2150
2151 if (account == NULL)
2152 return;
2153
2154 gc = gaim_account_get_connection(account);
2155 if (gc == NULL)
2156 return;
2157
2158 server = gaim_account_get_string(account, "server", NULL);
2159 if (server == NULL || *server == '\0') {
2160
2161 /* TODO: Would be nice to prompt if not set!
2162 * gaim_request_fields(gc, _("Server Address"),...);
2163 */
2164
2165 /* ...but for now just error out with a nice message. */
2166 gaim_connection_error(gc, _("Unable to connect to server."
2167 " Please enter the address of the server"
2168 " you wish to connect to."));
2169 return;
2170 }
2171
2172 port = gaim_account_get_int(account, "port", DEFAULT_PORT);
2173 name = gaim_account_get_username(account);
2174
2175 user = nm_initialize_user(name, server, port, account, _event_callback);
2176 if (user) {
2177 /* save user */
2178 gc->proto_data = user;
2179
2180 /* connect to the server */
2181 gaim_connection_update_progress(gc, _("Connecting"),
2182 1, NOVELL_CONNECT_STEPS);
2183
2184 user->conn->use_ssl = TRUE;
2185 if (gaim_ssl_connect(user->client_data, user->conn->addr,
2186 user->conn->port, novell_ssl_connected_cb,
2187 novell_ssl_connect_error, gc) == NULL) {
2188 gaim_connection_error(gc, _("Error."
2189 " SSL support is not installed."));
2190 }
2191 }
2192 }
2193
2194 static void
2195 novell_close(GaimConnection * gc)
2196 {
2197 NMUser *user;
2198 NMConn *conn;
2199
2200 if (gc == NULL)
2201 return;
2202
2203 user = gc->proto_data;
2204 if (user) {
2205 conn = user->conn;
2206 if (conn && conn->ssl_conn) {
2207 gaim_ssl_close(user->conn->ssl_conn->data);
2208 }
2209 nm_deinitialize_user(user);
2210 }
2211 gc->proto_data = NULL;
2212 }
2213
2214 static int
2215 novell_send_im(GaimConnection * gc, const char *name,
2216 const char *message_body, GaimMessageFlags flags)
2217 {
2218 NMUserRecord *user_record = NULL;
2219 NMConference *conf = NULL;
2220 NMMessage *message;
2221 NMUser *user;
2222 const char *dn = NULL;
2223 char *plain;
2224 gboolean done = TRUE, created_conf = FALSE;
2225 NMERR_T rc = NM_OK;
2226
2227 if (gc == NULL || name == NULL ||
2228 message_body == NULL || *message_body == '\0')
2229 return 0;
2230
2231 user = gc->proto_data;
2232 if (user == NULL)
2233 return 0;
2234
2235 /* Create a new message */
2236 plain = gaim_unescape_html(message_body);
2237 message = nm_create_message(plain);
2238 g_free(plain);
2239
2240 /* Need to get the DN for the buddy so we can look up the convo */
2241 dn = nm_lookup_dn(user, name);
2242
2243 /* Do we already know about the sender? */
2244 user_record = nm_find_user_record(user, dn);
2245 if (user_record) {
2246
2247 /* Do we already have an instantiated conference? */
2248 conf = nm_find_conversation(user, dn);
2249 if (conf == NULL) {
2250
2251 /* If not, create a blank conference */
2252 conf = nm_create_conference(NULL);
2253 created_conf = TRUE;
2254
2255 nm_conference_add_participant(conf, user_record);
2256 }
2257
2258 nm_message_set_conference(message, conf);
2259
2260 /* Make sure conference is instantiated */
2261 if (!nm_conference_is_instantiated(conf)) {
2262
2263 /* It is not, so send the createconf. We will
2264 * have to finish sending the message when we
2265 * get the response with the new conference guid.
2266 */
2267 rc = nm_send_create_conference(user, conf, _createconf_resp_send_msg, message);
2268 _check_for_disconnect(user, rc);
2269
2270 done = FALSE;
2271 }
2272
2273 } else {
2274
2275 /* If we don't have details for the user, then we don't have
2276 * a conference yet. So create one and send the getdetails
2277 * to the server. We will have to finish sending the message
2278 * when we get the response from the server.
2279 */
2280 conf = nm_create_conference(NULL);
2281 created_conf = TRUE;
2282
2283 nm_message_set_conference(message, conf);
2284
2285 rc = nm_send_get_details(user, name, _get_details_resp_send_msg, message);
2286 _check_for_disconnect(user, rc);
2287
2288 done = FALSE;
2289 }
2290
2291 if (done) {
2292
2293 /* Did we find everything we needed? */
2294 rc = nm_send_message(user, message, _send_message_resp_cb);
2295 _check_for_disconnect(user, rc);
2296
2297 nm_release_message(message);
2298 }
2299
2300 if (created_conf && conf)
2301 nm_release_conference(conf);
2302
2303 return 1;
2304 }
2305
2306 static unsigned int
2307 novell_send_typing(GaimConnection * gc, const char *name, GaimTypingState state)
2308 {
2309 NMConference *conf = NULL;
2310 NMUser *user;
2311 const char *dn = NULL;
2312 NMERR_T rc = NM_OK;
2313
2314 if (gc == NULL || name == NULL)
2315 return 0;
2316
2317 user = gc->proto_data;
2318 if (user == NULL)
2319 return 0;
2320
2321 /* Need to get the DN for the buddy so we can look up the convo */
2322 dn = nm_lookup_dn(user, name);
2323 if (dn) {
2324
2325 /* Now find the conference in our list */
2326 conf = nm_find_conversation(user, dn);
2327 if (conf) {
2328
2329 rc = nm_send_typing(user, conf,
2330 ((state == GAIM_TYPING) ? TRUE : FALSE), NULL);
2331 _check_for_disconnect(user, rc);
2332
2333 }
2334
2335 }
2336
2337 return 0;
2338 }
2339
2340 static void
2341 novell_convo_closed(GaimConnection * gc, const char *who)
2342 {
2343 NMUser *user;
2344 NMConference *conf;
2345 const char *dn;
2346 NMERR_T rc = NM_OK;
2347
2348 if (gc == NULL || who == NULL)
2349 return;
2350
2351 user = gc->proto_data;
2352 if (user && (dn = nm_lookup_dn(user, who))) {
2353 conf = nm_find_conversation(user, dn);
2354 if (conf) {
2355 rc = nm_send_leave_conference(user, conf, NULL, NULL);
2356 _check_for_disconnect(user, rc);
2357 }
2358 }
2359 }
2360
2361 static void
2362 novell_chat_leave(GaimConnection * gc, int id)
2363 {
2364 NMConference *conference;
2365 NMUser *user;
2366 GaimConversation *chat;
2367 GSList *cnode;
2368 NMERR_T rc = NM_OK;
2369
2370 if (gc == NULL)
2371 return;
2372
2373 user = gc->proto_data;
2374 if (user == NULL)
2375 return;
2376
2377 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {
2378 conference = cnode->data;
2379 if (conference && (chat = nm_conference_get_data(conference))) {
2380 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) {
2381 rc = nm_send_leave_conference(user, conference, NULL, NULL);
2382 _check_for_disconnect(user, rc);
2383 break;
2384 }
2385 }
2386 }
2387
2388 serv_got_chat_left(gc, id);
2389 }
2390
2391 static void
2392 novell_chat_invite(GaimConnection *gc, int id,
2393 const char *message, const char *who)
2394 {
2395 NMConference *conference;
2396 NMUser *user;
2397 GaimConversation *chat;
2398 GSList *cnode;
2399 NMERR_T rc = NM_OK;
2400 NMUserRecord *user_record = NULL;
2401
2402 if (gc == NULL)
2403 return;
2404
2405 user = gc->proto_data;
2406 if (user == NULL)
2407 return;
2408
2409 user_record = nm_find_user_record(user, who);
2410 if (user_record == NULL) {
2411 rc = nm_send_get_details(user, who, _get_details_resp_send_invite, GINT_TO_POINTER(id));
2412 _check_for_disconnect(user, rc);
2413 return;
2414 }
2415
2416 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {
2417 conference = cnode->data;
2418 if (conference && (chat = nm_conference_get_data(conference))) {
2419 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) {
2420 rc = nm_send_conference_invite(user, conference, user_record,
2421 message, _sendinvite_resp_cb, NULL);
2422 _check_for_disconnect(user, rc);
2423 break;
2424 }
2425 }
2426 }
2427 }
2428
2429 static int
2430 novell_chat_send(GaimConnection * gc, int id, const char *text, GaimMessageFlags flags)
2431 {
2432 NMConference *conference;
2433 GaimConversation *chat;
2434 GSList *cnode;
2435 NMMessage *message;
2436 NMUser *user;
2437 NMERR_T rc = NM_OK;
2438 const char *name;
2439 char *str, *plain;
2440
2441 if (gc == NULL || text == NULL)
2442 return -1;
2443
2444 user = gc->proto_data;
2445 if (user == NULL)
2446 return -1;
2447
2448 plain = gaim_unescape_html(text);
2449 message = nm_create_message(plain);
2450 g_free(plain);
2451
2452 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {
2453 conference = cnode->data;
2454 if (conference && (chat = nm_conference_get_data(conference))) {
2455 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) {
2456
2457 nm_message_set_conference(message, conference);
2458
2459 /* check to see if the conference is instatiated yet */
2460 if (!nm_conference_is_instantiated(conference)) {
2461 nm_message_add_ref(message);
2462 nm_send_create_conference(user, conference, _createconf_resp_send_msg, message);
2463 } else {
2464 rc = nm_send_message(user, message, _send_message_resp_cb);
2465 }
2466
2467 nm_release_message(message);
2468
2469 if (!_check_for_disconnect(user, rc)) {
2470
2471 /* Use the account alias if it is set */
2472 name = gaim_account_get_alias(user->client_data);
2473 if (name == NULL || *name == '\0') {
2474
2475 /* If there is no account alias, try full name */
2476 name = nm_user_record_get_full_name(user->user_record);
2477 if (name == NULL || *name == '\0') {
2478
2479 /* Fall back to the username that we are signed in with */
2480 name = gaim_account_get_username(user->client_data);
2481 }
2482 }
2483
2484 serv_got_chat_in(gc, id, name, 0, text, time(NULL));
2485 return 0;
2486 } else
2487 return -1;
2488
2489 }
2490 }
2491 }
2492
2493
2494 /* The conference was not found, must be closed */
2495 chat = gaim_find_chat(gc, id);
2496 if (chat) {
2497 str = g_strdup_printf(_("This conference has been closed."
2498 " No more messages can be sent."));
2499 gaim_conversation_write(chat, NULL, str, GAIM_MESSAGE_SYSTEM, time(NULL));
2500 g_free(str);
2501 }
2502
2503 if (message)
2504 nm_release_message(message);
2505
2506 return -1;
2507 }
2508
2509 static void
2510 novell_add_buddy(GaimConnection * gc, GaimBuddy *buddy, GaimGroup * group)
2511 {
2512 NMFolder *folder = NULL;
2513 NMContact *contact;
2514 NMUser *user;
2515 NMERR_T rc = NM_OK;
2516 const char *alias, *gname;
2517
2518 if (gc == NULL || buddy == NULL || group == NULL)
2519 return;
2520
2521 user = (NMUser *) gc->proto_data;
2522 if (user == NULL)
2523 return;
2524
2525 /* If we haven't synched the contact list yet, ignore
2526 * the add_buddy calls. Server side list is the master.
2527 */
2528 if (!user->clist_synched)
2529 return;
2530
2531 contact = nm_create_contact();
2532 nm_contact_set_dn(contact, buddy->name);
2533
2534 /* Remove the GaimBuddy (we will add it back after adding it
2535 * to the server side list). Save the alias if there is one.
2536 */
2537 alias = gaim_buddy_get_alias(buddy);
2538 if (alias && strcmp(alias, buddy->name))
2539 nm_contact_set_display_name(contact, alias);
2540
2541 gaim_blist_remove_buddy(buddy);
2542 buddy = NULL;
2543
2544 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) {
2545 gname = "";
2546 } else {
2547 gname = group->name;
2548 }
2549
2550 folder = nm_find_folder(user, gname);
2551 if (folder) {
2552
2553 /* We have everything that we need, so send the createcontact */
2554 rc = nm_send_create_contact(user, folder, contact,
2555 _create_contact_resp_cb, contact);
2556
2557 } else {
2558
2559 /* Need to create the folder before we can add the contact */
2560 rc = nm_send_create_folder(user, gname,
2561 _create_folder_resp_add_contact, contact);
2562 }
2563
2564 _check_for_disconnect(user, rc);
2565
2566 }
2567
2568 static void
2569 novell_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
2570 {
2571 NMContact *contact;
2572 NMFolder *folder;
2573 NMUser *user;
2574 const char *dn, *gname;
2575 NMERR_T rc = NM_OK;
2576
2577 if (gc == NULL || buddy == NULL || group == NULL)
2578 return;
2579
2580 user = (NMUser *) gc->proto_data;
2581 if (user && (dn = nm_lookup_dn(user, buddy->name))) {
2582 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) {
2583 gname = "";
2584 } else {
2585 gname = group->name;
2586 }
2587 folder = nm_find_folder(user, gname);
2588 if (folder) {
2589 contact = nm_folder_find_contact(folder, dn);
2590 if (contact) {
2591
2592 /* Remove the buddy from the contact */
2593 nm_contact_set_data(contact, NULL);
2594
2595 /* Tell the server to remove the contact */
2596 rc = nm_send_remove_contact(user, folder, contact,
2597 _remove_contact_resp_cb, NULL);
2598 _check_for_disconnect(user, rc);
2599 }
2600 }
2601 }
2602 }
2603
2604 static void
2605 novell_remove_group(GaimConnection * gc, GaimGroup *group)
2606 {
2607 NMUser *user;
2608 NMERR_T rc = NM_OK;
2609
2610 if (gc == NULL || group == NULL)
2611 return;
2612
2613 user = (NMUser *) gc->proto_data;
2614 if (user) {
2615 NMFolder *folder = nm_find_folder(user, group->name);
2616
2617 if (folder) {
2618 rc = nm_send_remove_folder(user, folder,
2619 _remove_folder_resp_cb, NULL);
2620 _check_for_disconnect(user, rc);
2621 }
2622 }
2623 }
2624
2625 static void
2626 novell_alias_buddy(GaimConnection * gc, const char *name, const char *alias)
2627 {
2628 NMContact *contact;
2629 NMUser *user;
2630 GList *contacts = NULL;
2631 GList *cnode = NULL;
2632 const char *dn = NULL, *fname = NULL;
2633 NMERR_T rc = NM_OK;
2634
2635 if (gc == NULL || name == NULL || alias == NULL)
2636 return;
2637
2638 user = (NMUser *) gc->proto_data;
2639 if (user && (dn = nm_lookup_dn(user, name))) {
2640
2641 /* Alias all of instances of the contact */
2642 contacts = nm_find_contacts(user, dn);
2643 for (cnode = contacts; cnode != NULL; cnode = cnode->next) {
2644 contact = (NMContact *) cnode->data;
2645 if (contact) {
2646 GaimGroup *group = NULL;
2647 GaimBuddy *buddy;
2648 NMFolder *folder;
2649
2650 /* Alias the Gaim buddy? */
2651 folder = nm_find_folder_by_id(user,
2652 nm_contact_get_parent_id(contact));
2653 if (folder) {
2654 fname = nm_folder_get_name(folder);
2655 if (*fname == '\0') {
2656 fname = NM_ROOT_FOLDER_NAME;
2657 }
2658 group = gaim_find_group(fname);
2659 }
2660
2661 if (group) {
2662 buddy = gaim_find_buddy_in_group(user->client_data,
2663 name, group);
2664 if (buddy && strcmp(buddy->alias, alias))
2665 gaim_blist_alias_buddy(buddy, alias);
2666 }
2667
2668 /* Tell the server to alias the contact */
2669 rc = nm_send_rename_contact(user, contact, alias,
2670 _rename_contact_resp_cb, NULL);
2671 _check_for_disconnect(user, rc);
2672 }
2673 }
2674 if (contacts)
2675 g_list_free(contacts);
2676 }
2677 }
2678
2679 static void
2680 novell_group_buddy(GaimConnection * gc,
2681 const char *name, const char *old_group_name,
2682 const char *new_group_name)
2683 {
2684 NMFolder *old_folder;
2685 NMFolder *new_folder;
2686 NMContact *contact;
2687 NMUser *user;
2688 const char *dn;
2689 NMERR_T rc = NM_OK;
2690
2691 if (gc == NULL || name == NULL ||
2692 old_group_name == NULL || new_group_name == NULL)
2693 return;
2694
2695 user = (NMUser *) gc->proto_data;
2696 if (user && (dn = nm_lookup_dn(user, name))) {
2697
2698 /* Find the old folder */
2699 if (strcmp(old_group_name, NM_ROOT_FOLDER_NAME) == 0) {
2700 old_folder = nm_get_root_folder(user);
2701 if (nm_folder_find_contact(old_folder, dn) == NULL)
2702 old_folder = nm_find_folder(user, old_group_name);
2703 } else {
2704 old_folder = nm_find_folder(user, old_group_name);
2705 }
2706
2707 if (old_folder && (contact = nm_folder_find_contact(old_folder, dn))) {
2708
2709 /* Find the new folder */
2710 new_folder = nm_find_folder(user, new_group_name);
2711 if (new_folder == NULL) {
2712 if (strcmp(new_group_name, NM_ROOT_FOLDER_NAME) == 0)
2713 new_folder = nm_get_root_folder(user);
2714 }
2715
2716 if (new_folder) {
2717
2718 /* Tell the server to move the contact to the new folder */
2719 rc = nm_send_move_contact(user, contact, new_folder,
2720 _move_contact_resp_cb, NULL);
2721
2722 } else {
2723
2724 nm_contact_add_ref(contact);
2725
2726 /* Remove the old contact first */
2727 nm_send_remove_contact(user, old_folder, contact,
2728 _remove_contact_resp_cb, NULL);
2729
2730 /* New folder does not exist yet, so create it */
2731 rc = nm_send_create_folder(user, new_group_name,
2732 _create_folder_resp_move_contact,
2733 contact);
2734 }
2735
2736 _check_for_disconnect(user, rc);
2737 }
2738 }
2739 }
2740
2741 static void
2742 novell_rename_group(GaimConnection * gc, const char *old_name,
2743 GaimGroup *group, GList *moved_buddies)
2744 {
2745 NMERR_T rc = NM_OK;
2746 NMFolder *folder;
2747 NMUser *user;
2748
2749 if (gc == NULL || old_name == NULL || group == NULL || moved_buddies == NULL) {
2750 return;
2751 }
2752
2753 user = gc->proto_data;
2754 if (user) {
2755 /* Does new folder exist already? */
2756 if (nm_find_folder(user, group->name)) {
2757 /* gaim_blist_rename_group() adds the buddies
2758 * to the new group and removes the old group...
2759 * so there is nothing more to do here.
2760 */
2761 return;
2762 }
2763
2764 if (strcmp(old_name, NM_ROOT_FOLDER_NAME) == 0) {
2765 /* Can't rename the root folder ... need to revisit this */
2766 return;
2767 }
2768
2769 folder = nm_find_folder(user, old_name);
2770 if (folder) {
2771 rc = nm_send_rename_folder(user, folder, group->name,
2772 _rename_folder_resp_cb, NULL);
2773 _check_for_disconnect(user, rc);
2774 }
2775 }
2776 }
2777
2778 static void
2779 novell_list_emblems(GaimBuddy * buddy, const char **se, const char **sw, const char **nw, const char **ne)
2780 {
2781 NMUserRecord *user_record = NULL;
2782 GaimConnection *gc;
2783 NMUser *user;
2784 int status = 0;
2785
2786 gc = gaim_account_get_connection(buddy->account);
2787
2788 if (gc == NULL || (user = gc->proto_data) == NULL)
2789 return;
2790
2791 user_record = nm_find_user_record(user, buddy->name);
2792
2793 if (user_record)
2794 status = nm_user_record_get_status(user_record);
2795
2796 switch (status) {
2797 case NM_STATUS_AVAILABLE:
2798 *se = "";
2799 break;
2800 case NM_STATUS_AWAY:
2801 *se = "away";
2802 break;
2803 case NM_STATUS_BUSY:
2804 *se = "occupied";
2805 break;
2806 case NM_STATUS_UNKNOWN:
2807 *se = "error";
2808 break;
2809 }
2810 }
2811
2812 static const char *
2813 novell_list_icon(GaimAccount * account, GaimBuddy * buddy)
2814 {
2815 return "novell";
2816 }
2817
2818 static void
2819 novell_tooltip_text(GaimBuddy * buddy, GString * str, gboolean full)
2820 {
2821 NMUserRecord *user_record = NULL;
2822 GaimConnection *gc;
2823 NMUser *user;
2824 int status = 0;
2825 const char *status_str = NULL;
2826 const char *text = NULL;
2827
2828 if (buddy == NULL)
2829 return;
2830
2831 gc = gaim_account_get_connection(buddy->account);
2832 if (gc == NULL || (user = gc->proto_data) == NULL)
2833 return;
2834
2835 if (GAIM_BUDDY_IS_ONLINE(buddy)) {
2836 user_record = nm_find_user_record(user, buddy->name);
2837 if (user_record) {
2838 status = nm_user_record_get_status(user_record);
2839 text = nm_user_record_get_status_text(user_record);
2840 /* No custom text, so default it ... */
2841 switch (status) {
2842 case NM_STATUS_AVAILABLE:
2843 status_str = _("Available");
2844 break;
2845 case NM_STATUS_AWAY:
2846 status_str = _("Away");
2847 break;
2848 case NM_STATUS_BUSY:
2849 status_str = _("Busy");
2850 break;
2851 case NM_STATUS_AWAY_IDLE:
2852 status_str = _("Idle");
2853 break;
2854 case NM_STATUS_OFFLINE:
2855 status_str = _("Offline");
2856 break;
2857 default:
2858 status_str = _("Unknown");
2859 break;
2860 }
2861
2862 if (text)
2863 g_string_append_printf(str, "\n<b>%s:</b> %s"
2864 "\n<b>%s:</b> %s",
2865 _("Status"), status_str,
2866 _("Message"), text);
2867 else
2868 g_string_append_printf(str, "\n<b>%s:</b> %s",
2869 _("Status"), status_str);
2870 }
2871 }
2872 }
2873
2874 static void
2875 novell_set_idle(GaimConnection * gc, int time)
2876 {
2877 NMUser *user;
2878 NMERR_T rc = NM_OK;
2879 const char *id = NULL;
2880 GaimStatus *status = NULL;
2881
2882 if (gc == NULL)
2883 return;
2884
2885 user = gc->proto_data;
2886 if (user == NULL)
2887 return;
2888
2889 status = gaim_account_get_active_status(gaim_connection_get_account(gc));
2890 id = gaim_status_get_id(status);
2891
2892 /* Only go idle if active status is available */
2893 if (!strcmp(id, NOVELL_STATUS_TYPE_AVAILABLE)) {
2894 if (time > 0) {
2895 rc = nm_send_set_status(user, NM_STATUS_AWAY_IDLE, NULL, NULL, NULL, NULL);
2896 } else {
2897 rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL, NULL);
2898 }
2899 }
2900
2901 _check_for_disconnect(user, rc);
2902 }
2903
2904 static void
2905 novell_get_info(GaimConnection * gc, const char *name)
2906 {
2907 NMUserRecord *user_record;
2908 NMUser *user;
2909 NMERR_T rc;
2910
2911 if (gc == NULL || name == NULL)
2912 return;
2913
2914 user = (NMUser *) gc->proto_data;
2915 if (user) {
2916
2917 user_record = nm_find_user_record(user, name);
2918 if (user_record) {
2919
2920 _show_info(gc, user_record);
2921
2922 } else {
2923
2924 rc = nm_send_get_details(user, name,
2925 _get_details_resp_show_info, g_strdup(name));
2926
2927 _check_for_disconnect(user, rc);
2928
2929 }
2930
2931 }
2932 }
2933
2934 static char *
2935 novell_status_text(GaimBuddy * buddy)
2936 {
2937 const char *text = NULL;
2938 const char *dn = NULL;
2939
2940 if (buddy && buddy->account) {
2941 GaimConnection *gc = gaim_account_get_connection(buddy->account);
2942
2943 if (gc && gc->proto_data) {
2944 NMUser *user = gc->proto_data;
2945
2946 dn = nm_lookup_dn(user, buddy->name);
2947 if (dn) {
2948 NMUserRecord *user_record = nm_find_user_record(user, dn);
2949
2950 if (user_record) {
2951 text = nm_user_record_get_status_text(user_record);
2952 if (text)
2953 return g_strdup(text);
2954 }
2955 }
2956 }
2957 }
2958
2959 return NULL;
2960 }
2961
2962 static GList *
2963 novell_status_types(GaimAccount *account)
2964 {
2965 GList *status_types = NULL;
2966 GaimStatusType *type;
2967
2968 g_return_val_if_fail(account != NULL, NULL);
2969
2970 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, NOVELL_STATUS_TYPE_AVAILABLE,
2971 NULL, TRUE, TRUE, FALSE,
2972 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
2973 NULL);
2974 status_types = g_list_append(status_types, type);
2975
2976 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, NOVELL_STATUS_TYPE_AWAY,
2977 NULL, TRUE, TRUE, FALSE,
2978 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
2979 NULL);
2980 status_types = g_list_append(status_types, type);
2981
2982 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, NOVELL_STATUS_TYPE_BUSY,
2983 _("Busy"), TRUE, TRUE, FALSE,
2984 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
2985 NULL);
2986 status_types = g_list_append(status_types, type);
2987
2988 type = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, NOVELL_STATUS_TYPE_APPEAR_OFFLINE,
2989 NULL, TRUE, TRUE, FALSE);
2990 status_types = g_list_append(status_types, type);
2991
2992 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE);
2993 status_types = g_list_append(status_types, type);
2994
2995 return status_types;
2996 }
2997
2998 static void
2999 novell_set_status(GaimAccount *account, GaimStatus *status)
3000 {
3001 GaimConnection *gc;
3002 gboolean connected;
3003 GaimPresence *presence;
3004 GaimStatusType *type;
3005 GaimStatusPrimitive primitive;
3006 NMUser *user;
3007 NMSTATUS_T novellstatus = NM_STATUS_AVAILABLE;
3008 NMERR_T rc = NM_OK;
3009 const char *msg = NULL;
3010 char *text = NULL;
3011
3012 connected = gaim_account_is_connected(account);
3013 presence = gaim_status_get_presence(status);
3014 type = gaim_status_get_type(status);
3015 primitive = gaim_status_type_get_primitive(type);
3016
3017 /*
3018 * We don't have any independent statuses, so we don't need to
3019 * do anything when a status is deactivated (because another
3020 * status is about to be activated).
3021 */
3022 if (!gaim_status_is_active(status))
3023 return;
3024
3025 if (!connected)
3026 return;
3027
3028 gc = gaim_account_get_connection(account);
3029 user = gc->proto_data;
3030 if (user == NULL)
3031 return;
3032
3033 if (primitive == GAIM_STATUS_AVAILABLE) {
3034 novellstatus = NM_STATUS_AVAILABLE;
3035 } else if (primitive == GAIM_STATUS_AWAY) {
3036 novellstatus = NM_STATUS_AWAY;
3037 } else if (primitive == GAIM_STATUS_UNAVAILABLE) {
3038 novellstatus = NM_STATUS_BUSY;
3039 } else if (primitive == GAIM_STATUS_INVISIBLE) {
3040 novellstatus = NM_STATUS_OFFLINE;
3041 } else if (gaim_presence_is_idle(presence)) {
3042 novellstatus = NM_STATUS_AWAY_IDLE;
3043 } else {
3044 novellstatus = NM_STATUS_AVAILABLE;
3045 }
3046
3047 if (primitive == GAIM_STATUS_AWAY || primitive == GAIM_STATUS_AVAILABLE ||
3048 primitive == GAIM_STATUS_UNAVAILABLE) {
3049 msg = gaim_status_get_attr_string(status, "message");
3050 text = g_strdup(msg);
3051
3052 if (primitive == GAIM_STATUS_AVAILABLE)
3053 msg = NULL; /* no auto replies for online status */
3054
3055 /* Don't want newlines in status text */
3056 gaim_util_chrreplace(text, '\n', ' ');
3057 }
3058
3059 rc = nm_send_set_status(user, novellstatus, text, msg, NULL, NULL);
3060 _check_for_disconnect(user, rc);
3061
3062 if (text)
3063 g_free(text);
3064 }
3065
3066 static void
3067 novell_add_permit(GaimConnection *gc, const char *who)
3068 {
3069 NMUser *user;
3070 NMERR_T rc = NM_OK;
3071 const char *name = who;
3072
3073 if (gc == NULL || who == NULL)
3074 return;
3075
3076 user = gc->proto_data;
3077 if (user == NULL)
3078 return;
3079
3080 /* Remove first -- we will add it back in when we get
3081 * the okay from the server
3082 */
3083 gaim_privacy_permit_remove(gc->account, who, TRUE);
3084
3085 if (nm_user_is_privacy_locked(user)) {
3086 _show_privacy_locked_error(gc, user);
3087 _sync_privacy_lists(user);
3088 return;
3089 }
3090
3091 /* Work around for problem with un-typed, dotted contexts */
3092 if (strchr(who, '.')) {
3093 const char *dn = nm_lookup_dn(user, who);
3094 if (dn == NULL) {
3095 rc = nm_send_get_details(user, who, _get_details_send_privacy_create,
3096 (gpointer)TRUE);
3097 _check_for_disconnect(user, rc);
3098 return;
3099 } else {
3100 name = dn;
3101 }
3102 }
3103
3104 rc = nm_send_create_privacy_item(user, name, TRUE,
3105 _create_privacy_item_permit_resp_cb,
3106 g_strdup(who));
3107 _check_for_disconnect(user, rc);
3108 }
3109
3110 static void
3111 novell_add_deny(GaimConnection *gc, const char *who)
3112 {
3113 NMUser *user;
3114 NMERR_T rc = NM_OK;
3115 const char *name = who;
3116
3117 if (gc == NULL || who == NULL)
3118 return;
3119
3120 user = gc->proto_data;
3121 if (user == NULL)
3122 return;
3123
3124 /* Remove first -- we will add it back in when we get
3125 * the okay from the server
3126 */
3127 gaim_privacy_deny_remove(gc->account, who, TRUE);
3128
3129 if (nm_user_is_privacy_locked(user)) {
3130 _show_privacy_locked_error(gc, user);
3131 _sync_privacy_lists(user);
3132 return;
3133 }
3134
3135 /* Work around for problem with un-typed, dotted contexts */
3136 if (strchr(who, '.')) {
3137 const char *dn = nm_lookup_dn(user, who);
3138 if (dn == NULL) {
3139 rc = nm_send_get_details(user, who, _get_details_send_privacy_create,
3140 (gpointer)FALSE);
3141 _check_for_disconnect(user, rc);
3142 return;
3143 } else {
3144 name = dn;
3145 }
3146 }
3147
3148 rc = nm_send_create_privacy_item(user, name, FALSE,
3149 _create_privacy_item_deny_resp_cb,
3150 g_strdup(who));
3151 _check_for_disconnect(user, rc);
3152 }
3153
3154 static void
3155 novell_rem_permit(GaimConnection *gc, const char *who)
3156 {
3157 NMUser *user;
3158 NMERR_T rc = NM_OK;
3159 const char *dn = NULL;
3160
3161 if (gc == NULL || who == NULL)
3162 return;
3163
3164 user = gc->proto_data;
3165 if (user == NULL)
3166 return;
3167
3168 if (nm_user_is_privacy_locked(user)) {
3169 _show_privacy_locked_error(gc, user);
3170 _sync_privacy_lists(user);
3171 return;
3172 }
3173
3174 dn = nm_lookup_dn(user, who);
3175 if (dn == NULL)
3176 dn = who;
3177
3178 rc = nm_send_remove_privacy_item(user, dn, TRUE,
3179 _remove_privacy_item_resp_cb,
3180 g_strdup(who));
3181 _check_for_disconnect(user, rc);
3182 }
3183
3184 static void
3185 novell_rem_deny(GaimConnection *gc, const char *who)
3186 {
3187 NMUser *user;
3188 NMERR_T rc = NM_OK;
3189 const char *dn = NULL;
3190
3191 if (gc == NULL || who == NULL)
3192 return;
3193
3194 user = gc->proto_data;
3195 if (user == NULL)
3196 return;
3197
3198 if (nm_user_is_privacy_locked(user)) {
3199 _show_privacy_locked_error(gc, user);
3200 _sync_privacy_lists(user);
3201 return;
3202 }
3203
3204 dn = nm_lookup_dn(user, who);
3205 if (dn == NULL)
3206 dn = who;
3207
3208 rc = nm_send_remove_privacy_item(user, dn, FALSE,
3209 _remove_privacy_item_resp_cb,
3210 g_strdup(who));
3211 _check_for_disconnect(user, rc);
3212 }
3213
3214 static void
3215 novell_set_permit_deny(GaimConnection *gc)
3216 {
3217 NMERR_T rc = NM_OK;
3218 const char *dn, *name = NULL;
3219 NMUserRecord *user_record = NULL;
3220 GSList *node = NULL, *copy = NULL;
3221 NMUser *user;
3222 int i, j, num_contacts, num_folders;
3223 NMContact *contact;
3224 NMFolder *folder = NULL;
3225
3226 if (gc == NULL)
3227 return;
3228
3229 user = gc->proto_data;
3230 if (user == NULL)
3231 return;
3232
3233 if (user->privacy_synched == FALSE) {
3234 _sync_privacy_lists(user);
3235 user->privacy_synched = TRUE;
3236 return;
3237 }
3238
3239 if (nm_user_is_privacy_locked(user)) {
3240 _show_privacy_locked_error(gc, user);
3241 _sync_privacy_lists(user);
3242 return;
3243 }
3244
3245 switch (gc->account->perm_deny) {
3246
3247 case GAIM_PRIVACY_ALLOW_ALL:
3248 rc = nm_send_set_privacy_default(user, FALSE,
3249 _set_privacy_default_resp_cb, NULL);
3250 _check_for_disconnect(user, rc);
3251
3252 /* clear server side deny list */
3253 if (rc == NM_OK) {
3254 copy = g_slist_copy(user->deny_list);
3255 for (node = copy; node && node->data; node = node->next) {
3256 rc = nm_send_remove_privacy_item(user, (const char *)node->data,
3257 FALSE, NULL, NULL);
3258 if (_check_for_disconnect(user, rc))
3259 break;
3260 }
3261 g_slist_free(copy);
3262 g_slist_free(user->deny_list);
3263 user->deny_list = NULL;
3264 }
3265 break;
3266
3267 case GAIM_PRIVACY_DENY_ALL:
3268 rc = nm_send_set_privacy_default(user, TRUE,
3269 _set_privacy_default_resp_cb, NULL);
3270 _check_for_disconnect(user, rc);
3271
3272 /* clear server side allow list */
3273 if (rc == NM_OK) {
3274 copy = g_slist_copy(user->allow_list);
3275 for (node = copy; node && node->data; node = node->next) {
3276 rc = nm_send_remove_privacy_item(user, (const char *)node->data,
3277 TRUE, NULL, NULL);
3278 if (_check_for_disconnect(user, rc))
3279 break;
3280 }
3281 g_slist_free(copy);
3282 g_slist_free(user->allow_list);
3283 user->allow_list = NULL;
3284 }
3285 break;
3286
3287 case GAIM_PRIVACY_ALLOW_USERS:
3288
3289 rc = nm_send_set_privacy_default(user, TRUE,
3290 _set_privacy_default_resp_cb, NULL);
3291 _check_for_disconnect(user, rc);
3292
3293 /* sync allow lists */
3294 if (rc == NM_OK) {
3295
3296 for (node = user->allow_list; node; node = node->next) {
3297 user_record = nm_find_user_record(user, (char *)node->data);
3298 if (user_record) {
3299 name = nm_user_record_get_display_id(user_record);
3300
3301 if (!g_slist_find_custom(gc->account->permit,
3302 name, (GCompareFunc)nm_utf8_strcasecmp)) {
3303 gaim_privacy_permit_add(gc->account, name , TRUE);
3304 }
3305 }
3306 }
3307
3308 for (node = gc->account->permit; node; node = node->next) {
3309 name = NULL;
3310 dn = nm_lookup_dn(user, (char *)node->data);
3311 if (dn) {
3312 user_record = nm_find_user_record(user, dn);
3313 name = nm_user_record_get_display_id(user_record);
3314
3315 if (!g_slist_find_custom(user->allow_list,
3316 dn, (GCompareFunc)nm_utf8_strcasecmp)) {
3317 rc = nm_send_create_privacy_item(user, dn, TRUE,
3318 _create_privacy_item_deny_resp_cb,
3319 g_strdup(dn));
3320 }
3321 } else {
3322 gaim_privacy_permit_remove(gc->account, (char *)node->data, TRUE);
3323 }
3324 }
3325 }
3326 break;
3327
3328 case GAIM_PRIVACY_DENY_USERS:
3329
3330 /* set to default allow */
3331 rc = nm_send_set_privacy_default(user, FALSE,
3332 _set_privacy_default_resp_cb, NULL);
3333 _check_for_disconnect(user, rc);
3334
3335 /* sync deny lists */
3336 if (rc == NM_OK) {
3337
3338 for (node = user->deny_list; node; node = node->next) {
3339 user_record = nm_find_user_record(user, (char *)node->data);
3340 if (user_record) {
3341 name = nm_user_record_get_display_id(user_record);
3342
3343 if (!g_slist_find_custom(gc->account->deny,
3344 name, (GCompareFunc)nm_utf8_strcasecmp)) {
3345 gaim_privacy_deny_add(gc->account, name , TRUE);
3346 }
3347 }
3348 }
3349
3350 for (node = gc->account->deny; node; node = node->next) {
3351
3352 name = NULL;
3353 dn = nm_lookup_dn(user, (char *)node->data);
3354 if (dn) {
3355 user_record = nm_find_user_record(user, dn);
3356 name = nm_user_record_get_display_id(user_record);
3357
3358 if (!g_slist_find_custom(user->deny_list,
3359 dn, (GCompareFunc)nm_utf8_strcasecmp)) {
3360 rc = nm_send_create_privacy_item(user, dn, FALSE,
3361 _create_privacy_item_deny_resp_cb,
3362 g_strdup(name));
3363 }
3364 } else {
3365 gaim_privacy_deny_remove(gc->account, (char *)node->data, TRUE);
3366 }
3367 }
3368
3369 }
3370 break;
3371
3372 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
3373
3374 /* remove users from allow list that are not in buddy list */
3375 copy = g_slist_copy(user->allow_list);
3376 for (node = copy; node && node->data; node = node->next) {
3377 if (!nm_find_contacts(user, node->data)) {
3378 rc = nm_send_remove_privacy_item(user, (const char *)node->data,
3379 TRUE, NULL, NULL);
3380 if (_check_for_disconnect(user, rc))
3381 return;
3382 }
3383 }
3384 g_slist_free(copy);
3385
3386 /* add all buddies to allow list */
3387 num_contacts = nm_folder_get_contact_count(user->root_folder);
3388 for (i = 0; i < num_contacts; i++) {
3389 contact = nm_folder_get_contact(user->root_folder, i);
3390 dn = nm_contact_get_dn(contact);
3391 if (dn && !g_slist_find_custom(user->allow_list,
3392 dn, (GCompareFunc)nm_utf8_strcasecmp))
3393 {
3394 rc = nm_send_create_privacy_item(user, dn, TRUE,
3395 _create_privacy_item_deny_resp_cb,
3396 g_strdup(dn));
3397 if (_check_for_disconnect(user, rc))
3398 return;
3399 }
3400
3401 }
3402
3403 num_folders = nm_folder_get_subfolder_count(user->root_folder);
3404 for (i = 0; i < num_folders; i++) {
3405 folder = nm_folder_get_subfolder(user->root_folder, i);
3406 num_contacts = nm_folder_get_contact_count(folder);
3407 for (j = 0; j < num_contacts; j++) {
3408 contact = nm_folder_get_contact(folder, j);
3409 dn = nm_contact_get_dn(contact);
3410 if (dn && !g_slist_find_custom(user->allow_list,
3411 dn, (GCompareFunc)nm_utf8_strcasecmp))
3412 {
3413 rc = nm_send_create_privacy_item(user, dn, TRUE,
3414 _create_privacy_item_deny_resp_cb,
3415 g_strdup(dn));
3416 if (_check_for_disconnect(user, rc))
3417 return;
3418 }
3419 }
3420 }
3421
3422 /* set to default deny */
3423 rc = nm_send_set_privacy_default(user, TRUE,
3424 _set_privacy_default_resp_cb, NULL);
3425 if (_check_for_disconnect(user, rc))
3426 break;
3427
3428 break;
3429 }
3430 }
3431
3432 static GList *
3433 novell_blist_node_menu(GaimBlistNode *node)
3434 {
3435 GList *list = NULL;
3436 GaimMenuAction *act;
3437
3438 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
3439 act = gaim_menu_action_new(_("Initiate _Chat"),
3440 GAIM_CALLBACK(_initiate_conference_cb),
3441 NULL, NULL);
3442 list = g_list_append(list, act);
3443 }
3444
3445 return list;
3446 }
3447
3448 static void
3449 novell_keepalive(GaimConnection *gc)
3450 {
3451 NMUser *user;
3452 NMERR_T rc = NM_OK;
3453
3454 if (gc == NULL)
3455 return;
3456
3457 user = gc->proto_data;
3458 if (user == NULL)
3459 return;
3460
3461 rc = nm_send_keepalive(user, NULL, NULL);
3462 _check_for_disconnect(user, rc);
3463 }
3464
3465 static GaimPluginProtocolInfo prpl_info = {
3466 0,
3467 NULL, /* user_splits */
3468 NULL, /* protocol_options */
3469 NO_BUDDY_ICONS, /* icon_spec */
3470 novell_list_icon, /* list_icon */
3471 novell_list_emblems, /* list_emblems */
3472 novell_status_text, /* status_text */
3473 novell_tooltip_text, /* tooltip_text */
3474 novell_status_types, /* status_types */
3475 novell_blist_node_menu, /* blist_node_menu */
3476 NULL, /* chat_info */
3477 NULL, /* chat_info_defaults */
3478 novell_login, /* login */
3479 novell_close, /* close */
3480 novell_send_im, /* send_im */
3481 NULL, /* set_info */
3482 novell_send_typing, /* send_typing */
3483 novell_get_info, /* get_info */
3484 novell_set_status, /* set_status */
3485 novell_set_idle, /* set_idle */
3486 NULL, /* change_passwd */
3487 novell_add_buddy, /* add_buddy */
3488 NULL, /* add_buddies */
3489 novell_remove_buddy, /* remove_buddy */
3490 NULL, /* remove_buddies */
3491 novell_add_permit, /* add_permit */
3492 novell_add_deny, /* add_deny */
3493 novell_rem_permit, /* rem_permit */
3494 novell_rem_deny, /* rem_deny */
3495 novell_set_permit_deny, /* set_permit_deny */
3496 NULL, /* join_chat */
3497 NULL, /* reject_chat */
3498 NULL, /* get_chat_name */
3499 novell_chat_invite, /* chat_invite */
3500 novell_chat_leave, /* chat_leave */
3501 NULL, /* chat_whisper */
3502 novell_chat_send, /* chat_send */
3503 novell_keepalive, /* keepalive */
3504 NULL, /* register_user */
3505 NULL, /* get_cb_info */
3506 NULL, /* get_cb_away */
3507 novell_alias_buddy, /* alias_buddy */
3508 novell_group_buddy, /* group_buddy */
3509 novell_rename_group, /* rename_group */
3510 NULL, /* buddy_free */
3511 novell_convo_closed, /* convo_closed */
3512 gaim_normalize_nocase, /* normalize */
3513 NULL, /* set_buddy_icon */
3514 novell_remove_group, /* remove_group */
3515 NULL, /* get_cb_real_name */
3516 NULL, /* set_chat_topic */
3517 NULL, /* find_blist_chat */
3518 NULL, /* roomlist_get_list */
3519 NULL, /* roomlist_cancel */
3520 NULL, /* roomlist_expand_category */
3521 NULL, /* can_receive_file */
3522 NULL, /* send_file */
3523 NULL, /* new_xfer */
3524 NULL, /* offline_message */
3525 NULL, /* whiteboard_prpl_ops */
3526 };
3527
3528 static GaimPluginInfo info = {
3529 GAIM_PLUGIN_MAGIC,
3530 GAIM_MAJOR_VERSION,
3531 GAIM_MINOR_VERSION,
3532 GAIM_PLUGIN_PROTOCOL, /**< type */
3533 NULL, /**< ui_requirement */
3534 0, /**< flags */
3535 NULL, /**< dependencies */
3536 GAIM_PRIORITY_DEFAULT, /**< priority */
3537 "prpl-novell", /**< id */
3538 "GroupWise", /**< name */
3539 VERSION, /**< version */
3540 /** summary */
3541 N_("Novell GroupWise Messenger Protocol Plugin"),
3542 /** description */
3543 N_("Novell GroupWise Messenger Protocol Plugin"),
3544 NULL, /**< author */
3545 GAIM_WEBSITE, /**< homepage */
3546
3547 NULL, /**< load */
3548 NULL, /**< unload */
3549 NULL, /**< destroy */
3550
3551 NULL, /**< ui_info */
3552 &prpl_info, /**< extra_info */
3553 NULL,
3554 NULL
3555 };
3556
3557 static void
3558 init_plugin(GaimPlugin * plugin)
3559 {
3560 GaimAccountOption *option;
3561
3562 option = gaim_account_option_string_new(_("Server address"), "server", NULL);
3563 prpl_info.protocol_options =
3564 g_list_append(prpl_info.protocol_options, option);
3565
3566 option = gaim_account_option_int_new(_("Server port"), "port", DEFAULT_PORT);
3567 prpl_info.protocol_options =
3568 g_list_append(prpl_info.protocol_options, option);
3569
3570 my_protocol = plugin;
3571 }
3572
3573 GAIM_INIT_PLUGIN(novell, init_plugin, info);

mercurial