From: <svn...@op...> - 2009-07-16 11:45:30
|
Author: bellmich Date: Thu Jul 16 13:45:22 2009 New Revision: 1211 URL: http://libsyncml.opensync.org/changeset/1211 Log: cleaned up header file usage in sml_parse.c Modified: trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_notification.c trunk/libsyncml/sml_notification.h trunk/libsyncml/sml_notification_internals.h trunk/libsyncml/sml_parse.c Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_command.c Thu Jul 16 13:45:22 2009 (r1211) @@ -925,6 +925,12 @@ } } +gsize +smlCommandGetID (SmlCommand *cmd) +{ + return cmd->cmdID; +} + void smlCommandSetID (SmlCommand *cmd, gsize id) @@ -955,3 +961,35 @@ { return cmd->private.alert.contentType; } + +void +smlCommandDisableChanges (SmlCommand *cmd) +{ + smlAssert(cmd); + + if (cmd->private.change.items) + { + guint i; + for (i=0; i < g_list_length(cmd->private.change.items); i++) + { + SmlItem *item = g_list_nth_data(cmd->private.change.items, i); + smlItemSetDisable(item, TRUE); + } + } +} + +void +smlCommandEnableChanges (SmlCommand *cmd) +{ + smlAssert(cmd); + + if (cmd->private.change.items) + { + guint i; + for (i=0; i < g_list_length(cmd->private.change.items); i++) + { + SmlItem *item = g_list_nth_data(cmd->private.change.items, i); + smlItemSetDisable(item, FALSE); + } + } +} Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_command.h Thu Jul 16 13:45:22 2009 (r1211) @@ -65,7 +65,8 @@ SmlCommand* smlCommandNewMap (SmlLocation *target, SmlLocation *source, GError **error); gboolean smlCommandAddMapItem (SmlCommand *map, SmlMapItem *item, GError **error); -void smlCommandSetID (SmlCommand *cmd, gsize id); +void smlCommandSetID (SmlCommand *cmd, gsize id); +gsize smlCommandGetID (SmlCommand *cmd); SmlCommandType smlCommandGetType (SmlCommand *cmd); SmlLocation* smlCommandGetSource (SmlCommand *cmd); @@ -74,6 +75,9 @@ G_CONST_RETURN gchar *smlCommandTypeToString(SmlCommandType type, GError **error); +void smlCommandDisableChanges (SmlCommand *cmd); +void smlCommandEnableChanges (SmlCommand *cmd); + #endif //_SML_COMMAND_H_ /*@}*/ Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_elements.c Thu Jul 16 13:45:22 2009 (r1211) @@ -344,6 +344,13 @@ } void +smlItemSetDisable (SmlItem *item, + gboolean disable) +{ + item->disabled = disable; +} + +void smlItemSetSource (SmlItem *item, SmlLocation *source) { Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_elements.h Thu Jul 16 13:45:22 2009 (r1211) @@ -63,6 +63,7 @@ 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); void smlItemSetMoreData (SmlItem *item, gboolean enable); gboolean smlItemGetMoreData (SmlItem *item); Modified: trunk/libsyncml/sml_notification.c ============================================================================== --- trunk/libsyncml/sml_notification.c Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_notification.c Thu Jul 16 13:45:22 2009 (r1211) @@ -104,6 +104,28 @@ } void +smlNotificationSetMimeType (SmlNotification *san, + SmlMimeType mimeType) +{ + san->type = mimeType; +} + +void +smlNotificationSetSessionType (SmlNotification *san, + SmlSessionType sessionType) +{ + san->sessionType = sessionType; +} + +void +smlNotificationSetTarget (SmlNotification *san, + SmlLocation *target) +{ + san->target = target; + g_object_ref(san->target); +} + +void smlNotificationFree (SmlNotification *san) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, san); Modified: trunk/libsyncml/sml_notification.h ============================================================================== --- trunk/libsyncml/sml_notification.h Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_notification.h Thu Jul 16 13:45:22 2009 (r1211) @@ -56,13 +56,16 @@ SML_SAN_INITIATOR_SERVER = 1 } SmlNotificationInitiator; -SmlNotification* smlNotificationNew (SmlNotificationVersion version, SmlNotificationUIMode mode, SmlNotificationInitiator init, guint sessionID, const gchar *identifier, const gchar *target, SmlMimeType type, GError **error); -void smlNotificationSetCred (SmlNotification *san, SmlCred *cred); -void smlNotificationSetManager (SmlNotification *san, SmlManager *manager); -void smlNotificationFree (SmlNotification *san); -SmlNotification* smlNotificationParse (const gchar *data, gsize size, GError **error); -gboolean smlNotificationAssemble (SmlNotification *san, gchar **data, gsize *size, GError **error); -gboolean smlNotificationSend (SmlNotification *san, SmlTransport *tsp, GError **error); +SmlNotification* smlNotificationNew (SmlNotificationVersion version, SmlNotificationUIMode mode, SmlNotificationInitiator init, guint sessionID, const gchar *identifier, const gchar *target, SmlMimeType type, GError **error); +void smlNotificationSetCred (SmlNotification *san, SmlCred *cred); +void smlNotificationSetManager (SmlNotification *san, SmlManager *manager); +void smlNotificationSetMimeType (SmlNotification *san, SmlMimeType mimeType); +void smlNotificationSetSessionType (SmlNotification *san, SmlSessionType sessionType); +void smlNotificationSetTarget (SmlNotification *san, SmlLocation *target); +void smlNotificationFree (SmlNotification *san); +SmlNotification* smlNotificationParse (const gchar *data, gsize size, GError **error); +gboolean smlNotificationAssemble (SmlNotification *san, gchar **data, gsize *size, GError **error); +gboolean smlNotificationSend (SmlNotification *san, SmlTransport *tsp, GError **error); gboolean smlNotificationNewAlert (SmlNotification *san, SmlAlertType type, const gchar *contenttype, const gchar *serverURI, GError **error); void smlNotificationFreeAlert (SmlSanAlert *alert); @@ -79,6 +82,8 @@ const gchar* smlSanAlertGetContentType (SmlSanAlert *alert); const gchar* smlSanAlertGetServerURI (SmlSanAlert *alert); +gboolean smlNotificationAssemble11 (SmlNotification *san, gchar **data, gsize *size, SmlProtocolVersion version, GError **error); + #endif //_SML_NOTIFICATION_H_ /*@{*/ Modified: trunk/libsyncml/sml_notification_internals.h ============================================================================== --- trunk/libsyncml/sml_notification_internals.h Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_notification_internals.h Thu Jul 16 13:45:22 2009 (r1211) @@ -55,13 +55,6 @@ gchar *serverURI; }; -gboolean smlNotificationAssemble11( - SmlNotification *san, - gchar **data, - gsize *size, - SmlProtocolVersion version, - GError **error); - #endif //_SML_NOTIFICATION_INTERNALS_H_ /*@{*/ Modified: trunk/libsyncml/sml_parse.c ============================================================================== --- trunk/libsyncml/sml_parse.c Thu Jul 16 12:33:01 2009 (r1210) +++ trunk/libsyncml/sml_parse.c Thu Jul 16 13:45:22 2009 (r1211) @@ -19,14 +19,17 @@ * */ +#include "sml_parse_internals.h" + #include <config.h> #include "sml_error_internals.h" #include "sml_support.h" -#include "sml_parse_internals.h" -#include "sml_command_internals.h" -#include "sml_elements_internals.h" -#include "sml_notification_internals.h" + +#include "sml_command.h" +#include "sml_elements.h" +#include "sml_notification.h" + #include "data_sync_api/sml_location_internals.h" #include "parser/sml_xml_assm.h" @@ -166,11 +169,14 @@ /* fix 1.2 SAN for use with SyncML 1.1 */ smlNotificationSetManager(san, parser->manager); - san->type = SML_MIMETYPE_XML; - san->sessionType = SML_SESSION_TYPE_CLIENT; - san->target = sml_location_new_with_options("/", NULL, error); - if (!san->target) - goto error; + smlNotificationSetMimeType(san, SML_MIMETYPE_XML); + smlNotificationSetSessionType(san, SML_SESSION_TYPE_CLIENT); + SmlLocation *target = sml_location_new_with_options("/", NULL, error); + if (!target) + goto error; + smlNotificationSetTarget(san, target); + g_object_unref(target); + target = NULL; /* assemble a SyncML 1.1 notification */ char *xmlData = NULL; @@ -589,7 +595,7 @@ smlAssert(cmd); smlAssert(assm->functions.start_cmd); smlAssert(assm->functions.rem_cmd); - smlAssert(cmd->type == SML_COMMAND_TYPE_ADD || cmd->type == SML_COMMAND_TYPE_REPLACE); + smlAssert(smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE); unsigned int parentID = 0; gsize limit = smlAssemblerGetRemoteMaxMsgSize(assm); @@ -601,30 +607,25 @@ /* Add the command */ if (parent) { - if (!parent->cmdID) { + if (!smlCommandGetID(parent)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Parent has to be added before"); goto error; } - parentID = parent->cmdID; + parentID = smlCommandGetID(parent); } /* disable the items */ - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - item->disabled = TRUE; - } - } + smlCommandDisableChanges(cmd); + gboolean noCmdID = FALSE; - if (!cmd->cmdID) { + if (!smlCommandGetID(cmd)) { noCmdID = TRUE; /* FIXME: This code does not support more - * FIXME: than 99.999 commands in one session. */ - cmd->cmdID = 10000; + * FIXME: than 99.999 commands in one session. + * FIXME: Why don't we use 0? + */ + smlCommandSetID(cmd, 10000); } if (!assm->functions.start_cmd(assm->assm_userdata, parentID, cmd, error)) @@ -645,18 +646,10 @@ goto error_remove; /* enable the items again */ - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - item->disabled = FALSE; - } - } + smlCommandEnableChanges(cmd); if (noCmdID) - cmd->cmdID = 0; + smlCommandSetID(cmd, 0); smlTrace(TRACE_EXIT, "%s: %i", __func__, *space); return TRUE; @@ -664,17 +657,9 @@ error_remove: assm->functions.rem_cmd(assm->assm_userdata, parentID, NULL); error_enable_item: - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - item->disabled = FALSE; - } - } + smlCommandEnableChanges(cmd); if (noCmdID) - cmd->cmdID = 0; + smlCommandSetID(cmd, 0); error: smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; @@ -710,11 +695,11 @@ /* Add the command */ if (parent) { - if (!parent->cmdID) { + if (!smlCommandGetID(parent)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Parent has to be added before"); goto error; } - parentID = parent->cmdID; + parentID = smlCommandGetID(parent); } if (!assm->functions.start_cmd(assm->assm_userdata, parentID, cmd, error)) @@ -739,7 +724,7 @@ smlTrace(TRACE_INTERNAL, "%s: size %i, limit %i", __func__, size, limit); } - if (cmd->cmdID) + if (smlCommandGetID(cmd)) assm->empty = FALSE; smlTrace(TRACE_EXIT, "%s", __func__); @@ -774,11 +759,11 @@ /* Add the command */ if (parent) { - if (!parent->cmdID) { + if (!smlCommandGetID(parent)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Parent has to be added before"); goto error; } - parentID = parent->cmdID; + parentID = smlCommandGetID(parent); } /* End the command */ |