22 #include "opensync_internals.h" 29 static osync_bool target_fn_fmtnames(
const void *data,
OSyncObjFormat *fmt)
31 const char *
const *list = data;
32 const char *
const *i;
33 for (i = list; *i; i++) {
34 if (!strcmp(fmt->name, *i))
47 static osync_bool target_fn_simple(
const void *data,
OSyncObjFormat *fmt)
57 static osync_bool target_fn_fmtname(
const void *data,
OSyncObjFormat *fmt)
59 const char *name = data;
60 return !strcmp(name, fmt->name);
67 static osync_bool target_fn_membersink(
const void *data,
OSyncObjFormat *fmt)
71 for (i = memb->format_sinks; i; i = i->next) {
72 OSyncObjFormatSink *sink = i->data;
73 if (sink->format == fmt)
106 if (!format->print_func)
107 return g_strndup(change->
data, change->
size);
109 return format->print_func(change);
125 osync_error_set(error, OSYNC_ERROR_GENERIC,
"No data set when asking for the timestamp");
133 if (!format->revision_func) {
134 osync_error_set(error, OSYNC_ERROR_GENERIC,
"No revision function set");
139 time_t time = format->revision_func(change, error);
161 g_assert(rightchange);
162 g_assert(leftchange);
168 osync_trace(
TRACE_EXIT,
"osync_change_compare_data: MISMATCH: Could not convert leftchange to common format");
174 osync_trace(
TRACE_EXIT,
"osync_change_compare_data: MISMATCH: Could not convert rightchange to common format");
178 if (!(rightchange->
data == leftchange->
data)) {
187 if (!rightchange->
data || !leftchange->
data) {
221 g_assert(rightchange);
222 g_assert(leftchange);
228 osync_trace(
TRACE_EXIT,
"osync_change_compare: MISMATCH: Could not convert leftchange to common format");
234 osync_trace(
TRACE_EXIT,
"osync_change_compare: MISMATCH: Could not convert leftchange to common format");
275 if (!format || !format->copy_func) {
277 target->
data = g_malloc0(
sizeof(
char) * (source->
size + 1));
284 if (!format->copy_func(source->
data, source->
size, &(target->
data), &(target->
size))) {
285 osync_error_set(error, OSYNC_ERROR_GENERIC,
"Something went wrong during copying");
308 newchange->
uid = g_strdup(source->
uid);
309 newchange->
hash = g_strdup(source->
hash);
342 osync_debug(
"OSCONV", 3,
"Duplicating change %s with format %s\n", change->
uid, format->name);
343 if (!format || !format->duplicate_func)
345 format->duplicate_func(change);
365 osync_trace(
TRACE_ENTRY,
"osync_change_convert(%p, %p, %p:%s, %s, %p)", env, change, targetformat, targetformat ? targetformat->name :
"NONE", extension_name, error);
366 if (osync_conv_convert_fn(env, change, target_fn_simple, targetformat, extension_name, error)) {
404 osync_error_set(error, OSYNC_ERROR_GENERIC,
"The change has no objtype");
440 return osync_conv_convert_fn(env, change, target_fn_fmtname, targetname, NULL, error);
457 return osync_conv_convert_fn(env, change, target_fn_fmtnames, targetnames, NULL, error);
472 if (!osync_member_require_sink_info(member, error))
475 return osync_conv_convert_fn(env, change, target_fn_membersink, member, member->extension, error);
494 return format->objtype;
514 return format->objtype;
543 if (converter->detect_func && converter->detect_func(env, change->
data, change->
size)) {
544 osync_trace(
TRACE_EXIT,
"osync_change_detect_objformat: %p:%s", converter->target_format, converter->target_format->name);
545 return converter->target_format;
550 osync_error_set(error, OSYNC_ERROR_GENERIC,
"None of the detectors was able to recognize this data");
582 if (!strcmp(converter->source_format->name,
osync_change_get_objformat(change)->name) && converter->type == CONVERTER_DECAP) {
583 osync_bool free_output = FALSE;
584 if (!(new_change = osync_converter_invoke_decap(converter, new_change, &free_output))) {
585 osync_error_set(error, OSYNC_ERROR_GENERIC,
"Unable to decap the change");
osync_bool osync_change_duplicate(OSyncChange *change)
Duplicates the uid of the change.
void osync_change_free(OSyncChange *change)
Frees a change.
OSyncObjFormat * osync_change_detect_objformat(OSyncFormatEnv *env, OSyncChange *change, OSyncError **error)
Tries to detect the format of the given change.
void osync_change_free_data(OSyncChange *change)
Frees the data of a change.
osync_bool osync_change_convert(OSyncFormatEnv *env, OSyncChange *change, OSyncObjFormat *targetformat, OSyncError **error)
Convert a change to a specific format.
OSyncObjType * osync_change_detect_objtype_full(OSyncFormatEnv *env, OSyncChange *change, OSyncError **error)
Tries to detect the encapsulated object type of the given change.
OSyncChange * osync_change_copy(OSyncChange *source, OSyncError **error)
Makes a exact copy of change.
osync_bool osync_error_is_set(OSyncError **error)
Checks if the error is set.
OSyncObjFormat * osync_change_detect_objformat_full(OSyncFormatEnv *env, OSyncChange *change, OSyncError **error)
Tries to detect the encapsulated format of the given change.
OSyncObjType * osync_change_detect_objtype(OSyncFormatEnv *env, OSyncChange *change, OSyncError **error)
Tries to detect the object type of the given change.
OSyncChange * osync_change_new(void)
Spawns a new change object.
osync_bool osync_change_convert_fmtnames(OSyncFormatEnv *env, OSyncChange *change, const char **targetnames, OSyncError **error)
Convert a change to some formats.
void osync_error_free(OSyncError **error)
Frees the error so it can be reused.
A member of a group which represent a single device.
OSyncObjFormat * osync_change_get_objformat(OSyncChange *change)
Gets the object format of a change.
osync_bool osync_change_copy_data(OSyncChange *source, OSyncChange *target, OSyncError **error)
Copies the data from one change to another change.
osync_bool osync_change_convert_fmtname(OSyncFormatEnv *env, OSyncChange *change, const char *targetname, OSyncError **error)
Convert a change to a specific format with the given name.
void osync_debug(const char *subpart, int level, const char *message,...)
Used for debugging.
osync_bool osync_change_convert_extension(OSyncFormatEnv *env, OSyncChange *change, OSyncObjFormat *targetformat, const char *extension_name, OSyncError **error)
Convert a change to a specific format with a specific extension.
time_t osync_change_get_revision(OSyncChange *change, OSyncError **error)
Returns the revision of the object.
void osync_error_set(OSyncError **error, OSyncErrorType type, const char *format,...)
Sets the error.
const char * osync_error_print(OSyncError **error)
Returns the message of the error.
void osync_trace(OSyncTraceType type, const char *message,...)
Used for tracing the application.
char * osync_change_get_printable(OSyncChange *change)
Returns a string describing a change object.
OSyncConvCmpResult
The possible returns of a change comparison.
osync_bool osync_change_convert_to_common(OSyncChange *change, OSyncError **error)
Convert a change to the specified common format.
osync_bool osync_change_convert_member_sink(OSyncFormatEnv *env, OSyncChange *change, OSyncMember *member, OSyncError **error)
Convert a change to the nearest sink on a member.
OSyncObjType * osync_change_get_objtype(OSyncChange *change)
Gets the object type of a change.
Represent a abstract object type (like "contact")
OSyncConvCmpResult osync_change_compare(OSyncChange *leftchange, OSyncChange *rightchange)
Compares 2 changes.
OSyncConvCmpResult osync_change_compare_data(OSyncChange *leftchange, OSyncChange *rightchange)
Compares the data of 2 changes.
OSyncChangeType changetype