END_TEST START_TEST (test_get_params) { NPlugin *plugin = NULL; /* NULL checking */ fail_unless (n_plugin_get_params (plugin) == NULL); plugin = g_new0 (NPlugin, 1); fail_unless (plugin != NULL); NProplist *proplist = NULL; proplist = n_proplist_new (); plugin->params = proplist; const NProplist *receivedParams = NULL; const char *key1 = "key1"; n_proplist_set_int (proplist, key1, -100); receivedParams = n_plugin_get_params (plugin); fail_unless (receivedParams != NULL); fail_unless (n_proplist_match_exact (receivedParams, proplist) == TRUE); n_proplist_free (proplist); proplist = NULL; g_free (plugin); plugin = NULL; }
static NProplist* n_core_load_params (NCore *core, const char *plugin_name) { g_assert (core != NULL); g_assert (plugin_name != NULL); NProplist *proplist = NULL; GKeyFile *keyfile = NULL; gchar *filename = NULL; gchar *full_path = NULL; gchar **keys = NULL; gchar **iter = NULL; GError *error = NULL; gchar *value = NULL; filename = g_strdup_printf ("%s.ini", plugin_name); full_path = g_build_filename (core->conf_path, PLUGIN_CONF_PATH, filename, NULL); keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, full_path, G_KEY_FILE_NONE, &error)) { if (error->code & G_KEY_FILE_ERROR_NOT_FOUND) { N_WARNING (LOG_CAT "problem with configuration file '%s': %s", filename, error->message); } goto done; } keys = g_key_file_get_keys (keyfile, plugin_name, NULL, NULL); if (!keys) { N_WARNING (LOG_CAT "no group '%s' within configuration file '%s'", plugin_name, filename); goto done; } proplist = n_proplist_new (); for (iter = keys; *iter; ++iter) { if ((value = g_key_file_get_string (keyfile, plugin_name, *iter, NULL)) == NULL) continue; N_DEBUG (LOG_CAT "+ plugin parameter: %s = %s", *iter, value); n_proplist_set_string (proplist, *iter, value); g_free (value); } g_strfreev (keys); done: if (error) g_error_free (error); if (keyfile) g_key_file_free (keyfile); g_free (full_path); g_free (filename); return proplist; }
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); }
NContext* n_context_new () { NContext *context = NULL; context = g_new0 (NContext, 1); context->values = n_proplist_new (); return context; }
/* Read and create proplist from a custom file */ static NProplist* ffm_read_props(const char *file_name) { NProplist *proplist = NULL; GKeyFile *keyfile = NULL; gchar **keys = NULL; gchar **iter = NULL; GError *error = NULL; gchar *value = NULL; if (!file_name) { N_DEBUG (LOG_CAT "NULL file_name parameter, cannot read props"); return NULL; } keyfile = g_key_file_new (); N_DEBUG (LOG_CAT "Loading properties from file \"%s\"", file_name); if (!g_key_file_load_from_file (keyfile, file_name, G_KEY_FILE_NONE, &error)) { N_WARNING (LOG_CAT "problem with configuration file" " '%s': %s", file_name, error->message); goto done; } keys = g_key_file_get_keys (keyfile, FFM_PLUGIN_NAME, NULL, NULL); if (!keys) { N_WARNING (LOG_CAT "no group '%s' within configuration file " "'%s'", FFM_PLUGIN_NAME, file_name); goto done; } proplist = n_proplist_new (); for (iter = keys; *iter; ++iter) { if ((value = g_key_file_get_string (keyfile, FFM_PLUGIN_NAME, *iter, NULL)) == NULL) continue; N_DEBUG (LOG_CAT "+ plugin parameter: %s = %s", *iter, value); n_proplist_set_string (proplist, *iter, value); g_free (value); } g_strfreev (keys); done: if (error) g_error_free (error); if (keyfile) g_key_file_free (keyfile); return proplist; }