void osync_context_report_uid_update(OSyncContext *context, const char *olduid, const char *newuid)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, context, __NULLSTR(olduid), __NULLSTR(newuid));

	osync_return_if_fail(context);
	osync_return_if_fail(olduid);
	osync_return_if_fail(newuid);

	context->uid_update_function(olduid, newuid, context->uid_update_sink, context->uid_update_data);

	osync_trace(TRACE_EXIT, "%s", __func__);
}
osync_bool osync_capabilities_save(OSyncCapabilities *capabilities, const char *file, OSyncError **error)
{
	unsigned int size;
	char *buffer;
	osync_bool ret;

	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, capabilities, __NULLSTR(file), error);

	osync_assert(capabilities);
	osync_assert(file);

	osync_capabilities_sort(capabilities);

	ret = osync_capabilities_assemble(capabilities, &buffer, &size, error);
	if (!ret)
		goto error;

	ret = osync_file_write(file, buffer, size, 0600, error);
	osync_free(buffer);

	if (!ret)
		goto error;
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;

error:	
	osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error));
	return FALSE;
}
osync_bool osync_plugin_env_load(OSyncPluginEnv *env, const char *path, OSyncError **error)
{
	osync_bool must_exist = TRUE;
	GDir *dir = NULL;
	GError *gerror = NULL;
	char *filename = NULL;
	const gchar *de = NULL;
	
	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, env, __NULLSTR(path), error);
	
	if (!path) {
		path = OPENSYNC_PLUGINDIR;
		must_exist = FALSE;
	}
	
	//Load all available shared libraries (plugins)
	if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
		if (must_exist) {
			osync_error_set(error, OSYNC_ERROR_GENERIC, "Path is not loadable");
			goto error;
		} else {
			osync_trace(TRACE_EXIT, "%s: Directory %s does not exist (non-fatal)", __func__, path);
			return TRUE;
		}
	}
	
	dir = g_dir_open(path, 0, &gerror);
	if (!dir) {
		osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to open directory %s: %s", path, gerror->message);
		g_error_free(gerror);
		goto error;
	}
	
	while ((de = g_dir_read_name(dir))) {
		filename = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR, de);
		
		if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || !g_pattern_match_simple("*."G_MODULE_SUFFIX, filename)) {
			g_free(filename);
			continue;
		}
		
		if (!osync_plugin_env_load_module(env, filename, error)) {
			osync_trace(TRACE_ERROR, "Unable to load module: %s", osync_error_print(error));
		}
		
		g_free(filename);
	}
	
	g_dir_close(dir);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;

