Mercurial > pidgin
comparison libpurple/protocols/novell/novell.c @ 15373:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | 0b6f337a46d5 |
comparison
equal
deleted
inserted
replaced
15372:f79e0f4df793 | 15373:5fe8042783c1 |
---|---|
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 GaimNotifyUserInfo *user_info = gaim_notify_user_info_new(); | |
1498 GString *info_text; | |
1499 int count, i; | |
1500 NMProperty *property; | |
1501 const char *tag, *value; | |
1502 | |
1503 info_text = g_string_new(""); | |
1504 | |
1505 tag = _("User ID"); | |
1506 value = nm_user_record_get_userid(user_record); | |
1507 if (value) { | |
1508 gaim_notify_user_info_add_pair(user_info, tag, value); | |
1509 } | |
1510 | |
1511 /* tag = _("DN"); | |
1512 value = nm_user_record_get_dn(user_record); | |
1513 if (value) { | |
1514 gaim_notify_user_info_add_pair(user_info, tag, value); | |
1515 } | |
1516 */ | |
1517 | |
1518 tag = _("Full name"); | |
1519 value = nm_user_record_get_full_name(user_record); | |
1520 if (value) { | |
1521 gaim_notify_user_info_add_pair(user_info, 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 gaim_notify_user_info_add_pair(user_info, tag, value); | |
1532 } | |
1533 nm_release_property(property); | |
1534 } | |
1535 } | |
1536 | |
1537 gaim_notify_userinfo(gc, nm_user_record_get_userid(user_record), | |
1538 user_info, NULL, NULL); | |
1539 gaim_notify_user_info_destroy(user_info); | |
1540 } | |
1541 | |
1542 /* Send a join conference, the first item in the parms list is the | |
1543 * NMUser object and the second item is the conference to join. | |
1544 * This callback is passed to gaim_request_action when we ask the | |
1545 * user if they want to join the conference. | |
1546 */ | |
1547 static void | |
1548 _join_conference_cb(GSList * parms) | |
1549 { | |
1550 NMUser *user; | |
1551 NMConference *conference; | |
1552 NMERR_T rc = NM_OK; | |
1553 | |
1554 if (parms == NULL || g_slist_length(parms) != 2) | |
1555 return; | |
1556 | |
1557 user = g_slist_nth_data(parms, 0); | |
1558 conference = g_slist_nth_data(parms, 1); | |
1559 | |
1560 if (user && conference) { | |
1561 rc = nm_send_join_conference(user, conference, | |
1562 _join_conf_resp_cb, conference); | |
1563 _check_for_disconnect(user, rc); | |
1564 } | |
1565 | |
1566 g_slist_free(parms); | |
1567 } | |
1568 | |
1569 /* Send a reject conference, the first item in the parms list is the | |
1570 * NMUser object and the second item is the conference to reject. | |
1571 * This callback is passed to gaim_request_action when we ask the | |
1572 * user if they want to joing the conference. | |
1573 */ | |
1574 static void | |
1575 _reject_conference_cb(GSList * parms) | |
1576 { | |
1577 NMUser *user; | |
1578 NMConference *conference; | |
1579 NMERR_T rc = NM_OK; | |
1580 | |
1581 if (parms == NULL || g_slist_length(parms) != 2) | |
1582 return; | |
1583 | |
1584 user = g_slist_nth_data(parms, 0); | |
1585 conference = g_slist_nth_data(parms, 1); | |
1586 | |
1587 if (user && conference) { | |
1588 rc = nm_send_reject_conference(user, conference, NULL, NULL); | |
1589 _check_for_disconnect(user, rc); | |
1590 } | |
1591 | |
1592 g_slist_free(parms); | |
1593 } | |
1594 | |
1595 static void | |
1596 _initiate_conference_cb(GaimBlistNode *node, gpointer ignored) | |
1597 { | |
1598 GaimBuddy *buddy; | |
1599 GaimConnection *gc; | |
1600 | |
1601 NMUser *user; | |
1602 const char *conf_name; | |
1603 GaimConversation *chat = NULL; | |
1604 NMUserRecord *user_record; | |
1605 NMConference *conference; | |
1606 | |
1607 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
1608 | |
1609 buddy = (GaimBuddy *) node; | |
1610 gc = gaim_account_get_connection(buddy->account); | |
1611 | |
1612 user = gc->proto_data; | |
1613 if (user == NULL) | |
1614 return; | |
1615 | |
1616 /* We should already have a userrecord for the buddy */ | |
1617 user_record = nm_find_user_record(user, buddy->name); | |
1618 if (user_record == NULL) | |
1619 return; | |
1620 | |
1621 conf_name = _get_conference_name(++user->conference_count); | |
1622 chat = serv_got_joined_chat(gc, user->conference_count, conf_name); | |
1623 if (chat) { | |
1624 | |
1625 conference = nm_create_conference(NULL); | |
1626 nm_conference_set_data(conference, (gpointer) chat); | |
1627 nm_send_create_conference(user, conference, _createconf_resp_send_invite, user_record); | |
1628 nm_release_conference(conference); | |
1629 } | |
1630 } | |
1631 | |
1632 const char * | |
1633 _get_conference_name(int id) | |
1634 { | |
1635 static char *name = NULL; | |
1636 | |
1637 if (name) | |
1638 g_free(name); | |
1639 | |
1640 name = g_strdup_printf(_("GroupWise Conference %d"), id); | |
1641 | |
1642 return name; | |
1643 } | |
1644 | |
1645 static void | |
1646 _show_privacy_locked_error(GaimConnection *gc, NMUser *user) | |
1647 { | |
1648 char *err; | |
1649 | |
1650 err = g_strdup_printf(_("Unable to change server side privacy settings (%s)."), | |
1651 nm_error_to_string(NMERR_ADMIN_LOCKED)); | |
1652 gaim_notify_error(gc, NULL, err, NULL); | |
1653 g_free(err); | |
1654 } | |
1655 | |
1656 /******************************************************************************* | |
1657 * Connect and recv callbacks | |
1658 ******************************************************************************/ | |
1659 | |
1660 static void | |
1661 novell_ssl_connect_error(GaimSslConnection * gsc, | |
1662 GaimSslErrorType error, gpointer data) | |
1663 { | |
1664 GaimConnection *gc; | |
1665 NMUser *user; | |
1666 | |
1667 gc = data; | |
1668 user = gc->proto_data; | |
1669 user->conn->ssl_conn->data = NULL; | |
1670 | |
1671 gaim_connection_error(gc, _("Unable to make SSL connection to server.")); | |
1672 } | |
1673 | |
1674 static void | |
1675 novell_ssl_recv_cb(gpointer data, GaimSslConnection * gsc, | |
1676 GaimInputCondition condition) | |
1677 { | |
1678 GaimConnection *gc = data; | |
1679 NMUser *user; | |
1680 NMERR_T rc; | |
1681 | |
1682 if (gc == NULL) | |
1683 return; | |
1684 | |
1685 user = gc->proto_data; | |
1686 if (user == NULL) | |
1687 return; | |
1688 | |
1689 rc = nm_process_new_data(user); | |
1690 if (rc != NM_OK) { | |
1691 | |
1692 if (_is_disconnect_error(rc)) { | |
1693 | |
1694 gaim_connection_error(gc, | |
1695 _("Error communicating with server." | |
1696 " Closing connection.")); | |
1697 } else { | |
1698 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
1699 "Error processing event or response (%d).\n", rc); | |
1700 } | |
1701 } | |
1702 } | |
1703 | |
1704 static void | |
1705 novell_ssl_connected_cb(gpointer data, GaimSslConnection * gsc, | |
1706 GaimInputCondition cond) | |
1707 { | |
1708 GaimConnection *gc = data; | |
1709 NMUser *user; | |
1710 NMConn *conn; | |
1711 NMERR_T rc = 0; | |
1712 const char *pwd = NULL; | |
1713 const char *my_addr = NULL; | |
1714 char *ua = NULL; | |
1715 | |
1716 if (gc == NULL || gsc == NULL) | |
1717 return; | |
1718 | |
1719 user = gc->proto_data; | |
1720 if ((user == NULL) || (conn = user->conn) == NULL) | |
1721 return; | |
1722 | |
1723 gaim_connection_update_progress(gc, _("Authenticating..."), | |
1724 2, NOVELL_CONNECT_STEPS); | |
1725 | |
1726 my_addr = gaim_network_get_my_ip(gsc->fd); | |
1727 pwd = gaim_connection_get_password(gc); | |
1728 ua = _user_agent_string(); | |
1729 | |
1730 rc = nm_send_login(user, pwd, my_addr, ua, _login_resp_cb, NULL); | |
1731 if (rc == NM_OK) { | |
1732 conn->connected = TRUE; | |
1733 gaim_ssl_input_add(gsc, novell_ssl_recv_cb, gc); | |
1734 } else { | |
1735 gaim_connection_error(gc, _("Unable to connect to server.")); | |
1736 } | |
1737 | |
1738 gaim_connection_update_progress(gc, _("Waiting for response..."), | |
1739 3, NOVELL_CONNECT_STEPS); | |
1740 | |
1741 g_free(ua); | |
1742 } | |
1743 | |
1744 /******************************************************************************* | |
1745 * Event callback and event handlers | |
1746 ******************************************************************************/ | |
1747 | |
1748 static void | |
1749 _evt_receive_message(NMUser * user, NMEvent * event) | |
1750 { | |
1751 NMUserRecord *user_record = NULL; | |
1752 NMContact *contact = NULL; | |
1753 GaimConversation *gconv; | |
1754 NMConference *conference; | |
1755 GaimMessageFlags flags; | |
1756 char *text = NULL; | |
1757 | |
1758 text = g_markup_escape_text(nm_event_get_text(event), -1); | |
1759 | |
1760 conference = nm_event_get_conference(event); | |
1761 if (conference) { | |
1762 | |
1763 GaimConversation *chat = nm_conference_get_data(conference); | |
1764 | |
1765 /* Is this a single person 'conversation' or a conference? */ | |
1766 if (chat == NULL && nm_conference_get_participant_count(conference) == 1) { | |
1767 | |
1768 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
1769 if (user_record) { | |
1770 | |
1771 flags = 0; | |
1772 if (nm_event_get_type(event) == NMEVT_RECEIVE_AUTOREPLY) | |
1773 flags |= GAIM_MESSAGE_AUTO_RESP; | |
1774 | |
1775 serv_got_im(gaim_account_get_connection(user->client_data), | |
1776 nm_user_record_get_display_id(user_record), | |
1777 text, flags, | |
1778 nm_event_get_gmt(event)); | |
1779 | |
1780 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, | |
1781 nm_user_record_get_display_id(user_record), | |
1782 (GaimAccount *) user->client_data); | |
1783 if (gconv) { | |
1784 | |
1785 contact = nm_find_contact(user, nm_event_get_source(event)); | |
1786 if (contact) { | |
1787 | |
1788 gaim_conversation_set_title( | |
1789 gconv, nm_contact_get_display_name(contact)); | |
1790 | |
1791 | |
1792 } else { | |
1793 | |
1794 const char *name = | |
1795 nm_user_record_get_full_name(user_record); | |
1796 | |
1797 if (name == NULL) | |
1798 name = nm_user_record_get_userid(user_record); | |
1799 | |
1800 gaim_conversation_set_title(gconv, name); | |
1801 } | |
1802 | |
1803 } | |
1804 | |
1805 } else { | |
1806 /* this should not happen, see the event code. | |
1807 * the event code will get the contact details from | |
1808 * the server if it does not have them before calling | |
1809 * the event callback. | |
1810 */ | |
1811 } | |
1812 | |
1813 } else if (chat) { | |
1814 | |
1815 /* get the contact for send if we have one */ | |
1816 NMContact *contact = nm_find_contact(user, | |
1817 nm_event_get_source(event)); | |
1818 | |
1819 /* get the user record for the sender */ | |
1820 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
1821 if (user_record) { | |
1822 const char *name = nm_contact_get_display_name(contact); | |
1823 | |
1824 if (name == NULL) { | |
1825 name = nm_user_record_get_full_name(user_record); | |
1826 if (name == NULL) | |
1827 name = nm_user_record_get_display_id(user_record); | |
1828 } | |
1829 | |
1830 serv_got_chat_in(gaim_account_get_connection(user->client_data), | |
1831 gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)), | |
1832 name, 0, text, nm_event_get_gmt(event)); | |
1833 } | |
1834 } | |
1835 } | |
1836 | |
1837 g_free(text); | |
1838 } | |
1839 | |
1840 static void | |
1841 _evt_conference_left(NMUser * user, NMEvent * event) | |
1842 { | |
1843 GaimConversation *chat; | |
1844 NMConference *conference; | |
1845 | |
1846 conference = nm_event_get_conference(event); | |
1847 if (conference) { | |
1848 chat = nm_conference_get_data(conference); | |
1849 if (chat) { | |
1850 NMUserRecord *ur = nm_find_user_record(user, | |
1851 nm_event_get_source(event)); | |
1852 | |
1853 if (ur) | |
1854 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat), | |
1855 nm_user_record_get_display_id(ur), | |
1856 NULL); | |
1857 } | |
1858 } | |
1859 } | |
1860 | |
1861 static void | |
1862 _evt_conference_invite_notify(NMUser * user, NMEvent * event) | |
1863 { | |
1864 GaimConversation *gconv; | |
1865 NMConference *conference; | |
1866 NMUserRecord *user_record = NULL; | |
1867 char *str = NULL; | |
1868 | |
1869 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
1870 conference = nm_event_get_conference(event); | |
1871 if (user_record && conference) { | |
1872 gconv = nm_conference_get_data(conference); | |
1873 str = g_strdup_printf(_("%s has been invited to this conversation."), | |
1874 nm_user_record_get_display_id(user_record)); | |
1875 gaim_conversation_write(gconv, NULL, str, | |
1876 GAIM_MESSAGE_SYSTEM, time(NULL)); | |
1877 g_free(str); | |
1878 } | |
1879 } | |
1880 | |
1881 static void | |
1882 _evt_conference_invite(NMUser * user, NMEvent * event) | |
1883 { | |
1884 NMUserRecord *ur; | |
1885 GaimConnection *gc; | |
1886 GSList *parms = NULL; | |
1887 const char *title = NULL; | |
1888 const char *secondary = NULL; | |
1889 const char *name = NULL; | |
1890 char *primary = NULL; | |
1891 time_t gmt; | |
1892 | |
1893 ur = nm_find_user_record(user, nm_event_get_source(event)); | |
1894 if (ur) | |
1895 name = nm_user_record_get_full_name(ur); | |
1896 | |
1897 if (name == NULL) | |
1898 name = nm_event_get_source(event); | |
1899 | |
1900 gmt = nm_event_get_gmt(event); | |
1901 title = _("Invitation to Conversation"); | |
1902 primary = g_strdup_printf(_("Invitation from: %s\n\nSent: %s"), | |
1903 name, gaim_date_format_full(localtime(&gmt))); | |
1904 secondary = _("Would you like to join the conversation?"); | |
1905 | |
1906 /* Set up parms list for the callbacks | |
1907 * We need to send the NMUser object and | |
1908 * the NMConference object to the callbacks | |
1909 */ | |
1910 parms = NULL; | |
1911 parms = g_slist_append(parms, user); | |
1912 parms = g_slist_append(parms, nm_event_get_conference(event)); | |
1913 | |
1914 /* Prompt the user */ | |
1915 gc = gaim_account_get_connection(user->client_data); | |
1916 gaim_request_action(gc, title, primary, secondary, | |
1917 GAIM_DEFAULT_ACTION_NONE, parms, 2, | |
1918 _("Yes"), G_CALLBACK(_join_conference_cb), | |
1919 _("No"), G_CALLBACK(_reject_conference_cb)); | |
1920 | |
1921 g_free(primary); | |
1922 } | |
1923 | |
1924 | |
1925 static void | |
1926 _evt_conference_joined(NMUser * user, NMEvent * event) | |
1927 { | |
1928 GaimConversation *chat = NULL; | |
1929 GaimConnection *gc; | |
1930 NMConference *conference = NULL; | |
1931 NMUserRecord *ur = NULL; | |
1932 const char *name; | |
1933 const char *conf_name; | |
1934 | |
1935 gc = gaim_account_get_connection(user->client_data); | |
1936 if (gc == NULL) | |
1937 return; | |
1938 | |
1939 conference = nm_event_get_conference(event); | |
1940 if (conference) { | |
1941 chat = nm_conference_get_data(conference); | |
1942 if (nm_conference_get_participant_count(conference) == 2 && chat == NULL) { | |
1943 ur = nm_conference_get_participant(conference, 0); | |
1944 if (ur) { | |
1945 conf_name = _get_conference_name(++user->conference_count); | |
1946 chat = | |
1947 serv_got_joined_chat(gc, user->conference_count, conf_name); | |
1948 if (chat) { | |
1949 | |
1950 nm_conference_set_data(conference, (gpointer) chat); | |
1951 | |
1952 name = nm_user_record_get_display_id(ur); | |
1953 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL, | |
1954 GAIM_CBFLAGS_NONE, TRUE); | |
1955 | |
1956 } | |
1957 } | |
1958 } | |
1959 | |
1960 if (chat != NULL) { | |
1961 ur = nm_find_user_record(user, nm_event_get_source(event)); | |
1962 if (ur) { | |
1963 name = nm_user_record_get_display_id(ur); | |
1964 if (!gaim_conv_chat_find_user(GAIM_CONV_CHAT(chat), name)) { | |
1965 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL, | |
1966 GAIM_CBFLAGS_NONE, TRUE); | |
1967 } | |
1968 } | |
1969 } | |
1970 } | |
1971 } | |
1972 | |
1973 static void | |
1974 _evt_status_change(NMUser * user, NMEvent * event) | |
1975 { | |
1976 GaimBuddy *buddy = NULL; | |
1977 GSList *buddies; | |
1978 GSList *bnode; | |
1979 NMUserRecord *user_record; | |
1980 const char *display_id; | |
1981 int status; | |
1982 | |
1983 user_record = nm_event_get_user_record(event); | |
1984 if (user_record) { | |
1985 | |
1986 /* Retrieve new status */ | |
1987 status = nm_user_record_get_status(user_record); | |
1988 | |
1989 /* Update status for buddy in all folders */ | |
1990 display_id = nm_user_record_get_display_id(user_record); | |
1991 buddies = gaim_find_buddies(user->client_data, display_id); | |
1992 for (bnode = buddies; bnode; bnode = bnode->next) { | |
1993 buddy = (GaimBuddy *) bnode->data; | |
1994 if (buddy) { | |
1995 _update_buddy_status(user, buddy, status, nm_event_get_gmt(event)); | |
1996 } | |
1997 } | |
1998 | |
1999 g_slist_free(buddies); | |
2000 | |
2001 } | |
2002 } | |
2003 | |
2004 static void | |
2005 _evt_user_disconnect(NMUser * user, NMEvent * event) | |
2006 { | |
2007 GaimConnection *gc; | |
2008 | |
2009 gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
2010 if (gc) | |
2011 { | |
2012 gc->wants_to_die = TRUE; /* we don't want to reconnect in this case */ | |
2013 gaim_connection_error(gc, _("You have been logged out because you" | |
2014 " logged in at another workstation.")); | |
2015 } | |
2016 } | |
2017 | |
2018 static void | |
2019 _evt_user_typing(NMUser * user, NMEvent * event) | |
2020 { | |
2021 GaimConnection *gc; | |
2022 NMUserRecord *user_record = NULL; | |
2023 | |
2024 gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
2025 if (gc) { | |
2026 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
2027 if (user_record) { | |
2028 serv_got_typing(gc, nm_user_record_get_display_id(user_record), | |
2029 30, GAIM_TYPING); | |
2030 } | |
2031 } | |
2032 } | |
2033 | |
2034 static void | |
2035 _evt_user_not_typing(NMUser * user, NMEvent * event) | |
2036 { | |
2037 GaimConnection *gc; | |
2038 NMUserRecord *user_record; | |
2039 | |
2040 gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
2041 if (gc) { | |
2042 user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
2043 if (user_record) { | |
2044 serv_got_typing_stopped(gc, | |
2045 nm_user_record_get_display_id(user_record)); | |
2046 } | |
2047 } | |
2048 } | |
2049 | |
2050 static void | |
2051 _evt_undeliverable_status(NMUser * user, NMEvent * event) | |
2052 { | |
2053 NMUserRecord *ur; | |
2054 GaimConversation *gconv; | |
2055 char *str; | |
2056 | |
2057 ur = nm_find_user_record(user, nm_event_get_source(event)); | |
2058 if (ur) { | |
2059 /* XXX - Should this be GAIM_CONV_TYPE_IM? */ | |
2060 gconv = | |
2061 gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, | |
2062 nm_user_record_get_display_id(ur), | |
2063 user->client_data); | |
2064 if (gconv) { | |
2065 const char *name = nm_user_record_get_full_name(ur); | |
2066 | |
2067 if (name == NULL) { | |
2068 name = nm_user_record_get_display_id(ur); | |
2069 } | |
2070 str = g_strdup_printf(_("%s appears to be offline and did not receive" | |
2071 " the message that you just sent."), name); | |
2072 gaim_conversation_write(gconv, NULL, str, | |
2073 GAIM_MESSAGE_SYSTEM, time(NULL)); | |
2074 g_free(str); | |
2075 } | |
2076 } | |
2077 } | |
2078 | |
2079 static void | |
2080 _event_callback(NMUser * user, NMEvent * event) | |
2081 { | |
2082 if (user == NULL || event == NULL) | |
2083 return; | |
2084 | |
2085 switch (nm_event_get_type(event)) { | |
2086 case NMEVT_STATUS_CHANGE: | |
2087 _evt_status_change(user, event); | |
2088 break; | |
2089 case NMEVT_RECEIVE_AUTOREPLY: | |
2090 case NMEVT_RECEIVE_MESSAGE: | |
2091 _evt_receive_message(user, event); | |
2092 break; | |
2093 case NMEVT_USER_DISCONNECT: | |
2094 _evt_user_disconnect(user, event); | |
2095 break; | |
2096 case NMEVT_USER_TYPING: | |
2097 _evt_user_typing(user, event); | |
2098 break; | |
2099 case NMEVT_USER_NOT_TYPING: | |
2100 _evt_user_not_typing(user, event); | |
2101 break; | |
2102 case NMEVT_SERVER_DISCONNECT: | |
2103 /* Nothing to do? */ | |
2104 break; | |
2105 case NMEVT_INVALID_RECIPIENT: | |
2106 break; | |
2107 case NMEVT_UNDELIVERABLE_STATUS: | |
2108 _evt_undeliverable_status(user, event); | |
2109 break; | |
2110 case NMEVT_CONFERENCE_INVITE_NOTIFY: | |
2111 /* Someone else has been invited to join a | |
2112 * conference that we are currently a part of | |
2113 */ | |
2114 _evt_conference_invite_notify(user, event); | |
2115 break; | |
2116 case NMEVT_CONFERENCE_INVITE: | |
2117 /* We have been invited to join a conference */ | |
2118 _evt_conference_invite(user, event); | |
2119 break; | |
2120 case NMEVT_CONFERENCE_JOINED: | |
2121 /* Some one has joined a conference that we | |
2122 * are a part of | |
2123 */ | |
2124 _evt_conference_joined(user, event); | |
2125 break; | |
2126 case NMEVT_CONFERENCE_LEFT: | |
2127 /* Someone else has left a conference that we | |
2128 * are currently a part of | |
2129 */ | |
2130 _evt_conference_left(user, event); | |
2131 break; | |
2132 default: | |
2133 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
2134 "_event_callback(): unhandled event, %d\n", | |
2135 nm_event_get_type(event)); | |
2136 break; | |
2137 } | |
2138 } | |
2139 | |
2140 /******************************************************************************* | |
2141 * Prpl Ops | |
2142 ******************************************************************************/ | |
2143 | |
2144 static void | |
2145 novell_login(GaimAccount * account) | |
2146 { | |
2147 GaimConnection *gc; | |
2148 NMUser *user = NULL; | |
2149 const char *server; | |
2150 const char *name; | |
2151 int port; | |
2152 | |
2153 if (account == NULL) | |
2154 return; | |
2155 | |
2156 gc = gaim_account_get_connection(account); | |
2157 if (gc == NULL) | |
2158 return; | |
2159 | |
2160 server = gaim_account_get_string(account, "server", NULL); | |
2161 if (server == NULL || *server == '\0') { | |
2162 | |
2163 /* TODO: Would be nice to prompt if not set! | |
2164 * gaim_request_fields(gc, _("Server Address"),...); | |
2165 */ | |
2166 | |
2167 /* ...but for now just error out with a nice message. */ | |
2168 gaim_connection_error(gc, _("Unable to connect to server." | |
2169 " Please enter the address of the server" | |
2170 " you wish to connect to.")); | |
2171 return; | |
2172 } | |
2173 | |
2174 port = gaim_account_get_int(account, "port", DEFAULT_PORT); | |
2175 name = gaim_account_get_username(account); | |
2176 | |
2177 user = nm_initialize_user(name, server, port, account, _event_callback); | |
2178 if (user && user->conn) { | |
2179 /* save user */ | |
2180 gc->proto_data = user; | |
2181 | |
2182 /* connect to the server */ | |
2183 gaim_connection_update_progress(gc, _("Connecting"), | |
2184 1, NOVELL_CONNECT_STEPS); | |
2185 | |
2186 user->conn->use_ssl = TRUE; | |
2187 | |
2188 user->conn->ssl_conn = g_new0(NMSSLConn, 1); | |
2189 user->conn->ssl_conn->read = (nm_ssl_read_cb) gaim_ssl_read; | |
2190 user->conn->ssl_conn->write = (nm_ssl_write_cb) gaim_ssl_write; | |
2191 | |
2192 user->conn->ssl_conn->data = gaim_ssl_connect(user->client_data, | |
2193 user->conn->addr, user->conn->port, | |
2194 novell_ssl_connected_cb, novell_ssl_connect_error, gc); | |
2195 if (user->conn->ssl_conn->data == NULL) { | |
2196 gaim_connection_error(gc, _("Error." | |
2197 " SSL support is not installed.")); | |
2198 } | |
2199 } | |
2200 } | |
2201 | |
2202 static void | |
2203 novell_close(GaimConnection * gc) | |
2204 { | |
2205 NMUser *user; | |
2206 NMConn *conn; | |
2207 | |
2208 if (gc == NULL) | |
2209 return; | |
2210 | |
2211 user = gc->proto_data; | |
2212 if (user) { | |
2213 conn = user->conn; | |
2214 if (conn && conn->ssl_conn) { | |
2215 gaim_ssl_close(user->conn->ssl_conn->data); | |
2216 } | |
2217 nm_deinitialize_user(user); | |
2218 } | |
2219 gc->proto_data = NULL; | |
2220 } | |
2221 | |
2222 static int | |
2223 novell_send_im(GaimConnection * gc, const char *name, | |
2224 const char *message_body, GaimMessageFlags flags) | |
2225 { | |
2226 NMUserRecord *user_record = NULL; | |
2227 NMConference *conf = NULL; | |
2228 NMMessage *message; | |
2229 NMUser *user; | |
2230 const char *dn = NULL; | |
2231 char *plain; | |
2232 gboolean done = TRUE, created_conf = FALSE; | |
2233 NMERR_T rc = NM_OK; | |
2234 | |
2235 if (gc == NULL || name == NULL || | |
2236 message_body == NULL || *message_body == '\0') | |
2237 return 0; | |
2238 | |
2239 user = gc->proto_data; | |
2240 if (user == NULL) | |
2241 return 0; | |
2242 | |
2243 /* Create a new message */ | |
2244 plain = gaim_unescape_html(message_body); | |
2245 message = nm_create_message(plain); | |
2246 g_free(plain); | |
2247 | |
2248 /* Need to get the DN for the buddy so we can look up the convo */ | |
2249 dn = nm_lookup_dn(user, name); | |
2250 | |
2251 /* Do we already know about the sender? */ | |
2252 user_record = nm_find_user_record(user, dn); | |
2253 if (user_record) { | |
2254 | |
2255 /* Do we already have an instantiated conference? */ | |
2256 conf = nm_find_conversation(user, dn); | |
2257 if (conf == NULL) { | |
2258 | |
2259 /* If not, create a blank conference */ | |
2260 conf = nm_create_conference(NULL); | |
2261 created_conf = TRUE; | |
2262 | |
2263 nm_conference_add_participant(conf, user_record); | |
2264 } | |
2265 | |
2266 nm_message_set_conference(message, conf); | |
2267 | |
2268 /* Make sure conference is instantiated */ | |
2269 if (!nm_conference_is_instantiated(conf)) { | |
2270 | |
2271 /* It is not, so send the createconf. We will | |
2272 * have to finish sending the message when we | |
2273 * get the response with the new conference guid. | |
2274 */ | |
2275 rc = nm_send_create_conference(user, conf, _createconf_resp_send_msg, message); | |
2276 _check_for_disconnect(user, rc); | |
2277 | |
2278 done = FALSE; | |
2279 } | |
2280 | |
2281 } else { | |
2282 | |
2283 /* If we don't have details for the user, then we don't have | |
2284 * a conference yet. So create one and send the getdetails | |
2285 * to the server. We will have to finish sending the message | |
2286 * when we get the response from the server. | |
2287 */ | |
2288 conf = nm_create_conference(NULL); | |
2289 created_conf = TRUE; | |
2290 | |
2291 nm_message_set_conference(message, conf); | |
2292 | |
2293 rc = nm_send_get_details(user, name, _get_details_resp_send_msg, message); | |
2294 _check_for_disconnect(user, rc); | |
2295 | |
2296 done = FALSE; | |
2297 } | |
2298 | |
2299 if (done) { | |
2300 | |
2301 /* Did we find everything we needed? */ | |
2302 rc = nm_send_message(user, message, _send_message_resp_cb); | |
2303 _check_for_disconnect(user, rc); | |
2304 | |
2305 nm_release_message(message); | |
2306 } | |
2307 | |
2308 if (created_conf && conf) | |
2309 nm_release_conference(conf); | |
2310 | |
2311 return 1; | |
2312 } | |
2313 | |
2314 static unsigned int | |
2315 novell_send_typing(GaimConnection * gc, const char *name, GaimTypingState state) | |
2316 { | |
2317 NMConference *conf = NULL; | |
2318 NMUser *user; | |
2319 const char *dn = NULL; | |
2320 NMERR_T rc = NM_OK; | |
2321 | |
2322 if (gc == NULL || name == NULL) | |
2323 return 0; | |
2324 | |
2325 user = gc->proto_data; | |
2326 if (user == NULL) | |
2327 return 0; | |
2328 | |
2329 /* Need to get the DN for the buddy so we can look up the convo */ | |
2330 dn = nm_lookup_dn(user, name); | |
2331 if (dn) { | |
2332 | |
2333 /* Now find the conference in our list */ | |
2334 conf = nm_find_conversation(user, dn); | |
2335 if (conf) { | |
2336 | |
2337 rc = nm_send_typing(user, conf, | |
2338 ((state == GAIM_TYPING) ? TRUE : FALSE), NULL); | |
2339 _check_for_disconnect(user, rc); | |
2340 | |
2341 } | |
2342 | |
2343 } | |
2344 | |
2345 return 0; | |
2346 } | |
2347 | |
2348 static void | |
2349 novell_convo_closed(GaimConnection * gc, const char *who) | |
2350 { | |
2351 NMUser *user; | |
2352 NMConference *conf; | |
2353 const char *dn; | |
2354 NMERR_T rc = NM_OK; | |
2355 | |
2356 if (gc == NULL || who == NULL) | |
2357 return; | |
2358 | |
2359 user = gc->proto_data; | |
2360 if (user && (dn = nm_lookup_dn(user, who))) { | |
2361 conf = nm_find_conversation(user, dn); | |
2362 if (conf) { | |
2363 rc = nm_send_leave_conference(user, conf, NULL, NULL); | |
2364 _check_for_disconnect(user, rc); | |
2365 } | |
2366 } | |
2367 } | |
2368 | |
2369 static void | |
2370 novell_chat_leave(GaimConnection * gc, int id) | |
2371 { | |
2372 NMConference *conference; | |
2373 NMUser *user; | |
2374 GaimConversation *chat; | |
2375 GSList *cnode; | |
2376 NMERR_T rc = NM_OK; | |
2377 | |
2378 if (gc == NULL) | |
2379 return; | |
2380 | |
2381 user = gc->proto_data; | |
2382 if (user == NULL) | |
2383 return; | |
2384 | |
2385 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) { | |
2386 conference = cnode->data; | |
2387 if (conference && (chat = nm_conference_get_data(conference))) { | |
2388 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) { | |
2389 rc = nm_send_leave_conference(user, conference, NULL, NULL); | |
2390 _check_for_disconnect(user, rc); | |
2391 break; | |
2392 } | |
2393 } | |
2394 } | |
2395 | |
2396 serv_got_chat_left(gc, id); | |
2397 } | |
2398 | |
2399 static void | |
2400 novell_chat_invite(GaimConnection *gc, int id, | |
2401 const char *message, const char *who) | |
2402 { | |
2403 NMConference *conference; | |
2404 NMUser *user; | |
2405 GaimConversation *chat; | |
2406 GSList *cnode; | |
2407 NMERR_T rc = NM_OK; | |
2408 NMUserRecord *user_record = NULL; | |
2409 | |
2410 if (gc == NULL) | |
2411 return; | |
2412 | |
2413 user = gc->proto_data; | |
2414 if (user == NULL) | |
2415 return; | |
2416 | |
2417 user_record = nm_find_user_record(user, who); | |
2418 if (user_record == NULL) { | |
2419 rc = nm_send_get_details(user, who, _get_details_resp_send_invite, GINT_TO_POINTER(id)); | |
2420 _check_for_disconnect(user, rc); | |
2421 return; | |
2422 } | |
2423 | |
2424 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) { | |
2425 conference = cnode->data; | |
2426 if (conference && (chat = nm_conference_get_data(conference))) { | |
2427 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) { | |
2428 rc = nm_send_conference_invite(user, conference, user_record, | |
2429 message, _sendinvite_resp_cb, NULL); | |
2430 _check_for_disconnect(user, rc); | |
2431 break; | |
2432 } | |
2433 } | |
2434 } | |
2435 } | |
2436 | |
2437 static int | |
2438 novell_chat_send(GaimConnection * gc, int id, const char *text, GaimMessageFlags flags) | |
2439 { | |
2440 NMConference *conference; | |
2441 GaimConversation *chat; | |
2442 GSList *cnode; | |
2443 NMMessage *message; | |
2444 NMUser *user; | |
2445 NMERR_T rc = NM_OK; | |
2446 const char *name; | |
2447 char *str, *plain; | |
2448 | |
2449 if (gc == NULL || text == NULL) | |
2450 return -1; | |
2451 | |
2452 user = gc->proto_data; | |
2453 if (user == NULL) | |
2454 return -1; | |
2455 | |
2456 plain = gaim_unescape_html(text); | |
2457 message = nm_create_message(plain); | |
2458 g_free(plain); | |
2459 | |
2460 for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) { | |
2461 conference = cnode->data; | |
2462 if (conference && (chat = nm_conference_get_data(conference))) { | |
2463 if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) { | |
2464 | |
2465 nm_message_set_conference(message, conference); | |
2466 | |
2467 /* check to see if the conference is instatiated yet */ | |
2468 if (!nm_conference_is_instantiated(conference)) { | |
2469 nm_message_add_ref(message); | |
2470 nm_send_create_conference(user, conference, _createconf_resp_send_msg, message); | |
2471 } else { | |
2472 rc = nm_send_message(user, message, _send_message_resp_cb); | |
2473 } | |
2474 | |
2475 nm_release_message(message); | |
2476 | |
2477 if (!_check_for_disconnect(user, rc)) { | |
2478 | |
2479 /* Use the account alias if it is set */ | |
2480 name = gaim_account_get_alias(user->client_data); | |
2481 if (name == NULL || *name == '\0') { | |
2482 | |
2483 /* If there is no account alias, try full name */ | |
2484 name = nm_user_record_get_full_name(user->user_record); | |
2485 if (name == NULL || *name == '\0') { | |
2486 | |
2487 /* Fall back to the username that we are signed in with */ | |
2488 name = gaim_account_get_username(user->client_data); | |
2489 } | |
2490 } | |
2491 | |
2492 serv_got_chat_in(gc, id, name, 0, text, time(NULL)); | |
2493 return 0; | |
2494 } else | |
2495 return -1; | |
2496 | |
2497 } | |
2498 } | |
2499 } | |
2500 | |
2501 | |
2502 /* The conference was not found, must be closed */ | |
2503 chat = gaim_find_chat(gc, id); | |
2504 if (chat) { | |
2505 str = g_strdup_printf(_("This conference has been closed." | |
2506 " No more messages can be sent.")); | |
2507 gaim_conversation_write(chat, NULL, str, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
2508 g_free(str); | |
2509 } | |
2510 | |
2511 if (message) | |
2512 nm_release_message(message); | |
2513 | |
2514 return -1; | |
2515 } | |
2516 | |
2517 static void | |
2518 novell_add_buddy(GaimConnection * gc, GaimBuddy *buddy, GaimGroup * group) | |
2519 { | |
2520 NMFolder *folder = NULL; | |
2521 NMContact *contact; | |
2522 NMUser *user; | |
2523 NMERR_T rc = NM_OK; | |
2524 const char *alias, *gname; | |
2525 | |
2526 if (gc == NULL || buddy == NULL || group == NULL) | |
2527 return; | |
2528 | |
2529 user = (NMUser *) gc->proto_data; | |
2530 if (user == NULL) | |
2531 return; | |
2532 | |
2533 /* If we haven't synched the contact list yet, ignore | |
2534 * the add_buddy calls. Server side list is the master. | |
2535 */ | |
2536 if (!user->clist_synched) | |
2537 return; | |
2538 | |
2539 contact = nm_create_contact(); | |
2540 nm_contact_set_dn(contact, buddy->name); | |
2541 | |
2542 /* Remove the GaimBuddy (we will add it back after adding it | |
2543 * to the server side list). Save the alias if there is one. | |
2544 */ | |
2545 alias = gaim_buddy_get_alias(buddy); | |
2546 if (alias && strcmp(alias, buddy->name)) | |
2547 nm_contact_set_display_name(contact, alias); | |
2548 | |
2549 gaim_blist_remove_buddy(buddy); | |
2550 buddy = NULL; | |
2551 | |
2552 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) { | |
2553 gname = ""; | |
2554 } else { | |
2555 gname = group->name; | |
2556 } | |
2557 | |
2558 folder = nm_find_folder(user, gname); | |
2559 if (folder) { | |
2560 | |
2561 /* We have everything that we need, so send the createcontact */ | |
2562 rc = nm_send_create_contact(user, folder, contact, | |
2563 _create_contact_resp_cb, contact); | |
2564 | |
2565 } else { | |
2566 | |
2567 /* Need to create the folder before we can add the contact */ | |
2568 rc = nm_send_create_folder(user, gname, | |
2569 _create_folder_resp_add_contact, contact); | |
2570 } | |
2571 | |
2572 _check_for_disconnect(user, rc); | |
2573 | |
2574 } | |
2575 | |
2576 static void | |
2577 novell_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
2578 { | |
2579 NMContact *contact; | |
2580 NMFolder *folder; | |
2581 NMUser *user; | |
2582 const char *dn, *gname; | |
2583 NMERR_T rc = NM_OK; | |
2584 | |
2585 if (gc == NULL || buddy == NULL || group == NULL) | |
2586 return; | |
2587 | |
2588 user = (NMUser *) gc->proto_data; | |
2589 if (user && (dn = nm_lookup_dn(user, buddy->name))) { | |
2590 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) { | |
2591 gname = ""; | |
2592 } else { | |
2593 gname = group->name; | |
2594 } | |
2595 folder = nm_find_folder(user, gname); | |
2596 if (folder) { | |
2597 contact = nm_folder_find_contact(folder, dn); | |
2598 if (contact) { | |
2599 | |
2600 /* Remove the buddy from the contact */ | |
2601 nm_contact_set_data(contact, NULL); | |
2602 | |
2603 /* Tell the server to remove the contact */ | |
2604 rc = nm_send_remove_contact(user, folder, contact, | |
2605 _remove_contact_resp_cb, NULL); | |
2606 _check_for_disconnect(user, rc); | |
2607 } | |
2608 } | |
2609 } | |
2610 } | |
2611 | |
2612 static void | |
2613 novell_remove_group(GaimConnection * gc, GaimGroup *group) | |
2614 { | |
2615 NMUser *user; | |
2616 NMERR_T rc = NM_OK; | |
2617 | |
2618 if (gc == NULL || group == NULL) | |
2619 return; | |
2620 | |
2621 user = (NMUser *) gc->proto_data; | |
2622 if (user) { | |
2623 NMFolder *folder = nm_find_folder(user, group->name); | |
2624 | |
2625 if (folder) { | |
2626 rc = nm_send_remove_folder(user, folder, | |
2627 _remove_folder_resp_cb, NULL); | |
2628 _check_for_disconnect(user, rc); | |
2629 } | |
2630 } | |
2631 } | |
2632 | |
2633 static void | |
2634 novell_alias_buddy(GaimConnection * gc, const char *name, const char *alias) | |
2635 { | |
2636 NMContact *contact; | |
2637 NMUser *user; | |
2638 GList *contacts = NULL; | |
2639 GList *cnode = NULL; | |
2640 const char *dn = NULL, *fname = NULL; | |
2641 NMERR_T rc = NM_OK; | |
2642 | |
2643 if (gc == NULL || name == NULL || alias == NULL) | |
2644 return; | |
2645 | |
2646 user = (NMUser *) gc->proto_data; | |
2647 if (user && (dn = nm_lookup_dn(user, name))) { | |
2648 | |
2649 /* Alias all of instances of the contact */ | |
2650 contacts = nm_find_contacts(user, dn); | |
2651 for (cnode = contacts; cnode != NULL; cnode = cnode->next) { | |
2652 contact = (NMContact *) cnode->data; | |
2653 if (contact) { | |
2654 GaimGroup *group = NULL; | |
2655 GaimBuddy *buddy; | |
2656 NMFolder *folder; | |
2657 | |
2658 /* Alias the Gaim buddy? */ | |
2659 folder = nm_find_folder_by_id(user, | |
2660 nm_contact_get_parent_id(contact)); | |
2661 if (folder) { | |
2662 fname = nm_folder_get_name(folder); | |
2663 if (*fname == '\0') { | |
2664 fname = NM_ROOT_FOLDER_NAME; | |
2665 } | |
2666 group = gaim_find_group(fname); | |
2667 } | |
2668 | |
2669 if (group) { | |
2670 buddy = gaim_find_buddy_in_group(user->client_data, | |
2671 name, group); | |
2672 if (buddy && strcmp(buddy->alias, alias)) | |
2673 gaim_blist_alias_buddy(buddy, alias); | |
2674 } | |
2675 | |
2676 /* Tell the server to alias the contact */ | |
2677 rc = nm_send_rename_contact(user, contact, alias, | |
2678 _rename_contact_resp_cb, NULL); | |
2679 _check_for_disconnect(user, rc); | |
2680 } | |
2681 } | |
2682 if (contacts) | |
2683 g_list_free(contacts); | |
2684 } | |
2685 } | |
2686 | |
2687 static void | |
2688 novell_group_buddy(GaimConnection * gc, | |
2689 const char *name, const char *old_group_name, | |
2690 const char *new_group_name) | |
2691 { | |
2692 NMFolder *old_folder; | |
2693 NMFolder *new_folder; | |
2694 NMContact *contact; | |
2695 NMUser *user; | |
2696 const char *dn; | |
2697 NMERR_T rc = NM_OK; | |
2698 | |
2699 if (gc == NULL || name == NULL || | |
2700 old_group_name == NULL || new_group_name == NULL) | |
2701 return; | |
2702 | |
2703 user = (NMUser *) gc->proto_data; | |
2704 if (user && (dn = nm_lookup_dn(user, name))) { | |
2705 | |
2706 /* Find the old folder */ | |
2707 if (strcmp(old_group_name, NM_ROOT_FOLDER_NAME) == 0) { | |
2708 old_folder = nm_get_root_folder(user); | |
2709 if (nm_folder_find_contact(old_folder, dn) == NULL) | |
2710 old_folder = nm_find_folder(user, old_group_name); | |
2711 } else { | |
2712 old_folder = nm_find_folder(user, old_group_name); | |
2713 } | |
2714 | |
2715 if (old_folder && (contact = nm_folder_find_contact(old_folder, dn))) { | |
2716 | |
2717 /* Find the new folder */ | |
2718 new_folder = nm_find_folder(user, new_group_name); | |
2719 if (new_folder == NULL) { | |
2720 if (strcmp(new_group_name, NM_ROOT_FOLDER_NAME) == 0) | |
2721 new_folder = nm_get_root_folder(user); | |
2722 } | |
2723 | |
2724 if (new_folder) { | |
2725 | |
2726 /* Tell the server to move the contact to the new folder */ | |
2727 rc = nm_send_move_contact(user, contact, new_folder, | |
2728 _move_contact_resp_cb, NULL); | |
2729 | |
2730 } else { | |
2731 | |
2732 nm_contact_add_ref(contact); | |
2733 | |
2734 /* Remove the old contact first */ | |
2735 nm_send_remove_contact(user, old_folder, contact, | |
2736 _remove_contact_resp_cb, NULL); | |
2737 | |
2738 /* New folder does not exist yet, so create it */ | |
2739 rc = nm_send_create_folder(user, new_group_name, | |
2740 _create_folder_resp_move_contact, | |
2741 contact); | |
2742 } | |
2743 | |
2744 _check_for_disconnect(user, rc); | |
2745 } | |
2746 } | |
2747 } | |
2748 | |
2749 static void | |
2750 novell_rename_group(GaimConnection * gc, const char *old_name, | |
2751 GaimGroup *group, GList *moved_buddies) | |
2752 { | |
2753 NMERR_T rc = NM_OK; | |
2754 NMFolder *folder; | |
2755 NMUser *user; | |
2756 | |
2757 if (gc == NULL || old_name == NULL || group == NULL || moved_buddies == NULL) { | |
2758 return; | |
2759 } | |
2760 | |
2761 user = gc->proto_data; | |
2762 if (user) { | |
2763 /* Does new folder exist already? */ | |
2764 if (nm_find_folder(user, group->name)) { | |
2765 /* gaim_blist_rename_group() adds the buddies | |
2766 * to the new group and removes the old group... | |
2767 * so there is nothing more to do here. | |
2768 */ | |
2769 return; | |
2770 } | |
2771 | |
2772 if (strcmp(old_name, NM_ROOT_FOLDER_NAME) == 0) { | |
2773 /* Can't rename the root folder ... need to revisit this */ | |
2774 return; | |
2775 } | |
2776 | |
2777 folder = nm_find_folder(user, old_name); | |
2778 if (folder) { | |
2779 rc = nm_send_rename_folder(user, folder, group->name, | |
2780 _rename_folder_resp_cb, NULL); | |
2781 _check_for_disconnect(user, rc); | |
2782 } | |
2783 } | |
2784 } | |
2785 | |
2786 static void | |
2787 novell_list_emblems(GaimBuddy * buddy, const char **se, const char **sw, const char **nw, const char **ne) | |
2788 { | |
2789 NMUserRecord *user_record = NULL; | |
2790 GaimConnection *gc; | |
2791 NMUser *user; | |
2792 int status = 0; | |
2793 | |
2794 gc = gaim_account_get_connection(buddy->account); | |
2795 | |
2796 if (gc == NULL || (user = gc->proto_data) == NULL) | |
2797 return; | |
2798 | |
2799 user_record = nm_find_user_record(user, buddy->name); | |
2800 | |
2801 if (user_record) | |
2802 status = nm_user_record_get_status(user_record); | |
2803 | |
2804 switch (status) { | |
2805 case NM_STATUS_AVAILABLE: | |
2806 *se = ""; | |
2807 break; | |
2808 case NM_STATUS_AWAY: | |
2809 *se = "away"; | |
2810 break; | |
2811 case NM_STATUS_BUSY: | |
2812 *se = "occupied"; | |
2813 break; | |
2814 case NM_STATUS_UNKNOWN: | |
2815 *se = "error"; | |
2816 break; | |
2817 } | |
2818 } | |
2819 | |
2820 static const char * | |
2821 novell_list_icon(GaimAccount * account, GaimBuddy * buddy) | |
2822 { | |
2823 return "novell"; | |
2824 } | |
2825 | |
2826 static void | |
2827 novell_tooltip_text(GaimBuddy * buddy, GaimNotifyUserInfo * user_info, gboolean full) | |
2828 { | |
2829 NMUserRecord *user_record = NULL; | |
2830 GaimConnection *gc; | |
2831 NMUser *user; | |
2832 int status = 0; | |
2833 const char *status_str = NULL; | |
2834 const char *text = NULL; | |
2835 | |
2836 if (buddy == NULL) | |
2837 return; | |
2838 | |
2839 gc = gaim_account_get_connection(buddy->account); | |
2840 if (gc == NULL || (user = gc->proto_data) == NULL) | |
2841 return; | |
2842 | |
2843 if (GAIM_BUDDY_IS_ONLINE(buddy)) { | |
2844 user_record = nm_find_user_record(user, buddy->name); | |
2845 if (user_record) { | |
2846 status = nm_user_record_get_status(user_record); | |
2847 text = nm_user_record_get_status_text(user_record); | |
2848 /* No custom text, so default it ... */ | |
2849 switch (status) { | |
2850 case NM_STATUS_AVAILABLE: | |
2851 status_str = _("Available"); | |
2852 break; | |
2853 case NM_STATUS_AWAY: | |
2854 status_str = _("Away"); | |
2855 break; | |
2856 case NM_STATUS_BUSY: | |
2857 status_str = _("Busy"); | |
2858 break; | |
2859 case NM_STATUS_AWAY_IDLE: | |
2860 status_str = _("Idle"); | |
2861 break; | |
2862 case NM_STATUS_OFFLINE: | |
2863 status_str = _("Offline"); | |
2864 break; | |
2865 default: | |
2866 status_str = _("Unknown"); | |
2867 break; | |
2868 } | |
2869 | |
2870 gaim_notify_user_info_add_pair(user_info, _("Status"), status_str); | |
2871 | |
2872 if (text) | |
2873 gaim_notify_user_info_add_pair(user_info, _("Message"), text); | |
2874 } | |
2875 } | |
2876 } | |
2877 | |
2878 static void | |
2879 novell_set_idle(GaimConnection * gc, int time) | |
2880 { | |
2881 NMUser *user; | |
2882 NMERR_T rc = NM_OK; | |
2883 const char *id = NULL; | |
2884 GaimStatus *status = NULL; | |
2885 | |
2886 if (gc == NULL) | |
2887 return; | |
2888 | |
2889 user = gc->proto_data; | |
2890 if (user == NULL) | |
2891 return; | |
2892 | |
2893 status = gaim_account_get_active_status(gaim_connection_get_account(gc)); | |
2894 id = gaim_status_get_id(status); | |
2895 | |
2896 /* Only go idle if active status is available */ | |
2897 if (!strcmp(id, NOVELL_STATUS_TYPE_AVAILABLE)) { | |
2898 if (time > 0) { | |
2899 rc = nm_send_set_status(user, NM_STATUS_AWAY_IDLE, NULL, NULL, NULL, NULL); | |
2900 } else { | |
2901 rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL, NULL); | |
2902 } | |
2903 } | |
2904 | |
2905 _check_for_disconnect(user, rc); | |
2906 } | |
2907 | |
2908 static void | |
2909 novell_get_info(GaimConnection * gc, const char *name) | |
2910 { | |
2911 NMUserRecord *user_record; | |
2912 NMUser *user; | |
2913 NMERR_T rc; | |
2914 | |
2915 if (gc == NULL || name == NULL) | |
2916 return; | |
2917 | |
2918 user = (NMUser *) gc->proto_data; | |
2919 if (user) { | |
2920 | |
2921 user_record = nm_find_user_record(user, name); | |
2922 if (user_record) { | |
2923 | |
2924 _show_info(gc, user_record); | |
2925 | |
2926 } else { | |
2927 | |
2928 rc = nm_send_get_details(user, name, | |
2929 _get_details_resp_show_info, g_strdup(name)); | |
2930 | |
2931 _check_for_disconnect(user, rc); | |
2932 | |
2933 } | |
2934 | |
2935 } | |
2936 } | |
2937 | |
2938 static char * | |
2939 novell_status_text(GaimBuddy * buddy) | |
2940 { | |
2941 const char *text = NULL; | |
2942 const char *dn = NULL; | |
2943 | |
2944 if (buddy && buddy->account) { | |
2945 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
2946 | |
2947 if (gc && gc->proto_data) { | |
2948 NMUser *user = gc->proto_data; | |
2949 | |
2950 dn = nm_lookup_dn(user, buddy->name); | |
2951 if (dn) { | |
2952 NMUserRecord *user_record = nm_find_user_record(user, dn); | |
2953 | |
2954 if (user_record) { | |
2955 text = nm_user_record_get_status_text(user_record); | |
2956 if (text) | |
2957 return g_strdup(text); | |
2958 } | |
2959 } | |
2960 } | |
2961 } | |
2962 | |
2963 return NULL; | |
2964 } | |
2965 | |
2966 static GList * | |
2967 novell_status_types(GaimAccount *account) | |
2968 { | |
2969 GList *status_types = NULL; | |
2970 GaimStatusType *type; | |
2971 | |
2972 g_return_val_if_fail(account != NULL, NULL); | |
2973 | |
2974 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, NOVELL_STATUS_TYPE_AVAILABLE, | |
2975 NULL, TRUE, TRUE, FALSE, | |
2976 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
2977 NULL); | |
2978 status_types = g_list_append(status_types, type); | |
2979 | |
2980 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, NOVELL_STATUS_TYPE_AWAY, | |
2981 NULL, TRUE, TRUE, FALSE, | |
2982 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
2983 NULL); | |
2984 status_types = g_list_append(status_types, type); | |
2985 | |
2986 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, NOVELL_STATUS_TYPE_BUSY, | |
2987 _("Busy"), TRUE, TRUE, FALSE, | |
2988 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), | |
2989 NULL); | |
2990 status_types = g_list_append(status_types, type); | |
2991 | |
2992 type = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, NOVELL_STATUS_TYPE_APPEAR_OFFLINE, | |
2993 NULL, TRUE, TRUE, FALSE); | |
2994 status_types = g_list_append(status_types, type); | |
2995 | |
2996 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE); | |
2997 status_types = g_list_append(status_types, type); | |
2998 | |
2999 return status_types; | |
3000 } | |
3001 | |
3002 static void | |
3003 novell_set_status(GaimAccount *account, GaimStatus *status) | |
3004 { | |
3005 GaimConnection *gc; | |
3006 gboolean connected; | |
3007 GaimPresence *presence; | |
3008 GaimStatusType *type; | |
3009 GaimStatusPrimitive primitive; | |
3010 NMUser *user; | |
3011 NMSTATUS_T novellstatus = NM_STATUS_AVAILABLE; | |
3012 NMERR_T rc = NM_OK; | |
3013 const char *msg = NULL; | |
3014 char *text = NULL; | |
3015 | |
3016 connected = gaim_account_is_connected(account); | |
3017 presence = gaim_status_get_presence(status); | |
3018 type = gaim_status_get_type(status); | |
3019 primitive = gaim_status_type_get_primitive(type); | |
3020 | |
3021 /* | |
3022 * We don't have any independent statuses, so we don't need to | |
3023 * do anything when a status is deactivated (because another | |
3024 * status is about to be activated). | |
3025 */ | |
3026 if (!gaim_status_is_active(status)) | |
3027 return; | |
3028 | |
3029 if (!connected) | |
3030 return; | |
3031 | |
3032 gc = gaim_account_get_connection(account); | |
3033 user = gc->proto_data; | |
3034 if (user == NULL) | |
3035 return; | |
3036 | |
3037 if (primitive == GAIM_STATUS_AVAILABLE) { | |
3038 novellstatus = NM_STATUS_AVAILABLE; | |
3039 } else if (primitive == GAIM_STATUS_AWAY) { | |
3040 novellstatus = NM_STATUS_AWAY; | |
3041 } else if (primitive == GAIM_STATUS_UNAVAILABLE) { | |
3042 novellstatus = NM_STATUS_BUSY; | |
3043 } else if (primitive == GAIM_STATUS_INVISIBLE) { | |
3044 novellstatus = NM_STATUS_OFFLINE; | |
3045 } else if (gaim_presence_is_idle(presence)) { | |
3046 novellstatus = NM_STATUS_AWAY_IDLE; | |
3047 } else { | |
3048 novellstatus = NM_STATUS_AVAILABLE; | |
3049 } | |
3050 | |
3051 if (primitive == GAIM_STATUS_AWAY || primitive == GAIM_STATUS_AVAILABLE || | |
3052 primitive == GAIM_STATUS_UNAVAILABLE) { | |
3053 msg = gaim_status_get_attr_string(status, "message"); | |
3054 text = g_strdup(msg); | |
3055 | |
3056 if (primitive == GAIM_STATUS_AVAILABLE) | |
3057 msg = NULL; /* no auto replies for online status */ | |
3058 | |
3059 /* Don't want newlines in status text */ | |
3060 gaim_util_chrreplace(text, '\n', ' '); | |
3061 } | |
3062 | |
3063 rc = nm_send_set_status(user, novellstatus, text, msg, NULL, NULL); | |
3064 _check_for_disconnect(user, rc); | |
3065 | |
3066 if (text) | |
3067 g_free(text); | |
3068 } | |
3069 | |
3070 static void | |
3071 novell_add_permit(GaimConnection *gc, const char *who) | |
3072 { | |
3073 NMUser *user; | |
3074 NMERR_T rc = NM_OK; | |
3075 const char *name = who; | |
3076 | |
3077 if (gc == NULL || who == NULL) | |
3078 return; | |
3079 | |
3080 user = gc->proto_data; | |
3081 if (user == NULL) | |
3082 return; | |
3083 | |
3084 /* Remove first -- we will add it back in when we get | |
3085 * the okay from the server | |
3086 */ | |
3087 gaim_privacy_permit_remove(gc->account, who, TRUE); | |
3088 | |
3089 if (nm_user_is_privacy_locked(user)) { | |
3090 _show_privacy_locked_error(gc, user); | |
3091 _sync_privacy_lists(user); | |
3092 return; | |
3093 } | |
3094 | |
3095 /* Work around for problem with un-typed, dotted contexts */ | |
3096 if (strchr(who, '.')) { | |
3097 const char *dn = nm_lookup_dn(user, who); | |
3098 if (dn == NULL) { | |
3099 rc = nm_send_get_details(user, who, _get_details_send_privacy_create, | |
3100 (gpointer)TRUE); | |
3101 _check_for_disconnect(user, rc); | |
3102 return; | |
3103 } else { | |
3104 name = dn; | |
3105 } | |
3106 } | |
3107 | |
3108 rc = nm_send_create_privacy_item(user, name, TRUE, | |
3109 _create_privacy_item_permit_resp_cb, | |
3110 g_strdup(who)); | |
3111 _check_for_disconnect(user, rc); | |
3112 } | |
3113 | |
3114 static void | |
3115 novell_add_deny(GaimConnection *gc, const char *who) | |
3116 { | |
3117 NMUser *user; | |
3118 NMERR_T rc = NM_OK; | |
3119 const char *name = who; | |
3120 | |
3121 if (gc == NULL || who == NULL) | |
3122 return; | |
3123 | |
3124 user = gc->proto_data; | |
3125 if (user == NULL) | |
3126 return; | |
3127 | |
3128 /* Remove first -- we will add it back in when we get | |
3129 * the okay from the server | |
3130 */ | |
3131 gaim_privacy_deny_remove(gc->account, who, TRUE); | |
3132 | |
3133 if (nm_user_is_privacy_locked(user)) { | |
3134 _show_privacy_locked_error(gc, user); | |
3135 _sync_privacy_lists(user); | |
3136 return; | |
3137 } | |
3138 | |
3139 /* Work around for problem with un-typed, dotted contexts */ | |
3140 if (strchr(who, '.')) { | |
3141 const char *dn = nm_lookup_dn(user, who); | |
3142 if (dn == NULL) { | |
3143 rc = nm_send_get_details(user, who, _get_details_send_privacy_create, | |
3144 (gpointer)FALSE); | |
3145 _check_for_disconnect(user, rc); | |
3146 return; | |
3147 } else { | |
3148 name = dn; | |
3149 } | |
3150 } | |
3151 | |
3152 rc = nm_send_create_privacy_item(user, name, FALSE, | |
3153 _create_privacy_item_deny_resp_cb, | |
3154 g_strdup(who)); | |
3155 _check_for_disconnect(user, rc); | |
3156 } | |
3157 | |
3158 static void | |
3159 novell_rem_permit(GaimConnection *gc, const char *who) | |
3160 { | |
3161 NMUser *user; | |
3162 NMERR_T rc = NM_OK; | |
3163 const char *dn = NULL; | |
3164 | |
3165 if (gc == NULL || who == NULL) | |
3166 return; | |
3167 | |
3168 user = gc->proto_data; | |
3169 if (user == NULL) | |
3170 return; | |
3171 | |
3172 if (nm_user_is_privacy_locked(user)) { | |
3173 _show_privacy_locked_error(gc, user); | |
3174 _sync_privacy_lists(user); | |
3175 return; | |
3176 } | |
3177 | |
3178 dn = nm_lookup_dn(user, who); | |
3179 if (dn == NULL) | |
3180 dn = who; | |
3181 | |
3182 rc = nm_send_remove_privacy_item(user, dn, TRUE, | |
3183 _remove_privacy_item_resp_cb, | |
3184 g_strdup(who)); | |
3185 _check_for_disconnect(user, rc); | |
3186 } | |
3187 | |
3188 static void | |
3189 novell_rem_deny(GaimConnection *gc, const char *who) | |
3190 { | |
3191 NMUser *user; | |
3192 NMERR_T rc = NM_OK; | |
3193 const char *dn = NULL; | |
3194 | |
3195 if (gc == NULL || who == NULL) | |
3196 return; | |
3197 | |
3198 user = gc->proto_data; | |
3199 if (user == NULL) | |
3200 return; | |
3201 | |
3202 if (nm_user_is_privacy_locked(user)) { | |
3203 _show_privacy_locked_error(gc, user); | |
3204 _sync_privacy_lists(user); | |
3205 return; | |
3206 } | |
3207 | |
3208 dn = nm_lookup_dn(user, who); | |
3209 if (dn == NULL) | |
3210 dn = who; | |
3211 | |
3212 rc = nm_send_remove_privacy_item(user, dn, FALSE, | |
3213 _remove_privacy_item_resp_cb, | |
3214 g_strdup(who)); | |
3215 _check_for_disconnect(user, rc); | |
3216 } | |
3217 | |
3218 static void | |
3219 novell_set_permit_deny(GaimConnection *gc) | |
3220 { | |
3221 NMERR_T rc = NM_OK; | |
3222 const char *dn, *name = NULL; | |
3223 NMUserRecord *user_record = NULL; | |
3224 GSList *node = NULL, *copy = NULL; | |
3225 NMUser *user; | |
3226 int i, j, num_contacts, num_folders; | |
3227 NMContact *contact; | |
3228 NMFolder *folder = NULL; | |
3229 | |
3230 if (gc == NULL) | |
3231 return; | |
3232 | |
3233 user = gc->proto_data; | |
3234 if (user == NULL) | |
3235 return; | |
3236 | |
3237 if (user->privacy_synched == FALSE) { | |
3238 _sync_privacy_lists(user); | |
3239 user->privacy_synched = TRUE; | |
3240 return; | |
3241 } | |
3242 | |
3243 if (nm_user_is_privacy_locked(user)) { | |
3244 _show_privacy_locked_error(gc, user); | |
3245 _sync_privacy_lists(user); | |
3246 return; | |
3247 } | |
3248 | |
3249 switch (gc->account->perm_deny) { | |
3250 | |
3251 case GAIM_PRIVACY_ALLOW_ALL: | |
3252 rc = nm_send_set_privacy_default(user, FALSE, | |
3253 _set_privacy_default_resp_cb, NULL); | |
3254 _check_for_disconnect(user, rc); | |
3255 | |
3256 /* clear server side deny list */ | |
3257 if (rc == NM_OK) { | |
3258 copy = g_slist_copy(user->deny_list); | |
3259 for (node = copy; node && node->data; node = node->next) { | |
3260 rc = nm_send_remove_privacy_item(user, (const char *)node->data, | |
3261 FALSE, NULL, NULL); | |
3262 if (_check_for_disconnect(user, rc)) | |
3263 break; | |
3264 } | |
3265 g_slist_free(copy); | |
3266 g_slist_free(user->deny_list); | |
3267 user->deny_list = NULL; | |
3268 } | |
3269 break; | |
3270 | |
3271 case GAIM_PRIVACY_DENY_ALL: | |
3272 rc = nm_send_set_privacy_default(user, TRUE, | |
3273 _set_privacy_default_resp_cb, NULL); | |
3274 _check_for_disconnect(user, rc); | |
3275 | |
3276 /* clear server side allow list */ | |
3277 if (rc == NM_OK) { | |
3278 copy = g_slist_copy(user->allow_list); | |
3279 for (node = copy; node && node->data; node = node->next) { | |
3280 rc = nm_send_remove_privacy_item(user, (const char *)node->data, | |
3281 TRUE, NULL, NULL); | |
3282 if (_check_for_disconnect(user, rc)) | |
3283 break; | |
3284 } | |
3285 g_slist_free(copy); | |
3286 g_slist_free(user->allow_list); | |
3287 user->allow_list = NULL; | |
3288 } | |
3289 break; | |
3290 | |
3291 case GAIM_PRIVACY_ALLOW_USERS: | |
3292 | |
3293 rc = nm_send_set_privacy_default(user, TRUE, | |
3294 _set_privacy_default_resp_cb, NULL); | |
3295 _check_for_disconnect(user, rc); | |
3296 | |
3297 /* sync allow lists */ | |
3298 if (rc == NM_OK) { | |
3299 | |
3300 for (node = user->allow_list; node; node = node->next) { | |
3301 user_record = nm_find_user_record(user, (char *)node->data); | |
3302 if (user_record) { | |
3303 name = nm_user_record_get_display_id(user_record); | |
3304 | |
3305 if (!g_slist_find_custom(gc->account->permit, | |
3306 name, (GCompareFunc)nm_utf8_strcasecmp)) { | |
3307 gaim_privacy_permit_add(gc->account, name , TRUE); | |
3308 } | |
3309 } | |
3310 } | |
3311 | |
3312 for (node = gc->account->permit; node; node = node->next) { | |
3313 name = NULL; | |
3314 dn = nm_lookup_dn(user, (char *)node->data); | |
3315 if (dn) { | |
3316 user_record = nm_find_user_record(user, dn); | |
3317 name = nm_user_record_get_display_id(user_record); | |
3318 | |
3319 if (!g_slist_find_custom(user->allow_list, | |
3320 dn, (GCompareFunc)nm_utf8_strcasecmp)) { | |
3321 rc = nm_send_create_privacy_item(user, dn, TRUE, | |
3322 _create_privacy_item_deny_resp_cb, | |
3323 g_strdup(dn)); | |
3324 } | |
3325 } else { | |
3326 gaim_privacy_permit_remove(gc->account, (char *)node->data, TRUE); | |
3327 } | |
3328 } | |
3329 } | |
3330 break; | |
3331 | |
3332 case GAIM_PRIVACY_DENY_USERS: | |
3333 | |
3334 /* set to default allow */ | |
3335 rc = nm_send_set_privacy_default(user, FALSE, | |
3336 _set_privacy_default_resp_cb, NULL); | |
3337 _check_for_disconnect(user, rc); | |
3338 | |
3339 /* sync deny lists */ | |
3340 if (rc == NM_OK) { | |
3341 | |
3342 for (node = user->deny_list; node; node = node->next) { | |
3343 user_record = nm_find_user_record(user, (char *)node->data); | |
3344 if (user_record) { | |
3345 name = nm_user_record_get_display_id(user_record); | |
3346 | |
3347 if (!g_slist_find_custom(gc->account->deny, | |
3348 name, (GCompareFunc)nm_utf8_strcasecmp)) { | |
3349 gaim_privacy_deny_add(gc->account, name , TRUE); | |
3350 } | |
3351 } | |
3352 } | |
3353 | |
3354 for (node = gc->account->deny; node; node = node->next) { | |
3355 | |
3356 name = NULL; | |
3357 dn = nm_lookup_dn(user, (char *)node->data); | |
3358 if (dn) { | |
3359 user_record = nm_find_user_record(user, dn); | |
3360 name = nm_user_record_get_display_id(user_record); | |
3361 | |
3362 if (!g_slist_find_custom(user->deny_list, | |
3363 dn, (GCompareFunc)nm_utf8_strcasecmp)) { | |
3364 rc = nm_send_create_privacy_item(user, dn, FALSE, | |
3365 _create_privacy_item_deny_resp_cb, | |
3366 g_strdup(name)); | |
3367 } | |
3368 } else { | |
3369 gaim_privacy_deny_remove(gc->account, (char *)node->data, TRUE); | |
3370 } | |
3371 } | |
3372 | |
3373 } | |
3374 break; | |
3375 | |
3376 case GAIM_PRIVACY_ALLOW_BUDDYLIST: | |
3377 | |
3378 /* remove users from allow list that are not in buddy list */ | |
3379 copy = g_slist_copy(user->allow_list); | |
3380 for (node = copy; node && node->data; node = node->next) { | |
3381 if (!nm_find_contacts(user, node->data)) { | |
3382 rc = nm_send_remove_privacy_item(user, (const char *)node->data, | |
3383 TRUE, NULL, NULL); | |
3384 if (_check_for_disconnect(user, rc)) | |
3385 return; | |
3386 } | |
3387 } | |
3388 g_slist_free(copy); | |
3389 | |
3390 /* add all buddies to allow list */ | |
3391 num_contacts = nm_folder_get_contact_count(user->root_folder); | |
3392 for (i = 0; i < num_contacts; i++) { | |
3393 contact = nm_folder_get_contact(user->root_folder, i); | |
3394 dn = nm_contact_get_dn(contact); | |
3395 if (dn && !g_slist_find_custom(user->allow_list, | |
3396 dn, (GCompareFunc)nm_utf8_strcasecmp)) | |
3397 { | |
3398 rc = nm_send_create_privacy_item(user, dn, TRUE, | |
3399 _create_privacy_item_deny_resp_cb, | |
3400 g_strdup(dn)); | |
3401 if (_check_for_disconnect(user, rc)) | |
3402 return; | |
3403 } | |
3404 | |
3405 } | |
3406 | |
3407 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
3408 for (i = 0; i < num_folders; i++) { | |
3409 folder = nm_folder_get_subfolder(user->root_folder, i); | |
3410 num_contacts = nm_folder_get_contact_count(folder); | |
3411 for (j = 0; j < num_contacts; j++) { | |
3412 contact = nm_folder_get_contact(folder, j); | |
3413 dn = nm_contact_get_dn(contact); | |
3414 if (dn && !g_slist_find_custom(user->allow_list, | |
3415 dn, (GCompareFunc)nm_utf8_strcasecmp)) | |
3416 { | |
3417 rc = nm_send_create_privacy_item(user, dn, TRUE, | |
3418 _create_privacy_item_deny_resp_cb, | |
3419 g_strdup(dn)); | |
3420 if (_check_for_disconnect(user, rc)) | |
3421 return; | |
3422 } | |
3423 } | |
3424 } | |
3425 | |
3426 /* set to default deny */ | |
3427 rc = nm_send_set_privacy_default(user, TRUE, | |
3428 _set_privacy_default_resp_cb, NULL); | |
3429 if (_check_for_disconnect(user, rc)) | |
3430 break; | |
3431 | |
3432 break; | |
3433 } | |
3434 } | |
3435 | |
3436 static GList * | |
3437 novell_blist_node_menu(GaimBlistNode *node) | |
3438 { | |
3439 GList *list = NULL; | |
3440 GaimMenuAction *act; | |
3441 | |
3442 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
3443 act = gaim_menu_action_new(_("Initiate _Chat"), | |
3444 GAIM_CALLBACK(_initiate_conference_cb), | |
3445 NULL, NULL); | |
3446 list = g_list_append(list, act); | |
3447 } | |
3448 | |
3449 return list; | |
3450 } | |
3451 | |
3452 static void | |
3453 novell_keepalive(GaimConnection *gc) | |
3454 { | |
3455 NMUser *user; | |
3456 NMERR_T rc = NM_OK; | |
3457 | |
3458 if (gc == NULL) | |
3459 return; | |
3460 | |
3461 user = gc->proto_data; | |
3462 if (user == NULL) | |
3463 return; | |
3464 | |
3465 rc = nm_send_keepalive(user, NULL, NULL); | |
3466 _check_for_disconnect(user, rc); | |
3467 } | |
3468 | |
3469 static GaimPluginProtocolInfo prpl_info = { | |
3470 0, | |
3471 NULL, /* user_splits */ | |
3472 NULL, /* protocol_options */ | |
3473 NO_BUDDY_ICONS, /* icon_spec */ | |
3474 novell_list_icon, /* list_icon */ | |
3475 novell_list_emblems, /* list_emblems */ | |
3476 novell_status_text, /* status_text */ | |
3477 novell_tooltip_text, /* tooltip_text */ | |
3478 novell_status_types, /* status_types */ | |
3479 novell_blist_node_menu, /* blist_node_menu */ | |
3480 NULL, /* chat_info */ | |
3481 NULL, /* chat_info_defaults */ | |
3482 novell_login, /* login */ | |
3483 novell_close, /* close */ | |
3484 novell_send_im, /* send_im */ | |
3485 NULL, /* set_info */ | |
3486 novell_send_typing, /* send_typing */ | |
3487 novell_get_info, /* get_info */ | |
3488 novell_set_status, /* set_status */ | |
3489 novell_set_idle, /* set_idle */ | |
3490 NULL, /* change_passwd */ | |
3491 novell_add_buddy, /* add_buddy */ | |
3492 NULL, /* add_buddies */ | |
3493 novell_remove_buddy, /* remove_buddy */ | |
3494 NULL, /* remove_buddies */ | |
3495 novell_add_permit, /* add_permit */ | |
3496 novell_add_deny, /* add_deny */ | |
3497 novell_rem_permit, /* rem_permit */ | |
3498 novell_rem_deny, /* rem_deny */ | |
3499 novell_set_permit_deny, /* set_permit_deny */ | |
3500 NULL, /* join_chat */ | |
3501 NULL, /* reject_chat */ | |
3502 NULL, /* get_chat_name */ | |
3503 novell_chat_invite, /* chat_invite */ | |
3504 novell_chat_leave, /* chat_leave */ | |
3505 NULL, /* chat_whisper */ | |
3506 novell_chat_send, /* chat_send */ | |
3507 novell_keepalive, /* keepalive */ | |
3508 NULL, /* register_user */ | |
3509 NULL, /* get_cb_info */ | |
3510 NULL, /* get_cb_away */ | |
3511 novell_alias_buddy, /* alias_buddy */ | |
3512 novell_group_buddy, /* group_buddy */ | |
3513 novell_rename_group, /* rename_group */ | |
3514 NULL, /* buddy_free */ | |
3515 novell_convo_closed, /* convo_closed */ | |
3516 gaim_normalize_nocase, /* normalize */ | |
3517 NULL, /* set_buddy_icon */ | |
3518 novell_remove_group, /* remove_group */ | |
3519 NULL, /* get_cb_real_name */ | |
3520 NULL, /* set_chat_topic */ | |
3521 NULL, /* find_blist_chat */ | |
3522 NULL, /* roomlist_get_list */ | |
3523 NULL, /* roomlist_cancel */ | |
3524 NULL, /* roomlist_expand_category */ | |
3525 NULL, /* can_receive_file */ | |
3526 NULL, /* send_file */ | |
3527 NULL, /* new_xfer */ | |
3528 NULL, /* offline_message */ | |
3529 NULL, /* whiteboard_prpl_ops */ | |
3530 NULL, /* send_raw */ | |
3531 NULL, /* roomlist_room_serialize */ | |
3532 | |
3533 }; | |
3534 | |
3535 static GaimPluginInfo info = { | |
3536 GAIM_PLUGIN_MAGIC, | |
3537 GAIM_MAJOR_VERSION, | |
3538 GAIM_MINOR_VERSION, | |
3539 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
3540 NULL, /**< ui_requirement */ | |
3541 0, /**< flags */ | |
3542 NULL, /**< dependencies */ | |
3543 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
3544 "prpl-novell", /**< id */ | |
3545 "GroupWise", /**< name */ | |
3546 VERSION, /**< version */ | |
3547 /** summary */ | |
3548 N_("Novell GroupWise Messenger Protocol Plugin"), | |
3549 /** description */ | |
3550 N_("Novell GroupWise Messenger Protocol Plugin"), | |
3551 NULL, /**< author */ | |
3552 GAIM_WEBSITE, /**< homepage */ | |
3553 | |
3554 NULL, /**< load */ | |
3555 NULL, /**< unload */ | |
3556 NULL, /**< destroy */ | |
3557 | |
3558 NULL, /**< ui_info */ | |
3559 &prpl_info, /**< extra_info */ | |
3560 NULL, | |
3561 NULL | |
3562 }; | |
3563 | |
3564 static void | |
3565 init_plugin(GaimPlugin * plugin) | |
3566 { | |
3567 GaimAccountOption *option; | |
3568 | |
3569 option = gaim_account_option_string_new(_("Server address"), "server", NULL); | |
3570 prpl_info.protocol_options = | |
3571 g_list_append(prpl_info.protocol_options, option); | |
3572 | |
3573 option = gaim_account_option_int_new(_("Server port"), "port", DEFAULT_PORT); | |
3574 prpl_info.protocol_options = | |
3575 g_list_append(prpl_info.protocol_options, option); | |
3576 | |
3577 my_protocol = plugin; | |
3578 } | |
3579 | |
3580 GAIM_INIT_PLUGIN(novell, init_plugin, info); |