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