Changeset d5c55ac for storage_xml.c


Ignore:
Timestamp:
2015-02-22T21:19:21Z (5 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
273949d
Parents:
5ff4618
git-author:
dequis <dx@…> (23-01-15 07:01:05)
git-committer:
dequis <dx@…> (22-02-15 21:19:21)
Message:

storage_xml: replace hackish code with a GHashTableIter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r5ff4618 rd5c55ac  
    259259
    260260
    261 static gboolean xml_generate_nick(gpointer key, gpointer value, gpointer data);
    262261static void xml_generate_settings(struct xt_node *cur, set_t **head);
    263262
     
    292291
    293292        for (acc = irc->b->accounts; acc; acc = acc->next) {
     293                GHashTableIter iter;
     294                gpointer key, value;
    294295                unsigned char *pass_cr;
    295296                char *pass_b64;
     
    312313                g_free(pass_b64);
    313314
    314                 /* This probably looks pretty strange. g_hash_table_foreach
    315                    is quite a PITA already (but it can't get much better in
    316                    C without using #define, I'm afraid), and it
    317                    doesn't seem to be possible to abort the foreach on write
    318                    errors, so instead let's use the _find function and
    319                    return TRUE on write errors. Which means, if we found
    320                    something, there was an error. :-) */
    321                 g_hash_table_find(acc->nicks, xml_generate_nick, cur);
     315                g_hash_table_iter_init(&iter, acc->nicks);
     316                while (g_hash_table_iter_next(&iter, &key, &value)) {
     317                        struct xt_node *node = xt_new_node("buddy", NULL, NULL);
     318                        xt_add_attr(node, "handle", key);
     319                        xt_add_attr(node, "nick", value);
     320                        xt_add_child(cur, node);
     321                }
    322322
    323323                xml_generate_settings(cur, &acc->set);
     
    343343
    344344        return root;
    345 }
    346 
    347 static gboolean xml_generate_nick(gpointer key, gpointer value, gpointer data)
    348 {
    349         struct xt_node *node = xt_new_node("buddy", NULL, NULL);
    350 
    351         xt_add_attr(node, "handle", key);
    352         xt_add_attr(node, "nick", value);
    353         xt_add_child((struct xt_node *) data, node);
    354 
    355         return FALSE;
    356345}
    357346
Note: See TracChangeset for help on using the changeset viewer.