2 commits - c++/lib c++/README schemas/xCard.xsd

Christian Mollekopf mollekopf at kolabsys.com
Fri Mar 9 19:37:21 CET 2012


 c++/README                 |   18 ++++--
 c++/lib/CMakeLists.txt     |    8 --
 c++/lib/kolabconversions.h |   13 ++--
 c++/lib/uricode.h          |  122 +++++++++++++++++++++++++++++++++++++++++++++
 c++/lib/utils.cpp          |    5 +
 schemas/xCard.xsd          |   12 ++--
 6 files changed, 149 insertions(+), 29 deletions(-)

New commits:
commit 03f560eff6b8c5091132af114db49eb1eec6b934
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Mar 9 19:36:27 2012 +0100

    cleanup

diff --git a/c++/README b/c++/README
index ba1f383..88b9c36 100644
--- a/c++/README
+++ b/c++/README
@@ -7,12 +7,16 @@ $make
 
 
 Minimum requirements are:
--cmake 2.8
--boost >1.47
--xerces-c >3.0
--cxx >3.0 (http://www.codesynthesis.com/products/xsd/)
+-cmake 2.6
+-boost >= 1.47
+-xerces-c >= 3.0
+-cxx >= 3.0 (http://www.codesynthesis.com/products/xsd/)
 
 For further features:
--SWIG >2.0
--QT >4.7
--KCalCore/KDECore >4.7
+-SWIG >= 2.0
+-QT >= 4.7
+-KCalCore/KDECore >= 4.7
+
+
+For further information see lib/DEVELOPMENT.
+
diff --git a/c++/lib/CMakeLists.txt b/c++/lib/CMakeLists.txt
index b26fc0e..0e34045 100644
--- a/c++/lib/CMakeLists.txt
+++ b/c++/lib/CMakeLists.txt
@@ -1,17 +1,11 @@
 
-include_directories( ./ )
-include_directories( ../ )
-include_directories( ../build/ )
-include(${Boost_INCLUDE_DIRS})
-
 SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1)
 
 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC " ) #always generate shared libraries with -fPIC
 
 #Library with serialization/deserialization code and kolab-containers
 add_library(kolabxml SHARED kolabformat.cpp kolabcontainers.cpp kolabnote.cpp kolabevent.cpp kolabtodo.cpp kolabjournal.cpp kolabcontact.cpp utils.cpp base64.cpp ../compiled/XMLParserWrapper.cpp ../compiled/grammar-input-stream.cxx ${SCHEMA_SOURCEFILES})
-# boost
-find_package(Boost COMPONENTS thread REQUIRED)
+
 target_link_libraries(kolabxml ${XERCES_C} ${Boost_LIBRARIES})
 
 #For the core library we can be stricter when compiling. This doesn't work with the auto generated code though.
diff --git a/c++/lib/kolabconversions.h b/c++/lib/kolabconversions.h
index 4414b49..c762044 100644
--- a/c++/lib/kolabconversions.h
+++ b/c++/lib/kolabconversions.h
@@ -38,10 +38,9 @@ using namespace Kolab::Utils;
 using namespace Kolab::Shared;
 
 template <typename T>
-std::string serializeObject(const Kolab::Note &note, const std::string prod = std::string()) {
-
+std::string serializeObject(const Kolab::Note &note, const std::string prod = std::string())
+{
     clearErrors();
-    
     try {
 
         const std::string &uid = getUID(note.uid());
@@ -79,16 +78,16 @@ std::string serializeObject(const Kolab::Note &note, const std::string prod = st
         n.summary(note.summary());
         n.description(note.description());
         n.color(note.color());
-        
+
         if (!note.customProperties().empty()) {
             BOOST_FOREACH(const Kolab::CustomProperty &a, note.customProperties()) {
                 n.x_custom().push_back(KolabXSD::CustomType(a.identifier, a.value));
             }
         }
-                    
+
         xml_schema::namespace_infomap map;
         map[""].name = KOLAB_NAMESPACE;
-        
+
         std::ostringstream ostringstream;
         KolabXSD::note(ostringstream, n, map);
         return ostringstream.str();
@@ -179,4 +178,4 @@ boost::shared_ptr<Kolab::Note> deserializeObject(const std::string& s, bool isUr
     }//Namespace
 } //Namespace
 
-#endif
\ No newline at end of file
+#endif
diff --git a/schemas/xCard.xsd b/schemas/xCard.xsd
index 429e4bf..beb7970 100644
--- a/schemas/xCard.xsd
+++ b/schemas/xCard.xsd
@@ -343,12 +343,12 @@
   </xs:complexType>
   
   <xs:simpleType name="SexType">
-        <xs:restriction base="xs:token">
-            <xs:enumeration value=""/>
-            <xs:enumeration value="M"/>
-            <xs:enumeration value="F"/>
-        </xs:restriction>
-    </xs:simpleType>
+      <xs:restriction base="xs:token">
+          <xs:enumeration value=""/>
+          <xs:enumeration value="M"/>
+          <xs:enumeration value="F"/>
+      </xs:restriction>
+  </xs:simpleType>
   
   <xs:complexType name="genderPropType">
   <xs:sequence>


commit 14928668195924f44f5307957b723798b1a8f4cb
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Mar 9 19:35:27 2012 +0100

    Added encoding of mailto uris.

diff --git a/c++/lib/uricode.h b/c++/lib/uricode.h
new file mode 100644
index 0000000..54bf542
--- /dev/null
+++ b/c++/lib/uricode.h
@@ -0,0 +1,122 @@
+// Uri encode and decode.
+// RFC1630, RFC1738, RFC2396
+
+#include <string>
+#include <assert.h>
+
+const char HEX2DEC[256] = 
+{
+    /*       0  1  2  3   4  5  6  7   8  9  A  B   C  D  E  F */
+    /* 0 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 1 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 2 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 3 */  0, 1, 2, 3,  4, 5, 6, 7,  8, 9,-1,-1, -1,-1,-1,-1,
+    
+    /* 4 */ -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 5 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 6 */ -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 7 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    
+    /* 8 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* 9 */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* A */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* B */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    
+    /* C */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* D */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* E */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
+    /* F */ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
+};
+
+std::string UriDecode(const std::string & sSrc)
+{
+    // Note from RFC1630:  "Sequences which start with a percent sign
+    // but are not followed by two hexadecimal characters (0-9, A-F) are reserved
+    // for future extension"
+    
+    const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
+    const int SRC_LEN = sSrc.length();
+    const unsigned char * const SRC_END = pSrc + SRC_LEN;
+    const unsigned char * const SRC_LAST_DEC = SRC_END - 2;   // last decodable '%' 
+    
+    char * const pStart = new char[SRC_LEN];
+    char * pEnd = pStart;
+    
+    while (pSrc < SRC_LAST_DEC)
+    {
+        if (*pSrc == '%')
+        {
+            char dec1, dec2;
+            if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)])
+                && -1 != (dec2 = HEX2DEC[*(pSrc + 2)]))
+            {
+                *pEnd++ = (dec1 << 4) + dec2;
+                pSrc += 3;
+                continue;
+            }
+        }
+        
+        *pEnd++ = *pSrc++;
+    }
+    
+    // the last 2- chars
+    while (pSrc < SRC_END)
+        *pEnd++ = *pSrc++;
+    
+    std::string sResult(pStart, pEnd);
+    delete [] pStart;
+    return sResult;
+}
+
+// Only alphanum is safe.
+const char SAFE[256] =
+{
+    /*      0 1 2 3  4 5 6 7  8 9 A B  C D E F */
+    /* 0 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* 1 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* 2 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* 3 */ 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0,
+    
+    /* 4 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
+    /* 5 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
+    /* 6 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
+    /* 7 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
+    
+    /* 8 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* 9 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* A */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* B */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    
+    /* C */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* D */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* E */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
+    /* F */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
+};
+
+std::string UriEncode(const std::string & sSrc)
+{
+    const char DEC2HEX[16 + 1] = "0123456789ABCDEF";
+    const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
+    const int SRC_LEN = sSrc.length();
+    unsigned char * const pStart = new unsigned char[SRC_LEN * 3];
+    unsigned char * pEnd = pStart;
+    const unsigned char * const SRC_END = pSrc + SRC_LEN;
+    
+    for (; pSrc < SRC_END; ++pSrc)
+    {
+        if (SAFE[*pSrc]) 
+            *pEnd++ = *pSrc;
+        else
+        {
+            // escape this char
+            *pEnd++ = '%';
+            *pEnd++ = DEC2HEX[*pSrc >> 4];
+            *pEnd++ = DEC2HEX[*pSrc & 0x0F];
+        }
+    }
+    
+    std::string sResult((char *)pStart, (char *)pEnd);
+    delete [] pStart;
+    return sResult;
+}
+
diff --git a/c++/lib/utils.cpp b/c++/lib/utils.cpp
index 11ebbe9..4140fd5 100644
--- a/c++/lib/utils.cpp
+++ b/c++/lib/utils.cpp
@@ -23,6 +23,7 @@
 #include <boost/thread.hpp>
 #include <time.h>
 #include "base64.h"
+#include "uricode.h"
 
 namespace Kolab {
     
@@ -192,12 +193,12 @@ std::string toMailto(const std::string &email, const std::string &name)
     mailto.append("<");
     mailto.append(email);
     mailto.append(">");
-    return std::string("mailto:")+mailto;
+    return std::string("mailto:")+UriEncode(mailto);
 }
 
 std::string fromMailto(const std::string &mailtoUri, std::string &name)
 {
-    const std::string &decoded = mailtoUri;
+    const std::string &decoded = UriDecode(mailtoUri);
     if (decoded.substr(0, 7).compare("mailto:")) {
         WARNING("no mailto address");
         std::cout << decoded << std::endl;





More information about the commits mailing list