Example #1
0
static void *plugin_initialize(OSyncError **error)
{
	OSyncList *list;
	OSyncList *objtypesinks = NULL;
	void *plugin_data;
	osync_bool couldinit;
	couldinit = osync_plugin_initialize(plugin, &(plugin_data), plugin_info, error);
	if (!couldinit)
		goto error;

	objtypesinks = osync_plugin_info_get_objtype_sinks(plugin_info);
	list = objtypesinks;
	while(list) {
		OSyncObjTypeSink *sink = (OSyncObjTypeSink*)list->data;
		if (!osync_objtype_sink_open_state_db(sink, plugin_info, error)) 
			goto error;

		if (!osync_objtype_sink_load_hashtable(sink, plugin_info, error))
			goto error;
		
		list = list->next;
	}
	osync_list_free(objtypesinks);

	return plugin_data;
error:
	osync_list_free(objtypesinks);
	return NULL;
}
static osync_bool _inject_changelog_entries(OSyncObjEngine *engine, OSyncError **error) {
  OSyncList *ids = NULL;
  OSyncList *changetypes = NULL;
  OSyncList *j = NULL, *t = NULL;

  osync_trace(TRACE_ENTRY, "%s(%p)", __func__, engine);

  osync_assert(engine);
  osync_assert(engine->archive);
  osync_assert(engine->objtype);
	
  if (!osync_archive_load_ignored_conflicts(engine->archive, engine->objtype, &ids, &changetypes, error)) {
    osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
    return FALSE;
  }

  t = changetypes;
  for (j = ids; j; j = j->next) {
    long long int id = (long long int)GPOINTER_TO_INT(j->data);

    OSyncMapping *ignored_mapping = osync_mapping_table_find_mapping(engine->mapping_table, id);

    GList *e;
    for (e = engine->mapping_engines; e; e = e->next) {
      OSyncMappingEngine *mapping_engine = e->data;

      if (mapping_engine->mapping == ignored_mapping) {
        GList *m;
        for (m = mapping_engine->entries; m; m = m->next) {
          OSyncMappingEntryEngine *entry = m->data;
          OSyncChangeType changetype = (OSyncChangeType) t->data;
          OSyncChange *ignored_change = osync_change_new(error);
          OSyncObjFormat *dummyformat = NULL;
          OSyncData *data = NULL;

          osync_change_set_changetype(ignored_change, changetype); 
          osync_entry_engine_update(entry, ignored_change);

          dummyformat = osync_objformat_new("plain", engine->objtype, NULL);
          data = osync_data_new(NULL, 0, dummyformat, NULL);
          osync_change_set_data(ignored_change, data);
          osync_objformat_unref(dummyformat);

          osync_change_set_uid(ignored_change, osync_mapping_entry_get_uid(entry->entry));

          osync_trace(TRACE_INTERNAL, "CHANGE: %p", entry->change);
        }
        break;
      }
    }

    t = t->next;
  }

  osync_list_free(ids);
  osync_list_free(changetypes);

  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;
}
Example #3
0
static void dump_map_objtype(OSyncGroupEnv *env, const char *objtype, const char *groupname)
{
	printf("Dumping of mappings got temporarliy disabled\n");

/* FIXME: Temporarily disabled - OSyncArchive got removed from 0.40 API draft */
#if 0	

	OSyncError *error = NULL;
	OSyncGroup *group = osync_group_env_find_group(env, groupname);

	char *path = g_strdup_printf("%s/archive.db", osync_group_get_configdir(group));
	OSyncArchive *archive = osync_archive_new(path, &error);
	OSyncList *ids = NULL;
	OSyncList *uids = NULL;
	OSyncList *mappingids = NULL;
	OSyncList *memberids = NULL;
	OSyncList *d , *u, *m, *i;

	if (!archive)
		goto error;
	g_free(path);
	
	if (!osync_archive_load_changes(archive, objtype, &ids, &uids, &mappingids, &memberids, &error))
		goto error;
	
	d = ids;
	u = uids;
	m = mappingids;
	i = memberids;
	
	for (; u; u = u->next) {
		long long int id = (long long int)GPOINTER_TO_INT(d->data);
		char *uid = u->data;
		long long int memberid = (long long int)GPOINTER_TO_INT(i->data);
		long long int mappingid = (long long int)GPOINTER_TO_INT(m->data);
		
		printf("ID: %lli UID: %s MEMBER: %lli MAPPINGID: %lli\n", id, uid, memberid, mappingid);
		
		m = m->next;
		d = d->next;
		i = i->next;
	}
	
	osync_list_free(ids);
	osync_list_free(uids);
	osync_list_free(mappingids);
	osync_list_free(memberids);
	
	osync_archive_unref(archive);
	return;

 error:
	printf("ERROR: %s", osync_error_print(&error));
	osync_error_unref(&error);
#endif	
}
Example #4
0
void osync_db_free_list(OSyncList *list) {
	OSyncList *row;
	osync_trace(TRACE_ENTRY, "%s(%p)", __func__, list);

	for (row = list; row; row = row->next) {
		osync_list_foreach((OSyncList *) row->data, (GFunc) osync_free, NULL);
		osync_list_free((OSyncList *) row->data);
	}

	osync_list_free(list);

	osync_trace(TRACE_EXIT, "%s", __func__);
}
Example #5
0
static void dump_map(OSyncGroupEnv *env, const char *groupname)
{

	OSyncGroup *group = osync_group_env_find_group(env, groupname);
	int num_objtypes;
	
	if (!group) {
		printf("Unable to find group with name \"%s\"\n", groupname);
		return;
	}
	
	OSyncList *objtypes = osync_group_get_objtypes(group);
	num_objtypes = osync_list_length(objtypes); 
	if (num_objtypes == 0) { 
		printf("Group has no objtypes. Have the objtypes already been discovered?\n"); 
		return;
	}

	OSyncList *o;
	for (o = objtypes; o; o = o->next) {
		const char *objtype = (char *) o->data;
		printf("Mappings for objtype \"%s\":\n", objtype);
		dump_map_objtype(env, objtype, groupname);
	}
	osync_list_free(objtypes);
}
Example #6
0
static osync_bool get_changes(Command *cmd, SyncType type, OSyncError **error)
{
	OSyncObjTypeSink *sink = NULL;
	OSyncList *list;
	OSyncList *objtypesinks = NULL;
	const char *objtype = cmd->arg;

	if (objtype) {
		sink = find_sink(objtype, error);
		if (!sink)
			goto error;

		cmd->sink = sink;
		if (!get_changes_sink(cmd, sink, type, error))
			goto error;

	} else {
		/* all available objtypes */
		objtypesinks = osync_plugin_info_get_objtype_sinks(plugin_info);
		list = objtypesinks;
		while(list) {
			sink = (OSyncObjTypeSink*)list->data;

			cmd->sink = sink;
			if (!get_changes_sink(cmd, sink, type, error))
				goto error;
			list = list->next;
		}
		/* last but not least - the main sink */
		if (get_main_sink())
			if (!get_changes_sink(cmd, get_main_sink(), type, error))
				goto error;
		
		osync_list_free(objtypesinks);
	}

	return TRUE;

 error:
	osync_list_free(objtypesinks);
	return FALSE;
}
Example #7
0
static osync_bool commit(Command *cmd, OSyncChange *change, OSyncError **error)
{
	OSyncList *list;
	OSyncList *objtypesinks = NULL;
	OSyncObjTypeSink *sink = NULL;
	const char *objtype = cmd->arg;

	assert(change);

	if (objtype) {
		sink = find_sink(objtype, error);
		if (!sink)
			goto error;

		if (!commit_sink(cmd, sink, change, error))
			goto error;
	} else {
		objtypesinks = osync_plugin_info_get_objtype_sinks(plugin_info);
		list = objtypesinks;
		while(list){
			sink = (OSyncObjTypeSink*)list->data;

			if (!commit_sink(cmd, sink, change, error))
				goto error;
			list = list->next;
		}

		/* last but not least - the main sink */
		if (get_main_sink())
			if (!commit_sink(cmd, get_main_sink(), change, error))
				goto error;
		
		osync_list_free(objtypesinks);
	}
	
	return TRUE;
 error:
	osync_list_free(objtypesinks);
	return FALSE;
}
static osync_bool discover(OSyncPluginInfo *info, void *data, OSyncError **error)
{

	printf("[EXTERNAL-DEMO]: %s\n", __func__);
	OSyncList *s, *sinks = osync_plugin_info_get_objtype_sinks(info);
	for (s = sinks; s; s = s->next) {
		OSyncObjTypeSink *sink = (OSyncObjTypeSink *) s->data;
		osync_objtype_sink_set_available(sink, TRUE);
	}
	osync_list_free(sinks);
	
	OSyncVersion *version = osync_version_new(error);
	osync_version_set_plugin(version, "external-demo");
	osync_plugin_info_set_version(info, version);
	osync_version_unref(version);

	return TRUE;
}
END_TEST

