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); }
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); }