Wed, 28 Apr 2004 03:16:40 +0000
[gaim-migrate @ 9604]
-Fix the compile error in perl that was my fault
-Rename a network.c function and change it's signature (is that work
applicable in c?)
-Make rendezvous crash when trying to sign on
| 8675 | 1 | /* |
| 2 | * novell.c | |
| 3 | * | |
| 4 | * Copyright © 2004 Unpublished Work of Novell, Inc. All Rights Reserved. | |
| 5 | * | |
| 6 | * THIS WORK IS AN UNPUBLISHED WORK OF NOVELL, INC. NO PART OF THIS WORK MAY BE | |
| 7 | * USED, PRACTICED, PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED, | |
| 8 | * TRANSLATED, ABRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, | |
| 9 | * RECAST, TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, | |
| 10 | * INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT | |
| 11 | * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY. | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
12 | * |
| 8675 | 13 | * AS BETWEEN [GAIM] AND NOVELL, NOVELL GRANTS [GAIM] THE RIGHT TO REPUBLISH |
| 14 | * THIS WORK UNDER THE GPL (GNU GENERAL PUBLIC LICENSE) WITH ALL RIGHTS AND | |
| 15 | * LICENSES THEREUNDER. IF YOU HAVE RECEIVED THIS WORK DIRECTLY OR INDIRECTLY | |
| 16 | * FROM [GAIM] AS PART OF SUCH A REPUBLICATION, YOU HAVE ALL RIGHTS AND LICENSES | |
| 17 | * GRANTED BY [GAIM] UNDER THE GPL. IN CONNECTION WITH SUCH A REPUBLICATION, IF | |
| 18 | * ANYTHING IN THIS NOTICE CONFLICTS WITH THE TERMS OF THE GPL, SUCH TERMS | |
| 19 | * PREVAIL. | |
| 20 | * | |
| 21 | */ | |
| 22 | ||
| 23 | #include "internal.h" | |
| 24 | #include "accountopt.h" | |
| 25 | #include "debug.h" | |
| 26 | #include "prpl.h" | |
| 27 | #include "server.h" | |
| 28 | #include "nmuser.h" | |
| 29 | #include "notify.h" | |
| 30 | #include "util.h" | |
| 31 | #include "sslconn.h" | |
| 32 | #include "request.h" | |
| 33 | #include "network.h" | |
| 34 | ||
| 35 | #define DEFAULT_PORT 8300 | |
| 36 | #define NOVELL_CONNECT_STEPS 4 | |
| 37 | ||
| 38 | static GaimPlugin *my_protocol = NULL; | |
| 39 | ||
| 40 | static gboolean | |
| 41 | _is_disconnect_error(NMERR_T err); | |
| 42 | ||
| 43 | static gboolean | |
| 44 | _check_for_disconnect(NMUser * user, NMERR_T err); | |
| 45 | ||
| 46 | static void | |
| 47 | _send_message(NMUser * user, NMMessage * message); | |
| 48 | ||
| 49 | static void | |
| 50 | _update_buddy_status(GaimBuddy * buddy, int status, int gmt); | |
| 51 | ||
| 52 | static void | |
| 53 | _remove_gaim_buddies(NMUser * user); | |
| 54 | ||
| 55 | static void | |
| 56 | _add_contacts_to_gaim_blist(NMUser * user, NMFolder * folder); | |
| 57 | ||
| 58 | static void | |
| 59 | _add_gaim_buddies(NMUser * user); | |
| 60 | ||
| 61 | static void | |
| 62 | _show_info(GaimConnection * gc, NMUserRecord * user_record); | |
| 63 | ||
| 64 | /******************************************************************************* | |
| 65 | * Response callbacks | |
| 66 | *******************************************************************************/ | |
| 67 | ||
| 68 | /* Handle login response */ | |
| 69 | static void | |
| 70 | _login_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 71 | gpointer resp_data, gpointer user_data) | |
| 72 | { | |
| 73 | GaimConnection *gc; | |
| 74 | const char *alias; | |
| 75 | NMERR_T rc; | |
| 76 | ||
| 77 | if (user == NULL) | |
| 78 | return; | |
| 79 | ||
| 80 | gc = gaim_account_get_connection(user->client_data); | |
| 81 | if (gc == NULL) | |
| 82 | return; | |
| 83 | ||
| 84 | if (ret_code == NM_OK) { | |
| 85 | ||
| 86 | /* Set alias for user if not set (use Full Name) */ | |
| 87 | alias = gaim_account_get_alias(user->client_data); | |
| 88 | if (alias == NULL || *alias == '\0') { | |
| 89 | alias = nm_user_record_get_full_name(user->user_record); | |
| 90 | ||
| 91 | if (alias) | |
| 92 | gaim_account_set_alias(user->client_data, alias); | |
| 93 | } | |
| 94 | ||
| 95 | /* Tell Gaim that we are connected */ | |
| 96 | gaim_connection_set_state(gc, GAIM_CONNECTED); | |
| 97 | serv_finish_login(gc); | |
| 98 | ||
| 99 | /* Sync the contact list. This is pretty simplistic right now, | |
| 100 | * we just remove all of the GaimBuddy from the client side list | |
| 101 | * for this account and then add in all of the contacts from the | |
| 102 | * server side list. | |
| 103 | */ | |
| 104 | _remove_gaim_buddies(user); | |
| 105 | _add_gaim_buddies(user); | |
| 106 | ||
| 107 | rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL, | |
| 108 | NULL); | |
| 109 | _check_for_disconnect(user, rc); | |
| 110 | ||
| 111 | } else { | |
| 112 | ||
| 113 | char *err = g_strdup_printf(_("Login failed (0x%X)."), ret_code); | |
| 114 | ||
| 115 | gaim_connection_error(gc, err); | |
| 116 | g_free(err); | |
| 117 | ||
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | /* Handle getstatus response*/ | |
| 122 | static void | |
| 123 | _get_status_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 124 | gpointer resp_data, gpointer user_data) | |
| 125 | { | |
| 126 | GaimBuddy *buddy; | |
| 127 | GSList *buddies; | |
| 128 | GSList *bnode; | |
| 129 | NMUserRecord *user_record = (NMUserRecord *) resp_data; | |
| 130 | int status; | |
| 131 | ||
| 132 | if (user == NULL || user_record == NULL) | |
| 133 | return; | |
| 134 | ||
| 135 | if (ret_code == NM_OK) { | |
| 136 | ||
| 137 | /* Find all Gaim buddies and update their statuses */ | |
| 138 | const char *name = nm_user_record_get_display_id(user_record); | |
| 139 | ||
| 140 | if (name) { | |
| 141 | buddies = gaim_find_buddies((GaimAccount *) user->client_data, name); | |
| 142 | for (bnode = buddies; bnode; bnode = bnode->next) { | |
| 143 | buddy = (GaimBuddy *) bnode->data; | |
| 144 | if (buddy) { | |
| 145 | status = nm_user_record_get_status(user_record); | |
| 146 | _update_buddy_status(buddy, status, time(0)); | |
| 147 | } | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | } else { | |
| 152 | ||
| 153 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 154 | "_get_status_resp_cb(): rc = 0x%X\n", ret_code); | |
| 155 | ||
| 156 | } | |
| 157 | } | |
| 158 | ||
| 159 | /* Show an error if the rename failed */ | |
| 160 | static void | |
| 161 | _rename_contact_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 162 | gpointer resp_data, gpointer user_data) | |
| 163 | { | |
| 164 | if (ret_code != NM_OK) { | |
| 165 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 166 | "_rename_contact_resp_cb(): rc = 0x%X\n", ret_code); | |
| 167 | } | |
| 168 | } | |
| 169 | ||
| 170 | /* Handle the getdetails response and send the message */ | |
| 171 | static void | |
| 172 | _get_details_resp_send_msg(NMUser * user, NMERR_T ret_code, | |
| 173 | gpointer resp_data, gpointer user_data) | |
| 174 | { | |
| 175 | GaimConversation *gconv; | |
| 176 | GaimConnection *gc; | |
| 177 | NMUserRecord *user_record = NULL; | |
| 178 | NMContact *cntct = NULL; | |
| 179 | NMConference *conf; | |
| 180 | NMMessage *msg = user_data; | |
| 181 | const char *dn = NULL; | |
| 182 | const char *name; | |
| 183 | ||
| 184 | if (user == NULL || msg == NULL) | |
| 185 | return; | |
| 186 | ||
| 187 | if (ret_code == NM_OK) { | |
| 188 | user_record = (NMUserRecord *) resp_data; | |
| 189 | if (user_record) { | |
| 190 | ||
| 191 | /* Set the title for the conversation */ | |
| 192 | gconv = gaim_find_conversation_with_account(nm_user_record_get_display_id(user_record), | |
| 193 | (GaimAccount *) user->client_data); | |
| 194 | if (gconv) { | |
| 195 | ||
| 196 | dn = nm_user_record_get_dn(user_record); | |
| 197 | if (dn) { | |
| 198 | cntct = nm_find_contact(user, dn); | |
| 199 | } | |
| 200 | ||
| 201 | if (cntct) { | |
| 202 | gaim_conversation_set_title(gconv, | |
| 203 | nm_contact_get_display_name(cntct)); | |
| 204 | } else { | |
| 205 | ||
| 206 | /* Not in the contact list, try to user full name */ | |
| 207 | name = (char *) nm_user_record_get_full_name(user_record); | |
| 208 | if (name) | |
| 209 | gaim_conversation_set_title(gconv, name); | |
| 210 | } | |
| 211 | } | |
| 212 | ||
| 213 | /* Add the user record to particpant list */ | |
| 214 | conf = nm_message_get_conference(msg); | |
| 215 | if (conf) { | |
| 216 | nm_conference_add_participant(conf, user_record); | |
| 217 | _send_message(user, msg); | |
| 218 | } | |
| 219 | } | |
| 220 | ||
| 221 | } else { | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
222 | |
| 8675 | 223 | gc = gaim_account_get_connection(user->client_data); |
| 224 | if (gc != NULL) { | |
| 225 | char *err = g_strdup_printf(_("Unable to send message." | |
| 226 | " Could not get details for user (0x%X)."), | |
| 227 | ret_code); | |
| 228 | ||
| 229 | gaim_notify_error(gc, NULL, err, NULL); | |
| 230 | g_free(err); | |
| 231 | } | |
| 232 | ||
| 233 | if (msg) | |
| 234 | nm_release_message(msg); | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 238 | /* Set up the new GaimBuddy based on the response from getdetails */ | |
| 239 | static void | |
| 240 | _get_details_resp_setup_buddy(NMUser * user, NMERR_T ret_code, | |
| 241 | gpointer resp_data, gpointer user_data) | |
| 242 | { | |
| 243 | NMUserRecord *user_record; | |
| 244 | NMContact *contact; | |
| 245 | GaimBuddy *buddy; | |
| 246 | const char *alias; | |
| 247 | NMERR_T rc = NM_OK; | |
| 248 | ||
| 249 | if (user == NULL || resp_data == NULL || user_data == NULL) | |
| 250 | return; | |
| 251 | ||
| 252 | contact = user_data; | |
| 253 | ||
| 254 | if (ret_code == NM_OK) { | |
| 255 | user_record = resp_data; | |
| 256 | ||
| 257 | buddy = nm_contact_get_data(contact); | |
| 258 | ||
| 259 | nm_contact_set_user_record(contact, user_record); | |
| 260 | ||
| 261 | /* Set the display id */ | |
| 262 | gaim_blist_rename_buddy(buddy, | |
| 263 | nm_user_record_get_display_id(user_record)); | |
| 264 | ||
| 265 | alias = gaim_get_buddy_alias(buddy); | |
| 266 | if (alias == NULL || (strcmp(alias, buddy->name) == 0)) { | |
| 267 | gaim_blist_alias_buddy(buddy, | |
| 268 | nm_user_record_get_full_name(user_record)); | |
| 269 | ||
| 270 | /* Tell the server about the new display name */ | |
| 271 | rc = nm_send_rename_contact(user, contact, | |
| 272 | nm_user_record_get_full_name(user_record), | |
| 273 | NULL, NULL); | |
| 274 | _check_for_disconnect(user, rc); | |
| 275 | ||
| 276 | } | |
| 277 | ||
| 278 | ||
| 279 | /* Get initial status for the buddy */ | |
| 280 | rc = nm_send_get_status(user, resp_data, _get_status_resp_cb, NULL); | |
| 281 | _check_for_disconnect(user, rc); | |
| 282 | ||
| 283 | /* nm_release_contact(contact);*/ | |
| 284 | ||
| 285 | } | |
| 286 | ||
| 287 | if (contact) | |
| 288 | nm_release_contact(contact); | |
| 289 | } | |
| 290 | ||
| 291 | /* Add the new contact into the GaimBuddy list */ | |
| 292 | static void | |
| 293 | _create_contact_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 294 | gpointer resp_data, gpointer user_data) | |
| 295 | { | |
| 296 | NMContact *tmp_contact = (NMContact *) user_data; | |
| 297 | NMContact *new_contact = NULL; | |
| 298 | NMFolder *folder = NULL; | |
| 299 | GaimGroup *group; | |
| 300 | GaimBuddy *buddy; | |
| 301 | const char *folder_name = NULL; | |
| 302 | NMERR_T rc = NM_OK; | |
| 303 | ||
| 304 | if (user == NULL) | |
| 305 | return; | |
| 306 | ||
| 307 | if (ret_code == NM_OK) { | |
| 308 | ||
| 309 | new_contact = (NMContact *) resp_data; | |
| 310 | if (new_contact == NULL || tmp_contact == NULL) | |
| 311 | return; | |
| 312 | ||
| 313 | /* Get the userid and folder name for the new contact */ | |
| 314 | folder = nm_find_folder_by_id(user, | |
| 315 | nm_contact_get_parent_id(new_contact)); | |
| 316 | if (folder) { | |
| 317 | folder_name = nm_folder_get_name(folder); | |
| 318 | } | |
| 319 | ||
| 320 | /* Re-add the buddy now that we got the okay from the server */ | |
| 321 | if (folder_name && (group = gaim_find_group(folder_name))) { | |
| 322 | ||
| 323 | const char *alias = nm_contact_get_display_name(tmp_contact); | |
| 324 | const char *display_id = nm_contact_get_display_id(new_contact); | |
| 325 | ||
| 326 | if (display_id == NULL) | |
| 327 | display_id = nm_contact_get_dn(new_contact); | |
| 328 | ||
| 329 | if (alias && strcmp(alias, display_id)) { | |
| 330 | ||
| 331 | /* The user requested an alias, tell the server about it. */ | |
| 332 | rc = nm_send_rename_contact(user, new_contact, alias, | |
| 333 | _rename_contact_resp_cb, NULL); | |
| 334 | _check_for_disconnect(user, rc); | |
| 335 | ||
| 336 | } else { | |
| 337 | ||
| 338 | alias = ""; | |
| 339 | ||
| 340 | } | |
| 341 | ||
| 342 | /* Add it to the gaim buddy list if it is not there */ | |
| 343 | buddy = gaim_find_buddy_in_group(user->client_data, display_id, group); | |
| 344 | if (buddy == NULL) { | |
| 345 | buddy = gaim_buddy_new(user->client_data, display_id, alias); | |
| 346 | gaim_blist_add_buddy(buddy, NULL, group, NULL); | |
| 347 | } | |
| 348 | ||
| 349 | /* Save the new buddy as part of the contact object */ | |
| 350 | nm_contact_set_data(new_contact, (gpointer) buddy); | |
| 351 | ||
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
352 | /* We need details for the user before we can setup the |
| 8675 | 353 | * new Gaim buddy. We always call this because the |
| 354 | * 'createcontact' response fields do not always contain | |
| 355 | * everything that we need. | |
| 356 | */ | |
| 357 | nm_contact_add_ref(new_contact); | |
| 358 | ||
| 359 | rc = nm_send_get_details(user, nm_contact_get_dn(new_contact), | |
| 360 | _get_details_resp_setup_buddy, new_contact); | |
| 361 | _check_for_disconnect(user, rc); | |
| 362 | ||
| 363 | } | |
| 364 | ||
| 365 | } else { | |
| 366 | GaimConnection *gc = gaim_account_get_connection(user->client_data); | |
| 367 | const char *name = nm_contact_get_dn(tmp_contact); | |
| 368 | char *err; | |
| 369 | ||
| 370 | err = | |
| 371 | g_strdup_printf(_("Unable to add %s to your buddy list (0x%X)."), | |
| 372 | name, ret_code); | |
| 373 | gaim_notify_error(gc, NULL, err, NULL); | |
| 374 | g_free(err); | |
| 375 | ||
| 376 | } | |
| 377 | ||
| 378 | if (tmp_contact) | |
| 379 | nm_release_contact(tmp_contact); | |
| 380 | } | |
| 381 | ||
| 382 | /* Show an error if we failed to send the message */ | |
| 383 | static void | |
| 384 | _send_message_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 385 | gpointer resp_data, gpointer user_data) | |
| 386 | { | |
| 387 | GaimConnection *gc; | |
| 388 | char *err = NULL; | |
| 389 | ||
| 390 | if (user == NULL) | |
| 391 | return; | |
| 392 | ||
| 393 | if (ret_code != NM_OK) { | |
| 394 | gc = gaim_account_get_connection(user->client_data); | |
| 395 | ||
| 396 | /* TODO: Improve this! message to who or for what conference? */ | |
| 397 | err = g_strdup_printf(_("Unable to send message (0x%X)."), | |
| 398 | ret_code); | |
| 399 | gaim_notify_error(gc, NULL, err, NULL); | |
| 400 | g_free(err); | |
| 401 | } | |
| 402 | } | |
| 403 | ||
| 404 | /* Show an error if the remove failed */ | |
| 405 | static void | |
| 406 | _remove_contact_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 407 | gpointer resp_data, gpointer user_data) | |
| 408 | { | |
| 409 | if (ret_code != NM_OK) { | |
| 410 | /* TODO: Display an error? */ | |
| 411 | ||
| 412 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 413 | "_remove_contact_resp_cb(): rc = 0x%x\n", ret_code); | |
| 414 | } | |
| 415 | } | |
| 416 | ||
| 417 | /* Show an error if the remove failed */ | |
| 418 | static void | |
| 419 | _remove_folder_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 420 | gpointer resp_data, gpointer user_data) | |
| 421 | { | |
| 422 | if (ret_code != NM_OK) { | |
| 423 | /* TODO: Display an error? */ | |
| 424 | ||
| 425 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 426 | "_remove_folder_resp_cb(): rc = 0x%x\n", ret_code); | |
| 427 | } | |
| 428 | } | |
| 429 | ||
| 430 | /* Show an error if the move failed */ | |
| 431 | static void | |
| 432 | _move_contact_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 433 | gpointer resp_data, gpointer user_data) | |
| 434 | { | |
| 435 | if (ret_code != NM_OK) { | |
| 436 | /* TODO: Display an error? */ | |
| 437 | ||
| 438 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 439 | "_move_contact_resp_cb(): rc = 0x%x\n", ret_code); | |
| 440 | } | |
| 441 | } | |
| 442 | ||
| 443 | /* Show an error if the rename failed */ | |
| 444 | static void | |
| 445 | _rename_folder_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 446 | gpointer resp_data, gpointer user_data) | |
| 447 | { | |
| 448 | if (ret_code != NM_OK) { | |
| 449 | /* TODO: Display an error? */ | |
| 450 | ||
| 451 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 452 | "_rename_folder_resp_cb(): rc = 0x%x\n", ret_code); | |
| 453 | } | |
| 454 | } | |
| 455 | ||
| 456 | /* If the createconf was successful attempt to send the message, | |
| 457 | * otherwise display an error message to the user. | |
| 458 | */ | |
| 459 | static void | |
| 460 | _createconf_resp_send_msg(NMUser * user, NMERR_T ret_code, | |
| 461 | gpointer resp_data, gpointer user_data) | |
| 462 | { | |
| 463 | NMConference *conf; | |
| 464 | NMMessage *msg = user_data; | |
| 465 | ||
| 466 | if (user == NULL || msg == NULL) | |
| 467 | return; | |
| 468 | ||
| 469 | if (ret_code == NM_OK) { | |
| 470 | _send_message(user, msg); | |
| 471 | } else { | |
| 472 | ||
| 473 | if ((conf = nm_message_get_conference(msg))) { | |
| 474 | ||
| 475 | GaimConnection *gc = gaim_account_get_connection(user->client_data); | |
| 476 | const char *name = NULL; | |
| 477 | char *err; | |
| 478 | NMUserRecord *ur; | |
| 479 | ||
| 480 | ur = nm_conference_get_participant(conf, 0); | |
| 481 | if (ur) | |
| 482 | name = nm_user_record_get_userid(ur); | |
| 483 | ||
| 484 | if (name) | |
| 485 | err = g_strdup_printf(_("Unable to send message to %s." | |
| 486 | " Could not create the conference (0x%X)."), | |
| 487 | name, ret_code); | |
| 488 | else | |
| 489 | err = g_strdup_printf(_("Unable to send message." | |
| 490 | " Could not create the conference (0x%X)."), | |
| 491 | ret_code); | |
| 492 | ||
| 493 | gaim_notify_error(gc, NULL, err, NULL); | |
| 494 | g_free(err); | |
| 495 | } | |
| 496 | ||
| 497 | if (msg) | |
| 498 | nm_release_message(msg); | |
| 499 | } | |
| 500 | } | |
| 501 | ||
| 502 | /* Move contact to newly created folder */ | |
| 503 | static void | |
| 504 | _create_folder_resp_move_contact(NMUser * user, NMERR_T ret_code, | |
| 505 | gpointer resp_data, gpointer user_data) | |
| 506 | { | |
| 507 | NMContact *contact = user_data; | |
| 508 | NMFolder *new_folder; | |
| 509 | char *folder_name = resp_data; | |
| 510 | NMERR_T rc = NM_OK; | |
| 511 | ||
| 512 | if (user == NULL || folder_name == NULL || contact == NULL) { | |
| 513 | ||
| 514 | if (folder_name) | |
| 515 | g_free(folder_name); | |
| 516 | ||
| 517 | return; | |
| 518 | } | |
| 519 | ||
| 520 | if (ret_code == NM_OK || ret_code == 0xD126) { | |
| 521 | new_folder = nm_find_folder(user, folder_name); | |
| 522 | if (new_folder) { | |
| 523 | ||
| 524 | /* Tell the server to move the contact to the new folder */ | |
| 525 | /* rc = nm_send_move_contact(user, contact, new_folder, | |
| 526 | _move_contact_resp_cb, NULL); */ | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
527 | |
| 8675 | 528 | rc = nm_send_create_contact(user, new_folder, contact, |
| 529 | NULL, NULL); | |
| 530 | ||
| 531 | _check_for_disconnect(user, rc); | |
| 532 | ||
| 533 | } | |
| 534 | } else { | |
| 535 | GaimConnection *gc = gaim_account_get_connection(user->client_data); | |
| 536 | char *err = g_strdup_printf(_("Unable to move user %s" | |
| 537 | " to folder %s in the server side list." | |
| 538 | " Error while creating folder (0x%X)."), | |
| 539 | nm_contact_get_dn(contact), | |
| 540 | folder_name, | |
| 541 | ret_code); | |
| 542 | ||
| 543 | gaim_notify_error(gc, NULL, err, NULL); | |
| 544 | g_free(err); | |
| 545 | } | |
| 546 | ||
| 547 | if (folder_name) | |
| 548 | g_free(folder_name); | |
| 549 | } | |
| 550 | ||
| 551 | /* Add contact to newly create folder */ | |
| 552 | static void | |
| 553 | _create_folder_resp_add_contact(NMUser * user, NMERR_T ret_code, | |
| 554 | gpointer resp_data, gpointer user_data) | |
| 555 | { | |
| 556 | NMContact *contact = (NMContact *) user_data; | |
| 557 | NMFolder *folder; | |
| 558 | char *folder_name = (char *) resp_data; | |
| 559 | NMERR_T rc = NM_OK; | |
| 560 | ||
| 561 | if (user == NULL || folder_name == NULL || contact == NULL) { | |
| 562 | ||
| 563 | if (contact) | |
| 564 | nm_release_contact(contact); | |
| 565 | ||
| 566 | if (folder_name) | |
| 567 | g_free(folder_name); | |
| 568 | ||
| 569 | return; | |
| 570 | } | |
| 571 | ||
| 572 | if (ret_code == NM_OK || ret_code == 0xD126) { | |
| 573 | folder = nm_find_folder(user, folder_name); | |
| 574 | if (folder) { | |
| 575 | ||
| 576 | rc = nm_send_create_contact(user, folder, contact, | |
| 577 | _create_contact_resp_cb, contact); | |
| 578 | _check_for_disconnect(user, rc); | |
| 579 | } | |
| 580 | } else { | |
| 581 | GaimConnection *gc = gaim_account_get_connection(user->client_data); | |
| 582 | const char *name = nm_contact_get_dn(contact); | |
| 583 | char *err = | |
| 584 | g_strdup_printf(_("Unable to add %s to your buddy list." | |
| 585 | " Error creating folder in server side list (0x%X)."), | |
| 586 | name, ret_code); | |
| 587 | ||
| 588 | gaim_notify_error(gc, NULL, err, NULL); | |
| 589 | ||
| 590 | nm_release_contact(contact); | |
| 591 | g_free(err); | |
| 592 | } | |
| 593 | ||
| 594 | g_free(folder_name); | |
| 595 | } | |
| 596 | ||
| 597 | static void | |
| 598 | _join_conf_resp_cb(NMUser * user, NMERR_T ret_code, | |
| 599 | gpointer resp_data, gpointer user_data) | |
| 600 | { | |
| 601 | GaimConversation *chat; | |
| 602 | GaimConnection *gc; | |
| 603 | NMUserRecord *ur; | |
| 604 | NMConference *conference = user_data; | |
| 605 | const char *name; | |
| 606 | char *conf_name; | |
| 607 | int i, count; | |
| 608 | ||
| 609 | if (user == NULL || conference == NULL) | |
| 610 | return; | |
| 611 | ||
| 612 | gc = gaim_account_get_connection(user->client_data); | |
| 613 | ||
| 614 | if (ret_code == NM_OK) { | |
| 615 | conf_name = g_strdup_printf(_("GroupWise Conference %d"), | |
| 616 | ++user->conference_count); | |
| 617 | chat = serv_got_joined_chat(gc, user->conference_count, conf_name); | |
| 618 | if (chat) { | |
| 619 | ||
| 620 | nm_conference_set_data(conference, (gpointer) chat); | |
| 621 | ||
| 622 | count = nm_conference_get_participant_count(conference); | |
| 623 | for (i = 0; i < count; i++) { | |
| 624 | ur = nm_conference_get_participant(conference, i); | |
| 625 | if (ur) { | |
| 626 | name = nm_user_record_get_display_id(ur); | |
| 627 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL); | |
| 628 | } | |
| 629 | } | |
| 630 | } | |
| 631 | g_free(conf_name); | |
| 632 | } | |
| 633 | } | |
| 634 | ||
| 635 | /* Show info returned by getdetails */ | |
| 636 | static void | |
| 637 | _get_details_resp_show_info(NMUser * user, NMERR_T ret_code, | |
| 638 | gpointer resp_data, gpointer user_data) | |
| 639 | { | |
| 640 | GaimConnection *gc; | |
| 641 | NMUserRecord *user_record; | |
| 642 | char *name; | |
| 643 | char *err; | |
| 644 | ||
| 645 | if (user == NULL) | |
| 646 | return; | |
| 647 | ||
| 648 | name = user_data; | |
| 649 | ||
| 650 | if (ret_code == NM_OK) { | |
| 651 | user_record = (NMUserRecord *) resp_data; | |
| 652 | if (user_record) { | |
| 653 | _show_info(gaim_account_get_connection(user->client_data), | |
| 654 | user_record); | |
| 655 | } | |
| 656 | } else { | |
| 657 | gc = gaim_account_get_connection(user->client_data); | |
| 658 | err = | |
| 659 | g_strdup_printf(_("Could not get details for user %s (0x%X)."), name, | |
| 660 | ret_code); | |
| 661 | gaim_notify_error(gc, NULL, err, NULL); | |
| 662 | g_free(err); | |
| 663 | } | |
| 664 | ||
| 665 | if (name) | |
| 666 | g_free(name); | |
| 667 | } | |
| 668 | ||
| 669 | /******************************************************************************* | |
| 670 | * Helper functions | |
| 671 | ******************************************************************************/ | |
| 672 | ||
| 673 | static char * | |
| 674 | _user_agent_string() | |
| 675 | { | |
| 676 | ||
| 677 | #if !defined(_WIN32) | |
| 678 | ||
| 679 | const char *sysname = ""; | |
| 680 | const char *release = ""; | |
| 681 | const char *template = "Gaim/%s (%s; %s)"; | |
| 682 | struct utsname u; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
683 | |
| 8675 | 684 | if (uname(&u) == 0) { |
| 685 | sysname = u.sysname; | |
| 686 | release = u.release; | |
| 687 | } else { | |
| 688 | sysname = "Linux"; | |
| 689 | release = "Unknown"; | |
| 690 | } | |
| 691 | ||
| 692 | return g_strdup_printf(template, VERSION, sysname, release); | |
| 693 | ||
| 694 | #else | |
| 695 | ||
| 696 | const char *sysname = ""; | |
| 697 | const char *template = "Gaim/%s (%s; %d.%d)"; | |
| 698 | OSVERSIONINFO os_info; | |
| 699 | SYSTEM_INFO sys_info; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
700 | |
| 8675 | 701 | os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
| 702 | GetVersionEx(&os_info); | |
| 703 | GetSystemInfo(&sys_info); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
704 | |
| 8675 | 705 | if (os_info.dwPlatformId == VER_PLATFORM_WIN32_NT) { |
| 706 | switch (os_info.dwMajorVersion) { | |
| 707 | case 3: | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
708 | case 4: |
| 8675 | 709 | sysname = "Windows NT"; |
| 710 | break; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
711 | case 5: |
| 8675 | 712 | switch (os_info.dwMinorVersion) { |
| 713 | case 0: | |
| 714 | sysname = "Windows 2000"; | |
| 715 | break; | |
| 716 | case 1: | |
| 717 | sysname = "Windows XP"; | |
| 718 | break; | |
| 719 | case 2: | |
| 720 | sysname = "Windows Server 2003"; | |
| 721 | break; | |
| 722 | default: | |
| 723 | sysname = "Windows"; | |
| 724 | break; | |
| 725 | } | |
| 726 | break; | |
| 727 | default: | |
| 728 | sysname = "Windows"; | |
| 729 | break; | |
| 730 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
731 | |
| 8675 | 732 | } else if (os_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { |
| 733 | switch (os_info.dwMinorVersion) { | |
| 734 | case 0: | |
| 735 | sysname = "Windows 95"; | |
| 736 | break; | |
| 737 | case 10: | |
| 738 | sysname = "Windows 98"; | |
| 739 | break; | |
| 740 | case 90: | |
| 741 | sysname = "Windows ME"; | |
| 742 | break; | |
| 743 | default: | |
| 744 | sysname = "Windows"; | |
| 745 | break; | |
| 746 | } | |
| 747 | } else { | |
| 748 | sysname = "Windows"; | |
| 749 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
750 | |
| 8675 | 751 | return g_strdup_printf(template, VERSION, sysname, |
| 752 | os_info.dwMajorVersion, os_info.dwMinorVersion); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
753 | |
| 8675 | 754 | #endif |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
755 | |
|
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
756 | |
| 8675 | 757 | } |
| 758 | ||
| 759 | static gboolean | |
| 760 | _is_disconnect_error(NMERR_T err) | |
| 761 | { | |
| 762 | return (err == NMERR_TCP_WRITE || | |
| 763 | err == NMERR_TCP_READ || err == NMERR_PROTOCOL); | |
| 764 | } | |
| 765 | ||
| 766 | static gboolean | |
| 767 | _check_for_disconnect(NMUser * user, NMERR_T err) | |
| 768 | { | |
| 769 | GaimConnection *gc = gaim_account_get_connection(user->client_data); | |
| 770 | ||
| 771 | if (_is_disconnect_error(err)) { | |
| 772 | ||
| 773 | gaim_connection_error(gc, _("Error communicating with server." | |
| 774 | " Closing connection.")); | |
| 775 | return TRUE; | |
| 776 | ||
| 777 | } | |
| 778 | ||
| 779 | return FALSE; | |
| 780 | } | |
| 781 | ||
| 782 | /* Check to see if the conference is instantiated, if so send the message. | |
| 783 | * If not send the create conference -- the response handler for the createconf | |
| 784 | * will call this function again. | |
| 785 | */ | |
| 786 | static void | |
| 787 | _send_message(NMUser * user, NMMessage * message) | |
| 788 | { | |
| 789 | NMConference *conf; | |
| 790 | NMERR_T rc = NM_OK; | |
| 791 | ||
| 792 | conf = nm_message_get_conference(message); | |
| 793 | if (conf) { | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
794 | /* We have a conference make sure that the |
| 8675 | 795 | server knows about it already. */ |
| 796 | if (nm_conference_is_instantiated(conf)) { | |
| 797 | ||
| 798 | /* We have everything that we need...finally! */ | |
| 799 | rc = nm_send_message(user, message, _send_message_resp_cb); | |
| 800 | _check_for_disconnect(user, rc); | |
| 801 | ||
| 802 | nm_release_message(message); | |
| 803 | ||
| 804 | } else { | |
| 805 | rc = nm_send_create_conference(user, conf, | |
| 806 | _createconf_resp_send_msg, message); | |
| 807 | _check_for_disconnect(user, rc); | |
| 808 | } | |
| 809 | } | |
| 810 | } | |
| 811 | ||
| 812 | /* Update the status of the given buddy in the Gaim buddy list */ | |
| 813 | static void | |
| 814 | _update_buddy_status(GaimBuddy * buddy, int status, int gmt) | |
| 815 | { | |
| 816 | GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
| 817 | int gstatus = status << 1; | |
| 818 | int idle = 0; | |
| 819 | int loggedin = 1; | |
| 820 | ||
| 821 | switch (status) { | |
| 822 | case NM_STATUS_AVAILABLE: | |
| 823 | /*nothing to do */ | |
| 824 | break; | |
| 825 | case NM_STATUS_AWAY: | |
| 826 | case NM_STATUS_BUSY: | |
| 827 | gstatus |= UC_UNAVAILABLE; | |
| 828 | break; | |
| 829 | case NM_STATUS_OFFLINE: | |
| 830 | loggedin = 0; | |
| 831 | gstatus |= UC_UNAVAILABLE; | |
| 832 | break; | |
| 833 | case NM_STATUS_AWAY_IDLE: | |
| 834 | idle = gmt; | |
| 835 | gstatus |= UC_UNAVAILABLE; | |
| 836 | break; | |
| 837 | default: | |
| 838 | gstatus |= UC_UNAVAILABLE; | |
| 839 | loggedin = 0; | |
| 840 | break; | |
| 841 | } | |
| 842 | ||
| 843 | serv_got_update(gc, buddy->name, loggedin, 0, 0, idle, gstatus); | |
| 844 | } | |
| 845 | ||
| 846 | /* Iterate through the cached Gaim buddy list and remove all buddies | |
| 847 | * for this account. | |
| 848 | */ | |
| 849 | static void | |
| 850 | _remove_gaim_buddies(NMUser * user) | |
| 851 | { | |
| 852 | GaimBlistNode *gnode; | |
| 853 | GaimBlistNode *cnode; | |
| 854 | GaimBlistNode *bnode; | |
| 855 | GaimGroup *group; | |
| 856 | GaimBuddy *buddy; | |
| 857 | GaimBuddyList *blist; | |
| 858 | GSList *rem_list = NULL; | |
| 859 | GSList *l; | |
| 860 | ||
| 861 | if ((blist = gaim_get_blist())) { | |
| 862 | for (gnode = blist->root; gnode; gnode = gnode->next) { | |
| 863 | if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 864 | continue; | |
| 865 | group = (GaimGroup *) gnode; | |
| 866 | for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
| 867 | if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 868 | continue; | |
| 869 | for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 870 | if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 871 | continue; | |
| 872 | buddy = (GaimBuddy *) bnode; | |
| 873 | if (buddy->account == user->client_data) { | |
| 874 | rem_list = g_slist_append(rem_list, buddy); | |
| 875 | } | |
| 876 | } | |
| 877 | } | |
| 878 | } | |
| 879 | ||
| 880 | if (rem_list) { | |
| 881 | for (l = rem_list; l; l = l->next) { | |
| 882 | gaim_blist_remove_buddy(l->data); | |
| 883 | } | |
| 884 | g_slist_free(rem_list); | |
| 885 | } | |
| 886 | } | |
| 887 | } | |
| 888 | ||
| 889 | /* Add all of the contacts in the given folder to the Gaim buddy list */ | |
| 890 | static void | |
| 891 | _add_contacts_to_gaim_blist(NMUser * user, NMFolder * folder) | |
| 892 | { | |
| 893 | NMUserRecord *user_record = NULL; | |
| 894 | NMContact *contact = NULL; | |
| 895 | GaimBuddy *buddy = NULL; | |
| 8782 | 896 | GaimGroup *group; |
| 8675 | 897 | NMERR_T cnt = 0, i; |
| 898 | const char *text = NULL; | |
| 899 | const char *name = NULL; | |
| 900 | int status = 0; | |
| 901 | ||
| 902 | /* Get each contact for this folder */ | |
| 903 | cnt = nm_folder_get_contact_count(folder); | |
| 904 | for (i = 0; i < cnt; i++) { | |
| 905 | contact = nm_folder_get_contact(folder, i); | |
| 906 | if (contact) { | |
| 907 | ||
| 908 | name = nm_contact_get_display_id(contact); | |
| 909 | if (name) { | |
| 910 | /* Add it to the gaim buddy list */ | |
| 911 | buddy = gaim_buddy_new(user->client_data, | |
| 912 | name, | |
| 913 | nm_contact_get_display_name(contact)); | |
| 914 | ||
| 915 | /* Does the Gaim group exist already? */ | |
| 8782 | 916 | group = gaim_find_group(nm_folder_get_name(folder)); |
| 8675 | 917 | |
| 918 | if (group == NULL) { | |
| 919 | group = gaim_group_new(nm_folder_get_name(folder)); | |
| 920 | gaim_blist_add_group(group, NULL); | |
| 921 | } | |
| 922 | ||
| 923 | /* Set the initial status for the buddy */ | |
| 924 | user_record = nm_contact_get_user_record(contact); | |
| 925 | if (user_record) { | |
| 926 | status = nm_user_record_get_status(user_record); | |
| 927 | text = nm_user_record_get_status_text(user_record); | |
| 928 | } | |
| 929 | ||
| 930 | gaim_blist_add_buddy(buddy, NULL, group, NULL); | |
| 931 | _update_buddy_status(buddy, status, time(0)); | |
| 932 | ||
| 933 | /* Save the new buddy as part of the contact object */ | |
| 934 | nm_contact_set_data(contact, (gpointer) buddy); | |
| 935 | } | |
| 936 | ||
| 937 | } else { | |
| 938 | /* NULL contact. This should not happen, but | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
939 | * let's break out of the loop. |
| 8675 | 940 | */ |
| 941 | break; | |
| 942 | } | |
| 943 | } | |
| 944 | ||
| 945 | } | |
| 946 | ||
| 947 | /* Add all of the server side contacts to the Gaim buddy list. */ | |
| 948 | static void | |
| 949 | _add_gaim_buddies(NMUser * user) | |
| 950 | { | |
| 951 | NMERR_T cnt = 0, i; | |
| 952 | NMFolder *root_folder = NULL; | |
| 953 | NMFolder *folder = NULL; | |
| 954 | ||
| 955 | root_folder = nm_get_root_folder(user); | |
| 956 | if (root_folder) { | |
| 957 | ||
| 958 | /* Add contacts for the sub folders */ | |
| 959 | cnt = nm_folder_get_subfolder_count(root_folder); | |
| 960 | for (i = 0; i < cnt; i++) { | |
| 961 | folder = nm_folder_get_subfolder(root_folder, i); | |
| 962 | if (folder) { | |
| 963 | _add_contacts_to_gaim_blist(user, folder); | |
| 964 | } | |
| 965 | } | |
| 966 | ||
| 967 | /* Add contacts for the root folder */ | |
| 968 | _add_contacts_to_gaim_blist(user, root_folder); | |
| 969 | } | |
| 970 | } | |
| 971 | ||
| 972 | /* Display a dialog box showing the properties for the given user record */ | |
| 973 | static void | |
| 974 | _show_info(GaimConnection * gc, NMUserRecord * user_record) | |
| 975 | { | |
| 976 | GString *info_text; | |
| 977 | int count, i; | |
| 978 | NMProperty *property; | |
| 979 | const char *tag, *value; | |
| 980 | ||
| 981 | info_text = g_string_new(""); | |
| 982 | ||
| 983 | tag = _("Userid"); | |
| 984 | value = nm_user_record_get_userid(user_record); | |
| 985 | if (value) { | |
| 986 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", tag, value); | |
| 987 | } | |
| 988 | ||
| 989 | /* tag = _("DN"); | |
| 990 | value = nm_user_record_get_dn(user_record); | |
| 991 | if (value) { | |
| 992 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 993 | tag, value); | |
| 994 | } | |
| 995 | */ | |
| 996 | ||
| 997 | tag = _("Full name"); | |
| 998 | value = nm_user_record_get_full_name(user_record); | |
| 999 | if (value) { | |
| 1000 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", tag, value); | |
| 1001 | } | |
| 1002 | ||
| 1003 | count = nm_user_record_get_property_count(user_record); | |
| 1004 | for (i = 0; i < count; i++) { | |
| 1005 | property = nm_user_record_get_property(user_record, i); | |
| 1006 | if (property) { | |
| 1007 | tag = nm_property_get_tag(property); | |
| 1008 | value = nm_property_get_value(property); | |
| 1009 | if (tag && value) { | |
| 1010 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 1011 | tag, value); | |
| 1012 | } | |
| 1013 | nm_release_property(property); | |
| 1014 | } | |
| 1015 | } | |
| 1016 | ||
|
8744
14a15b6f466d
[gaim-migrate @ 9499]
Mike Stoddard <mistoddard@novell.com>
parents:
8739
diff
changeset
|
1017 | gaim_notify_formatted(NULL, NULL, _("User Properties"), |
| 8675 | 1018 | NULL, info_text->str, NULL, NULL); |
| 1019 | ||
| 1020 | g_string_free(info_text, TRUE); | |
| 1021 | } | |
| 1022 | ||
| 1023 | /* Send a join conference, the first item in the parms list is the | |
| 1024 | * NMUser object and the second item is the conference to join. | |
| 1025 | * This callback is passed to gaim_request_action when we ask the | |
| 1026 | * user if they want to join the conference. | |
| 1027 | */ | |
| 1028 | static void | |
| 1029 | _join_conference_cb(GSList * parms) | |
| 1030 | { | |
| 1031 | NMUser *user; | |
| 1032 | NMConference *conference; | |
| 1033 | NMERR_T rc = NM_OK; | |
| 1034 | ||
| 1035 | if (parms == NULL || g_slist_length(parms) != 2) | |
| 1036 | return; | |
| 1037 | ||
| 1038 | user = g_slist_nth_data(parms, 0); | |
| 1039 | conference = g_slist_nth_data(parms, 1); | |
| 1040 | ||
| 1041 | if (user && conference) { | |
| 1042 | rc = nm_send_join_conference(user, conference, | |
| 1043 | _join_conf_resp_cb, conference); | |
| 1044 | _check_for_disconnect(user, rc); | |
| 1045 | } | |
| 1046 | ||
| 1047 | g_slist_free(parms); | |
| 1048 | } | |
| 1049 | ||
| 1050 | /* Send a reject conference, the first item in the parms list is the | |
| 1051 | * NMUser object and the second item is the conference to reject. | |
| 1052 | * This callback is passed to gaim_request_action when we ask the | |
| 1053 | * user if they want to joing the conference. | |
| 1054 | */ | |
| 1055 | static void | |
| 1056 | _reject_conference_cb(GSList * parms) | |
| 1057 | { | |
| 1058 | NMUser *user; | |
| 1059 | NMConference *conference; | |
| 1060 | NMERR_T rc = NM_OK; | |
| 1061 | ||
| 1062 | if (parms == NULL || g_slist_length(parms) != 2) | |
| 1063 | return; | |
| 1064 | ||
| 1065 | user = g_slist_nth_data(parms, 0); | |
| 1066 | conference = g_slist_nth_data(parms, 1); | |
| 1067 | ||
| 1068 | if (user && conference) { | |
| 1069 | rc = nm_send_reject_conference(user, conference, NULL, NULL); | |
| 1070 | _check_for_disconnect(user, rc); | |
| 1071 | } | |
| 1072 | ||
| 1073 | g_slist_free(parms); | |
| 1074 | } | |
| 1075 | ||
| 1076 | /******************************************************************************* | |
| 1077 | * Connect and recv callbacks | |
| 1078 | ******************************************************************************/ | |
| 1079 | ||
| 1080 | static void | |
| 1081 | novell_ssl_connect_error(GaimSslConnection * gsc, | |
| 1082 | GaimSslErrorType error, gpointer data) | |
| 1083 | { | |
| 1084 | gaim_connection_error((GaimConnection *)data, | |
| 1085 | _("Unable to make SSL connection to server.")); | |
| 1086 | } | |
| 1087 | ||
| 1088 | static void | |
| 1089 | novell_ssl_recv_cb(gpointer data, GaimSslConnection * gsc, | |
| 1090 | GaimInputCondition condition) | |
| 1091 | { | |
| 1092 | GaimConnection *gc = data; | |
| 1093 | NMUser *user; | |
| 1094 | NMERR_T rc; | |
| 1095 | ||
| 1096 | if (gc == NULL) | |
| 1097 | return; | |
| 1098 | ||
| 1099 | user = gc->proto_data; | |
| 1100 | if (user == NULL) | |
| 1101 | return; | |
| 1102 | ||
| 1103 | rc = nm_process_new_data(user); | |
| 1104 | if (rc != NM_OK) { | |
| 1105 | ||
| 1106 | if (_is_disconnect_error(rc)) { | |
| 1107 | gaim_connection_error(gc, | |
| 1108 | _("Error communicating with server." | |
| 1109 | " Closing connection.")); | |
| 1110 | } else { | |
| 1111 | ||
| 1112 | char *error; | |
| 1113 | ||
| 1114 | error = g_strdup_printf(_("Error processing event or response." | |
| 1115 | " (0x%X)"), rc); | |
| 1116 | gaim_notify_error(gc, NULL, error, NULL); | |
| 1117 | g_free(error); | |
| 1118 | ||
| 1119 | } | |
| 1120 | ||
| 1121 | } | |
| 1122 | } | |
| 1123 | ||
| 1124 | static void | |
| 1125 | novell_ssl_connected_cb(gpointer data, GaimSslConnection * gsc, | |
| 1126 | GaimInputCondition cond) | |
| 1127 | { | |
| 1128 | GaimConnection *gc = data; | |
| 1129 | NMUser *user; | |
| 1130 | NMConn *conn; | |
| 1131 | NMERR_T rc = 0; | |
| 1132 | const char *pwd = NULL; | |
| 1133 | const char *my_addr = NULL; | |
| 1134 | char *ua = NULL; | |
| 1135 | ||
| 1136 | if (gc == NULL || gsc == NULL) | |
| 1137 | return; | |
| 1138 | ||
| 1139 | user = gc->proto_data; | |
| 1140 | if ((user == NULL) || (conn = user->conn) == NULL) | |
| 1141 | return; | |
| 1142 | ||
| 1143 | conn->ssl_conn = g_new0(NMSSLConn, 1); | |
| 1144 | conn->ssl_conn->data = gsc; | |
| 1145 | conn->ssl_conn->read = (nm_ssl_read_cb) gaim_ssl_read; | |
| 1146 | conn->ssl_conn->write = (nm_ssl_write_cb) gaim_ssl_write; | |
| 1147 | ||
| 1148 | gaim_connection_update_progress(gc, _("Authenticating..."), | |
| 1149 | 2, NOVELL_CONNECT_STEPS); | |
| 1150 | ||
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8782
diff
changeset
|
1151 | my_addr = gaim_network_get_my_ip(gsc->fd); |
| 8675 | 1152 | pwd = gaim_account_get_password(user->client_data); |
| 1153 | ua = _user_agent_string(); | |
| 1154 | ||
| 1155 | rc = nm_send_login(user, pwd, my_addr, ua, _login_resp_cb, NULL); | |
| 1156 | if (rc == NM_OK) { | |
| 1157 | conn->connected = TRUE; | |
| 1158 | gaim_ssl_input_add(gsc, novell_ssl_recv_cb, gc); | |
| 1159 | } else { | |
| 1160 | gaim_connection_error(gc, _("Unable to connect to server.")); | |
| 1161 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1162 | |
| 8675 | 1163 | gaim_connection_update_progress(gc, _("Waiting for response..."), |
| 1164 | 3, NOVELL_CONNECT_STEPS); | |
| 1165 | ||
| 1166 | g_free(ua); | |
| 1167 | } | |
| 1168 | ||
| 1169 | /******************************************************************************* | |
| 1170 | * Event callback and event handlers | |
| 1171 | ******************************************************************************/ | |
| 1172 | ||
| 1173 | static void | |
| 1174 | _evt_receive_message(NMUser * user, NMEvent * event) | |
| 1175 | { | |
| 1176 | NMUserRecord *user_record = NULL; | |
| 1177 | NMContact *contact = NULL; | |
| 1178 | GaimConversation *gconv; | |
| 1179 | NMConference *conference; | |
| 1180 | GaimConvImFlags imflags; | |
| 1181 | ||
| 1182 | conference = nm_event_get_conference(event); | |
| 1183 | if (conference) { | |
| 1184 | ||
| 1185 | GaimConversation *chat = nm_conference_get_data(conference); | |
| 1186 | ||
| 1187 | /* Is this a single person 'conversation' or a conference? */ | |
| 1188 | if (chat == NULL && nm_conference_get_participant_count(conference) == 1) { | |
| 1189 | ||
| 1190 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1191 | if (user_record) { | |
| 1192 | ||
| 1193 | imflags = 0; | |
| 1194 | if (nm_event_get_type(event) == NMEVT_RECEIVE_AUTOREPLY) | |
| 1195 | imflags |= GAIM_CONV_IM_AUTO_RESP; | |
| 1196 | ||
| 1197 | serv_got_im(gaim_account_get_connection(user->client_data), | |
| 1198 | nm_user_record_get_display_id(user_record), | |
| 1199 | nm_event_get_text(event), imflags, | |
| 1200 | nm_event_get_gmt(event)); | |
| 1201 | ||
| 1202 | gconv = gaim_find_conversation_with_account( | |
| 1203 | nm_user_record_get_display_id(user_record), | |
| 1204 | (GaimAccount *) user->client_data); | |
| 1205 | if (gconv) { | |
| 1206 | ||
| 1207 | contact = nm_find_contact(user, nm_event_get_source(event)); | |
| 1208 | if (contact) { | |
| 1209 | ||
| 1210 | gaim_conversation_set_title( | |
| 1211 | gconv, | |
| 1212 | nm_contact_get_display_name(contact)); | |
| 1213 | ||
| 1214 | ||
| 1215 | } else { | |
| 1216 | ||
| 1217 | const char *name = | |
| 1218 | nm_user_record_get_full_name(user_record); | |
| 1219 | ||
| 1220 | if (name == NULL) | |
| 1221 | name = nm_user_record_get_userid(user_record); | |
| 1222 | ||
| 1223 | gaim_conversation_set_title(gconv, name); | |
| 1224 | } | |
| 1225 | ||
| 1226 | } | |
| 1227 | ||
| 1228 | } else { | |
| 1229 | /* this should not happen, see the event code. | |
| 1230 | * the event code will get the contact details from | |
| 1231 | * the server if it does not have them before calling | |
| 1232 | * the event callback. | |
| 1233 | */ | |
| 1234 | } | |
| 1235 | ||
| 1236 | } else if (chat) { | |
| 1237 | ||
| 1238 | /* get the contact for send if we have one */ | |
| 1239 | NMContact *contact = nm_find_contact(user, | |
| 1240 | nm_event_get_source(event)); | |
| 1241 | ||
| 1242 | /* get the user record for the sender */ | |
| 1243 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1244 | if (user_record) { | |
| 1245 | const char *name = nm_contact_get_display_name(contact); | |
| 1246 | ||
| 1247 | if (name == NULL) { | |
| 1248 | name = nm_user_record_get_full_name(user_record); | |
| 1249 | if (name == NULL) | |
| 1250 | name = nm_user_record_get_display_id(user_record); | |
| 1251 | } | |
| 1252 | ||
| 1253 | serv_got_chat_in(gaim_account_get_connection(user->client_data), | |
| 1254 | gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)), | |
| 1255 | name, | |
| 1256 | 0, nm_event_get_text(event), | |
| 1257 | nm_event_get_gmt(event)); | |
| 1258 | } | |
| 1259 | } | |
| 1260 | } | |
| 1261 | } | |
| 1262 | ||
| 1263 | static void | |
| 1264 | _evt_conference_left(NMUser * user, NMEvent * event) | |
| 1265 | { | |
| 1266 | GaimConversation *chat; | |
| 1267 | NMConference *conference; | |
| 1268 | ||
| 1269 | conference = nm_event_get_conference(event); | |
| 1270 | if (conference) { | |
| 1271 | chat = nm_conference_get_data(conference); | |
| 1272 | if (chat) { | |
| 1273 | NMUserRecord *ur = nm_find_user_record(user, | |
| 1274 | nm_event_get_source(event)); | |
| 1275 | ||
| 1276 | if (ur) | |
| 1277 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat), | |
| 1278 | nm_user_record_get_display_id(ur), | |
| 1279 | NULL); | |
| 1280 | } | |
| 1281 | } | |
| 1282 | } | |
| 1283 | ||
| 1284 | static void | |
| 1285 | _evt_conference_invite(NMUser * user, NMEvent * event) | |
| 1286 | { | |
| 1287 | NMUserRecord *ur; | |
| 1288 | GSList *parms = NULL; | |
| 1289 | const char *title = NULL; | |
| 1290 | const char *secondary = NULL; | |
| 1291 | const char *name = NULL; | |
| 1292 | char *primary = NULL; | |
| 1293 | time_t gmt; | |
| 1294 | ||
| 1295 | ur = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1296 | if (ur) | |
| 1297 | name = nm_user_record_get_full_name(ur); | |
| 1298 | ||
| 1299 | if (name == NULL) | |
| 1300 | name = nm_event_get_source(event); | |
| 1301 | ||
| 1302 | gmt = nm_event_get_gmt(event); | |
| 1303 | title = _("Invitation to Conversation"); | |
| 1304 | primary = g_strdup_printf(_("Invitation from: %s\n\nSent: %s"), | |
| 1305 | name, asctime(localtime(&gmt))); | |
| 1306 | secondary = _("Would you like to join the conversation?"); | |
| 1307 | ||
| 1308 | /* Set up parms list for the callbacks | |
| 1309 | * We need to send the NMUser object and | |
| 1310 | * the NMConference object to the callbacks | |
| 1311 | */ | |
| 1312 | parms = NULL; | |
| 1313 | parms = g_slist_append(parms, user); | |
| 1314 | parms = g_slist_append(parms, nm_event_get_conference(event)); | |
| 1315 | ||
| 1316 | /* Prompt the user */ | |
| 1317 | gaim_request_action(NULL, title, primary, secondary, -1, parms, 2, | |
| 1318 | _("Yes"), G_CALLBACK(_join_conference_cb), | |
| 1319 | _("No"), G_CALLBACK(_reject_conference_cb)); | |
| 1320 | ||
| 1321 | g_free(primary); | |
| 1322 | } | |
| 1323 | ||
| 1324 | ||
| 1325 | static void | |
| 1326 | _evt_conference_joined(NMUser * user, NMEvent * event) | |
| 1327 | { | |
| 1328 | GaimConversation *chat = NULL; | |
| 1329 | GaimConnection *gc; | |
| 1330 | NMConference *conference = NULL; | |
| 1331 | NMUserRecord *ur = NULL; | |
| 1332 | const char *name; | |
| 1333 | char *conf_name; | |
| 1334 | ||
| 1335 | gc = gaim_account_get_connection(user->client_data); | |
| 1336 | if (gc == NULL) | |
| 1337 | return; | |
| 1338 | ||
| 1339 | conference = nm_event_get_conference(event); | |
| 1340 | if (conference) { | |
| 1341 | chat = nm_conference_get_data(conference); | |
| 1342 | if (nm_conference_get_participant_count(conference) == 2 && chat == NULL) { | |
| 1343 | ur = nm_conference_get_participant(conference, 0); | |
| 1344 | if (ur) { | |
| 1345 | conf_name = g_strdup_printf(_("GroupWise Conference %d"), | |
| 1346 | ++user->conference_count); | |
| 1347 | chat = | |
| 1348 | serv_got_joined_chat(gc, user->conference_count, conf_name); | |
| 1349 | g_free(conf_name); | |
| 1350 | if (chat) { | |
| 1351 | ||
| 1352 | nm_conference_set_data(conference, (gpointer) chat); | |
| 1353 | ||
| 1354 | name = nm_user_record_get_display_id(ur); | |
| 1355 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL); | |
| 1356 | ||
| 1357 | } | |
| 1358 | } | |
| 1359 | } | |
| 1360 | ||
| 1361 | if (chat != NULL) { | |
| 1362 | ur = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1363 | if (ur) { | |
| 1364 | name = nm_user_record_get_display_id(ur); | |
| 1365 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat), name, NULL); | |
| 1366 | } | |
| 1367 | } | |
| 1368 | } | |
| 1369 | } | |
| 1370 | ||
| 1371 | static void | |
| 1372 | _evt_status_change(NMUser * user, NMEvent * event) | |
| 1373 | { | |
| 1374 | GaimBuddy *buddy = NULL; | |
| 1375 | GSList *buddies; | |
| 1376 | GSList *bnode; | |
| 1377 | NMUserRecord *user_record; | |
| 1378 | const char *display_id; | |
| 1379 | int status; | |
| 1380 | ||
| 1381 | user_record = nm_event_get_user_record(event); | |
| 1382 | if (user_record) { | |
| 1383 | ||
| 1384 | /* Retrieve new status */ | |
| 1385 | status = nm_user_record_get_status(user_record); | |
| 1386 | ||
| 1387 | /* Update status for buddy in all folders */ | |
| 1388 | display_id = nm_user_record_get_display_id(user_record); | |
| 1389 | buddies = gaim_find_buddies(user->client_data, display_id); | |
| 1390 | for (bnode = buddies; bnode; bnode = bnode->next) { | |
| 1391 | buddy = (GaimBuddy *) bnode->data; | |
| 1392 | if (buddy) { | |
| 1393 | _update_buddy_status(buddy, status, nm_event_get_gmt(event)); | |
| 1394 | } | |
| 1395 | } | |
| 1396 | ||
| 1397 | g_slist_free(buddies); | |
| 1398 | ||
| 1399 | } | |
| 1400 | } | |
| 1401 | ||
| 1402 | static void | |
| 1403 | _evt_user_disconnect(NMUser * user, NMEvent * event) | |
| 1404 | { | |
| 1405 | GaimConnection *gc; | |
| 1406 | ||
| 1407 | gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
| 1408 | if (gc) | |
| 1409 | gaim_connection_error(gc, _("You have been logged out because you" | |
| 1410 | " logged in at another workstation.")); | |
| 1411 | } | |
| 1412 | ||
| 1413 | static void | |
| 1414 | _evt_user_typing(NMUser * user, NMEvent * event) | |
| 1415 | { | |
| 1416 | GaimConnection *gc; | |
| 1417 | NMUserRecord *user_record = NULL; | |
| 1418 | ||
| 1419 | gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
| 1420 | if (gc) { | |
| 1421 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1422 | if (user_record) { | |
| 1423 | serv_got_typing(gc, nm_user_record_get_display_id(user_record), | |
| 1424 | 30, GAIM_TYPING); | |
| 1425 | } | |
| 1426 | } | |
| 1427 | } | |
| 1428 | ||
| 1429 | static void | |
| 1430 | _evt_user_not_typing(NMUser * user, NMEvent * event) | |
| 1431 | { | |
| 1432 | GaimConnection *gc; | |
| 1433 | NMUserRecord *user_record; | |
| 1434 | ||
| 1435 | gc = gaim_account_get_connection((GaimAccount *) user->client_data); | |
| 1436 | if (gc) { | |
| 1437 | user_record = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1438 | if (user_record) { | |
| 1439 | serv_got_typing_stopped(gc, | |
| 1440 | nm_user_record_get_display_id(user_record)); | |
| 1441 | } | |
| 1442 | } | |
| 1443 | } | |
| 1444 | ||
| 1445 | static void | |
| 1446 | _evt_undeliverable_status(NMUser * user, NMEvent * event) | |
| 1447 | { | |
| 1448 | NMUserRecord *ur; | |
| 1449 | GaimConversation *gconv; | |
| 1450 | char *str; | |
| 1451 | ||
| 1452 | ur = nm_find_user_record(user, nm_event_get_source(event)); | |
| 1453 | if (ur) { | |
| 1454 | gconv = | |
| 1455 | gaim_find_conversation_with_account(nm_user_record_get_display_id(ur), | |
| 1456 | user->client_data); | |
| 1457 | if (gconv) { | |
| 1458 | const char *name = nm_user_record_get_full_name(ur); | |
| 1459 | ||
| 1460 | if (name == NULL) { | |
| 1461 | name = nm_user_record_get_display_id(ur); | |
| 1462 | } | |
| 1463 | str = g_strdup_printf(_("%s appears to be offline and did not receive" | |
| 1464 | " the message that you just sent."), name); | |
| 1465 | gaim_conversation_write(gconv, NULL, str, | |
| 1466 | GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1467 | g_free(str); | |
| 1468 | } | |
| 1469 | } | |
| 1470 | } | |
| 1471 | ||
| 1472 | static void | |
| 1473 | _event_callback(NMUser * user, NMEvent * event) | |
| 1474 | { | |
| 1475 | if (user == NULL || event == NULL) | |
| 1476 | return; | |
| 1477 | ||
| 1478 | switch (nm_event_get_type(event)) { | |
| 1479 | case NMEVT_STATUS_CHANGE: | |
| 1480 | _evt_status_change(user, event); | |
| 1481 | break; | |
| 1482 | case NMEVT_RECEIVE_AUTOREPLY: | |
| 1483 | case NMEVT_RECEIVE_MESSAGE: | |
| 1484 | _evt_receive_message(user, event); | |
| 1485 | break; | |
| 1486 | case NMEVT_USER_DISCONNECT: | |
| 1487 | _evt_user_disconnect(user, event); | |
| 1488 | break; | |
| 1489 | case NMEVT_USER_TYPING: | |
| 1490 | _evt_user_typing(user, event); | |
| 1491 | break; | |
| 1492 | case NMEVT_USER_NOT_TYPING: | |
| 1493 | _evt_user_not_typing(user, event); | |
| 1494 | break; | |
| 1495 | case NMEVT_SERVER_DISCONNECT: | |
| 1496 | /* Nothing to do? */ | |
| 1497 | break; | |
| 1498 | case NMEVT_INVALID_RECIPIENT: | |
| 1499 | break; | |
| 1500 | case NMEVT_UNDELIVERABLE_STATUS: | |
| 1501 | _evt_undeliverable_status(user, event); | |
| 1502 | break; | |
| 1503 | case NMEVT_CONFERENCE_INVITE_NOTIFY: | |
| 1504 | /* Someone else has been invited to join a | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1505 | * conference that we are currently a part of |
| 8675 | 1506 | */ |
| 1507 | /* TODO: show the invite notify in chat window */ | |
| 1508 | break; | |
| 1509 | case NMEVT_CONFERENCE_INVITE: | |
| 1510 | /* We have been invited to join a conference */ | |
| 1511 | _evt_conference_invite(user, event); | |
| 1512 | break; | |
| 1513 | case NMEVT_CONFERENCE_JOINED: | |
| 1514 | /* Some one has joined a conference that we | |
| 1515 | * are a part of | |
| 1516 | */ | |
| 1517 | _evt_conference_joined(user, event); | |
| 1518 | break; | |
| 1519 | case NMEVT_CONFERENCE_LEFT: | |
| 1520 | /* Someone else has left a conference that we | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1521 | * are currently a part of |
| 8675 | 1522 | */ |
| 1523 | _evt_conference_left(user, event); | |
| 1524 | break; | |
| 1525 | default: | |
| 1526 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 1527 | "_event_callback(): unhandled event, %d\n", | |
| 1528 | nm_event_get_type(event)); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1529 | break; |
| 8675 | 1530 | } |
| 1531 | } | |
| 1532 | ||
| 1533 | /******************************************************************************* | |
| 1534 | * Prpl Ops | |
| 1535 | ******************************************************************************/ | |
| 1536 | ||
| 1537 | static void | |
| 1538 | novell_login(GaimAccount * account) | |
| 1539 | { | |
| 1540 | GaimConnection *gc; | |
| 1541 | NMUser *user = NULL; | |
| 1542 | const char *server; | |
| 1543 | const char *name; | |
| 1544 | int port; | |
| 1545 | ||
| 1546 | if (account == NULL) | |
| 1547 | return; | |
| 1548 | ||
| 1549 | gc = gaim_account_get_connection(account); | |
| 1550 | if (gc == NULL) | |
| 1551 | return; | |
| 1552 | ||
| 1553 | server = gaim_account_get_string(account, "server", NULL); | |
| 1554 | if (server == NULL || *server == '\0') { | |
| 1555 | ||
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1556 | /* TODO: Would be nice to prompt if not set! |
| 8675 | 1557 | * gaim_request_fields(gc, _("Server Address"),...); |
| 1558 | */ | |
| 1559 | ||
| 1560 | /* ...but for now just error out with a nice message. */ | |
| 1561 | gaim_connection_error(gc, _("Unable to connect to server." | |
| 1562 | " Please enter the address of the server" | |
| 1563 | " you wish to connect to.")); | |
| 1564 | return; | |
| 1565 | } | |
| 1566 | ||
| 1567 | port = gaim_account_get_int(account, "port", DEFAULT_PORT); | |
| 1568 | name = gaim_account_get_username(account); | |
| 1569 | ||
| 1570 | user = nm_initialize_user(name, server, port, account, _event_callback); | |
| 1571 | if (user) { | |
| 1572 | /* save user */ | |
| 1573 | gc->proto_data = user; | |
| 1574 | ||
| 1575 | /* connect to the server */ | |
| 1576 | gaim_connection_update_progress(gc, _("Connecting"), | |
| 1577 | 1, NOVELL_CONNECT_STEPS); | |
| 1578 | ||
| 1579 | user->conn->use_ssl = TRUE; | |
| 1580 | if (gaim_ssl_connect(user->client_data, user->conn->addr, | |
| 1581 | user->conn->port, novell_ssl_connected_cb, | |
| 1582 | novell_ssl_connect_error, gc) == NULL) { | |
| 1583 | gaim_connection_error(gc, _("Error." | |
| 1584 | " SSL support is not installed.")); | |
| 1585 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1586 | } |
| 8675 | 1587 | } |
| 1588 | ||
| 1589 | static void | |
| 1590 | novell_close(GaimConnection * gc) | |
| 1591 | { | |
| 1592 | NMUser *user; | |
| 1593 | NMConn *conn; | |
| 1594 | ||
| 1595 | if (gc == NULL) | |
| 1596 | return; | |
| 1597 | ||
| 1598 | user = gc->proto_data; | |
| 1599 | if (user) { | |
| 1600 | conn = user->conn; | |
| 1601 | if (conn) { | |
| 1602 | if (conn->use_ssl && user->conn->ssl_conn) { | |
| 1603 | gaim_ssl_close(user->conn->ssl_conn->data); | |
| 1604 | } else { | |
| 1605 | gaim_input_remove(gc->inpa); | |
| 1606 | close(conn->fd); | |
| 1607 | } | |
| 1608 | } | |
| 1609 | nm_deinitialize_user(user); | |
| 1610 | } | |
| 1611 | gc->proto_data = NULL; | |
| 1612 | } | |
| 1613 | ||
| 1614 | static int | |
| 1615 | novell_send_im(GaimConnection * gc, const char *name, | |
| 1616 | const char *message_body, GaimConvImFlags flags) | |
| 1617 | { | |
| 1618 | NMUserRecord *user_record = NULL; | |
| 1619 | NMConference *conf = NULL; | |
| 1620 | NMMessage *message; | |
| 1621 | NMUser *user; | |
| 1622 | const char *dn = NULL; | |
| 1623 | gboolean done = TRUE, created_conf = FALSE; | |
| 1624 | NMERR_T rc = NM_OK; | |
| 1625 | ||
| 1626 | if (gc == NULL || name == NULL || | |
| 1627 | message_body == NULL || *message_body == '\0') | |
| 1628 | return 0; | |
| 1629 | ||
| 1630 | user = gc->proto_data; | |
| 1631 | if (user == NULL) | |
| 1632 | return 0; | |
| 1633 | ||
| 1634 | /* Create a new message */ | |
| 1635 | message = nm_create_message(gaim_markup_strip_html(message_body)); | |
| 1636 | ||
| 1637 | /* Need to get the DN for the buddy so we can look up the convo */ | |
| 1638 | dn = nm_lookup_dn(user, name); | |
| 1639 | ||
| 1640 | /* Do we already know about the sender? */ | |
| 1641 | user_record = nm_find_user_record(user, dn); | |
| 1642 | if (user_record) { | |
| 1643 | ||
| 1644 | /* Do we already have an instantiated conference? */ | |
| 1645 | conf = nm_find_conversation(user, dn); | |
| 1646 | if (conf == NULL) { | |
| 1647 | ||
| 1648 | /* If not, create a blank conference */ | |
| 1649 | conf = nm_create_conference(NULL); | |
| 1650 | created_conf = TRUE; | |
| 1651 | ||
| 1652 | nm_conference_add_participant(conf, user_record); | |
| 1653 | } | |
| 1654 | ||
| 1655 | nm_message_set_conference(message, conf); | |
| 1656 | ||
| 1657 | /* Make sure conference is instatiated */ | |
| 1658 | if (!nm_conference_is_instantiated(conf)) { | |
| 1659 | ||
| 1660 | /* It is not, so send the createconf. We will | |
| 1661 | * have to finish sending the message when we | |
| 1662 | * get the response with the new conference guid. | |
| 1663 | */ | |
| 1664 | rc = nm_send_create_conference(user, conf, | |
| 1665 | _createconf_resp_send_msg, message); | |
| 1666 | _check_for_disconnect(user, rc); | |
| 1667 | ||
| 1668 | done = FALSE; | |
| 1669 | } | |
| 1670 | ||
| 1671 | } else { | |
| 1672 | ||
| 1673 | /* If we don't have details for the user, then we don't have | |
| 1674 | * a conference yet. So create one and send the getdetails | |
| 1675 | * to the server. We will have to finish sending the message | |
| 1676 | * when we get the response from the server. | |
| 1677 | */ | |
| 1678 | conf = nm_create_conference(NULL); | |
| 1679 | created_conf = TRUE; | |
| 1680 | ||
| 1681 | nm_message_set_conference(message, conf); | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1682 | |
| 8675 | 1683 | rc = nm_send_get_details(user, name, _get_details_resp_send_msg, message); |
| 1684 | _check_for_disconnect(user, rc); | |
| 1685 | ||
| 1686 | done = FALSE; | |
| 1687 | } | |
| 1688 | ||
| 1689 | if (done) { | |
| 1690 | ||
| 1691 | /* Did we find everything we needed? */ | |
| 1692 | rc = nm_send_message(user, message, _send_message_resp_cb); | |
| 1693 | _check_for_disconnect(user, rc); | |
| 1694 | ||
| 1695 | nm_release_message(message); | |
| 1696 | } | |
| 1697 | ||
| 1698 | if (created_conf && conf) | |
| 1699 | nm_release_conference(conf); | |
| 1700 | ||
| 1701 | return 1; | |
| 1702 | } | |
| 1703 | ||
| 1704 | static int | |
| 1705 | novell_send_typing(GaimConnection * gc, const char *name, int typing) | |
| 1706 | { | |
| 1707 | NMConference *conf = NULL; | |
| 1708 | NMUser *user; | |
| 1709 | const char *dn = NULL; | |
| 1710 | NMERR_T rc = NM_OK; | |
| 1711 | ||
| 1712 | if (gc == NULL || name == NULL) | |
| 1713 | return -1; | |
| 1714 | ||
| 1715 | user = gc->proto_data; | |
| 1716 | if (user == NULL) | |
| 1717 | return -1; | |
| 1718 | ||
| 1719 | /* Need to get the DN for the buddy so we can look up the convo */ | |
| 1720 | dn = nm_lookup_dn(user, name); | |
| 1721 | if (dn) { | |
| 1722 | ||
| 1723 | /* Now find the conference in our list */ | |
| 1724 | conf = nm_find_conversation(user, dn); | |
| 1725 | if (conf) { | |
| 1726 | ||
| 1727 | rc = nm_send_typing(user, conf, | |
| 1728 | ((typing == GAIM_TYPING) ? TRUE : FALSE), NULL); | |
| 1729 | _check_for_disconnect(user, rc); | |
| 1730 | ||
| 1731 | } | |
| 1732 | ||
| 1733 | } | |
| 1734 | ||
| 1735 | return 0; | |
| 1736 | } | |
| 1737 | ||
| 1738 | static void | |
| 1739 | novell_convo_closed(GaimConnection * gc, const char *who) | |
| 1740 | { | |
| 1741 | NMUser *user; | |
| 1742 | NMConference *conf; | |
| 1743 | const char *dn; | |
| 1744 | NMERR_T rc = NM_OK; | |
| 1745 | ||
| 1746 | if (gc == NULL || who == NULL) | |
| 1747 | return; | |
| 1748 | ||
| 1749 | user = gc->proto_data; | |
| 1750 | if (user && (dn = nm_lookup_dn(user, who))) { | |
| 1751 | conf = nm_find_conversation(user, dn); | |
| 1752 | if (conf) { | |
| 1753 | rc = nm_send_leave_conference(user, conf, NULL, NULL); | |
| 1754 | _check_for_disconnect(user, rc); | |
| 1755 | } | |
| 1756 | } | |
| 1757 | } | |
| 1758 | ||
| 1759 | static void | |
| 1760 | novell_chat_leave(GaimConnection * gc, int id) | |
| 1761 | { | |
| 1762 | NMConference *conference; | |
| 1763 | NMUser *user; | |
| 1764 | GaimConversation *chat; | |
| 1765 | GSList *cnode; | |
| 1766 | NMERR_T rc = NM_OK; | |
| 1767 | ||
| 1768 | if (gc == NULL) | |
| 1769 | return; | |
| 1770 | ||
| 1771 | user = gc->proto_data; | |
| 1772 | if (user == NULL) | |
| 1773 | return; | |
| 1774 | ||
| 1775 | for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) { | |
| 1776 | conference = cnode->data; | |
| 1777 | if (conference && (chat = nm_conference_get_data(conference))) { | |
| 1778 | if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) { | |
| 1779 | rc = nm_send_leave_conference(user, conference, NULL, NULL); | |
| 1780 | _check_for_disconnect(user, rc); | |
| 1781 | break; | |
| 1782 | } | |
| 1783 | } | |
| 1784 | } | |
| 1785 | ||
| 1786 | serv_got_chat_left(gc, id); | |
| 1787 | } | |
| 1788 | ||
| 1789 | static int | |
| 1790 | novell_chat_send(GaimConnection * gc, int id, const char *text) | |
| 1791 | { | |
| 1792 | NMConference *conference; | |
| 1793 | GaimConversation *chat; | |
| 1794 | GSList *cnode; | |
| 1795 | NMMessage *message; | |
| 1796 | NMUser *user; | |
| 1797 | NMERR_T rc = NM_OK; | |
| 1798 | const char *name; | |
| 1799 | char *str; | |
| 1800 | ||
| 1801 | if (gc == NULL || text == NULL) | |
| 1802 | return -1; | |
| 1803 | ||
| 1804 | user = gc->proto_data; | |
| 1805 | if (user == NULL) | |
| 1806 | return -1; | |
| 1807 | ||
| 1808 | message = nm_create_message(gaim_markup_strip_html(text)); | |
| 1809 | ||
| 1810 | for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) { | |
| 1811 | conference = cnode->data; | |
| 1812 | if (conference && (chat = nm_conference_get_data(conference))) { | |
| 1813 | if (gaim_conv_chat_get_id(GAIM_CONV_CHAT(chat)) == id) { | |
| 1814 | ||
| 1815 | nm_message_set_conference(message, conference); | |
| 1816 | ||
| 1817 | rc = nm_send_message(user, message, _send_message_resp_cb); | |
| 1818 | nm_release_message(message); | |
| 1819 | ||
| 1820 | if (!_check_for_disconnect(user, rc)) { | |
| 1821 | ||
| 1822 | /* Use the account alias if it is set */ | |
| 1823 | name = gaim_account_get_alias(user->client_data); | |
| 1824 | if (name == NULL || *name == '\0') { | |
| 1825 | ||
| 1826 | /* If there is no account alias, try full name */ | |
| 1827 | name = nm_user_record_get_full_name(user->user_record); | |
| 1828 | if (name == NULL || *name == '\0') { | |
| 1829 | ||
| 1830 | /* Fall back to the username that we are signed in with */ | |
| 1831 | name = gaim_account_get_username(user->client_data); | |
| 1832 | } | |
| 1833 | } | |
| 1834 | ||
| 1835 | serv_got_chat_in(gc, id, name, 0, text, time(NULL)); | |
| 1836 | return 0; | |
| 1837 | } else | |
| 1838 | return -1; | |
| 1839 | ||
| 1840 | } | |
| 1841 | } | |
| 1842 | } | |
| 1843 | ||
| 1844 | /* The conference was not found, must be closed */ | |
| 1845 | chat = gaim_find_chat(gc, id); | |
| 1846 | if (chat) { | |
| 1847 | str = g_strdup_printf(_("This conference has been closed." | |
| 1848 | " No more messages can be sent.")); | |
| 1849 | gaim_conversation_write(chat, NULL, str, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1850 | g_free(str); | |
| 1851 | } | |
| 1852 | ||
|
8744
14a15b6f466d
[gaim-migrate @ 9499]
Mike Stoddard <mistoddard@novell.com>
parents:
8739
diff
changeset
|
1853 | if (message) |
|
14a15b6f466d
[gaim-migrate @ 9499]
Mike Stoddard <mistoddard@novell.com>
parents:
8739
diff
changeset
|
1854 | nm_release_message(message); |
|
14a15b6f466d
[gaim-migrate @ 9499]
Mike Stoddard <mistoddard@novell.com>
parents:
8739
diff
changeset
|
1855 | |
| 8675 | 1856 | return -1; |
| 1857 | } | |
| 1858 | ||
| 1859 | static void | |
| 1860 | novell_add_buddy(GaimConnection * gc, const char *name, GaimGroup * group) | |
| 1861 | { | |
| 1862 | GaimBuddy *buddy; | |
| 1863 | NMFolder *folder = NULL; | |
| 1864 | NMContact *contact; | |
| 1865 | NMUser *user; | |
| 1866 | NMERR_T rc = NM_OK; | |
| 1867 | ||
| 1868 | if (gc == NULL || name == NULL || group == NULL) | |
| 1869 | return; | |
| 1870 | ||
| 1871 | user = (NMUser *) gc->proto_data; | |
| 1872 | if (user == NULL) | |
| 1873 | return; | |
| 1874 | ||
| 1875 | contact = nm_create_contact(); | |
| 1876 | nm_contact_set_dn(contact, name); | |
| 1877 | ||
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8676
diff
changeset
|
1878 | /* Remove the GaimBuddy (we will add it back after adding it |
| 8675 | 1879 | * to the server side list). Save the alias if there is one. |
| 1880 | */ | |
| 1881 | buddy = gaim_find_buddy_in_group(user->client_data, name, group); | |
| 1882 | if (buddy) { | |
| 1883 | const char *alias = gaim_get_buddy_alias(buddy); | |
| 1884 | ||
| 1885 | if (alias && strcmp(alias, name)) | |
| 1886 | nm_contact_set_display_name(contact, gaim_get_buddy_alias(buddy)); | |
| 1887 | gaim_blist_remove_buddy(buddy); | |
| 1888 | buddy = NULL; | |
| 1889 | } | |
| 1890 | ||
| 1891 | ||
| 1892 | folder = nm_find_folder(user, group->name); | |
| 1893 | if (folder) { | |
| 1894 | ||
| 1895 | /* We have everything that we need, so send the createcontact */ | |
| 1896 | rc = nm_send_create_contact(user, folder, contact, | |
| 1897 | _create_contact_resp_cb, contact); | |
| 1898 | ||
| 1899 | } else { | |
| 1900 | ||
| 1901 | /* Need to create the folder before we can add the contact */ | |
| 1902 | rc = nm_send_create_folder(user, group->name, | |
| 1903 | _create_folder_resp_add_contact, contact); | |
| 1904 | } | |
| 1905 | ||
| 1906 | _check_for_disconnect(user, rc); | |
| 1907 | ||
| 1908 | } | |
| 1909 | ||
| 1910 | static void | |
| 1911 | novell_remove_buddy(GaimConnection * gc, const char *name, const char *group_name) | |
| 1912 | { | |
| 1913 | NMContact *contact; | |
| 1914 | NMFolder *folder; | |
| 1915 | NMUser *user; | |
| 1916 | const char *dn; | |
| 1917 | NMERR_T rc = NM_OK; | |
| 1918 | ||
| 1919 | if (gc == NULL || name == NULL || group_name == NULL) | |
| 1920 | return; | |
| 1921 | ||
| 1922 | user = (NMUser *) gc->proto_data; | |
| 1923 | if (user && (dn = nm_lookup_dn(user, name))) { | |
| 1924 | ||
| 1925 | folder = nm_find_folder(user, group_name); | |
| 1926 | if (folder) { | |
| 1927 | contact = nm_folder_find_contact(folder, dn); | |
| 1928 | if (contact) { | |
| 1929 | ||
| 1930 | /* Remove the buddy from the contact */ | |
| 1931 | nm_contact_set_data(contact, NULL); | |
| 1932 | ||
| 1933 | /* Tell the server to remove the contact */ | |
| 1934 | rc = nm_send_remove_contact(user, folder, contact, | |
| 1935 | _remove_contact_resp_cb, NULL); | |
| 1936 | _check_for_disconnect(user, rc); | |
| 1937 | } | |
| 1938 | } | |
| 1939 | } | |
| 1940 | } | |
| 1941 | ||
| 1942 | static void | |
| 1943 | novell_remove_group(GaimConnection * gc, const char *name) | |
| 1944 | { | |
| 1945 | NMUser *user; | |
| 1946 | NMERR_T rc = NM_OK; | |
| 1947 | ||
| 1948 | if (gc == NULL || name == NULL) | |
| 1949 | return; | |
| 1950 | ||
| 1951 | user = (NMUser *) gc->proto_data; | |
| 1952 | if (user) { | |
| 1953 | NMFolder *folder = nm_find_folder(user, name); | |
| 1954 | ||
| 1955 | if (folder) { | |
| 1956 | rc = nm_send_remove_folder(user, folder, | |
| 1957 | _remove_folder_resp_cb, NULL); | |
| 1958 | _check_for_disconnect(user, rc); | |
| 1959 | } | |
| 1960 | } | |
| 1961 | } | |
| 1962 | ||
| 1963 | static void | |
| 1964 | novell_alias_buddy(GaimConnection * gc, const char *name, const char *alias) | |
| 1965 | { | |
| 1966 | NMContact *contact; | |
| 1967 | NMUser *user; | |
| 1968 | GList *contacts = NULL; | |
| 1969 | GList *cnode = NULL; | |
| 1970 | const char *dn = NULL; | |
| 1971 | NMERR_T rc = NM_OK; | |
| 1972 | ||
| 1973 | if (gc == NULL || name == NULL || alias == NULL) | |
| 1974 | return; | |
| 1975 | ||
| 1976 | user = (NMUser *) gc->proto_data; | |
| 1977 | if (user && (dn = nm_lookup_dn(user, name))) { | |
| 1978 | ||
| 1979 | /* Alias all of instances of the contact */ | |
| 1980 | contacts = nm_find_contacts(user, dn); | |
| 1981 | for (cnode = contacts; cnode != NULL; cnode = cnode->next) { | |
| 1982 | contact = (NMContact *) cnode->data; | |
| 1983 | if (contact) { | |
| 1984 | GaimGroup *group; | |
| 1985 | GaimBuddy *buddy; | |
| 1986 | NMFolder *folder; | |
| 1987 | ||
| 1988 | /* Alias the Gaim buddy? */ | |
| 1989 | folder = nm_find_folder_by_id(user, | |
| 1990 | nm_contact_get_parent_id(contact)); | |
| 1991 | if (folder && | |
| 1992 | (group = gaim_find_group(nm_folder_get_name(folder)))) { | |
| 1993 | buddy = gaim_find_buddy_in_group(user->client_data, | |
| 1994 | name, group); | |
| 1995 | if (buddy && strcmp(buddy->alias, alias)) | |
| 1996 | gaim_blist_alias_buddy(buddy, alias); | |
| 1997 | ||
| 1998 | } | |
| 1999 | /* Tell the server to alias the contact */ | |
| 2000 | rc = nm_send_rename_contact(user, contact, alias, | |
| 2001 | _rename_contact_resp_cb, NULL); | |
| 2002 | _check_for_disconnect(user, rc); | |
| 2003 | } | |
| 2004 | } | |
| 2005 | if (contacts) | |
| 2006 | g_list_free(contacts); | |
| 2007 | } | |
| 2008 | } | |
| 2009 | ||
| 2010 | static void | |
| 2011 | novell_group_buddy(GaimConnection * gc, | |
| 2012 | const char *name, const char *old_group_name, | |
| 2013 | const char *new_group_name) | |
| 2014 | { | |
| 2015 | NMFolder *old_folder; | |
| 2016 | NMFolder *new_folder; | |
| 2017 | NMContact *contact; | |
| 2018 | NMUser *user; | |
| 2019 | const char *dn; | |
| 2020 | NMERR_T rc = NM_OK; | |
| 2021 | ||
| 2022 | if (gc == NULL || name == NULL || | |
| 2023 | old_group_name == NULL || new_group_name == NULL) | |
| 2024 | return; | |
| 2025 | ||
| 2026 | user = (NMUser *) gc->proto_data; | |
| 2027 | if (user && (dn = nm_lookup_dn(user, name))) { | |
| 2028 | ||
| 2029 | /* Find the old folder */ | |
| 2030 | old_folder = nm_find_folder(user, old_group_name); | |
| 2031 | if (old_folder && (contact = nm_folder_find_contact(old_folder, dn))) { | |
| 2032 | ||
| 2033 | /* Find the new folder */ | |
| 2034 | new_folder = nm_find_folder(user, new_group_name); | |
| 2035 | if (new_folder) { | |
| 2036 | ||
| 2037 | /* Tell the server to move the contact to the new folder */ | |
| 2038 | rc = nm_send_move_contact(user, contact, new_folder, | |
| 2039 | _move_contact_resp_cb, NULL); | |
| 2040 | ||
| 2041 | } else { | |
| 2042 | ||
| 2043 | nm_contact_add_ref(contact); | |
| 2044 | ||
| 2045 | /* Remove the old contact first */ | |
| 2046 | nm_send_remove_contact(user, old_folder, contact, | |
| 2047 | _remove_contact_resp_cb, NULL); | |
| 2048 | ||
| 2049 | /* New folder does not exist yet, so create it */ | |
| 2050 | rc = nm_send_create_folder(user, new_group_name, | |
| 2051 | _create_folder_resp_move_contact, | |
| 2052 | contact); | |
| 2053 | } | |
| 2054 | ||
| 2055 | _check_for_disconnect(user, rc); | |
| 2056 | } | |
| 2057 | } | |
| 2058 | } | |
| 2059 | ||
| 2060 | static void | |
| 2061 | novell_rename_group(GaimConnection * gc, const char *old_name, | |
| 2062 | const char *new_name, GList * tobemoved) | |
| 2063 | { | |
| 2064 | NMERR_T rc = NM_OK; | |
| 8782 | 2065 | NMFolder *folder; |
| 8675 | 2066 | NMUser *user; |
| 2067 | ||
| 2068 | if (gc == NULL || old_name == NULL || new_name == NULL || tobemoved == NULL) { | |
| 2069 | return; | |
| 2070 | } | |
| 2071 | ||
| 2072 | user = gc->proto_data; | |
| 2073 | if (user) { | |
| 2074 | /* Does new folder exist already? */ | |
| 2075 | if (nm_find_folder(user, new_name)) { | |
| 2076 | /* Gaim currently calls novell_group_buddy() for | |
| 2077 | * for all buddies in the group, so we don't | |
| 2078 | * need to worry about this situation. | |
| 2079 | */ | |
| 2080 | return; | |
| 2081 | } | |
| 2082 | ||
| 8782 | 2083 | folder = nm_find_folder(user, old_name); |
| 8675 | 2084 | |
| 2085 | if (folder) { | |
| 2086 | rc = nm_send_rename_folder(user, folder, new_name, | |
| 2087 | _rename_folder_resp_cb, NULL); | |
| 2088 | _check_for_disconnect(user, rc); | |
| 2089 | } | |
| 2090 | } | |
| 2091 | } | |
| 2092 | ||
| 2093 | static void | |
| 2094 | novell_list_emblems(GaimBuddy * buddy, char **se, char **sw, char **nw, char **ne) | |
| 2095 | { | |
| 2096 | int status = buddy->uc >> 1; | |
| 2097 | ||
| 2098 | switch (status) { | |
| 2099 | case NM_STATUS_AVAILABLE: | |
| 2100 | *se = ""; | |
| 2101 | break; | |
| 2102 | case NM_STATUS_AWAY: | |
| 2103 | *se = "away"; | |
| 2104 | break; | |
| 2105 | case NM_STATUS_BUSY: | |
| 2106 | *se = "occupied"; | |
| 2107 | break; | |
| 2108 | case NM_STATUS_UNKNOWN: | |
| 2109 | *se = "error"; | |
| 2110 | break; | |
| 2111 | } | |
| 2112 | } | |
| 2113 | ||
| 2114 | static const char * | |
| 2115 | novell_list_icon(GaimAccount * account, GaimBuddy * buddy) | |
| 2116 | { | |
| 2117 | return "novell"; | |
| 2118 | } | |
| 2119 | ||
| 2120 | static char * | |
| 2121 | novell_tooltip_text(GaimBuddy * buddy) | |
| 2122 | { | |
| 2123 | NMUserRecord *user_record = NULL; | |
| 2124 | GaimConnection *gc; | |
| 2125 | NMUser *user; | |
| 2126 | int status = 0; | |
| 2127 | char *ret_text = NULL; | |
| 2128 | const char *status_str = NULL; | |
| 2129 | const char *text = NULL; | |
| 2130 | ||
| 2131 | if (buddy == NULL) | |
| 2132 | return ""; | |
| 2133 | ||
| 2134 | gc = gaim_account_get_connection(buddy->account); | |
| 2135 | if (gc == NULL || (user = gc->proto_data) == NULL) | |
| 2136 | return ""; | |
| 2137 | ||
| 2138 | if (GAIM_BUDDY_IS_ONLINE(buddy)) { | |
| 2139 | user_record = nm_find_user_record(user, buddy->name); | |
| 2140 | if (user_record) { | |
| 2141 | status = nm_user_record_get_status(user_record); | |
| 2142 | text = nm_user_record_get_status_text(user_record); | |
| 2143 | /* No custom text, so default it ... */ | |
| 2144 | switch (status) { | |
| 2145 | case NM_STATUS_AVAILABLE: | |
| 2146 | status_str = _("Available"); | |
| 2147 | break; | |
| 2148 | case NM_STATUS_AWAY: | |
| 2149 | status_str = _("Away"); | |
| 2150 | break; | |
| 2151 | case NM_STATUS_BUSY: | |
| 2152 | status_str = _("Busy"); | |
| 2153 | break; | |
| 2154 | case NM_STATUS_AWAY_IDLE: | |
| 2155 | status_str = _("Idle"); | |
| 2156 | break; | |
| 2157 | case NM_STATUS_OFFLINE: | |
| 2158 | status_str = _("Offline"); | |
| 2159 | break; | |
| 2160 | default: | |
| 2161 | status_str = _("Unknown"); | |
| 2162 | break; | |
| 2163 | } | |
| 2164 | ||
| 2165 | if (text) | |
|
8781
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2166 | ret_text = g_strdup_printf("\n<b>%s:</b> %s" |
|
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2167 | "\n<b>%s:</b> %s", |
|
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2168 | _("Status"), status_str, |
|
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2169 | _("Message"), text); |
| 8675 | 2170 | else |
|
8781
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2171 | ret_text = g_strdup_printf("\n<b>%s:</b> %s", |
|
d72008eb09e3
[gaim-migrate @ 9543]
Mark Doliner <markdoliner@pidgin.im>
parents:
8749
diff
changeset
|
2172 | _("Status"), status_str); |
| 8675 | 2173 | } |
| 2174 | } | |
| 2175 | ||
| 2176 | return ret_text; | |
| 2177 | } | |
| 2178 | ||
| 2179 | static void | |
| 2180 | novell_set_idle(GaimConnection * gc, int time) | |
| 2181 | { | |
| 2182 | NMUser *user; | |
| 2183 | NMERR_T rc = NM_OK; | |
| 2184 | ||
| 2185 | if (gc == NULL) | |
| 2186 | return; | |
| 2187 | ||
| 2188 | user = gc->proto_data; | |
| 2189 | if (user == NULL) | |
| 2190 | return; | |
| 2191 | ||
| 2192 | if (time > 0) | |
| 2193 | rc = nm_send_set_status(user, NM_STATUS_AWAY_IDLE, NULL, NULL, NULL, | |
| 2194 | NULL); | |
| 2195 | else | |
| 2196 | rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL, | |
| 2197 | NULL); | |
| 2198 | ||
| 2199 | _check_for_disconnect(user, rc); | |
| 2200 | } | |
| 2201 | ||
| 2202 | static void | |
| 2203 | novell_get_info(GaimConnection * gc, const char *name) | |
| 2204 | { | |
| 2205 | NMUserRecord *user_record; | |
| 2206 | NMUser *user; | |
| 2207 | NMERR_T rc; | |
| 2208 | ||
| 2209 | if (gc == NULL || name == NULL) | |
| 2210 | return; | |
| 2211 | ||
| 2212 | user = (NMUser *) gc->proto_data; | |
| 2213 | if (user) { | |
| 2214 | ||
| 2215 | user_record = nm_find_user_record(user, name); | |
| 2216 | if (user_record) { | |
| 2217 | ||
| 2218 | _show_info(gc, user_record); | |
| 2219 | ||
| 2220 | } else { | |
| 2221 | ||
| 2222 | rc = nm_send_get_details(user, name, | |
| 2223 | _get_details_resp_show_info, g_strdup(name)); | |
| 2224 | ||
| 2225 | _check_for_disconnect(user, rc); | |
| 2226 | ||
| 2227 | } | |
| 2228 | ||
| 2229 | } | |
| 2230 | } | |
| 2231 | ||
| 2232 | static char * | |
| 2233 | novell_status_text(GaimBuddy * buddy) | |
| 2234 | { | |
| 2235 | const char *text = NULL; | |
| 2236 | const char *dn = NULL; | |
| 2237 | ||
| 2238 | if (buddy && buddy->account) { | |
| 2239 | GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
| 2240 | ||
| 2241 | if (gc && gc->proto_data) { | |
| 2242 | NMUser *user = gc->proto_data; | |
| 2243 | ||
| 2244 | dn = nm_lookup_dn(user, buddy->name); | |
| 2245 | if (dn) { | |
| 2246 | NMUserRecord *user_record = nm_find_user_record(user, dn); | |
| 2247 | ||
| 2248 | if (user_record) { | |
| 2249 | text = nm_user_record_get_status_text(user_record); | |
| 2250 | if (text) | |
| 2251 | return g_strdup(text); | |
| 2252 | } | |
| 2253 | } | |
| 2254 | } | |
| 2255 | } | |
| 2256 | ||
| 2257 | return NULL; | |
| 2258 | } | |
| 2259 | ||
| 2260 | static GList * | |
| 2261 | novell_away_states(GaimConnection * gc) | |
| 2262 | { | |
| 2263 | GList *m = NULL; | |
| 2264 | ||
| 2265 | m = g_list_append(m, _("Available")); | |
| 2266 | m = g_list_append(m, _("Away")); | |
| 2267 | m = g_list_append(m, _("Busy")); | |
| 2268 | m = g_list_append(m, _("Appear Offline")); | |
| 2269 | m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
| 2270 | ||
| 2271 | return m; | |
| 2272 | } | |
| 2273 | ||
| 2274 | static void | |
| 2275 | novell_set_away(GaimConnection * gc, const char *state, const char *msg) | |
| 2276 | { | |
| 2277 | NMUser *user; | |
| 2278 | NMSTATUS_T status = NM_STATUS_AVAILABLE; | |
| 2279 | NMERR_T rc = NM_OK; | |
| 2280 | char *text = NULL; | |
| 2281 | char *tmp = NULL; | |
| 2282 | char *p = NULL; | |
| 2283 | ||
| 2284 | if (gc == NULL) | |
| 2285 | return; | |
| 2286 | ||
| 2287 | user = gc->proto_data; | |
| 2288 | if (user == NULL) | |
| 2289 | return; | |
| 2290 | ||
| 2291 | if (gc->away) { | |
| 2292 | g_free(gc->away); | |
| 2293 | gc->away = NULL; | |
| 2294 | } | |
| 2295 | ||
| 2296 | if (msg != NULL) { | |
| 2297 | status = NM_STATUS_AWAY; | |
| 2298 | gc->away = g_strdup(""); | |
| 2299 | ||
| 2300 | /* Don't want newlines in status text */ | |
| 2301 | tmp = g_strdup(msg); | |
| 2302 | if ((p = strchr(tmp, '\n'))) { | |
| 2303 | *p = '\0'; | |
| 2304 | } | |
| 2305 | ||
| 2306 | /* Truncate the status text if necessary */ | |
| 2307 | text = g_strdup(tmp); | |
| 2308 | if (g_utf8_strlen(tmp, -1) > 60) { | |
| 2309 | g_utf8_strncpy(text, tmp, 60); | |
| 2310 | strcat(text, "..."); | |
| 2311 | } | |
| 2312 | ||
| 2313 | g_free(tmp); | |
| 2314 | ||
| 2315 | } else if (state) { | |
| 2316 | if (!strcmp(state, _("Available"))) { | |
| 2317 | status = NM_STATUS_AVAILABLE; | |
| 2318 | } else if (!strcmp(state, _("Away"))) { | |
| 2319 | status = NM_STATUS_AWAY; | |
| 2320 | gc->away = g_strdup(""); | |
| 2321 | } else if (!strcmp(state, _("Busy"))) { | |
| 2322 | status = NM_STATUS_BUSY; | |
| 2323 | gc->away = g_strdup(""); | |
| 2324 | } else if (!strcmp(state, _("Appear Offline"))) { | |
| 2325 | status = NM_STATUS_OFFLINE; | |
| 2326 | gc->away = g_strdup(""); | |
| 2327 | } else { | |
| 2328 | status = NM_STATUS_AVAILABLE; | |
| 2329 | g_free(gc->away); | |
| 2330 | gc->away = NULL; | |
| 2331 | } | |
| 2332 | } else if (gc->is_idle) { | |
| 2333 | status = NM_STATUS_AWAY_IDLE; | |
| 2334 | } else { | |
| 2335 | status = NM_STATUS_AVAILABLE; | |
| 2336 | } | |
| 2337 | ||
| 2338 | rc = nm_send_set_status(user, status, text, msg, NULL, NULL); | |
| 2339 | _check_for_disconnect(user, rc); | |
| 2340 | ||
| 2341 | if (text) | |
| 2342 | g_free(text); | |
| 2343 | } | |
| 2344 | ||
| 2345 | static GaimPluginProtocolInfo prpl_info = { | |
|
8749
fb487e9e101a
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8746
diff
changeset
|
2346 | GAIM_PRPL_API_VERSION, |
| 8675 | 2347 | 0, |
| 2348 | NULL, | |
| 2349 | NULL, | |
| 2350 | novell_list_icon, | |
| 2351 | novell_list_emblems, | |
| 2352 | novell_status_text, | |
| 2353 | novell_tooltip_text, | |
| 2354 | novell_away_states, | |
| 2355 | NULL, /* prpl_actions */ | |
| 2356 | NULL, /* buddy_menu */ | |
| 2357 | NULL, /* chat_info */ | |
| 2358 | novell_login, | |
| 2359 | novell_close, | |
| 2360 | novell_send_im, | |
| 2361 | NULL, /* set_info */ | |
| 2362 | novell_send_typing, | |
| 2363 | novell_get_info, | |
| 2364 | novell_set_away, | |
| 2365 | NULL, /* set_dir */ | |
| 2366 | NULL, /* get_dir */ | |
| 2367 | NULL, /* dir_search */ | |
| 2368 | novell_set_idle, | |
| 2369 | NULL, /* change pwd */ | |
| 2370 | novell_add_buddy, | |
| 2371 | NULL, /* add_buddies */ | |
| 2372 | novell_remove_buddy, | |
| 2373 | NULL, /* remove_buddies */ | |
| 2374 | NULL, /* add_permit */ | |
| 2375 | NULL, /* add_deny */ | |
| 2376 | NULL, /* rem_permit */ | |
| 2377 | NULL, /* rem_deny */ | |
| 2378 | NULL, /* set_permit_deny */ | |
| 2379 | NULL, /* warn */ | |
| 2380 | NULL, /* join_chat */ | |
| 2381 | NULL, /* reject_chat ?? */ | |
| 2382 | NULL, /* chat_invite */ | |
| 2383 | novell_chat_leave, | |
| 2384 | NULL, /* chat_whisper */ | |
| 2385 | novell_chat_send, | |
| 2386 | NULL, /* keepalive */ | |
| 2387 | NULL, /* register_user */ | |
| 2388 | NULL, /* get_cb_info */ | |
| 2389 | NULL, /* get_cb_away_msg */ | |
| 2390 | novell_alias_buddy, | |
| 2391 | novell_group_buddy, | |
| 2392 | novell_rename_group, | |
| 2393 | NULL, /* buddy_free */ | |
| 2394 | novell_convo_closed, | |
| 2395 | NULL, /* normalize */ | |
| 2396 | NULL, /* set_buddy_icon */ | |
| 2397 | novell_remove_group, | |
| 2398 | NULL | |
| 2399 | }; | |
| 2400 | ||
| 2401 | static GaimPluginInfo info = { | |
|
8749
fb487e9e101a
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8746
diff
changeset
|
2402 | GAIM_PLUGIN_API_VERSION, /**< api_version */ |
| 8675 | 2403 | GAIM_PLUGIN_PROTOCOL, /**< type */ |
| 2404 | NULL, /**< ui_requirement */ | |
| 2405 | 0, /**< flags */ | |
| 2406 | NULL, /**< dependencies */ | |
| 2407 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 2408 | ||
| 2409 | "prpl-novell", /**< id */ | |
| 8676 | 2410 | "GroupWise", /**< name */ |
| 8675 | 2411 | VERSION, /**< version */ |
| 2412 | /** summary */ | |
| 2413 | N_("Novell GroupWise Messenger Protocol Plugin"), | |
| 2414 | /** description */ | |
| 2415 | N_("Novell GroupWise Messenger Protocol Plugin"), | |
| 2416 | NULL, /**< author */ | |
| 2417 | GAIM_WEBSITE, /**< homepage */ | |
| 2418 | ||
| 2419 | NULL, /**< load */ | |
| 2420 | NULL, /**< unload */ | |
| 2421 | NULL, /**< destroy */ | |
| 2422 | ||
| 2423 | NULL, /**< ui_info */ | |
| 2424 | &prpl_info /**< extra_info */ | |
| 2425 | }; | |
| 2426 | ||
| 2427 | static void | |
| 2428 | init_plugin(GaimPlugin * plugin) | |
| 2429 | { | |
| 2430 | GaimAccountOption *option; | |
| 2431 | ||
| 2432 | option = gaim_account_option_string_new(_("Server address"), "server", NULL); | |
| 2433 | prpl_info.protocol_options = | |
| 2434 | g_list_append(prpl_info.protocol_options, option); | |
| 2435 | ||
| 2436 | option = gaim_account_option_int_new(_("Server port"), "port", DEFAULT_PORT); | |
| 2437 | prpl_info.protocol_options = | |
| 2438 | g_list_append(prpl_info.protocol_options, option); | |
| 2439 | ||
| 2440 | my_protocol = plugin; | |
| 2441 | } | |
| 2442 | ||
| 2443 | GAIM_INIT_PLUGIN(novell, init_plugin, info); |