From: <svn...@op...> - 2009-07-02 14:15:48
|
Author: bellmich Date: Thu Jul 2 16:06:31 2009 New Revision: 1143 URL: http://libsyncml.opensync.org/changeset/1143 Log: - migrated sml_elements and sml_error from SmlError to GError - fixed some minor issues in sml_command Modified: trunk/libsyncml/CMakeLists.txt trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h trunk/libsyncml/sml_command_internals.h trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h trunk/libsyncml/sml_error.h trunk/libsyncml/sml_error_internals.h trunk/libsyncml/sml_parse.c trunk/libsyncml/sml_support.h Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/CMakeLists.txt Thu Jul 2 16:06:31 2009 (r1143) @@ -5,7 +5,6 @@ SET( libsyncml_LIB_SRCS sml_command.c sml_elements.c - sml_error.c sml_manager.c sml_md5.c sml_notification.c @@ -71,10 +70,7 @@ objects/sml_devinf_obj.h objects/sml_ds_server.h objects/sml_auth.h - sml_command.h sml_defines.h - sml_elements.h - sml_error.h sml_manager.h sml_md5.h sml_notification.h Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_command.c Thu Jul 2 16:06:31 2009 (r1143) @@ -30,7 +30,7 @@ #include "parser/sml_xml_assm.h" SmlCommandType -smlCommandTypeFromString (const char *name, +smlCommandTypeFromString (const gchar *name, GError **error) { CHECK_ERROR_REF @@ -98,8 +98,8 @@ SmlStatus* smlStatusNew (SmlErrorType data, - guint cmdref, - guint msgref, + gsize cmdref, + gsize msgref, SmlLocation *sourceref, SmlLocation *targetref, SmlCommandType type, @@ -266,7 +266,7 @@ smlCommandNewResult (SmlCommand *cmd, SmlLocation *source, gchar *data, - guint size, + gsize size, const gchar *contenttype, GError **error) { @@ -396,7 +396,7 @@ smlCommandNewChange (SmlChangeType type, const gchar *uid, const gchar *data, - guint size, + gsize size, const gchar *contenttype, GError **error) { @@ -474,8 +474,8 @@ smlCommandNewPartialChange (SmlChangeType type, const gchar *uid, const gchar *data, - guint complete_size, - guint partial_size, + gsize complete_size, + gsize partial_size, const gchar *contenttype, GError **error) { @@ -597,7 +597,7 @@ SmlCommand* smlCommandNewSync (SmlLocation *target, SmlLocation *source, - guint num_changes, + gsize num_changes, GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, target, source, num_changes, error); @@ -625,7 +625,7 @@ smlCommandNewPut (SmlLocation *target, SmlLocation *source, const gchar *data, - guint size, + gsize size, const gchar *contenttype, GError **error) { Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_command.h Thu Jul 2 16:06:31 2009 (r1143) @@ -33,33 +33,33 @@ #include <libsyncml/syncml.h> #include <libsyncml/dev_inf_api/sml_dev_inf.h> -SmlStatus *smlStatusNew(SmlErrorType data, unsigned int cmdref, unsigned int msgref, SmlLocation *sourceref, SmlLocation *targeref, SmlCommandType type, GError **error); -SmlStatus *smlStatusRef(SmlStatus *status); -void smlStatusUnref(SmlStatus *status); -SmlErrorType smlStatusGetCode(SmlStatus *status); -SmlErrorClass smlStatusGetClass(SmlStatus *status); -SmlCommand *smlStatusGetResult(SmlStatus *status); -SmlBool smlStatusIsResult(SmlStatus *status); - -SmlCommand *smlCommandNew(SmlCommandType type, GError **error); -SmlStatus *smlCommandNewReply(const SmlCommand *cmd, SmlErrorType code, GError **error); -SmlCommand *smlCommandRef(SmlCommand *cmd); -void smlCommandUnref(SmlCommand *cmd); - -SmlCommand *smlCommandNewAlert(SmlAlertType type, SmlLocation *target, SmlLocation *source, const char *next, const char *last, const char *contenttype, GError **error); -SmlCommand *smlCommandNewSync(SmlLocation *target, SmlLocation *source, unsigned int num_changes, GError **error); -SmlCommand *smlCommandNewChange(SmlChangeType type, const char *uid, const char *data, unsigned int size, const char *contenttype, GError **error); -SmlCommand *smlCommandNewPartialChange(SmlChangeType type, const char *uid, const char *data, unsigned int complete_size, unsigned int partial_size, const char *contenttype, GError **error); -SmlCommand *smlCommandNewResult(SmlCommand *cmd, SmlLocation *source, char *data, unsigned int size, const char *contenttype, GError **error); -SmlCommand *smlCommandNewPut(SmlLocation *target, SmlLocation *source, const char *data, unsigned int size, const char *contenttype, GError **error); -SmlCommand *smlCommandNewGet(SmlLocation *target, const char *contenttype, GError **error); - -SmlCommand *smlCommandNewDevInfResult(SmlCommand *cmd, SmlDevInf *devinf, SmlDevInfVersion version, GError **error); -SmlCommand *smlCommandNewDevInfPut(SmlDevInf *devinf, SmlDevInfVersion version, GError **error); -SmlCommand *smlCommandNewDevInfGet(SmlDevInfVersion version, GError **error); +SmlStatus* smlStatusNew (SmlErrorType data, gsize cmdref, gsize msgref, SmlLocation *sourceref, SmlLocation *targeref, SmlCommandType type, GError **error); +SmlStatus* smlStatusRef (SmlStatus *status); +void smlStatusUnref (SmlStatus *status); +SmlErrorType smlStatusGetCode (SmlStatus *status); +SmlErrorClass smlStatusGetClass (SmlStatus *status); +SmlCommand* smlStatusGetResult (SmlStatus *status); +gboolean smlStatusIsResult (SmlStatus *status); + +SmlCommand* smlCommandNew (SmlCommandType type, GError **error); +SmlStatus* smlCommandNewReply (const SmlCommand *cmd, SmlErrorType code, GError **error); +SmlCommand* smlCommandRef (SmlCommand *cmd); +void smlCommandUnref (SmlCommand *cmd); + +SmlCommand* smlCommandNewAlert (SmlAlertType type, SmlLocation *target, SmlLocation *source, const gchar *next, const gchar *last, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewSync (SmlLocation *target, SmlLocation *source, gsize num_changes, GError **error); +SmlCommand* smlCommandNewChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewPartialChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize complete_size, gsize partial_size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewResult (SmlCommand *cmd, SmlLocation *source, gchar *data, gsize size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewPut (SmlLocation *target, SmlLocation *source, const gchar *data, gsize size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewGet (SmlLocation *target, const gchar *contenttype, GError **error); + +SmlCommand* smlCommandNewDevInfResult (SmlCommand *cmd, SmlDevInf *devinf, SmlDevInfVersion version, GError **error); +SmlCommand* smlCommandNewDevInfPut (SmlDevInf *devinf, SmlDevInfVersion version, GError **error); +SmlCommand* smlCommandNewDevInfGet (SmlDevInfVersion version, GError **error); -SmlCommand *smlCommandNewMap(SmlLocation *target, SmlLocation *source, GError **error); -SmlBool smlCommandAddMapItem(SmlCommand *map, SmlMapItem *item, GError **error); +SmlCommand* smlCommandNewMap (SmlLocation *target, SmlLocation *source, GError **error); +gboolean smlCommandAddMapItem (SmlCommand *map, SmlMapItem *item, GError **error); #endif //_SML_COMMAND_H_ Modified: trunk/libsyncml/sml_command_internals.h ============================================================================== --- trunk/libsyncml/sml_command_internals.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_command_internals.h Thu Jul 2 16:06:31 2009 (r1143) @@ -33,18 +33,18 @@ typedef struct SmlCommandAlertPrivate { SmlAlertType type; SmlAnchor *anchor; - char *contentType; - int maxObjSize; + gchar *contentType; + gsize maxObjSize; } SmlCommandAlertPrivate; typedef struct SmlCommandSyncPrivate { - unsigned int numChanged; - int maxObjSize; + gsize numChanged; + gsize maxObjSize; SmlBool hasNumChanged; } SmlCommandSyncPrivate; typedef struct SmlCommandAccessPrivate { - char *type; + gchar *type; SmlItem *item; } SmlCommandAccessPrivate; @@ -73,8 +73,8 @@ struct SmlCommand { gint refCount; SmlCommandType type; - unsigned int cmdID; - unsigned int msgID; + gsize cmdID; + gsize msgID; SmlCommandPrivate private; SmlLocation *source; SmlLocation *target; @@ -83,7 +83,7 @@ SmlCommand *parent; SmlBool noResp; - unsigned int size; + gsize size; /** True if the command has already seen a mismatch * in size. If a second mismatch happens, the command is @@ -93,10 +93,10 @@ struct SmlStatus { gint refCount; - unsigned int msgRef; - unsigned int cmdRef; + gsize msgRef; + gsize cmdRef; SmlCommandType type; - char *data; + gchar *data; SmlAnchor *anchor; SmlLocation *sourceRef; SmlLocation *targetRef; @@ -107,10 +107,10 @@ SmlCommand *result; }; -SmlCommandType smlCommandTypeFromString(const char *name, GError **error); -const char *smlCommandTypeToString(SmlCommandType type, GError **error); +SmlCommandType smlCommandTypeFromString(const gchar *name, GError **error); +G_CONST_RETURN gchar *smlCommandTypeToString(SmlCommandType type, GError **error); -SmlAlertType smlAlertTypeConvert(unsigned int id, GError **error); +SmlAlertType smlAlertTypeConvert(guint id, GError **error); #endif //_SML_COMMAND_INTERNALS_H_ Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_elements.c Thu Jul 2 16:06:31 2009 (r1143) @@ -28,7 +28,10 @@ #include "sml_error_internals.h" #include "data_sync_api/sml_location_internals.h" -SmlAnchor *smlAnchorNew(const char *last, const char *next, SmlError **error) +SmlAnchor* +smlAnchorNew (const gchar *last, + const gchar *next, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, VA_STRING(last), VA_STRING(next), error); CHECK_ERROR_REF @@ -42,13 +45,13 @@ smlTrace(TRACE_EXIT, "%s: %p", __func__, anchor); return anchor; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -void smlAnchorFree(SmlAnchor *anchor) +void +smlAnchorFree (SmlAnchor *anchor) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, anchor); smlAssert(anchor); @@ -63,7 +66,8 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -void smlHeaderFree(SmlHeader *header) +void +smlHeaderFree (SmlHeader *header) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, header); @@ -87,7 +91,9 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -SmlItem *smlItemNew(unsigned int size, SmlError **error) +SmlItem* +smlItemNew (gsize size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%i, %p)", __func__, size, error); CHECK_ERROR_REF @@ -101,14 +107,16 @@ smlTrace(TRACE_EXIT, "%s: %p", __func__, item); return item; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } /* If data is NULL, this call is the same if smlItemNew */ -SmlItem *smlItemNewForData(const char *data, unsigned int size, SmlError **error) +SmlItem* +smlItemNewForData (const gchar *data, + gsize size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, data, size, error); CHECK_ERROR_REF @@ -119,20 +127,20 @@ if (data) { if (!smlItemAddData(item, data, size, error)) - goto error_free_item; + goto error; } smlTrace(TRACE_EXIT, "%s: %p", __func__, item); return item; - -error_free_item: - smlItemUnref(item); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + if (item) + smlItemUnref(item); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -SmlItem *smlItemRef(SmlItem *item) +SmlItem* +smlItemRef (SmlItem *item) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); smlAssert(item); @@ -143,7 +151,8 @@ return item; } -void smlItemUnref(SmlItem *item) +void +smlItemUnref(SmlItem *item) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); smlAssert(item); @@ -172,13 +181,17 @@ smlTrace(TRACE_EXIT, "%s: %i", __func__, item ? item->refCount : 0); } -SmlBool smlItemAddData(SmlItem *item, const char *data, unsigned int size, SmlError **error) +gboolean +smlItemAddData (SmlItem *item, + const gchar *data, + gsize size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, item, data, size, error); CHECK_ERROR_REF if (item->size && xmlBufferLength(item->buffer) + size > item->size) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add data. size limit reached"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to add data. size limit reached"); goto error; } @@ -191,22 +204,22 @@ } if (xmlBufferAdd(item->buffer, (xmlChar *)data, size) != 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add data."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to add data."); goto error; } } smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } /** Checks if the item is complete */ -SmlBool smlItemCheck(SmlItem *item) +gboolean +smlItemCheck (SmlItem *item) { smlAssert(xmlBufferLength(item->buffer) >= 0); smlAssert(item); @@ -224,7 +237,8 @@ return TRUE; } -SmlBool smlItemHasData(SmlItem *item) +gboolean +smlItemHasData (SmlItem *item) { smlAssert(item); return item->buffer ? TRUE : FALSE; @@ -232,14 +246,18 @@ /** Returns the data of the item. The data will not be freed when the item is unrefd. After * this call, smlItemHasData will report FALSE */ -SmlBool smlItemStealData(SmlItem *item, char **data, unsigned int *size, SmlError **error) +gboolean +smlItemStealData (SmlItem *item, + gchar **data, + gsize *size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, item, data, size, error); CHECK_ERROR_REF smlAssert(size); if (!smlItemCheck(item)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Item check failed"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Item check failed"); goto error; } @@ -250,20 +268,23 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } /** Returns a const pointer to the data of the item. the data will disappear when the data is derefd */ -SmlBool smlItemGetData(SmlItem *item, char **data, unsigned int *size, SmlError **error) +gboolean +smlItemGetData (SmlItem *item, + gchar **data, + gsize *size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, item, data, size, error); CHECK_ERROR_REF if (!smlItemCheck(item)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Item check failed"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Item check failed"); goto error; } @@ -272,13 +293,14 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -void smlItemSetSource(SmlItem *item, SmlLocation *source) +void +smlItemSetSource (SmlItem *item, + SmlLocation *source) { smlAssert(item); smlAssert(source); @@ -287,14 +309,17 @@ g_object_ref(source); } -SmlLocation *smlItemGetSource(SmlItem *item) +SmlLocation* +smlItemGetSource (SmlItem *item) { smlAssert(item); return item->source; } -void smlItemSetTarget(SmlItem *item, SmlLocation *target) +void +smlItemSetTarget (SmlItem *item, + SmlLocation *target) { smlAssert(item); smlAssert(target); @@ -303,24 +328,28 @@ g_object_ref(target); } -SmlLocation *smlItemGetTarget(SmlItem *item) +SmlLocation* +smlItemGetTarget (SmlItem *item) { smlAssert(item); return item->target; } -void smlItemSetRaw(SmlItem *item, SmlBool raw) +void +smlItemSetRaw (SmlItem *item, + gboolean raw) { smlAssert(item); item->raw = raw; } -SmlCred *smlCredNewFromString(const char *type, - const char *format, - const char *data, - SmlError **error) +SmlCred* +smlCredNewFromString (const gchar *type, + const gchar *format, + const gchar *data, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%s, %s, %s, %p)", __func__, VA_STRING(data), VA_STRING(type), VA_STRING(format), error); CHECK_ERROR_REF @@ -333,33 +362,34 @@ } else if (!strcmp(type, SML_AUTH_MD5)) { smlType = SML_AUTH_TYPE_MD5; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown type - %s.", type); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown type - %s.", type); goto error; } if (!format || !strcmp(format, SML_BASE64)) { smlFormat = SML_FORMAT_TYPE_BASE64; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "SyncML credential: Unknown format - %s.", format); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "SyncML credential: Unknown format - %s.", format); goto error; } if (!data) { - smlErrorSet(error, SML_ERROR_GENERIC, "Data is missing in %s.", __func__); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Data is missing in %s.", __func__); goto error; } smlTrace(TRACE_EXIT, "%s", __func__); return smlCredNew(smlType, smlFormat, data, NULL, error); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -SmlCred *smlCredNewAuth(SmlAuthType type, - const char *username, - const char *password, - SmlError **error) +SmlCred* +smlCredNewAuth (SmlAuthType type, + const gchar *username, + const gchar *password, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%d, %s, %p)", __func__, type, VA_STRING(username), error); CHECK_ERROR_REF @@ -367,12 +397,12 @@ SmlCred *cred = NULL; if (username == NULL || !strlen(username)) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "If authentication should be used then the username must be set."); goto error; } if (password == NULL || !strlen(password)) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "If authentication should be used then the password must be set."); goto error; } @@ -392,15 +422,16 @@ error: if (cred) smlSafeFree((gpointer *)&cred); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -SmlCred *smlCredNew(SmlAuthType type, - SmlFormatType format, - const char *data, - const char *username, - SmlError **error) +SmlCred* +smlCredNew (SmlAuthType type, + SmlFormatType format, + const gchar *data, + const gchar *username, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%s, %d, %d, %p)", __func__, VA_STRING(data), type, format, error); CHECK_ERROR_REF @@ -427,11 +458,12 @@ smlSafeCFree(&(cred->username)); if (cred) smlSafeFree((gpointer *)&cred); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -void smlCredRef(SmlCred *cred) +void +smlCredRef (SmlCred *cred) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, cred); smlAssert(cred); @@ -441,7 +473,8 @@ smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, cred->refCount); } -void smlCredUnref(SmlCred *cred) +void +smlCredUnref (SmlCred *cred) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, cred); smlAssert(cred); @@ -462,13 +495,9 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -/* FIXME: DEPRECATED */ -void smlCredFree(SmlCred *cred) -{ - smlCredUnref(cred); -} - -SmlChal *smlChalNew(SmlAuthType type, SmlError **error) +SmlChal* +smlChalNew (SmlAuthType type, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%u, %p)", __func__, type, error); CHECK_ERROR_REF @@ -496,7 +525,7 @@ (const unsigned char *) chal->nonce_plain, chal->nonce_length); if (!chal->nonce_b64) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The nonce of the challenge cannot be base64 encoded."); goto error; } @@ -511,15 +540,15 @@ smlSafeCFree(&(chal->nonce_b64)); if (chal) smlSafeFree((gpointer *)&chal); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return NULL; } -SmlChal *smlChalNewFromBinary( - SmlAuthType type, - const char *nonce, - size_t length, - SmlError **error) +SmlChal* +smlChalNewFromBinary(SmlAuthType type, + const gchar *nonce, + gsize length, + GError **error) { smlTrace(TRACE_ENTRY, "%s", __func__); CHECK_ERROR_REF @@ -543,7 +572,7 @@ /* create base64 nonce */ chal->nonce_b64 = g_base64_encode((const unsigned char *) nonce, length); if (!chal->nonce_b64) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The base64 encoding of the nonce failed."); goto error; } @@ -551,14 +580,14 @@ smlTrace(TRACE_EXIT, "%s", __func__); return chal; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return NULL; } -SmlChal *smlChalNewFromBase64( - SmlAuthType type, - const char *nonce, - SmlError **error) +SmlChal* +smlChalNewFromBase64 (SmlAuthType type, + const gchar *nonce, + GError **error) { smlTrace(TRACE_ENTRY, "%s", __func__); CHECK_ERROR_REF @@ -582,7 +611,7 @@ size_t length = 0; chal->nonce_plain = (char *) g_base64_decode(nonce, &length); if (!chal->nonce_plain || length < 1) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The base64 encoded nonce cannot be decoded."); goto error; } @@ -591,11 +620,12 @@ smlTrace(TRACE_EXIT, "%s", __func__); return chal; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return NULL; } -void smlChalRef(SmlChal *chal) +void +smlChalRef (SmlChal *chal) { smlTrace(TRACE_ENTRY, "%s", __func__); smlAssert(chal); @@ -605,7 +635,8 @@ smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, chal->refCount); } -void smlChalUnref(SmlChal *chal) +void +smlChalUnref (SmlChal *chal) { smlTrace(TRACE_ENTRY, "%s", __func__); smlAssert(chal); @@ -625,30 +656,26 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -/* FIXME: DEPRECATED */ -void smlChalFree(SmlChal *chal) -{ - smlChalUnref(chal); -} - -SmlMapItem *smlMapItemNew(const char *uid, const char *newuid, SmlError **error) +SmlMapItem* +smlMapItemNew (const gchar *uid, + const gchar *newuid, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, VA_STRING(uid), VA_STRING(newuid), error); CHECK_ERROR_REF smlAssert(uid); smlAssert(newuid); - GError *gerror = NULL; SmlMapItem *item = smlTryMalloc0(sizeof(SmlMapItem), error); if (!item) goto error; item->refCount = 1; - item->source = sml_location_new_with_options(newuid, NULL, &gerror); + item->source = sml_location_new_with_options(newuid, NULL, error); if (!item->source) goto error; - item->target = sml_location_new_with_options(uid, NULL, &gerror); + item->target = sml_location_new_with_options(uid, NULL, error); if (!item->target) goto error; @@ -661,15 +688,12 @@ g_object_unref(item->source); smlSafeFree((gpointer *)&item); } - if (gerror) { - smlErrorSet(error, gerror->code, "%s", gerror->message); - g_error_free(gerror); - } - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -SmlMapItem *smlMapItemRef(SmlMapItem *item) +SmlMapItem* +smlMapItemRef (SmlMapItem *item) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); smlAssert(item); @@ -680,7 +704,8 @@ return item; } -void smlMapItemUnref(SmlMapItem *item) +void +smlMapItemUnref (SmlMapItem *item) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); smlAssert(item); Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_elements.h Thu Jul 2 16:06:31 2009 (r1143) @@ -30,42 +30,42 @@ #ifndef _SML_ELEMENTS_H_ #define _SML_ELEMENTS_H_ -SmlCred *smlCredNewFromString(const char *type, const char *format, const char *data, GError **error); -SmlCred *smlCredNewAuth(SmlAuthType type, const char *username, const char *password, GError **error); -SmlCred *smlCredNew(SmlAuthType type, SmlFormatType format, const char *data, const char*username, GError **error); -void smlCredRef(SmlCred *cred); -void smlCredUnref(SmlCred *cred); - -SmlAnchor *smlAnchorNew(const char *last, const char *next, GError **error); -void smlAnchorFree(SmlAnchor *anchor); - -SmlItem *smlItemNew(unsigned int size, GError **error); -SmlItem *smlItemNewForData(const char *data, unsigned int size, GError **error); -SmlItem *smlItemRef(SmlItem *item); -void smlItemUnref(SmlItem *item); -SmlBool smlItemAddData(SmlItem *item, const char *data, unsigned int size, GError **error); -SmlBool smlItemCheck(SmlItem *item); -SmlBool smlItemHasData(SmlItem *item); -SmlBool smlItemGetData(SmlItem *item, char **data, unsigned int *size, GError **error); -SmlBool smlItemStealData(SmlItem *item, char **data, unsigned int *size, GError **error); - -void smlItemSetSource(SmlItem *item, SmlLocation *source); -SmlLocation *smlItemGetSource(SmlItem *item); -void smlItemSetTarget(SmlItem *item, SmlLocation *target); -SmlLocation *smlItemGetTarget(SmlItem *item); -void smlItemSetRaw(SmlItem *item, SmlBool raw); +SmlCred* smlCredNewFromString (const gchar *type, const gchar *format, const gchar *data, GError **error); +SmlCred* smlCredNewAuth (SmlAuthType type, const gchar *username, const gchar *password, GError **error); +SmlCred* smlCredNew (SmlAuthType type, SmlFormatType format, const gchar *data, const gchar *username, GError **error); +void smlCredRef (SmlCred *cred); +void smlCredUnref (SmlCred *cred); + +SmlAnchor* smlAnchorNew (const gchar *last, const gchar *next, GError **error); +void smlAnchorFree (SmlAnchor *anchor); + +SmlItem* smlItemNew (gsize size, GError **error); +SmlItem* smlItemNewForData (const gchar *data, gsize size, GError **error); +SmlItem* smlItemRef (SmlItem *item); +void smlItemUnref (SmlItem *item); +gboolean smlItemAddData (SmlItem *item, const gchar *data, gsize size, GError **error); +gboolean smlItemCheck (SmlItem *item); +gboolean smlItemHasData (SmlItem *item); +gboolean smlItemGetData (SmlItem *item, gchar **data, gsize *size, GError **error); +gboolean smlItemStealData (SmlItem *item, gchar **data, gsize *size, GError **error); + +void smlItemSetSource (SmlItem *item, SmlLocation *source); +SmlLocation* smlItemGetSource (SmlItem *item); +void smlItemSetTarget (SmlItem *item, SmlLocation *target); +SmlLocation* smlItemGetTarget (SmlItem *item); +void smlItemSetRaw (SmlItem *item, gboolean raw); void smlHeaderFree(SmlHeader *header); -SmlChal *smlChalNew(SmlAuthType type, GError **error); -SmlChal *smlChalNewFromBinary(SmlAuthType type, const char *nonce, size_t length, GError **error); -SmlChal *smlChalNewFromBase64(SmlAuthType type, const char *nonce, GError **error); -void smlChalRef(SmlChal *chal); -void smlChalUnref(SmlChal *chal); - -SmlMapItem *smlMapItemNew(const char *uid, const char *newuid, GError **error); -SmlMapItem *smlMapItemRef(SmlMapItem *item); -void smlMapItemUnref(SmlMapItem *item); +SmlChal* smlChalNew (SmlAuthType type, GError **error); +SmlChal* smlChalNewFromBinary (SmlAuthType type, const gchar *nonce, gsize length, GError **error); +SmlChal* smlChalNewFromBase64 (SmlAuthType type, const gchar *nonce, GError **error); +void smlChalRef (SmlChal *chal); +void smlChalUnref (SmlChal *chal); + +SmlMapItem* smlMapItemNew (const gchar *uid, const gchar *newuid, GError **error); +SmlMapItem* smlMapItemRef (SmlMapItem *item); +void smlMapItemUnref (SmlMapItem *item); #endif //_SML_ELEMENTS_H_ Modified: trunk/libsyncml/sml_elements_internals.h ============================================================================== --- trunk/libsyncml/sml_elements_internals.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_elements_internals.h Thu Jul 2 16:06:31 2009 (r1143) @@ -33,8 +33,8 @@ #include <libxml/xmlreader.h> struct SmlAnchor { - char *next; - char *last; + gchar *next; + gchar *last; }; struct SmlItem { @@ -46,9 +46,9 @@ xmlBuffer *buffer; - unsigned int size; + gsize size; - char *contenttype; + gchar *contenttype; SmlBool moreData; SmlBool disabled; @@ -63,34 +63,34 @@ }; struct SmlHeader { - char *sessionID; + gchar *sessionID; SmlProtocolVersion version; SmlProtocolType protocol; SmlLocation *source; SmlLocation *target; - char *responseURI; + gchar *responseURI; SmlBool noResponse; - unsigned int messageID; - unsigned int maxmsgsize; - unsigned int maxobjsize; - char *emi; + guint messageID; + guint maxmsgsize; + guint maxobjsize; + gchar *emi; }; struct SmlCred { SmlFormatType format; SmlAuthType type; - char *data; + gchar *data; gint refCount; - char *username; - char *password; + gchar *username; + gchar *password; }; struct SmlChal { SmlFormatType format; SmlAuthType type; - char *nonce_plain; - unsigned int nonce_length; - char *nonce_b64; + gchar *nonce_plain; + guint nonce_length; + gchar *nonce_b64; gint refCount; }; Modified: trunk/libsyncml/sml_error.h ============================================================================== --- trunk/libsyncml/sml_error.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_error.h Thu Jul 2 16:06:31 2009 (r1143) @@ -113,15 +113,4 @@ } SmlErrorType; -SmlError **smlErrorRef(SmlError **error); -void smlErrorDeref(SmlError **error); -SmlBool smlErrorIsSet(SmlError **error); -void smlErrorSet(SmlError **error, SmlErrorType type, const char *format, ...); -void smlErrorUpdate(SmlError **error, const char *format, ...); -void smlErrorDuplicate(SmlError **target, SmlError **source); -const char *smlErrorPrint(SmlError **error); -SmlErrorType smlErrorGetType(SmlError **error); -void smlErrorSetType(SmlError **error, SmlErrorType type); -SmlErrorClass smlErrorGetClass(SmlError **error); - #endif //_SML_ERROR_H_ Modified: trunk/libsyncml/sml_error_internals.h ============================================================================== --- trunk/libsyncml/sml_error_internals.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_error_internals.h Thu Jul 2 16:06:31 2009 (r1143) @@ -24,24 +24,9 @@ #include "syncml_internals.h" -/*! @brief Represent an error - */ -struct SmlError { - /** The type of the error that occured */ - SmlErrorType type; - /** The message */ - char *message; - /** The printed message */ - char *printMessage; - /** The reference counter */ - gint32 refCount; -}; - -void smlErrorSetVargs(SmlError **error, SmlErrorType type, const char *format, va_list args); - #define CHECK_ERROR_REF \ - smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); \ - smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); + smlAssertMsg(error, "The error handling of the function must be used."); \ + smlAssertMsg(*error == NULL, "The error parameter is already filled (ignored error)."); #define SML_ERROR g_quark_from_static_string("Sml") @@ -53,20 +38,6 @@ *d_error = NULL; \ } -#define GERROR_TO_SML_ERROR(gerror, error) \ - if (gerror) { \ - smlErrorSet(error, gerror->code, "%s", gerror->message); \ - g_error_free(gerror); \ - gerror = NULL; \ - } - -/* Error messages for assertions */ -#define SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL "The error handling of the function must be used." -#define SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY "The error parameter is already filled (ignored error)." -#define SML_ASSERT_MSG_ERROR_MUST_BE_AVAILABLE "If this function is used then there must be an error." -#define SML_ASSERT_MSG_ERROR_MUST_BE_FILLED "If this function is used then the error message must be present." -#define SML_ASSERT_MSG_SAN_PARSE_REQUIRES_MANAGER "If an OMA DS 1.2 SAN must be parsed then the manager must be present." - #endif //_SML_ERROR_INTERNALS_H_ /*@}*/ Modified: trunk/libsyncml/sml_parse.c ============================================================================== --- trunk/libsyncml/sml_parse.c Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_parse.c Thu Jul 2 16:06:31 2009 (r1143) @@ -140,7 +140,7 @@ smlAssert(size); smlAssert(parser->functions.start); smlAssertMsg(parser->type != SML_MIMETYPE_SAN || parser->manager, - SML_ASSERT_MSG_SAN_PARSE_REQUIRES_MANAGER); + "If an OMA DS 1.2 SAN must be parsed then the manager must be present."); if (parser->limit && size > parser->limit) { smlErrorSet(error, SML_ERROR_GENERIC, "Input data too large"); Modified: trunk/libsyncml/sml_support.h ============================================================================== --- trunk/libsyncml/sml_support.h Thu Jul 2 10:11:46 2009 (r1142) +++ trunk/libsyncml/sml_support.h Thu Jul 2 16:06:31 2009 (r1143) @@ -42,12 +42,12 @@ */ #define VA_STRING(param) param?param:"NULL" -void smlLog(const char *logname, const char *data, unsigned int size); -void smlTrace(SmlTraceType type, const char *message, ...); -char *smlPrintBinary(const char *data, int len); -char *smlPrintHex(const char *data, int len); -char *smlRandStr(int maxlength, SmlBool exact); -void *smlTryMalloc0(long n_bytes, GError **error); +void smlLog (const gchar *logname, const gchar *data, gsize size); +void smlTrace (SmlTraceType type, const gchar *message, ...); +gchar* smlPrintBinary (const gchar *data, gsize len); +gchar* smlPrintHex (const gchar *data, gsize len); +gchar* smlRandStr (gsize maxlength, gboolean exact); +void* smlTryMalloc0 (gsize n_bytes, GError **error); typedef struct SmlThread { GThread *thread; @@ -58,22 +58,22 @@ GMainLoop *loop; } SmlThread; -SmlThread *smlThreadNew(GMainContext *context, SmlError **error); -void smlThreadFree(SmlThread *thread); -void smlThreadStart(SmlThread *thread); -void smlThreadStop(SmlThread *thread); +SmlThread* smlThreadNew (GMainContext *context, GError **error); +void smlThreadFree (SmlThread *thread); +void smlThreadStart (SmlThread *thread); +void smlThreadStop (SmlThread *thread); typedef SmlBool (* SmlThreadCallFunctionType) ( gpointer data, - SmlError **error); + GError **error); SmlBool smlThreadCallFunction( SmlThread *thread, SmlThreadCallFunctionType func, gpointer data, - SmlError **error); + GError **error); -void smlSafeFree(gpointer *address); -void smlSafeCFree(char **address); +void smlSafeFree (gpointer *address); +void smlSafeCFree (char **address); #endif //_SML_SUPPORT_H_ |