From 766f8acf743a7e678ad02a8e5d084309c36702e2 Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Tue, 31 Dec 2019 13:21:06 +0100 Subject: [PATCH] Support private extensions (X-PRIVATE) Signed-off-by: Michael Rasmussen --- example/vcard-2.1.vcf | 1 + example/vcard-3.0.vcf | 1 + example/vcard-4.0.vcf | 2 +- example/vcard-all-versions.vcf | 3 +++ src/vcard-parser.c | 29 +++++++++-------------------- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/example/vcard-2.1.vcf b/example/vcard-2.1.vcf index c7d858f..55fe080 100644 --- a/example/vcard-2.1.vcf +++ b/example/vcard-2.1.vcf @@ -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 diff --git a/example/vcard-3.0.vcf b/example/vcard-3.0.vcf index b2ba355..1475359 100644 --- a/example/vcard-3.0.vcf +++ b/example/vcard-3.0.vcf @@ -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 diff --git a/example/vcard-4.0.vcf b/example/vcard-4.0.vcf index 1b585e5..1f224ab 100644 --- a/example/vcard-4.0.vcf +++ b/example/vcard-4.0.vcf @@ -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 diff --git a/example/vcard-all-versions.vcf b/example/vcard-all-versions.vcf index c6bf44d..ad4f358 100644 --- a/example/vcard-all-versions.vcf +++ b/example/vcard-all-versions.vcf @@ -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 diff --git a/src/vcard-parser.c b/src/vcard-parser.c index 056adbd..e35dba8 100644 --- a/src/vcard-parser.c +++ b/src/vcard-parser.c @@ -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]); -- 2.39.5