All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix issues with emails category
@ 2010-08-23 13:45 Lukasz Pawlik
  2010-08-23 20:50 ` Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Pawlik @ 2010-08-23 13:45 UTC (permalink / raw)
  To: linux-bluetooth

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



[-- Attachment #2: 0001-Fix-issues-with-emails-category.patch --]
[-- Type: text/x-patch, Size: 5783 bytes --]

From 35e6beaea7a20c42c3bd13af9b18e0883dd33f66 Mon Sep 17 00:00:00 2001
From: Lukasz Pawlik <lucas.pawlik@gmail.com>
Date: Mon, 23 Aug 2010 15:25:20 +0200
Subject: [PATCH] Fix issues with emails category

Previously all emails sent during phonebook pull had the same
category INTERNET. Now email are sent with valid category name
(INTERNET;HOME or INTERNET;WORK)
---
 plugins/phonebook-tracker.c |   31 +++++++++++++++++--------
 plugins/vcard.c             |   53 ++++++++++++++++++++++++++++++++++---------
 plugins/vcard.h             |   11 +++++++++
 3 files changed, 74 insertions(+), 21 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 3f63dcb..35742b6 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -687,27 +687,38 @@ static void add_phone_number(struct phonebook_contact *contact,
 	contact->numbers = g_slist_append(contact->numbers, number);
 }
 
-static gchar *find_email(GSList *emails, const char *email)
+static struct phonebook_email *find_email(GSList *emails, const char *address,
+										int type)
 {
 	GSList *l;
 
-	for (l = emails; l; l = l->next)
-		if (g_strcmp0(l->data, email) == 0)
-			return l->data;
+	for (l = emails; l; l = l->next) {
+		struct phonebook_email *email;
+		email = l->data;
+		if (g_strcmp0(email->address, address) == 0 &&
+					email->type == type)
+			return email;
+	}
 
 	return NULL;
 }
 
-static void add_email(struct phonebook_contact *contact, const char *email)
+static void add_email(struct phonebook_contact *contact, const char *address,
+						int type)
 {
-	if (email == NULL || strlen(email) == 0)
+	struct phonebook_email *email;
+	if (address == NULL || strlen(address) == 0)
 		return;
 
 	/* Not adding email if there is already added with the same value */
-	if (find_email(contact->emails, email))
+	if (find_email(contact->emails, address, type))
 		return;
 
-	contact->emails = g_slist_append(contact->emails, g_strdup(email));
+	email = g_new0(struct phonebook_email, 1);
+	email->address = g_strdup(address);
+	email->type = type;
+
+	contact->emails = g_slist_append(contact->emails, email);
 }
 
 static GString *gen_vcards(GSList *contacts,
@@ -817,8 +828,8 @@ add_numbers:
 	add_phone_number(contact, reply[COL_FAX_NUMBER], TEL_TYPE_FAX);
 
 	/* Adding emails */
-	add_email(contact, reply[COL_HOME_EMAIL]);
-	add_email(contact, reply[COL_WORK_EMAIL]);
+	add_email(contact, reply[COL_HOME_EMAIL], EMAIL_TYPE_HOME);
+	add_email(contact, reply[COL_WORK_EMAIL], EMAIL_TYPE_WORK);
 
 	DBG("contact %p", contact);
 
diff --git a/plugins/vcard.c b/plugins/vcard.c
index 0eed8ae..3b67535 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -306,19 +306,39 @@ static void vcard_printf_slash_tag(GString *vcards, const char *tag,
 	vcard_printf(vcards, "%s:%s", buf, field);
 }
 
-static void vcard_printf_email(GString *vcards, const char *email)
+static void vcard_printf_email(GString *vcards, uint8_t format,
+								const char *address,
+								enum phonebook_email_type category)
 {
+	const char *category_string = "";
+	char field[LEN_MAX];
 	int len = 0;
 
-	if (email)
-		len = strlen(email);
+	if (!address || !(len = strlen(address)))
+		return;
 
-	if (len) {
-		char field[LEN_MAX];
-		add_slash(field, email, LEN_MAX, len);
-		vcard_printf(vcards,
-				"EMAIL;TYPE=INTERNET:%s", field);
+	switch (category){
+	case EMAIL_TYPE_HOME:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET;HOME";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET;TYPE=HOME";
+		break;
+	case EMAIL_TYPE_WORK:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET;WORK";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET;TYPE=WORK";
+		break;
+	default:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET";
 	}
+
+	add_slash(field, address, LEN_MAX, len);
+	vcard_printf(vcards,"EMAIL;%s:%s", category_string, field);
 }
 
 static gboolean org_fields_present(struct phonebook_contact *contact)
@@ -421,8 +441,11 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	if (filter & FILTER_EMAIL) {
 		GSList *l;
 
-		for (l = contact->emails; l; l = l->next)
-			vcard_printf_email(vcards, l->data);
+		for (l = contact->emails; l; l = l->next){
+			struct phonebook_email *email = l->data;
+
+			vcard_printf_email(vcards, format, email->address, email->type);
+		}
 	}
 
 	if (filter & FILTER_ADR)
@@ -459,6 +482,14 @@ static void number_free(gpointer data, gpointer user_data)
 	g_free(number);
 }
 
+static void email_free(gpointer data, gpointer user_data)
+{
+	struct phonebook_email *email = data;
+
+	g_free(email->address);
+	g_free(email);
+}
+
 void phonebook_contact_free(struct phonebook_contact *contact)
 {
 	if (contact == NULL)
@@ -467,7 +498,7 @@ void phonebook_contact_free(struct phonebook_contact *contact)
 	g_slist_foreach(contact->numbers, number_free, NULL);
 	g_slist_free(contact->numbers);
 
-	g_slist_foreach(contact->emails, (GFunc) g_free, NULL);
+	g_slist_foreach(contact->emails, email_free, NULL);
 	g_slist_free(contact->emails);
 
 	g_free(contact->fullname);
diff --git a/plugins/vcard.h b/plugins/vcard.h
index 0f52425..a22dfc1 100644
--- a/plugins/vcard.h
+++ b/plugins/vcard.h
@@ -27,6 +27,12 @@ enum phonebook_number_type {
 	TEL_TYPE_OTHER,
 };
 
+enum phonebook_email_type {
+	EMAIL_TYPE_HOME,
+	EMAIL_TYPE_WORK,
+	EMAIL_TYPE_OTHER,
+};
+
 enum phonebook_call_type {
 	CALL_TYPE_NOT_A_CALL,
 	CALL_TYPE_MISSED,
@@ -39,6 +45,11 @@ struct phonebook_number {
 	int type;
 };
 
+struct phonebook_email {
+	char *address;
+	int  type;
+};
+
 struct phonebook_contact {
 	char *fullname;
 	char *given;
-- 
1.7.0.4


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

* Re: [PATCH] Fix issues with emails category
  2010-08-23 13:45 [PATCH] Fix issues with emails category Lukasz Pawlik
@ 2010-08-23 20:50 ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2010-08-23 20:50 UTC (permalink / raw)
  To: Lukasz Pawlik; +Cc: linux-bluetooth

Hi Lukasz,

On Mon, Aug 23, 2010, Lukasz Pawlik wrote:
> From: Lukasz Pawlik <lucas.pawlik@gmail.com>
> Date: Mon, 23 Aug 2010 15:25:20 +0200
> Subject: [PATCH] Fix issues with emails category
> 
> Previously all emails sent during phonebook pull had the same
> category INTERNET. Now email are sent with valid category name
> (INTERNET;HOME or INTERNET;WORK)
> ---
>  plugins/phonebook-tracker.c |   31 +++++++++++++++++--------
>  plugins/vcard.c             |   53 ++++++++++++++++++++++++++++++++++---------
>  plugins/vcard.h             |   11 +++++++++
>  3 files changed, 74 insertions(+), 21 deletions(-)

Thanks. The patch is now pushed upstream, but I had to make a few coding
style fixes before that:

> +static struct phonebook_email *find_email(GSList *emails, const char *address,
> +										int type)

Over 80 column line.

> +	for (l = emails; l; l = l->next) {
> +		struct phonebook_email *email;
> +		email = l->data;

You don't really need the variable definition and assignment on
different lines here.

> +static void add_email(struct phonebook_contact *contact, const char *address,
> +						int type)

The continuation line should be indented as much as possible as long as
you don't go beyond 80 columns. (not sure if this is a kernel coding
style thingie but at least Marcel wants it that way).

> +static void vcard_printf_email(GString *vcards, uint8_t format,
> +								const char *address,
> +								enum phonebook_email_type category)

Way over 80 column lines. Are you using some other tab-width than 8?

Johan

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

* Re: [PATCH] Fix issues with emails category
  2010-08-23 11:18 Lukasz Pawlik
  2010-08-23 11:42 ` Johan Hedberg
