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