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