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