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