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