Пример #1
0
static void
set_commodity_value(xmlNodePtr node, gnc_commodity* com)
{
    if (g_strcmp0((char*) node->name, cmdty_fraction) == 0)
    {
        gint64 val;
        char *string;

        string = (char*) xmlNodeGetContent (node->xmlChildrenNode);
        if (string_to_gint64(string, &val))
        {
            gnc_commodity_set_fraction(com, val);
        }
        xmlFree (string);
    }
    else if (g_strcmp0((char*)node->name, cmdty_get_quotes) == 0)
    {
        gnc_commodity_set_quote_flag(com, TRUE);
    }
    else if (g_strcmp0((char*)node->name, cmdty_quote_source) == 0)
    {
        gnc_quote_source *source;
        char *string;

        string = (char*) xmlNodeGetContent (node->xmlChildrenNode);
        source = gnc_quote_source_lookup_by_internal(string);
        if (!source)
            source = gnc_quote_source_add_new(string, FALSE);
        gnc_commodity_set_quote_source(com, source);
        xmlFree (string);
    }
    else if (g_strcmp0((char*)node->name, cmdty_slots) == 0)
    {
        /* We ignore the results here */
        dom_tree_create_instance_slots(node, QOF_INSTANCE(com));
    }
    else
    {
        struct com_char_handler *mark;

        for (mark = com_handlers; mark->tag; mark++)
        {
            if (g_strcmp0(mark->tag, (char*)node->name) == 0)
            {
                gchar* val = dom_tree_to_text(node);
                g_strstrip(val);
                (mark->func)(com, val);
                g_free(val);
                break;
            }
        }
    }
}
Пример #2
0
gboolean
equals_node_val_vs_int(xmlNodePtr node, gint64 val)
{
    gchar *text;
    gint64 test_val;

    g_return_val_if_fail(node, FALSE);

    text = dom_tree_to_text(node);

    if (!string_to_gint64(text, &test_val))
    {
        g_free(text);
        return FALSE;
    }

    g_free(text);

    return val == test_val;
}
Пример #3
0
static const char*
node_and_commodity_equal (xmlNodePtr node, const gnc_commodity* com)
{
    xmlNodePtr mark;

    while (g_strcmp0 ((char*)node->name, "text") == 0)
        node = node->next;

    if (!check_dom_tree_version (node, "2.0.0"))
    {
        return "version wrong.  Not 2.0.0 or not there";
    }

    if (!node->name || g_strcmp0 ((char*)node->name, "gnc:commodity"))
    {
        return "Name of toplevel node is bad";
    }

    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
    {
        if (g_strcmp0 ((char*)mark->name, "text") == 0)
        {
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:space") == 0)
        {
            if (!equals_node_val_vs_string (
                    mark, gnc_commodity_get_namespace_compat (com)))
            {
                return "namespaces differ";
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:id") == 0)
        {
            if (!equals_node_val_vs_string (
                    mark, gnc_commodity_get_mnemonic (com)))
            {
                return "mnemonic differ";
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:name") == 0)
        {
            if (!equals_node_val_vs_string (
                    mark, gnc_commodity_get_fullname (com)))
            {
                return "names differ";
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:xcode") == 0)
        {
            if (!equals_node_val_vs_string (
                    mark, gnc_commodity_get_cusip (com)))
            {
                return "exchange codes differ";
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:fraction") == 0)
        {
            gchar* txt;
            gint64 type;

            txt = dom_tree_to_text (mark);

            if (!txt)
            {
                return "couldn't get fraction string";
            }

            else if (!string_to_gint64 (txt, &type))
            {
                g_free (txt);
                return "couldn't convert fraction string to int";
            }
            else if (type != gnc_commodity_get_fraction (com))
            {
                g_free (txt);
                return "fractions differ";
            }
            else
            {
                g_free (txt);
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "cmdty:slots") == 0)
        {
            if (!equals_node_val_vs_kvp_frame (mark,
                                               gnc_commodity_get_kvp_frame (com)))
                return "slots differ";
        }
        /* Legitimate tags which we don't yet have tests */
        else if (g_strcmp0 ((char*)mark->name, "cmdty:get_quotes") == 0 ||
                 g_strcmp0 ((char*)mark->name, "cmdty:quote_source") == 0 ||
                 g_strcmp0 ((char*)mark->name, "cmdty:quote_tz") == 0)
        {
            continue;
        }
        else
        {
            return "unknown node";
        }
    }

    return NULL;
}