From: <svn...@op...> - 2009-07-17 12:37:14
|
Author: bellmich Date: Fri Jul 17 14:37:06 2009 New Revision: 1213 URL: http://libsyncml.opensync.org/changeset/1213 Log: cleaned up header file usage in sml_session.c Modified: trunk/libsyncml/objects/sml_auth.h trunk/libsyncml/objects/sml_auth_internals.h trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_session.c Modified: trunk/libsyncml/objects/sml_auth.h ============================================================================== --- trunk/libsyncml/objects/sml_auth.h Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/objects/sml_auth.h Fri Jul 17 14:37:06 2009 (r1213) @@ -52,5 +52,7 @@ /* set required authentication type if this is a server */ void smlAuthSetType(SmlAuthenticator *auth, SmlAuthType code); +gchar *smlAuthGetCredString (SmlAuthType type, const gchar *username, const gchar *password, const gchar *b64_nonce, GError **error); + #endif //_SML_AUTH_H_ /*@}*/ Modified: trunk/libsyncml/objects/sml_auth_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_auth_internals.h Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/objects/sml_auth_internals.h Fri Jul 17 14:37:06 2009 (r1213) @@ -40,12 +40,5 @@ SmlAuthType type; }; -gchar *smlAuthGetCredString( - SmlAuthType type, - const gchar *username, - const gchar *password, - const gchar *b64_nonce, - GError **error); - #endif //_SML_AUTH_INTERNALS_H_ /*@}*/ Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/sml_command.c Fri Jul 17 14:37:06 2009 (r1213) @@ -204,6 +204,42 @@ return status->type == SML_COMMAND_TYPE_RESULTS ? TRUE : FALSE; } +SmlCommandType +smlStatusGetType (SmlStatus *status) +{ + return status->type; +} + +SmlAnchor* +smlStatusGetAnchor (SmlStatus *status) +{ + return status->anchor; +} + +SmlChal* +smlStatusGetChal (SmlStatus *status) +{ + return status->chal; +} + +gsize +smlStatusGetCommandRef (SmlStatus *status) +{ + return status->cmdRef; +} + +gsize +smlStatusGetMessageRef (SmlStatus *status) +{ + return status->msgRef; +} + +const gchar* +smlStatusGetData (SmlStatus *status) +{ + return status->data; +} + SmlCommand* smlCommandNew (SmlCommandType type, GError **error) @@ -938,6 +974,72 @@ cmd->cmdID = id; } +gsize +smlCommandGetMessageID (SmlCommand *cmd) +{ + return cmd->msgID; +} + +void +smlCommandSetMessageID (SmlCommand *cmd, + gsize id) +{ + cmd->msgID = id; +} + +gsize +smlCommandGetMaxObjSize (SmlCommand *cmd) +{ + switch (cmd->type) + { + case SML_COMMAND_TYPE_ALERT: + return cmd->private.alert.maxObjSize; + case SML_COMMAND_TYPE_SYNC: + return cmd->private.sync.maxObjSize; + default: + return 0; + } +} + +SmlAlertType +smlCommandGetAlertType (SmlCommand *cmd) +{ + return cmd->private.alert.type; +} + +gsize +smlCommandGetSize (SmlCommand *cmd) +{ + return cmd->size; +} + +void +smlCommandSetSize (SmlCommand *cmd, + gsize size) +{ + cmd->size = size; +} + +void +smlCommandSetNoResp (SmlCommand *cmd, + gboolean noResp) +{ + cmd->noResp = noResp; +} + +gboolean +smlCommandGetPushedBack (SmlCommand *cmd) +{ + return cmd->pushedBack; +} + +void +smlCommandSetPushedBack (SmlCommand *cmd, + gboolean pushedBack) +{ + cmd->pushedBack = pushedBack; +} + SmlCommandType smlCommandGetType (SmlCommand *cmd) { @@ -993,3 +1095,129 @@ } } } + +gsize +smlCommandGetNumChanges (SmlCommand *cmd) +{ + smlAssert(cmd); + + return g_list_length(cmd->private.change.items); +} + +gsize +smlCommandGetNthItemSize (SmlCommand *orig_cmd, + gsize n, + GError **error) +{ + smlAssert(orig_cmd); + + char *data = NULL; + gsize size = 0; + + SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, n); + if (!smlItemGetData(orig_item, &data, &size, error)) + goto error; + return size; +error: + return 0; +} + +SmlCommand* +smlCommandGetFragment (SmlCommand *orig_cmd, + gsize start, + gsize space, + gsize complete_size, + GError **error) +{ + smlAssert(orig_cmd); + + gchar *data = NULL; + gsize size = 0; + SmlItem *frag_item = NULL; + SmlCommand *frag_cmd = NULL; + + SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); + if (!smlItemGetData(orig_item, &data, &size, error)) + goto error; + + /* create item fragment */ + + frag_item = smlItemGetFragment(orig_item, start, space, error); + if (!frag_item) + goto error; + + /* create command fragment */ + + frag_cmd = smlCommandNew(orig_cmd->type, error); + if (!frag_cmd) + goto error; + + frag_cmd->private.change.items = g_list_append (NULL, frag_item); + if (!frag_cmd->private.change.items) + { + goto error; + } + frag_item = NULL; + + /* If this is the first sent part of the fragmented command + * then this command must include the size of the complete + * command. + */ + if (start == 0) + frag_cmd->size = complete_size; + + return frag_cmd; +error: + if (frag_cmd) + smlCommandUnref(frag_cmd); + if (frag_item) + smlItemUnref(frag_item); + return NULL; +} + +SmlStatus* +smlCommandResultsGetStatus (SmlCommand *cmd) +{ + smlAssert(cmd); + return cmd->private.results.status; +} + +void +smlCommandTransferItems (SmlCommand *source, + SmlCommand *target, + gsize start) +{ + smlAssert(source); + smlAssert(target); + + while(1) { + SmlItem *item = g_list_nth_data(source->private.change.items, start); + if (!item) + return; + target->private.change.items = g_list_append(target->private.change.items, item); + source->private.change.items = g_list_remove(source->private.change.items, item); + } +} + +SmlItem* +smlCommandGetFirstChange (SmlCommand *cmd) +{ + smlAssert(cmd); + return g_list_nth_data(cmd->private.change.items, 0); +} + +SmlItem* +smlCommandGetLastChange (SmlCommand *cmd) +{ + smlAssert(cmd); + return g_list_nth_data(cmd->private.change.items, g_list_length(cmd->private.change.items) - 1); +} + +void +smlCommandFreeFirstChange (SmlCommand *cmd) +{ + smlAssert(cmd); + SmlItem *first = smlCommandGetFirstChange(cmd); + cmd->private.change.items = g_list_remove(cmd->private.change.items, first); + smlItemUnref(first); +} Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/sml_command.h Fri Jul 17 14:37:06 2009 (r1213) @@ -37,13 +37,19 @@ typedef struct SmlCommand SmlCommand; typedef struct SmlStatus SmlStatus; -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); +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); +SmlCommandType smlStatusGetType (SmlStatus *status); +SmlAnchor* smlStatusGetAnchor (SmlStatus *status); +SmlChal* smlStatusGetChal (SmlStatus *status); +gsize smlStatusGetCommandRef (SmlStatus *status); +gsize smlStatusGetMessageRef (SmlStatus *status); +const gchar* smlStatusGetData (SmlStatus *status); SmlCommand* smlCommandNew (SmlCommandType type, GError **error); SmlStatus* smlCommandNewReply (const SmlCommand *cmd, SmlErrorType code, GError **error); @@ -65,8 +71,17 @@ SmlCommand* smlCommandNewMap (SmlLocation *target, SmlLocation *source, GError **error); gboolean smlCommandAddMapItem (SmlCommand *map, SmlMapItem *item, GError **error); -void smlCommandSetID (SmlCommand *cmd, gsize id); -gsize smlCommandGetID (SmlCommand *cmd); +void smlCommandSetID (SmlCommand *cmd, gsize id); +gsize smlCommandGetID (SmlCommand *cmd); +void smlCommandSetMessageID (SmlCommand *cmd, gsize id); +gsize smlCommandGetMessageID (SmlCommand *cmd); +gsize smlCommandGetMaxObjSize (SmlCommand *cmd); +SmlAlertType smlCommandGetAlertType (SmlCommand *cmd); +gsize smlCommandGetSize (SmlCommand *cmd); +void smlCommandSetSize (SmlCommand *cmd, gsize size); +void smlCommandSetNoResp (SmlCommand *cmd, gboolean noResp); +gboolean smlCommandGetPushedBack (SmlCommand *cmd); +void smlCommandSetPushedBack (SmlCommand *cmd, gboolean pushedBack); SmlCommandType smlCommandGetType (SmlCommand *cmd); SmlLocation* smlCommandGetSource (SmlCommand *cmd); @@ -77,6 +92,16 @@ void smlCommandDisableChanges (SmlCommand *cmd); void smlCommandEnableChanges (SmlCommand *cmd); +gsize smlCommandGetNumChanges (SmlCommand *cmd); + +SmlStatus* smlCommandResultsGetStatus (SmlCommand *cmd); +void smlCommandTransferItems (SmlCommand *source, SmlCommand *target, gsize start); +SmlItem* smlCommandGetLastChange (SmlCommand *cmd); +SmlItem* smlCommandGetFirstChange (SmlCommand *cmd); +void smlCommandFreeFirstChange (SmlCommand *cmd); + +gsize smlCommandGetNthItemSize (SmlCommand *orig_cmd, gsize n, GError **error); +SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, gsize complete_size, GError **error); #endif //_SML_COMMAND_H_ Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/sml_elements.c Fri Jul 17 14:37:06 2009 (r1213) @@ -114,6 +114,18 @@ return header->target; } +gsize +smlHeaderGetMaxMsgSize (SmlHeader *header) +{ + return header->maxmsgsize; +} + +const gchar* +smlHeaderGetResponseURI (SmlHeader *header) +{ + return header->responseURI; +} + void smlHeaderFree (SmlHeader *header) { @@ -343,6 +355,20 @@ return FALSE; } +gsize +smlItemGetSize (SmlItem *item) +{ + smlAssert(item); + return xmlBufferLength(item->buffer); +} + +const gchar* +smlItemGetContent (SmlItem *item) +{ + smlAssert(item); + return (gchar *)xmlBufferContent(item->buffer); +} + void smlItemSetDisable (SmlItem *item, gboolean disable) @@ -426,6 +452,43 @@ return item->contenttype; } +SmlItem * +smlItemGetFragment (SmlItem *orig_item, + gsize start, + gsize space, + GError **error) +{ + smlAssert(orig_item); + + const char *data = (char *)xmlBufferContent(orig_item->buffer); + gsize size = xmlBufferLength(orig_item->buffer); + + SmlItem *frag_item = smlItemNewForData(data + start, space, error); + if (!frag_item) + goto error; + + if (start + space < size) + frag_item->moreData = TRUE; + else + frag_item->moreData = FALSE; + + frag_item->target = orig_item->target; + if (frag_item->target) + g_object_ref(frag_item->target); + + frag_item->source = orig_item->source; + if (frag_item->source) + g_object_ref(frag_item->source); + + frag_item->contenttype = g_strdup(orig_item->contenttype); + + return frag_item; +error: + if (frag_item) + smlItemUnref(frag_item); + return NULL; +} + SmlCred* smlCredNewFromString (const gchar *type, const gchar *format, @@ -579,15 +642,39 @@ const gchar* smlCredGetUsername (SmlCred *cred) { + smlAssert(cred); return cred->username; } const gchar* smlCredGetPassword (SmlCred *cred) { + smlAssert(cred); return cred->password; } +const gchar* +smlCredGetData (SmlCred *cred) +{ + smlAssert(cred); + return cred->data; +} + +void +smlCredSetData (SmlCred *cred, + gchar *data) +{ + smlAssert(cred); + cred->data = data; +} + +SmlAuthType +smlCredGetType (SmlCred *cred) +{ + smlAssert(cred); + return cred->type; +} + SmlChal* smlChalNew (SmlAuthType type, GError **error) @@ -749,6 +836,21 @@ smlTrace(TRACE_EXIT, "%s", __func__); } +/* Base 64 only */ +const gchar* +smlChalGetNonce (SmlChal *chal) +{ + smlAssert(chal); + return chal->nonce_b64; +} + +SmlAuthType +smlChalGetType (SmlChal *chal) +{ + smlAssert(chal); + return chal->type; +} + SmlMapItem* smlMapItemNew (const gchar *uid, const gchar *newuid, Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/sml_elements.h Fri Jul 17 14:37:06 2009 (r1213) @@ -41,29 +41,34 @@ typedef struct SmlChal SmlChal; typedef struct SmlMapItem SmlMapItem; -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); -const gchar* smlCredGetUsername (SmlCred *cred); -const gchar* smlCredGetPassword (SmlCred *cred); +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); +const gchar* smlCredGetUsername (SmlCred *cred); +const gchar* smlCredGetPassword (SmlCred *cred); +const gchar* smlCredGetData (SmlCred *cred); +void smlCredSetData (SmlCred *cred, gchar *data); +SmlAuthType smlCredGetType (SmlCred *cred); SmlAnchor* smlAnchorNew (const gchar *last, const gchar *next, GError **error); const char* smlAnchorGetLast (SmlAnchor *anchor); const char* smlAnchorGetNext (SmlAnchor *anchor); 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 smlItemSetDisable (SmlItem *item, gboolean disable); +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); +gsize smlItemGetSize (SmlItem *item); +const char* smlItemGetContent (SmlItem *item); +gboolean smlItemStealData (SmlItem *item, gchar **data, gsize *size, GError **error); +void smlItemSetDisable (SmlItem *item, gboolean disable); void smlItemSetMoreData (SmlItem *item, gboolean enable); gboolean smlItemGetMoreData (SmlItem *item); @@ -76,19 +81,25 @@ SmlLocation* smlItemGetTarget (SmlItem *item); void smlItemSetRaw (SmlItem *item, gboolean raw); +SmlItem * smlItemGetFragment (SmlItem *orig_item, gsize start, gsize space, GError **error); + gsize smlHeaderGetSessionID (SmlHeader *header); gsize smlHeaderGetMessageID (SmlHeader *header); SmlProtocolVersion smlHeaderGetProtocolVersion (SmlHeader *header); SmlProtocolType smlHeaderGetProtocolType (SmlHeader *header); SmlLocation* smlHeaderGetSource (SmlHeader *header); SmlLocation* smlHeaderGetTarget (SmlHeader *header); +gsize smlHeaderGetMaxMsgSize (SmlHeader *header); +const gchar* smlHeaderGetResponseURI (SmlHeader *header); void smlHeaderFree (SmlHeader *header); -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); +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); +const gchar* smlChalGetNonce (SmlChal *chal); /* Base 64 only */ +SmlAuthType smlChalGetType (SmlChal *chal); SmlMapItem* smlMapItemNew (const gchar *uid, const gchar *newuid, GError **error); SmlMapItem* smlMapItemRef (SmlMapItem *item); Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Thu Jul 16 13:46:35 2009 (r1212) +++ trunk/libsyncml/sml_session.c Fri Jul 17 14:37:06 2009 (r1213) @@ -19,15 +19,18 @@ * */ +#include "sml_session_internals.h" + #include "sml_support.h" #include "sml_error_internals.h" + #include "sml_queue_internals.h" -#include "sml_session_internals.h" -#include "sml_command_internals.h" -#include "sml_elements_internals.h" -#include "sml_parse_internals.h" +#include "sml_command.h" +#include "sml_elements.h" +#include "sml_parse.h" #include "sml_transport.h" -#include "objects/sml_auth_internals.h" +#include "objects/sml_auth.h" + #include "data_sync_api/sml_location_internals.h" /** @@ -199,7 +202,7 @@ smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, status, userdata); //SmlError *error = NULL; - smlTrace(TRACE_INTERNAL, "%s: Got a status reply %i", __func__, status->type); + smlTrace(TRACE_INTERNAL, "%s: Got a status reply %i", __func__, smlStatusGetType(status)); if (smlStatusGetCode(status) != SML_CHUNK_ACCEPTED) { /* We need to send a error reply for the original command */ @@ -229,17 +232,15 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, complete_size, error); CHECK_ERROR_REF - /* This library must not send more that one item per change + /* This library must not send more than one item per change * command. This is compliant with all specification and only a * self limitation. */ - smlAssert(g_list_length(orig_cmd->private.change.items) == 1); + smlAssert(smlCommandGetNumChanges(orig_cmd) == 1); SmlCommand *frag_cmd = NULL; - char *data = NULL; - gsize size = 0; - SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); - if (!smlItemGetData(orig_item, &data, &size, error)) + gsize size = smlCommandGetNthItemSize(orig_cmd, 0, error); + if (!size) goto error; // FIXME: should we add an assertion here to guarantee @@ -248,39 +249,10 @@ if (space < size - start) { /* We need to create a new command. But we only send as much data as space * is available */ - frag_cmd = smlCommandNew(orig_cmd->type, error); + frag_cmd = smlCommandGetFragment(orig_cmd, start, space, complete_size, error); if (!frag_cmd) goto error; - SmlItem *frag_item = smlItemNewForData(data + start, space, error); - if (!frag_item) - goto error; - frag_cmd->private.change.items = g_list_append (NULL, frag_item); - if (!frag_cmd->private.change.items) - { - smlItemUnref(frag_item); - goto error; - } - - frag_item->moreData = TRUE; - - frag_item->target = orig_item->target; - if (frag_item->target) - g_object_ref(frag_item->target); - - frag_item->source = orig_item->source; - if (frag_item->source) - g_object_ref(frag_item->source); - - frag_item->contenttype = g_strdup(orig_item->contenttype); - - /* If this is the first sent part of the fragmented command - * then this command must include the size of the complete - * command. - */ - if (start == 0) - frag_cmd->size = complete_size; - session->frag_size += space; } else { /* We have enough room to send the original command. @@ -289,43 +261,15 @@ * The original item must be freed. */ - /* get original item and cleanup item list */ - smlAssert(g_list_length(orig_cmd->private.change.items) == 1); - smlAssert(g_list_remove(orig_cmd->private.change.items, orig_item) == NULL); - orig_cmd->private.change.items = NULL; - - /* setup new item */ - SmlItem *frag_item = smlItemNewForData(data + start, size - start, error); - if (!frag_item) { - smlItemUnref(orig_item); - goto error; - } - orig_cmd->private.change.items = g_list_append(NULL, frag_item); - if (!orig_cmd->private.change.items) - { - smlItemUnref(orig_item); - smlItemUnref(frag_item); + /* create fragmentation command */ + frag_cmd = smlCommandGetFragment(orig_cmd, start, size - start, complete_size, error); + if (!frag_cmd) goto error; - } - /* configure new item */ - frag_item->contenttype = g_strdup(orig_item->contenttype); - frag_item->target = orig_item->target; - if (frag_item->target) - g_object_ref(frag_item->target); - frag_item->source = orig_item->source; - if (frag_item->source) - g_object_ref(frag_item->source); - - /* cleanup original item */ - smlItemUnref(orig_item); - /* setup fragmentation command */ - frag_cmd = orig_cmd; session->frag_size += size - start; } - smlTrace(TRACE_EXIT, "%s: %p", __func__, frag_cmd); return frag_cmd; error: @@ -368,7 +312,13 @@ /* Large object handling. Only possible of the session has a limit and * we dont have a 1.0 session */ - if ((cmd->type == SML_COMMAND_TYPE_ADD || cmd->type == SML_COMMAND_TYPE_REPLACE) && + smlTrace(TRACE_INTERNAL, "%s: type: %d, MaxMsgSize: %llu, version: %d", + __func__, + smlCommandGetType(cmd), + smlAssemblerGetRemoteMaxMsgSize(session->assembler), + session->version); + if ((smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || + smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE) && smlAssemblerGetRemoteMaxMsgSize(session->assembler) > 0 && session->version != SML_VERSION_10) { smlTrace(TRACE_INTERNAL, "%s: Checking if command needs to be fragmented", __func__); @@ -376,19 +326,19 @@ * command. This is compliant with all specification and only a * self limitation. */ - smlAssert(g_list_length(cmd->private.change.items) == 1); + //smlAssert(g_list_length(cmd->private.change.items) == 1); char *data = NULL; gsize size = 0; - SmlItem *item = g_list_nth_data(cmd->private.change.items, 0); + SmlItem *item = smlCommandGetFirstChange(cmd); if (!smlItemGetData(item, &data, &size, error)) goto error; /* If max obj size is not unlimited (0), and the size of the item is larger * than the max obj size, we have to return an error */ - int sendingmaxobjsize = smlSessionGetRemoteMaxObjSize(session); + gsize sendingmaxobjsize = smlSessionGetRemoteMaxObjSize(session); if ((sendingmaxobjsize > 0) && - (size > (unsigned int)sendingmaxobjsize)) + (size > sendingmaxobjsize)) { g_set_error(error, SML_ERROR, SML_ERROR_SIZE_MISMATCH, "Item (%ub) is larger than the limit (%db)", size, smlSessionGetRemoteMaxObjSize(session)); @@ -396,13 +346,13 @@ } if (!session->frag_command) - cmd->size = size; - item->moreData = TRUE; + smlCommandSetSize(cmd, size); + smlItemSetMoreData(item, TRUE); gssize space = 0; if (!smlAssemblerGetSpace(session->assembler, &space, parent, cmd, error)) goto error; - cmd->size = 0; - item->moreData = FALSE; + smlCommandSetSize(cmd, 0); + smlItemSetMoreData(item, FALSE); /* Check if item data fits into the current message */ if (session->frag_command || @@ -434,8 +384,8 @@ * happen that the item is replaced. Therefore the item * reference must be determined again. */ - item = g_list_nth_data(cmd->private.change.items, 0); - if (item->moreData == FALSE) { + item = smlCommandGetFirstChange(cmd); + if (smlItemGetMoreData(item) == FALSE) { smlTrace(TRACE_INTERNAL, "%s: This is the last chunk", __func__); callback = session->frag_callback; @@ -454,21 +404,21 @@ /* We now increment the session ID */ session->lastCommandID++; - cmd->cmdID = session->lastCommandID; + smlCommandSetID(cmd, session->lastCommandID); smlTrace(TRACE_INTERNAL, "%s: last command id is %i", __func__, session->lastCommandID); /* Now we can try to add the command to the assembler */ switch (smlAssemblerStartCommand(session->assembler, parent, cmd, error)) { case SML_ASSEMBLER_RESULT_OK: /* We successfully added the command */ - cmd->pushedBack = FALSE; + smlCommandSetPushedBack(cmd, FALSE); break; case SML_ASSEMBLER_RESULT_MISMATCH: - if (cmd->pushedBack) { + if (smlCommandGetPushedBack(cmd)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Command is too large"); goto error; } - cmd->pushedBack = TRUE; + smlCommandSetPushedBack(cmd, TRUE); /* We werent able to add the command. So we have to flush the already * added statuses/commands and then add it again later */ @@ -496,17 +446,17 @@ pending->callback = callback; pending->userdata = userdata; - pending->cmdID = cmd->cmdID; + pending->cmdID = smlCommandGetID(cmd); pending->msgID = session->lastMessageID; smlTrace(TRACE_INTERNAL, "%s: Appending pending status with cmdID %i and msgID %i", __func__, pending->cmdID, pending->msgID); session->pendingReplies = g_list_append(session->pendingReplies, pending); } else - cmd->noResp = TRUE; + smlCommandSetNoResp(cmd, TRUE); /* We will get a status and a result to a get command * so we register a second callback for the result */ - if (cmd->type == SML_COMMAND_TYPE_GET) { + if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_GET) { pending = smlTryMalloc0(sizeof(SmlPendingStatus), error); if (!pending) { session->lastCommandID--; @@ -515,7 +465,7 @@ pending->callback = callback; pending->userdata = userdata; - pending->cmdID = cmd->cmdID; + pending->cmdID = smlCommandGetID(cmd); pending->msgID = session->lastMessageID; smlTrace(TRACE_INTERNAL, "%s: Appending pending status for a result with cmdID %i and msgID %i", __func__, pending->cmdID, pending->msgID); @@ -640,12 +590,15 @@ goto error; } - if (status->cmdRef != cmdRef || status->msgRef != msgRef) { + if (smlStatusGetCommandRef(status) != cmdRef || + smlStatusGetMessageRef(status) != msgRef) { //Put it on the end of the queue smlQueueSendPrio(session->command_queue, message); smlTrace(TRACE_EXIT, "%s - next needed command status %d for message %d is not this one (cmd %d, msg %d)", - __func__, cmdRef, msgRef, status->cmdRef, status->msgRef); + __func__, cmdRef, msgRef, + smlStatusGetCommandRef(status), + smlStatusGetMessageRef(status)); return; } @@ -703,40 +656,41 @@ CHECK_ERROR_REF /* check and set the counters */ - if (header->messageID <= session->lastReceivedMessageID) { + if (smlHeaderGetMessageID(header) <= session->lastReceivedMessageID) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Message ID not incremented"); goto error; } - session->lastReceivedMessageID = header->messageID; + session->lastReceivedMessageID = smlHeaderGetMessageID(header); session->lastCommandID++; /* check and set the MaxMsgSize */ - if (0 < header->maxmsgsize) { + if (0 < smlHeaderGetMaxMsgSize(header)) { /* If MaxMsgSize is 0 then it is not set. Therefore * a MaxMsgSize of 0 is ignored to not override an * already configured MaxMsgSize from an earlier * message. */ - smlAssemblerSetRemoteMaxMsgSize(session->assembler, header->maxmsgsize); + smlAssemblerSetRemoteMaxMsgSize(session->assembler, smlHeaderGetMaxMsgSize(header)); } - if (0 < header->maxmsgsize && header->maxmsgsize < session->localMaxMsgSize) + if (0 < smlHeaderGetMaxMsgSize(header) && + smlHeaderGetMaxMsgSize(header) < session->localMaxMsgSize) { /* The localMaxMsgSize is only set if it is already * configured. If there is no local limit then it is not * necessary to configure it only because the remote * peer has a limit. */ - smlSessionSetLocalMaxMsgSize(session, header->maxmsgsize); + smlSessionSetLocalMaxMsgSize(session, smlHeaderGetMaxMsgSize(header)); } /* Reserve the status for header reply. It will always be cmdRef 0 * and it will always be the first command in the message */ - if (!smlAssemblerReserveStatus(session->assembler, 0, header->messageID, 1, error)) + if (!smlAssemblerReserveStatus(session->assembler, 0, smlHeaderGetMessageID(header), 1, error)) goto error; /* If RespURI is send in the header * then the URI in the transport layer must be adjusted. */ - if (header->responseURI) { + if (smlHeaderGetResponseURI(header)) { if (!session->orgTarget) { /* If the original target is already set * then it MUST NOT be set again @@ -759,7 +713,7 @@ /* build the new target and publish it*/ session->target = sml_location_new_with_options( - header->responseURI, + smlHeaderGetResponseURI(header), sml_location_get_name(session->orgTarget), error); if (!session->target) @@ -777,7 +731,7 @@ * then we have to change the TargetRef/LocURI * of the session. */ - const char *header_source = sml_location_get_uri(header->source); + const char *header_source = sml_location_get_uri(smlHeaderGetSource(header)); const char *session_target = sml_location_get_uri(session->target); if (header_source && session_target && @@ -807,10 +761,10 @@ smlAssert(status); CHECK_ERROR_REF - if (status->cmdRef == 0) { - smlAssert(status->type == SML_COMMAND_TYPE_HEADER); - smlAssert(status->data); - SmlErrorType errorCode = atoi(status->data); + if (smlStatusGetCommandRef(status) == 0) { + smlAssert(smlStatusGetType(status) == SML_COMMAND_TYPE_HEADER); + smlAssert(smlStatusGetData(status)); + SmlErrorType errorCode = atoi(smlStatusGetData(status)); if (session->sessionType == SML_SESSION_TYPE_SERVER) { /* If this is an OMA DS server then the session @@ -859,10 +813,10 @@ session->established = FALSE; smlAssemblerRestoreCommands(session->assembler); smlTrace(TRACE_INTERNAL, "%s - restored commands from previous message", __func__); - smlAssert(status->chal); + smlAssert(smlStatusGetChal(status)); smlAssert(session->cred); - if (session->cred->type == SML_AUTH_TYPE_MD5 && - status->chal->type != SML_AUTH_TYPE_MD5) + if (smlCredGetType(session->cred) == SML_AUTH_TYPE_MD5 && + smlChalGetType(smlStatusGetChal(status)) != SML_AUTH_TYPE_MD5) { g_set_error(error, SML_ERROR, SML_ERROR_AUTH_REJECTED, "The remote peer tries to enforce an authentication method which violates the local security policy (syncml:auth-md5 is required)."); @@ -871,13 +825,15 @@ smlTrace(TRACE_INTERNAL, "%s - authentication type conforms to security policy", __func__); /* build the authentication string */ - session->cred->data = smlAuthGetCredString( - status->chal->type, - session->cred->username, - session->cred->password, - status->chal->nonce_b64, + char *cred_data = smlAuthGetCredString( + smlChalGetType(smlStatusGetChal(status)), + smlCredGetUsername(session->cred), + smlCredGetPassword(session->cred), + smlChalGetNonce(smlStatusGetChal(status)), error); - if (!session->cred->data) + smlCredSetData(session->cred, cred_data); + cred_data = NULL; + if (!smlCredGetData(session->cred)) goto error; smlTrace(TRACE_INTERNAL, "%s - credential string set", __func__); } else { @@ -906,9 +862,11 @@ for (o = session->pendingReplies; o; o = o ? o->next : NULL ) { SmlPendingStatus *pending = o->data; smlTrace(TRACE_INTERNAL, "%s: check cmd %i of msg %i", __func__, pending->cmdID, pending->msgID); - if (pending->cmdID == status->cmdRef && pending->msgID == status->msgRef) { + if (pending->cmdID == smlStatusGetCommandRef(status) && + pending->msgID == smlStatusGetMessageRef(status)) { smlTrace(TRACE_INTERNAL, "%s - Found pending status %s of command %d in message %d", - __func__, VA_STRING(status->data), status->cmdRef, status->msgRef); + __func__, VA_STRING(smlStatusGetData(status)), + smlStatusGetCommandRef(status), smlStatusGetMessageRef(status)); if (session->authenticate) { /* modify the pending reply @@ -950,9 +908,9 @@ /* We have to catch at this point if the status reply is the reply * to our server alerted sync. Since this initial alert is not sent * over a session, the status can of course not be wanted */ - if (status->type == SML_COMMAND_TYPE_ALERT && !status->anchor) { + if (smlStatusGetType(status) == SML_COMMAND_TYPE_ALERT && !smlStatusGetAnchor(status)) { smlTrace(TRACE_INTERNAL, "%s: Handling status for server alerted sync", __func__); - SmlErrorType errorCode = atoi(status->data); + SmlErrorType errorCode = atoi(smlStatusGetData(status)); if ((199 < errorCode && errorCode < 300) || errorCode == 508) { @@ -970,7 +928,9 @@ g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Received unwanted status %s of command %d in message %d", - status->data, status->cmdRef, status->msgRef); + smlStatusGetData(status), + smlStatusGetCommandRef(status), + smlStatusGetMessageRef(status)); goto error; out: smlTrace(TRACE_EXIT, "%s", __func__); @@ -1145,7 +1105,7 @@ } if (cmd) - cmd->msgID = session->lastReceivedMessageID; + smlCommandSetMessageID(cmd, session->lastReceivedMessageID); /* If the handler of the header signals that an authentication * is still required then we must send status 407 to all @@ -1157,7 +1117,7 @@ session->lastCommandID++; /* Reserve the place for the status in the assembler */ - if (!smlAssemblerReserveStatus(session->assembler, cmd->cmdID, session->lastReceivedMessageID, session->lastCommandID, error)) + if (!smlAssemblerReserveStatus(session->assembler, smlCommandGetID(cmd), session->lastReceivedMessageID, session->lastCommandID, error)) goto error; /* send status 407 */ @@ -1177,7 +1137,7 @@ smlTrace(TRACE_INTERNAL, "%s: RESULT_OPEN", __func__); session->lastCommandID++; /* Reserve the place for the status in the assembler */ - if (!smlAssemblerReserveStatus(session->assembler, cmd->cmdID, session->lastReceivedMessageID, session->lastCommandID, error)) + if (!smlAssemblerReserveStatus(session->assembler, smlCommandGetID(cmd), session->lastReceivedMessageID, session->lastCommandID, error)) goto error; /* Store the parent */ @@ -1189,16 +1149,14 @@ /* If we are a server, we just mimick the behaviour of the client regarding * large object handling and support of number of changes. This way we dont * need to parse the devinf */ - if (cmd->type == SML_COMMAND_TYPE_SYNC) { - smlTrace(TRACE_INTERNAL, "%s: SYNC => maxObjSize: %i, numbOfChanges: %i, %i", + if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_SYNC) { + smlTrace(TRACE_INTERNAL, "%s: SYNC => maxObjSize: %i", __func__, - cmd->private.sync.maxObjSize, - cmd->private.sync.hasNumChanged, - cmd->private.sync.numChanged); - /* If the sync has the maxObjSize set (>= 0), we set the requested max obj size. + smlCommandGetMaxObjSize(cmd)); + /* If the sync has the maxObjSize set (> 0), we set the requested max obj size. * If the max obj size was set before (with the alert, we overwrite it */ - if (cmd->private.sync.maxObjSize >= 0) - smlSessionSetRemoteMaxObjSize(session, cmd->private.sync.maxObjSize); + if (smlCommandGetMaxObjSize(cmd) > 0) + smlSessionSetRemoteMaxObjSize(session, smlCommandGetMaxObjSize(cmd)); /* If the DevInf of the client includes SupportNumberOfChanges * but the client does not send NumberOfChanges * then the server still MUST send NumberOfChanges. @@ -1215,7 +1173,7 @@ } session->parentCommand = cmd; - cmd->msgID = session->lastReceivedMessageID; + smlCommandSetMessageID(cmd, session->lastReceivedMessageID); if (!session->end) { smlSessionDispatchEvent(session, SML_SESSION_EVENT_COMMAND_START, cmd, NULL, NULL, NULL); @@ -1236,13 +1194,13 @@ smlTrace(TRACE_INTERNAL, "%s: RESULT_NORMAL", __func__); session->lastCommandID++; /* Reserve the place for the status in the assembler */ - if (!smlAssemblerReserveStatus(session->assembler, cmd->cmdID, session->lastReceivedMessageID, session->lastCommandID, error)) + if (!smlAssemblerReserveStatus(session->assembler, smlCommandGetID(cmd), session->lastReceivedMessageID, session->lastCommandID, error)) goto error; /* Here we catch Alerts for the next message */ - if (cmd->type == SML_COMMAND_TYPE_ALERT) { + if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_ALERT) { smlTrace(TRACE_INTERNAL, "%s: ALERT with RESULT_NORMAL", __func__); - if (cmd->private.alert.type == SML_ALERT_NEXT_MESSAGE) { + if (smlCommandGetAlertType(cmd) == SML_ALERT_NEXT_MESSAGE) { SmlStatus *reply = smlCommandNewReply(cmd, SML_NO_ERROR, error); if (!reply) goto error; @@ -1256,17 +1214,16 @@ break; } else { smlTrace(TRACE_INTERNAL, "%s: Alert maxObjSize: %i", - __func__, cmd->private.alert.maxObjSize); - if (cmd->private.alert.maxObjSize >= 0) - smlAssemblerSetRemoteMaxObjSize(session->assembler, cmd->private.alert.maxObjSize); + __func__, smlCommandGetMaxObjSize(cmd)); + if (smlCommandGetMaxObjSize(cmd) >= 0) + smlAssemblerSetRemoteMaxObjSize(session->assembler, smlCommandGetMaxObjSize(cmd)); } } /* Here we catch changes with moreData set */ - if (cmd->type == SML_COMMAND_TYPE_ADD || cmd->type == SML_COMMAND_TYPE_REPLACE) { + if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE) { - SmlItem *lastItem = g_list_nth_data(cmd->private.change.items, - g_list_length(cmd->private.change.items) - 1); + SmlItem *lastItem = smlCommandGetLastChange(cmd); if (session->incomingBuffer) { /* There is a command in the incoming buffer. @@ -1283,7 +1240,7 @@ /* The size of an item must not be set in the * different chunks except the first one. */ - if (cmd->size) { + if (smlCommandGetSize(cmd)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Only the first chunk can have the size set"); goto error; @@ -1295,40 +1252,30 @@ */ char *data = NULL; gsize size = 0; - SmlItem *item = g_list_nth_data(cmd->private.change.items, 0); + SmlItem *item = smlCommandGetFirstChange(cmd); if (!item) goto error; if (!smlItemGetData(item, &data, &size, error)) goto error; - lastItem = g_list_nth_data(session->incomingBuffer->private.change.items, g_list_length(session->incomingBuffer->private.change.items) - 1); + lastItem = smlCommandGetLastChange(session->incomingBuffer); if (!smlItemAddData(lastItem, data, size, error)) goto error; - lastItem->moreData = item->moreData; - smlTrace(TRACE_INTERNAL, - "%s: Appended %i to buffer. Buffer size: %i. Required: %i", - __func__, size, - xmlBufferLength(lastItem->buffer), - lastItem->size); + smlItemSetMoreData(lastItem, smlItemGetMoreData(item)); + //smlTrace(TRACE_INTERNAL, + // "%s: Appended %i to buffer. Buffer size: %i. Required: %i", + // __func__, size, + // xmlBufferLength(lastItem->buffer), + // lastItem->size); /* move all other items from the new to the buffered command */ - guint i; - for (i=1; i < g_list_length(cmd->private.change.items); i++) - { - item = g_list_nth_data(cmd->private.change.items, i); - session->incomingBuffer->private.change.items = - g_list_append( - session->incomingBuffer->private.change.items, - item); - } - smlItemUnref(g_list_nth_data(cmd->private.change.items, 0)); - g_list_free(cmd->private.change.items); - cmd->private.change.items = NULL; + smlCommandTransferItems(cmd, session->incomingBuffer, 1); + smlCommandFreeFirstChange(cmd); /* If the last item of the command is complete * then the command must be prepared for dispatching. */ - lastItem = g_list_nth_data(session->incomingBuffer->private.change.items, g_list_length(session->incomingBuffer->private.change.items) - 1); - if (!lastItem->moreData) { + lastItem = smlCommandGetLastChange(session->incomingBuffer); + if (!smlItemGetMoreData(lastItem)) { smlTrace(TRACE_INTERNAL, "%s: Command buffer complete. Dispatching.", __func__); @@ -1353,20 +1300,18 @@ * the message ID are required for correct * status replies. */ - cmd->private.change.items = - session->incomingBuffer->private.change.items; - session->incomingBuffer->private.change.items = NULL; + smlCommandTransferItems(session->incomingBuffer, cmd, 0); smlCommandUnref(session->incomingBuffer); session->incomingBuffer = NULL; } - } else if (lastItem->moreData) { + } else if (smlItemGetMoreData(lastItem)) { /* There is no buffered command yet. * The new command is copied to the buffer. * This is done by reference copy and * an incrementation of the reference counter. */ - if (!cmd->size) { + if (!smlCommandGetSize(cmd)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "First MoreData item didn't have size set"); goto error; @@ -1374,20 +1319,20 @@ session->incomingBuffer = cmd; smlCommandRef(cmd); - smlTrace(TRACE_INTERNAL, "%s: New Buffer started. Buffered item size: %i. Required: %i", - __func__, - xmlBufferLength(lastItem->buffer), - lastItem->size); + //smlTrace(TRACE_INTERNAL, "%s: New Buffer started. Buffered item size: %i. Required: %i", + // __func__, + // xmlBufferLength(lastItem->buffer), + // lastItem->size); - char *bin = smlPrintBinary((char *) xmlBufferContent(lastItem->buffer), xmlBufferLength(lastItem->buffer)); + char *bin = smlPrintBinary(smlItemGetContent(lastItem), smlItemGetSize(lastItem)); smlTrace(TRACE_INTERNAL, "%s: Content so far: %s\n", __func__, VA_STRING(bin)); smlSafeCFree(&bin); } - if (lastItem->moreData == TRUE) { + if (smlItemGetMoreData(lastItem) == TRUE) { smlTrace(TRACE_INTERNAL, "%s: Got item with moreData %i", - __func__, cmd->msgID); + __func__, smlCommandGetMessageID(cmd)); SmlStatus *reply = smlCommandNewReply(cmd, SML_CHUNK_ACCEPTED, error); if (!reply) @@ -1404,13 +1349,13 @@ } /* if the command is a result, we treat it as a status */ - if (cmd->type == SML_COMMAND_TYPE_RESULTS) { + if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_RESULTS) { /* Call the callback*/ - if (!smlSessionDispatchStatus(session, cmd->private.results.status, error)) + if (!smlSessionDispatchStatus(session, smlCommandResultsGetStatus(cmd), error)) goto error; } else { /* Dispatch the command */ - cmd->msgID = session->lastReceivedMessageID; + smlCommandSetMessageID(cmd, session->lastReceivedMessageID); if (!session->end) { if (!session->parentCommand) { smlSessionDispatchEvent(session, SML_SESSION_EVENT_COMMAND_START, cmd, NULL, NULL, NULL); @@ -1441,7 +1386,7 @@ * twice that the callback are ready to be called twice * (usually this requires some kind of statefulness). */ - if (session->parentCommand->type == SML_COMMAND_TYPE_SYNC) { + if (smlCommandGetType(session->parentCommand) == SML_COMMAND_TYPE_SYNC) { smlSessionDispatchEvent( session, SML_SESSION_EVENT_COMMAND_END, @@ -1866,9 +1811,9 @@ if (session->cred) smlCredUnref(session->cred); session->cred = cred; - if (cred->username) { + if (smlCredGetUsername(cred)) { GError *error = NULL; - sml_location_set_name(session->source, cred->username, &error); + sml_location_set_name(session->source, smlCredGetUsername(cred), &error); if (error) g_error_free(error); } @@ -2356,7 +2301,7 @@ session->localMaxMsgSize = smlSessionGetRemoteMaxMsgSize(session); } - smlTrace(TRACE_EXIT, "%s", __func__); + smlTrace(TRACE_EXIT, "%s - %u", __func__, session->localMaxMsgSize); } gsize |