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