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