]> git.datanom.net - vcard-parser.git/commitdiff
Support private extensions (X-PRIVATE)
authorMichael Rasmussen <mir@datanom.net>
Tue, 31 Dec 2019 12:21:06 +0000 (13:21 +0100)
committerMichael Rasmussen <mir@datanom.net>
Tue, 31 Dec 2019 12:21:06 +0000 (13:21 +0100)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
example/vcard-2.1.vcf
example/vcard-3.0.vcf
example/vcard-4.0.vcf
example/vcard-all-versions.vcf
src/vcard-parser.c

index c7d858fb3d737fe502857db32726eb019a9da828..55fe080a5269dd2efaa4404b245ddf7e8860e6c0 100644 (file)
@@ -16,4 +16,5 @@ LABEL;HOME;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:42 Plantation St.=0D=0A=
  Baytown, LA 30314=0D=0AUnited States of America
 EMAIL:forrestgump@example.com
 REV:20080424T195243Z
+X-TEST:Test for private extension
 END:VCARD
index b2ba355d3dc710d18024ca1fdd2834d13d12d88f..1475359d16d980a2014af0f744111c4a3baf8507 100644 (file)
@@ -13,4 +13,5 @@ ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
 LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of America
 EMAIL:forrestgump@example.com
 REV:2008-04-24T19:52:43Z
+X-TEST:Test for private extension
 END:VCARD
index 1b585e5be7848eef75c2b314fa1637b6df8da7eb..1f224ab63186c1174c44c73ae0491e613516a94d 100644 (file)
@@ -11,6 +11,6 @@ ADR;TYPE=WORK;PREF=1;LABEL="100 Waters Edge\nBaytown\, LA 30314\nUnited States o
 ADR;TYPE=HOME;LABEL="42 Plantation St.\nBaytown\, LA 30314\nUnited States of America":;;42 Plantation St.;Baytown;LA;30314;United States of America
 EMAIL:forrestgump@example.com
 REV:20080424T195243Z
-x-qq:21588891
+X-TEST:Test for private extension
 END:VCARD
 
index c6bf44df7655cb112901d4b7257deaf527a86922..ad4f3589b92ab127ea2e8acafba7d463b9422ed5 100644 (file)
@@ -16,6 +16,7 @@ LABEL;HOME;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:42 Plantation St.=0D=0A=
  Baytown, LA 30314=0D=0AUnited States of America
 EMAIL:forrestgump@example.com
 REV:20080424T195243Z
+X-TEST:Test for private extension
 END:VCARD
 
 BEGIN:VCARD
@@ -38,6 +39,7 @@ LABEL;HOME;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:42 Plantation St.=0D=0A=
 EMAIL:forrestgump@example.com
 REV:20080424T195243Z
 SORT-STRING:alibaba
+X-TEST:Test for private extension
 END:VCARD
 
 BEGIN:VCARD
@@ -58,4 +60,5 @@ REV:20111228T014034Z
 ORG-DIRECTORY:test af ORG-DIRECTORY
 SORT-STRING:alibaba
 VERSION:4.0
+X-TEST:Test for private extension
 END:VCARD
index 056adbd6191f4840d1446cdf3a1951ccc52d0c5b..e35dba85f9cdc4075c20da5b736f1aee81b895ba 100644 (file)
@@ -89,23 +89,6 @@ static void vcard_property_free(gpointer data) {
 }
 
 static Property get_property(const gchar* property) {
-/*     Property p = VCARD_PROPERTIES;
-       gchar* lookup = NULL;
-
-       if (g_strcmp0("ORG-DIRECTORY", property) == 0)
-               lookup = g_strdup("ORG_DIRECTORY");
-       else if (g_strcmp0("SORT-STRING", property) == 0)
-               lookup = g_strdup("SORT_STRING");
-       else
-               lookup = g_strdup(property);
-
-       for (int i = 0; i < VCARD_PROPERTIES; i++) {
-               if (g_strcmp0(Properties[i], lookup) == 0) {
-                       p = i;
-                       break;
-               }
-       }
-       g_free(lookup);*/
        for (Property i = N; i < VCARD_PROPERTIES; i++) {
                if (g_strcmp0(Properties[i], property) == 0) return i;
        }
@@ -122,7 +105,7 @@ static gboolean check_support(Property property, VCardVersion version) {
                support = property <= IMPP ? TRUE : FALSE;
        } else if (version == VCARD_VERSION_4_0) {
                support = property <= VCARD_PROPERTIES ? TRUE : FALSE;
-       };
+       }
 
        return support;
 }
@@ -235,6 +218,7 @@ static void init_g_hash_table(GHashTable** ht, VCardVersion version) {
 static VCardParserResponse vcard_parse(gchar** text, VCardVersion version, GHashTable** vcard) {
        VCardParserResponse r = VCARD_PARSER_ERROR;
        guint l = g_strv_length(text);
+       gboolean support;
 
        for (guint i = 0; i < l; i++) {
                gchar** b = g_strsplit(text[i], ":", 2);
@@ -252,8 +236,13 @@ static VCardParserResponse vcard_parse(gchar** text, VCardVersion version, GHash
                                g_strfreev(b);
                                continue;
                }
-               Property property = get_property(c[0]);
-               if (check_support(property, version)) {
+               if (g_str_has_prefix(c[0], "X-")) {
+                       support = TRUE;
+               } else {
+                       Property property = get_property(c[0]);
+                       support = check_support(property, version);
+               }
+               if (support) {
                        GSList* value = g_hash_table_lookup(*vcard, c[0]);
                        VCardProperty* vp = g_new(VCardProperty, 1);
                        vp->name = g_strdup(b[0]);
This page took 0.039906 seconds and 5 git commands to generate.