Yo.
gtk1-stable
v0_59_9
2003-03-01, Sean Egan
* Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA void remove_buddy(struct gaim_connection *gc, struct group *rem_g, struct buddy *rem_b) /* we assume that gc is not NULL and that the buddy exists somewhere within the * gc's buddy list, therefore we can safely remove it. we need to ensure this grp = g_slist_find(gc->groups, rem_g); delg = (struct group *)grp->data; mem = g_slist_find(mem, rem_b); delb = (struct buddy *)mem->data; delg->members = g_slist_remove(delg->members, delb); ui_remove_buddy(gc, rem_g, rem_b); /* we don't flush buddy list to cache because in the case of remove_group that would * mean writing to the buddy list file once for each buddy, plus one more time */ void remove_group(struct gaim_connection *gc, struct group *rem_g) /* we assume that the group actually does exist within the gc, and that the gc is not NULL. * the UI is responsible for this */ grp = g_slist_find(gc->groups, rem_g); delg = (struct group *)grp->data; delb = (struct buddy *)delg->members->data; tmp = g_list_append(tmp, g_strdup(delb->name)); remove_buddy(gc, delg, delb); /* this should take care of removing the group_show if necessary */ gc->groups = g_slist_remove(gc->groups, delg); serv_remove_buddies(gc, tmp, rem_g->name); tmp = g_list_remove(tmp, tmp->data); ui_remove_group(gc, rem_g); /* don't flush buddy list to cache in order to be consistent with remove_buddy, * mostly. remove_group is only called from one place, so we'll let it handle it. */ struct buddy *add_buddy(struct gaim_connection *gc, char *group, char *buddy, char *show) if (!g_slist_find(connections, gc)) if ((b = find_buddy(gc, buddy)) != NULL) g = find_group(gc, group); g = add_group(gc, group); b = (struct buddy *)g_new0(struct buddy, 1); good = gc->prpl->normalize(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); struct group *add_group(struct gaim_connection *gc, char *group) struct group *g = find_group(gc, group); if (!g_slist_find(connections, gc)) g = (struct group *)g_new0(struct group, 1); strncpy(g->name, group, sizeof(g->name)); gc->groups = g_slist_append(gc->groups, g); struct group *find_group(struct gaim_connection *gc, char *group) struct gaim_connection *z; char *grpname = g_malloc(strlen(group) + 1); strcpy(grpname, normalize (group)); if (!g_slist_find(connections, gc)) g = (struct group *)grp->data; if (!g_strcasecmp(normalize (g->name), grpname)) { z = (struct gaim_connection *)c->data; g = (struct group *)grp->data; if (!g_strcasecmp(normalize (g->name), grpname)) { struct group *find_group_by_buddy(struct gaim_connection *gc, char *who) char *(*norm)(const char *); norm = gc->prpl->normalize; whoname = g_strdup(norm(who)); g = (struct group *)grp->data; b = (struct buddy *)mem->data; if (!strcmp(norm(b->name), whoname)) { struct gaim_connection *z; z = (struct gaim_connection *)c->data; norm = z->prpl->normalize; whoname = g_strdup(norm(who)); g = (struct group *)grp->data; b = (struct buddy *)mem->data; if (!strcmp(norm(b->name), whoname)) { struct buddy *find_buddy(struct gaim_connection *gc, char *who) struct gaim_connection *z; char *(*norm)(const char *); if (!g_slist_find(connections, gc)) norm = gc->prpl->normalize; whoname = g_strdup(norm(who)); g = (struct group *)grp->data; b = (struct buddy *)mem->data; if (!strcmp(norm(b->name), whoname)) { z = (struct gaim_connection *)c->data; norm = z->prpl->normalize; whoname = g_strdup(norm(who)); g = (struct group *)grp->data; b = (struct buddy *)mem->data; if (!strcmp(norm(b->name), whoname)) { void parse_toc_buddy_list(struct gaim_connection *gc, char *config) /* skip "CONFIG:" (if it exists) */ c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); strncpy(current, c + 2, sizeof(current)); if (!find_group(gc, current)) { } else if (*c == 'b' && !find_buddy(gc, c + 2)) { char nm[80], sw[BUDDY_ALIAS_MAXLEN], *tmp = c + 2; while (*tmp != ':' && *tmp && i < sizeof(nm) - 1) while (*tmp != ':' && *tmp) while (*tmp && i < sizeof(sw) - 1) if (!find_buddy(gc, nm)) { add_buddy(gc, current, nm, sw); bud = g_list_append(bud, c + 2); name = g_malloc(strlen(c + 2) + 2); g_snprintf(name, strlen(c + 2) + 1, "%s", c + 2); n = g_strdup(normalize (name)); if (!g_strcasecmp(n, normalize (d->data))) gc->permit = g_slist_append(gc->permit, name); name = g_malloc(strlen(c + 2) + 2); g_snprintf(name, strlen(c + 2) + 1, "%s", c + 2); n = g_strdup(normalize (name)); if (!g_strcasecmp(n, normalize (d->data))) gc->deny = g_slist_append(gc->deny, name); } else if (!strncmp("toc", c, 3)) { sscanf(c + strlen(c) - 1, "%d", &gc->permdeny); debug_printf("permdeny: %d\n", gc->permdeny); sscanf(c + 2, "%d", &gc->permdeny); debug_printf("permdeny: %d\n", gc->permdeny); } while ((c = strtok(NULL, "\n"))); serv_add_buddies(gc, bud); serv_set_permit_deny(gc); void toc_build_config(struct gaim_connection *gc, char *s, int len, gboolean show) GSList *grp = gc->groups; GSList *plist = gc->permit; GSList *dlist = gc->deny; pos += g_snprintf(&s[pos], len - pos, "m %d\n", gc->permdeny); while (len > pos && grp) { g = (struct group *)grp->data; pos += g_snprintf(&s[pos], len - pos, "g %s\n", g->name); while (len > pos && mem) { b = (struct buddy *)mem->data; pos += g_snprintf(&s[pos], len - pos, "b %s%s%s\n", b->name, (show && strcmp(b->name, b->show)) ? ":" : "", (show && strcmp(b->name, b->show)) ? b->show : ""); while (len > pos && plist) { pos += g_snprintf(&s[pos], len - pos, "p %s\n", (char *)plist->data); while (len > pos && dlist) { pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ static GString *translate_lst(FILE *src_fp) char line[BUF_LEN], *line2; GString *dest = g_string_new("m 1\n"); while (fgets(line, BUF_LEN, src_fp)) { if (strstr(line2, "group") == line2) { name = strpbrk(line2, " \t\n\r\f") + 1; dest = g_string_append(dest, "g "); for (i = 0; i < strcspn(name, "\n\r"); i++) dest = g_string_append_c(dest, name[i]); dest = g_string_append_c(dest, '\n'); if (strstr(line2, "buddy") == line2) { name = strpbrk(line2, " \t\n\r\f") + 1; dest = g_string_append(dest, "b "); for (i = 0; i < strcspn(name, "\n\r"); i++) dest = g_string_append_c(dest, name[i]); dest = g_string_append_c(dest, '\n'); /* translate an AIM 4 buddylist (*.blt) to Gaim format */ static GString *translate_blt(FILE *src_fp) GString *dest = g_string_new("m 1\n"); while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); fgets(line, BUF_LEN, src_fp); g_strchomp(line); if (strchr(line, '}') != NULL) if (strchr(line, '{') != NULL) { /* Syntax starting with "<group> {" */ dest = g_string_append(dest, "g "); buddy = g_strchug(strtok(line, "{")); for (i = 0; i < strlen(buddy); i++) dest = g_string_append_c(dest, buddy[i]); dest = g_string_append_c(dest, '\n'); while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { debug_printf("\nbuddy: \"%s\"\n\n", buddy); dest = g_string_append(dest, "b "); if (strchr(buddy, '{') != NULL) { char *pos = strchr(buddy, '{') - 1; if ((e = strchr(buddy, '\"')) != NULL) { dest = g_string_append(dest, buddy); dest = g_string_append_c(dest, '\n'); fgets(line, BUF_LEN, src_fp); while (!strchr(line, '}')); /* Syntax "group buddy buddy ..." */ buddy = g_strchug(strtok(line, " \n")); dest = g_string_append(dest, "g "); if (strchr(buddy, '\"') != NULL) { dest = g_string_append(dest, &buddy[1]); dest = g_string_append_c(dest, ' '); buddy = g_strchug(strtok(NULL, " \n")); while (strchr(buddy, '\"') == NULL) { dest = g_string_append(dest, buddy); dest = g_string_append_c(dest, ' '); buddy = g_strchug(strtok(NULL, " \n")); buddy[strlen(buddy) - 1] = '\0'; dest = g_string_append(dest, buddy); dest = g_string_append(dest, buddy); dest = g_string_append_c(dest, '\n'); while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { dest = g_string_append(dest, "b "); if (strchr(buddy, '\"') != NULL) { dest = g_string_append(dest, &buddy[1]); dest = g_string_append_c(dest, ' '); buddy = g_strchug(strtok(NULL, " \n")); while (strchr(buddy, '\"') == NULL) { dest = g_string_append(dest, buddy); dest = g_string_append_c(dest, ' '); buddy = g_strchug(strtok(NULL, " \n")); buddy[strlen(buddy) - 1] = '\0'; dest = g_string_append(dest, buddy); dest = g_string_append(dest, buddy); dest = g_string_append_c(dest, '\n'); static GString *translate_gnomeicu(FILE *src_fp) GString *dest = g_string_new("m 1\ng Buddies\n"); while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); while (fgets(line, BUF_LEN, src_fp)) { if (line[0] == '\n' || line[0] == '[') dest = g_string_append(dest, "b "); dest = g_string_append(dest, line); dest = g_string_append_c(dest, '\n'); static gchar *get_screenname_filename(const char *name) split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); good = g_strjoinv(NULL, split); /* see if a buddy list cache file for this user exists */ gboolean bud_list_cache_exists(struct gaim_connection *gc) g_screenname = get_screenname_filename(gc->username); if (file != (char *)NULL) { g_snprintf(path, sizeof path, "%s/%s.%d.blist", file, g_screenname, gc->protocol); if (!stat(path, &sbuf)) { debug_printf("%s exists.\n", path); debug_printf("%s does not exist.\n", path); g_snprintf(path2, sizeof path2, "%s/%s.blist", file, g_screenname); if (!stat(path2, &sbuf)) { debug_printf("%s exists, moving to %s\n", path2, path); debug_printf("rename didn't work!\n"); void do_import(struct gaim_connection *gc, char *filename) g_snprintf(path, sizeof(path), "%s", filename); char *g_screenname = get_screenname_filename(gc->username); char *file = gaim_user_dir(); if (file != (char *)NULL) { sprintf(path, "%s/%s.%d.blist", file, g_screenname, gc->protocol); debug_printf("Unable to stat %s.\n", path); if (!(f = fopen(path, "r"))) { debug_printf("Unable to open %s.\n", path); if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { } else if (strstr(first, "group") != NULL) { } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { /* GnomeICU (hopefully) */ debug_printf("gnomeicu\n"); buf = translate_gnomeicu(f); } else if (first[0] == 'm') { /* Gaim buddy list - no translation */ len = fread(buf2, 1, BUF_LONG * 2 - 1, f); buf = g_string_append(buf, buf2); if (len != BUF_LONG * 2 - 1) buf = g_string_prepend(buf, "toc_set_config {"); buf = g_string_append(buf, "}\n"); parse_toc_buddy_list(gc, buf->str); g_string_free(buf, TRUE); void do_export(struct gaim_connection *g) mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR); g_screenname = get_screenname_filename(g->username); sprintf(path, "%s/%s.%d.blist", file, g_screenname, g->protocol); if ((f = fopen(path, "w"))) { debug_printf("writing %s\n", path); toc_build_config(g, buf, 8192 - 1, TRUE); chmod(path, S_IRUSR | S_IWUSR); debug_printf("unable to write %s\n", path); static gboolean is_blocked(struct buddy *b) struct gaim_connection *gc = b->gc; if (gc->permdeny == PERMIT_ALL) if (gc->permdeny == PERMIT_NONE) { if (g_strcasecmp(b->name, gc->displayname)) if (gc->permdeny == PERMIT_SOME) { char *x = g_strdup(normalize(b->name)); if (!g_strcasecmp(x, normalize(s->data))) if (gc->permdeny == DENY_SOME) { char *x = g_strdup(normalize(b->name)); if (!g_strcasecmp(x, normalize(s->data))) void signoff_blocked(struct gaim_connection *gc) GSList *m = ((struct group *)g->data)->members; struct buddy *b = m->data; serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0);