From c8e98708ea3a8b6462de538ccd8cecfa22797ea2 Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Mon, 19 Apr 2010 18:37:34 -0300 Subject: [PATCH] obexd: Add support to all fields required by vCard 3.0 This adds support to dealing with FULLNAME (FN) and the filter application parameter. --- obexd/plugins/phonebook-tracker.c | 27 +++++++----- obexd/plugins/vcard.c | 68 +++++++++++++++++++++++++++---- obexd/plugins/vcard.h | 3 +- 3 files changed, 78 insertions(+), 20 deletions(-) diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c index efa7e3fd8..f88eb6c85 100644 --- a/obexd/plugins/phonebook-tracker.c +++ b/obexd/plugins/phonebook-tracker.c @@ -43,12 +43,13 @@ #define TRACKER_DEFAULT_CONTACT_ME "" #define CONTACTS_QUERY_ALL \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ "?suffix ?email " \ "WHERE { " \ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -70,7 +71,7 @@ "}" #define MISSED_CALLS_QUERY \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ "?suffix ?email " \ "WHERE { " \ "?call a nmo:Call ; " \ @@ -80,6 +81,7 @@ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -106,7 +108,7 @@ "}" #define INCOMING_CALLS_QUERY \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ "?suffix ?email " \ "WHERE { " \ "?call a nmo:Call ; " \ @@ -115,6 +117,7 @@ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -139,7 +142,7 @@ "}" #define OUTGOING_CALLS_QUERY \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ "?suffix ?email " \ "WHERE { " \ "?call a nmo:Call ; " \ @@ -148,6 +151,7 @@ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -172,7 +176,7 @@ "}" #define COMBINED_CALLS_QUERY \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ "?suffix ?email " \ "WHERE { " \ "{ " \ @@ -182,6 +186,7 @@ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -194,6 +199,7 @@ "?contact a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { ?contact nco:hasEmailAddress ?email } " \ "OPTIONAL { ?contact nco:nameAdditional ?additional } " \ @@ -231,12 +237,13 @@ #define CONTACTS_QUERY_FROM_URI \ - "SELECT ?phone ?family ?given ?additional ?prefix " \ + "SELECT ?phone ?fullname ?family ?given ?additional ?prefix " \ " ?suffix ?email " \ "WHERE { " \ "<%s> a nco:PersonContact ; " \ "nco:nameFamily ?family ; " \ "nco:nameGiven ?given ; " \ + "nco:fullname ?fullname ; " \ "nco:hasPhoneNumber ?phone . " \ "OPTIONAL { <%s> nco:hasEmailAddress ?email } " \ "OPTIONAL { <%s> nco:nameAdditional ?additional } " \ @@ -478,11 +485,11 @@ static void pull_contacts(char **reply, int num_fields, void *user_data) if (data->index < params->liststartoffset || data->index > last_index) return; - formatted = g_strdup_printf("%s;%s;%s;%s;%s", reply[1], reply[2], - reply[3], reply[4], reply[5]); + formatted = g_strdup_printf("%s;%s;%s;%s;%s", reply[2], reply[3], + reply[4], reply[5], reply[6]); phonebook_add_entry(vcards, reply[0], TEL_TYPE_HOME, formatted, - reply[6]); + reply[6], reply[1], params->filter); g_free(formatted); @@ -619,7 +626,7 @@ int phonebook_pull(const char *name, const struct apparam_field *params, data->user_data = user_data; data->cb = cb; - return query_tracker(query, 7, pull_contacts, data); + return query_tracker(query, 8, pull_contacts, data); } int phonebook_get_entry(const char *folder, const char *id, diff --git a/obexd/plugins/vcard.c b/obexd/plugins/vcard.c index 41a099507..3b833ef9b 100644 --- a/obexd/plugins/vcard.c +++ b/obexd/plugins/vcard.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,36 @@ #define PHONEBOOK_FLAG_CACHED 0x1 +#define FILTER_VERSION (1 << 0) +#define FILTER_FN (1 << 1) +#define FILTER_N (1 << 2) +#define FILTER_PHOTO (1 << 3) +#define FILTER_BDAY (1 << 4) +#define FILTER_ADR (1 << 5) +#define FILTER_LABEL (1 << 6) +#define FILTER_TEL (1 << 7) +#define FILTER_EMAIL (1 << 8) +#define FILTER_MAILER (1 << 9) +#define FILTER_TZ (1 << 10) +#define FILTER_GEO (1 << 11) +#define FILTER_TITLE (1 << 12) +#define FILTER_ROLE (1 << 13) +#define FILTER_LOGO (1 << 14) +#define FILTER_AGENT (1 << 15) +#define FILTER_ORG (1 << 16) +#define FILTER_NOTE (1 << 17) +#define FILTER_REV (1 << 18) +#define FILTER_SOUND (1 << 19) +#define FILTER_URL (1 << 20) +#define FILTER_UID (1 << 21) +#define FILTER_KEY (1 << 22) +#define FILTER_NICKNAME (1 << 23) +#define FILTER_CATEGORIES (1 << 24) +#define FILTER_PROID (1 << 25) +#define FILTER_CLASS (1 << 26) +#define FILTER_SORT_STRING (1 << 27) +#define FILTER_X_IRMC_CALL_DATETIME (1 << 28) + /* according to RFC 2425, the output string may need folding */ static void vcard_printf(GString *str, const char *fmt, ...) { @@ -95,13 +126,20 @@ static void vcard_printf_begin(GString *vcards) vcard_printf(vcards, "VERSION:3.0"); } -static void vcard_printf_text(GString *vcards, const char *text) +static void vcard_printf_fullname(GString *vcards, const char *text) { char field[LEN_MAX]; add_slash(field, text, LEN_MAX, strlen(text)); vcard_printf(vcards, "FN:%s", field); } +static void vcard_printf_name(GString *vcards, const char *text) +{ + char field[LEN_MAX]; + add_slash(field, text, LEN_MAX, strlen(text)); + vcard_printf(vcards, "N:%s", field); +} + static void vcard_printf_number(GString *vcards, const char *number, int type, enum phonebook_number_type category) { @@ -159,21 +197,33 @@ static void vcard_printf_end(GString *vcards) } void phonebook_add_entry(GString *vcards, const char *number, int type, - const char *text, const char *email) + const char *name, const char *fullname, + const char *email, uint64_t filter) { /* There's really nothing to do */ if ((number == NULL || number[0] == '\0') && - (text == NULL || text[0] == '\0')) + (fullname == NULL || fullname[0] == '\0')) return; + filter |= (FILTER_VERSION | FILTER_FN | FILTER_N | FILTER_TEL); + vcard_printf_begin(vcards); - if (text == NULL || text[0] == '\0') - vcard_printf_text(vcards, number); - else - vcard_printf_text(vcards, text); + if (filter & FILTER_FN) { + if (fullname == NULL || fullname[0] == '\0') + vcard_printf_fullname(vcards, number); + else + vcard_printf_fullname(vcards, fullname); + } + + if (filter & FILTER_TEL) + vcard_printf_number(vcards, number, type, TEL_TYPE_OTHER); + + if (filter & FILTER_N) + vcard_printf_name(vcards, name); + + if (filter & FILTER_EMAIL) + vcard_printf_email(vcards, email); - vcard_printf_email(vcards, email); - vcard_printf_number(vcards, number, type, TEL_TYPE_OTHER); vcard_printf_end(vcards); } diff --git a/obexd/plugins/vcard.h b/obexd/plugins/vcard.h index 7b47984f8..d9171ccd6 100644 --- a/obexd/plugins/vcard.h +++ b/obexd/plugins/vcard.h @@ -28,4 +28,5 @@ enum phonebook_number_type { }; void phonebook_add_entry(GString *vcards, const char *number, int type, - const char *text, const char *email); + const char *name, const char *fullname, + const char *email, uint64_t filter); -- 2.47.3