comparison src/protocols/jabber/jabber.c @ 3349:000546860da7

[gaim-migrate @ 3368] Group rename synchronized on server roster. committer: Tailor Script <tailor@pidgin.im>
author Jim Seymour <jseymour>
date Sun, 07 Jul 2002 14:34:41 +0000
parents f56b36347375
children 8fa61405af2b
comparison
equal deleted inserted replaced
3348:dd34e0b40fed 3349:000546860da7
2274 return 1; 2274 return 1;
2275 } 2275 }
2276 2276
2277 /* 2277 /*
2278 * Add/update buddy's roster entry on server 2278 * Add/update buddy's roster entry on server
2279 */ 2279 *
2280 static void jabber_roster_update(struct gaim_connection *gc, char *name) 2280 * If "alias" or "group" are NULL, gets them from Gaim's current buddylist values
2281 * for the buddy.
2282 */
2283 static void jabber_roster_update(struct gaim_connection *gc, char *name, char *alias, char *group)
2281 { 2284 {
2282 xmlnode x, y; 2285 xmlnode x, y;
2283 char *realwho; 2286 char *realwho;
2284 gjconn gjc; 2287 gjconn gjc;
2285 struct buddy *buddy = NULL; 2288 struct buddy *buddy = NULL;
2286 struct group *buddy_group = NULL; 2289 struct group *buddy_group = NULL;
2290 char *my_alias = NULL;
2291 char *my_group = NULL;
2287 2292
2288 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) { 2293 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) {
2289 gaim_jid gjid; 2294 gaim_jid gjid;
2290 gjc = ((struct jabber_data *)gc->proto_data)->gjc; 2295 gjc = ((struct jabber_data *)gc->proto_data)->gjc;
2291 2296
2302 2307
2303 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); 2308 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
2304 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); 2309 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
2305 xmlnode_put_attrib(y, "jid", realwho); 2310 xmlnode_put_attrib(y, "jid", realwho);
2306 2311
2307 2312 /*
2308 /* If we can find the buddy, there's an alias for him, it's not 0-length 2313 * See if there's an explict (new?) alias for the buddy or we can pull
2314 * one out of current Gaim buddylist data for him.
2315 */
2316 if(alias && alias[0] != '\0') {
2317 my_alias = alias;
2318 } else if((buddy = find_buddy(gc, realwho)) != NULL) {
2319 my_alias = buddy->show;
2320 }
2321
2322 /* If there's an alias for the buddy, it's not 0-length
2309 * and it doesn't match his JID, add the "name" attribute. 2323 * and it doesn't match his JID, add the "name" attribute.
2310 */ 2324 */
2311 if((buddy = find_buddy(gc, realwho)) != NULL && 2325 if(my_alias != NULL && my_alias[0] != '\0' && strcmp(realwho, my_alias))
2312 buddy->show != NULL && buddy->show[0] != '\0' && strcmp(realwho, buddy->show))
2313 { 2326 {
2314 char *utf8 = str_to_utf8(buddy->show); 2327 char *utf8 = str_to_utf8(my_alias);
2315 xmlnode_put_attrib(y, "name", utf8); 2328 xmlnode_put_attrib(y, "name", utf8);
2316 g_free(utf8); 2329 g_free(utf8);
2317 } 2330 }
2318 2331
2319 /* 2332 /*
2320 * Find out what group the buddy's in and send that along 2333 * See if there's an explict (new?) group for the buddy or pull
2321 * with the roster item. 2334 * one out of current Gaim buddylist data for him.
2322 */ 2335 */
2323 if((buddy_group = find_group_by_buddy(gc, realwho)) != NULL) { 2336 if(group && group[0] != '\0') {
2324 xmlnode z; 2337 my_group = group;
2325 z = xmlnode_insert_tag(y, "group"); 2338 } else if((buddy_group = find_group_by_buddy(gc, realwho)) != NULL) {
2326 xmlnode_insert_cdata(z, buddy_group->name, -1); 2339 my_group = buddy_group->name;
2340 }
2341
2342 /*
2343 * Send what group the buddy's in along with the roster item.
2344 */
2345 if(my_group != NULL && my_group[0] != '\0') {
2346 xmlnode z = xmlnode_insert_tag(y, "group");
2347 xmlnode_insert_cdata(z, my_group, -1);
2327 } 2348 }
2328 2349
2329 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); 2350 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2330 2351
2331 xmlnode_free(x); 2352 xmlnode_free(x);
2332 g_free(realwho); 2353 g_free(realwho);
2333 } 2354 }
2334 } 2355 }
2335 2356
2336 /* 2357 /*
2358 * Add/update buddy's alias on server
2359 *
2360 * This is just a roster update using existing, local buddylist data
2361 */
2362 static void jabber_alias_buddy(struct gaim_connection *gc, char *name)
2363 {
2364 jabber_roster_update(gc, name, NULL, NULL);
2365 }
2366
2367 /*
2337 * Change buddy's group on server roster 2368 * Change buddy's group on server roster
2338 */ 2369 */
2339 static void jabber_group_change(struct gaim_connection *gc, char *name, char *old_group, char *new_group) 2370 static void jabber_group_change(struct gaim_connection *gc, char *name, char *old_group, char *new_group)
2340 { 2371 {
2341 if(strcmp(old_group, new_group)) { 2372 if(old_group && new_group && strcmp(old_group, new_group))
2342 jabber_roster_update(gc, name); 2373 jabber_roster_update(gc, name, NULL, new_group);
2343 } 2374 }
2375
2376 /*
2377 * Group rename
2378 *
2379 * Jabber doesn't have "groups," per se. "Group" is simply a JID attribute.
2380 * So we iterate through the list of buddies that are in the group and change
2381 * the group attribute for each of them.
2382 */
2383 static void jabber_rename_group(struct gaim_connection *gc,
2384 char *old_group,
2385 char *new_group,
2386 GList *members)
2387 {
2388 if(old_group && new_group && strcmp(old_group, new_group))
2389 while(members) {
2390 jabber_group_change(gc, (char *)(members->data), old_group, new_group);
2391 members = members->next;
2392 }
2344 } 2393 }
2345 2394
2346 static void jabber_add_buddy(struct gaim_connection *gc, char *name) 2395 static void jabber_add_buddy(struct gaim_connection *gc, char *name)
2347 { 2396 {
2348 xmlnode x; 2397 xmlnode x;
2379 xmlnode_put_attrib(x, "to", realwho); 2428 xmlnode_put_attrib(x, "to", realwho);
2380 xmlnode_put_attrib(x, "type", "subscribe"); 2429 xmlnode_put_attrib(x, "type", "subscribe");
2381 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); 2430 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2382 xmlnode_free(x); 2431 xmlnode_free(x);
2383 2432
2384 jabber_roster_update(gc, realwho); 2433 jabber_roster_update(gc, realwho, NULL, NULL);
2385 2434
2386 g_free(realwho); 2435 g_free(realwho);
2387 } 2436 }
2388 2437
2389 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group) 2438 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group)
3963 ret->chat_whisper = jabber_chat_whisper; 4012 ret->chat_whisper = jabber_chat_whisper;
3964 ret->chat_send = jabber_chat_send; 4013 ret->chat_send = jabber_chat_send;
3965 ret->keepalive = jabber_keepalive; 4014 ret->keepalive = jabber_keepalive;
3966 ret->normalize = jabber_normalize; 4015 ret->normalize = jabber_normalize;
3967 ret->register_user = jabber_register_user; 4016 ret->register_user = jabber_register_user;
3968 ret->alias_buddy = jabber_roster_update; 4017 ret->alias_buddy = jabber_alias_buddy;
3969 ret->group_buddy = jabber_group_change; 4018 ret->group_buddy = jabber_group_change;
3970 ret->send_typing = jabber_send_typing; 4019 ret->send_typing = jabber_send_typing;
3971 ret->convo_closed = jabber_convo_closed; 4020 ret->convo_closed = jabber_convo_closed;
4021 ret->rename_group = jabber_rename_group;
3972 4022
3973 my_protocol = ret; 4023 my_protocol = ret;
3974 } 4024 }
3975 4025
3976 #ifndef STATIC 4026 #ifndef STATIC