diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c
index f88eb6c..82068dc 100644
--- a/obexd/plugins/phonebook-tracker.c
+++ b/obexd/plugins/phonebook-tracker.c
{
struct phonebook_data *data = user_data;
const struct apparam_field *params = data->params;
+ struct phonebook_contact *contact;
GString *vcards = data->vcards;
- char *formatted;
int last_index;
if (reply == NULL)
if (data->index < params->liststartoffset || data->index > last_index)
return;
- formatted = g_strdup_printf("%s;%s;%s;%s;%s", reply[2], reply[3],
- reply[4], reply[5], reply[6]);
-
- phonebook_add_entry(vcards, reply[0], TEL_TYPE_HOME, formatted,
- reply[6], reply[1], params->filter);
-
- g_free(formatted);
+ contact = g_new0(struct phonebook_contact, 1);
+ contact->tel = g_strdup(reply[0]);
+ contact->tel_type = 1; /* HOME */
+ contact->fullname = g_strdup(reply[1]);
+ contact->family = g_strdup(reply[2]);
+ contact->given = g_strdup(reply[3]);
+ contact->additional = g_strdup(reply[4]);
+ contact->prefix = g_strdup(reply[5]);
+ contact->suffix = g_strdup(reply[6]);
+ contact->email = g_strdup(reply[7]);
+
+ phonebook_add_contact(vcards, contact, params->filter);
+ phonebook_contact_free(contact);
return;
diff --git a/obexd/plugins/vcard.c b/obexd/plugins/vcard.c
index 3b833ef..a9d464f 100644
--- a/obexd/plugins/vcard.c
+++ b/obexd/plugins/vcard.c
vcard_printf(vcards, "VERSION:3.0");
}
-static void vcard_printf_fullname(GString *vcards, const char *text)
+static void vcard_printf_name(GString *vcards,
+ struct phonebook_contact *contact)
{
- char field[LEN_MAX];
- add_slash(field, text, LEN_MAX, strlen(text));
- vcard_printf(vcards, "FN:%s", field);
+ vcard_printf(vcards, "N:%s;%s;%s;%s;%s", contact->family,
+ contact->given, contact->additional,
+ contact->prefix, contact->suffix);
}
-static void vcard_printf_name(GString *vcards, const char *text)
+static void vcard_printf_fullname(GString *vcards, const char *text)
{
char field[LEN_MAX];
add_slash(field, text, LEN_MAX, strlen(text));
- vcard_printf(vcards, "N:%s", field);
+ vcard_printf(vcards, "FN:%s", field);
}
static void vcard_printf_number(GString *vcards, const char *number, int type,
vcard_printf(vcards, "");
}
-void phonebook_add_entry(GString *vcards, const char *number, int type,
- const char *name, const char *fullname,
- const char *email, uint64_t filter)
+void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
+ uint64_t filter)
{
/* There's really nothing to do */
- if ((number == NULL || number[0] == '\0') &&
- (fullname == NULL || fullname[0] == '\0'))
+ if ((contact->tel == NULL || contact->tel[0] == '\0') &&
+ (contact->fullname == NULL ||
+ contact->fullname[0] == '\0'))
return;
filter |= (FILTER_VERSION | FILTER_FN | FILTER_N | FILTER_TEL);
vcard_printf_begin(vcards);
if (filter & FILTER_FN) {
- if (fullname == NULL || fullname[0] == '\0')
- vcard_printf_fullname(vcards, number);
+ if (contact->fullname == NULL || contact->fullname[0] == '\0')
+ vcard_printf_fullname(vcards, contact->tel);
else
- vcard_printf_fullname(vcards, fullname);
+ vcard_printf_fullname(vcards, contact->fullname);
}
if (filter & FILTER_TEL)
- vcard_printf_number(vcards, number, type, TEL_TYPE_OTHER);
+ vcard_printf_number(vcards, contact->tel, contact->tel_type,
+ TEL_TYPE_OTHER);
if (filter & FILTER_N)
- vcard_printf_name(vcards, name);
+ vcard_printf_name(vcards, contact);
if (filter & FILTER_EMAIL)
- vcard_printf_email(vcards, email);
+ vcard_printf_email(vcards, contact->email);
vcard_printf_end(vcards);
}
+
+void phonebook_contact_free(struct phonebook_contact *contact)
+{
+ if (contact == NULL)
+ return;
+
+ g_free(contact->fullname);
+ g_free(contact->given);
+ g_free(contact->family);
+ g_free(contact->additional);
+ g_free(contact->tel);
+ g_free(contact->email);
+ g_free(contact->prefix);
+ g_free(contact->suffix);
+ g_free(contact);
+
+}
diff --git a/obexd/plugins/vcard.h b/obexd/plugins/vcard.h
index d9171cc..f015e94 100644
--- a/obexd/plugins/vcard.h
+++ b/obexd/plugins/vcard.h
TEL_TYPE_OTHER,
};
-void phonebook_add_entry(GString *vcards, const char *number, int type,
- const char *name, const char *fullname,
- const char *email, uint64_t filter);
+struct phonebook_contact {
+ char *fullname;
+ char *given;
+ char *family;
+ char *additional;
+ char *tel;
+ int tel_type;
+ char *email;
+ char *prefix;
+ char *suffix;
+};
+
+void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
+ uint64_t filter);
+
+void phonebook_contact_free(struct phonebook_contact *contact);