From aceac1923f45b49f1ca30f0c582d4e7ca8b9522b Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Mon, 10 May 2010 11:05:22 -0300 Subject: [PATCH] obexd: Add support for vCard 2.1 to the Tracker backend --- obexd/plugins/phonebook-tracker.c | 2 +- obexd/plugins/vcard.c | 20 +++++++++++++++----- obexd/plugins/vcard.h | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c index 9453cd7ce..894d781de 100644 --- a/obexd/plugins/phonebook-tracker.c +++ b/obexd/plugins/phonebook-tracker.c @@ -496,7 +496,7 @@ static void pull_contacts(char **reply, int num_fields, void *user_data) contact->suffix = g_strdup(reply[6]); contact->email = g_strdup(reply[7]); - phonebook_add_contact(vcards, contact, params->filter); + phonebook_add_contact(vcards, contact, params->filter, params->format); phonebook_contact_free(contact); return; diff --git a/obexd/plugins/vcard.c b/obexd/plugins/vcard.c index a9d464f27..c0a5f85bc 100644 --- a/obexd/plugins/vcard.c +++ b/obexd/plugins/vcard.c @@ -66,6 +66,9 @@ #define FILTER_SORT_STRING (1 << 27) #define FILTER_X_IRMC_CALL_DATETIME (1 << 28) +#define FORMAT_VCARD21 0x00 +#define FORMAT_VCARD30 0x01 + /* according to RFC 2425, the output string may need folding */ static void vcard_printf(GString *str, const char *fmt, ...) { @@ -120,10 +123,14 @@ static void add_slash(char *dest, const char *src, int len_max, int len) return; } -static void vcard_printf_begin(GString *vcards) +static void vcard_printf_begin(GString *vcards, uint8_t format) { vcard_printf(vcards, "BEGIN:VCARD"); - vcard_printf(vcards, "VERSION:3.0"); + + if (format == FORMAT_VCARD30) + vcard_printf(vcards, "VERSION:3.0"); + else if (format == FORMAT_VCARD21) + vcard_printf(vcards, "VERSION:2.1"); } static void vcard_printf_name(GString *vcards, @@ -198,7 +205,7 @@ static void vcard_printf_end(GString *vcards) } void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact, - uint64_t filter) + uint64_t filter, uint8_t format) { /* There's really nothing to do */ if ((contact->tel == NULL || contact->tel[0] == '\0') && @@ -206,9 +213,12 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact, contact->fullname[0] == '\0')) return; - filter |= (FILTER_VERSION | FILTER_FN | FILTER_N | FILTER_TEL); + if (format == FORMAT_VCARD30) + filter |= (FILTER_VERSION | FILTER_FN | FILTER_N | FILTER_TEL); + else if (format == FORMAT_VCARD21) + filter |= (FILTER_VERSION | FILTER_N | FILTER_TEL); - vcard_printf_begin(vcards); + vcard_printf_begin(vcards, format); if (filter & FILTER_FN) { if (contact->fullname == NULL || contact->fullname[0] == '\0') diff --git a/obexd/plugins/vcard.h b/obexd/plugins/vcard.h index f015e9480..5362a66d6 100644 --- a/obexd/plugins/vcard.h +++ b/obexd/plugins/vcard.h @@ -40,6 +40,6 @@ struct phonebook_contact { }; void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact, - uint64_t filter); + uint64_t filter, uint8_t format); void phonebook_contact_free(struct phonebook_contact *contact); -- 2.47.3