From: <svn...@op...> - 2009-06-15 16:29:04
|
Author: bellmich Date: Mon Jun 15 18:27:55 2009 New Revision: 1088 URL: http://libsyncml.opensync.org/changeset/1088 Log: migrated SmlDevInfContentType to GObject Added: trunk/libsyncml/dev_inf_api/ trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.c trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.h trunk/tests/check_dev_inf_content_type.c Modified: trunk/CMakeLists.txt trunk/libsyncml/CMakeLists.txt trunk/libsyncml/data_sync_api/data_sync_devinf.c trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_devinf.c trunk/libsyncml/sml_devinf.h trunk/libsyncml/syncml.h trunk/tests/CMakeLists.txt Modified: trunk/CMakeLists.txt ============================================================================== --- trunk/CMakeLists.txt Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/CMakeLists.txt Mon Jun 15 18:27:55 2009 (r1088) @@ -187,6 +187,12 @@ INCLUDE( Testing ) ENDIF(CHECK_FOUND) +IF(MEMORYCHECK_COMMAND) + SET( MEMORYCHECK_AVAILABLE ON ) +ELSE(MEMORYCHECK_COMMAND) + SET( MEMORYCHECK_AVAILABLE OFF ) +ENDIF(MEMORYCHECK_COMMAND) + OPTION( ENABLE_TOOLS "enable building tools" ON ) OPTION( ENABLE_TRACE "enable tracing" ON ) OPTION( ENABLE_BASE64_TEST "enable deprecated base64 tests" OFF ) @@ -254,6 +260,7 @@ SHOW_STATUS( ENABLE_TRACE "tracing tools\t\t" ) SHOW_STATUS( ENABLE_UNIT_TEST "unit tests\t\t\t" ) SHOW_STATUS( THREAD_SAFE_CHECK "check is thread safe\t\t" CHECK_VERSION ) +SHOW_STATUS( MEMORYCHECK_AVAILABLE "memory debugger\t\t" ) SHOW_STATUS( ENABLE_WBXML "WAP Binary XML\t\t" LIBWBXML2_VERSION ) SHOW_STATUS( ENABLE_HTTP "http transports\t\t" LIBSOUP2_VERSION ) SHOW_STATUS( ENABLE_OBEX "obex transports\t\t" OPENOBEX_VERSION ) Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/CMakeLists.txt Mon Jun 15 18:27:55 2009 (r1088) @@ -33,6 +33,7 @@ parser/sml_wbxml.c parser/sml_xml_assm.c parser/sml_xml_parse.c + dev_inf_api/sml-dev-inf-content-type.c ) IF ( ENABLE_OBEX ) @@ -90,3 +91,10 @@ DESTINATION ${LIBSYNCML_INCLUDE_DIR}/libsyncml/data_sync_api ) +## install header files of DevInf API + +INSTALL( FILES + dev_inf_api/sml-dev-inf-content-type.h + DESTINATION ${LIBSYNCML_INCLUDE_DIR}/libsyncml/dev_inf_api +) + Modified: trunk/libsyncml/data_sync_api/data_sync_devinf.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_devinf.c Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/data_sync_api/data_sync_devinf.c Mon Jun 15 18:27:55 2009 (r1088) @@ -118,17 +118,21 @@ smlAssert(verct); // first we check for an already configure CTCap - SmlDevInfContentType *ct = smlDevInfNewContentType(cttype, verct, error); - if (!ct) + GError *gerror = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new(cttype, verct, &gerror); + if (!ct) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } if (smlDevInfGetCTCap(devinf, ct) != NULL) { - smlDevInfFreeContentType(ct); + g_object_unref(ct); smlTrace(TRACE_EXIT, "%s - content type already present in devinf", __func__); return TRUE; } else { - smlDevInfFreeContentType(ct); + g_object_unref(ct); smlTrace(TRACE_INTERNAL, "%s: new content type detected", __func__); } @@ -454,18 +458,25 @@ const char *ct = datastore->contentType; SmlDevInfContentType *ctype; + GError *gerror = NULL; if (!strcmp(ct, SML_ELEMENT_TEXT_VCARD)) { // we prefer actually vCard 2.1 // because the most cellphones support it - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCARD_30, "3.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCARD_30, "3.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddRx(ds, ctype); - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCARD_30, "3.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCARD_30, "3.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddTx(ds, ctype); smlDevInfDataStoreSetRxPref(ds, SML_ELEMENT_TEXT_VCARD, "2.1"); smlDevInfDataStoreSetTxPref(ds, SML_ELEMENT_TEXT_VCARD, "2.1"); @@ -476,13 +487,19 @@ } else if (!strcmp(ct, SML_ELEMENT_TEXT_VCARD_30)) { - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCARD_30, "2.1", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCARD_30, "2.1", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddRx(ds, ctype); - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCARD_30, "2.1", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCARD_30, "2.1", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddTx(ds, ctype); smlDevInfDataStoreSetRxPref(ds, SML_ELEMENT_TEXT_VCARD_30, "3.0"); smlDevInfDataStoreSetTxPref(ds, SML_ELEMENT_TEXT_VCARD_30, "3.0"); @@ -493,13 +510,19 @@ } else if (!strcmp(ct, SML_ELEMENT_TEXT_VCAL)) { - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_ICAL, "2.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_ICAL, "2.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddRx(ds, ctype); - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_ICAL, "2.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_ICAL, "2.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddTx(ds, ctype); smlDevInfDataStoreSetRxPref(ds, SML_ELEMENT_TEXT_VCAL, "1.0"); smlDevInfDataStoreSetTxPref(ds, SML_ELEMENT_TEXT_VCAL, "1.0"); @@ -510,13 +533,19 @@ } else if (!strcmp(ct, SML_ELEMENT_TEXT_ICAL)) { - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCAL, "1.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCAL, "1.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddRx(ds, ctype); - ctype = smlDevInfNewContentType(SML_ELEMENT_TEXT_VCAL, "1.0", error); - if (!ctype) + ctype = sml_dev_inf_content_type_new(SML_ELEMENT_TEXT_VCAL, "1.0", &gerror); + if (!ctype) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error; + } smlDevInfDataStoreAddTx(ds, ctype); smlDevInfDataStoreSetRxPref(ds, SML_ELEMENT_TEXT_ICAL, "2.0"); smlDevInfDataStoreSetTxPref(ds, SML_ELEMENT_TEXT_ICAL, "2.0"); Added: trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.c Mon Jun 15 18:27:55 2009 (r1088) @@ -0,0 +1,199 @@ +/* sml-dev-inf-content-type.c */ + +#include "sml-dev-inf-content-type.h" + +G_DEFINE_TYPE (SmlDevInfContentType, sml_dev_inf_content_type, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_CTTYPE, + PROP_VERCT +}; + +struct _SmlDevInfContentTypePrivate +{ + gchar* cttype; + gchar* verct; +}; + +static void +sml_dev_inf_content_type_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_CTTYPE: + g_value_set_string (value, SML_DEV_INF_CONTENT_TYPE (object)->priv->cttype); + break; + case PROP_VERCT: + g_value_set_string (value, SML_DEV_INF_CONTENT_TYPE (object)->priv->verct); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_dev_inf_content_type_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_dev_inf_content_type_finalize (GObject *object) +{ + g_return_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (object)); + SmlDevInfContentType *self = (SmlDevInfContentType*) object; + if (self->priv->cttype != NULL) + g_free(self->priv->cttype); + if (self->priv->verct != NULL) + g_free(self->priv->verct); + G_OBJECT_CLASS (sml_dev_inf_content_type_parent_class)->finalize (object); +} + +static void +sml_dev_inf_content_type_class_init (SmlDevInfContentTypeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlDevInfContentTypePrivate)); + + object_class->get_property = sml_dev_inf_content_type_get_property; + object_class->set_property = sml_dev_inf_content_type_set_property; + object_class->finalize = sml_dev_inf_content_type_finalize; + + /** + * SmlDevInfContentType:CTType: + * + * The property. + */ + g_object_class_install_property (object_class, + PROP_CTTYPE, + g_param_spec_string ("CTType", + "", + "", + NULL, + G_PARAM_READABLE)); + /** + * SmlDevInfContentType:VerCT: + * + * The property. + */ + g_object_class_install_property (object_class, + PROP_VERCT, + g_param_spec_string ("VerCT", + "", + "", + NULL, + G_PARAM_READABLE)); + +} + +static void +sml_dev_inf_content_type_init (SmlDevInfContentType *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_DEV_INF_CONTENT_TYPE, + SmlDevInfContentTypePrivate); +} + +/** + * sml_dev_inf_content_type_new: + * + * Creates a new instance of #SmlDevInfContentType. + * + * Return value: the newly created #SmlDevInfContentType instance + */ +SmlDevInfContentType* +sml_dev_inf_content_type_new (const gchar* cttype, + const gchar* verct, + GError **error) +{ + SmlDevInfContentType* self = g_object_new (SML_TYPE_DEV_INF_CONTENT_TYPE, NULL); + self->priv->cttype = g_strdup(cttype); + self->priv->verct = g_strdup(verct); + return self; +} + +/** + * sml_dev_inf_content_type_get_cttype: + * @self: A #SmlDevInfContentType + * + * Gets the property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_content_type_get_cttype (SmlDevInfContentType *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (self), NULL); + return self->priv->cttype; +} + +/** + * sml_dev_inf_content_type_get_verct: + * @self: A #SmlDevInfContentType + * + * Gets the property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_content_type_get_verct (SmlDevInfContentType *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (self), NULL); + return self->priv->verct; +} + +/** + * sml_dev_inf_content_type_set_cttype: + * @self: A #SmlDevInfContentType + * @cttype: The content type string + * @error: A potential failure reason + * + * Sets the property. + * + * Return value: + */ +gboolean +sml_dev_inf_content_type_set_cttype (SmlDevInfContentType *self, const gchar* cttype, GError **error) +{ + g_return_val_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (self), FALSE); + if (self->priv->cttype) { + g_free(self->priv->cttype); + self->priv->cttype = NULL; + } + self->priv->cttype = g_strdup(cttype); + return TRUE; +} + +/** + * sml_dev_inf_content_type_get_verct: + * @self: A #SmlDevInfContentType + * @verct: The version of the content type + * @error: A potential failure reason + * + * Gets the property. + * + * Return value: + */ +gboolean +sml_dev_inf_content_type_set_verct (SmlDevInfContentType *self, const gchar* verct, GError **error) +{ + g_return_val_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (self), FALSE); + if (self->priv->verct) { + g_free(self->priv->verct); + self->priv->verct = NULL; + } + self->priv->verct = g_strdup(verct); + return TRUE; +} + Added: trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml-dev-inf-content-type.h Mon Jun 15 18:27:55 2009 (r1088) @@ -0,0 +1,44 @@ +/* sml-dev-inf-content-type.h */ + +#ifndef __SML_DEV_INF_CONTENT_TYPE_H__ +#define __SML_DEV_INF_CONTENT_TYPE_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define SML_TYPE_DEV_INF_CONTENT_TYPE (sml_dev_inf_content_type_get_type()) +#define SML_DEV_INF_CONTENT_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_DEV_INF_CONTENT_TYPE, SmlDevInfContentType)) +#define SML_DEV_INF_CONTENT_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_DEV_INF_CONTENT_TYPE, SmlDevInfContentTypeClass)) +#define SML_IS_DEV_INF_CONTENT_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_DEV_INF_CONTENT_TYPE)) +#define SML_IS_DEV_INF_CONTENT_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_DEV_INF_CONTENT_TYPE)) +#define SML_DEV_INF_CONTENT_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_DEV_INF_CONTENT_TYPE, SmlDevInfContentTypeClass)) + +typedef struct _SmlDevInfContentType SmlDevInfContentType; +typedef struct _SmlDevInfContentTypeClass SmlDevInfContentTypeClass; +typedef struct _SmlDevInfContentTypePrivate SmlDevInfContentTypePrivate; + +struct _SmlDevInfContentType +{ + GObject parent; + + /*< private >*/ + SmlDevInfContentTypePrivate *priv; +}; + +struct _SmlDevInfContentTypeClass +{ + GObjectClass parent_class; + +}; + +GType sml_dev_inf_content_type_get_type (void); +SmlDevInfContentType* sml_dev_inf_content_type_new (const gchar* cttype, const gchar* verct, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_content_type_get_cttype (SmlDevInfContentType *self); +G_CONST_RETURN gchar* sml_dev_inf_content_type_get_verct (SmlDevInfContentType *self); +gboolean sml_dev_inf_content_type_set_cttype (SmlDevInfContentType *self, const gchar* cttype, GError **error); +gboolean sml_dev_inf_content_type_set_verct (SmlDevInfContentType *self, const gchar* verct, GError **error); + +G_END_DECLS + +#endif /* __SML_DEV_INF_CONTENT_TYPE_H__ */ Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/parser/sml_xml_assm.c Mon Jun 15 18:27:55 2009 (r1088) @@ -2063,7 +2063,7 @@ } // add CTType - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_CTTYPE, ctcap->ct->cttype, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_CTTYPE, sml_dev_inf_content_type_get_cttype(ctcap->ct), error)) goto error; // add VerCT @@ -2071,7 +2071,7 @@ // because this info is in the VERSION property. if (!flat) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_VERCT, ctcap->ct->verct, error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_VERCT, sml_dev_inf_content_type_get_verct(ctcap->ct), error)) goto error; } @@ -2234,6 +2234,7 @@ smlAssert(assm); GList *contentTypes = NULL; + GError *gerror = NULL; if (!datastore->sourceref) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing sourceref"); @@ -2278,11 +2279,12 @@ //rx-pref if (!_smlXmlDevInfDataStoreAssembleRxTx(assm, SML_ELEMENT_RXPREF, datastore->rxPrefContentType, datastore->rxPrefVersion, error)) goto error; + /* FIXME: ignored error */ contentTypes = g_list_append( contentTypes, - smlDevInfNewContentType( + sml_dev_inf_content_type_new( datastore->rxPrefContentType, - datastore->rxPrefVersion, error)); + datastore->rxPrefVersion, &gerror)); //rx if (datastore->rx) { @@ -2290,11 +2292,11 @@ for (hl = datastore->rx; hl; hl = hl->next) { SmlDevInfContentType *ct = hl->data; - if (!_smlXmlDevInfDataStoreAssembleRxTx(assm, SML_ELEMENT_RX, ct->cttype, ct->verct, error)) + if (!_smlXmlDevInfDataStoreAssembleRxTx(assm, SML_ELEMENT_RX, sml_dev_inf_content_type_get_cttype(ct), sml_dev_inf_content_type_get_verct(ct), error)) goto error; contentTypes = g_list_append( contentTypes, - smlDevInfNewContentType(ct->cttype, ct->verct, error)); + sml_dev_inf_content_type_new(sml_dev_inf_content_type_get_cttype(ct), sml_dev_inf_content_type_get_verct(ct), &gerror)); } } @@ -2303,9 +2305,9 @@ goto error; contentTypes = g_list_append( contentTypes, - smlDevInfNewContentType( + sml_dev_inf_content_type_new( datastore->txPrefContentType, - datastore->txPrefVersion, error)); + datastore->txPrefVersion, &gerror)); //tx if (datastore->tx) { @@ -2313,11 +2315,11 @@ for (hl = datastore->tx; hl; hl = hl->next) { SmlDevInfContentType *ct = hl->data; - if (!_smlXmlDevInfDataStoreAssembleRxTx(assm, SML_ELEMENT_TX, ct->cttype, ct->verct, error)) + if (!_smlXmlDevInfDataStoreAssembleRxTx(assm, SML_ELEMENT_TX, sml_dev_inf_content_type_get_cttype(ct), sml_dev_inf_content_type_get_verct(ct), error)) goto error; contentTypes = g_list_append( contentTypes, - smlDevInfNewContentType(ct->cttype, ct->verct, error)); + sml_dev_inf_content_type_new(sml_dev_inf_content_type_get_cttype(ct), sml_dev_inf_content_type_get_verct(ct), &gerror)); } } @@ -2339,7 +2341,7 @@ // this is a real source of trouble // WARNING: should we fail on this issue? smlTrace(TRACE_INTERNAL, "%s: found a content type (%s %d) without CTCap", - __func__, VA_STRING(ct->cttype), ct->verct); + __func__, VA_STRING(sml_dev_inf_content_type_get_cttype(ct)), VA_STRING(sml_dev_inf_content_type_get_verct(ct))); } } // end of contentTypes for loop } // end of SML_DEVINF_VERSION_12 @@ -2349,7 +2351,7 @@ { SmlDevInfContentType *ct = contentTypes->data; contentTypes = g_list_remove(contentTypes, ct); - smlDevInfFreeContentType(ct); + g_object_unref(ct); } //Dsmem Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/parser/sml_xml_parse.c Mon Jun 15 18:27:55 2009 (r1088) @@ -3232,12 +3232,16 @@ char *verct = NULL; if (!_smlXmlDevInfDataStoreParseRxTx(parser, SML_ELEMENT_RX, &cttype, &verct, error)) goto error_free_datastore; - SmlDevInfContentType *ct = smlDevInfNewContentType(cttype, verct, error); + GError *gerror = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new(cttype, verct, &gerror); smlSafeCFree(&cttype); if (verct) smlSafeCFree(&verct); - if (!ct) + if (!ct) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error_free_datastore; + } smlDevInfDataStoreAddRx(datastore, ct); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TXPREF)) { if (!_smlXmlDevInfDataStoreParseRxTx(parser, SML_ELEMENT_TXPREF, &(datastore->txPrefContentType), &(datastore->txPrefVersion), error)) @@ -3247,12 +3251,16 @@ char *verct = NULL; if (!_smlXmlDevInfDataStoreParseRxTx(parser, SML_ELEMENT_TX, &cttype, &verct, error)) goto error_free_datastore; - SmlDevInfContentType *ct = smlDevInfNewContentType(cttype, verct, error); + GError *gerror = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new(cttype, verct, &gerror); smlSafeCFree(&cttype); if (verct) smlSafeCFree(&verct); - if (!ct) + if (!ct) { + smlErrorSet(error, SML_ERROR_GENERIC, "%s", gerror->message); + g_error_free(gerror); goto error_free_datastore; + } smlDevInfDataStoreAddTx(datastore, ct); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CTCAP)) { if (!_smlXmlDevInfDataStoreParseCTCap(parser, devinf, error)) Modified: trunk/libsyncml/sml_devinf.c ============================================================================== --- trunk/libsyncml/sml_devinf.c Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/sml_devinf.c Mon Jun 15 18:27:55 2009 (r1088) @@ -146,10 +146,11 @@ while (devinf->ctcaps) { SmlDevInfCTCap *ctcap = devinf->ctcaps->data; devinf->ctcaps = g_list_remove(devinf->ctcaps, ctcap); - smlSafeCFree(&(ctcap->ct->cttype)); - if (ctcap->ct->verct) - smlSafeCFree(&(ctcap->ct->verct)); - smlSafeFree((gpointer *)&(ctcap->ct)); + //smlSafeCFree(&(ctcap->ct->cttype)); + //if (ctcap->ct->verct) + // smlSafeCFree(&(ctcap->ct->verct)); + //smlSafeFree((gpointer *)&(ctcap->ct)); + g_object_unref(ctcap->ct); while (ctcap->properties) { SmlDevInfProperty *prop = ctcap->properties->data; ctcap->properties = g_list_remove(ctcap->properties, prop); @@ -397,7 +398,7 @@ GList *d = NULL; for (d = datastore->rx; d; d = d->next) { SmlDevInfContentType *ct = d->data; - smlDevInfFreeContentType(ct); + g_object_unref(ct); } g_list_free(datastore->rx); @@ -405,7 +406,7 @@ smlSafeCFree(&(datastore->txPrefVersion)); for (d = datastore->tx; d; d = d->next) { SmlDevInfContentType *ct = d->data; - smlDevInfFreeContentType(ct); + g_object_unref(ct); } g_list_free(datastore->tx); @@ -471,32 +472,6 @@ return TRUE; } -/* FIXME: DEPRECATED*/ -void smlDevInfDataStoreSetRx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version) -{ - SmlError *error = NULL; - SmlDevInfContentType *ct = smlDevInfNewContentType(contenttype, version, &error); - if (!ct) - { - smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(&error)); - smlErrorDeref(&error); - return; - } - smlDevInfDataStoreAddRx(datastore, ct); -} - -/* FIXME: DEPRECATED*/ -SmlBool smlDevInfDataStoreGetRx(const SmlDevInfDataStore *datastore, char **contenttype, char **version) -{ - const SmlDevInfContentType *ct = smlDevInfDataStoreGetNthRx(datastore, 0); - if (!ct) - return FALSE; - - *contenttype = smlDevInfContentTypeGetCTType(ct); - *version = smlDevInfContentTypeGetVerCT(ct); - return TRUE; -} - void smlDevInfDataStoreAddRx(SmlDevInfDataStore *datastore, SmlDevInfContentType *ct) { smlAssert(datastore); @@ -537,32 +512,6 @@ return TRUE; } -/* FIXME: DEPRECATED*/ -void smlDevInfDataStoreSetTx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version) -{ - SmlError *error = NULL; - SmlDevInfContentType *ct = smlDevInfNewContentType(contenttype, version, &error); - if (!ct) - { - smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(&error)); - smlErrorDeref(&error); - return; - } - smlDevInfDataStoreAddTx(datastore, ct); -} - -/* FIXME: DEPRECATED*/ -SmlBool smlDevInfDataStoreGetTx(const SmlDevInfDataStore *datastore, char **contenttype, char **version) -{ - const SmlDevInfContentType *ct = smlDevInfDataStoreGetNthRx(datastore, 0); - if (!ct) - return FALSE; - - *contenttype = smlDevInfContentTypeGetCTType(ct); - *version = smlDevInfContentTypeGetVerCT(ct); - return TRUE; -} - void smlDevInfDataStoreAddTx(SmlDevInfDataStore *datastore, SmlDevInfContentType *ct) { smlAssert(datastore); @@ -1247,57 +1196,6 @@ /* CTCap stuff */ -SmlDevInfContentType *smlDevInfNewContentType( - const char *cttype, - const char *verct, - SmlError **error) -{ - smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error); - CHECK_ERROR_REF - - SmlDevInfContentType *ct = smlTryMalloc0(sizeof(SmlDevInfContentType), error); - if (!ct) { - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); - return NULL; - } - - if (cttype != NULL) - ct->cttype = g_strdup(cttype); - else - ct->cttype = NULL; - if (verct != NULL) - ct->verct = g_strdup(verct); - else - ct->verct = NULL; - - smlTrace(TRACE_EXIT, "%s", __func__); - return ct; -} - -char *smlDevInfContentTypeGetCTType(const SmlDevInfContentType *ct) -{ - return g_strdup(ct->cttype); -} - -char *smlDevInfContentTypeGetVerCT(const SmlDevInfContentType *ct) -{ - return g_strdup(ct->verct); -} - -void smlDevInfFreeContentType(SmlDevInfContentType *ct) -{ - smlTrace(TRACE_ENTRY, "%s", __func__); - smlAssert(ct); - - if (ct->cttype != NULL) - smlSafeCFree(&(ct->cttype)); - if (ct->verct != NULL) - smlSafeCFree(&(ct->verct)); - smlSafeFree((gpointer *)&ct); - - smlTrace(TRACE_EXIT, "%s", __func__); -} - SmlDevInfCTCap *smlDevInfNewCTCap(SmlError **error) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error); @@ -1309,9 +1207,10 @@ return NULL; } - ctcap->ct = smlDevInfNewContentType(NULL, NULL, error); + GError *gerror = NULL; + ctcap->ct = sml_dev_inf_content_type_new(NULL, NULL, &gerror); if (!ctcap->ct) { - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, gerror->message); smlSafeFree((gpointer *)&ctcap); return NULL; } @@ -1329,7 +1228,8 @@ smlAssert(ctcap); smlAssert(cttype); - ctcap->ct->cttype = g_strdup(cttype); + GError *gerror = NULL; + sml_dev_inf_content_type_set_cttype(ctcap->ct, cttype, &gerror); smlTrace(TRACE_EXIT, "%s", __func__); } @@ -1342,7 +1242,8 @@ smlAssert(ctcap); smlAssert(verct); - ctcap->ct->verct = g_strdup(verct); + GError *gerror = NULL; + sml_dev_inf_content_type_set_verct(ctcap->ct, verct, &gerror); smlTrace(TRACE_EXIT, "%s", __func__); } @@ -1353,7 +1254,7 @@ smlAssert(ctcap); char *cttype; - cttype = g_strdup(ctcap->ct->cttype); + cttype = g_strdup(sml_dev_inf_content_type_get_cttype(ctcap->ct)); smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(cttype)); return cttype; @@ -1365,7 +1266,7 @@ smlAssert(ctcap); char *verct; - verct = g_strdup(ctcap->ct->verct); + verct = g_strdup(sml_dev_inf_content_type_get_verct(ctcap->ct)); smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(verct)); return verct; @@ -1391,33 +1292,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -/* FIXME: DEPRECATED*/ -void smlDevInfAddCTCap(SmlDevInf *devinf, SmlDevInfCTCapType type, const char *value) -{ - SmlDevInfCTCap *ctcap = smlDevInfNewCTCap(NULL); - smlDevInfCTCapSetCTType(ctcap, smlDevInfCTCapTypeToString(type, NULL)); - smlDevInfCTCapSetVerCT(ctcap, value); - smlDevInfAppendCTCap(devinf, ctcap); -} - -/* FIXME: DEPRECATED*/ -SmlDevInfCTCapType smlDevInfGetNthCTCapType(SmlDevInf *devinf, unsigned int nth) -{ - const SmlDevInfCTCap *ctcap = smlDevInfGetNthCTCap(devinf, nth); - char *type = smlDevInfCTCapGetCTType(ctcap); - SmlError *error = NULL; - SmlDevInfCTCapType cttype = smlDevInfCTCapTypeFromString(type, &error); - smlSafeCFree(&type); - return cttype; -} - -/* FIXME: DEPRECATED*/ -const char *smlDevInfGetNthCTCapValue(SmlDevInf *devinf, unsigned int nth) -{ - const SmlDevInfCTCap *ctcap = smlDevInfGetNthCTCap(devinf, nth); - return smlDevInfCTCapGetVerCT(ctcap); -} - const SmlDevInfCTCap *smlDevInfGetCTCap( const SmlDevInf *devinf, SmlDevInfContentType *ct) @@ -1425,16 +1299,18 @@ smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, ct); smlAssert(devinf); smlAssert(ct); - smlAssert(ct->cttype); - smlAssert(ct->verct); + smlAssert(sml_dev_inf_content_type_get_cttype(ct)); + smlAssert(sml_dev_inf_content_type_get_verct(ct)); GList *h; for (h = devinf->ctcaps; h; h = h->next) { SmlDevInfCTCap *ctcap = h->data; // check that CTType matches - if (!strcmp(ct->cttype, ctcap->ct->cttype) && - !strcmp(ct->verct, ctcap->ct->verct)) + if (!strcmp(sml_dev_inf_content_type_get_cttype(ct), + sml_dev_inf_content_type_get_cttype(ctcap->ct)) && + !strcmp(sml_dev_inf_content_type_get_verct(ct), + sml_dev_inf_content_type_get_verct(ctcap->ct))) { smlTrace(TRACE_EXIT, "%s - succeeded", __func__); return ctcap; Modified: trunk/libsyncml/sml_devinf.h ============================================================================== --- trunk/libsyncml/sml_devinf.h Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/sml_devinf.h Mon Jun 15 18:27:55 2009 (r1088) @@ -30,6 +30,8 @@ #ifndef _SML_DEVINF_H_ #define _SML_DEVINF_H_ +#include <libsyncml/dev_inf_api/sml-dev-inf-content-type.h> + SmlDevInfDevTyp smlDevInfDevTypeFromString(const char *name, SmlError **error); const char *smlDevInfDevTypeToString(SmlDevInfDevTyp type, SmlError **error); @@ -179,13 +181,13 @@ /* CTCap stuff */ -SmlDevInfContentType *smlDevInfNewContentType( - const char *cttype, - const char *verct, - SmlError **error); -char *smlDevInfContentTypeGetCTType(const SmlDevInfContentType *ct); -char *smlDevInfContentTypeGetVerCT(const SmlDevInfContentType *ct); -void smlDevInfFreeContentType(SmlDevInfContentType *ct); +//SmlDevInfContentType *smlDevInfNewContentType( +// const char *cttype, +// const char *verct, +// SmlError **error); +//char *smlDevInfContentTypeGetCTType(const SmlDevInfContentType *ct); +//char *smlDevInfContentTypeGetVerCT(const SmlDevInfContentType *ct); +//void smlDevInfFreeContentType(SmlDevInfContentType *ct); SmlDevInfCTCap *smlDevInfNewCTCap(SmlError **error); void smlDevInfCTCapSetCTType( @@ -213,17 +215,6 @@ const SmlDevInfCTCap *ctcap, unsigned int n); -/* expire date: 20090120 */ -void smlDevInfAddCTCap(SmlDevInf *devinf, SmlDevInfCTCapType type, const char *value) LIBSYNCML_DEPRECATED; -SmlDevInfCTCapType smlDevInfGetNthCTCapType(SmlDevInf *devinf, unsigned int nth) LIBSYNCML_DEPRECATED; -const char *smlDevInfGetNthCTCapValue(SmlDevInf *devinf, unsigned int nth) LIBSYNCML_DEPRECATED; - -/* expire date: 20090407 */ -void smlDevInfDataStoreSetRx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version) LIBSYNCML_DEPRECATED; -SmlBool smlDevInfDataStoreGetRx(const SmlDevInfDataStore *datastore, char **contenttype, char **version) LIBSYNCML_DEPRECATED; -void smlDevInfDataStoreSetTx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version) LIBSYNCML_DEPRECATED; -SmlBool smlDevInfDataStoreGetTx(const SmlDevInfDataStore *datastore, char **contenttype, char **version) LIBSYNCML_DEPRECATED; - #endif //_SML_DEVINF_H_ /*@}*/ Modified: trunk/libsyncml/syncml.h ============================================================================== --- trunk/libsyncml/syncml.h Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/libsyncml/syncml.h Mon Jun 15 18:27:55 2009 (r1088) @@ -77,7 +77,7 @@ typedef struct SmlItem SmlItem; typedef struct SmlDevInf SmlDevInf; typedef struct SmlDevInfDataStore SmlDevInfDataStore; -typedef struct SmlDevInfContentType SmlDevInfContentType; +//typedef struct SmlDevInfContentType SmlDevInfContentType; typedef struct SmlDevInfCTCap SmlDevInfCTCap; typedef struct SmlDevInfProperty SmlDevInfProperty; typedef struct SmlDevInfPropParam SmlDevInfPropParam; Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Thu Jun 4 11:27:14 2009 (r1087) +++ trunk/tests/CMakeLists.txt Mon Jun 15 18:27:55 2009 (r1088) @@ -261,6 +261,13 @@ SML_ADD_TESTCASE( devinf_max_size_element ) SML_END_TEST() + SML_START_TEST( "DevInfContentType" dev_inf_content_type check_dev_inf_content_type.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( dev_inf_content_type_create ) + SML_ADD_TESTCASE( dev_inf_content_type_empty_get ) + SML_ADD_TESTCASE( dev_inf_content_type_filled_get ) + SML_ADD_TESTCASE( dev_inf_content_type_references ) + SML_END_TEST() + SML_START_TEST( "Sync" sync check_sync.c ${TEST_TARGET_LIBRARIES} ) IF ( ENABLE_HTTP ) SML_ADD_TESTCASE( sync_multi_start ) Added: trunk/tests/check_dev_inf_content_type.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/check_dev_inf_content_type.c Mon Jun 15 18:27:55 2009 (r1088) @@ -0,0 +1,103 @@ +/* + * libsyncml - A syncml protocol implementation + * 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 Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "tests/support.h" + +#include <libsyncml/dev_inf_api/sml-dev-inf-content-type.h> + +START_TEST (dev_inf_content_type_create) +{ + g_type_init(); + + GError *error = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + g_object_unref(ct); + + ct = sml_dev_inf_content_type_new("text/plain", NULL, &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + g_object_unref(ct); + + return; + + ct = sml_dev_inf_content_type_new(NULL, "2.1", &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + g_object_unref(ct); + + ct = sml_dev_inf_content_type_new("text/x-vCalendar", "1.0", &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + g_object_unref(ct); +} +END_TEST + +START_TEST (dev_inf_content_type_empty_get) +{ + g_type_init(); + + GError *error = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + + sml_fail_unless(sml_dev_inf_content_type_get_cttype(ct) == NULL, NULL); + sml_fail_unless(sml_dev_inf_content_type_get_verct(ct) == NULL, NULL); + + g_object_unref(ct); +} +END_TEST + +START_TEST (dev_inf_content_type_filled_get) +{ + g_type_init(); + + GError *error = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new("text/x-vCalendar", "1.0", &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + + sml_fail_unless(sml_dev_inf_content_type_get_cttype(ct) != NULL, NULL); + sml_fail_unless(sml_dev_inf_content_type_get_verct(ct) != NULL, NULL); + + g_object_unref(ct); +} +END_TEST + +START_TEST (dev_inf_content_type_references) +{ + g_type_init(); + + GError *error = NULL; + SmlDevInfContentType *ct = sml_dev_inf_content_type_new("text/x-vCalendar", "1.0", &error); + sml_fail_unless(ct != NULL, "%s", error?error->message:"No GError set."); + + g_object_ref(ct); + + sml_fail_unless(sml_dev_inf_content_type_get_cttype(ct) != NULL, NULL); + sml_fail_unless(sml_dev_inf_content_type_get_verct(ct) != NULL, NULL); + + g_object_unref(ct); + + sml_fail_unless(sml_dev_inf_content_type_get_cttype(ct) != NULL, NULL); + sml_fail_unless(sml_dev_inf_content_type_get_verct(ct) != NULL, NULL); + + g_object_unref(ct); +} +END_TEST + +@SML_TESTCASE_CODE@ + |