Exemple #1
0
double
kvp_frame_get_double(const KvpFrame *frame, const char *path)
{
    char *key = NULL;
    frame = get_trailer_or_null (frame, path, &key);
    return kvp_value_get_double(kvp_frame_get_slot (frame, key));
}
Exemple #2
0
static /*@ dependent @*//*@ null @*/ gpointer
get_double_val( gpointer pObject )
{
    slot_info_t* pInfo = (slot_info_t*)pObject;
    static double d_val;

    g_return_val_if_fail( pObject != NULL, NULL );

    if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_DOUBLE )
    {
        d_val = kvp_value_get_double( pInfo->pKvpValue );
        return (gpointer)&d_val;
    }
    else
    {
        return NULL;
    }
}
Exemple #3
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;
}
Exemple #4
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;

    }
}
Exemple #6
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 (" ");
}
Exemple #7
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;
    }
}