From: <svn...@op...> - 2009-11-01 14:33:08
|
Author: henrik Date: Sun Nov 1 15:32:43 2009 New Revision: 5896 URL: http://www.opensync.org/changeset/5896 Log: Plugins of type OSYNC_START_TYPE_EXTERNAL needs to be able to spawn an external command to run the actual plugin code. This patch allows a member to set an ExternalCommand in the plugin configuration file. This command will be executed by the proxy to start up the external process. The external_command should be a string in printf format, with one %s. Before the command is executed, a variant of printf will be called to replace the %s with the path to the plugin pipe. Example: <ExternalPlugin> <ExternalCommand>thunderbird -mozilla-sync %s</ExternalCommand> </ExternalPlugin> Added to public API: osync_plugin_config_get_externalplugin osync_plugin_config_set_externalplugin osync_plugin_externalplugin_new osync_plugin_externalplugin_unref osync_plugin_externalplugin_ref osync_plugin_externalplugin_get_external_command osync_plugin_externalplugin_set_external_command (as well as the changed format for the plugin configuration file) Changed internal interface: From osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, OSyncError **error) To osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error) Added: trunk/opensync/plugin/opensync_plugin_externalplugin.c trunk/opensync/plugin/opensync_plugin_externalplugin.h trunk/opensync/plugin/opensync_plugin_externalplugin_private.h Modified: trunk/misc/schemas/plugin_config.xsd trunk/opensync.sym trunk/opensync/CMakeLists.txt trunk/opensync/client/opensync_client_proxy.c trunk/opensync/client/opensync_client_proxy_internals.h trunk/opensync/engine/opensync_engine.c trunk/opensync/group/opensync_member.c trunk/opensync/group/opensync_member.h trunk/opensync/group/opensync_member_internals.h trunk/opensync/opensync-plugin.h trunk/opensync/opensync.h trunk/opensync/plugin/opensync_plugin_config.c trunk/opensync/plugin/opensync_plugin_config.h trunk/opensync/plugin/opensync_plugin_config_private.h trunk/tests/client-tests/check_proxy.c Modified: trunk/misc/schemas/plugin_config.xsd ============================================================================== --- trunk/misc/schemas/plugin_config.xsd Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/misc/schemas/plugin_config.xsd Sun Nov 1 15:32:43 2009 (r5896) @@ -9,6 +9,7 @@ <xsd:element maxOccurs="1" minOccurs="0" name="Connection" type="Connection"/> <xsd:element maxOccurs="1" minOccurs="0" name="Localization" type="Localization"/> <xsd:element maxOccurs="1" minOccurs="0" name="Resources" type="Resources"/> + <xsd:element maxOccurs="1" minOccurs="0" name="ExternalPlugin" type="ExternalPlugin"/> </xsd:sequence> <xsd:attribute name="version" type="xsd:string"/> </xsd:complexType> @@ -164,4 +165,10 @@ </xsd:all> </xsd:complexType> + <xsd:complexType name="ExternalPlugin"> + <xsd:all> + <xsd:element maxOccurs="1" minOccurs="1" name="ExternalCommand" type="xsd:string" /> + </xsd:all> + </xsd:complexType> + </xsd:schema> Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync.sym Sun Nov 1 15:32:43 2009 (r5896) @@ -511,6 +511,7 @@ osync_plugin_config_get_advancedoptions osync_plugin_config_get_authentication osync_plugin_config_get_connection +osync_plugin_config_get_externalplugin osync_plugin_config_get_localization osync_plugin_config_get_resources osync_plugin_config_is_supported @@ -520,6 +521,7 @@ osync_plugin_config_remove_resource osync_plugin_config_set_authentication osync_plugin_config_set_connection +osync_plugin_config_set_externalplugin osync_plugin_config_set_localization osync_plugin_config_set_supported osync_plugin_config_unref @@ -566,6 +568,11 @@ osync_plugin_env_ref osync_plugin_env_register_plugin osync_plugin_env_unref +osync_plugin_externalplugin_get_external_command +osync_plugin_externalplugin_new +osync_plugin_externalplugin_ref +osync_plugin_externalplugin_set_external_command +osync_plugin_externalplugin_unref osync_plugin_finalize osync_plugin_get_config_type osync_plugin_get_data Modified: trunk/opensync/CMakeLists.txt ============================================================================== --- trunk/opensync/CMakeLists.txt Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/CMakeLists.txt Sun Nov 1 15:32:43 2009 (r5896) @@ -60,6 +60,7 @@ plugin/opensync_plugin_info.c plugin/opensync_plugin_localization.c plugin/opensync_plugin_resource.c + plugin/opensync_plugin_externalplugin.c plugin/opensync_objtype_sink.c version/opensync_version.c xmlformat/opensync_xmlfield.c Modified: trunk/opensync/client/opensync_client_proxy.c ============================================================================== --- trunk/opensync/client/opensync_client_proxy.c Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/client/opensync_client_proxy.c Sun Nov 1 15:32:43 2009 (r5896) @@ -952,7 +952,7 @@ return proxy->member; } -osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, OSyncError **error) +osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error) { OSyncQueue *read1 = NULL; OSyncQueue *read2 = NULL; @@ -1080,6 +1080,22 @@ goto error; } else { name = osync_strdup_printf("%s%cpluginpipe", path, G_DIR_SEPARATOR); + + if (external_command) { + char *command = osync_strdup_printf(external_command, name); + osync_trace(TRACE_INTERNAL, "g_spawn_command_line_async(%s)", command); + GError *gerror = NULL; + gboolean f = g_spawn_command_line_async(command, &gerror); + if (!f) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to g_spawn_command_line_async(%s): %s", command, gerror->message); + g_error_free (gerror); + osync_free(command); + goto error; + } + osync_free(command); + } + + proxy->outgoing = osync_queue_new(name, error); osync_free(name); if (!proxy->outgoing) Modified: trunk/opensync/client/opensync_client_proxy_internals.h ============================================================================== --- trunk/opensync/client/opensync_client_proxy_internals.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/client/opensync_client_proxy_internals.h Sun Nov 1 15:32:43 2009 (r5896) @@ -44,7 +44,7 @@ void osync_client_proxy_set_change_callback(OSyncClientProxy *proxy, change_cb cb, void *userdata); OSyncMember *osync_client_proxy_get_member(OSyncClientProxy *proxy); -OSYNC_TEST_EXPORT osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, OSyncError **error); +OSYNC_TEST_EXPORT osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error); OSYNC_TEST_EXPORT osync_bool osync_client_proxy_shutdown(OSyncClientProxy *proxy, OSyncError **error); OSYNC_TEST_EXPORT osync_bool osync_client_proxy_initialize(OSyncClientProxy *proxy, initialize_cb callback, void *userdata, const char *formatdir, const char *plugindir, const char *plugin, const char *groupname, const char *configdir, OSyncPluginConfig *config, OSyncError **error); Modified: trunk/opensync/engine/opensync_engine.c ============================================================================== --- trunk/opensync/engine/opensync_engine.c Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/engine/opensync_engine.c Sun Nov 1 15:32:43 2009 (r5896) @@ -773,7 +773,11 @@ osync_client_proxy_set_context(proxy, engine->context); osync_client_proxy_set_change_callback(proxy, _osync_engine_receive_change, engine); - if (!osync_client_proxy_spawn(proxy, osync_plugin_get_start_type(plugin), osync_member_get_configdir(member), error)) + const char *external_command=NULL; + if (osync_plugin_get_start_type(plugin)==OSYNC_START_TYPE_EXTERNAL) + external_command=osync_member_get_external_command(member); + + if (!osync_client_proxy_spawn(proxy, osync_plugin_get_start_type(plugin), osync_member_get_configdir(member), external_command, error)) goto error_free_proxy; engine->busy = TRUE; Modified: trunk/opensync/group/opensync_member.c ============================================================================== --- trunk/opensync/group/opensync_member.c Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/group/opensync_member.c Sun Nov 1 15:32:43 2009 (r5896) @@ -832,6 +832,18 @@ return new_list; } +const char *osync_member_get_external_command(OSyncMember *member) +{ + osync_assert(member); + OSyncError *error; + OSyncPluginConfig *config = osync_member_get_config_or_default(member, &error); + if (config) { + OSyncPluginExternalPlugin *externalplugin = osync_plugin_config_get_externalplugin(config); + if (externalplugin) return osync_plugin_externalplugin_get_external_command(externalplugin); + } + return NULL; +} + osync_bool osync_member_objtype_enabled(OSyncMember *member, const char *objtype) { OSyncObjTypeSink *sink = NULL; Modified: trunk/opensync/group/opensync_member.h ============================================================================== --- trunk/opensync/group/opensync_member.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/group/opensync_member.h Sun Nov 1 15:32:43 2009 (r5896) @@ -334,6 +334,7 @@ */ OSYNC_EXPORT osync_bool osync_member_plugin_is_uptodate(OSyncMember *member); + /*@}*/ #endif /* _OPENSYNC_MEMBER_H_ */ Modified: trunk/opensync/group/opensync_member_internals.h ============================================================================== --- trunk/opensync/group/opensync_member_internals.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/group/opensync_member_internals.h Sun Nov 1 15:32:43 2009 (r5896) @@ -184,6 +184,25 @@ */ OSYNC_TEST_EXPORT osync_bool osync_member_save_capabilities(OSyncMember *member, OSyncCapabilities* capabilities, OSyncError** error); + +/** @brief Returns the external command of a member + * + * If the plugin is of type OSYNC_START_TYPE_EXTERNAL, an external command can be executed by OpenSync. + * The external_command should be a string in printf format, with one %s. + * Before the command is executed, a variant of printf will be called + * to replace the %s with the path to the plugin pipe. + * The resulting command will be exectued with the glib function + * g_spawn_command_line_async. + * + * The external command is specified in the plugin configuration file for the member, e.g. + * <ExternalPlugin><ExternalCommand>the command</ExternalCommand></ExternalPlugin> + * + * @param plugin Pointer to the plugin + * @returns External command of the plugin + * + */ +OSYNC_TEST_EXPORT const char *osync_member_get_external_command(OSyncMember *member); + /*@}*/ #endif /* _OPENSYNC_MEMBER_INTERNALS_H_ */ Modified: trunk/opensync/opensync-plugin.h ============================================================================== --- trunk/opensync/opensync-plugin.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/opensync-plugin.h Sun Nov 1 15:32:43 2009 (r5896) @@ -33,6 +33,7 @@ #include "plugin/opensync_plugin_connection.h" #include "plugin/opensync_plugin_localization.h" #include "plugin/opensync_plugin_resource.h" +#include "plugin/opensync_plugin_externalplugin.h" #include "plugin/opensync_objtype_sink.h" OPENSYNC_END_DECLS Modified: trunk/opensync/opensync.h ============================================================================== --- trunk/opensync/opensync.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/opensync.h Sun Nov 1 15:32:43 2009 (r5896) @@ -222,6 +222,7 @@ typedef struct OSyncPluginConnection OSyncPluginConnection; typedef struct OSyncPluginLocalization OSyncPluginLocalization; typedef struct OSyncPluginResource OSyncPluginResource; +typedef struct OSyncPluginExternalPlugin OSyncPluginExternalPlugin; /* Engine component */ typedef struct OSyncEngine OSyncEngine; Modified: trunk/opensync/plugin/opensync_plugin_config.c ============================================================================== --- trunk/opensync/plugin/opensync_plugin_config.c Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/plugin/opensync_plugin_config.c Sun Nov 1 15:32:43 2009 (r5896) @@ -33,6 +33,7 @@ #include "opensync_plugin_connection_internals.h" #include "opensync_plugin_localization_private.h" /* FIXME: direct access to private header */ #include "opensync_plugin_resource_private.h" /* FIXME: direct access to private header */ +#include "opensync_plugin_externalplugin_private.h" /* FIXME: direct access to private header */ #include "opensync_plugin_config_private.h" #include "opensync_plugin_config_internals.h" @@ -209,6 +210,47 @@ return FALSE; } +static osync_bool _osync_plugin_config_parse_externalplugin(OSyncPluginConfig *config, xmlNode *cur, OSyncError **error) +{ + OSyncPluginExternalPlugin *externalplugin = NULL; + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, cur, error); + + if (cur == NULL) { // don't set externalplugin if ExternalPlugin tag is empty + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + } + + externalplugin = osync_plugin_externalplugin_new(error); + if (!externalplugin) + goto error; + + for (; cur != NULL; cur = cur->next) { + char *str = NULL; + if (cur->type != XML_ELEMENT_NODE) + continue; + + str = (char*)xmlNodeGetContent(cur); + if (!str) + continue; + + if (!xmlStrcmp(cur->name, (const xmlChar *)"ExternalCommand")) { + osync_plugin_externalplugin_set_external_command(externalplugin, str); + } + + osync_xml_free(str); + } + + osync_plugin_config_set_externalplugin(config, externalplugin); + osync_plugin_externalplugin_unref(externalplugin); + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + + error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + static osync_bool _osync_plugin_config_parse_connection_bluetooth(OSyncPluginConnection *conn, xmlNode *cur, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, conn, cur, error); @@ -728,6 +770,9 @@ } else if (!xmlStrcmp(cur->name, (const xmlChar *)"Resources")) { config->supported |= OPENSYNC_PLUGIN_CONFIG_RESOURCES; ret = _osync_plugin_config_parse_resources(config, cur->xmlChildrenNode, error); + } else if (!xmlStrcmp(cur->name, (const xmlChar *)"ExternalPlugin")) { + config->supported |= OPENSYNC_PLUGIN_CONFIG_EXTERNALPLUGIN; + ret = _osync_plugin_config_parse_externalplugin(config, cur->xmlChildrenNode, error); } else { osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Unknown configuration field \"%s\"", cur->name); goto error; @@ -824,6 +869,28 @@ return FALSE; } +static osync_bool _osync_plugin_config_assemble_externalplugin(xmlNode *cur, OSyncPluginExternalPlugin *externalplugin, OSyncError **error) +{ + const char *external_command; + xmlNode *node = NULL; + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cur, externalplugin, error); + + node = xmlNewChild(cur, NULL, (xmlChar*)"ExternalPlugin", NULL); + if (!node) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "No memory left to assemble configuration."); + goto error; + } + + if ((external_command = osync_plugin_externalplugin_get_external_command(externalplugin))) + xmlNewChild(node, NULL, (xmlChar*)"ExternalCommand", (xmlChar*)external_command); + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + static osync_bool _osync_plugin_config_assemble_connection(xmlNode *cur, OSyncPluginConnection *conn, OSyncError **error) { char *str; @@ -1308,6 +1375,9 @@ config->resources = osync_list_remove(config->resources, res); } + if (config->externalplugin) + osync_plugin_externalplugin_unref(config->externalplugin); + if (config->schemadir) osync_free(config->schemadir); @@ -1330,6 +1400,7 @@ OSyncPluginConnection *conn; OSyncPluginAuthentication *auth; OSyncPluginLocalization *local; + OSyncPluginExternalPlugin *externalplugin; OSyncList *resources; OSyncList *options; char *version_str = NULL; @@ -1382,6 +1453,11 @@ if (!_osync_plugin_config_assemble_resources(doc->children, resources, error)) goto error_and_free; + /* ExternalPlugin */ + if ((externalplugin = osync_plugin_config_get_externalplugin(config))) + if (!_osync_plugin_config_assemble_externalplugin(doc->children, externalplugin, error)) + goto error_and_free; + xmlSaveFormatFile(path, doc, 1); osync_xml_free_doc(doc); @@ -1567,6 +1643,26 @@ return NULL; } +/* External Plugin */ +OSyncPluginExternalPlugin *osync_plugin_config_get_externalplugin(OSyncPluginConfig *config) +{ + osync_assert(config); + return config->externalplugin; +} + +void osync_plugin_config_set_externalplugin(OSyncPluginConfig *config, OSyncPluginExternalPlugin *externalplugin) +{ + osync_assert(config); + + if (config->externalplugin) { + osync_plugin_externalplugin_unref(config->externalplugin); + config->externalplugin = NULL; + } + + if (externalplugin) { + config->externalplugin = osync_plugin_externalplugin_ref(externalplugin); + } +} OSyncPluginConnection *osync_plugin_config_get_connection(OSyncPluginConfig *config) { Modified: trunk/opensync/plugin/opensync_plugin_config.h ============================================================================== --- trunk/opensync/plugin/opensync_plugin_config.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/plugin/opensync_plugin_config.h Sun Nov 1 15:32:43 2009 (r5896) @@ -47,7 +47,9 @@ /** Resources */ OPENSYNC_PLUGIN_CONFIG_RESOURCES = (1 << 3), /** Connection options */ - OPENSYNC_PLUGIN_CONFIG_CONNECTION = (1 << 4) + OPENSYNC_PLUGIN_CONFIG_CONNECTION = (1 << 4), + /** External Plugin */ + OPENSYNC_PLUGIN_CONFIG_EXTERNALPLUGIN = (1 << 5) } OSyncPluginConfigSupportedFlag; /** @brief Set of OSyncPluginConfigSupportedFlags @@ -217,6 +219,21 @@ */ OSYNC_EXPORT void osync_plugin_config_set_connection(OSyncPluginConfig *config, OSyncPluginConnection *connection); +/* External Plugin */ +/**@brief Get the external plugin settings from a config + * + * @param config An OSyncPluginConfig + * @returns an OSyncPluginExternalPlugin with the details of the external plugin or NULL if no external plugin settings configured + */ +OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_config_get_externalplugin(OSyncPluginConfig *config); + +/**@brief Set the external plugin configuration + * + * @param config An OSyncPluginConfig + * @param authentication The new external plugin settings as an OSyncPluginExternalPlugin + */ +OSYNC_EXPORT void osync_plugin_config_set_externalplugin(OSyncPluginConfig *config, OSyncPluginExternalPlugin *externalplugin); + /*@}*/ #endif /*_OPENSYNC_PLUGIN_CONFIG_H_*/ Modified: trunk/opensync/plugin/opensync_plugin_config_private.h ============================================================================== --- trunk/opensync/plugin/opensync_plugin_config_private.h Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/opensync/plugin/opensync_plugin_config_private.h Sun Nov 1 15:32:43 2009 (r5896) @@ -44,6 +44,8 @@ OSyncPluginLocalization *localization; /** List of resource configurations */ OSyncList *resources; + /** External plugin configuration */ + OSyncPluginExternalPlugin *externalplugin; /** Flags to store supported config options */ OSyncPluginConfigSupportedFlags supported; Added: trunk/opensync/plugin/opensync_plugin_externalplugin.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/opensync/plugin/opensync_plugin_externalplugin.c Sun Nov 1 15:32:43 2009 (r5896) @@ -0,0 +1,75 @@ +/* + * libopensync - A synchronization framework + * Copyright (C) 2009 Henrik Kaare Poulsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "opensync.h" +#include "opensync_internals.h" + +#include "opensync-plugin.h" +#include "opensync_plugin_externalplugin_private.h" + +OSyncPluginExternalPlugin *osync_plugin_externalplugin_new(OSyncError **error) +{ + OSyncPluginExternalPlugin *externalplugin = osync_try_malloc0(sizeof(OSyncPluginExternalPlugin), error); + if (!externalplugin) + return NULL; + + externalplugin->ref_count = 1; + + return externalplugin; +} + +OSyncPluginExternalPlugin *osync_plugin_externalplugin_ref(OSyncPluginExternalPlugin *externalplugin) +{ + osync_assert(externalplugin); + + g_atomic_int_inc(&(externalplugin->ref_count)); + + return externalplugin; +} + +void osync_plugin_externalplugin_unref(OSyncPluginExternalPlugin *externalplugin) +{ + osync_assert(externalplugin); + + if (g_atomic_int_dec_and_test(&(externalplugin->ref_count))) { + if (externalplugin->external_command) + osync_free(externalplugin->external_command); + osync_free(externalplugin); + } +} + + +const char *osync_plugin_externalplugin_get_external_command(OSyncPluginExternalPlugin *externalplugin) +{ + osync_assert(externalplugin); + return externalplugin->external_command; +} + +void osync_plugin_externalplugin_set_external_command(OSyncPluginExternalPlugin *externalplugin, const char *external_command) +{ + osync_assert(externalplugin); + + if (externalplugin->external_command) + osync_free(externalplugin->external_command); + + externalplugin->external_command = osync_strdup(external_command); +} + + Added: trunk/opensync/plugin/opensync_plugin_externalplugin.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/opensync/plugin/opensync_plugin_externalplugin.h Sun Nov 1 15:32:43 2009 (r5896) @@ -0,0 +1,87 @@ +/* + * libopensync - A synchronization framework + * Copyright (C) 2009 Henrik Kaare Poulsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_ +#define _OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_ + +/** + * @defgroup OSyncPluginExternalPluginAPI OpenSync Plugin ExternalPlugin + * @ingroup OSyncPlugin + * @brief Functions for configuring external plugin + * + */ +/*@{*/ + + +/** @brief Create a new OSyncPluginExternalPlugin object + * + * @param error Pointer to an error struct + * @returns the newly created object, or NULL in case of an error. + * + */ +OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_externalplugin_new(OSyncError **error); + +/** @brief Decrease the reference count on an OSyncPluginExternalPlugin object + * + * @param external_plugin Pointer to the OSyncPluginExternalPlugin object + * + */ +OSYNC_EXPORT void osync_plugin_externalplugin_unref(OSyncPluginExternalPlugin *external_plugin); + +/** @brief Increase the reference count on an OSyncPluginExternalPlugin object + * + * @param external_plugin Pointer to the OSyncPluginExternalPlugin object + * @returns The OSyncPluginExternalPlugin object passed in + * + */ +OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_externalplugin_ref(OSyncPluginExternalPlugin *external_plugin); + + +/** @brief Get the command to start the external plugin process + * + * @param external_plugin Pointer to the OSyncPluginExternalPlugin object + * @returns the external command or NULL if not set + * + */ +OSYNC_EXPORT const char *osync_plugin_externalplugin_get_external_command(OSyncPluginExternalPlugin *external_plugin); + +/** @brief Set the command to start the external plugin process + * + * If the plugin is of type OSYNC_START_TYPE_EXTERNAL, an external command can be executed by OpenSync. + * The external_command should be a string in printf format, with one %s. + * Before the command is executed, a variant of printf will be called + * to replace the %s with the path to the plugin pipe. + * The resulting command will be exectued with the glib function + * g_spawn_command_line_async. + * + * Example: "thunderbird -mozilla-sync %s" + * + * @param external_plugin Pointer to the OSyncPluginExternalPlugin object + * @param external_command The external command to set + * + */ +OSYNC_EXPORT void osync_plugin_externalplugin_set_external_command(OSyncPluginExternalPlugin *external_plugin, const char *external_command); + + + +/*@}*/ + +#endif /*_OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_*/ + Added: trunk/opensync/plugin/opensync_plugin_externalplugin_private.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/opensync/plugin/opensync_plugin_externalplugin_private.h Sun Nov 1 15:32:43 2009 (r5896) @@ -0,0 +1,49 @@ +/* + * libopensync - A synchronization framework + * Copyright (C) 2009 Henrik Kaare Poulsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_ +#define _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_ + +/** + * @defgroup OSyncPluginExternalPluginPrivateAPI OpenSync Plugin ExternalPlugin Private + * @ingroup OSyncPluginPrivate + */ + +/*@{*/ + +/** + * @brief Gives information for plugin of type OSYNC_START_TYPE_EXTERNAL + **/ +struct OSyncPluginExternalPlugin { + /** Command to be executed to start the external process. + In printf format; should have one %s + which will be replaced with + the path of the plugin pipe to the client process + */ + char *external_command; + + /** Object reference counting */ + int ref_count; +}; + +/*@}*/ + +#endif /* _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_ */ + Modified: trunk/tests/client-tests/check_proxy.c ============================================================================== --- trunk/tests/client-tests/check_proxy.c Fri Oct 30 22:30:07 2009 (r5895) +++ trunk/tests/client-tests/check_proxy.c Sun Nov 1 15:32:43 2009 (r5896) @@ -39,7 +39,7 @@ fail_unless(proxy != NULL, NULL); fail_unless(error == NULL, NULL); - fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL); + fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL); fail_unless(error == NULL, NULL); fail_unless(osync_client_proxy_shutdown(proxy, &error), NULL); @@ -110,7 +110,7 @@ fail_unless(proxy != NULL, NULL); fail_unless(error == NULL, NULL); - fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL); + fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL); fail_unless(error == NULL, NULL); OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL); @@ -159,7 +159,7 @@ fail_unless(proxy != NULL, NULL); fail_unless(error == NULL, NULL); - fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL); + fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL); fail_unless(error == NULL, NULL); OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL); @@ -225,7 +225,7 @@ fail_unless(proxy != NULL, NULL); fail_unless(error == NULL, NULL); - fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL); + fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL); fail_unless(error == NULL, NULL); OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL); |