From: <svn...@op...> - 2009-07-01 14:10:00
|
Author: bellmich Date: Wed Jul 1 15:31:13 2009 New Revision: 1138 URL: http://libsyncml.opensync.org/changeset/1138 Log: migrated SmlLocation to GObject style Added: trunk/libsyncml/data_sync_api/sml_location.c trunk/libsyncml/data_sync_api/sml_location.h trunk/libsyncml/data_sync_api/sml_location_internals.h trunk/tests/check_data_sync_api_location.c - copied, changed from r1137, trunk/tests/check_elements.c Deleted: trunk/tests/check_elements.c Modified: trunk/libsyncml/CMakeLists.txt trunk/libsyncml/data_sync_api/data_sync_callbacks.c trunk/libsyncml/data_sync_api/data_sync_client.c trunk/libsyncml/data_sync_api/data_sync_devinf.c trunk/libsyncml/data_sync_api/data_sync_server.c trunk/libsyncml/data_sync_api/transport_http_client.c trunk/libsyncml/objects/sml_auth.c trunk/libsyncml/objects/sml_devinf_obj.c trunk/libsyncml/objects/sml_ds_server.c trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_command.c trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h trunk/libsyncml/sml_error_internals.h trunk/libsyncml/sml_manager.c trunk/libsyncml/sml_notification.c trunk/libsyncml/sml_parse.c trunk/libsyncml/sml_session.c trunk/libsyncml/syncml.h trunk/tests/CMakeLists.txt trunk/tests/check_devinf.c trunk/tests/check_ds.c trunk/tests/check_manager.c trunk/tests/check_session.c trunk/tests/check_sync.c trunk/tests/check_wbxml_assembler.c trunk/tests/check_xml_assembler.c trunk/tests/support.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/CMakeLists.txt Wed Jul 1 15:31:13 2009 (r1138) @@ -23,6 +23,7 @@ data_sync_api/data_sync_loop.c data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c + data_sync_api/sml_location.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c data_sync_api/transport_obex_client.c @@ -89,6 +90,7 @@ ## install header files of data sync API INSTALL( FILES + data_sync_api/sml_location.h data_sync_api/defines.h data_sync_api/standard.h data_sync_api/callbacks.h Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.c Wed Jul 1 15:31:13 2009 (r1138) @@ -643,7 +643,7 @@ SmlLocation *newuid, void *userdata) { - smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(smlLocationGetURI(orig)), VA_STRING(smlLocationGetURI(newuid)), userdata); + smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(sml_location_get_uri(orig)), VA_STRING(sml_location_get_uri(newuid)), userdata); SmlError *error = NULL; SmlDataSyncDatastore *datastore = userdata; @@ -655,8 +655,8 @@ /* perform callback */ if (!datastore->dsObject->mappingCallback( datastore->dsObject, datastore->sourceUri, - smlLocationGetURI(orig), - smlLocationGetURI(newuid), + sml_location_get_uri(orig), + sml_location_get_uri(newuid), datastore->dsObject->mappingUserdata, &error)) goto error; Modified: trunk/libsyncml/data_sync_api/data_sync_client.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_client.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/data_sync_api/data_sync_client.c Wed Jul 1 15:31:13 2009 (r1138) @@ -39,6 +39,7 @@ SmlDataSyncObject *dsObject = datastore->dsObject; SmlBool ret = TRUE; SmlError *error = NULL; + GError *gerror = NULL; /* libsyncml only supports SML_ALERT_TWO_WAY and SML_ALERT_SLOW_SYNC * but some old phones reply on a SAN alert 206 with a slow sync 201 @@ -118,9 +119,15 @@ } else { /* send alert 201 */ SmlLocation *source = NULL; - source = smlLocationNew(datastore->sourceUri, NULL, &error); - if (!source) + source = sml_location_new(); + if (!source) { + g_set_error(&gerror, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; + } + if (!sml_location_set_uri(source, datastore->sourceUri, &gerror)) { + g_object_unref(source); + goto error; + } SmlCommand *alert = NULL; alert = smlCommandNewAlert( SML_ALERT_SLOW_SYNC, @@ -129,10 +136,10 @@ NULL, datastore->localNext, NULL, &error); if (!alert) { - smlLocationUnref(source); + g_object_unref(source); goto error; } - smlLocationUnref(source); + g_object_unref(source); if (!smlSessionSendCommand(dsObject->session, alert, NULL, NULL, NULL, &error)) { smlCommandUnref(alert); goto error; @@ -150,6 +157,10 @@ smlTrace(TRACE_EXIT, "%s: %i", __func__, ret); return ret; error: + if (gerror) { + smlErrorSet(&error, gerror->code, "%s", gerror->message); + g_error_free(gerror); + } smlErrorRef(&error); smlDataSyncSendEvent( dsObject, SML_DATA_SYNC_EVENT_ERROR, @@ -304,6 +315,8 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, dsObject, error); CHECK_ERROR_REF + GError *gerror = NULL; + /* The manager responsible for handling the other objects */ dsObject->manager = smlManagerNew(dsObject->tsp, error); if (!dsObject->manager) @@ -326,12 +339,16 @@ smlTrace(TRACE_INTERNAL, "preparing DsServer (datastore) %s", datastore->sourceUri); /* We now create the ds server at the given location. */ - SmlLocation *loc = smlLocationNew(datastore->sourceUri, NULL, error); - if (!loc) + SmlLocation *loc = sml_location_new(); + if (!loc) { + g_set_error(&gerror, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); + goto error; + } + if (!sml_location_set_uri(loc, datastore->sourceUri, &gerror)) goto error; datastore->server = smlDsClientNew(datastore->contentType, loc, loc, error); - smlLocationUnref(loc); + g_object_unref(loc); if (!datastore->server) goto error; @@ -368,6 +385,10 @@ return TRUE; error: + if (gerror) { + smlErrorSet(error, gerror->code, "%s", gerror->message); + g_error_free(gerror); + } smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); return FALSE; } Modified: trunk/libsyncml/data_sync_api/data_sync_devinf.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_devinf.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/data_sync_api/data_sync_devinf.c Wed Jul 1 15:31:13 2009 (r1138) @@ -685,7 +685,7 @@ smlTrace(TRACE_INTERNAL, "%s: calling read DevInf callback", __func__); SmlDevInf *devinf = dsObject->readDevInfCallback( dsObject, - smlLocationGetURI(smlSessionGetTarget(dsObject->session)), + sml_location_get_uri(smlSessionGetTarget(dsObject->session)), dsObject->readDevInfUserdata, error); if (!devinf && *error) goto error; Modified: trunk/libsyncml/data_sync_api/data_sync_server.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_server.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/data_sync_api/data_sync_server.c Wed Jul 1 15:31:13 2009 (r1138) @@ -212,6 +212,8 @@ SmlBool smlDataSyncServerInit(SmlDataSyncObject *dsObject, SmlError **error) { CHECK_ERROR_REF + GError *gerror = NULL; + /* The manager responsible for handling the other objects */ dsObject->manager = smlManagerNew(dsObject->tsp, error); if (!dsObject->manager) @@ -247,16 +249,20 @@ SmlDataSyncDatastore *datastore = o->data; /* We now create the ds server hat the given location */ - SmlLocation *loc = smlLocationNew(datastore->sourceUri, NULL, error); - if (!loc) + SmlLocation *loc = sml_location_new(); + if (!loc) { + g_set_error(&gerror, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); + goto error; + } + if (!sml_location_set_uri(loc, datastore->sourceUri, &gerror)) goto error; datastore->server = smlDsServerNew(datastore->contentType, loc, error); if (!datastore->server) { - smlLocationUnref(loc); + g_object_unref(loc); goto error; } - smlLocationUnref(loc); + g_object_unref(loc); if (!smlDsServerRegister(datastore->server, dsObject->manager, error)) goto error; @@ -283,6 +289,10 @@ return TRUE; error: + if (gerror) { + smlErrorSet(error, gerror->code, "%s", gerror->message); + g_error_free(gerror); + } smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); return FALSE; } Added: trunk/libsyncml/data_sync_api/sml_location.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_location.c Wed Jul 1 15:31:13 2009 (r1138) @@ -0,0 +1,541 @@ +/* sml_location.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_location.h" +#include <libsyncml/syncml.h> +#include "../sml_error_internals.h" + +G_DEFINE_TYPE (SmlLocation, sml_location, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_URI, + PROP_NAME, + PROP_PARENT_URI +}; + +struct _SmlLocationPrivate +{ + gchar* uri; + gchar* name; + gchar* parent_uri; + gchar* full_uri; +}; + +static void +sml_location_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_URI: + g_value_set_string (value, SML_LOCATION (object)->priv->uri); + break; + case PROP_NAME: + g_value_set_string (value, SML_LOCATION (object)->priv->name); + break; + case PROP_PARENT_URI: + g_value_set_string (value, SML_LOCATION (object)->priv->parent_uri); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_location_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_URI: + g_free (SML_LOCATION (object)->priv->uri); + SML_LOCATION (object)->priv->uri = g_strdup (g_value_get_string (value)); + break; + case PROP_NAME: + g_free (SML_LOCATION (object)->priv->name); + SML_LOCATION (object)->priv->name = g_strdup (g_value_get_string (value)); + break; + case PROP_PARENT_URI: + g_free (SML_LOCATION (object)->priv->parent_uri); + SML_LOCATION (object)->priv->parent_uri = g_strdup (g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_location_finalize (GObject *object) +{ + SmlLocation *self = SML_LOCATION (object); + g_free(self->priv->uri); + g_free(self->priv->name); + g_free(self->priv->parent_uri); + g_free(self->priv->full_uri); + /* all pointers must be NULL */ + self->priv->uri = NULL; + self->priv->name = NULL; + self->priv->parent_uri = NULL; + self->priv->full_uri = NULL; + G_OBJECT_CLASS (sml_location_parent_class)->finalize (object); +} + +static void +sml_location_class_init (SmlLocationClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlLocationPrivate)); + + object_class->get_property = sml_location_get_property; + object_class->set_property = sml_location_set_property; + object_class->finalize = sml_location_finalize; + + /** + * SmlLocation:uri: + * + * The URI property. + */ + g_object_class_install_property (object_class, + PROP_URI, + g_param_spec_string ("URI", + "URI", + "URI", + NULL, + G_PARAM_READWRITE)); + /** + * SmlLocation:name: + * + * The name property. + */ + g_object_class_install_property (object_class, + PROP_NAME, + g_param_spec_string ("name", + "name", + "name", + NULL, + G_PARAM_READWRITE)); + /** + * SmlLocation:parent_uri: + * + * The The URI of the parent property. + */ + g_object_class_install_property (object_class, + PROP_PARENT_URI, + g_param_spec_string ("parentURI", + "parentURI", + "The URI of the parent", + NULL, + G_PARAM_READWRITE)); + +} + +static void +sml_location_init (SmlLocation *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_LOCATION, + SmlLocationPrivate); +} + +/** + * sml_location_new: + * + * Creates a new instance of #SmlLocation. + * + * Return value: the newly created #SmlLocation instance + */ +SmlLocation* +sml_location_new (void) +{ + return g_object_new (SML_TYPE_LOCATION, NULL); +} + +/** + * sml_location_new_with_options: + * + * Creates a new instance of #SmlLocation. + * + * Return value: the newly created #SmlLocation instance + */ +SmlLocation* +sml_location_new_with_options (const gchar* uid, + const gchar* name, + GError **error) +{ + CHECK_ERROR_REF + + SmlLocation *loc = sml_location_new(); + sml_return_val_error_if_fail (SML_IS_LOCATION (loc), NULL, error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); + + if (!sml_location_set_uri(loc, uid, error)) { + g_object_unref(loc); + return NULL; + } + + if (!sml_location_set_name(loc, name, error)) { + g_object_unref(loc); + return NULL; + } + + return loc; +} + +/** + * sml_location_get_uri: + * @self: A #SmlLocation + * + * Gets the URI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_location_get_uri (SmlLocation *self) +{ + g_return_val_if_fail (SML_IS_LOCATION (self), NULL); + return self->priv->uri; +} + +/** + * sml_location_set_uri: + * @self: A #SmlLocation + * @uri: + * + * Sets the URI property. + */ +gboolean +sml_location_set_uri (SmlLocation *self, + const gchar* uri, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + + /* normalize the URI */ + if (uri && strlen(uri) == 0) + uri = NULL; + + g_free (self->priv->uri); + self->priv->uri = g_strdup (uri); + sml_return_val_error_if_fail (!uri || self->priv->uri, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the URI - out of memory."); + + return TRUE; +} + +/** + * sml_location_get_name: + * @self: A #SmlLocation + * + * Gets the name property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_location_get_name (SmlLocation *self) +{ + g_return_val_if_fail (SML_IS_LOCATION (self), NULL); + return self->priv->name; +} + +/** + * sml_location_set_name: + * @self: A #SmlLocation + * @name: + * + * Sets the name property. + */ +gboolean +sml_location_set_name (SmlLocation *self, + const gchar* name, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + + /* normalize the name */ + if (name && strlen(name) == 0) + name = NULL; + + g_free (self->priv->name); + self->priv->name = g_strdup (name); + sml_return_val_error_if_fail (!name || self->priv->name, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the name - out of memory."); + + return TRUE; +} + +/** + * sml_location_get_parent_uri: + * @self: A #SmlLocation + * + * Gets the parentURI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_location_get_parent_uri (SmlLocation *self) +{ + g_return_val_if_fail (SML_IS_LOCATION (self), NULL); + return self->priv->parent_uri; +} + +/** + * sml_location_set_parent_uri: + * @self: A #SmlLocation + * @parent_uri: + * + * Sets the parentURI property. + */ +gboolean +sml_location_set_parent_uri (SmlLocation *self, + const gchar* parent_uri, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + + /* normalize the parent URI */ + if (parent_uri && strlen(parent_uri) == 0) + parent_uri = NULL; + + g_free (self->priv->parent_uri); + self->priv->parent_uri = g_strdup (parent_uri); + sml_return_val_error_if_fail (!parent_uri || self->priv->parent_uri, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the parent URI - out of memory."); + + return TRUE; +} + +/** + * sml_location_clone: + * @self: A #SmlLocation + * + * + */ +SmlLocation* +sml_location_clone (SmlLocation *self, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + + SmlLocation *loc = sml_location_new(); + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); + if (self->priv->uri && !sml_location_set_uri(loc, self->priv->uri, error)) { + g_object_unref(loc); + return NULL; + } + if (self->priv->name && !sml_location_set_name(loc, self->priv->name, error)) { + g_object_unref(loc); + return NULL; + } + if (self->priv->parent_uri && !sml_location_set_parent_uri(loc, self->priv->parent_uri, error)) { + g_object_unref(loc); + return NULL; + } + return loc; +} + +/** + * + * This function replaces all occurences of @needle with @replacement. + * Actually we must still support glib 2.12. Therefore we cannot use + * GRegex. + * + */ +static gchar* +_sml_location_strreplace (const gchar *input, + const gchar *needle, + const gchar *replacement, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (input, NULL, error, SML_ERROR_GENERIC, "There must be an input string."); + sml_return_val_error_if_fail (strlen(input) > 0, NULL, error, SML_ERROR_GENERIC, "The input string cannot be an empty string."); + sml_return_val_error_if_fail (needle, NULL, error, SML_ERROR_GENERIC, "There must be a needle string."); + sml_return_val_error_if_fail (strlen(needle) > 0, NULL, error, SML_ERROR_GENERIC, "The needle string cannot be an empty string."); + + /* normalize the replacement string */ + if (replacement != NULL && strlen(replacement) == 0) + replacement = NULL; + + gchar *output = g_strdup(input); + sml_return_val_error_if_fail (output, NULL, error, SML_ERROR_GENERIC, "Cannot duplicate input string - out of memory."); + + /* loop until there is no needle */ + while (g_strrstr(output, needle)) { + + /* copy the string until the position of the needle */ + gchar *prefix = g_strndup(output, g_strrstr(output, needle) - output); + sml_return_val_error_if_fail (prefix, NULL, error, SML_ERROR_GENERIC, "Cannot copy string before the needle - out of memory."); + + /* concatenate prefix of needle, replacement and suffix of needle */ + gchar *buffer2 = g_strconcat(prefix, replacement ? replacement : "", g_strrstr(output, needle) + strlen(needle), NULL); + sml_return_val_error_if_fail (buffer2, NULL, error, SML_ERROR_GENERIC, "Cannot create new string with replacement - out of memory."); + + /* cleanup */ + g_free(prefix); + g_free(output); + output = buffer2; + } + + return output; +} + +static gchar* +_sml_location_get_normalized_uri (const gchar *uri, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (uri, NULL, error, SML_ERROR_GENERIC, "There must be an URI."); + sml_return_val_error_if_fail (strlen(uri) > 0, NULL, error, SML_ERROR_GENERIC, "The URI cannot be an empty string."); + + /* remove ./ (e.g. "./Contacts" will be "Contacts") */ + gchar *buffer = _sml_location_strreplace(uri, "./", "", error); + if (!buffer) + return NULL; + + /* replace // from Windows-like systems (e.g. "//Contacts" will be "/Contacts") */ + gchar *buffer2 = _sml_location_strreplace(buffer, "//", "/", error); + if (!buffer2) + return NULL; + + /* cleanup */ + g_free(buffer); + buffer = NULL; + + /* remove a trailing slash "/" (e.g. "Contacts/" will be "Contacts") + * Don't do this if the URI is "/" which has a special meaning. + */ + if (strlen(buffer2) > 1 && buffer2[strlen(buffer2) - 1] == '/') + buffer2[strlen(buffer2) - 1] = 0; + + return buffer2; +} + +/** + * sml_location_get_full_uri: + * @self: A #SmlLocation + * + * Gets the name property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_location_get_full_uri (SmlLocation *self, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + + /* cleanup cache */ + if (self->priv->full_uri) { + g_free(self->priv->full_uri); + self->priv->full_uri = NULL; + } + + /* normalize URI */ + gchar *path = NULL; + if (self->priv->uri) { + path = _sml_location_get_normalized_uri(self->priv->uri, error); + if (!path) + return NULL; + } + + /* add parent (e.g. TargetRef or SourceRef from hierarchical sync) */ + if (self->priv->parent_uri) { + + /* normalize parent */ + gchar *parent_uri = _sml_location_get_normalized_uri(self->priv->parent_uri, error); + if (!parent_uri) { + g_free(path); + return NULL; + } + + /* ensure absolute URI */ + if (path && !g_path_is_absolute(path)) { + gchar *absolute = g_strconcat("/", path, NULL); + g_free(path); + path = absolute; + if (!path) + g_free(parent_uri); + sml_return_val_error_if_fail (path, NULL, error, SML_ERROR_GENERIC, "Cannot add '/' as prefix - out of memory."); + } + + /* prepend the parent */ + gchar *parent = g_strconcat(parent_uri, path, NULL); + g_free(path); + g_free(parent_uri); + path = parent; + sml_return_val_error_if_fail (path, NULL, error, SML_ERROR_GENERIC, "Cannot add parent as prefix - out of memory."); + } + + /* cache the result */ + self->priv->full_uri = _sml_location_get_normalized_uri(path, error); + g_free(path); + + return self->priv->full_uri; +} + +/** + * sml_location_is_equal: + * @self: A #SmlLocation + * + * + */ +gboolean +sml_location_is_equal (SmlLocation *self, + SmlLocation *loc) +{ + g_return_val_if_fail (SML_IS_LOCATION (self), FALSE); + + GError *error = NULL; + gboolean ret = FALSE; + + if (!loc) + return FALSE; + + /* normalization */ + + const char *loc_path = sml_location_get_full_uri(loc, &error); + if (!loc_path) { + g_warning("%s", error->message); + g_error_free(error); + return FALSE; + } + + const char *self_path = sml_location_get_full_uri(self, &error); + if (!self_path) { + g_warning("%s", error->message); + g_error_free(error); + return FALSE; + } + + /* comparison */ + + if (strcmp(self_path, loc_path) != 0) + ret = FALSE; + else + ret = TRUE; + + return ret; +} Added: trunk/libsyncml/data_sync_api/sml_location.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_location.h Wed Jul 1 15:31:13 2009 (r1138) @@ -0,0 +1,67 @@ +/* sml_location.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_LOCATION_H__ +#define __SML_LOCATION_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define SML_TYPE_LOCATION (sml_location_get_type()) +#define SML_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_LOCATION, SmlLocation)) +#define SML_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_LOCATION, SmlLocationClass)) +#define SML_IS_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_LOCATION)) +#define SML_IS_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_LOCATION)) +#define SML_LOCATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_LOCATION, SmlLocationClass)) + +typedef struct _SmlLocation SmlLocation; +typedef struct _SmlLocationClass SmlLocationClass; +typedef struct _SmlLocationPrivate SmlLocationPrivate; + +struct _SmlLocation +{ + GObject parent; + + /*< private >*/ + SmlLocationPrivate *priv; +}; + +struct _SmlLocationClass +{ + GObjectClass parent_class; + +}; + +GType sml_location_get_type (void); +SmlLocation* sml_location_new (void); +G_CONST_RETURN gchar* sml_location_get_uri (SmlLocation *self); +gboolean sml_location_set_uri (SmlLocation *self, const gchar* uri, GError **error); +G_CONST_RETURN gchar* sml_location_get_name (SmlLocation *self); +gboolean sml_location_set_name (SmlLocation *self, const gchar* name, GError **error); +G_CONST_RETURN gchar* sml_location_get_parent_uri (SmlLocation *self); +gboolean sml_location_set_parent_uri (SmlLocation *self, const gchar* parent_uri, GError **error); +SmlLocation* sml_location_clone (SmlLocation *self, GError **error); +gboolean sml_location_is_equal (SmlLocation *self, SmlLocation *loc); +G_CONST_RETURN gchar* sml_location_get_full_uri (SmlLocation *self, GError **error); + +G_END_DECLS + +#endif /* __SML_LOCATION_H__ */ Added: trunk/libsyncml/data_sync_api/sml_location_internals.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_location_internals.h Wed Jul 1 15:31:13 2009 (r1138) @@ -0,0 +1,33 @@ +/* sml_location_internals.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_LOCATION_INTERNALS_H__ +#define __SML_LOCATION_INTERNALS_H__ + +#include "sml_location.h" +#include "../sml_error_internals.h" + +G_BEGIN_DECLS + +SmlLocation* sml_location_new_with_options (const gchar* uid, const gchar* name, GError **error); + +G_END_DECLS + +#endif /* __SML_LOCATION_INTERNALS_H__ */ Modified: trunk/libsyncml/data_sync_api/transport_http_client.c ============================================================================== --- trunk/libsyncml/data_sync_api/transport_http_client.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/data_sync_api/transport_http_client.c Wed Jul 1 15:31:13 2009 (r1138) @@ -68,6 +68,7 @@ smlAssert(dsObject->manager); smlAssert(dsObject->agent); + GError *gerror = NULL; SmlLocation *target = NULL; SmlLocation *source = NULL; @@ -83,12 +84,21 @@ /* create session */ - target = smlLocationNew(dsObject->target, NULL, error); - if (!target) + target = sml_location_new(); + if (!target) { + g_set_error(&gerror, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; - source = smlLocationNew(dsObject->identifier, NULL, error); - if (!source) + } + if (!sml_location_set_uri(target, dsObject->target, &gerror)) + g_object_unref(target); + + source = sml_location_new(); + if (!source) { + g_set_error(&gerror, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; + } + if (!sml_location_set_uri(source, dsObject->identifier, &gerror)) + g_object_unref(source); char *sessionString = smlManagerGetNewSessionID(dsObject->manager); dsObject->session = smlSessionNew(SML_SESSION_TYPE_CLIENT, @@ -101,9 +111,9 @@ if (!dsObject->session) goto error; - smlLocationUnref(target); + g_object_unref(target); target = NULL; - smlLocationUnref(source); + g_object_unref(source); source = NULL; /* register all the add-ons */ @@ -116,13 +126,17 @@ return TRUE; error: if (target) { - smlLocationUnref(target); + g_object_unref(target); target = NULL; } if (source) { - smlLocationUnref(source); + g_object_unref(source); source = NULL; } + if (gerror) { + smlErrorSet(error, gerror->code, "%s", gerror->message); + g_error_free(gerror); + } smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); return FALSE; } Modified: trunk/libsyncml/objects/sml_auth.c ============================================================================== --- trunk/libsyncml/objects/sml_auth.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/objects/sml_auth.c Wed Jul 1 15:31:13 2009 (r1138) @@ -107,14 +107,14 @@ * LocName(username) */ if (auth->verifyCallback(session->chal, cred, - smlLocationGetName(session->source), + sml_location_get_name(session->source), auth->verifyCallbackUserdata, &error)) { auth->state = SML_AUTH_ACCEPTED; } else { smlErrorSet(&error, SML_ERROR_AUTH_REJECTED, "Auth rejected for username %s", - smlLocationGetName(session->source)); + sml_location_get_name(session->source)); smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); smlErrorDeref(&error); auth->state = SML_ERROR_AUTH_REJECTED; @@ -401,7 +401,7 @@ // of the remote peer // we have to revert source and target smlTrace(TRACE_INTERNAL, "%s: SourceRef: %s --> TargetRef: %s", - __func__, VA_STRING(session->target->locURI), VA_STRING(session->source->locURI)); + __func__, VA_STRING(sml_location_get_uri(session->target)), VA_STRING(sml_location_get_uri(session->source))); SmlStatus *reply = smlStatusNew(code, 0, session->lastReceivedMessageID, session->target, session->source, SML_COMMAND_TYPE_HEADER, error); if (!reply) goto error; Modified: trunk/libsyncml/objects/sml_devinf_obj.c ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/objects/sml_devinf_obj.c Wed Jul 1 15:31:13 2009 (r1138) @@ -29,6 +29,7 @@ #include <libsyncml/sml_command_internals.h> #include "libsyncml/sml_error_internals.h" #include "libsyncml/parser/sml_xml_parse.h" +#include "libsyncml/data_sync_api/sml_location_internals.h" #ifdef WIN32 #include <windef.h> @@ -600,11 +601,21 @@ smlAssert(agent); smlAssert(manager); - SmlLocation *devinf12 = smlLocationNew("./devinf12", NULL, error); - SmlLocation *devinf11 = smlLocationNew("./devinf11", NULL, error); - SmlLocation *devinf10 = smlLocationNew("./devinf10", NULL, error); + GError *gerror = NULL; + SmlLocation *devinf10 = NULL; + SmlLocation *devinf11 = NULL; + SmlLocation *devinf12 = NULL; + + devinf12 = sml_location_new_with_options("./devinf12", NULL, &gerror); + if (!devinf12) + goto error; + + devinf11 = sml_location_new_with_options("./devinf11", NULL, &gerror); + if (!devinf12) + goto error; - if (!devinf12 || !devinf11 || !devinf10) + devinf10 = sml_location_new_with_options("./devinf10", NULL, &gerror); + if (!devinf12) goto error; /* PUT callbacks @@ -633,17 +644,17 @@ manager, SML_COMMAND_TYPE_PUT, session, NULL, devinf10, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_PUT, session, NULL, devinf11, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_PUT, session, NULL, devinf12, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; /* GET callbacks * @@ -670,17 +681,17 @@ manager, SML_COMMAND_TYPE_GET, session, devinf10, NULL, NULL, _request_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_GET, session, devinf11, NULL, NULL, _request_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_GET, session, devinf12, NULL, NULL, _request_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; /* RESULTS callbacks * @@ -703,33 +714,33 @@ manager, SML_COMMAND_TYPE_RESULTS, session, devinf10, NULL, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_RESULTS, session, devinf11, NULL, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; if (!smlManagerObjectRegister( manager, SML_COMMAND_TYPE_RESULTS, session, devinf12, NULL, NULL, _recv_devinf, NULL, agent, error)) - goto error_free_loc; + goto error; - smlLocationUnref(devinf10); - smlLocationUnref(devinf11); - smlLocationUnref(devinf12); + g_object_unref(devinf10); + g_object_unref(devinf11); + g_object_unref(devinf12); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; -error_free_loc: +error: if (devinf10) - smlLocationUnref(devinf10); + g_object_unref(devinf10); if (devinf11) - smlLocationUnref(devinf11); + g_object_unref(devinf11); if (devinf12) - smlLocationUnref(devinf12); -error: + g_object_unref(devinf12); + GERROR_TO_SML_ERROR(gerror,error) smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return FALSE; } Modified: trunk/libsyncml/objects/sml_ds_server.c ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/objects/sml_ds_server.c Wed Jul 1 15:31:13 2009 (r1138) @@ -200,7 +200,7 @@ goto error; server->location = location; - smlLocationRef(location); + g_object_ref(location); server->contenttype = g_strdup(type); server->servertype = SML_DS_SERVER; @@ -225,10 +225,10 @@ goto error; server->location = location; - smlLocationRef(location); + g_object_ref(location); server->target = target; - smlLocationRef(target); + g_object_ref(target); server->contenttype = g_strdup(type); server->servertype = SML_DS_CLIENT; @@ -253,10 +253,10 @@ smlAssert(server); if (server->location) - smlLocationUnref(server->location); + g_object_unref(server->location); if (server->target) - smlLocationUnref(server->target); + g_object_unref(server->target); if (server->contenttype) smlSafeCFree(&(server->contenttype)); @@ -315,7 +315,7 @@ { smlAssert(server); if (server->location) - return server->location->locURI; + return sml_location_get_uri(server->location); return NULL; } @@ -332,7 +332,7 @@ smlAssert(san); CHECK_ERROR_REF - if (!smlNotificationNewAlert(san, SML_ALERT_TWO_WAY_BY_SERVER, server->contenttype, smlLocationGetURI(server->location), error)) + if (!smlNotificationNewAlert(san, SML_ALERT_TWO_WAY_BY_SERVER, server->contenttype, sml_location_get_uri(server->location), error)) goto error; smlTrace(TRACE_EXIT, "%s", __func__); @@ -422,11 +422,11 @@ if (server->servertype == SML_DS_CLIENT) { dsession->target = server->target; - smlLocationRef(dsession->target); + g_object_ref(dsession->target); } dsession->location = server->location; - smlLocationRef(dsession->location); + g_object_ref(dsession->location); dsession->pendingMapsLock = g_mutex_new(); @@ -458,10 +458,10 @@ smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__); if (dsession->target) - smlLocationUnref(dsession->target); + g_object_unref(dsession->target); if (dsession->location) - smlLocationUnref(dsession->location); + g_object_unref(dsession->location); if (dsession->alertCommand) smlCommandUnref(dsession->alertCommand); @@ -652,7 +652,12 @@ if (!smlItemStealData(item, &data, &size, &error)) goto error; - if (!dsession->changesCallback(dsession, cmd->private.change.type, item->target ? item->target->locURI : item->source->locURI, data, size, item->contenttype, dsession->changesCallbackUserdata, &error)) + if (!dsession->changesCallback(dsession, + cmd->private.change.type, + item->target ? sml_location_get_uri(item->target) : sml_location_get_uri(item->source), + data, size, + item->contenttype, + dsession->changesCallbackUserdata, &error)) goto error; } @@ -744,7 +749,7 @@ return; } - if (!smlLocationCompare(NULL, dsession->location, NULL, cmd->target)) { + if (!sml_location_is_equal(dsession->location, cmd->target)) { SmlStatus *reply = smlCommandNewReply(cmd, SML_ERROR_NOT_FOUND, &error); if (!reply) goto error; @@ -764,7 +769,7 @@ if (!dsession->target) { dsession->target = cmd->source; - smlLocationRef(cmd->source); + g_object_ref(cmd->source); } dsession->alertCommand = cmd; @@ -907,15 +912,15 @@ item->source, dsession->recvMappingCallbackUserdata); } else { - SmlWriteContext *ctx = _write_context_find(dsession, item->target->locURI, SML_CHANGE_ADD); + SmlWriteContext *ctx = _write_context_find(dsession, sml_location_get_uri(item->target), SML_CHANGE_ADD); if (ctx) { - ctx->newuid = g_strdup(item->source->locURI); + ctx->newuid = g_strdup(sml_location_get_uri(item->source)); _write_context_dispatch(dsession, ctx); } else { smlTrace(TRACE_ERROR, "%s: Unknown map ... %s => %s", __func__, - VA_STRING(item->target->locURI), - VA_STRING(item->source->locURI)); + VA_STRING(sml_location_get_uri(item->target)), + VA_STRING(sml_location_get_uri(item->source))); } } } @@ -1305,9 +1310,9 @@ session->sessionType = SML_SESSION_TYPE_CLIENT; /* fix target */ - smlLocationUnref(server->target); + g_object_unref(server->target); server->target = cmd->source; - smlLocationRef(server->target); + g_object_ref(server->target); /* handle the SAN */ if (server->sanSessionCallback) { Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/parser/sml_xml_assm.c Wed Jul 1 15:31:13 2009 (r1138) @@ -245,16 +245,16 @@ goto error; } - if (!location->locURI) { + if (!sml_location_get_uri(location)) { smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); goto error; } - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, location->locURI, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, sml_location_get_uri(location), error)) goto error; - if (location->locName) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, location->locName, error)) + if (sml_location_get_name(location)) { + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, sml_location_get_name(location), error)) goto error; } @@ -573,25 +573,25 @@ sessionType == SML_SESSION_TYPE_SERVER) { /* only Target must be set */ if (item->target) - smlLocationUnref(item->target); + g_object_unref(item->target); item->target = item->source; item->source = NULL; } else { /* only Source must be set */ if (item->target) - smlLocationUnref(item->target); + g_object_unref(item->target); item->target = NULL; } } else { if (sessionType == SML_SESSION_TYPE_SERVER) { /* Target must be set */ if (item->source) - smlLocationUnref(item->source); + g_object_unref(item->source); item->source = NULL; } else { /* only Source must be set */ if (item->target) - smlLocationUnref(item->target); + g_object_unref(item->target); item->target = NULL; } } @@ -852,13 +852,13 @@ /* TargetRef */ if (cmd->private.results.status->targetRef) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_TARGETREF, cmd->private.results.status->targetRef->locURI, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_TARGETREF, sml_location_get_uri(cmd->private.results.status->targetRef), error)) goto error; } /* SourceRef */ if (cmd->private.results.status->sourceRef) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_SOURCEREF, cmd->private.results.status->sourceRef->locURI, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_SOURCEREF, sml_location_get_uri(cmd->private.results.status->sourceRef), error)) goto error; } @@ -1413,13 +1413,13 @@ /* TargetRef */ if (status->targetRef) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_TARGETREF, status->targetRef->locURI, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_TARGETREF, sml_location_get_uri(status->targetRef), error)) goto error; } /* SourceRef */ if (status->sourceRef) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_SOURCEREF, status->sourceRef->locURI, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_SOURCEREF, sml_location_get_uri(status->sourceRef), error)) goto error; } Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Mon Jun 29 16:06:44 2009 (r1137) +++ trunk/libsyncml/parser/sml_xml_parse.c Wed Jul 1 15:31:13 2009 (r1138) @@ -26,6 +26,7 @@ #include <libsyncml/sml_command_internals.h> #include <libsyncml/sml_session_internals.h> #include "libsyncml/sml_error_internals.h" +#include "libsyncml/data_sync_api/sml_location_internals.h" #include "sml_xml_parse.h" #include "sml_xml_parse_internals.h" @@ -372,6 +373,7 @@ CHECK_ERROR_REF smlAssert(parser); smlAssert(location); + GError *gerror = NULL; if (*location) { smlErrorSet(error, SML_ERROR_GENERIC, "Location already set"); @@ -379,15 +381,16 @@ return FALSE; } - *location = smlTryMalloc0(sizeof(SmlLocation), error); - if (!location) + *location = sml_location_new(); + if (!location) { + smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; - (*location)->refCount = 1; + } while (1) { if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_location; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET) && \ @@ -406,33 +409,46 @@ smlErrorSet(error, SML_ERROR_GENERIC, "The element %s is not a start node in locations (Target, Source, SourceParent or TargetParent).", xmlTextReaderConstName(parser->reader)); - goto error_free_location; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_LOCURI)) { - if (!_smlXmlParserGetString(parser, &((*location)->locURI), SML_ELEMENT_LOCURI, error)) - goto error_free_location; + gchar *uri = NULL; + if (!_smlXmlParserGetString(parser, &uri, SML_ELEMENT_LOCURI, error)) + goto error; + if (!sml_location_set_uri(*location, uri, &gerror)) { + g_free(uri); + goto error; + } + g_free(uri); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_LOCNAME)) { - if (!_smlXmlParserGetString(parser, &((*location)->locName), SML_ELEMENT_LOCNAME, error)) - goto error_free_location; + gchar *name = NULL; + if (!_smlXmlParserGetString(parser, &name, SML_ELEMENT_LOCNAME, error)) + goto error; + if (!sml_location_set_name(*location, name, &gerror)) { + g_free(name); + goto error; + } + g_free(name); } else { smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node. expected SyncHdr"); - goto error_free_location; + goto error; } } - if (!(*location)->locURI) { + if (!sml_location_get_uri(*location)) { smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); - goto error_free_location; + goto error; } smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; -error_free_location: - smlLocationUnref(*location); error: + if (*location) + g_object_unref(*location); *location = NULL; + GERROR_TO_SML_ERROR(gerror,error) smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return FALSE; } @@ -686,28 +702,28 @@ goto error_free_item; smlItemSetSource(item, source); - smlLocationUnref(source); + g_object_unref(source); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET)) { SmlLocation *target = NULL; if (!_smlLocationParse(&target, parser, error)) goto error_free_item; smlItemSetTarget(item, target); - smlLocationUnref(target); + g_object_unref(target); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE_PARENT)) { SmlLocation *source = NULL; if (!_smlLocationParse(&source, parser, error)) goto error_free_item; smlItemSetSourceParent(item, source); - smlLocationUnref(source); + g_object_unref(source); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET_PARENT)) { SmlLocation *target = NULL; if (!_smlLocationParse(&target, parser, error)) goto error_free_item; smlItemSetTargetParent(item, target); - smlLocationUnref(target); + g_object_unref(target); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { switch (type) { case SML_COMMAND_TYPE_ALERT: @@ -994,6 +1010,7 @@ CHECK_ERROR_REF smlAssert(parser); smlAssert(name); + GError *gerror = NULL; char *contenttype = NULL; *cmd = smlCommandNew(type, error); @@ -1004,7 +1021,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_cmd; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), name) && \ @@ -1014,41 +1031,41 @@ smlErrorSet(error, SML_ERROR_GENERIC, "The element %s is not a start node in %s.", xmlTextReaderConstName(parser->reader), name); - goto error_free_cmd; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { SmlItem *item = _smlItemParse(parser, *cmd, type, error); if (!item) - goto error_free_cmd; + goto error; (*cmd)->private.change.items = g_list_append((*cmd)->private.change.items, item); if (!(*cmd)->private.change.items) { smlItemUnref(item); smlErrorSet(error, SML_ERROR_GENERIC, "g_list_append for item list of change command failed."); - goto error_free_cmd; + goto error; } } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { if (!_smlCommandMetaParse(parser, NULL, &contenttype, NULL, &(*cmd)->size, NULL, error)) - goto error_free_cmd; + goto error; } else { smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); - goto error_free_cmd; + goto error; } } if (!(*cmd)->cmdID) { smlErrorSet(error, SML_ERROR_GENERIC, "No cmdid set"); - goto error_free_cmd; + goto error; } if (!(*cmd)->private.change.items || !g_list_length((*cmd)->private.change.items)) { smlErrorSet(error, SML_ERROR_GENERIC, "No items set"); - goto error_free_cmd; + goto error; } /* some clients set the contentype in the item, don't overwrite it with NULL */ @@ -1082,16 +1099,16 @@ break; default: smlErrorSet(error, SML_ERROR_GENERIC, "Unknown change type set"); - goto error_free_cmd; + goto error; } if (!(*cmd)->source) { SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); if (item->source) { - (*cmd)->source = smlLocationClone(item->source, error); + (*cmd)->source = sml_location_clone(item->source, &gerror); if (!(*cmd)->source) - goto error_free_cmd; + goto error; } } @@ -1099,27 +1116,28 @@ { SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); if (item->target) { - (*cmd)->target = smlLocationClone(item->target, error); + (*cmd)->target = sml_location_clone(item->target, &gerror); if (!(*cmd)->target) - goto error_free_cmd; + goto error; } } /* Step once more */ if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_cmd; + goto error; } smlTrace(TRACE_EXIT, "%s: %p", __func__, *cmd); return TRUE; -error_free_cmd: - smlCommandUnref(*cmd); error: + if (*cmd) + smlCommandUnref(*cmd); + *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); - *cmd = NULL; + GERROR_TO_SML_ERROR(gerror,error) smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return FALSE; } @@ -1535,6 +1553,7 @@ CHECK_ERROR_REF smlAssert(parser); smlAssert(cmd); + GError *gerror = NULL; char *contenttype = NULL; char *locURI = NULL; @@ -1553,7 +1572,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_cmd; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_RESULTS) && \ @@ -1563,39 +1582,39 @@ smlErrorSet(error, SML_ERROR_GENERIC, "The element %s is not a start node in Results.", xmlTextReaderConstName(parser->reader)); - goto error_free_cmd; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MSGREF)) { if (!_smlXmlParserGetID(parser, &((*cmd)->private.results.status->msgRef), SML_ELEMENT_MSGREF, error)) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDREF)) { if (!_smlXmlParserGetID(parser, &((*cmd)->private.results.status->cmdRef), SML_ELEMENT_CMDREF, error)) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCEREF)) { if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) - goto error_free_cmd; + goto error; - (*cmd)->private.results.status->sourceRef = smlLocationNew(locURI, NULL, error); + (*cmd)->private.results.status->sourceRef = sml_location_new_with_options(locURI, NULL, &gerror); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->sourceRef) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGETREF)) { if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) - goto error_free_cmd; + goto error; - (*cmd)->private.results.status->targetRef = smlLocationNew(locURI, NULL, error); + (*cmd)->private.results.status->targetRef = sml_location_new_with_options(locURI, NULL, &gerror); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->targetRef) - goto error_free_cmd; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { (*cmd)->private.results.status->item = _smlItemParse(parser, (*cmd), (*cmd)->type, error); if (!(*cmd)->private.results.status->item) - goto error_free_cmd; + goto error; (*cmd)->target = (*cmd)->private.results.status->item->target; (*cmd)->private.results.status->item->target = NULL; @@ -1605,17 +1624,17 @@ /* ignore format */ char *format = NULL; if (!_smlCommandMetaParse(parser, &format, &contenttype, NULL, NULL, NULL, error)) - goto error_free_cmd; + goto error; if (format) smlSafeCFree(&format); } else { smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); - goto error_free_cmd; + goto error; } } if (!(*cmd)->private.results.status->item) { smlErrorSet(error, SML_ERROR_GENERIC, "Result is missing item"); - goto error_free_cmd; + goto error; } /* We only use the content type of the put command if the item itself did not have @@ -1623,7 +1642,7 @@ if (!(*cmd)->private.results.status->item->contenttype) { if (!contenttype) { smlErrorSet(error, SML_ERROR_GENERIC, "Result is missing content type"); - goto error_free_cmd; + goto error; } (*cmd)->private.results.status->item->contenttype = g_strdup(contenttype); @@ -1635,18 +1654,19 @@ /* Step once more */ if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_cmd; + goto error; } smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; -error_free_cmd: - smlCommandUnref(*cmd); error: + if (*cmd) + smlCommandUnref(*cmd); *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); + GERROR_TO_SML_ERROR(gerror,error) smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return FALSE; } @@ -2299,6 +2319,7 @@ smlAssert(parser); smlAssert(status); + GError *gerror = NULL; char *locURI = NULL; SmlItem *item = NULL; @@ -2362,7 +2383,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_status; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_STATUS) && \ @@ -2372,15 +2393,15 @@ smlErrorSet(error, SML_ERROR_GENERIC, "The element %s is not a start node in Status.", xmlTextReaderConstName(parser->reader)); - goto error_free_status; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { //Errr... who cares? if (!_smlXmlParserExpectNode(parser, XML_NODE_TEXT, FALSE, NULL, error)) - goto error_free_status; + goto error; if (!_smlXmlParserExpectNode(parser, XML_NODE_CLOSE, FALSE, SML_ELEMENT_CMDID, error)) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MSGREF)) { /* MsgRef is defined as parsed character data: OMA-SUP-DTD_SyncML_RepPro-V1_2-20070221-A.txt:<!ELEMENT MsgRef (#PCDATA)> @@ -2391,37 +2412,37 @@ So it could be something else then an unsigned integer. */ if (!_smlXmlParserGetID(parser, &((*status)->msgRef), SML_ELEMENT_MSGREF, error)) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDREF)) { if (!_smlXmlParserGetID(parser, &((*status)->cmdRef), SML_ELEMENT_CMDREF, error)) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMD)) { char *cmdname = NULL; if (!_smlXmlParserGetString(parser, &cmdname, SML_ELEMENT_CMD, error)) - goto error_free_status; + goto error; (*status)->type = smlCommandTypeFromString(cmdname, error); smlSafeCFree(&cmdname); if ((*status)->type == SML_COMMAND_TYPE_UNKNOWN) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { if (!_smlXmlParserGetString(parser, &((*status)->data), SML_ELEMENT_DATA, error)) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCEREF)) { if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) - goto error_free_status; + goto error; - (*status)->sourceRef = smlLocationNew(locURI, NULL, error); + (*status)->sourceRef = sml_location_new_with_options(locURI, NULL, &gerror); smlSafeCFree(&locURI); if (!(*status)->sourceRef) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGETREF)) { if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) - goto error_free_status; + goto error; - (*status)->targetRef = smlLocationNew(locURI, NULL, error); + (*status)->targetRef = sml_location_new_with_options(locURI, NULL, &gerror); smlSafeCFree(&locURI); if (!(*status)->targetRef) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { /* Do not send SML_COMMAND_TYPE_ALERT * because this can give trouble. @@ -2429,11 +2450,11 @@ */ item = _smlItemParse(parser, NULL, (*status)->type, error); if (!item) - goto error_free_status; + goto error; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CHAL)) { (*status)->chal = _smlChalParse(parser, error); if (!(*status)->chal) - goto error_free_status; + goto error; } else { smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); goto error; @@ -2443,7 +2464,7 @@ /* Step once more */ if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); - goto error_free_status; + goto error; } if (item) @@ -2462,7 +2483,7 @@ } else { smlErrorSet(error, SML_ERROR_GENERIC, "Got wrong item"); smlItemUnref(item); - goto error_free_status; + ... [truncated message content] |