START_TEST (version_load_from_descriptions)
{
	char *testbed = setup_testbed(NULL);

	OSyncError *error = NULL;
	OSyncList *versions = osync_version_load_from_descriptions(&error, testbed, testbed);
	//fail_unless(versions != NULL, NULL);
	fail_unless(error == NULL, NULL);

	OSyncList *cur = osync_list_first(versions);
	while(cur) {
		osync_version_unref(cur->data);
		cur = cur->next;
	}
	osync_list_free(versions);

	destroy_testbed(testbed);
}
Example #10
0
static osync_bool plugin_list(OSyncError **error) {
	OSyncList *plugins;
	OSyncList *list;
	
	assert(!plugin_env);

	if (!(plugin_env = osync_plugin_env_new(error)))
		goto error;

	if (!(format_env = osync_format_env_new(error)))
		goto error_free_pluginenv;

	if (!osync_format_env_load_plugins(format_env, formatpath, error))
		goto error_free_formatenv;

	if (!osync_plugin_env_load(plugin_env, pluginpath, error))
		goto error_free_formatenv;

	plugins = osync_plugin_env_get_plugins(plugin_env);
	list = plugins;
	while(list) {
		OSyncPlugin* plugin = (OSyncPlugin*)list->data;
		fprintf (stdout, "Name:        %s\n", osync_plugin_get_name(plugin));
		fprintf (stdout, "Description: %s\n", osync_plugin_get_description(plugin));
		list = list->next;
	}
	osync_list_free(plugins);
	return TRUE;
	
 error_free_formatenv:
	osync_format_env_unref(format_env);
	format_env = NULL;
 error_free_pluginenv:
	osync_plugin_env_unref(plugin_env);
	plugin_env = NULL;
 error:	
	return FALSE;
}
int main(int argc, char *argv[]) {
	
	OSyncList *groups, *g;
	int i = 0;
	
	osync_bool couldloadgroups;
	
	OSyncGroup *group = NULL;
	OSyncGroupEnv *groupenv = NULL;
	
	groupenv = osync_group_env_new(NULL);
	/* load groups from default dir */
	couldloadgroups = osync_group_env_load_groups(groupenv, NULL, NULL);
	
	if ( !couldloadgroups ) {
		/* print error */
		printf("Could not load groups.");
		return -1;
	}
	
	groups = osync_group_env_get_groups(groupenv);
	printf("found %i groups\n", osync_list_length(groups));
	
	for (g = groups; g; g = g->next) {
		group = (OSyncGroup *) g->data;
		printf("group nr. %i is %s\n", i+1, osync_group_get_name(group));
	}

	/* Free the list */
	osync_list_free(groups);
	
	/* free env */
	osync_group_env_unref(groupenv);
	
	return 0;
}
Example #12
0
static void get_changes(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, ctx);

	//plugin_environment *env = (plugin_environment *)userdata;
	OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info);
	OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info);
	sink_environment *sinkenv = osync_objtype_sink_get_userdata(sink);

	OSyncError *error = NULL;

	//If you use opensync hashtables you can detect if you need
	//to do a slow-sync and set this on the hastable directly
	//otherwise you have to make 2 function like "get_changes" and
	//"get_all" and decide which to use using
	//osync_objtype_sink_get_slow_sync
	if (osync_objtype_sink_get_slowsync(sinkenv->sink)) {
		osync_trace(TRACE_INTERNAL, "Slow sync requested");

		if (osync_hashtable_slowsync(sinkenv->hashtable, &error)) {
			osync_context_report_osyncerror(ctx, error);
			osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error));
			osync_error_unref(&error);
			return;
		}

	}

	/*
	 * Now you can get the changes.
	 * Loop over all changes you get and do the following:
	 */

	do {
		char *hash = osync_strdup("<the calculated hash of the object>");
		char *uid = osync_strdup("<some uid>");

		//Now get the data of this change
		char *data = NULL;

		//Make the new change to report
		OSyncChange *change = osync_change_new(&error);
		if (!change) {
			osync_context_report_osyncwarning(ctx, error);
			osync_error_unref(&error);
			continue;
		}

		//Now set the uid of the object
		osync_change_set_uid(change, uid);
		osync_change_set_hash(change, hash);
		
		OSyncChangeType changetype = osync_hashtable_get_changetype(sinkenv->hashtable, change);
		osync_change_set_changetype(change, changetype);
		
		// Update entry.
		// Set the hash of the object (optional, only required if you use hashtabled)
		osync_hashtable_update_change(sinkenv->hashtable, change);
		
		if (changetype == OSYNC_CHANGE_TYPE_UNMODIFIED) {
			osync_free(hash);
			osync_free(uid);
			osync_change_unref(change);
			continue;
		}

		osync_free(hash);
		osync_free(uid);

		OSyncObjFormat *format = osync_format_env_find_objformat(formatenv, "<objformat>");
		
		OSyncData *odata = osync_data_new(data, 0, format, &error);
		if (!odata) {
			osync_change_unref(change);
			osync_context_report_osyncwarning(ctx, error);
			osync_error_unref(&error);
			continue;
		}

		osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink));

		//Now you can set the data for the object
		osync_change_set_data(change, odata);
		osync_data_unref(odata);

		// just report the change via
		osync_context_report_change(ctx, change);

		osync_change_unref(change);

		osync_free(uid);
	} while(0);

	//When you are done looping and if you are using hashtables
	//check for deleted entries ... via hashtable
	OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable);
	for (u = uids; u; u = u->next) {
		OSyncChange *change = osync_change_new(&error);
		if (!change) {
			osync_context_report_osyncwarning(ctx, error);
			osync_error_unref(&error);
			continue;
		}

		const char *uid = u->data;
		osync_change_set_uid(change, uid);
		osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED);
		
		OSyncObjFormat *format = osync_format_env_find_objformat(formatenv, "<objformat>");
		
		OSyncData *odata = osync_data_new(NULL, 0, format, &error);
		if (!odata) {
			osync_change_unref(change);
			osync_context_report_osyncwarning(ctx, error);
			osync_error_unref(&error);
			continue;
		}

		osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink));
		osync_change_set_data(change, odata);
		osync_data_unref(odata);

		osync_context_report_change(ctx, change);

		osync_hashtable_update_change(sinkenv->hashtable, change);

		osync_change_unref(change);
	}
	osync_list_free(uids);

	//Now we need to answer the call
	osync_context_report_success(ctx);
	osync_trace(TRACE_EXIT, "%s", __func__);
}
Example #13
0
static void *initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error)
{
	/*
	 * get the config
	 */
	OSyncPluginConfig *config = osync_plugin_info_get_config(info);
	if (!config) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config.");
		goto error;
	}
	/*
	 * You need to specify the <some name>_environment somewhere with
	 * all the members you need
	*/
	plugin_environment *env = osync_try_malloc0(sizeof(plugin_environment), error);
	if (!env)
		goto error;

	/* 
	 * Process the config here and set the options on your environment
	 * if required.
	*/
	/*
	 * Process plugin specific advanced options 
	 */
	OSyncList *optslist = osync_plugin_config_get_advancedoptions(config);
	OSyncList *o;
	for (o = optslist; o; o = o->next) {
		OSyncPluginAdvancedOption *option = o->data;

		const char *val = osync_plugin_advancedoption_get_value(option);
		const char *name = osync_plugin_advancedoption_get_name(option);

		if (!strcmp(name,"<your-option>")) {
			if (!strcmp(val, "<your-value>")) {
				/*
				 * set a varaible to a specific value
				 */;
			}
		}
	}
	osync_list_free(optslist);
	
	/*
	 * Process Ressource options
	 */
	OSyncList *l, *list = NULL;
	list = osync_plugin_info_get_objtype_sinks(info);
	for (l=list; l; l = l->next) {
		OSyncObjTypeSink *sink = (OSyncObjTypeSink *) l->data;

		const char *objtype = osync_objtype_sink_get_name(sink);
		OSyncPluginResource *res = osync_plugin_config_find_active_resource(config, objtype);
		
		/* get objformat sinks */
		OSyncList *s = NULL;
		OSyncList *objformats = osync_plugin_resource_get_objformat_sinks(res);
		for (s = objformats; s; s = s->next) {
			OSyncObjFormatSink *fsink = s->data; // there could be only one sink
			const char *objformat = osync_objformat_sink_get_objformat(fsink);
			osync_assert(objformat);
			osync_trace(TRACE_INTERNAL, "objtype %s has objformat %s", objtype, objformat);
		}	
		osync_list_free(objformats);
		/* Every sink can have different functions ... */
		osync_objtype_sink_set_connect_func(sink, connect);
		osync_objtype_sink_set_disconnect_func(sink, disconnect);
		osync_objtype_sink_set_get_changes_func(sink, get_changes);
		osync_objtype_sink_set_commit_func(sink, commit_change);
		osync_objtype_sink_set_sync_done_func(sink, sync_done);

		/*
		 * If you need plugin specific userdata passed to this
		 * plugin sink functions. You can set it with:
		 *
		 * osync_objtype_sink_set_userdata(sink, userdata_pointer);
		 */

		/* Request a Hahstable here - if you need it.
		 * It will be later available via osync_objtype_sink_get_hashtable(OSyncObjTypeSink *)
		 * in the plugin sink functions (e.g. connect, get_changes, commit, ...)
		 */ 
		osync_objtype_sink_enable_hashtable(sink, TRUE);

	}

	osync_list_free(list);
	
	//Now your return your environemtn struct.
	return (void *) env;

