6 commits - src/kolabconversions.h src/php src/utils.cpp src/xcalconversions.h

Christian Mollekopf mollekopf at kolabsys.com
Wed Jun 6 14:41:05 CEST 2012


 src/kolabconversions.h |   10 +++++-----
 src/php/CMakeLists.txt |    2 +-
 src/utils.cpp          |   43 +++++++++++++++++++++++++++++--------------
 src/xcalconversions.h  |   45 ++++++++++++---------------------------------
 4 files changed, 47 insertions(+), 53 deletions(-)

New commits:
commit 5c360b5c0de1257ae942db547dfa54b2b99a8ad5
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 14:40:47 2012 +0200

    cleanup

diff --git a/src/xcalconversions.h b/src/xcalconversions.h
index e1b951e..0759ef3 100644
--- a/src/xcalconversions.h
+++ b/src/xcalconversions.h
@@ -1433,35 +1433,6 @@ void getAlarms(IncidenceType &incidence, const typename KolabType::components_ty
 
 //--- Alarms ---
 
-class Incidence; //Just for Trait
-
-///Trait for Incidence object
-template <typename T, typename I> 
-struct IncidenceConverter;
-
-template <typename T> struct IncidenceConverter < Incidence, T >
-{
-    static std::string uid(const T &inc) {
-        if (inc.uid().empty()) { //generate new UID
-            return getUID();
-        }
-        return inc.uid();
-    }
-    
-    static xml_schema::date_time dtstamp() {
-        return fromDateTime(timestamp());
-    }
-    
-    static xml_schema::date_time created(const T &inc) {
-        if (inc.created().isValid()) {
-            return fromDateTime(inc.created());
-        }
-        return fromDateTime(timestamp());
-    }
-
-};
-
-
 ///Trait for incidence properties specialized for Event/Todo/Journal
 template <typename T> struct IncidenceTrait;
 
@@ -1671,14 +1642,13 @@ template <typename T>
 std::string serializeIncidence(const typename T::IncidenceType &incidence, const std::string productid = std::string()) {
     
     using namespace icalendar_2_0;
-    typedef IncidenceConverter< Incidence, typename T::IncidenceType > IC;
     typedef typename T::KolabType KolabType;
     
     clearErrors();
 
     try {
 
-        typename KolabType::properties_type::uid_type uid(IC::uid(incidence));
+        typename KolabType::properties_type::uid_type uid( getUID(incidence.uid()));
         setCreatedUid(uid.text());
         typename KolabType::properties_type::dtstamp_type dtstamp;
         if (incidence.lastModified().isValid()) {
@@ -1686,8 +1656,13 @@ std::string serializeIncidence(const typename T::IncidenceType &incidence, const
         } else {
             dtstamp.date_time(fromDateTime(timestamp()));
         }
+
         typename KolabType::properties_type::created_type created;
-        created.date_time(IC::created(incidence));
+        if (incidence.created().isValid()) {
+            created.date_time(fromDateTime(incidence.created()));
+        } else {
+            created.date_time(fromDateTime(timestamp()));
+        }
         typename KolabType::properties_type eventProps(uid, created, dtstamp);
         
         KolabType inc(eventProps);


commit 41424122cfa3a1fdf0a2344d0052c26d2ab4f62e
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 14:40:30 2012 +0200

    Don't overwrite dtstamp with current timestamp if lastModified date is set.

diff --git a/src/xcalconversions.h b/src/xcalconversions.h
index af01753..e1b951e 100644
--- a/src/xcalconversions.h
+++ b/src/xcalconversions.h
@@ -1681,7 +1681,11 @@ std::string serializeIncidence(const typename T::IncidenceType &incidence, const
         typename KolabType::properties_type::uid_type uid(IC::uid(incidence));
         setCreatedUid(uid.text());
         typename KolabType::properties_type::dtstamp_type dtstamp;
-        dtstamp.date_time(IC::dtstamp());
+        if (incidence.lastModified().isValid()) {
+            dtstamp.date_time(fromDateTime(incidence.lastModified()));
+        } else {
+            dtstamp.date_time(fromDateTime(timestamp()));
+        }
         typename KolabType::properties_type::created_type created;
         created.date_time(IC::created(incidence));
         typename KolabType::properties_type eventProps(uid, created, dtstamp);


commit f3c04d46f29a77fa848bad4d942c74b1d4810cf7
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 14:24:46 2012 +0200

    run swig if kolabformat.php is removed

diff --git a/src/php/CMakeLists.txt b/src/php/CMakeLists.txt
index f21e8d2..57bfe39 100644
--- a/src/php/CMakeLists.txt
+++ b/src/php/CMakeLists.txt
@@ -2,7 +2,7 @@
 include_directories(../)
 
 set(KOLAB_SWIG_PHP_SOURCE_FILE php_kolabformat_wrapper.cpp)
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOLAB_SWIG_PHP_SOURCE_FILE}
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOLAB_SWIG_PHP_SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/kolabformat.php
         COMMAND ${SWIG} -v -c++ -php -o ${CMAKE_CURRENT_BINARY_DIR}/${KOLAB_SWIG_PHP_SOURCE_FILE}  ../kolabformat.i
         COMMENT "Generating php bindings"
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}


commit e33f9ffff38d10ce61b88e48d9bc24622840e100
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 14:23:29 2012 +0200

    Fix boost::uuid usage.
    
    The uuid was never initialized, and therefore the "randomness" of the uid was subject to the content of the stack (same stack => same uuid).

diff --git a/src/utils.cpp b/src/utils.cpp
index 4991d14..5e0bcb0 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -24,6 +24,7 @@
 #if BOOST_VERSION >= 104200
 #include <boost/uuid/uuid.hpp>
 #include <boost/uuid/uuid_io.hpp>
+#include <boost/uuid/uuid_generators.hpp>
 #else
 #include <uuid.h>
 #endif
@@ -103,23 +104,37 @@ std::string createdUid()
 
 std::string getUID(const std::string &s)
 {
-    if (s.empty()) {
+    if (!s.empty()) {
+        return s;
+    }
 #if BOOST_VERSION >= 104200
-        boost::uuids::uuid u; // initialize uuid
-        return boost::uuids::to_string(u);
+
+    //Required because boost::uuids::uuid is implemented as POD type
+    class uuid_class : public boost::uuids::uuid
+    {
+    public:
+        uuid_class()
+            : boost::uuids::uuid(boost::uuids::random_generator()())
+        {}
+
+        operator boost::uuids::uuid() const {
+            return static_cast<boost::uuids::uuid const&>(*this);
+        }
+    };
+
+    uuid_class u; // initialize uuid
+    return  boost::uuids::to_string(u);
 #else
-        uuid_t *uuid;
-        //to avoid the "dereferencing type-punned pointer will break strict-aliasing rules" warning
-        char * __attribute__((__may_alias__)) str = 0;
-        uuid_create(&uuid);
-        uuid_make(uuid, UUID_MAKE_V1);
-        uuid_export(uuid, UUID_FMT_STR, (void**)&str, 0);
-        uuid_destroy(uuid);
-
-        return std::string(str, 36); //We don't need the terminating \0
+    uuid_t *uuid;
+    //to avoid the "dereferencing type-punned pointer will break strict-aliasing rules" warning
+    char * __attribute__((__may_alias__)) str = 0;
+    uuid_create(&uuid);
+    uuid_make(uuid, UUID_MAKE_V1);
+    uuid_export(uuid, UUID_FMT_STR, (void**)&str, 0);
+    uuid_destroy(uuid);
+
+    return std::string(str, 36); //We don't need the terminating \0
 #endif
-    }
-    return s;
 }
 
 cDateTime getCurrentTime()


commit d3409eb502c4c8256ae55be2dedf38f90a92b855
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 13:28:24 2012 +0200

    Avoid unnecessary warning.

diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index d369147..6174f19 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -105,7 +105,7 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
         if (note.lastModified().isValid()) {
             lastModificationDate = fromDateTime(note.lastModified());
         } else {
-            WARNING("missing last_modification_date, fallback to current timestamp");
+//             WARNING("missing last_modification_date, fallback to current timestamp");
             lastModificationDate = fromDateTime(timestamp());
         }
         KolabXSD::Configuration n(uid, getProductId(prod), created, lastModificationDate, getConfiguratinoType(note.type()));
@@ -134,7 +134,7 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
         KolabXSD::configuration(ostringstream, n, map);
         return ostringstream.str();
     } catch  (const xml_schema::exception& e) {
-        CRITICAL("Unknown Exception: failed to write Note");
+        CRITICAL("Unknown Exception: failed to write Configuration");
     }
     return std::string();
 }
@@ -158,7 +158,7 @@ std::string serializeObject <Kolab::Note> (const Kolab::Note &note, const std::s
         if (note.lastModified().isValid()) {
             lastModificationDate = fromDateTime(note.lastModified());
         } else {
-            WARNING("missing last_modification_date, fallback to current timestamp");
+//             WARNING("missing last_modification_date, fallback to current timestamp");
             lastModificationDate = fromDateTime(timestamp());
         }
 


commit 478114c7883fa43168154a13a5f4e1a4ee00572e
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Jun 6 13:28:03 2012 +0200

    Actually use the uid which we record as being serialized

diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 446771c..d369147 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -108,7 +108,7 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
             WARNING("missing last_modification_date, fallback to current timestamp");
             lastModificationDate = fromDateTime(timestamp());
         }
-        KolabXSD::Configuration n(getUID(note.uid()), getProductId(prod), created, lastModificationDate, getConfiguratinoType(note.type()));
+        KolabXSD::Configuration n(uid, getProductId(prod), created, lastModificationDate, getConfiguratinoType(note.type()));
 
         switch (note.type()) {
             case Kolab::Configuration::TypeDictionary: {
@@ -162,7 +162,7 @@ std::string serializeObject <Kolab::Note> (const Kolab::Note &note, const std::s
             lastModificationDate = fromDateTime(timestamp());
         }
 
-        KolabXSD::Note n(getUID(note.uid()), getProductId(prod), created, lastModificationDate);
+        KolabXSD::Note n(uid, getProductId(prod), created, lastModificationDate);
 
         if (!note.categories().empty()) {
             KolabXSD::Note::categories_sequence categories;





More information about the commits mailing list