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