linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string
@ 2010-08-02 21:29 Marcel Mol
  2010-08-02 21:57 ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Marcel Mol @ 2010-08-02 21:29 UTC (permalink / raw)
  To: linux-bluetooth

evcard_to_string() only took one TEL attrib from a vcard. But
multiple TEL attribs are supported. This patch will convert
all TEL attribs to strings.
---
 plugins/phonebook-ebook.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 089b956..d2482c0 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -97,6 +97,7 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 							uint64_t filter)
 {
 	EVCard *evcard2;
+	GList *l;
 	char *vcard;
 	unsigned int i;
 
@@ -109,18 +110,21 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 	 */
 	filter = format == EVC_FORMAT_VCARD_30 ? filter | 0x87: filter | 0x85;
 
+	l = e_vcard_get_attributes(evcard);
 	evcard2 = e_vcard_new();
-	for (i = 0; i < 29; i++) {
-		EVCardAttribute *attrib;
-
-		if (!(filter & (1 << i)))
-			continue;
-
-		attrib = e_vcard_get_attribute(evcard, attribute_mask[i]);
+	for (; l; l = g_list_next(l)) {
+		EVCardAttribute *attrib = l->data;
 		if (!attrib)
 			continue;
-
-		e_vcard_add_attribute(evcard2, e_vcard_attribute_copy(attrib));
+		const char *name = e_vcard_attribute_get_name(attrib);
+		for (i = 0; attribute_mask[i] != NULL; i++) {
+			if (!(filter & (1 << i)))
+				continue;
+			if (g_strcmp(name, attribute_mask[i]) != 0)
+				continue;
+			e_vcard_add_attribute(evcard2,
+						e_vcard_attribute_copy(attrib));
+		}
 	}
 
 	vcard = e_vcard_to_string(evcard2, format);
-- 
1.7.2


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

* [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string
@ 2010-08-02 21:29 Marcel Mol
  0 siblings, 0 replies; 5+ messages in thread
From: Marcel Mol @ 2010-08-02 21:29 UTC (permalink / raw)
  To: linux-bluetooth

evcard_to_string() only took one TEL attrib from a vcard. But
multiple TEL attribs are supported. This patch will convert
all TEL attribs to strings.
---
 plugins/phonebook-ebook.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 089b956..d2482c0 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -97,6 +97,7 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 							uint64_t filter)
 {
 	EVCard *evcard2;
+	GList *l;
 	char *vcard;
 	unsigned int i;
 
@@ -109,18 +110,21 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 	 */
 	filter = format == EVC_FORMAT_VCARD_30 ? filter | 0x87: filter | 0x85;
 
+	l = e_vcard_get_attributes(evcard);
 	evcard2 = e_vcard_new();
-	for (i = 0; i < 29; i++) {
-		EVCardAttribute *attrib;
-
-		if (!(filter & (1 << i)))
-			continue;
-
-		attrib = e_vcard_get_attribute(evcard, attribute_mask[i]);
+	for (; l; l = g_list_next(l)) {
+		EVCardAttribute *attrib = l->data;
 		if (!attrib)
 			continue;
-
-		e_vcard_add_attribute(evcard2, e_vcard_attribute_copy(attrib));
+		const char *name = e_vcard_attribute_get_name(attrib);
+		for (i = 0; attribute_mask[i] != NULL; i++) {
+			if (!(filter & (1 << i)))
+				continue;
+			if (g_strcmp0(name, attribute_mask[i]) != 0)
+				continue;
+			e_vcard_add_attribute(evcard2,
+						e_vcard_attribute_copy(attrib));
+		}
 	}
 
 	vcard = e_vcard_to_string(evcard2, format);
-- 
1.7.2


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

* Re: [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string
  2010-08-02 21:29 [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string Marcel Mol
@ 2010-08-02 21:57 ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2010-08-02 21:57 UTC (permalink / raw)
  To: Marcel Mol; +Cc: linux-bluetooth

On Mon, Aug 02, 2010, Marcel Mol wrote:
> +	for (; l; l = g_list_next(l)) {
> +		EVCardAttribute *attrib = l->data;
>  		if (!attrib)
>  			continue;

Add an empty line after variable declarations.

> -
> -		e_vcard_add_attribute(evcard2, e_vcard_attribute_copy(attrib));
> +		const char *name = e_vcard_attribute_get_name(attrib);

plugins/phonebook.c: In function ‘evcard_to_string’:
plugins/phonebook.c:119: error: ISO C90 forbids mixed declarations and code
make[1]: *** [plugins/phonebook.o] Error 1
make: *** [all] Error 2

> +		for (i = 0; attribute_mask[i] != NULL; i++) {
> +			if (!(filter & (1 << i)))
> +				continue;
> +			if (g_strcmp(name, attribute_mask[i]) != 0)

plugins/phonebook.c:123: error: implicit declaration of function ‘g_strcmp’

Probably some missing include. Furthermore, use g_strcmp0 if there's a
risk that one of the inputs might be NULL.

Always compile test with ./bootstrap-configure (in this case
--with-phonebook=ebook) before submitting patches.

Johan

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

* [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string
@ 2010-08-02 22:08 Marcel Mol
  2010-08-02 22:20 ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Marcel Mol @ 2010-08-02 22:08 UTC (permalink / raw)
  To: linux-bluetooth

evcard_to_string() only took one TEL attrib from a vcard. But
multiple TEL attribs are supported. This patch will convert
all TEL attribs to strings.
---
 plugins/phonebook-ebook.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 089b956..e80f797 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -97,6 +97,7 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 							uint64_t filter)
 {
 	EVCard *evcard2;
+	GList *l;
 	char *vcard;
 	unsigned int i;
 
@@ -109,18 +110,23 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
 	 */
 	filter = format == EVC_FORMAT_VCARD_30 ? filter | 0x87: filter | 0x85;
 
+	l = e_vcard_get_attributes(evcard);
 	evcard2 = e_vcard_new();
-	for (i = 0; i < 29; i++) {
-		EVCardAttribute *attrib;
-
-		if (!(filter & (1 << i)))
-			continue;
+	for (; l; l = g_list_next(l)) {
+		EVCardAttribute *attrib = l->data;
+		const char *name;
 
-		attrib = e_vcard_get_attribute(evcard, attribute_mask[i]);
 		if (!attrib)
 			continue;
-
-		e_vcard_add_attribute(evcard2, e_vcard_attribute_copy(attrib));
+		name = e_vcard_attribute_get_name(attrib);
+		for (i = 0; attribute_mask[i] != NULL; i++) {
+			if (!(filter & (1 << i)))
+				continue;
+			if (g_strcmp0(name, attribute_mask[i]) != 0)
+				continue;
+			e_vcard_add_attribute(evcard2,
+						e_vcard_attribute_copy(attrib));
+		}
 	}
 
 	vcard = e_vcard_to_string(evcard2, format);
-- 
1.7.2


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

* Re: [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string
  2010-08-02 22:08 Marcel Mol
@ 2010-08-02 22:20 ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2010-08-02 22:20 UTC (permalink / raw)
  To: Marcel Mol; +Cc: linux-bluetooth

Hi Marcel,

On Tue, Aug 03, 2010, Marcel Mol wrote:
> evcard_to_string() only took one TEL attrib from a vcard. But
> multiple TEL attribs are supported. This patch will convert
> all TEL attribs to strings.
> ---
>  plugins/phonebook-ebook.c |   22 ++++++++++++++--------
>  1 files changed, 14 insertions(+), 8 deletions(-)

Thanks for the quick update. The patch is now pushed upstream with a
couple more minor coding style cleanups (for which I didn't bother
having yet another review round ;) Take a look at the upstream tree if
you're interested in how exactly the final patch (and commit message)
ended up looking like.

Johan

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

end of thread, other threads:[~2010-08-02 22:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-02 21:29 [PATCH] obexd: ebook backend: return all TEL attribs from vcard in string Marcel Mol
2010-08-02 21:57 ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2010-08-02 21:29 Marcel Mol
2010-08-02 22:08 Marcel Mol
2010-08-02 22:20 ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).