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