Example #1
0
const char *
kvp_frame_get_string(const KvpFrame *frame, const char *path)
{
    char *key = NULL;
    frame = get_trailer_or_null (frame, path, &key);
    return kvp_value_get_string(kvp_frame_get_slot (frame, key));
}
Example #2
0
const char *
gnc_tree_util_split_reg_template_get_fcred_entry (Split *split)
{
    kvp_frame *kvpf = xaccSplitGetSlots (split);

    return kvp_value_get_string(
               kvp_frame_get_slot_path (kvpf, "sched-xaction", "credit-formula", NULL));
}
Example #3
0
static /*@ null @*/ gpointer
get_string_val( gpointer pObject )
{
    slot_info_t* pInfo = (slot_info_t*)pObject;

    g_return_val_if_fail( pObject != NULL, NULL );

    if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_STRING )
    {
        return (gpointer)kvp_value_get_string( pInfo->pKvpValue );
    }
    else
    {
        return NULL;
    }
}
static void gnc_features_test_one(const gchar *key, KvpValue *value, gpointer data)
{
    GList **unknown_features;
    gchar *feature_desc;

    g_assert(data);
    unknown_features = (GList**) data;

    /* Check if this feature is in the known features list. */
    if (g_hash_table_lookup_extended (features_table, key, NULL, NULL))
        return;

    /* It is unknown, so add the description to the unknown features list: */
    feature_desc = kvp_value_get_string(value);
    g_assert(feature_desc);

    *unknown_features = g_list_prepend(*unknown_features, feature_desc);
}
Example #5
0
/* Determine whether this book uses trading accounts */
gboolean
qof_book_use_trading_accounts (const QofBook *book)
{
    const char *opt;
    kvp_value *kvp_val;

    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book),
                                       KVP_OPTION_PATH,
                                       OPTION_SECTION_ACCOUNTS,
                                       OPTION_NAME_TRADING_ACCOUNTS,
                                       NULL);
    if (kvp_val == NULL)
        return FALSE;

    opt = kvp_value_get_string (kvp_val);

    if (opt && opt[0] == 't' && opt[1] == 0)
        return TRUE;
    return FALSE;
}
static void
_get_sx_formula_value(GncSxInstance *instance, Split *template_split, gnc_numeric *numeric, GList **creation_errors, const char *formula_key)
{
    kvp_frame *split_kvpf;
    kvp_value *kvp_val;
    char *formula_str, *parseErrorLoc;

    split_kvpf = xaccSplitGetSlots(template_split);
    kvp_val = kvp_frame_get_slot_path(split_kvpf,
                                      GNC_SX_ID,
                                      formula_key,
                                      NULL);
    formula_str = kvp_value_get_string(kvp_val);
    if (formula_str != NULL && strlen(formula_str) != 0)
    {
        GHashTable *parser_vars = gnc_sx_instance_get_variables_for_parser(instance->variable_bindings);
        if (!gnc_exp_parser_parse_separate_vars(formula_str,
                                                numeric,
                                                &parseErrorLoc,
                                                parser_vars))
        {
            GString *err = g_string_new("");
            g_string_printf(err, "Error parsing SX [%s] key [%s]=formula [%s] at [%s]: %s",
                            xaccSchedXactionGetName(instance->parent->sx),
                            formula_key,
                            formula_str,
                            parseErrorLoc,
                            gnc_exp_parser_error_string());
            g_critical("%s", err->str);
            if (creation_errors != NULL)
                *creation_errors = g_list_append(*creation_errors, err);
            else
                g_string_free(err, TRUE);
        }

        if (parser_vars != NULL)
        {
            g_hash_table_destroy(parser_vars);
        }
    }
}
Example #7
0
static GValue*
gvalue_from_kvp_value (KvpValue *kval)
{
    GValue *val;
    gnc_numeric num;
    Timespec tm;
    GDate gdate;

    if (kval == NULL) return NULL;
    val = g_slice_new0 (GValue);

    switch (kval->type)
    {
	case KVP_TYPE_GINT64:
	    g_value_init (val, G_TYPE_INT64);
	    g_value_set_int64 (val, kvp_value_get_gint64 (kval));
	    break;
	case KVP_TYPE_DOUBLE:
	    g_value_init (val, G_TYPE_DOUBLE);
	    g_value_set_double (val, kvp_value_get_double (kval));
	    break;
	case KVP_TYPE_NUMERIC:
	    g_value_init (val, GNC_TYPE_NUMERIC);
	    num = kvp_value_get_numeric (kval);
	    g_value_set_boxed (val, &num);
	    break;
	case KVP_TYPE_STRING:
	    g_value_init (val, G_TYPE_STRING);
	    g_value_set_string (val, kvp_value_get_string (kval));
	    break;
	case KVP_TYPE_GUID:
	    g_value_init (val, GNC_TYPE_GUID);
	    g_value_set_boxed (val, kvp_value_get_guid (kval));
	    break;
	case KVP_TYPE_TIMESPEC:
	    g_value_init (val, GNC_TYPE_TIMESPEC);
	    tm = kvp_value_get_timespec (kval);
	    g_value_set_boxed (val, &tm);
	    break;
	case KVP_TYPE_BINARY:
	    PWARN ("Error! Don't use Kvp Binary!");
	    g_slice_free (GValue, val);
	    val = NULL;
	    break;
	case KVP_TYPE_GDATE:
	    g_value_init (val, G_TYPE_DATE);
	    gdate = kvp_value_get_gdate (kval);
	    g_value_set_boxed (val, &gdate);
	    break;
	case KVP_TYPE_GLIST:
	{
	    GList *gvalue_list = NULL;
	    GList *kvp_list = kvp_value_get_glist (kval);
	    g_list_foreach (kvp_list, (GFunc)gvalue_list_from_kvp_value, &gvalue_list);
	    g_value_init (val, GNC_TYPE_VALUE_LIST);
	    gvalue_list = g_list_reverse (gvalue_list);
	    g_value_set_boxed (val, gvalue_list);
	    break;
	}
/* No transfer of KVP frames outside of QofInstance-derived classes! */
	case KVP_TYPE_FRAME:
	    PWARN ("Error! Attempt to transfer KvpFrame!");
	default:
	    PWARN ("Error! Invalid KVP Transfer Request!");
	    g_slice_free (GValue, val);
	    val = NULL;
	    break;
    }
    return val;
}
Example #8
0
gchar*
kvp_value_to_string(const KvpValue *val)
{
    gchar *tmp1;
    gchar *tmp2;
    const gchar *ctmp;

    g_return_val_if_fail(val, NULL);

    switch (kvp_value_get_type(val))
    {
    case KVP_TYPE_GINT64:
        return g_strdup_printf("KVP_VALUE_GINT64(%" G_GINT64_FORMAT ")",
                               kvp_value_get_gint64(val));
        break;

    case KVP_TYPE_DOUBLE:
        return g_strdup_printf("KVP_VALUE_DOUBLE(%g)",
                               kvp_value_get_double(val));
        break;

    case KVP_TYPE_NUMERIC:
        tmp1 = gnc_numeric_to_string(kvp_value_get_numeric(val));
        tmp2 = g_strdup_printf("KVP_VALUE_NUMERIC(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_STRING:
        tmp1 = kvp_value_get_string (val);
        return g_strdup_printf("KVP_VALUE_STRING(%s)", tmp1 ? tmp1 : "");
        break;

    case KVP_TYPE_GUID:
        gchar guidstr[GUID_ENCODING_LENGTH+1];
        guid_to_string_buff(kvp_value_get_guid(val),guidstr);
        tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr);
        return tmp2;
        break;

    case KVP_TYPE_TIMESPEC:
        tmp1 = g_new0 (char, 40);
        gnc_timespec_to_iso8601_buff (kvp_value_get_timespec (val), tmp1);
        tmp2 = g_strdup_printf("KVP_VALUE_TIMESPEC(%s)", tmp1);
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_BINARY:
    {
        guint64 len;
        void *data;
        data = kvp_value_get_binary(val, &len);
        tmp1 = binary_to_string(data, len);
        return g_strdup_printf("KVP_VALUE_BINARY(%s)", tmp1 ? tmp1 : "");
    }
    break;

    case KVP_TYPE_GLIST:
        tmp1 = kvp_value_glist_to_string(kvp_value_get_glist(val));
        tmp2 = g_strdup_printf("KVP_VALUE_GLIST(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_FRAME:
        tmp1 = kvp_frame_to_string(kvp_value_get_frame(val));
        tmp2 = g_strdup_printf("KVP_VALUE_FRAME(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_GDATE:
        return g_strdup_printf("KVP_VALUE_GDATE(%04d-%02d-%02d)",
                               g_date_get_year(&val->value.gdate),
                               g_date_get_month(&val->value.gdate),
                               g_date_get_day(&val->value.gdate));
    default:
	break;
    }
    g_assert(FALSE); /* must not be reached */
    return g_strdup("");
}
static void
add_kvp_value_node(xmlNodePtr node, gchar *tag, kvp_value* val)
{
    xmlNodePtr val_node;
    gchar *tmp_str1;
    kvp_value_t kvp_type;

    kvp_type = kvp_value_get_type(val);

    if (kvp_type == KVP_TYPE_STRING)
        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, BAD_CAST kvp_value_get_string(val));
    else if (kvp_type == KVP_TYPE_TIMESPEC)
        val_node = NULL;
    else if (kvp_type == KVP_TYPE_GDATE)
    {
        GDate d = kvp_value_get_gdate(val);
        val_node = gdate_to_dom_tree(tag, &d);
        xmlAddChild (node, val_node);
    }
    else
        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL);

    switch (kvp_value_get_type(val))
    {
    case KVP_TYPE_GINT64:
        add_text_to_node(val_node, "integer",
                         g_strdup_printf("%" G_GINT64_FORMAT,
                                         kvp_value_get_gint64(val)));
        break;
    case KVP_TYPE_DOUBLE:
        add_text_to_node(val_node, "double",
                         double_to_string(kvp_value_get_double(val)));
        break;
    case KVP_TYPE_NUMERIC:
        add_text_to_node(val_node, "numeric",
                         gnc_numeric_to_string(kvp_value_get_numeric(val)));
        break;
    case KVP_TYPE_STRING:
        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string");
        break;
    case KVP_TYPE_GUID:
        /* THREAD-UNSAFE */
        add_text_to_node(val_node, "guid",
                         g_strdup(guid_to_string(kvp_value_get_guid(val))));
        break;
    case KVP_TYPE_TIMESPEC:
    {
        Timespec ts = kvp_value_get_timespec (val);

        val_node = timespec_to_dom_tree (tag, &ts);
        xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
        xmlAddChild (node, val_node);
    }
    break;
    case KVP_TYPE_GDATE:
        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "gdate");
        break;
    case KVP_TYPE_BINARY:
    {
        guint64 size;
        void *binary_data = kvp_value_get_binary(val, &size);
        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "binary");
        g_return_if_fail(binary_data);
        tmp_str1 = binary_to_string(binary_data, size);
        xmlNodeSetContent(val_node, BAD_CAST tmp_str1);
        g_free(tmp_str1);
    }
    break;
    case KVP_TYPE_GLIST:
    {
        GList *cursor;

        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list");
        for (cursor = kvp_value_get_glist(val); cursor; cursor = cursor->next)
        {
            kvp_value *val = (kvp_value*)cursor->data;
            add_kvp_value_node(val_node, "slot:value", val);
        }
    }

    break;
    case KVP_TYPE_FRAME:
    {
        kvp_frame *frame;

        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "frame");

        frame = kvp_value_get_frame (val);
        if (!frame || !kvp_frame_get_hash (frame))
            break;

        g_hash_table_foreach_sorted(kvp_frame_get_hash(frame),
                                    add_kvp_slot, val_node, (GCompareFunc)strcmp);
    }
    break;

    }
}
Example #10
0
static gint
_get_vars_helper(Transaction *txn, void *var_hash_data)
{
    GHashTable *var_hash = (GHashTable*)var_hash_data;
    GList *split_list;
    kvp_frame *kvpf;
    kvp_value *kvp_val;
    Split *s;
    char *str;
    gnc_commodity *first_cmdty = NULL;

    split_list = xaccTransGetSplitList(txn);
    if (split_list == NULL)
    {
        return 1;
    }

    for ( ; split_list; split_list = split_list->next)
    {
        gnc_commodity *split_cmdty = NULL;
        GncGUID *acct_guid;
        Account *acct;

        s = (Split*)split_list->data;
        kvpf = xaccSplitGetSlots(s);
        kvp_val = kvp_frame_get_slot_path(kvpf,
                                          GNC_SX_ID,
                                          GNC_SX_ACCOUNT,
                                          NULL);
        acct_guid = kvp_value_get_guid(kvp_val);
        acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
        split_cmdty = xaccAccountGetCommodity(acct);
        if (first_cmdty == NULL)
        {
            first_cmdty = split_cmdty;
        }

        if (! gnc_commodity_equal(split_cmdty, first_cmdty))
        {
            GncSxVariable *var;
            GString *var_name;
            const gchar *split_mnemonic, *first_mnemonic;

            var_name = g_string_sized_new(16);
            split_mnemonic = gnc_commodity_get_mnemonic(split_cmdty);
            first_mnemonic = gnc_commodity_get_mnemonic(first_cmdty);
            g_string_printf(var_name, "%s -> %s",
                            split_mnemonic ? split_mnemonic : "(null)",
                            first_mnemonic ? first_mnemonic : "(null)");
            var = gnc_sx_variable_new(g_strdup(var_name->str));
            g_hash_table_insert(var_hash, g_strdup(var->name), var);
            g_string_free(var_name, TRUE);
        }

        // existing... ------------------------------------------
        kvp_val = kvp_frame_get_slot_path(kvpf,
                                          GNC_SX_ID,
                                          GNC_SX_CREDIT_FORMULA,
                                          NULL);
        if (kvp_val != NULL)
        {
            str = kvp_value_get_string(kvp_val);
            if (str && strlen(str) != 0)
            {
                gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
            }
        }

        kvp_val = kvp_frame_get_slot_path(kvpf,
                                          GNC_SX_ID,
                                          GNC_SX_DEBIT_FORMULA,
                                          NULL);
        if (kvp_val != NULL)
        {
            str = kvp_value_get_string(kvp_val);
            if (str && strlen(str) != 0)
            {
                gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
            }
        }
    }

    return 0;
}
Example #11
0
/* Set the option with the default KvpValue,
manipulate the option in the supplied callback routine
then set the value of the option into the KvpValue
in the configuration frame. */
static void
config_foreach_cb (const char *key, KvpValue *value, gpointer data)
{
    QofBackendOption option;
    gint64 int64;
    double db;
    gnc_numeric num;
    Timespec ts;
    gchar *parent;
    struct config_iterate *helper;

    g_return_if_fail(key || value || data);
    helper = (struct config_iterate*)data;
    if (!helper->recursive)
    {
        PERR (" no parent frame");
        return;
    }
    // skip the presets.
    if (0 == safe_strcmp(key, QOF_CONFIG_DESC))
    {
        return;
    }
    if (0 == safe_strcmp(key, QOF_CONFIG_TIP))
    {
        return;
    }
    ENTER (" key=%s", key);
    option.option_name = key;
    option.type = kvp_value_get_type(value);
    if (!option.type)
    {
        return;
    }
    switch (option.type)
    {
        /* set the KvpFrame value into the option */
    case KVP_TYPE_GINT64   :
    {
        int64 = kvp_value_get_gint64(value);
        option.value = (gpointer) & int64;
        break;
    }
    case KVP_TYPE_DOUBLE   :
    {
        db = kvp_value_get_double(value);
        option.value = (gpointer) & db;
        break;
    }
    case KVP_TYPE_NUMERIC  :
    {
        num = kvp_value_get_numeric(value);
        option.value = (gpointer) & num;
        break;
    }
    case KVP_TYPE_STRING   :
    {
        option.value = (gpointer)kvp_value_get_string(value);
        break;
    }
    case KVP_TYPE_TIMESPEC :
    {
        ts = kvp_value_get_timespec(value);
        option.value = (gpointer) & ts;
        break;
    }
    case KVP_TYPE_GUID     :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_BINARY   :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_GLIST    :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_FRAME    :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_GDATE    :
    {
        break;  /* unsupported */
    }
    }
    parent = g_strdup_printf("/%s/%s", QOF_CONFIG_DESC, key);
    option.description = kvp_frame_get_string(helper->recursive, parent);
    g_free(parent);
    parent = g_strdup_printf("/%s/%s", QOF_CONFIG_TIP, key);
    option.tooltip = kvp_frame_get_string(helper->recursive, parent);
    g_free(parent);
    helper->count++;
    /* manipulate the option */
    helper->fcn (&option, helper->data);
    switch (option.type)
    {
        /* set the option value into the KvpFrame */
    case KVP_TYPE_GINT64   :
    {
        kvp_frame_set_gint64(helper->recursive, key,
                             (*(gint64*)option.value));
        break;
    }
    case KVP_TYPE_DOUBLE   :
    {
        kvp_frame_set_double(helper->recursive, key,
                             (*(double*)option.value));
        break;
    }
    case KVP_TYPE_NUMERIC  :
    {
        kvp_frame_set_numeric(helper->recursive, key,
                              (*(gnc_numeric*)option.value));
        break;
    }
    case KVP_TYPE_STRING   :
    {
        kvp_frame_set_string(helper->recursive, key,
                             (gchar*)option.value);
        break;
    }
    case KVP_TYPE_TIMESPEC :
    {
        kvp_frame_set_timespec(helper->recursive, key,
                               (*(Timespec*)option.value));
        break;
    }
    case KVP_TYPE_GUID     :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_BINARY   :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_GLIST    :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_FRAME    :
    {
        break;  /* unsupported */
    }
    case KVP_TYPE_GDATE    :
    {
        break;  /* unsupported */
    }
    }
    LEAVE (" ");
}
Example #12
0
static void
add_kvp_value_node(xmlNodePtr node, gchar *tag, KvpValue* val)
{
    xmlNodePtr val_node;
    kvp_value_t kvp_type;

    kvp_type = kvp_value_get_type(val);

    if (kvp_type == KVP_TYPE_STRING)
    {
	gchar *newstr = g_strdup (kvp_value_get_string(val));
        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag,
				   checked_char_cast (newstr));
	g_free (newstr);
    }
    else if (kvp_type == KVP_TYPE_TIMESPEC)
        val_node = NULL;
    else if (kvp_type == KVP_TYPE_GDATE)
    {
        GDate d = kvp_value_get_gdate(val);
        val_node = gdate_to_dom_tree(tag, &d);
        xmlAddChild (node, val_node);
    }
    else
        val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, NULL);

    switch (kvp_value_get_type(val))
    {
    case KVP_TYPE_GINT64:
        add_text_to_node(val_node, "integer",
                         g_strdup_printf("%" G_GINT64_FORMAT,
                                         kvp_value_get_gint64(val)));
        break;
    case KVP_TYPE_DOUBLE:
        add_text_to_node(val_node, "double",
                         double_to_string(kvp_value_get_double(val)));
        break;
    case KVP_TYPE_NUMERIC:
        add_text_to_node(val_node, "numeric",
                         gnc_numeric_to_string(kvp_value_get_numeric(val)));
        break;
    case KVP_TYPE_STRING:
        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string");
        break;
    case KVP_TYPE_GUID:
    {
        gchar guidstr[GUID_ENCODING_LENGTH+1];
        guid_to_string_buff(kvp_value_get_guid(val), guidstr);
        add_text_to_node(val_node, "guid", guidstr);
        break;
    }
    case KVP_TYPE_TIMESPEC:
    {
        Timespec ts = kvp_value_get_timespec (val);

        val_node = timespec_to_dom_tree (tag, &ts);
        xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
        xmlAddChild (node, val_node);
    }
    break;
    case KVP_TYPE_GDATE:
        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "gdate");
    break;
    case KVP_TYPE_GLIST:
    {
        GList *cursor;

        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list");
        for (cursor = kvp_value_get_glist(val); cursor; cursor = cursor->next)
        {
            KvpValue *val = (KvpValue*)cursor->data;
            add_kvp_value_node(val_node, "slot:value", val);
        }
    }

    break;
    case KVP_TYPE_FRAME:
    {
        KvpFrame *frame;
        const char ** keys;
        unsigned int i;

        xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "frame");

        frame = kvp_value_get_frame (val);
        if (!frame)
            break;

        keys = kvp_frame_get_keys(frame);
        for (i = 0; keys[i]; ++i)
            add_kvp_slot(keys[i], kvp_frame_get_value(frame, keys[i]), val_node);
        g_free(keys);
    }
    break;
    default:
	break;
    }
}