Sat, 08 Sep 2007 03:09:35 +0000
The FSF changed its address a while ago; our files were out of date.
This is a quick update done with a for loop, find, and sed.
| 11414 | 1 | /** |
| 2 | * @file buddylist.c | |
| 3 | * | |
| 15884 | 4 | * purple |
| 11414 | 5 | * |
| 6 | * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 11414 | 21 | */ |
| 22 | ||
| 23 | ||
| 13318 | 24 | #include <libgadu.h> |
| 11414 | 25 | |
| 26 | #include "gg.h" | |
|
13627
44233a1064f9
[gaim-migrate @ 16013]
Evan Schoenberg <evands@pidgin.im>
parents:
13318
diff
changeset
|
27 | #include "gg-utils.h" |
| 11414 | 28 | #include "buddylist.h" |
| 29 | ||
| 30 | ||
| 15884 | 31 | /* void ggp_buddylist_send(PurpleConnection *gc) {{{ */ |
| 32 | void ggp_buddylist_send(PurpleConnection *gc) | |
| 11414 | 33 | { |
| 34 | GGPInfo *info = gc->proto_data; | |
| 15884 | 35 | PurpleAccount *account = purple_connection_get_account(gc); |
| 11414 | 36 | |
| 15884 | 37 | PurpleBuddyList *blist; |
| 38 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 39 | PurpleBuddy *buddy; | |
| 11414 | 40 | uin_t *userlist = NULL; |
| 41 | gchar *types = NULL; | |
| 12007 | 42 | int size = 0; |
| 43 | ||
| 15884 | 44 | if ((blist = purple_get_blist()) == NULL) |
| 12007 | 45 | return; |
| 11414 | 46 | |
| 12007 | 47 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { |
| 15884 | 48 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 12007 | 49 | continue; |
| 50 | ||
| 51 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 52 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 53 | continue; |
| 12007 | 54 | |
| 55 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
| 15884 | 56 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 57 | continue; |
| 12007 | 58 | |
| 15884 | 59 | buddy = (PurpleBuddy *)bnode; |
| 12007 | 60 | |
| 61 | if (buddy->account != account) | |
| 62 | continue; | |
| 11414 | 63 | |
| 12007 | 64 | size++; |
| 65 | userlist = (uin_t *) g_renew(uin_t, userlist, size); | |
| 66 | types = (gchar *) g_renew(gchar, types, size); | |
| 67 | userlist[size - 1] = ggp_str_to_uin(buddy->name); | |
| 68 | types[size - 1] = GG_USER_NORMAL; | |
| 15884 | 69 | purple_debug_info("gg", "ggp_buddylist_send: adding %d\n", |
| 12007 | 70 | userlist[size - 1]); |
| 11414 | 71 | } |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | if (userlist) { | |
| 12007 | 76 | int ret = gg_notify_ex(info->session, userlist, types, size); |
| 11414 | 77 | g_free(userlist); |
| 78 | g_free(types); | |
| 79 | ||
| 15884 | 80 | purple_debug_info("gg", "send: ret=%d; size=%d\n", ret, size); |
| 11414 | 81 | } |
| 82 | } | |
| 83 | /* }}} */ | |
| 84 | ||
| 15884 | 85 | /* void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) {{{ */ |
| 86 | void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) | |
| 11414 | 87 | { |
| 15884 | 88 | PurpleBuddy *buddy; |
| 89 | PurpleGroup *group; | |
| 11414 | 90 | gchar **users_tbl; |
| 91 | int i; | |
| 92 | ||
| 15288 | 93 | /* Don't limit a number of records in a buddylist. */ |
| 94 | users_tbl = g_strsplit(buddylist, "\r\n", -1); | |
| 11414 | 95 | |
| 96 | for (i = 0; users_tbl[i] != NULL; i++) { | |
| 97 | gchar **data_tbl; | |
| 98 | gchar *name, *show, *g; | |
| 99 | ||
| 100 | if (strlen(users_tbl[i]) == 0) | |
| 101 | continue; | |
| 102 | ||
| 103 | data_tbl = g_strsplit(users_tbl[i], ";", 8); | |
| 15288 | 104 | if (ggp_array_size(data_tbl) < 8) { |
| 15884 | 105 | purple_debug_warning("gg", |
| 15288 | 106 | "Something is wrong on line %d of the buddylist. Skipping.\n", |
| 107 | i + 1); | |
| 108 | continue; | |
| 109 | } | |
| 11414 | 110 | |
| 111 | show = charset_convert(data_tbl[3], "CP1250", "UTF-8"); | |
| 112 | name = data_tbl[6]; | |
| 15288 | 113 | if ('\0' == *name) { |
| 15884 | 114 | purple_debug_warning("gg", |
| 14925 | 115 | "Something is wrong on line %d of the buddylist. Skipping.\n", |
| 116 | i + 1); | |
| 117 | continue; | |
| 118 | } | |
| 119 | ||
| 15288 | 120 | if ('\0' == *show) { |
| 14925 | 121 | show = g_strdup(name); |
| 122 | } | |
| 11414 | 123 | |
| 15884 | 124 | purple_debug_info("gg", "got buddy: name=%s show=%s\n", name, show); |
| 11414 | 125 | |
| 15884 | 126 | if (purple_find_buddy(purple_connection_get_account(gc), name)) { |
| 11414 | 127 | g_free(show); |
| 128 | g_strfreev(data_tbl); | |
| 129 | continue; | |
| 130 | } | |
| 131 | ||
| 132 | g = g_strdup("Gadu-Gadu"); | |
| 133 | ||
| 15288 | 134 | if ('\0' != data_tbl[5]) { |
| 135 | /* XXX: Probably buddy should be added to all the groups. */ | |
| 11414 | 136 | /* Hard limit to at most 50 groups */ |
| 137 | gchar **group_tbl = g_strsplit(data_tbl[5], ",", 50); | |
| 15288 | 138 | if (ggp_array_size(group_tbl) > 0) { |
| 11414 | 139 | g_free(g); |
| 140 | g = g_strdup(group_tbl[0]); | |
| 141 | } | |
| 142 | g_strfreev(group_tbl); | |
| 143 | } | |
| 144 | ||
| 15884 | 145 | buddy = purple_buddy_new(purple_connection_get_account(gc), name, |
| 12007 | 146 | strlen(show) ? show : NULL); |
| 147 | ||
| 15884 | 148 | if (!(group = purple_find_group(g))) { |
| 149 | group = purple_group_new(g); | |
| 150 | purple_blist_add_group(group, NULL); | |
| 11414 | 151 | } |
| 152 | ||
| 15884 | 153 | purple_blist_add_buddy(buddy, NULL, group, NULL); |
| 11414 | 154 | g_free(g); |
| 155 | ||
| 156 | g_free(show); | |
| 157 | g_strfreev(data_tbl); | |
| 158 | } | |
| 159 | g_strfreev(users_tbl); | |
| 160 | ||
| 161 | ggp_buddylist_send(gc); | |
| 162 | ||
| 163 | } | |
| 164 | /* }}} */ | |
| 165 | ||
| 15884 | 166 | /* void ggp_buddylist_offline(PurpleConnection *gc) {{{ */ |
| 167 | void ggp_buddylist_offline(PurpleConnection *gc) | |
| 11414 | 168 | { |
| 15884 | 169 | PurpleAccount *account = purple_connection_get_account(gc); |
| 170 | PurpleBuddyList *blist; | |
| 171 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 172 | PurpleBuddy *buddy; | |
| 11414 | 173 | |
| 15884 | 174 | if ((blist = purple_get_blist()) == NULL) |
| 12007 | 175 | return; |
| 176 | ||
| 177 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { | |
| 15884 | 178 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 12007 | 179 | continue; |
| 180 | ||
| 181 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 182 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 183 | continue; |
| 12007 | 184 | |
| 185 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
| 15884 | 186 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 187 | continue; |
| 12007 | 188 | |
| 15884 | 189 | buddy = (PurpleBuddy *)bnode; |
| 11414 | 190 | |
| 12007 | 191 | if (buddy->account != account) |
| 192 | continue; | |
| 11414 | 193 | |
| 15884 | 194 | purple_prpl_got_user_status( |
| 195 | purple_connection_get_account(gc), | |
| 12007 | 196 | buddy->name, "offline", NULL); |
| 11414 | 197 | |
| 15884 | 198 | purple_debug_info("gg", |
| 12007 | 199 | "ggp_buddylist_offline: gone: %s\n", |
| 200 | buddy->name); | |
| 11414 | 201 | } |
| 202 | } | |
| 203 | } | |
| 204 | } | |
| 205 | /* }}} */ | |
| 206 | ||
| 15884 | 207 | /* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */ |
| 208 | char *ggp_buddylist_dump(PurpleAccount *account) | |
| 11414 | 209 | { |
| 15884 | 210 | PurpleBuddyList *blist; |
| 211 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 212 | PurpleGroup *group; | |
| 213 | PurpleBuddy *buddy; | |
| 11414 | 214 | |
| 215 | char *buddylist = g_strdup(""); | |
| 216 | char *ptr; | |
| 217 | ||
| 15884 | 218 | if ((blist = purple_get_blist()) == NULL) |
| 11414 | 219 | return NULL; |
| 220 | ||
| 221 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { | |
| 15884 | 222 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
| 11414 | 223 | continue; |
| 224 | ||
| 15884 | 225 | group = (PurpleGroup *)gnode; |
| 11414 | 226 | |
| 227 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | |
| 15884 | 228 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
| 11414 | 229 | continue; |
| 230 | ||
| 231 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | |
| 12007 | 232 | gchar *newdata, *name, *alias, *gname; |
| 233 | gchar *cp_alias, *cp_gname; | |
| 11414 | 234 | |
| 15884 | 235 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
| 11414 | 236 | continue; |
| 237 | ||
| 15884 | 238 | buddy = (PurpleBuddy *)bnode; |
| 11414 | 239 | if (buddy->account != account) |
| 240 | continue; | |
| 241 | ||
| 242 | name = buddy->name; | |
| 12007 | 243 | alias = buddy->alias ? buddy->alias : buddy->name; |
| 11414 | 244 | gname = group->name; |
| 245 | ||
| 12007 | 246 | cp_gname = charset_convert(gname, "UTF-8", "CP1250"); |
| 247 | cp_alias = charset_convert(alias, "UTF-8", "CP1250"); | |
| 248 | newdata = g_strdup_printf( | |
| 249 | "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", | |
| 250 | cp_alias, cp_alias, cp_alias, cp_alias, | |
| 251 | "", cp_gname, name, "", ""); | |
| 11414 | 252 | |
| 253 | ptr = buddylist; | |
| 254 | buddylist = g_strconcat(ptr, newdata, NULL); | |
| 255 | ||
| 256 | g_free(newdata); | |
| 257 | g_free(ptr); | |
| 12007 | 258 | g_free(cp_gname); |
| 259 | g_free(cp_alias); | |
| 11414 | 260 | } |
| 261 | } | |
| 262 | } | |
| 263 | ||
| 264 | return buddylist; | |
| 265 | } | |
| 266 | /* }}} */ | |
| 267 | ||
| 268 | ||
| 12007 | 269 | /* vim: set ts=8 sts=0 sw=8 noet: */ |