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