コード例 #1
0
ファイル: plugin.c プロジェクト: plundstr/ngfd
static void
transform_properties_cb (NHook *hook, void *data, void *userdata)
{
    (void) hook;
    (void) data;
    (void) userdata;

    NCore        *core        = (NCore*) userdata;
    NContext     *context     = n_core_get_context (core);
    NProplist    *new_props   = NULL;
    NProplist    *props       = NULL;
    GList        *iter        = NULL;
    const char   *match_str   = NULL;
    ProfileEntry *entry       = NULL;
    NValue       *value       = NULL;
    gchar        *context_key = NULL;

    NCoreHookTransformPropertiesData *transform = (NCoreHookTransformPropertiesData*) data;

    N_DEBUG (LOG_CAT "transforming profile values for request '%s'",
        n_request_get_name (transform->request));

    new_props = n_proplist_new ();
    props = (NProplist*) n_request_get_properties (transform->request);
    for (iter = g_list_first (request_keys); iter; iter = g_list_next (iter)) {
        match_str = n_proplist_get_string (props, (gchar*) iter->data);
        if (!match_str)
            continue;

        entry = g_hash_table_lookup (profile_entries, match_str);
        if (!entry)
            continue;

        /* if this a fallback request, we don't care if there is existing
           target. otherwise check if the target exists. */

        if (!n_request_is_fallback (transform->request) &&
             n_proplist_has_key (props, entry->target))
            continue;

        context_key = construct_context_key (entry->profile, entry->key);
        value = (NValue*) n_context_get_value (context, context_key);

        if (value) {
            N_DEBUG (LOG_CAT "+ transforming profile key '%s' to target '%s'",
                entry->key, entry->target);
            n_proplist_set (new_props, entry->target, n_value_copy (value));
        }

        g_free (context_key);
    }

    n_proplist_merge (props, new_props);
    n_proplist_free (new_props);

    N_DEBUG (LOG_CAT "new properties:")
    n_proplist_dump (props);
}
コード例 #2
0
ファイル: test-value.c プロジェクト: plundstr/ngfd
END_TEST

START_TEST (test_copy)
{
    NValue *val = NULL;
    NValue *copy = NULL;
    copy = n_value_copy (val);
    fail_unless (copy == NULL);
    val = n_value_new ();
    copy = n_value_copy (val);
    fail_unless (copy == NULL);
    gboolean result = FALSE;
    const char *str = "ngf";

    /* copy string value */
    n_value_set_string (val, str);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy int value */
    n_value_set_int (val, -10);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy uint value */
    n_value_set_uint (val, 10);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy bool value */
    n_value_set_bool (val, TRUE);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

/* copy pointer value */
    n_value_set_pointer(val, val);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);	
	
    n_value_free (val);
    val = NULL;
    n_value_free (copy);
    copy = NULL;
}
コード例 #3
0
ファイル: context.c プロジェクト: matthewvogt/ngfd
void
n_context_set_value (NContext *context, const char *key,
                     NValue *value)
{
    NValue *old_value = NULL;

    if (!context || !key)
        return;

    old_value = n_value_copy (n_proplist_get (context->values, key));
    n_proplist_set (context->values, key, value);
    n_context_broadcast_change (context, key, old_value, value);
    n_value_free (old_value);
}