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