@ 2010-08-23 12:20 ` Uwe Kleine-König
  1 sibling, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2010-08-23 12:20 UTC (permalink / raw)
  To: Lukasz Pawlik; +Cc: linux-bluetooth

Hallo Lukasz,

On Mon, Aug 23, 2010 at 01:18:11PM +0200, Lukasz Pawlik wrote:
> From a537ade2e108a91552e0d9a6c4ff71ca35388e10 Mon Sep 17 00:00:00 2001
> From: Lukasz Pawlik <lucas.pawlik@gmail.com>
> Date: Mon, 23 Aug 2010 12:57:40 +0200
> Subject: [PATCH] Fix issues with emails category
> 
> Previously all emails sent during phonebook pull had the same
> category INTERNET. Now email are sent with valid category name
> (INTERNET;HOME or INTERNET;WORK)
> ---
>  plugins/phonebook-tracker.c |   30 +++++++++++++++++-------
>  plugins/vcard.c             |   53 ++++++++++++++++++++++++++++++++++---------
>  plugins/vcard.h             |   11 +++++++++
>  3 files changed, 74 insertions(+), 20 deletions(-)
> 
> diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
> index 3f63dcb..069e324 100644
> --- a/plugins/phonebook-tracker.c
> +++ b/plugins/phonebook-tracker.c
> @@ -687,27 +687,39 @@ static void add_phone_number(struct phonebook_contact *contact,
>  	contact->numbers = g_slist_append(contact->numbers, number);
>  }
>  
> -static gchar *find_email(GSList *emails, const char *email)
> +static struct phonebook_email *find_email(GSList *emails, const char *email,
> +										int type)
I assume your tabsize is < 8, because for me "int type" is after the
comma on the preceeding line.  I don't know for sure, but I assume bluez
uses the same convention as the kernel, so tabsize is 8.  (The functions
below need the same fix.)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* Re: [PATCH] Fix issues with emails category
  2010-08-23 11:18 Lukasz Pawlik
@ 2010-08-23 11:42 ` Johan Hedberg
  2010-08-23 12:20 ` Uwe Kleine-König
  1 sibling, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2010-08-23 11:42 UTC (permalink / raw)
  To: Lukasz Pawlik; +Cc: linux-bluetooth

Hi Lukasz,

On Mon, Aug 23, 2010, Lukasz Pawlik wrote:
> +	struct phonebook_email *email_addr;
> +
> +	for (l = emails; l; l = l->next) {
> +		email_addr = l->data;

Please always define variables in the smallest possible scope. In this
case email_addr can be defined in the beginning of the for-loop instead
of the beginning of the function.

> +		if (g_strcmp0(email_addr->email, email) == 0
> +			&& email_addr->type == type)
> +			return email_addr;

Continuation lines should be indented by at least two tabs more than the
original so that they stand out clearly from the actual code that's part
of the subsection. Also, the && goes on the preceeding line.


> -static void add_email(struct phonebook_contact *contact, const char *email)
> +static void add_email(struct phonebook_contact *contact, const char *email,
> +					int type)
>  {
> +	struct phonebook_email *email_addr;
>  	if (email == NULL || strlen(email) == 0)
>  		return;
>  
>  	/* Not adding email if there is already added with the same value */
> -	if (find_email(contact->emails, email))
> +	if (find_email(contact->emails, email, type))
>  		return;
>  
> -	contact->emails = g_slist_append(contact->emails, g_strdup(email));
> +	email_addr = g_new0(struct phonebook_email, 1);
> +	email_addr->email = g_strdup(email);
> +	email_addr->type = type;
> +
> +	contact->emails = g_slist_append(contact->emails, email_addr);

I'd do some renaming of variables here to make it more readable:

s/email/address/
s/email_address/email/
s/email->email/email->address/

> +struct phonebook_email {
> +	char *email;

As mentioned above I'd do a s/email/address/ here.

Johan

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

* [PATCH] Fix issues with emails category
@ 2010-08-23 11:18 Lukasz Pawlik
  2010-08-23 11:42 ` Johan Hedberg
  2010-08-23 12:20 ` Uwe Kleine-König
  0 siblings, 2 replies; 5+ messages in thread
From: Lukasz Pawlik @ 2010-08-23 11:18 UTC (permalink / raw)
  To: linux-bluetooth

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



[-- Attachment #2: 0001-Fix-issues-with-emails-category.patch --]
[-- Type: text/x-patch, Size: 5755 bytes --]

From a537ade2e108a91552e0d9a6c4ff71ca35388e10 Mon Sep 17 00:00:00 2001
From: Lukasz Pawlik <lucas.pawlik@gmail.com>
Date: Mon, 23 Aug 2010 12:57:40 +0200
Subject: [PATCH] Fix issues with emails category

Previously all emails sent during phonebook pull had the same
category INTERNET. Now email are sent with valid category name
(INTERNET;HOME or INTERNET;WORK)
---
 plugins/phonebook-tracker.c |   30 +++++++++++++++++-------
 plugins/vcard.c             |   53 ++++++++++++++++++++++++++++++++++---------
 plugins/vcard.h             |   11 +++++++++
 3 files changed, 74 insertions(+), 20 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 3f63dcb..069e324 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -687,27 +687,39 @@ static void add_phone_number(struct phonebook_contact *contact,
 	contact->numbers = g_slist_append(contact->numbers, number);
 }
 
-static gchar *find_email(GSList *emails, const char *email)
+static struct phonebook_email *find_email(GSList *emails, const char *email,
+										int type)
 {
 	GSList *l;
 
-	for (l = emails; l; l = l->next)
-		if (g_strcmp0(l->data, email) == 0)
-			return l->data;
+	struct phonebook_email *email_addr;
+
+	for (l = emails; l; l = l->next) {
+		email_addr = l->data;
+		if (g_strcmp0(email_addr->email, email) == 0
+			&& email_addr->type == type)
+			return email_addr;
+	}
 
 	return NULL;
 }
 
-static void add_email(struct phonebook_contact *contact, const char *email)
+static void add_email(struct phonebook_contact *contact, const char *email,
+					int type)
 {
+	struct phonebook_email *email_addr;
 	if (email == NULL || strlen(email) == 0)
 		return;
 
 	/* Not adding email if there is already added with the same value */
-	if (find_email(contact->emails, email))
+	if (find_email(contact->emails, email, type))
 		return;
 
-	contact->emails = g_slist_append(contact->emails, g_strdup(email));
+	email_addr = g_new0(struct phonebook_email, 1);
+	email_addr->email = g_strdup(email);
+	email_addr->type = type;
+
+	contact->emails = g_slist_append(contact->emails, email_addr);
 }
 
 static GString *gen_vcards(GSList *contacts,
@@ -817,8 +829,8 @@ add_numbers:
 	add_phone_number(contact, reply[COL_FAX_NUMBER], TEL_TYPE_FAX);
 
 	/* Adding emails */
-	add_email(contact, reply[COL_HOME_EMAIL]);
-	add_email(contact, reply[COL_WORK_EMAIL]);
+	add_email(contact, reply[COL_HOME_EMAIL], EMAIL_TYPE_HOME);
+	add_email(contact, reply[COL_WORK_EMAIL], EMAIL_TYPE_WORK);
 
 	DBG("contact %p", contact);
 
diff --git a/plugins/vcard.c b/plugins/vcard.c
index 0eed8ae..425ac71 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -306,19 +306,39 @@ static void vcard_printf_slash_tag(GString *vcards, const char *tag,
 	vcard_printf(vcards, "%s:%s", buf, field);
 }
 
-static void vcard_printf_email(GString *vcards, const char *email)
+static void vcard_printf_email(GString *vcards, uint8_t format,
+								const char *email,
+								enum phonebook_email_type category)
 {
+	const char *category_string = "";
+	char field[LEN_MAX];
 	int len = 0;
 
-	if (email)
-		len = strlen(email);
+	if (!email || !(len = strlen(email)))
+		return;
 
-	if (len) {
-		char field[LEN_MAX];
-		add_slash(field, email, LEN_MAX, len);
-		vcard_printf(vcards,
-				"EMAIL;TYPE=INTERNET:%s", field);
+	switch (category){
+	case EMAIL_TYPE_HOME:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET;HOME";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET;TYPE=HOME";
+		break;
+	case EMAIL_TYPE_WORK:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET;WORK";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET;TYPE=WORK";
+		break;
+	default:
+		if (format == FORMAT_VCARD21)
+			category_string = "INTERNET";
+		else if (format == FORMAT_VCARD30)
+			category_string = "TYPE=INTERNET";
 	}
+
+	add_slash(field, email, LEN_MAX, len);
+	vcard_printf(vcards,"EMAIL;%s:%s", category_string, field);
 }
 
 static gboolean org_fields_present(struct phonebook_contact *contact)
@@ -421,8 +441,11 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
 	if (filter & FILTER_EMAIL) {
 		GSList *l;
 
-		for (l = contact->emails; l; l = l->next)
-			vcard_printf_email(vcards, l->data);
+		for (l = contact->emails; l; l = l->next){
+			struct phonebook_email *email = l->data;
+
+			vcard_printf_email(vcards, format, email->email, email->type);
+		}
 	}
 
 	if (filter & FILTER_ADR)
@@ -459,6 +482,14 @@ static void number_free(gpointer data, gpointer user_data)
 	g_free(number);
 }
 
+static void email_free(gpointer data, gpointer user_data)
+{
+	struct phonebook_email *email = data;
+
+	g_free(email->email);
+	g_free(email);
+}
+
 void phonebook_contact_free(struct phonebook_contact *contact)
 {
 	if (contact == NULL)
@@ -467,7 +498,7 @@ void phonebook_contact_free(struct phonebook_contact *contact)
 	g_slist_foreach(contact->numbers, number_free, NULL);
 	g_slist_free(contact->numbers);
 
-	g_slist_foreach(contact->emails, (GFunc) g_free, NULL);
+	g_slist_foreach(contact->emails, email_free, NULL);
 	g_slist_free(contact->emails);
 
 	g_free(contact->fullname);
diff --git a/plugins/vcard.h b/plugins/vcard.h
index 0f52425..41423e0 100644
--- a/plugins/vcard.h
+++ b/plugins/vcard.h
@@ -27,6 +27,12 @@ enum phonebook_number_type {
 	TEL_TYPE_OTHER,
 };
 
+enum phonebook_email_type {
+	EMAIL_TYPE_HOME,
+	EMAIL_TYPE_WORK,
+	EMAIL_TYPE_OTHER,
+};
+
 enum phonebook_call_type {
 	CALL_TYPE_NOT_A_CALL,
 	CALL_TYPE_MISSED,
@@ -39,6 +45,11 @@ struct phonebook_number {
 	int type;
 };
 
+struct phonebook_email {
+	char *email;
+	int  type;
+};
+
 struct phonebook_contact {
 	char *fullname;
 	char *given;
-- 
1.7.0.4


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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-23 13:45 [PATCH] Fix issues with emails category Lukasz Pawlik
2010-08-23 20:50 ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2010-08-23 11:18 Lukasz Pawlik
2010-08-23 11:42 ` Johan Hedberg
2010-08-23 12:20 ` Uwe Kleine-König

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.