Ejemplo n.º 1
0
void osync_version_set_hardwareversion(OSyncVersion *version, const char *hardwareversion)
{
	if(version->hardwareversion)
		osync_free(version->hardwareversion);
	if(!hardwareversion)
		version->hardwareversion = osync_strdup("");
	else
		version->hardwareversion = osync_strdup(hardwareversion);
}
Ejemplo n.º 2
0
void osync_version_set_identifier(OSyncVersion *version, const char *identifier)
{
	if(version->identifier)
		osync_free(version->identifier);
	if(!identifier)
		version->identifier = osync_strdup("");
	else
		version->identifier = osync_strdup(identifier);
}
Ejemplo n.º 3
0
void osync_version_set_firmwareversion(OSyncVersion *version, const char *firmwareversion)
{
	if(version->firmwareversion)
		osync_free(version->firmwareversion);
	if(!firmwareversion)
		version->firmwareversion = osync_strdup("");
	else
		version->firmwareversion = osync_strdup(firmwareversion);
}
Ejemplo n.º 4
0
void osync_version_set_vendor(OSyncVersion *version, const char *vendor)
{
	if(version->vendor)
		osync_free(version->vendor);
	if(!vendor)
		version->vendor = osync_strdup("");
	else
		version->vendor = osync_strdup(vendor);
}
Ejemplo n.º 5
0
void osync_version_set_modelversion(OSyncVersion *version, const char *modelversion)
{
	if(version->modelversion)
		osync_free(version->modelversion);
	if(!modelversion)
		version->modelversion = osync_strdup("");
	else
		version->modelversion = osync_strdup(modelversion);
}
Ejemplo n.º 6
0
void osync_version_set_priority(OSyncVersion *version, const char *priority)
{
	if(version->priority)
		osync_free(version->priority);
	if(!priority)
		version->priority = osync_strdup("");
	else
		version->priority = osync_strdup(priority);
}
Ejemplo n.º 7
0
void osync_version_set_plugin(OSyncVersion *version, const char *plugin)
{
	if(version->plugin)
		osync_free(version->plugin);
	if(!plugin)
		version->plugin = osync_strdup("");
	else
		version->plugin = osync_strdup(plugin);
}
Ejemplo n.º 8
0
void osync_version_set_softwareversion(OSyncVersion *version, const char *softwareversion)
{
	if(version->softwareversion)
		osync_free(version->softwareversion);
	if(!softwareversion)
		version->softwareversion = osync_strdup("");
	else
		version->softwareversion = osync_strdup(softwareversion);
	
}
void osync_plugin_info_set_groupname(OSyncPluginInfo *info, const char *groupname)
{
	osync_assert(info);
	if (info->groupname)
		osync_free(info->groupname);
	info->groupname = osync_strdup(groupname);
}
Ejemplo n.º 10
0
osync_bool osync_db_reset_full(OSyncDB *db, OSyncError **error)
{
	sqlite3_stmt *ppStmt = NULL;
	char *query = NULL;
	osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, db, error);

	osync_assert(db);

	query = osync_strdup("SELECT name FROM (SELECT * FROM sqlite_master) WHERE type='table'");

	if (sqlite3_prepare(db->sqlite3db, query, -1, &ppStmt, NULL) != SQLITE_OK) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Query Error: %s", sqlite3_errmsg(db->sqlite3db));
		goto error;
	}

	while (sqlite3_step(ppStmt) == SQLITE_ROW) {
		const char *table = (const char *) sqlite3_column_text(ppStmt, 0);
		if (!osync_db_reset_table(db, table, error))
			goto error;
	}

	sqlite3_finalize(ppStmt);

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

 error:
	sqlite3_finalize(ppStmt);
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
	return FALSE;
}
Ejemplo n.º 11
0
osync_bool osync_module_load(OSyncModule *module, const char *path, OSyncError **error)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, module, path, error);
	osync_assert(module);
	osync_assert(!module->module);
	
	if (!g_module_supported()) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "This platform does not support loading of modules");
		goto error;
	}

	/* Try to open the module or fail if an error occurs.
	 *
	 * Do local bind to avoid symbol-clashing - i.e. plugins having the same
	 * functions name - e.g. finalize().
	 *
	 * Don't do lazy binding, otherwise symbols of kdepim-sync can't get loaded.
	 * Related to C++ and dlopen?
	 */
	module->module = g_module_open(path, G_MODULE_BIND_LOCAL);
	if (!module->module) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to open module %s: %s", path, g_module_error());
		goto error;
	}
	
	module->path = osync_strdup(path);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;

 error:
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return FALSE;
}
void osync_plugin_info_set_configdir(OSyncPluginInfo *info, const char *configdir)
{
	osync_assert(info);
	if (info->configdir)
		osync_free(info->configdir);
	info->configdir = osync_strdup(configdir);
}
Ejemplo n.º 13
0
OSyncMerger *osync_merger_new(const char *objformat, const char *capsformat, OSyncError **error)
{
	OSyncMerger *merger = NULL;
	osync_trace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, objformat, capsformat, error);
	
	merger = osync_try_malloc0(sizeof(OSyncMerger), error);
	if (!merger) {
		osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
		return NULL;
	}
	merger->ref_count = 1;
	merger->objformat = osync_strdup(objformat);
	merger->capsformat = osync_strdup(capsformat);
	
	osync_trace(TRACE_EXIT, "%s: %p", __func__, merger);
	return merger;
}
void osync_mapping_entry_set_uid(OSyncMappingEntry *entry, const char *uid)
{
	osync_assert(entry);
	osync_assert(uid);

	if (entry->uid)
		osync_free(entry->uid);
	entry->uid = osync_strdup(uid);
}
void osync_objformat_sink_set_config(OSyncObjFormatSink *sink, const char *config)
{
	osync_assert(sink);

	if (sink->config)
		osync_free(sink->config);

	sink->config = osync_strdup(config);
}
void osync_capabilities_set_format(OSyncCapabilities *capabilities, const char *capsformat)
{
	osync_assert(capabilities);
	osync_assert(capsformat);

	if (capabilities->format)
		osync_free(capabilities->format);

	capabilities->format = osync_strdup(capsformat);
}
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;
}
OSyncCapabilitiesObjType *osync_capabilities_objtype_new(const char *objtype, OSyncError **error)
{
	OSyncCapabilitiesObjType *capobjtype = NULL;
	osync_assert(objtype);
	
	capobjtype = osync_try_malloc0(sizeof(OSyncCapabilitiesObjType), error);
	if (!capobjtype)
		goto error;

	capobjtype->name = osync_strdup(objtype);
	capobjtype->ref_count = 1;

	return capobjtype;

error:	
	osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error));
	return NULL;
}
Ejemplo n.º 19
0
OSyncList *osync_db_query_table(OSyncDB *db, const char *query, OSyncError **error)
{
	OSyncList *table = NULL;
	int i, j, column_count = 0;
	int numrows = 0, numcolumns = 0;
	char **result = NULL;
	char *errmsg = NULL;

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

	if (sqlite3_get_table(db->sqlite3db, query, &result, &numrows, &numcolumns, &errmsg) != SQLITE_OK) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to query table: %s", errmsg);
		sqlite3_free(errmsg);
		osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
		return NULL;
	}
	
	/* First row contains only names of columns. So we skip this!
		 We start reading the array with a offset (number of columns) */
	column_count = numcolumns;

	for (j=0; j < numrows; j++) {
		OSyncList *row = NULL;
		for (i=0; i < numcolumns; i++)
			/* speed up - prepend instead of append */
			row = osync_list_prepend(row, osync_strdup(result[column_count++]));

		/* items got prepended, reverse the list again */
		row = osync_list_reverse(row);

		/* speed up - prepend instead of append. */
		table = osync_list_prepend(table, row);
	}

	/* items got prepended, reverse the list again */
	table = osync_list_reverse(table);

	sqlite3_free_table(result);

	osync_trace(TRACE_EXIT, "%s: %p", __func__, table);
	return table; 
}
Ejemplo n.º 20
0
char *osync_db_query_single_string(OSyncDB *db, const char *query, OSyncError **error)
{
	char *result = NULL;
	sqlite3_stmt *ppStmt = NULL;

	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, db, query, error);

	osync_assert(db);
	osync_assert(query);

	if (sqlite3_prepare(db->sqlite3db, query, -1, &ppStmt, NULL) != SQLITE_OK) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Query Error: %s", sqlite3_errmsg(db->sqlite3db));
		goto error;
	}

	if (sqlite3_step(ppStmt) != SQLITE_ROW) {
		sqlite3_finalize(ppStmt);
		osync_trace(TRACE_EXIT, "%s: no result of query", __func__);
		return NULL;
	}
	
	result = osync_strdup((const char *)sqlite3_column_text(ppStmt, 0));

	if (sqlite3_step(ppStmt) == SQLITE_ROW) {
		osync_error_set(error, OSYNC_ERROR_GENERIC, "Returned more than one result! This function only handle a single string!");
		goto error;
	}
	
	sqlite3_finalize(ppStmt);
	
	osync_trace(TRACE_EXIT, "%s: %s", __func__, result);
	return result; 
	
 error:
	osync_free(result);
	sqlite3_finalize(ppStmt);
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return NULL;
}
Ejemplo n.º 21
0
OSyncVersion *osync_version_new(OSyncError **error)
{
	OSyncVersion *version = NULL;
	osync_trace(TRACE_ENTRY, "%s(%p)", __func__, error);
	
	version = osync_try_malloc0(sizeof(OSyncVersion), error);
	if(!version) {
		osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error));
		return NULL;
	}
	
	version->ref_count = 1;
	version->plugin = osync_strdup("");
	version->priority = osync_strdup("");
	version->vendor = osync_strdup("");
	version->modelversion = osync_strdup("");
	version->firmwareversion = osync_strdup("");
	version->softwareversion = osync_strdup("");
	version->hardwareversion = osync_strdup("");
	version->identifier = osync_strdup("");
	
	osync_trace(TRACE_EXIT, "%s: %p", __func__, version);
	return version;
}
Ejemplo n.º 22
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__);
}