error:
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return FALSE;
}
OSyncObjFormatSink *osync_objformat_sink_new(const char *objformat, OSyncError **error)
{
	OSyncObjFormatSink *formatsink = NULL;
	osync_trace(TRACE_ENTRY, "%s(%s %p, %p)", __func__, __NULLSTR(objformat), objformat, error);
	
	formatsink = osync_try_malloc0(sizeof(OSyncObjFormatSink), error);
	if (!formatsink)
		return NULL;
	
	/*formatsink->objformat = osync_objformat_ref(objformat);*/
	formatsink->objformat = osync_strdup(objformat);
	formatsink->config = NULL;
	formatsink->ref_count = 1;
	
	osync_trace(TRACE_EXIT, "%s: %p", __func__, formatsink);
	return formatsink;
}
void *osync_module_get_function(OSyncModule *module, const char *name, OSyncError **error)
{
	void *function = NULL;
	osync_assert(module);
	osync_assert(name);
	
	if (!module->module) {
		osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "You need to load the module before getting a function");
		return NULL;
	}
	
	if (!g_module_symbol(module->module, name, &function)) {
		osync_error_set(error, OSYNC_ERROR_PARAMETER, "Unable to locate symbol %s: %s", __NULLSTR(name), g_module_error());
		return NULL;
	}
	
	return function;
}
示例#6
0
osync_bool osync_format_env_load_plugins(OSyncFormatEnv *env, const char *path, OSyncError **error)
{
  osync_bool must_exist = TRUE;
  osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, env, __NULLSTR(path), error);
	
  if (!path) {
    path = OPENSYNC_FORMATSDIR;
    must_exist = FALSE;
  }
	
  if (!osync_format_env_load_modules(env, path, must_exist, error)) {
    osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
    return FALSE;
  }
	
  osync_format_env_converter_initialize(env, error);
	
  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;
}
osync_bool osync_module_check(OSyncModule *module, OSyncError **error)
{
	int version = 0;
	osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, module, error);
	
	version = osync_module_get_version(module);
	if (!version) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Could not load plugin \"%s\". Not a opensync library?", __NULLSTR(module->path));
		osync_trace(TRACE_EXIT_ERROR, "%s: No version", __func__);
		return FALSE;
	}
	
	if (version != OPENSYNC_PLUGINVERSION) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Plugin API version mismatch. Is: %i. Should %i", version, OPENSYNC_PLUGINVERSION);
		osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
		return FALSE;
	}
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;
}
示例#8
0
static osync_bool osync_format_env_load_modules(OSyncFormatEnv *env, const char *path, osync_bool must_exist, OSyncError **error)
{
  GDir *dir = NULL;
  GError *gerror = NULL;
  char *filename = NULL;
  OSyncModule *module = NULL;
  const gchar *de = NULL;
  GList *m = NULL;
	
  osync_trace(TRACE_ENTRY, "%s(%p, %s, %i, %p)", __func__, env, path, must_exist, error);
  osync_assert(env);
  osync_assert(path);
	
  //Load all available shared libraries (plugins)
  if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
    if (must_exist) {
      osync_error_set(error, OSYNC_ERROR_GENERIC, "Path is not loadable");
      goto error;
    } else {
      osync_trace(TRACE_EXIT, "%s: Directory does not exist (non-fatal)", __func__);
      return TRUE;
    }
  }
	
  dir = g_dir_open(path, 0, &gerror);
  if (!dir) {
    osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to open directory %s: %s", path, gerror->message);
    g_error_free(gerror);
    goto error;
  }
	
  while ((de = g_dir_read_name(dir))) {
    filename = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR, de);
		
    if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || !g_pattern_match_simple("*."G_MODULE_SUFFIX, filename)) {
      g_free(filename);
      continue;
    }
		
    module = osync_module_new(error);
    if (!module)
      goto error_free_filename;
		
    if (!osync_module_load(module, filename, error)) {
      osync_trace(TRACE_INTERNAL, "Unable to load module %s: %s", filename, osync_error_print(error));
      osync_module_free(module);
      g_free(filename);
      continue;
    }
		
    if (!osync_module_check(module, error)) {
      if (osync_error_is_set(error)) {
        osync_trace(TRACE_INTERNAL, "Module check error for %s: %s", filename, osync_error_print(error));
      }
      osync_module_free(module);
      g_free(filename);
      continue;
    }
	
    if (!osync_module_get_format_info(module, env, error) && !osync_module_get_function(module, "get_conversion_info", NULL)) {
      if (osync_error_is_set(error)) {
        osync_trace(TRACE_ERROR, "Module load format plugin error for %s: %s", filename, osync_error_print(error));
      }
      osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to load format plugin %s. Neither a converter nor a format could be initialized.", __NULLSTR(filename));
      osync_trace(TRACE_ERROR, "%s", osync_error_print(error));
      osync_module_free(module);
      g_free(filename);
      continue;
    }
		
    env->modules = g_list_append(env->modules, module);
		
    g_free(filename);
  }
	
  g_dir_close(dir);
	
  /* Load the converters, filters, etc */
  for (m = env->modules; m; m = m->next) {
    module = m->data;
    if (!osync_module_get_conversion_info(module, env, error)) {
      osync_trace(TRACE_INTERNAL, "Module get conversion error %s", osync_error_print(error));
      osync_error_unref(error);
    }
  }
	
  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;

 error_free_filename:
  g_free(filename);
  g_dir_close(dir);
 error:
  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return FALSE;
}