Mercurial > pidgin
annotate src/list.c @ 4931:d80bc307e2c8
[gaim-migrate @ 5265]
I never liked that thing.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Mon, 31 Mar 2003 23:15:25 +0000 |
| parents | a1551892049c |
| children | cfeab08d4be9 |
| rev | line source |
|---|---|
| 2382 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 4687 | 4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> |
| 2382 | 5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 #ifdef HAVE_CONFIG_H | |
| 24 #include <config.h> | |
| 25 #endif | |
| 26 #include <string.h> | |
| 4349 | 27 #include <stdlib.h> |
| 2382 | 28 #include <sys/types.h> |
| 29 #include <sys/stat.h> | |
| 3630 | 30 #ifndef _WIN32 |
| 2382 | 31 #include <unistd.h> |
| 3630 | 32 #else |
| 33 #include <direct.h> | |
| 34 #endif | |
| 4349 | 35 #include <ctype.h> |
| 2382 | 36 #include "gaim.h" |
| 37 #include "prpl.h" | |
| 4687 | 38 #include "list.h" |
| 2382 | 39 |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
40 #ifdef _WIN32 |
|
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
41 #include "win32dep.h" |
|
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
42 #endif |
|
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
43 |
| 2382 | 44 #define PATHSIZE 1024 |
| 45 | |
| 4687 | 46 struct gaim_buddy_list *gaimbuddylist = NULL; |
| 47 static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
| 2382 | 48 |
| 4687 | 49 /***************************************************************************** |
| 50 * Private Utility functions * | |
| 51 *****************************************************************************/ | |
| 52 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
| 53 { | |
| 54 GaimBlistNode *n = node; | |
| 55 if (!n) | |
| 56 return NULL; | |
| 57 while (n->next) | |
| 58 n = n->next; | |
| 59 return n; | |
| 60 } | |
| 61 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
| 62 { | |
| 63 if (!node) | |
| 64 return NULL; | |
| 65 return gaim_blist_get_last_sibling(node->child); | |
| 66 } | |
| 2382 | 67 |
| 4770 | 68 /***************************************************************************** |
| 4687 | 69 * Public API functions * |
| 70 *****************************************************************************/ | |
| 4349 | 71 |
| 4687 | 72 struct gaim_buddy_list *gaim_blist_new() |
| 73 { | |
| 74 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
75 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
76 gbl->ui_ops = gaim_get_blist_ui_ops(); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
77 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
78 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
79 gbl->ui_ops->new_list(gbl); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
80 |
| 4687 | 81 return gbl; |
| 82 } | |
| 2382 | 83 |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
84 void |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
85 gaim_set_blist(struct gaim_buddy_list *list) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
86 { |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
87 gaimbuddylist = list; |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
88 } |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
89 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
90 struct gaim_buddy_list * |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
91 gaim_get_blist(void) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
92 { |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
93 return gaimbuddylist; |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
94 } |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
95 |
| 4687 | 96 void gaim_blist_show () |
| 97 { | |
| 98 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 99 if (ops) | |
| 100 ops->show(gaimbuddylist); | |
| 101 } | |
| 2382 | 102 |
| 4687 | 103 void gaim_blist_destroy() |
| 104 { | |
| 105 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 106 if (ops) | |
| 107 ops->destroy(gaimbuddylist); | |
| 108 } | |
| 2382 | 109 |
| 4687 | 110 void gaim_blist_set_visible (gboolean show) |
| 111 { | |
| 112 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 113 if (ops) | |
| 114 ops->set_visible(gaimbuddylist, show); | |
| 115 } | |
| 2382 | 116 |
| 4687 | 117 void gaim_blist_update_buddy_status (struct buddy *buddy, int status) |
| 118 { | |
| 119 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 120 buddy->uc = status; | |
| 121 if (ops) | |
| 122 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 2382 | 123 } |
| 124 | |
| 4687 | 125 void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { |
| 126 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 127 if (!buddy->present && presence) | |
| 128 buddy->present = 2; | |
| 129 else if (buddy->present != 2) | |
| 130 buddy->present = presence; | |
| 131 if (ops) | |
| 132 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 133 } | |
| 2382 | 134 |
| 135 | |
| 4687 | 136 void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) |
| 137 { | |
| 138 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 139 buddy->idle = idle; | |
| 140 if (ops) | |
| 141 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 142 } | |
| 143 void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
| 144 { | |
| 145 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 146 buddy->evil = warning; | |
| 147 if (ops) | |
| 148 ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
| 149 } | |
| 4757 | 150 void gaim_blist_update_buddy_icon(struct buddy *buddy) { |
| 151 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 152 if(ops) | |
| 153 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 154 } | |
| 4687 | 155 void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) |
| 156 { | |
| 157 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 158 g_free(buddy->name); | |
| 159 buddy->name = g_strdup(name); | |
| 160 if (ops) | |
| 161 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 162 } | |
| 163 void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) | |
| 164 { | |
| 165 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 166 g_free(buddy->alias); | |
| 167 buddy->alias = g_strdup(alias); | |
| 168 if (ops) | |
| 169 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 170 } | |
| 171 void gaim_blist_rename_group(struct group *group, const char *name) | |
| 172 { | |
| 173 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 174 g_free(group->name); | |
| 175 group->name = g_strdup(name); | |
| 176 if (ops) | |
| 177 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 178 } | |
| 179 struct buddy *gaim_buddy_new(struct gaim_account *account, const char *screenname, const char *alias) | |
| 180 { | |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
181 struct buddy *b; |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
182 struct gaim_blist_ui_ops *ops; |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
183 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
184 b = g_new0(struct buddy, 1); |
| 4491 | 185 b->account = account; |
| 4687 | 186 b->name = g_strdup(screenname); |
| 187 b->alias = g_strdup(alias); | |
| 4349 | 188 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| 4687 | 189 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; |
| 2382 | 190 |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
191 ops = gaim_get_blist_ui_ops(); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
192 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
193 if (ops != NULL && ops->new_node != NULL) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
194 ops->new_node((GaimBlistNode *)b); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
195 |
| 2382 | 196 return b; |
| 197 } | |
| 4687 | 198 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
| 2382 | 199 { |
| 4687 | 200 GaimBlistNode *n = node, *node2, *node3; |
| 201 struct group *g = group; | |
| 202 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 4770 | 203 gboolean save = FALSE; |
| 4865 | 204 |
| 205 /* if we're moving to overtop of ourselves, do nothing */ | |
| 206 if((GaimBlistNode*)buddy == node) | |
| 207 return; | |
| 208 | |
| 4687 | 209 if (!n) { |
| 210 if (!g) { | |
| 211 g = gaim_group_new(_("Buddies")); | |
| 212 gaim_blist_add_group(g, NULL); | |
| 213 } | |
| 214 n = gaim_blist_get_last_child((GaimBlistNode*)g); | |
| 215 } | |
| 216 | |
| 4770 | 217 if (((GaimBlistNode*)buddy)->parent) { |
| 218 /* This buddy was already in the list and is | |
| 219 * being moved. | |
| 220 */ | |
| 221 ops->remove(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 222 node2 = ((GaimBlistNode*)buddy)->next; | |
| 223 node3 = ((GaimBlistNode*)buddy)->prev; | |
| 4865 | 224 |
| 4770 | 225 if (node2) |
| 226 node2->prev = node3; | |
| 227 if (node3) | |
| 228 node3->next = node2; | |
| 229 | |
| 230 if (((GaimBlistNode*)buddy)->parent != n->parent) | |
| 4865 | 231 serv_move_buddy(buddy, (struct group*)((GaimBlistNode*)buddy)->parent, |
| 4770 | 232 (struct group*)n->parent); |
| 233 save = TRUE; | |
| 234 } | |
| 2382 | 235 |
| 4687 | 236 if (n) { |
| 237 ((GaimBlistNode*)buddy)->next = n->next; | |
| 238 ((GaimBlistNode*)buddy)->prev = n; | |
| 239 ((GaimBlistNode*)buddy)->parent = n->parent; | |
| 240 n->next = (GaimBlistNode*)buddy; | |
| 241 } else { | |
| 242 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; | |
| 243 ((GaimBlistNode*)buddy)->next = NULL; | |
| 244 ((GaimBlistNode*)buddy)->prev = NULL; | |
| 245 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
| 246 } | |
| 2382 | 247 |
| 4687 | 248 if (ops) |
| 249 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 4865 | 250 if (save) |
| 4770 | 251 gaim_blist_save(); |
| 4687 | 252 } |
| 2382 | 253 |
| 4687 | 254 struct group *gaim_group_new(const char *name) |
| 255 { | |
| 256 struct group *g = gaim_find_group(name); | |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
257 |
| 4687 | 258 if (!g) { |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
259 struct gaim_blist_ui_ops *ops; |
| 4687 | 260 g= g_new0(struct group, 1); |
| 261 g->name = g_strdup(name); | |
| 262 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
| 2382 | 263 |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
264 ops = gaim_get_blist_ui_ops(); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
265 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
266 if (ops != NULL && ops->new_node != NULL) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
267 ops->new_node((GaimBlistNode *)g); |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
268 |
| 4687 | 269 } |
| 2382 | 270 return g; |
| 271 } | |
| 272 | |
| 4687 | 273 void gaim_blist_add_group (struct group *group, GaimBlistNode *node) |
| 2382 | 274 { |
| 4687 | 275 struct gaim_blist_ui_ops *ops; |
| 4785 | 276 gboolean save = FALSE; |
| 277 | |
| 4687 | 278 if (!gaimbuddylist) |
| 279 gaimbuddylist = gaim_blist_new(); | |
| 280 ops = gaimbuddylist->ui_ops; | |
| 4785 | 281 |
| 4687 | 282 if (!gaimbuddylist->root) { |
| 283 gaimbuddylist->root = (GaimBlistNode*)group; | |
| 284 return; | |
| 285 } | |
| 4785 | 286 |
| 287 | |
| 288 if (!node) | |
| 4687 | 289 node = gaim_blist_get_last_sibling(gaimbuddylist->root); |
| 4785 | 290 |
| 4781 | 291 if (gaim_find_group(group->name)) { |
| 292 /* This is just being moved */ | |
| 293 GaimBlistNode *node2 = ((GaimBlistNode*)group)->next; | |
| 294 GaimBlistNode *node3 = ((GaimBlistNode*)group)->prev; | |
| 2382 | 295 |
| 4781 | 296 ops->remove(gaimbuddylist, (GaimBlistNode*)group); |
| 297 | |
| 298 if (node2) | |
| 299 node2->prev = node3; | |
| 300 if (node3) | |
| 301 node3->next = node2; | |
| 302 save = TRUE; | |
| 303 } | |
| 4785 | 304 |
| 4687 | 305 ((GaimBlistNode*)group)->next = node ? node->next : NULL; |
| 306 ((GaimBlistNode*)group)->prev = node; | |
| 307 node->next = (GaimBlistNode*)group; | |
| 308 | |
| 309 if (ops) | |
| 310 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 4785 | 311 if (save) |
| 4781 | 312 gaim_blist_save(); |
| 4687 | 313 } |
| 314 | |
| 315 void gaim_blist_remove_buddy (struct buddy *buddy) | |
| 316 { | |
| 317 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 318 | |
| 4721 | 319 GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; |
| 320 struct group *group; | |
| 321 | |
| 322 gnode = node->parent; | |
| 323 group = (struct group *)gnode; | |
| 324 | |
| 325 if(gnode->child == node) | |
| 326 gnode->child = node->next; | |
| 4687 | 327 if (node->prev) |
| 328 node->prev->next = node->next; | |
| 329 if (node->next) | |
| 330 node->next->prev = node->prev; | |
| 4721 | 331 |
| 4687 | 332 ops->remove(gaimbuddylist, node); |
| 333 g_free(buddy->name); | |
| 334 g_free(buddy->alias); | |
| 335 g_free(buddy); | |
| 2382 | 336 } |
| 337 | |
| 4687 | 338 void gaim_blist_remove_group (struct group *group) |
| 4349 | 339 { |
| 4687 | 340 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 341 GaimBlistNode *node = (GaimBlistNode*)group; | |
| 342 GaimBlistNode *child = node->child; | |
| 343 while (child) { | |
| 344 GaimBlistNode *n = child; | |
| 345 child = child->next; | |
| 346 gaim_blist_remove_buddy((struct buddy*)n); | |
| 347 } | |
| 348 ops->remove(gaimbuddylist, node); | |
| 349 g_free(group->name); | |
| 350 g_free(group); | |
| 351 } | |
| 4349 | 352 |
| 4687 | 353 char *gaim_get_buddy_alias_only(struct buddy *b) { |
| 354 if(!b) | |
| 355 return NULL; | |
| 356 if(b->alias && b->alias[0]) | |
| 357 return b->alias; | |
| 358 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias) | |
| 359 return b->server_alias; | |
| 360 return NULL; | |
| 361 } | |
| 362 | |
| 363 char * gaim_get_buddy_alias (struct buddy *buddy) | |
| 364 { | |
| 365 char *ret = gaim_get_buddy_alias_only(buddy); | |
| 366 if(!ret) | |
| 367 return buddy ? buddy->name : _("Unknown"); | |
| 368 return ret; | |
| 369 | |
| 370 } | |
| 371 | |
| 372 struct buddy *gaim_find_buddy(struct gaim_account *account, const char *name) | |
| 373 { | |
| 4757 | 374 GaimBlistNode *group; |
| 4687 | 375 GaimBlistNode *buddy; |
| 4757 | 376 char *norm_name = g_strdup(normalize(name)); |
| 377 | |
| 4687 | 378 if (!gaimbuddylist) |
| 379 return NULL; | |
| 4757 | 380 |
| 381 group = gaimbuddylist->root; | |
| 4687 | 382 while (group) { |
| 383 buddy = group->child; | |
| 384 while (buddy) { | |
| 4793 | 385 if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name) && account == ((struct buddy*)buddy)->account) { |
| 4757 | 386 g_free(norm_name); |
| 4687 | 387 return (struct buddy*)buddy; |
| 4757 | 388 } |
| 4687 | 389 buddy = buddy->next; |
| 390 } | |
| 391 group = group->next; | |
| 4349 | 392 } |
| 4757 | 393 g_free(norm_name); |
| 4349 | 394 return NULL; |
| 395 } | |
| 396 | |
| 4687 | 397 struct group *gaim_find_group(const char *name) |
| 2382 | 398 { |
| 4687 | 399 GaimBlistNode *node; |
| 400 if (!gaimbuddylist) | |
| 401 return NULL; | |
| 402 node = gaimbuddylist->root; | |
| 403 while(node) { | |
| 404 if (!strcmp(((struct group*)node)->name, name)) | |
| 405 return (struct group*)node; | |
| 406 node = node->next; | |
| 2382 | 407 } |
| 4349 | 408 return NULL; |
| 2382 | 409 } |
| 4687 | 410 struct group *gaim_find_buddys_group(struct buddy *buddy) |
| 411 { | |
| 4830 | 412 if (!buddy) |
| 413 return NULL; | |
| 4687 | 414 return (struct group*)(((GaimBlistNode*)buddy)->parent); |
| 415 } | |
| 416 | |
| 417 GSList *gaim_group_get_accounts(struct group *g) | |
| 418 { | |
| 419 GSList *l = NULL; | |
| 420 GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
| 421 | |
| 422 while (child) { | |
| 423 if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
| 424 l = g_slist_append(l, ((struct buddy*)child)->account); | |
| 425 child = child->next; | |
| 426 } | |
| 427 return l; | |
| 428 } | |
| 429 | |
| 430 void gaim_blist_remove_account(struct gaim_account *account) | |
| 431 { | |
| 432 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 433 GaimBlistNode *group = gaimbuddylist->root; | |
| 434 GaimBlistNode *buddy; | |
| 435 if (!gaimbuddylist) | |
| 436 return; | |
| 437 while (group) { | |
| 438 buddy = group->child; | |
| 439 while (buddy) { | |
| 440 if (account == ((struct buddy*)buddy)->account) { | |
| 441 ((struct buddy*)buddy)->present = 0; | |
| 4919 | 442 if(ops) |
| 443 ops->remove(gaimbuddylist, buddy); | |
| 4687 | 444 } |
| 445 buddy = buddy->next; | |
| 446 } | |
| 447 group = group->next; | |
| 448 } | |
| 449 } | |
| 2382 | 450 |
| 4491 | 451 void parse_toc_buddy_list(struct gaim_account *account, char *config) |
| 2382 | 452 { |
| 453 char *c; | |
| 454 char current[256]; | |
| 4351 | 455 GList *bud = NULL; |
| 4349 | 456 |
| 2382 | 457 |
| 458 if (config != NULL) { | |
| 4349 | 459 |
| 2382 | 460 /* skip "CONFIG:" (if it exists) */ |
| 461 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 2998 | 462 strtok(config, "\n") : |
| 463 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 2382 | 464 do { |
| 465 if (c == NULL) | |
| 466 break; | |
| 467 if (*c == 'g') { | |
| 4404 | 468 char *utf8 = NULL; |
| 4458 | 469 utf8 = gaim_try_conv_to_utf8(c + 2); |
| 4404 | 470 if (utf8 == NULL) { |
| 471 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 472 } else { | |
| 473 g_strlcpy(current, utf8, sizeof(current)); | |
| 474 g_free(utf8); | |
| 475 } | |
| 4687 | 476 if (!gaim_find_group(current)) { |
| 477 struct group *g = gaim_group_new(current); | |
| 478 gaim_blist_add_group(g, NULL); | |
|
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
479 } |
| 4687 | 480 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ |
| 481 char nm[80], sw[388], *a, *utf8 = NULL; | |
| 4408 | 482 |
| 4404 | 483 if ((a = strchr(c + 2, ':')) != NULL) { |
| 484 *a++ = '\0'; /* nul the : */ | |
| 485 } | |
| 4349 | 486 |
| 4404 | 487 g_strlcpy(nm, c + 2, sizeof(nm)); |
| 488 if (a) { | |
| 4458 | 489 utf8 = gaim_try_conv_to_utf8(a); |
| 4404 | 490 if (utf8 == NULL) { |
| 491 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); | |
| 492 } | |
| 493 } | |
| 494 if (utf8 == NULL) { | |
| 495 sw[0] = '\0'; | |
| 496 } else { | |
| 4491 | 497 /* This can leave a partial sequence at the end, |
| 4404 | 498 * but who cares? */ |
| 499 g_strlcpy(sw, utf8, sizeof(sw)); | |
| 500 g_free(utf8); | |
| 501 } | |
| 4491 | 502 |
| 4687 | 503 if (!gaim_find_buddy(account, nm)) { |
| 504 struct buddy *b = gaim_buddy_new(account, nm, sw); | |
| 505 struct group *g = gaim_find_group(current); | |
| 506 gaim_blist_add_buddy(b, g, NULL); | |
| 4404 | 507 bud = g_list_append(bud, nm); |
|
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
508 } |
| 2382 | 509 } else if (*c == 'p') { |
| 4491 | 510 gaim_privacy_permit_add(account, c + 2); |
| 2382 | 511 } else if (*c == 'd') { |
| 4491 | 512 gaim_privacy_deny_add(account, c + 2); |
| 2382 | 513 } else if (!strncmp("toc", c, 3)) { |
| 4491 | 514 sscanf(c + strlen(c) - 1, "%d", &account->permdeny); |
| 515 debug_printf("permdeny: %d\n", account->permdeny); | |
| 516 if (account->permdeny == 0) | |
| 517 account->permdeny = 1; | |
| 2382 | 518 } else if (*c == 'm') { |
| 4491 | 519 sscanf(c + 2, "%d", &account->permdeny); |
| 520 debug_printf("permdeny: %d\n", account->permdeny); | |
| 521 if (account->permdeny == 0) | |
| 522 account->permdeny = 1; | |
| 2382 | 523 } |
| 524 } while ((c = strtok(NULL, "\n"))); | |
| 4351 | 525 |
| 4491 | 526 if(account->gc) { |
| 4351 | 527 if(bud) |
| 4491 | 528 serv_add_buddies(account->gc, bud); |
| 529 serv_set_permit_deny(account->gc); | |
| 4351 | 530 } |
| 531 g_list_free(bud); | |
| 2382 | 532 } |
| 533 } | |
| 534 | |
| 4687 | 535 #if 0 |
|
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
536 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
537 static GString *translate_lst(FILE *src_fp) |
| 2382 | 538 { |
| 539 char line[BUF_LEN], *line2; | |
| 540 char *name; | |
| 541 int i; | |
| 542 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
543 GString *dest = g_string_new("m 1\n"); |
| 2382 | 544 |
| 545 while (fgets(line, BUF_LEN, src_fp)) { | |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
546 line2 = g_strchug(line); |
| 2382 | 547 if (strstr(line2, "group") == line2) { |
| 548 name = strpbrk(line2, " \t\n\r\f") + 1; | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
549 dest = g_string_append(dest, "g "); |
| 2382 | 550 for (i = 0; i < strcspn(name, "\n\r"); i++) |
| 551 if (name[i] != '\"') | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
552 dest = g_string_append_c(dest, name[i]); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
553 dest = g_string_append_c(dest, '\n'); |
| 2382 | 554 } |
| 555 if (strstr(line2, "buddy") == line2) { | |
| 556 name = strpbrk(line2, " \t\n\r\f") + 1; | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
557 dest = g_string_append(dest, "b "); |
| 2382 | 558 for (i = 0; i < strcspn(name, "\n\r"); i++) |
| 559 if (name[i] != '\"') | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
560 dest = g_string_append_c(dest, name[i]); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
561 dest = g_string_append_c(dest, '\n'); |
| 2382 | 562 } |
| 563 } | |
| 564 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
565 return dest; |
| 2382 | 566 } |
| 567 | |
| 568 | |
|
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
569 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
570 static GString *translate_blt(FILE *src_fp) |
| 2382 | 571 { |
| 572 int i; | |
| 573 char line[BUF_LEN]; | |
| 574 char *buddy; | |
| 575 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
576 GString *dest = g_string_new("m 1\n"); |
| 2382 | 577 |
| 578 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 579 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 580 | |
| 581 while (1) { | |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
582 fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
| 2382 | 583 if (strchr(line, '}') != NULL) |
| 584 break; | |
| 585 | |
| 586 if (strchr(line, '{') != NULL) { | |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
587 /* Syntax starting with "<group> {" */ |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
588 |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
589 dest = g_string_append(dest, "g "); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
590 buddy = g_strchug(strtok(line, "{")); |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
591 for (i = 0; i < strlen(buddy); i++) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
592 if (buddy[i] != '\"') |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
593 dest = g_string_append_c(dest, buddy[i]); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
594 dest = g_string_append_c(dest, '\n'); |
| 2382 | 595 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
596 gboolean pounce = FALSE; |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
597 char *e; |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
598 g_strchomp(line); |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
599 buddy = g_strchug(line); |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
600 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
601 dest = g_string_append(dest, "b "); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
602 if (strchr(buddy, '{') != NULL) { |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
603 /* buddy pounce, etc */ |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
604 char *pos = strchr(buddy, '{') - 1; |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
605 *pos = 0; |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
606 pounce = TRUE; |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
607 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
608 if ((e = strchr(buddy, '\"')) != NULL) { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
609 *e = '\0'; |
| 2382 | 610 buddy++; |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
611 } |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
612 dest = g_string_append(dest, buddy); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
613 dest = g_string_append_c(dest, '\n'); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
614 if (pounce) |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
615 do |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
616 fgets(line, BUF_LEN, src_fp); |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
617 while (!strchr(line, '}')); |
| 2382 | 618 } |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
619 } else { |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
620 |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
621 /* Syntax "group buddy buddy ..." */ |
|
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
622 buddy = g_strchug(strtok(line, " \n")); |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
623 dest = g_string_append(dest, "g "); |
| 2382 | 624 if (strchr(buddy, '\"') != NULL) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
625 dest = g_string_append(dest, &buddy[1]); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
626 dest = g_string_append_c(dest, ' '); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
627 buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 628 while (strchr(buddy, '\"') == NULL) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
629 dest = g_string_append(dest, buddy); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
630 dest = g_string_append_c(dest, ' '); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
631 buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 632 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
633 buddy[strlen(buddy) - 1] = '\0'; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
634 dest = g_string_append(dest, buddy); |
| 2382 | 635 } else { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
636 dest = g_string_append(dest, buddy); |
| 2382 | 637 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
638 dest = g_string_append_c(dest, '\n'); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
639 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
640 dest = g_string_append(dest, "b "); |
| 2382 | 641 if (strchr(buddy, '\"') != NULL) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
642 dest = g_string_append(dest, &buddy[1]); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
643 dest = g_string_append_c(dest, ' '); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
644 buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 645 while (strchr(buddy, '\"') == NULL) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
646 dest = g_string_append(dest, buddy); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
647 dest = g_string_append_c(dest, ' '); |
|
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
648 buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 649 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
650 buddy[strlen(buddy) - 1] = '\0'; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
651 dest = g_string_append(dest, buddy); |
| 2382 | 652 } else { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
653 dest = g_string_append(dest, buddy); |
| 2382 | 654 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
655 dest = g_string_append_c(dest, '\n'); |
| 2382 | 656 } |
| 657 } | |
| 658 } | |
| 659 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
660 return dest; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
661 } |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
662 |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
663 static GString *translate_gnomeicu(FILE *src_fp) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
664 { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
665 char line[BUF_LEN]; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
666 GString *dest = g_string_new("m 1\ng Buddies\n"); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
667 |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
668 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
669 |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
670 while (fgets(line, BUF_LEN, src_fp)) { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
671 char *eq; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
672 g_strchomp(line); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
673 if (line[0] == '\n' || line[0] == '[') |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
674 break; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
675 eq = strchr(line, '='); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
676 if (!eq) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
677 break; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
678 *eq = ':'; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
679 eq = strchr(eq, ','); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
680 if (eq) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
681 *eq = '\0'; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
682 dest = g_string_append(dest, "b "); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
683 dest = g_string_append(dest, line); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
684 dest = g_string_append_c(dest, '\n'); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
685 } |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
686 |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
687 return dest; |
| 2382 | 688 } |
| 4687 | 689 #endif |
| 2382 | 690 |
| 691 static gchar *get_screenname_filename(const char *name) | |
| 692 { | |
| 693 gchar **split; | |
| 694 gchar *good; | |
| 4793 | 695 gchar *ret; |
| 2382 | 696 |
| 697 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 698 good = g_strjoinv(NULL, split); | |
| 699 g_strfreev(split); | |
| 700 | |
| 4793 | 701 ret = g_utf8_strup(good, -1); |
| 2382 | 702 |
| 4793 | 703 g_free(good); |
| 704 | |
| 705 return ret; | |
| 2382 | 706 } |
| 707 | |
| 4349 | 708 static gboolean gaim_blist_read(const char *filename); |
| 2382 | 709 |
| 4687 | 710 |
| 711 static void do_import(struct gaim_account *account, const char *filename) | |
| 2382 | 712 { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
713 GString *buf = NULL; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
714 char first[64]; |
| 2382 | 715 char path[PATHSIZE]; |
| 716 int len; | |
| 717 FILE *f; | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
718 struct stat st; |
| 2382 | 719 |
| 720 if (filename) { | |
| 721 g_snprintf(path, sizeof(path), "%s", filename); | |
| 722 } else { | |
| 4491 | 723 char *g_screenname = get_screenname_filename(account->username); |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
724 char *file = gaim_user_dir(); |
| 4491 | 725 int protocol = (account->protocol == PROTO_OSCAR) ? (isalpha(account->username[0]) ? PROTO_TOC : PROTO_ICQ): account->protocol; |
| 2382 | 726 |
| 727 if (file != (char *)NULL) { | |
| 4349 | 728 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 2382 | 729 g_free(g_screenname); |
| 730 } else { | |
| 731 g_free(g_screenname); | |
| 732 return; | |
| 733 } | |
| 734 } | |
| 735 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
736 if (stat(path, &st)) { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
737 debug_printf("Unable to stat %s.\n", path); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
738 return; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
739 } |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
740 |
| 2382 | 741 if (!(f = fopen(path, "r"))) { |
| 742 debug_printf("Unable to open %s.\n", path); | |
| 743 return; | |
| 744 } | |
| 745 | |
| 746 fgets(first, 64, f); | |
| 747 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
748 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
749 fgets(first, 64, f); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
750 |
| 4687 | 751 #if 0 |
| 4349 | 752 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { |
| 753 /* new gaim XML buddy list */ | |
| 754 gaim_blist_read(path); | |
| 4687 | 755 |
| 756 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 757 | |
| 4349 | 758 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
759 /* AIM 4 buddy list */ |
| 2382 | 760 debug_printf("aim 4\n"); |
| 761 rewind(f); | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
762 buf = translate_blt(f); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
763 } else if (strstr(first, "group") != NULL) { |
| 2382 | 764 /* AIM 3 buddy list */ |
| 765 debug_printf("aim 3\n"); | |
| 766 rewind(f); | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
767 buf = translate_lst(f); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
768 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
769 /* GnomeICU (hopefully) */ |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
770 debug_printf("gnomeicu\n"); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
771 rewind(f); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
772 buf = translate_gnomeicu(f); |
| 4687 | 773 |
| 774 } else | |
| 775 #endif | |
| 776 if (first[0] == 'm') { | |
| 777 /* Gaim buddy list - no translation */ | |
| 778 char buf2[BUF_LONG * 2]; | |
| 779 buf = g_string_new(""); | |
| 780 rewind(f); | |
| 781 while (1) { | |
| 782 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 783 if (len <= 0) | |
| 784 break; | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
785 buf2[len] = '\0'; |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
786 buf = g_string_append(buf, buf2); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
787 if (len != BUF_LONG * 2 - 1) |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
788 break; |
| 4687 | 789 } |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
790 } |
| 4687 | 791 |
| 2382 | 792 fclose(f); |
| 793 | |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
794 if (buf) { |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
795 buf = g_string_prepend(buf, "toc_set_config {"); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
796 buf = g_string_append(buf, "}\n"); |
| 4491 | 797 parse_toc_buddy_list(account, buf->str); |
|
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
798 g_string_free(buf, TRUE); |
|
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
799 } |
| 2382 | 800 } |
| 801 | |
| 4491 | 802 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { |
| 4785 | 803 GaimBlistNode *bnode; |
| 804 for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
| 805 struct buddy *b = (struct buddy *)bnode; | |
| 806 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 807 continue; | |
| 4491 | 808 if((!account && b->account->gc) || b->account == account) |
| 4349 | 809 return TRUE; |
| 810 } | |
| 811 return FALSE; | |
| 812 } | |
| 813 | |
| 4497 | 814 static gboolean blist_safe_to_write = FALSE; |
| 4349 | 815 |
| 816 static char *blist_parser_group_name = NULL; | |
| 817 static char *blist_parser_person_name = NULL; | |
| 818 static char *blist_parser_account_name = NULL; | |
| 819 static int blist_parser_account_protocol = 0; | |
| 820 static char *blist_parser_buddy_name = NULL; | |
| 821 static char *blist_parser_buddy_alias = NULL; | |
| 822 static char *blist_parser_setting_name = NULL; | |
| 823 static char *blist_parser_setting_value = NULL; | |
| 824 static GHashTable *blist_parser_buddy_settings = NULL; | |
| 825 static int blist_parser_privacy_mode = 0; | |
| 826 static enum { | |
| 827 BLIST_TAG_GAIM, | |
| 828 BLIST_TAG_BLIST, | |
| 829 BLIST_TAG_GROUP, | |
| 830 BLIST_TAG_PERSON, | |
| 831 BLIST_TAG_BUDDY, | |
| 832 BLIST_TAG_NAME, | |
| 833 BLIST_TAG_ALIAS, | |
| 834 BLIST_TAG_SETTING, | |
| 835 BLIST_TAG_PRIVACY, | |
| 836 BLIST_TAG_ACCOUNT, | |
| 837 BLIST_TAG_PERMIT, | |
| 838 BLIST_TAG_BLOCK, | |
| 839 BLIST_TAG_IGNORE | |
| 840 } blist_parser_current_tag; | |
| 4439 | 841 static gboolean blist_parser_error_occurred = FALSE; |
| 4349 | 842 |
| 843 static void blist_start_element_handler (GMarkupParseContext *context, | |
| 844 const gchar *element_name, | |
| 845 const gchar **attribute_names, | |
| 846 const gchar **attribute_values, | |
| 847 gpointer user_data, | |
| 848 GError **error) { | |
| 849 int i; | |
| 850 | |
| 851 if(!strcmp(element_name, "gaim")) { | |
| 852 blist_parser_current_tag = BLIST_TAG_GAIM; | |
| 853 } else if(!strcmp(element_name, "blist")) { | |
| 854 blist_parser_current_tag = BLIST_TAG_BLIST; | |
| 855 } else if(!strcmp(element_name, "group")) { | |
| 856 blist_parser_current_tag = BLIST_TAG_GROUP; | |
| 857 for(i=0; attribute_names[i]; i++) { | |
| 4444 | 858 if(!strcmp(attribute_names[i], "name")) { |
| 859 g_free(blist_parser_group_name); | |
| 4349 | 860 blist_parser_group_name = g_strdup(attribute_values[i]); |
| 4444 | 861 } |
| 4349 | 862 } |
| 863 if(blist_parser_group_name) { | |
| 4687 | 864 struct group *g = gaim_group_new(blist_parser_group_name); |
| 865 gaim_blist_add_group(g,NULL); | |
| 4349 | 866 } |
| 867 } else if(!strcmp(element_name, "person")) { | |
| 868 blist_parser_current_tag = BLIST_TAG_PERSON; | |
| 869 for(i=0; attribute_names[i]; i++) { | |
| 4444 | 870 if(!strcmp(attribute_names[i], "name")) { |
| 871 g_free(blist_parser_person_name); | |
| 4349 | 872 blist_parser_person_name = g_strdup(attribute_values[i]); |
| 4444 | 873 } |
| 4349 | 874 } |
| 875 } else if(!strcmp(element_name, "buddy")) { | |
| 876 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
| 877 for(i=0; attribute_names[i]; i++) { | |
| 4444 | 878 if(!strcmp(attribute_names[i], "account")) { |
| 879 g_free(blist_parser_account_name); | |
| 4349 | 880 blist_parser_account_name = g_strdup(attribute_values[i]); |
| 4444 | 881 } else if(!strcmp(attribute_names[i], "protocol")) { |
| 4349 | 882 blist_parser_account_protocol = atoi(attribute_values[i]); |
| 4444 | 883 } |
| 4349 | 884 } |
| 885 } else if(!strcmp(element_name, "name")) { | |
| 886 blist_parser_current_tag = BLIST_TAG_NAME; | |
| 887 } else if(!strcmp(element_name, "alias")) { | |
| 888 blist_parser_current_tag = BLIST_TAG_ALIAS; | |
| 889 } else if(!strcmp(element_name, "setting")) { | |
| 890 blist_parser_current_tag = BLIST_TAG_SETTING; | |
| 891 for(i=0; attribute_names[i]; i++) { | |
| 4444 | 892 if(!strcmp(attribute_names[i], "name")) { |
| 893 g_free(blist_parser_setting_name); | |
| 4349 | 894 blist_parser_setting_name = g_strdup(attribute_values[i]); |
| 4444 | 895 } |
| 4349 | 896 } |
| 897 } else if(!strcmp(element_name, "privacy")) { | |
| 898 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
| 899 } else if(!strcmp(element_name, "account")) { | |
| 900 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
| 901 for(i=0; attribute_names[i]; i++) { | |
| 902 if(!strcmp(attribute_names[i], "protocol")) | |
| 903 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 904 else if(!strcmp(attribute_names[i], "mode")) | |
| 905 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 4444 | 906 else if(!strcmp(attribute_names[i], "name")) { |
| 907 g_free(blist_parser_account_name); | |
| 4349 | 908 blist_parser_account_name = g_strdup(attribute_values[i]); |
| 4444 | 909 } |
| 4349 | 910 } |
| 911 } else if(!strcmp(element_name, "permit")) { | |
| 912 blist_parser_current_tag = BLIST_TAG_PERMIT; | |
| 913 } else if(!strcmp(element_name, "block")) { | |
| 914 blist_parser_current_tag = BLIST_TAG_BLOCK; | |
| 915 } else if(!strcmp(element_name, "ignore")) { | |
| 916 blist_parser_current_tag = BLIST_TAG_IGNORE; | |
| 917 } | |
| 918 } | |
| 919 | |
| 920 static void blist_end_element_handler(GMarkupParseContext *context, | |
| 921 const gchar *element_name, gpointer user_data, GError **error) { | |
| 922 if(!strcmp(element_name, "gaim")) { | |
| 923 } else if(!strcmp(element_name, "blist")) { | |
| 924 blist_parser_current_tag = BLIST_TAG_GAIM; | |
| 925 } else if(!strcmp(element_name, "group")) { | |
| 926 blist_parser_current_tag = BLIST_TAG_BLIST; | |
| 927 } else if(!strcmp(element_name, "person")) { | |
| 928 blist_parser_current_tag = BLIST_TAG_GROUP; | |
| 929 g_free(blist_parser_person_name); | |
| 930 blist_parser_person_name = NULL; | |
| 931 } else if(!strcmp(element_name, "buddy")) { | |
| 4491 | 932 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 933 blist_parser_account_protocol); |
| 4491 | 934 if(account) { |
| 4687 | 935 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); |
| 936 struct group *g = gaim_find_group(blist_parser_group_name); | |
| 937 gaim_blist_add_buddy(b,g,NULL); | |
| 4349 | 938 if(blist_parser_buddy_settings) { |
| 939 g_hash_table_destroy(b->settings); | |
| 940 b->settings = blist_parser_buddy_settings; | |
| 941 } | |
| 942 } | |
| 943 blist_parser_current_tag = BLIST_TAG_PERSON; | |
| 944 g_free(blist_parser_buddy_name); | |
| 945 blist_parser_buddy_name = NULL; | |
| 946 g_free(blist_parser_buddy_alias); | |
| 947 blist_parser_buddy_alias = NULL; | |
| 948 g_free(blist_parser_account_name); | |
| 949 blist_parser_account_name = NULL; | |
| 950 blist_parser_buddy_settings = NULL; | |
| 951 } else if(!strcmp(element_name, "name")) { | |
| 952 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
| 953 } else if(!strcmp(element_name, "alias")) { | |
| 954 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
| 955 } else if(!strcmp(element_name, "setting")) { | |
| 956 if(!blist_parser_buddy_settings) | |
| 957 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 958 g_str_equal, g_free, g_free); | |
| 959 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 960 g_hash_table_replace(blist_parser_buddy_settings, | |
| 961 g_strdup(blist_parser_setting_name), | |
| 962 g_strdup(blist_parser_setting_value)); | |
| 963 } | |
| 964 g_free(blist_parser_setting_name); | |
| 965 g_free(blist_parser_setting_value); | |
| 4720 | 966 blist_parser_setting_name = NULL; |
| 967 blist_parser_setting_value = NULL; | |
| 4349 | 968 blist_parser_current_tag = BLIST_TAG_BUDDY; |
| 969 } else if(!strcmp(element_name, "privacy")) { | |
| 970 blist_parser_current_tag = BLIST_TAG_GAIM; | |
| 971 } else if(!strcmp(element_name, "account")) { | |
| 4491 | 972 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 973 blist_parser_account_protocol); |
| 4491 | 974 if(account) { |
| 975 account->permdeny = blist_parser_privacy_mode; | |
| 4349 | 976 } |
| 977 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
| 978 g_free(blist_parser_account_name); | |
| 979 blist_parser_account_name = NULL; | |
| 980 } else if(!strcmp(element_name, "permit")) { | |
| 4491 | 981 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 982 blist_parser_account_protocol); |
| 4491 | 983 if(account) { |
| 984 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
| 4349 | 985 } |
| 4444 | 986 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
| 4442 | 987 g_free(blist_parser_buddy_name); |
| 4444 | 988 blist_parser_buddy_name = NULL; |
| 4349 | 989 } else if(!strcmp(element_name, "block")) { |
| 4491 | 990 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 991 blist_parser_account_protocol); |
| 4491 | 992 if(account) { |
| 993 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
| 4349 | 994 } |
| 4444 | 995 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
| 4442 | 996 g_free(blist_parser_buddy_name); |
| 4444 | 997 blist_parser_buddy_name = NULL; |
| 4349 | 998 } else if(!strcmp(element_name, "ignore")) { |
| 999 /* we'll apparently do something with this later */ | |
| 1000 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
| 1001 } | |
| 1002 } | |
| 1003 | |
| 1004 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 1005 gsize text_len, gpointer user_data, GError **error) { | |
| 1006 switch(blist_parser_current_tag) { | |
| 1007 case BLIST_TAG_NAME: | |
| 1008 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1009 break; | |
| 1010 case BLIST_TAG_ALIAS: | |
| 1011 blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 1012 break; | |
| 1013 case BLIST_TAG_PERMIT: | |
| 1014 case BLIST_TAG_BLOCK: | |
| 1015 case BLIST_TAG_IGNORE: | |
| 1016 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1017 break; | |
| 1018 case BLIST_TAG_SETTING: | |
| 1019 blist_parser_setting_value = g_strndup(text, text_len); | |
| 1020 break; | |
| 1021 default: | |
| 1022 break; | |
| 1023 } | |
| 1024 } | |
| 1025 | |
| 4439 | 1026 static void blist_error_handler(GMarkupParseContext *context, GError *error, |
| 1027 gpointer user_data) { | |
| 1028 blist_parser_error_occurred = TRUE; | |
| 1029 debug_printf("error parsing blist.xml: %s\n", error->message); | |
| 1030 } | |
| 1031 | |
| 4349 | 1032 static GMarkupParser blist_parser = { |
| 1033 blist_start_element_handler, | |
| 1034 blist_end_element_handler, | |
| 1035 blist_text_handler, | |
| 1036 NULL, | |
| 4439 | 1037 blist_error_handler |
| 4349 | 1038 }; |
| 1039 | |
| 1040 static gboolean gaim_blist_read(const char *filename) { | |
| 4441 | 1041 gchar *contents = NULL; |
| 4349 | 1042 gsize length; |
| 1043 GMarkupParseContext *context; | |
| 1044 GError *error = NULL; | |
| 4496 | 1045 |
| 1046 debug_printf("gaim_blist_read: reading %s\n", filename); | |
| 4349 | 1047 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
| 1048 debug_printf("error reading blist: %s\n", error->message); | |
| 1049 g_error_free(error); | |
| 1050 return FALSE; | |
| 1051 } | |
| 1052 | |
| 1053 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 1054 | |
| 1055 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 1056 g_markup_parse_context_free(context); | |
| 4441 | 1057 g_free(contents); |
| 4349 | 1058 return FALSE; |
| 1059 } | |
| 1060 | |
| 1061 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 1062 debug_printf("error parsing blist\n"); | |
| 1063 g_markup_parse_context_free(context); | |
| 4441 | 1064 g_free(contents); |
| 4349 | 1065 return FALSE; |
| 1066 } | |
| 1067 | |
| 1068 g_markup_parse_context_free(context); | |
| 4441 | 1069 g_free(contents); |
| 1070 | |
| 4439 | 1071 if(blist_parser_error_occurred) |
| 1072 return FALSE; | |
| 1073 | |
| 4496 | 1074 debug_printf("gaim_blist_read: finished reading %s\n", filename); |
| 1075 | |
| 4349 | 1076 return TRUE; |
| 1077 } | |
| 1078 | |
| 1079 void gaim_blist_load() { | |
| 1080 GSList *accts; | |
| 1081 char *user_dir = gaim_user_dir(); | |
| 1082 char *filename; | |
| 1083 char *msg; | |
| 1084 | |
| 4497 | 1085 blist_safe_to_write = TRUE; |
| 1086 | |
| 1087 if(!user_dir) | |
| 4349 | 1088 return; |
| 1089 | |
| 1090 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1091 | |
| 1092 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 1093 if(!gaim_blist_read(filename)) { | |
| 1094 msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 1095 "buddy list. It has not been loaded.")); | |
| 1096 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR); | |
| 1097 g_free(msg); | |
| 1098 } | |
| 4491 | 1099 } else if(g_slist_length(gaim_accounts)) { |
| 4349 | 1100 /* rob wants to inform the user that their buddy lists are |
| 1101 * being converted */ | |
| 1102 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
| 1103 "to a new format, which will now be located at %s"), | |
| 1104 filename); | |
| 1105 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO); | |
| 1106 g_free(msg); | |
| 1107 | |
| 1108 /* now, let gtk actually display the dialog before we start anything */ | |
| 1109 while(gtk_events_pending()) | |
| 1110 gtk_main_iteration(); | |
| 1111 | |
| 1112 /* read in the old lists, then save to the new format */ | |
| 4491 | 1113 for(accts = gaim_accounts; accts; accts = accts->next) { |
| 4349 | 1114 do_import(accts->data, NULL); |
| 1115 } | |
| 1116 gaim_blist_save(); | |
| 1117 } | |
| 1118 | |
| 1119 g_free(filename); | |
| 1120 } | |
| 1121 | |
| 1122 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 1123 gpointer user_data) { | |
| 1124 char *key_val = g_markup_escape_text(key, -1); | |
| 1125 char *data_val = g_markup_escape_text(data, -1); | |
| 1126 FILE *file = user_data; | |
| 1127 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1128 data_val); | |
| 1129 g_free(key_val); | |
| 1130 g_free(data_val); | |
| 1131 } | |
| 1132 | |
| 4491 | 1133 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) { |
| 4687 | 1134 GSList *accounts, *buds; |
| 4785 | 1135 GaimBlistNode *gnode,*bnode; |
| 4687 | 1136 struct group *group; |
| 1137 struct buddy *bud; | |
| 4349 | 1138 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
| 1139 fprintf(file, "<gaim version=\"1\">\n"); | |
| 1140 fprintf(file, "\t<blist>\n"); | |
| 1141 | |
| 4785 | 1142 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 1143 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 1144 continue; | |
| 1145 group = (struct group *)gnode; | |
| 4687 | 1146 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
| 1147 char *group_name = g_markup_escape_text(group->name, -1); | |
| 4349 | 1148 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); |
| 4785 | 1149 for(bnode = gnode->child; bnode; bnode = bnode->next) { |
| 1150 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1151 continue; | |
| 1152 bud = (struct buddy *)bnode; | |
| 4687 | 1153 if(!exp_acct || bud->account == exp_acct) { |
| 1154 char *bud_name = g_markup_escape_text(bud->name, -1); | |
| 4349 | 1155 char *bud_alias = NULL; |
| 4687 | 1156 char *acct_name = g_markup_escape_text(bud->account->username, -1); |
| 1157 if(bud->alias) | |
| 1158 bud_alias= g_markup_escape_text(bud->alias, -1); | |
| 4349 | 1159 fprintf(file, "\t\t\t<person name=\"%s\">\n", |
| 1160 bud_alias ? bud_alias : bud_name); | |
| 1161 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
| 4687 | 1162 "account=\"%s\">\n", bud->account->protocol, |
| 4349 | 1163 acct_name); |
| 1164 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 1165 if(bud_alias) { | |
| 1166 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
| 1167 bud_alias); | |
| 1168 } | |
| 4687 | 1169 g_hash_table_foreach(bud->settings, |
| 4349 | 1170 blist_print_buddy_settings, file); |
| 1171 fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 1172 fprintf(file, "\t\t\t</person>\n"); | |
| 1173 g_free(bud_name); | |
| 1174 g_free(bud_alias); | |
| 1175 g_free(acct_name); | |
| 1176 } | |
| 1177 } | |
| 1178 fprintf(file, "\t\t</group>\n"); | |
| 1179 g_free(group_name); | |
| 1180 } | |
| 1181 } | |
| 1182 | |
| 1183 fprintf(file, "\t</blist>\n"); | |
| 1184 fprintf(file, "\t<privacy>\n"); | |
| 1185 | |
| 4491 | 1186 for(accounts = gaim_accounts; accounts; accounts = accounts->next) { |
| 1187 struct gaim_account *account = accounts->data; | |
| 1188 char *acct_name = g_markup_escape_text(account->username, -1); | |
| 1189 if(!exp_acct || account == exp_acct) { | |
| 4349 | 1190 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " |
| 4491 | 1191 "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny); |
| 1192 for(buds = account->permit; buds; buds = buds->next) { | |
| 4349 | 1193 char *bud_name = g_markup_escape_text(buds->data, -1); |
| 1194 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 1195 g_free(bud_name); | |
| 1196 } | |
| 4491 | 1197 for(buds = account->deny; buds; buds = buds->next) { |
| 4349 | 1198 char *bud_name = g_markup_escape_text(buds->data, -1); |
| 1199 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 1200 g_free(bud_name); | |
| 1201 } | |
| 1202 fprintf(file, "\t\t</account>\n"); | |
| 1203 } | |
| 4491 | 1204 g_free(acct_name); |
| 4349 | 1205 } |
| 1206 | |
| 1207 fprintf(file, "\t</privacy>\n"); | |
| 1208 fprintf(file, "</gaim>\n"); | |
| 1209 } | |
| 1210 | |
| 1211 void gaim_blist_save() { | |
| 1212 FILE *file; | |
| 1213 char *user_dir = gaim_user_dir(); | |
| 1214 char *filename; | |
| 4891 | 1215 char *filename_real; |
| 4349 | 1216 |
| 1217 if(!user_dir) | |
| 1218 return; | |
| 4497 | 1219 if(!blist_safe_to_write) { |
| 1220 debug_printf("AHH!! tried to write the blist before we read it!\n"); | |
| 1221 return; | |
| 1222 } | |
| 1223 | |
| 4349 | 1224 file = fopen(user_dir, "r"); |
| 1225 if(!file) | |
| 1226 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 1227 else | |
| 1228 fclose(file); | |
| 1229 | |
| 4891 | 1230 filename = g_build_filename(user_dir, "blist.xml.save", NULL); |
| 4349 | 1231 |
| 1232 if((file = fopen(filename, "w"))) { | |
| 1233 gaim_blist_write(file, NULL); | |
| 1234 fclose(file); | |
| 1235 chmod(filename, S_IRUSR | S_IWUSR); | |
| 1236 } else { | |
| 1237 debug_printf("unable to write %s\n", filename); | |
| 1238 } | |
| 1239 | |
| 4891 | 1240 filename_real = g_build_filename(user_dir, "blist.xml", NULL); |
| 1241 | |
| 1242 if(rename(filename, filename_real) < 0) | |
| 1243 debug_printf("error renaming %s to %s\n", filename, filename_real); | |
| 1244 | |
| 1245 | |
| 4349 | 1246 g_free(filename); |
| 4891 | 1247 g_free(filename_real); |
| 4349 | 1248 } |
| 1249 | |
| 4491 | 1250 gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) { |
| 1251 GSList *d = account->permit; | |
| 4349 | 1252 char *n = g_strdup(normalize(who)); |
| 1253 while(d) { | |
| 4793 | 1254 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1255 break; |
| 1256 d = d->next; | |
| 1257 } | |
| 1258 g_free(n); | |
| 1259 if(!d) { | |
| 4491 | 1260 account->permit = g_slist_append(account->permit, g_strdup(who)); |
| 4349 | 1261 return TRUE; |
| 1262 } | |
| 1263 | |
| 1264 return FALSE; | |
| 1265 } | |
| 1266 | |
| 4491 | 1267 gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) { |
| 1268 GSList *d = account->permit; | |
| 4349 | 1269 char *n = g_strdup(normalize(who)); |
| 1270 while(d) { | |
| 4793 | 1271 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1272 break; |
| 1273 d = d->next; | |
| 1274 } | |
| 1275 g_free(n); | |
| 1276 if(d) { | |
| 4491 | 1277 account->permit = g_slist_remove(account->permit, d->data); |
| 4349 | 1278 g_free(d->data); |
| 1279 return TRUE; | |
| 1280 } | |
| 1281 return FALSE; | |
| 1282 } | |
| 1283 | |
| 4491 | 1284 gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) { |
| 1285 GSList *d = account->deny; | |
| 4349 | 1286 char *n = g_strdup(normalize(who)); |
| 1287 while(d) { | |
| 4793 | 1288 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1289 break; |
| 1290 d = d->next; | |
| 1291 } | |
| 1292 g_free(n); | |
| 1293 if(!d) { | |
| 4491 | 1294 account->deny = g_slist_append(account->deny, g_strdup(who)); |
| 4349 | 1295 return TRUE; |
| 1296 } | |
| 1297 | |
| 1298 return FALSE; | |
| 1299 } | |
| 1300 | |
| 4491 | 1301 gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) { |
| 1302 GSList *d = account->deny; | |
| 4349 | 1303 char *n = g_strdup(normalize(who)); |
| 1304 while(d) { | |
| 4793 | 1305 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1306 break; |
| 1307 d = d->next; | |
| 1308 } | |
| 1309 g_free(n); | |
| 1310 if(d) { | |
| 4491 | 1311 account->deny = g_slist_remove(account->deny, d->data); |
| 4349 | 1312 g_free(d->data); |
| 1313 return TRUE; | |
| 1314 } | |
| 1315 return FALSE; | |
| 1316 } | |
| 1317 | |
| 1318 void gaim_buddy_set_setting(struct buddy *b, const char *key, | |
| 1319 const char *value) { | |
| 1320 if(!b) | |
| 1321 return; | |
| 1322 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 1323 } | |
| 1324 | |
| 1325 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
| 1326 if(!b) | |
| 1327 return NULL; | |
| 1328 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 1329 } | |
| 4687 | 1330 |
| 1331 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 1332 { | |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1333 blist_ui_ops = ops; |
| 4687 | 1334 } |
|
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1335 |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1336 struct gaim_blist_ui_ops * |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1337 gaim_get_blist_ui_ops(void) |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1338 { |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1339 return blist_ui_ops; |
|
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1340 } |
| 4701 | 1341 |
| 1342 int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
| 1343 GaimBlistNode *node; | |
| 1344 int count = 0; | |
| 1345 | |
| 1346 if(!group) | |
| 1347 return 0; | |
| 1348 | |
| 1349 for(node = group->node.child; node; node = node->next) { | |
| 1350 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1351 struct buddy *b = (struct buddy *)node; | |
| 1352 if(b->account->gc || offline) | |
| 1353 count++; | |
| 1354 } | |
| 1355 } | |
| 1356 | |
| 1357 return count; | |
| 1358 } | |
| 1359 | |
| 1360 int gaim_blist_get_group_online_count(struct group *group) { | |
| 1361 GaimBlistNode *node; | |
| 1362 int count = 0; | |
| 1363 | |
| 1364 if(!group) | |
| 1365 return 0; | |
| 1366 | |
| 1367 for(node = group->node.child; node; node = node->next) { | |
| 1368 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1369 struct buddy *b = (struct buddy *)node; | |
| 1370 if(b->present) | |
| 1371 count++; | |
| 1372 } | |
| 1373 } | |
| 1374 | |
| 1375 return count; | |
| 1376 } | |
| 1377 | |
| 1378 |
