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