All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix handling empty fields in VCARDs
@ 2010-08-26  9:48 Lukasz Pawlik
  2010-08-26 11:28 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Lukasz Pawlik @ 2010-08-26  9:48 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0001-Fix-handling-empty-fields-in-VCARDs.patch --]
[-- Type: text/x-patch, Size: 5044 bytes --]

From c9a89b18acf88ac0546ba72d0a169d9c2f18656d Mon Sep 17 00:00:00 2001
From: Lukasz Pawlik <lucas.pawlik@gmail.com>
Date: Thu, 26 Aug 2010 11:33:33 +0200
Subject: [PATCH] Fix handling empty fields in VCARDs

Previously even mandatory TEL field was not printed in VCARD if it was
empty. This patch fix this. Now tag TEL will be printed if phone number
is not set in phonebook. This patch also fix handling category string
for VCARDs in version 2.1 for url field.
---
 plugins/vcard.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/plugins/vcard.c b/plugins/vcard.c
index a20ab4d..c4c4c5a 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -256,7 +256,7 @@ static void vcard_printf_number(GString *vcards, uint8_t format,
 	vcard_printf(vcards, buf, number);
 }
 
-static void vcard_printf_tag(GString *vcards, const char *tag,
+static void vcard_printf_tag(GString *vcards, uint8_t format, const char *tag,
 					const char *category, const char *fld)
 {
 	char *separator = "", *type = "";
@@ -265,12 +265,15 @@ static void vcard_printf_tag(GString *vcards, const char *tag,
 	if (tag == NULL || strlen(tag) == 0)
 		return;
 
-	if (fld == NULL || strlen(fld) == 0)
+	if (fld == NULL || strlen(fld) == 0){
+		vcard_printf(vcards, "%s:", tag);
 		return;
+	}
 
 	if (category && strlen(category)) {
 		separator = ";";
-		type = "TYPE=";
+		if (format == FORMAT_VCARD30)
+			type = "TYPE=";
 	} else {
 		category = "";
 	}
@@ -280,8 +283,9 @@ static void vcard_printf_tag(GString *vcards, const char *tag,
 	vcard_printf(vcards, "%s:%s", buf, fld);
 }
 
-static void vcard_printf_slash_tag(GString *vcards, const char *tag,
-					const char *category, const char *fld)
+static void vcard_printf_slash_tag(GString *vcards, uint8_t format,
+					const char *tag, const char *category,
+					const char *fld)
 {
 	int len;
 	char *separator = "", *type = "";
@@ -290,12 +294,15 @@ static void vcard_printf_slash_tag(GString *vcards, const char *tag,
 	if (tag == NULL || strlen(tag) == 0)
 		return;
 
-	if (fld == NULL || (len = strlen(fld)) == 0)
+	if (fld == NULL || (len = strlen(fld)) == 0){
+		vcard_printf(vcards, "%s:", tag);
 		return;
+	}
 
 	if (category && strlen(category)) {
 		separator = ";";
-		type = "TYPE=";
+		if (format == FORMAT_VCARD30)
+			type = "TYPE=";
 	} else {
 		category = "";
 	}
@@ -314,9 +321,10 @@ static void vcard_printf_email(GString *vcards, uint8_t format,
 	char field[LEN_MAX];
 	int len = 0;
 
-	if (!address || !(len = strlen(address)))
+	if (!address || !(len = strlen(address))){
+		vcard_printf(vcards, "EMAIL:");
 		return;
-
+	}
 	switch (category){
 	case EMAIL_TYPE_HOME:
 		if (format == FORMAT_VCARD21)
@@ -358,8 +366,10 @@ 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)
+	if (org_fields_present(contact) == FALSE){
+		vcard_printf(vcards, "ORG:");
 		return;
+	}
 
 	vcard_printf(vcards, "ORG:%s;%s;%s", contact->company,
 				contact->department, contact->title);
@@ -428,9 +438,13 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 		vcard_printf_fullname(vcards, contact->fullname);
 
 	if (filter & FILTER_TEL) {
-		GSList *l;
+		GSList *l = contact->numbers;
 
-		for (l = contact->numbers; l; l = l->next) {
+		if (g_slist_length(l) == 0)
+			vcard_printf_number(vcards, format, NULL, 1,
+							TEL_TYPE_OTHER);
+
+		for (; l; l = l->next) {
 			struct phonebook_number *number = l->data;
 
 			vcard_printf_number(vcards, format, number->tel, 1,
@@ -439,9 +453,13 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	}
 
 	if (filter & FILTER_EMAIL) {
-		GSList *l;
+		GSList *l = contact->emails;
+
+		if (g_slist_length(l) == 0)
+			vcard_printf_email(vcards, format, NULL,
+							EMAIL_TYPE_OTHER);
 
-		for (l = contact->emails; l; l = l->next){
+		for (; l; l = l->next){
 			struct phonebook_email *email = l->data;
 
 			vcard_printf_email(vcards, format, email->address, email->type);
@@ -452,18 +470,18 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 		vcard_printf_adr(vcards, contact);
 
 	if (filter & FILTER_BDAY)
-		vcard_printf_tag(vcards, "BDAY", NULL, contact->birthday);
+		vcard_printf_tag(vcards, format, "BDAY", NULL, contact->birthday);
 
 	if (filter & FILTER_NICKNAME)
-		vcard_printf_slash_tag(vcards, "NICKNAME", NULL,
+		vcard_printf_slash_tag(vcards, format, "NICKNAME", NULL,
 							contact->nickname);
 
 	if (filter & FILTER_URL)
-		vcard_printf_slash_tag(vcards, "URL", "INTERNET",
+		vcard_printf_slash_tag(vcards, format, "URL", "INTERNET",
 							contact->website);
 
 	if (filter & FILTER_PHOTO)
-		vcard_printf_tag(vcards, "PHOTO", NULL, contact->photo);
+		vcard_printf_tag(vcards, format, "PHOTO", NULL, contact->photo);
 
 	if (filter & FILTER_ORG)
 		vcard_printf_org(vcards, contact);
-- 
1.7.0.4


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

* Re: [PATCH] Fix handling empty fields in VCARDs
  2010-08-26  9:48 [PATCH] Fix handling empty fields in VCARDs Lukasz Pawlik
@ 2010-08-26 11:28 ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-08-26 11:28 UTC (permalink / raw)
  To: Lukasz Pawlik; +Cc: linux-bluetooth

Hi Lukasz,

On Thu, Aug 26, 2010, Lukasz Pawlik wrote:
> From c9a89b18acf88ac0546ba72d0a169d9c2f18656d Mon Sep 17 00:00:00 2001
> From: Lukasz Pawlik <lucas.pawlik@gmail.com>
> Date: Thu, 26 Aug 2010 11:33:33 +0200
> Subject: [PATCH] Fix handling empty fields in VCARDs
> 
> Previously even mandatory TEL field was not printed in VCARD if it was
> empty. This patch fix this. Now tag TEL will be printed if phone number
> is not set in phonebook. This patch also fix handling category string
> for VCARDs in version 2.1 for url field.
> ---
>  plugins/vcard.c |   54 ++++++++++++++++++++++++++++++++++++------------------
>  1 files changed, 36 insertions(+), 18 deletions(-)

Thanks. The patch is now upstream. Btw, it's written vCard and not VCARD
(I fixed this for you manually).

Johan

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

* Re: [PATCH] Fix handling empty fields in VCARDs
  2010-08-26  7:45 Lukasz Pawlik
@ 2010-08-26  8:15 ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-08-26  8:15 UTC (permalink / raw)
  To: Lukasz Pawlik; +Cc: linux-bluetooth

Hi Lukasz,

> From 4bb29cdaf4a9923ab62973c38914ebb67f718d64 Mon Sep 17 00:00:00 2001
> From: Lukasz Pawlik <lucas.pawlik@gmail.com>
> Date: Thu, 26 Aug 2010 09:10:26 +0200
> Subject: [PATCH] Fix handling empty fields in VCARDs
> 
> Previously even mandatory TEL field was not printed in VCARD if it was
> empty. This patch fix this. Now tag TEL will be printed if phone number
> is not set in phonebook. This patch also fix handling category string
> for VCARDs in version 2.1 for url field.
> ---
>  plugins/vcard.c |   51 ++++++++++++++++++++++++++++++++-------------------
>  1 files changed, 32 insertions(+), 19 deletions(-)

In general the patch seems fine, but you need to fix your editor
settings when dealing with BlueZ code. It seems like you're using spaces
for indentation when the coding style is tabs-only:

> -		for (l = contact->numbers; l; l = l->next) {
> +                if (g_slist_length(l) == 0)
> +                        vcard_printf_number(vcards, format, NULL, 1,
> +                                                        TEL_TYPE_OTHER);

All of the above three added lines are indented with spaces.

> +		for (; l; l = l->next) {

This added line is indented with tabs. How did you manage to get your
editor to produce such mixed results?

> +		if (g_slist_length(l) == 0)
> +                        vcard_printf_email(vcards, format, NULL,
> +                                                        EMAIL_TYPE_OTHER);

The first line is tabs but the two others use spaces!?

> -		for (l = contact->emails; l; l = l->next){
> +                for (; l; l = l->next){

Again spaces here.

Please enable whitespace visualization and use proper editor settings to
avoid these issues in the future. Thanks.

Johan

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

* [PATCH] Fix handling empty fields in VCARDs
@ 2010-08-26  7:45 Lukasz Pawlik
  2010-08-26  8:15 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Lukasz Pawlik @ 2010-08-26  7:45 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0001-Fix-handling-empty-fields-in-VCARDs.patch --]
[-- Type: text/x-patch, Size: 5038 bytes --]

From 4bb29cdaf4a9923ab62973c38914ebb67f718d64 Mon Sep 17 00:00:00 2001
From: Lukasz Pawlik <lucas.pawlik@gmail.com>
Date: Thu, 26 Aug 2010 09:10:26 +0200
Subject: [PATCH] Fix handling empty fields in VCARDs

Previously even mandatory TEL field was not printed in VCARD if it was
empty. This patch fix this. Now tag TEL will be printed if phone number
is not set in phonebook. This patch also fix handling category string
for VCARDs in version 2.1 for url field.
---
 plugins/vcard.c |   51 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/plugins/vcard.c b/plugins/vcard.c
index a20ab4d..a163d1b 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -256,7 +256,7 @@ static void vcard_printf_number(GString *vcards, uint8_t format,
 	vcard_printf(vcards, buf, number);
 }
 
-static void vcard_printf_tag(GString *vcards, const char *tag,
+static void vcard_printf_tag(GString *vcards, uint8_t format, const char *tag,
 					const char *category, const char *fld)
 {
 	char *separator = "", *type = "";
@@ -265,9 +265,10 @@ static void vcard_printf_tag(GString *vcards, const char *tag,
 	if (tag == NULL || strlen(tag) == 0)
 		return;
 
-	if (fld == NULL || strlen(fld) == 0)
+	if (fld == NULL || strlen(fld) == 0){
+		vcard_printf(vcards, "%s:", tag);
 		return;
-
+	}
 	if (category && strlen(category)) {
 		separator = ";";
 		type = "TYPE=";
@@ -280,8 +281,9 @@ static void vcard_printf_tag(GString *vcards, const char *tag,
 	vcard_printf(vcards, "%s:%s", buf, fld);
 }
 
-static void vcard_printf_slash_tag(GString *vcards, const char *tag,
-					const char *category, const char *fld)
+static void vcard_printf_slash_tag(GString *vcards, uint8_t format,
+					const char *tag, const char *category,
+					const char *fld)
 {
 	int len;
 	char *separator = "", *type = "";
@@ -290,9 +292,10 @@ static void vcard_printf_slash_tag(GString *vcards, const char *tag,
 	if (tag == NULL || strlen(tag) == 0)
 		return;
 
-	if (fld == NULL || (len = strlen(fld)) == 0)
+	if (fld == NULL || (len = strlen(fld)) == 0){
+		vcard_printf(vcards, "%s:", tag);
 		return;
-
+	}
 	if (category && strlen(category)) {
 		separator = ";";
 		type = "TYPE=";
@@ -314,9 +317,10 @@ static void vcard_printf_email(GString *vcards, uint8_t format,
 	char field[LEN_MAX];
 	int len = 0;
 
-	if (!address || !(len = strlen(address)))
+	if (!address || !(len = strlen(address))){
+		vcard_printf(vcards, "EMAIL:");
 		return;
-
+	}
 	switch (category){
 	case EMAIL_TYPE_HOME:
 		if (format == FORMAT_VCARD21)
@@ -358,9 +362,10 @@ 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)
+	if (org_fields_present(contact) == FALSE){
+		vcard_printf(vcards, "ORG:");
 		return;
-
+	}
 	vcard_printf(vcards, "ORG:%s;%s;%s", contact->company,
 				contact->department, contact->title);
 }
@@ -428,9 +433,13 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 		vcard_printf_fullname(vcards, contact->fullname);
 
 	if (filter & FILTER_TEL) {
-		GSList *l;
+		GSList *l = contact->numbers;
 
-		for (l = contact->numbers; l; l = l->next) {
+                if (g_slist_length(l) == 0)
+                        vcard_printf_number(vcards, format, NULL, 1,
+                                                        TEL_TYPE_OTHER);
+
+		for (; l; l = l->next) {
 			struct phonebook_number *number = l->data;
 
 			vcard_printf_number(vcards, format, number->tel, 1,
@@ -439,9 +448,13 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	}
 
 	if (filter & FILTER_EMAIL) {
-		GSList *l;
+		GSList *l = contact->emails;
+
+		if (g_slist_length(l) == 0)
+                        vcard_printf_email(vcards, format, NULL,
+                                                        EMAIL_TYPE_OTHER);
 
-		for (l = contact->emails; l; l = l->next){
+                for (; l; l = l->next){
 			struct phonebook_email *email = l->data;
 
 			vcard_printf_email(vcards, format, email->address, email->type);
@@ -452,18 +465,18 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 		vcard_printf_adr(vcards, contact);
 
 	if (filter & FILTER_BDAY)
-		vcard_printf_tag(vcards, "BDAY", NULL, contact->birthday);
+		vcard_printf_tag(vcards, format, "BDAY", NULL, contact->birthday);
 
 	if (filter & FILTER_NICKNAME)
-		vcard_printf_slash_tag(vcards, "NICKNAME", NULL,
+		vcard_printf_slash_tag(vcards, format, "NICKNAME", NULL,
 							contact->nickname);
 
 	if (filter & FILTER_URL)
-		vcard_printf_slash_tag(vcards, "URL", "INTERNET",
+		vcard_printf_slash_tag(vcards, format, "URL", "INTERNET",
 							contact->website);
 
 	if (filter & FILTER_PHOTO)
-		vcard_printf_tag(vcards, "PHOTO", NULL, contact->photo);
+		vcard_printf_tag(vcards, format, "PHOTO", NULL, contact->photo);
 
 	if (filter & FILTER_ORG)
 		vcard_printf_org(vcards, contact);
-- 
1.7.0.4


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

end of thread, other threads:[~2010-08-26 11:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-26  9:48 [PATCH] Fix handling empty fields in VCARDs Lukasz Pawlik
2010-08-26 11:28 ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2010-08-26  7:45 Lukasz Pawlik
2010-08-26  8:15 ` 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.