Mercurial > pidgin
comparison libpurple/protocols/gg/buddylist.c @ 24561:0b2a1b6f7464
Validate Gadu-Gadu UID's and perform proper CP1250 to UTF-8 conversions when
handling import and export operations for the buddy list. Fixes #5694.
committer: John Bailey <rekkanoryo@rekkanoryo.org>
author | Adam Strzelecki <ono@java.pl> |
---|---|
date | Sat, 29 Nov 2008 16:50:34 +0000 |
parents | d30ea407576e |
children | c9c4b31d98a7 aa1fe87558d8 |
comparison
equal
deleted
inserted
replaced
24560:9bb624e345aa | 24561:0b2a1b6f7464 |
---|---|
94 { | 94 { |
95 PurpleBuddy *buddy; | 95 PurpleBuddy *buddy; |
96 PurpleGroup *group; | 96 PurpleGroup *group; |
97 gchar **users_tbl; | 97 gchar **users_tbl; |
98 int i; | 98 int i; |
99 char *utf8buddylist = charset_convert(buddylist, "CP1250", "UTF-8"); | |
99 | 100 |
100 /* Don't limit the number of records in a buddylist. */ | 101 /* Don't limit the number of records in a buddylist. */ |
101 users_tbl = g_strsplit(buddylist, "\r\n", -1); | 102 users_tbl = g_strsplit(utf8buddylist, "\r\n", -1); |
102 | 103 |
103 for (i = 0; users_tbl[i] != NULL; i++) { | 104 for (i = 0; users_tbl[i] != NULL; i++) { |
104 gchar **data_tbl; | 105 gchar **data_tbl; |
105 gchar *name, *show, *g; | 106 gchar *name, *show, *g; |
106 | 107 |
113 "Something is wrong on line %d of the buddylist. Skipping.\n", | 114 "Something is wrong on line %d of the buddylist. Skipping.\n", |
114 i + 1); | 115 i + 1); |
115 continue; | 116 continue; |
116 } | 117 } |
117 | 118 |
118 show = charset_convert(data_tbl[F_NICKNAME], "CP1250", "UTF-8"); | 119 show = data_tbl[F_NICKNAME]; |
119 name = data_tbl[F_UIN]; | 120 name = data_tbl[F_UIN]; |
120 if ('\0' == *name) { | 121 if ('\0' == *name || !atol(name)) { |
121 purple_debug_warning("gg", | 122 purple_debug_warning("gg", |
122 "Something is wrong on line %d of the buddylist. Skipping.\n", | 123 "Identifier on line %d of the buddylist is not a number. Skipping.\n", |
123 i + 1); | 124 i + 1); |
124 continue; | 125 continue; |
125 } | 126 } |
126 | 127 |
127 if ('\0' == *show) { | 128 if ('\0' == *show) { |
128 show = g_strdup(name); | 129 show = name; |
129 } | 130 } |
130 | 131 |
131 purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name, show); | 132 purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name, show); |
132 | 133 |
133 if (purple_find_buddy(purple_connection_get_account(gc), name)) { | 134 if (purple_find_buddy(purple_connection_get_account(gc), name)) { |
134 g_free(show); | |
135 g_strfreev(data_tbl); | 135 g_strfreev(data_tbl); |
136 continue; | 136 continue; |
137 } | 137 } |
138 | 138 |
139 g = g_strdup("Gadu-Gadu"); | 139 g = g_strdup("Gadu-Gadu"); |
142 /* XXX: Probably buddy should be added to all the groups. */ | 142 /* XXX: Probably buddy should be added to all the groups. */ |
143 /* Hard limit to at most 50 groups */ | 143 /* Hard limit to at most 50 groups */ |
144 gchar **group_tbl = g_strsplit(data_tbl[F_GROUP], ",", 50); | 144 gchar **group_tbl = g_strsplit(data_tbl[F_GROUP], ",", 50); |
145 if (ggp_array_size(group_tbl) > 0) { | 145 if (ggp_array_size(group_tbl) > 0) { |
146 g_free(g); | 146 g_free(g); |
147 g = charset_convert(group_tbl[0], "CP1250", "UTF-8"); | 147 g = g_strdup(group_tbl[0]); |
148 } | 148 } |
149 g_strfreev(group_tbl); | 149 g_strfreev(group_tbl); |
150 } | 150 } |
151 | 151 |
152 buddy = purple_buddy_new(purple_connection_get_account(gc), name, | 152 buddy = purple_buddy_new(purple_connection_get_account(gc), name, |
158 } | 158 } |
159 | 159 |
160 purple_blist_add_buddy(buddy, NULL, group, NULL); | 160 purple_blist_add_buddy(buddy, NULL, group, NULL); |
161 g_free(g); | 161 g_free(g); |
162 | 162 |
163 g_free(show); | |
164 g_strfreev(data_tbl); | 163 g_strfreev(data_tbl); |
165 } | 164 } |
166 g_strfreev(users_tbl); | 165 g_strfreev(users_tbl); |
166 g_free(utf8buddylist); | |
167 | 167 |
168 ggp_buddylist_send(gc); | 168 ggp_buddylist_send(gc); |
169 } | 169 } |
170 /* }}} */ | 170 /* }}} */ |
171 | 171 |
232 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { | 232 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) { |
233 if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) | 233 if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
234 continue; | 234 continue; |
235 | 235 |
236 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { | 236 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { |
237 gchar *newdata, *name, *alias, *gname; | 237 gchar *name, *alias, *gname; |
238 gchar *cp_alias, *cp_gname; | |
239 | 238 |
240 if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) | 239 if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
241 continue; | 240 continue; |
242 | 241 |
243 buddy = (PurpleBuddy *)bnode; | 242 buddy = (PurpleBuddy *)bnode; |
246 | 245 |
247 name = buddy->name; | 246 name = buddy->name; |
248 alias = buddy->alias ? buddy->alias : buddy->name; | 247 alias = buddy->alias ? buddy->alias : buddy->name; |
249 gname = group->name; | 248 gname = group->name; |
250 | 249 |
251 cp_gname = charset_convert(gname, "UTF-8", "CP1250"); | |
252 cp_alias = charset_convert(alias, "UTF-8", "CP1250"); | |
253 newdata = g_strdup_printf( | |
254 "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", | |
255 cp_alias, cp_alias, cp_alias, cp_alias, | |
256 "", cp_gname, name, "", ""); | |
257 | |
258 ptr = buddylist; | 250 ptr = buddylist; |
259 buddylist = g_strconcat(ptr, newdata, NULL); | 251 buddylist = g_strdup_printf( |
260 | 252 "%s%s;%s;%s;%s;%s;%s;%s;%s%s\r\n", |
261 g_free(newdata); | 253 ptr, alias, alias, alias, alias, |
254 "", gname, name, "", ""); | |
255 | |
262 g_free(ptr); | 256 g_free(ptr); |
263 g_free(cp_gname); | 257 } |
264 g_free(cp_alias); | 258 } |
265 } | 259 } |
266 } | 260 |
267 } | 261 ptr = charset_convert(buddylist, "UTF-8", "CP1250"); |
268 | 262 g_free(buddylist); |
269 return buddylist; | 263 return ptr; |
270 } | 264 } |
271 /* }}} */ | 265 /* }}} */ |
272 | 266 |
273 | 267 |
274 /* vim: set ts=8 sts=0 sw=8 noet: */ | 268 /* vim: set ts=8 sts=0 sw=8 noet: */ |