From: <dg...@su...> - 2009-01-28 13:47:07
|
Author: bellmich Date: Wed Jan 28 14:45:42 2009 New Revision: 904 URL: http://libsyncml.opensync.org/changeset/904 Log: - added support for generic content-types - added automatic base64 conversion for binary data types which are prefixed with application, audio, image, message and video - fixed wrong interpretation of return value from smlTransportFinalize in data_sync.c - fixed wrong handling of REPLACE during SLOW SYNC - added support for receiving SANs Modified: trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync_callbacks.c trunk/libsyncml/data_sync_api/data_sync_devinf.c trunk/libsyncml/data_sync_api/defines.h Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Wed Jan 28 14:41:31 2009 (r903) +++ trunk/libsyncml/data_sync_api/data_sync.c Wed Jan 28 14:45:42 2009 (r904) @@ -517,18 +517,45 @@ /* fill the new change */ change->type = type; change->name = g_strdup(name); - change->size = size; - change->data = smlTryMalloc0(size+1, error); - if (!change->data) - goto error; change->userdata = userdata; - memcpy(change->data, data, size); - /* append change to datastore */ + /* determine the datastore */ change->datastore = smlDataSyncGetDatastoreFromSource(dsObject, source, error); if (!change->datastore) goto error; - change->datastore->changes = g_list_append(change->datastore->changes, change); + SmlDataSyncDatastore *datastore = change->datastore; + + /* copy data */ + size_t appClassLength = index(datastore->contentType, '/') - datastore->contentType; + if ( ( strstr(datastore->contentType, SML_CONTENT_TYPE_APPLICATION) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_APPLICATION) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_AUDIO) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_IMAGE) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_IMAGE) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_MESSAGE) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_MESSAGE) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_VIDEO) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) ) + { + /* binary data must be base64 encoded */ + change->data = g_base64_encode((const unsigned char *) data, size); + if (!change->data) { + smlErrorSet(error, SML_ERROR_GENERIC, + "The base 64 encoding of glib failed."); + goto error; + } + change->size = strlen(change->data); + } else { + change->data = smlTryMalloc0(size+1, error); + if (!change->data) + goto error; + memcpy(change->data, data, size); + change->size = size; + } + + /* append change to datastore */ + datastore->changes = g_list_append(datastore->changes, change); smlTrace(TRACE_EXIT, "%s - TRUE", __func__); return TRUE; @@ -725,8 +752,8 @@ /* cleanup transport */ if ((*dsObject)->tsp) { SmlError *error = NULL; - if (smlTransportFinalize((*dsObject)->tsp, &error)) { - g_warning("%s", smlErrorPrint(&error)); + if (!smlTransportFinalize((*dsObject)->tsp, &error)) { + g_warning("%s: %s", __func__, smlErrorPrint(&error)); smlErrorDeref(&error); } smlTransportFree((*dsObject)->tsp); Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.c Wed Jan 28 14:41:31 2009 (r903) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.c Wed Jan 28 14:45:42 2009 (r904) @@ -23,6 +23,7 @@ #include "libsyncml/sml_support.h" #include "libsyncml/sml_error_internals.h" #include <string.h> +#include "defines.h" #include "data_sync_devinf.h" #include "libsyncml/objects/sml_ds_server_internals.h" #include "libsyncml/sml_manager_internals.h" @@ -222,6 +223,17 @@ switch(dsObject->actualPackage) { case SML_PACKAGE_1: /* SAN received by client */ + /* This is the best position to check for + * the availability of the remote device + * information. If it is not present then + * the own device information is send and + * the remote ones is requested. + */ + if (!smlDataSyncManageDevInf(dsObject, &error)) + goto error; + if (!smlSessionFlush(dsObject->session, TRUE, &error)) + goto error; + break; case SML_PACKAGE_2: /* alerts received by server */ /* This is the best position to check for * the availability of the remote device @@ -282,6 +294,13 @@ &error); if (!link && error) goto error; + /* OBEX is a stateful protocol and the client should + * init the disconnect. The problem is what happens + * when the client hangs? + * + * if (dsObject->tspType != SML_TRANSPORT_OBEX_SERVER && + * !smlTransportDisconnect(dsObject->tsp, link, &error)) + */ if (!smlTransportDisconnect(dsObject->tsp, link, &error)) { if (link) @@ -529,12 +548,36 @@ smlAssert(datastore->dsObject->changeCallback); /* some mobiles sends replace commands during slow-sync */ - /* FIXME: heavy bug - where is the check that this - * FIXME: is a SLOW-SYNC alert? - */ - if (datastore->alertType && datastore->alertType == SML_CHANGE_REPLACE) + if (datastore->alertType == SML_ALERT_SLOW_SYNC && + type == SML_CHANGE_REPLACE) type = SML_CHANGE_ADD; + /* decode base64 data if necessary */ + size_t appClassLength = index(datastore->contentType, '/') - datastore->contentType; + if ( ( strstr(datastore->contentType, SML_CONTENT_TYPE_APPLICATION) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_APPLICATION) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_AUDIO) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_IMAGE) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_IMAGE) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_MESSAGE) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_MESSAGE) ) || + ( strstr(datastore->contentType, SML_CONTENT_TYPE_VIDEO) == datastore->contentType && + appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) ) + { + /* binary data must be base64 encoded */ + char *b64data = data; + size_t length = 0; + data = (char *) g_base64_decode(b64data, &length); + size = length; + smlSafeCFree(&b64data); + if (!data) { + smlErrorSet(error, SML_ERROR_GENERIC, + "The base 64 decoding of glib failed."); + goto error; + } + } + /* perform callback */ if (!datastore->dsObject->changeCallback( datastore->dsObject, datastore->sourceUri, Modified: trunk/libsyncml/data_sync_api/data_sync_devinf.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_devinf.c Wed Jan 28 14:41:31 2009 (r903) +++ trunk/libsyncml/data_sync_api/data_sync_devinf.c Wed Jan 28 14:45:42 2009 (r904) @@ -535,11 +535,10 @@ { smlTrace(TRACE_INTERNAL, "%s - unknown content type detected (%s)", __func__, VA_STRING(ct)); - if (ct != NULL) - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, - "content-type unknown (%s)", - ct); - goto error; + smlDevInfDataStoreSetRxPref(ds, ct, "1.0"); + smlDevInfDataStoreSetTxPref(ds, ct, "1.0"); + if (!add_devinf_ctcap(devinf, ct, "1.0", error)) + goto error; } // configure supported sync modes Modified: trunk/libsyncml/data_sync_api/defines.h ============================================================================== --- trunk/libsyncml/data_sync_api/defines.h Wed Jan 28 14:41:31 2009 (r903) +++ trunk/libsyncml/data_sync_api/defines.h Wed Jan 28 14:45:42 2009 (r904) @@ -83,6 +83,12 @@ #define SML_DATA_SYNC_CONFIG_FAKE_MODEL "FAKE_MODEL" #define SML_DATA_SYNC_CONFIG_FAKE_SOFTWARE_VERSION "FAKE_SOFTWARE_VERSION" +#define SML_CONTENT_TYPE_APPLICATION "application" +#define SML_CONTENT_TYPE_AUDIO "audio" +#define SML_CONTENT_TYPE_IMAGE "image" +#define SML_CONTENT_TYPE_MESSAGE "message" +#define SML_CONTENT_TYPE_VIDEO "video" + #endif /* _SML_DATA_SYNC_API_CONFIG_H_ */ /*@}*/ |