All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd v2] Do not send empty vCard attributes
@ 2011-07-11  8:37 Slawomir Bochenski
  2011-07-11 12:27 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Slawomir Bochenski @ 2011-07-11  8:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Johan Hedberg, Slawomir Bochenski

PBAP specification v1.1, chap. 5.1.4.1 and 5.4.4.1 states that
non-mandatory attributes shall be sent only when their value is not NULL.
In case of vCards this can be simply understood as non-empty, therefore
the patch makes phonebook_add_contact add only mandatory attributes for
specified vCard version as well as those for which values are of non-zero
length.
---
v2: Fix conflicts coming from 1666935c5ae68bf645ca10b18303378adf77f599

 plugins/vcard.c |   31 +++++++++----------------------
 1 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/plugins/vcard.c b/plugins/vcard.c
index d6df360..76e760b 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -398,10 +398,8 @@ static gboolean org_fields_present(struct phonebook_contact *contact)
 static void vcard_printf_org(GString *vcards,
 					struct phonebook_contact *contact)
 {
-	if (org_fields_present(contact) == FALSE) {
-		vcard_printf(vcards, "ORG:");
+	if (org_fields_present(contact) == FALSE)
 		return;
-	}
 
 	vcard_printf(vcards, "ORG:%s;%s", contact->company,
 				contact->department);
@@ -505,13 +503,14 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 
 	vcard_printf_begin(vcards, format);
 
-	if (filter & FILTER_UID)
+	if (filter & FILTER_UID && *contact->uid)
 		vcard_printf_tag(vcards, format, "UID", NULL, contact->uid);
 
 	if (filter & FILTER_N)
 		vcard_printf_name(vcards, contact);
 
-	if (filter & FILTER_FN)
+	if (filter & FILTER_FN && (*contact->fullname ||
+					format == FORMAT_VCARD30))
 		vcard_printf_fullname(vcards, contact->fullname);
 
 	if (filter & FILTER_TEL) {
@@ -532,10 +531,6 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	if (filter & FILTER_EMAIL) {
 		GSList *l = contact->emails;
 
-		if (g_slist_length(l) == 0)
-			vcard_printf_email(vcards, format, NULL,
-							FIELD_TYPE_OTHER);
-
 		for (; l; l = l->next) {
 			struct phonebook_field *email = l->data;
 			vcard_printf_email(vcards, format, email->text,
@@ -546,10 +541,6 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	if (filter & FILTER_ADR) {
 		GSList *l = contact->addresses;
 
-		if (g_slist_length(l) == 0)
-			vcard_printf_address(vcards, format, NULL,
-							FIELD_TYPE_OTHER);
-
 		for (; l; l = l->next) {
 			struct phonebook_field *addr = l->data;
 			vcard_printf_address(vcards, format, addr->text,
@@ -557,38 +548,34 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 		}
 	}
 
-	if (filter & FILTER_BDAY)
+	if (filter & FILTER_BDAY && *contact->birthday)
 		vcard_printf_tag(vcards, format, "BDAY", NULL,
 						contact->birthday);
 
-	if (filter & FILTER_NICKNAME)
+	if (filter & FILTER_NICKNAME && *contact->nickname)
 		vcard_printf_slash_tag(vcards, format, "NICKNAME", NULL,
 							contact->nickname);
 
 	if (filter & FILTER_URL) {
 		GSList *l = contact->urls;
 
-		if (g_slist_length(l) == 0)
-			vcard_printf_url(vcards, format, NULL,
-							FIELD_TYPE_OTHER);
-
 		for (; l; l = l->next) {
 			struct phonebook_field *url = l->data;
 			vcard_printf_url(vcards, format, url->text, url->type);
 		}
 	}
 
-	if (filter & FILTER_PHOTO)
+	if (filter & FILTER_PHOTO && *contact->photo)
 		vcard_printf_tag(vcards, format, "PHOTO", NULL,
 							contact->photo);
 
 	if (filter & FILTER_ORG)
 		vcard_printf_org(vcards, contact);
 
-	if (filter & FILTER_ROLE)
+	if (filter & FILTER_ROLE && *contact->role)
 		vcard_printf_tag(vcards, format, "ROLE", NULL, contact->role);
 
-	if (filter & FILTER_TITLE)
+	if (filter & FILTER_TITLE && *contact->title)
 		vcard_printf_tag(vcards, format, "TITLE", NULL, contact->title);
 
 	if (filter & FILTER_X_IRMC_CALL_DATETIME)
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH obexd v2] Do not send empty vCard attributes
  2011-07-11  8:37 [PATCH obexd v2] Do not send empty vCard attributes Slawomir Bochenski
@ 2011-07-11 12:27 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2011-07-11 12:27 UTC (permalink / raw)
  To: Slawomir Bochenski; +Cc: linux-bluetooth

Hi Slawek,

On Mon, Jul 11, 2011, Slawomir Bochenski wrote:
> PBAP specification v1.1, chap. 5.1.4.1 and 5.4.4.1 states that
> non-mandatory attributes shall be sent only when their value is not NULL.
> In case of vCards this can be simply understood as non-empty, therefore
> the patch makes phonebook_add_contact add only mandatory attributes for
> specified vCard version as well as those for which values are of non-zero
> length.
> ---
> v2: Fix conflicts coming from 1666935c5ae68bf645ca10b18303378adf77f599

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-11 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11  8:37 [PATCH obexd v2] Do not send empty vCard attributes Slawomir Bochenski
2011-07-11 12:27 ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.