error:
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return NULL;
}
OSyncCapabilities *osync_version_find_capabilities(OSyncVersion *version, OSyncError **error)
{
	int priority = -1;
	OSyncVersion *winner = NULL;
	OSyncCapabilities *capabilities = NULL;
	OSyncList *versions = NULL;
	OSyncList *cur = NULL;

	osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, version, error);
	osync_assert(version);

	versions = osync_version_load_from_default_descriptions(error);
	if (*error) /* versions can be null */
		goto error;

	cur = osync_list_first(versions);
	while(cur) {
		int curpriority = osync_version_matches(cur->data, version, error);
		if (curpriority == -1) {
			if (versions)
				osync_list_free(versions);

			if (winner)
				osync_version_unref(winner);

			goto error;
		}

		if( curpriority > 0 && curpriority > priority) {
			if(winner)
				osync_version_unref(winner);

			winner = cur->data;
			osync_version_ref(winner);
			priority = curpriority;
		}
		osync_version_unref(cur->data);
		cur = cur->next;
	}
	osync_list_free(versions);
	
	/* we found or own capabilities */
	if(priority > 0)
		{
			osync_trace(TRACE_INTERNAL, "Found capabilities file by version: %s ", (const char*)osync_version_get_identifier(winner));

			capabilities = osync_capabilities_load_identifier((const char*)osync_version_get_identifier(winner), error);
			osync_version_unref(winner);

			if (!capabilities)
				goto error;
		}

	osync_trace(TRACE_EXIT, "%s: %p", __func__, capabilities);
	return capabilities;

 error:	

	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return NULL;
}
Example #15
0
/* In initialize, we get the config for the plugin. Here we also must register
 * all _possible_ objtype sinks. */
