|
From: <svn...@op...> - 2009-11-02 13:52:27
|
Author: dgollub Date: Mon Nov 2 14:52:11 2009 New Revision: 5916 URL: http://www.opensync.org/changeset/5916 Log: Validate External Plugin Configuration XML files against OSYNC_EXTERNAL_PLUGIN_CONFIG_SCHEMA Modified: trunk/opensync/plugin/opensync_plugin_env.c trunk/opensync/plugin/opensync_plugin_env_internals.h trunk/opensync/plugin/opensync_plugin_env_private.h Modified: trunk/opensync/plugin/opensync_plugin_env.c ============================================================================== --- trunk/opensync/plugin/opensync_plugin_env.c Mon Nov 2 14:02:51 2009 (r5915) +++ trunk/opensync/plugin/opensync_plugin_env.c Mon Nov 2 14:52:11 2009 (r5916) @@ -77,6 +77,10 @@ osync_module_unref(env->modules->data); env->modules = osync_list_remove(env->modules, env->modules->data); } + + if (env->schemapath) + osync_free(env->schemapath); + osync_free(env); } @@ -229,10 +233,19 @@ return FALSE; } +#ifdef OPENSYNC_UNITTESTING +void osync_plugin_env_set_schemapath(OSyncPluginEnv *env, const char *schemapth) +{ + env->schemapth = osync_strdup(schempath); +} +#endif /* OPENSYNC_UNITTESTING */ + osync_bool osync_plugin_env_load_module_xml(OSyncPluginEnv *env, const char *filename, OSyncError **error) { OSyncModule *module = NULL; int version = 0; + const char *schemapath = env->schemapath ? env->schemapath : OPENSYNC_SCHEMASDIR; + char *schemafile = NULL; gchar *name = NULL, *longname = NULL, *description = NULL, *command = NULL; xmlChar *version_str = NULL; xmlDocPtr doc; @@ -245,6 +258,15 @@ if (!osync_xml_open_file(&doc, &cur, filename, "ExternalPlugin", error)) goto error; + /* Validate external plugin configuration file */ + schemafile = osync_strdup_printf("%s%c%s", schemapath, G_DIR_SEPARATOR, OSYNC_EXTERNAL_PLUGIN_CONFIG_SCHEMA); + if (!osync_xml_validate_document(doc, schemafile)) { + osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Plugin configuration file is not valid! %s", schemafile); + osync_free(schemafile); + goto error; + } + osync_free(schemafile); + version_str = xmlGetProp(cur->parent, BAD_CAST "version"); if (version_str) { version = atoi((const char *) version_str); Modified: trunk/opensync/plugin/opensync_plugin_env_internals.h ============================================================================== --- trunk/opensync/plugin/opensync_plugin_env_internals.h Mon Nov 2 14:02:51 2009 (r5915) +++ trunk/opensync/plugin/opensync_plugin_env_internals.h Mon Nov 2 14:52:11 2009 (r5916) @@ -30,6 +30,8 @@ /*@{*/ +#define OSYNC_EXTERNAL_PLUGIN_CONFIG_SCHEMA "external_plugin_config.xsd" + /** @brief Loads a module into the plugin environment * * @param env Pointer to a plugin environment @@ -72,6 +74,19 @@ */ OSYNC_TEST_EXPORT unsigned int osync_plugin_env_num_plugins(OSyncPluginEnv *env); + +#ifdef OPENSYNC_UNITTESTING +/** @brief Change the schema path to a non-default directory + * + * XXX: This is only intended for unittesting. + * + * @param env Pointer to a OSyncPluginEnv environment + * @param schemapath Path to the non-default schema-path + * + */ +OSYNC_TEST_EXPORT void osync_plugin_env_set_schemapath(OSyncPluginEnv *env, const char *schemapth); +#endif /* OPENSYNC_UNITTESTING */ + /*@}*/ #endif /* _OPENSYNC_PLUGIN_ENV_INTERNALS_H_ */ Modified: trunk/opensync/plugin/opensync_plugin_env_private.h ============================================================================== --- trunk/opensync/plugin/opensync_plugin_env_private.h Mon Nov 2 14:02:51 2009 (r5915) +++ trunk/opensync/plugin/opensync_plugin_env_private.h Mon Nov 2 14:52:11 2009 (r5916) @@ -35,6 +35,9 @@ GModule *current_module; + /** Non-default schemapath, only for unit-testing */ + char *schemapath; + int ref_count; }; |