Mercurial > pidgin.yaz
changeset 1713:14caa7df478c
[gaim-migrate @ 1723]
fun stuff
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 13 Apr 2001 23:18:02 +0000 |
parents | 560b3117aedf |
children | 8987160e446b |
files | TODO plugins/jabber/jabber.c src/buddy.c src/prpl.h |
diffstat | 4 files changed, 72 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO Fri Apr 13 17:47:06 2001 +0000 +++ b/TODO Fri Apr 13 23:18:02 2001 +0000 @@ -64,18 +64,3 @@ and the Feature Requests. SourceForge should really allow users to vote on feature requests and bugs..... http://sourceforge.net/tracker/?atid=350235&group_id=235&func=browse - ----------- - This is how buddy lists should work. This needs to be added to struct - prpl: - char *(*normalize)(char *) - This is mostly for Jabber/MSN. E.g. for Jabber, passing "warmenhoven" - gets you "warmenhoven@jabber.org", passing "warmenhoven@jabber.org/GAIM" - gets you "warmenhoven@jabber.org". For AIM, "EWarmenhoven" returns - "ewarmenhoven" and "Rob Flynn" returns "robflynn" (i.e. the names are - normalized). Then finding buddies (in your buddy list and such) should - work based off of that. Adding buddies similarly, you get the real name - before you complete the adding process. Returning NULL will be for an - invalid name (such as a non-numeric name in ICQ). It will also be handy - in IRC for removing the @ and + from the front of ops and those with +V - status.
--- a/plugins/jabber/jabber.c Fri Apr 13 17:47:06 2001 +0000 +++ b/plugins/jabber/jabber.c Fri Apr 13 23:18:02 2001 +0000 @@ -1354,6 +1354,35 @@ reginpa = gdk_input_add(jab_getfd(regjconn), GDK_INPUT_READ, regjcall, NULL); } +static char *jabber_normalize(const char *s) +{ + static char buf[BUF_LEN]; + char *t, *u; + int x = 0; + + g_return_val_if_fail((s != NULL), NULL); + + u = t = g_strdup(s); + + g_strdown(t); + + while (*t && (x < BUF_LEN - 1)) { + if (*t != ' ') + buf[x++] = *t; + t++; + } + buf[x] = '\0'; + g_free(u); + + if (!strchr(buf, '@')) { + strcat(buf, "@jabber.org"); /* this isn't always right, but eh */ + } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { + *u = '\0'; + } + + return buf; +} + static struct prpl *my_protocol = NULL; void Jabber_init(struct prpl *ret) @@ -1394,6 +1423,7 @@ ret->chat_whisper = NULL; ret->chat_send = jabber_chat_send; ret->keepalive = NULL; + ret->normalize = jabber_normalize; my_protocol = ret; }
--- a/src/buddy.c Fri Apr 13 17:47:06 2001 +0000 +++ b/src/buddy.c Fri Apr 13 23:18:02 2001 +0000 @@ -1041,6 +1041,7 @@ struct buddy *b; struct group *g; struct group_show *gs = find_group_show(group); + char *good; if ((b = find_buddy(gc, buddy)) != NULL) return b; @@ -1059,8 +1060,13 @@ b->gc = gc; b->present = 0; - g_snprintf(b->name, sizeof(b->name), "%s", buddy); - g_snprintf(b->show, sizeof(b->show), "%s", show ? (show[0] ? show : buddy) : buddy); + if (gc->prpl->normalize) + good = (*gc->prpl->normalize)(buddy); + else + good = buddy; + + g_snprintf(b->name, sizeof(b->name), "%s", good); + g_snprintf(b->show, sizeof(b->show), "%s", show ? (show[0] ? show : good) : good); g->members = g_slist_append(g->members, b); @@ -1348,11 +1354,15 @@ struct buddy *b; GSList *grp; GSList *mem; - char *whoname = g_malloc(strlen(who) + 1); - - strcpy(whoname, normalize(who)); - + char *whoname; + char *(*norm)(const char *); + if (gc) { + if (gc->prpl->normalize) + norm = gc->prpl->normalize; + else + norm = normalize; + whoname = g_strdup((*norm)(who)); grp = gc->groups; while(grp) { g = (struct group *)grp->data; @@ -1360,7 +1370,7 @@ mem = g->members; while(mem) { b = (struct buddy *)mem->data; - if (!strcasecmp(normalize(b->name), whoname)) { + if (!strcmp((*norm)(b->name), whoname)) { g_free(whoname); return g; } @@ -1375,6 +1385,11 @@ struct gaim_connection *z; while (c) { z = (struct gaim_connection *)c->data; + if (z->prpl->normalize) + norm = z->prpl->normalize; + else + norm = normalize; + whoname = g_strdup((*norm)(who)); grp = z->groups; while(grp) { g = (struct group *)grp->data; @@ -1382,7 +1397,7 @@ mem = g->members; while(mem) { b = (struct buddy *)mem->data; - if (!strcasecmp(normalize(b->name), whoname)) { + if (!strcmp((*norm)(b->name), whoname)) { g_free(whoname); return g; } @@ -1391,8 +1406,8 @@ grp = g_slist_next(grp); } c = c->next; + g_free(whoname); } - g_free(whoname); return NULL; } } @@ -1406,10 +1421,15 @@ GSList *c; struct gaim_connection *z; GSList *mem; - char *whoname = g_malloc(strlen(who) + 1); - - strcpy(whoname, normalize(who)); + char *whoname; + char *(*norm)(const char *); + if (gc) { + if (gc->prpl->normalize) + norm = gc->prpl->normalize; + else + norm = normalize; + whoname = g_strdup((*norm)(who)); grp = gc->groups; while(grp) { g = (struct group *)grp->data; @@ -1417,7 +1437,7 @@ mem = g->members; while(mem) { b = (struct buddy *)mem->data; - if (!strcasecmp(normalize(b->name), whoname)) { + if (!strcmp((*norm)(b->name), whoname)) { g_free(whoname); return b; } @@ -1431,6 +1451,11 @@ c = connections; while (c) { z = (struct gaim_connection *)c->data; + if (z->prpl->normalize) + norm = z->prpl->normalize; + else + norm = normalize; + whoname = g_strdup((*norm)(who)); grp = z->groups; while(grp) { g = (struct group *)grp->data; @@ -1438,7 +1463,7 @@ mem = g->members; while(mem) { b = (struct buddy *)mem->data; - if (!strcasecmp(normalize(b->name), whoname)) { + if (!strcmp((*norm)(b->name), whoname)) { g_free(whoname); return b; } @@ -1447,8 +1472,8 @@ grp = g_slist_next(grp); } c = c->next; + g_free(whoname); } - g_free(whoname); return NULL; } }
--- a/src/prpl.h Fri Apr 13 17:47:06 2001 +0000 +++ b/src/prpl.h Fri Apr 13 23:18:02 2001 +0000 @@ -38,7 +38,6 @@ #define OPT_PROTO_HTML 0x00000001 #define OPT_PROTO_CORRECT_TIME 0x00000002 -#define OPT_PROTO_NORMALIZE 0x00000004 /* there should be more here eventually... These should all be stuff that other * plugins can't do (for example, TOC and Oscar and Jabber can do HTML in messages, * but IRC etc can't, so TOC/Oscar/Jabber have _HTML set but not IRC. */ @@ -108,6 +107,8 @@ void (* chat_whisper) (struct gaim_connection *, int id, char *who, char *message); void (* chat_send) (struct gaim_connection *, int id, char *message); void (* keepalive) (struct gaim_connection *); + + char *(* normalize)(const char *); }; extern GSList *protocols;