Mercurial > pidgin
comparison src/protocols/novell/novell.c @ 9651:8ce2dc65e591
[gaim-migrate @ 10499]
updates from Mike Stoddard of Novell
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 03 Aug 2004 23:22:48 +0000 |
parents | c001be3c330e |
children | 9c9932c9cd09 |
comparison
equal
deleted
inserted
replaced
9650:780a8fbeb85b | 9651:8ce2dc65e591 |
---|---|
32 #include "privacy.h" | 32 #include "privacy.h" |
33 #include "multi.h" | 33 #include "multi.h" |
34 | 34 |
35 #define DEFAULT_PORT 8300 | 35 #define DEFAULT_PORT 8300 |
36 #define NOVELL_CONNECT_STEPS 4 | 36 #define NOVELL_CONNECT_STEPS 4 |
37 #define NM_ROOT_FOLDER_NAME "GroupWise Messenger" | |
37 | 38 |
38 static GaimPlugin *my_protocol = NULL; | 39 static GaimPlugin *my_protocol = NULL; |
39 | 40 |
40 static gboolean | 41 static gboolean |
41 _is_disconnect_error(NMERR_T err); | 42 _is_disconnect_error(NMERR_T err); |
318 folder = nm_find_folder_by_id(user, | 319 folder = nm_find_folder_by_id(user, |
319 nm_contact_get_parent_id(new_contact)); | 320 nm_contact_get_parent_id(new_contact)); |
320 if (folder) { | 321 if (folder) { |
321 folder_name = nm_folder_get_name(folder); | 322 folder_name = nm_folder_get_name(folder); |
322 } | 323 } |
324 | |
325 if (*folder_name == '\0') | |
326 folder_name = NM_ROOT_FOLDER_NAME; | |
323 | 327 |
324 /* Re-add the buddy now that we got the okay from the server */ | 328 /* Re-add the buddy now that we got the okay from the server */ |
325 if (folder_name && (group = gaim_find_group(folder_name))) { | 329 if (folder_name && (group = gaim_find_group(folder_name))) { |
326 | 330 |
327 const char *alias = nm_contact_get_display_name(tmp_contact); | 331 const char *alias = nm_contact_get_display_name(tmp_contact); |
1185 GaimBuddy *buddy; | 1189 GaimBuddy *buddy; |
1186 GaimBuddyList *blist; | 1190 GaimBuddyList *blist; |
1187 GSList *rem_list = NULL; | 1191 GSList *rem_list = NULL; |
1188 GSList *l; | 1192 GSList *l; |
1189 NMFolder *folder = NULL; | 1193 NMFolder *folder = NULL; |
1194 const char *gname = NULL; | |
1190 | 1195 |
1191 if ((blist = gaim_get_blist())) { | 1196 if ((blist = gaim_get_blist())) { |
1192 for (gnode = blist->root; gnode; gnode = gnode->next) { | 1197 for (gnode = blist->root; gnode; gnode = gnode->next) { |
1193 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | 1198 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
1194 continue; | 1199 continue; |
1199 for (bnode = cnode->child; bnode; bnode = bnode->next) { | 1204 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1200 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | 1205 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
1201 continue; | 1206 continue; |
1202 buddy = (GaimBuddy *) bnode; | 1207 buddy = (GaimBuddy *) bnode; |
1203 if (buddy->account == user->client_data) { | 1208 if (buddy->account == user->client_data) { |
1204 folder = nm_find_folder(user, group->name); | 1209 gname = group->name; |
1210 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) | |
1211 gname = ""; | |
1212 folder = nm_find_folder(user, gname); | |
1205 if (folder == NULL || | 1213 if (folder == NULL || |
1206 !nm_folder_find_contact_by_display_id(folder, buddy->name)) { | 1214 !nm_folder_find_contact_by_display_id(folder, buddy->name)) { |
1207 rem_list = g_slist_append(rem_list, buddy); | 1215 rem_list = g_slist_append(rem_list, buddy); |
1208 } | 1216 } |
1209 } | 1217 } |
1229 GaimBuddy *buddy = NULL; | 1237 GaimBuddy *buddy = NULL; |
1230 GaimGroup *group; | 1238 GaimGroup *group; |
1231 NMERR_T cnt = 0, i; | 1239 NMERR_T cnt = 0, i; |
1232 const char *text = NULL; | 1240 const char *text = NULL; |
1233 const char *name = NULL; | 1241 const char *name = NULL; |
1242 const char *fname = NULL; | |
1234 int status = 0; | 1243 int status = 0; |
1235 | 1244 |
1245 /* If this is the root folder give it a name. Gaim does not have the concept of | |
1246 * a root folder. | |
1247 */ | |
1248 fname = nm_folder_get_name(folder); | |
1249 if (fname == NULL || *fname == '\0') { | |
1250 fname = NM_ROOT_FOLDER_NAME; | |
1251 } | |
1252 | |
1236 /* Does the Gaim group exist already? */ | 1253 /* Does the Gaim group exist already? */ |
1237 group = gaim_find_group(nm_folder_get_name(folder)); | 1254 group = gaim_find_group(fname); |
1238 | |
1239 if (group == NULL) { | 1255 if (group == NULL) { |
1240 group = gaim_group_new(nm_folder_get_name(folder)); | 1256 group = gaim_group_new(fname); |
1241 gaim_blist_add_group(group, NULL); | 1257 gaim_blist_add_group(group, NULL); |
1242 } | 1258 } |
1243 | 1259 |
1244 /* Get each contact for this folder */ | 1260 /* Get each contact for this folder */ |
1245 cnt = nm_folder_get_contact_count(folder); | 1261 cnt = nm_folder_get_contact_count(folder); |
1283 | 1299 |
1284 /* Add all of the server side contacts to the Gaim buddy list. */ | 1300 /* Add all of the server side contacts to the Gaim buddy list. */ |
1285 static void | 1301 static void |
1286 _add_gaim_buddies(NMUser * user) | 1302 _add_gaim_buddies(NMUser * user) |
1287 { | 1303 { |
1288 NMERR_T cnt = 0, i; | 1304 int cnt = 0, i; |
1289 NMFolder *root_folder = NULL; | 1305 NMFolder *root_folder = NULL; |
1290 NMFolder *folder = NULL; | 1306 NMFolder *folder = NULL; |
1291 | 1307 |
1292 root_folder = nm_get_root_folder(user); | 1308 root_folder = nm_get_root_folder(user); |
1293 if (root_folder) { | 1309 if (root_folder) { |
1294 | 1310 |
1295 /* Add contacts for the sub folders */ | 1311 /* Add sub-folders and contacts to sub-folders... |
1312 * iterate throught the sub-folders in reverse order | |
1313 * because Gaim adds the folders to the front -- so we | |
1314 * want to add the first folder last | |
1315 */ | |
1296 cnt = nm_folder_get_subfolder_count(root_folder); | 1316 cnt = nm_folder_get_subfolder_count(root_folder); |
1297 for (i = 0; i < cnt; i++) { | 1317 for (i = cnt-1; i >= 0; i--) { |
1298 folder = nm_folder_get_subfolder(root_folder, i); | 1318 folder = nm_folder_get_subfolder(root_folder, i); |
1299 if (folder) { | 1319 if (folder) { |
1300 _add_contacts_to_gaim_blist(user, folder); | 1320 _add_contacts_to_gaim_blist(user, folder); |
1301 } | 1321 } |
1302 } | 1322 } |
2123 return; | 2143 return; |
2124 | 2144 |
2125 user = gc->proto_data; | 2145 user = gc->proto_data; |
2126 if (user) { | 2146 if (user) { |
2127 conn = user->conn; | 2147 conn = user->conn; |
2128 if (conn) { | 2148 if (conn && conn->ssl_conn) { |
2129 if (conn->use_ssl && user->conn->ssl_conn) { | 2149 gaim_ssl_close(user->conn->ssl_conn->data); |
2130 gaim_ssl_close(user->conn->ssl_conn->data); | |
2131 } else { | |
2132 gaim_input_remove(gc->inpa); | |
2133 close(conn->fd); | |
2134 } | |
2135 } | 2150 } |
2136 nm_deinitialize_user(user); | 2151 nm_deinitialize_user(user); |
2137 } | 2152 } |
2138 gc->proto_data = NULL; | 2153 gc->proto_data = NULL; |
2139 } | 2154 } |
2433 { | 2448 { |
2434 NMFolder *folder = NULL; | 2449 NMFolder *folder = NULL; |
2435 NMContact *contact; | 2450 NMContact *contact; |
2436 NMUser *user; | 2451 NMUser *user; |
2437 NMERR_T rc = NM_OK; | 2452 NMERR_T rc = NM_OK; |
2438 const char *alias; | 2453 const char *alias, *gname; |
2439 | 2454 |
2440 if (gc == NULL || buddy == NULL || group == NULL) | 2455 if (gc == NULL || buddy == NULL || group == NULL) |
2441 return; | 2456 return; |
2442 | 2457 |
2443 user = (NMUser *) gc->proto_data; | 2458 user = (NMUser *) gc->proto_data; |
2461 nm_contact_set_display_name(contact, alias); | 2476 nm_contact_set_display_name(contact, alias); |
2462 | 2477 |
2463 gaim_blist_remove_buddy(buddy); | 2478 gaim_blist_remove_buddy(buddy); |
2464 buddy = NULL; | 2479 buddy = NULL; |
2465 | 2480 |
2466 folder = nm_find_folder(user, group->name); | 2481 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) { |
2482 gname = ""; | |
2483 } else { | |
2484 gname = group->name; | |
2485 } | |
2486 | |
2487 folder = nm_find_folder(user, gname); | |
2467 if (folder) { | 2488 if (folder) { |
2468 | 2489 |
2469 /* We have everything that we need, so send the createcontact */ | 2490 /* We have everything that we need, so send the createcontact */ |
2470 rc = nm_send_create_contact(user, folder, contact, | 2491 rc = nm_send_create_contact(user, folder, contact, |
2471 _create_contact_resp_cb, contact); | 2492 _create_contact_resp_cb, contact); |
2472 | 2493 |
2473 } else { | 2494 } else { |
2474 | 2495 |
2475 /* Need to create the folder before we can add the contact */ | 2496 /* Need to create the folder before we can add the contact */ |
2476 rc = nm_send_create_folder(user, group->name, | 2497 rc = nm_send_create_folder(user, gname, |
2477 _create_folder_resp_add_contact, contact); | 2498 _create_folder_resp_add_contact, contact); |
2478 } | 2499 } |
2479 | 2500 |
2480 _check_for_disconnect(user, rc); | 2501 _check_for_disconnect(user, rc); |
2481 | 2502 |
2485 novell_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | 2506 novell_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
2486 { | 2507 { |
2487 NMContact *contact; | 2508 NMContact *contact; |
2488 NMFolder *folder; | 2509 NMFolder *folder; |
2489 NMUser *user; | 2510 NMUser *user; |
2490 const char *dn; | 2511 const char *dn, *gname; |
2491 NMERR_T rc = NM_OK; | 2512 NMERR_T rc = NM_OK; |
2492 | 2513 |
2493 if (gc == NULL || buddy == NULL || group == NULL) | 2514 if (gc == NULL || buddy == NULL || group == NULL) |
2494 return; | 2515 return; |
2495 | 2516 |
2496 user = (NMUser *) gc->proto_data; | 2517 user = (NMUser *) gc->proto_data; |
2497 if (user && (dn = nm_lookup_dn(user, buddy->name))) { | 2518 if (user && (dn = nm_lookup_dn(user, buddy->name))) { |
2498 folder = nm_find_folder(user, group->name); | 2519 if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) { |
2520 gname = ""; | |
2521 } else { | |
2522 gname = group->name; | |
2523 } | |
2524 folder = nm_find_folder(user, gname); | |
2499 if (folder) { | 2525 if (folder) { |
2500 contact = nm_folder_find_contact(folder, dn); | 2526 contact = nm_folder_find_contact(folder, dn); |
2501 if (contact) { | 2527 if (contact) { |
2502 | 2528 |
2503 /* Remove the buddy from the contact */ | 2529 /* Remove the buddy from the contact */ |
2538 { | 2564 { |
2539 NMContact *contact; | 2565 NMContact *contact; |
2540 NMUser *user; | 2566 NMUser *user; |
2541 GList *contacts = NULL; | 2567 GList *contacts = NULL; |
2542 GList *cnode = NULL; | 2568 GList *cnode = NULL; |
2543 const char *dn = NULL; | 2569 const char *dn = NULL, *fname = NULL; |
2544 NMERR_T rc = NM_OK; | 2570 NMERR_T rc = NM_OK; |
2545 | 2571 |
2546 if (gc == NULL || name == NULL || alias == NULL) | 2572 if (gc == NULL || name == NULL || alias == NULL) |
2547 return; | 2573 return; |
2548 | 2574 |
2552 /* Alias all of instances of the contact */ | 2578 /* Alias all of instances of the contact */ |
2553 contacts = nm_find_contacts(user, dn); | 2579 contacts = nm_find_contacts(user, dn); |
2554 for (cnode = contacts; cnode != NULL; cnode = cnode->next) { | 2580 for (cnode = contacts; cnode != NULL; cnode = cnode->next) { |
2555 contact = (NMContact *) cnode->data; | 2581 contact = (NMContact *) cnode->data; |
2556 if (contact) { | 2582 if (contact) { |
2557 GaimGroup *group; | 2583 GaimGroup *group = NULL; |
2558 GaimBuddy *buddy; | 2584 GaimBuddy *buddy; |
2559 NMFolder *folder; | 2585 NMFolder *folder; |
2560 | 2586 |
2561 /* Alias the Gaim buddy? */ | 2587 /* Alias the Gaim buddy? */ |
2562 folder = nm_find_folder_by_id(user, | 2588 folder = nm_find_folder_by_id(user, |
2563 nm_contact_get_parent_id(contact)); | 2589 nm_contact_get_parent_id(contact)); |
2564 if (folder && | 2590 if (folder) { |
2565 (group = gaim_find_group(nm_folder_get_name(folder)))) { | 2591 fname = nm_folder_get_name(folder); |
2592 if (*fname == '\0') { | |
2593 fname = NM_ROOT_FOLDER_NAME; | |
2594 } | |
2595 group = gaim_find_group(fname); | |
2596 } | |
2597 | |
2598 if (group) { | |
2566 buddy = gaim_find_buddy_in_group(user->client_data, | 2599 buddy = gaim_find_buddy_in_group(user->client_data, |
2567 name, group); | 2600 name, group); |
2568 if (buddy && strcmp(buddy->alias, alias)) | 2601 if (buddy && strcmp(buddy->alias, alias)) |
2569 gaim_blist_alias_buddy(buddy, alias); | 2602 gaim_blist_alias_buddy(buddy, alias); |
2570 | |
2571 } | 2603 } |
2604 | |
2572 /* Tell the server to alias the contact */ | 2605 /* Tell the server to alias the contact */ |
2573 rc = nm_send_rename_contact(user, contact, alias, | 2606 rc = nm_send_rename_contact(user, contact, alias, |
2574 _rename_contact_resp_cb, NULL); | 2607 _rename_contact_resp_cb, NULL); |
2575 _check_for_disconnect(user, rc); | 2608 _check_for_disconnect(user, rc); |
2576 } | 2609 } |
2598 | 2631 |
2599 user = (NMUser *) gc->proto_data; | 2632 user = (NMUser *) gc->proto_data; |
2600 if (user && (dn = nm_lookup_dn(user, name))) { | 2633 if (user && (dn = nm_lookup_dn(user, name))) { |
2601 | 2634 |
2602 /* Find the old folder */ | 2635 /* Find the old folder */ |
2603 old_folder = nm_find_folder(user, old_group_name); | 2636 if (strcmp(old_group_name, NM_ROOT_FOLDER_NAME) == 0) { |
2637 old_folder = nm_get_root_folder(user); | |
2638 if (nm_folder_find_contact(old_folder, dn) == NULL) | |
2639 old_folder = nm_find_folder(user, old_group_name); | |
2640 } else { | |
2641 old_folder = nm_find_folder(user, old_group_name); | |
2642 } | |
2643 | |
2604 if (old_folder && (contact = nm_folder_find_contact(old_folder, dn))) { | 2644 if (old_folder && (contact = nm_folder_find_contact(old_folder, dn))) { |
2605 | 2645 |
2606 /* Find the new folder */ | 2646 /* Find the new folder */ |
2607 new_folder = nm_find_folder(user, new_group_name); | 2647 new_folder = nm_find_folder(user, new_group_name); |
2648 if (new_folder == NULL) { | |
2649 if (strcmp(new_group_name, NM_ROOT_FOLDER_NAME) == 0) | |
2650 new_folder = nm_get_root_folder(user); | |
2651 } | |
2652 | |
2608 if (new_folder) { | 2653 if (new_folder) { |
2609 | 2654 |
2610 /* Tell the server to move the contact to the new folder */ | 2655 /* Tell the server to move the contact to the new folder */ |
2611 rc = nm_send_move_contact(user, contact, new_folder, | 2656 rc = nm_send_move_contact(user, contact, new_folder, |
2612 _move_contact_resp_cb, NULL); | 2657 _move_contact_resp_cb, NULL); |
2644 | 2689 |
2645 user = gc->proto_data; | 2690 user = gc->proto_data; |
2646 if (user) { | 2691 if (user) { |
2647 /* Does new folder exist already? */ | 2692 /* Does new folder exist already? */ |
2648 if (nm_find_folder(user, group->name)) { | 2693 if (nm_find_folder(user, group->name)) { |
2649 /* Gaim currently calls novell_group_buddy() | 2694 /* gaim_blist_rename_group() adds the buddies |
2650 * for all buddies in the group, so we don't | 2695 * to the new group and removes the old group... |
2651 * need to worry about this situation. | 2696 * so there is nothing more to do here. |
2652 */ | 2697 */ |
2653 return; | 2698 return; |
2654 } | 2699 } |
2655 | 2700 |
2701 if (strcmp(old_name, NM_ROOT_FOLDER_NAME) == 0) { | |
2702 /* Can't rename the root folder ... need to revisit this */ | |
2703 return; | |
2704 } | |
2705 | |
2656 folder = nm_find_folder(user, old_name); | 2706 folder = nm_find_folder(user, old_name); |
2657 | |
2658 if (folder) { | 2707 if (folder) { |
2659 rc = nm_send_rename_folder(user, folder, group->name, | 2708 rc = nm_send_rename_folder(user, folder, group->name, |
2660 _rename_folder_resp_cb, NULL); | 2709 _rename_folder_resp_cb, NULL); |
2661 _check_for_disconnect(user, rc); | 2710 _check_for_disconnect(user, rc); |
2662 } | 2711 } |