static void *mock_initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, plugin, info, error);

	if (mock_get_error(info->memberid, "INIT_NULL_NOERROR")) {
		osync_trace(TRACE_EXIT, "%s: %s", __func__, "Everything is fine. I don't need plugin userdata.");
		return NULL;
	}

	if (mock_get_error(info->memberid, "INIT_NULL")) {
		osync_error_set(error, OSYNC_ERROR_EXPECTED, "Triggering INIT_NULL error");
		osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
		return NULL;
	}

	mock_env *env = osync_try_malloc0(sizeof(mock_env), error);
	osync_assert(env);

	OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info);
	osync_assert(formatenv);

	OSyncPluginConfig *config = osync_plugin_info_get_config(info);
	osync_assert(config);

	if (mock_get_error(info->memberid, "MAINSINK_CONNECT")) {
		env->mainsink = osync_objtype_main_sink_new(error);

		osync_objtype_sink_set_connect_func(env->mainsink, mock_connect);
		osync_objtype_sink_set_disconnect_func(env->mainsink, mock_mainsink_disconnect);

		osync_objtype_sink_set_userdata(env->mainsink, env);

		osync_plugin_info_set_main_sink(info, env->mainsink);
	}

	/* Now we register the objtypes that we can sync. This plugin is special. It can
	 * synchronize any objtype we configure it to sync and where a conversion
	 * path to the file format can be found */
	OSyncList *objtypesinks = osync_plugin_info_get_objtype_sinks(info);
	OSyncList *list = NULL;
	for (list = objtypesinks;list; list = list->next) {
		MockDir *dir = osync_try_malloc0(sizeof(MockDir), error);
		osync_assert(dir);

		dir->committed_all = TRUE;

		OSyncObjTypeSink *sink = (OSyncObjTypeSink*)list->data;
		osync_assert(sink);

		const char *objtype = osync_objtype_sink_get_name(sink);
		dir->res = osync_plugin_config_find_active_resource(config, objtype);
		osync_plugin_resource_ref(dir->res);
		dir->path = osync_plugin_resource_get_path(dir->res);
		osync_assert(dir->path);

		OSyncList *format_sinks = osync_plugin_resource_get_objformat_sinks(dir->res);
		osync_assert(osync_list_length(format_sinks) == 1);
		OSyncObjFormatSink *format_sink = osync_list_nth_data(format_sinks, 0);
		const char *objformat_str = osync_objformat_sink_get_objformat(format_sink);
		osync_assert(objformat_str);
		dir->objformat = osync_format_env_find_objformat(formatenv, objformat_str);
		osync_assert(dir->objformat);
		osync_objformat_ref(dir->objformat);

		osync_list_free(format_sinks);
		/*
		const char *objformat = osync_objformat_get_name(dir->objformat);
		OSyncObjFormatSink *format_sink = osync_objformat_sink_new(objformat, error);
		if (!format_sink)
			return NULL;

		osync_objtype_sink_add_objformat_sink(sink, format_sink);
		*/

		/* Sanity check for connect_done */
		dir->connect_done = TRUE;

		if (!mock_get_error(info->memberid, "MAINSINK_CONNECT")) {
			osync_objtype_sink_set_connect_func(sink, mock_connect);
			osync_objtype_sink_set_connect_done_func(sink, mock_connect_done);
			osync_objtype_sink_set_disconnect_func(sink, mock_disconnect);
		}

		osync_objtype_sink_set_get_changes_func(sink, mock_get_changes);

		osync_objtype_sink_set_committed_all_func(sink, mock_committed_all);
		osync_objtype_sink_set_commit_func(sink, mock_commit_change);
		osync_objtype_sink_set_read_func(sink, mock_read);
		osync_objtype_sink_set_sync_done_func(sink, mock_sync_done);

		/* We pass the MockDir object to the sink, so we dont have to look it up
		 * again once the functions are called */
		osync_objtype_sink_set_userdata(sink, dir);

		/* Request an Anchor */
		osync_objtype_sink_enable_state_db(sink, TRUE);

		/* Request an Hashtable */
		osync_objtype_sink_enable_hashtable(sink, TRUE);

		//Lets reduce the timeouts a bit so the checks work faster
		osync_objtype_sink_set_connect_timeout(sink, 2);
		osync_objtype_sink_set_getchanges_timeout(sink, 2);
		osync_objtype_sink_set_commit_timeout(sink, 4);
		osync_objtype_sink_set_committedall_timeout(sink, 4);
		osync_objtype_sink_set_syncdone_timeout(sink, 2);
		osync_objtype_sink_set_disconnect_timeout(sink, 2);

		osync_objtype_sink_set_read_timeout(sink, 2);


/* XXX No testcase is currently using this at all! */
#if 0

		if (g_getenv("NO_TIMEOUTS")) {

			/* XXX Timeout value of wouldn't work out, since
			   the Sink object would fallback to the default timeout value:

			 sink->timeout.connect ? sink->timeout.connect : OSYNC_SINK_TIMEOUT_CONNECT;

			 Really needed?!
			 */

			osync_objtype_sink_set_connect_timeout(sink, 0);
			osync_objtype_sink_set_getchanges_timeout(sink, 0);
			osync_objtype_sink_set_commit_timeout(sink, 0);
			osync_objtype_sink_set_committedall_timeout(sink, 0);
			osync_objtype_sink_set_syncdone_timeout(sink, 0);
			osync_objtype_sink_set_disconnect_timeout(sink, 0);

			osync_objtype_sink_set_read_timeout(sink, 0);
		}

		/* What is meant by this?! Maybe OSyncPlugin.useable?! Not used at all...
		if (g_getenv("IS_AVAILABLE"))
			info->functions.is_available = mock_is_available;
		*/

#endif
		env->directories = g_list_append(env->directories, dir);
	}
	osync_list_free(objtypesinks);
	osync_trace(TRACE_EXIT, "%s: %p", __func__, env);
	return (void *)env;
}
Example #16
0
static osync_bool init(OSyncError **error) {
	OSyncPluginConfig *config;
	assert(!plugin);
	assert(!plugin_env);

	if (!(plugin_env = osync_plugin_env_new(error)))
		goto error;

	if (!(format_env = osync_format_env_new(error)))
		goto error_free_pluginenv;

	if (!osync_format_env_load_plugins(format_env, formatpath, error))
		goto error_free_formatenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"format plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!osync_plugin_env_load(plugin_env, pluginpath, error))
		goto error_free_pluginenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!(plugin = osync_plugin_env_find_plugin(plugin_env, pluginname))) {
		osync_error_set(error, OSYNC_ERROR_PLUGIN_NOT_FOUND, "Plugin not found: \"%s\"", pluginname);
		goto error_free_pluginenv;
	}

	if (!(plugin_info = osync_plugin_info_new(error)))
		goto error_free_pluginenv;

	config = osync_plugin_config_new(error);
	if (!config)
		goto error_free_plugininfo;

	if (osync_plugin_get_config_type(plugin) != OSYNC_PLUGIN_NO_CONFIGURATION && configfile) {
		OSyncList *r = NULL;
		if (!osync_plugin_config_file_load(config, configfile, error))
			goto error_free_pluginconfig;

		osync_plugin_info_set_config(plugin_info, config);

		/** Redudant(aka. stolen) code from opensync/client/opensync_client.c */
		/* Enable active sinks */

		if (config)
			r = osync_plugin_config_get_resources(config);

		for (; r; r = r->next) {
			OSyncPluginResource *res = r->data;
			OSyncObjTypeSink *sink;

			const char *objtype = osync_plugin_resource_get_objtype(res); 
			OSyncList *o = NULL;
			/* Check for ObjType sink */
			if (!(sink = osync_plugin_info_find_objtype(plugin_info, objtype))) {
				sink = osync_objtype_sink_new(objtype, error);
				if (!sink)
					goto error_free_pluginconfig;

				osync_plugin_info_add_objtype(plugin_info, sink);
			}
			OSyncList *objformats = osync_plugin_resource_get_objformat_sinks(res);
			for ( o = objformats; o; o = o->next) {
				OSyncObjFormatSink *format_sink = (OSyncObjFormatSink *) o->data; 
				osync_objtype_sink_add_objformat_sink(sink, format_sink);
			}
			osync_list_free(objformats);
		}

		osync_plugin_config_unref(config);

	}

	if (!configfile && osync_plugin_get_config_type(plugin) == OSYNC_PLUGIN_NEEDS_CONFIGURATION) {
		osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Plugin \"%s\" requires configuration!", pluginname); 
		goto error_free_pluginconfig;
	}

	assert(!ctx);
	ctx = g_main_context_new();

	osync_plugin_info_set_configdir(plugin_info, configdir);
	osync_plugin_info_set_loop(plugin_info, ctx);
	osync_plugin_info_set_format_env(plugin_info, format_env);
	osync_plugin_info_set_groupname(plugin_info, syncgroup);

	return TRUE;

	/*
		error_free_loop:
		g_main_context_unref(ctx);
	*/
 error_free_pluginconfig:
	osync_plugin_config_unref(config);
 error_free_plugininfo:
	osync_plugin_info_unref(plugin_info);
 error_free_formatenv:
	osync_format_env_unref(format_env);
	format_env = NULL;
 error_free_pluginenv:
	osync_plugin_env_unref(plugin_env);
	plugin_env = NULL;
 error:	
	return FALSE;
}