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