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