From 8c1d1ada1dc7fbeaaba3693b448b07acc94806ab Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Wed, 9 Jun 2010 15:37:11 -0300 Subject: [PATCH] obexd: Add support for the X-IRMC-CALL-DATETIME field This field indicates the type of the call and when the call was made. --- obexd/plugins/phonebook-tracker.c | 55 ++++++++++++++++++++++++++----- obexd/plugins/vcard.c | 31 +++++++++++++++++ obexd/plugins/vcard.h | 9 +++++ 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c index 18c6fc5a6..1c41f5f22 100644 --- a/obexd/plugins/phonebook-tracker.c +++ b/obexd/plugins/phonebook-tracker.c @@ -49,7 +49,8 @@ "nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) \"NOTACALL\" \"false\" " \ + "\"false\" " \ "WHERE { " \ "?c a nco:Contact . " \ "OPTIONAL { ?c nco:hasPhoneNumber ?h . } " \ @@ -78,7 +79,8 @@ "nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) nmo:receivedDate(?call) " \ + "nmo:isSent(?call) nmo:isAnswered(?call)" \ "WHERE { " \ "?call a nmo:Call ; " \ "nmo:from ?c ; " \ @@ -115,7 +117,8 @@ "nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) nmo:receivedDate(?call) " \ + "nmo:isSent(?call) nmo:isAnswered(?call)" \ "WHERE { " \ "?call a nmo:Call ; " \ "nmo:from ?c ; " \ @@ -150,7 +153,8 @@ "nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) nmo:receivedDate(?call) " \ + "nmo:isSent(?call) nmo:isAnswered(?call)" \ "WHERE { " \ "?call a nmo:Call ; " \ "nmo:to ?c ; " \ @@ -185,7 +189,8 @@ "nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) nmo:receivedDate(?call) " \ + "nmo:isSent(?call) nmo:isAnswered(?call)" \ "WHERE { " \ "{ " \ "?call a nmo:Call ; " \ @@ -240,7 +245,8 @@ "nco:nameHonorificSuffix(<%s>) nco:emailAddress(?e) " \ "nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \ "nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ - "nco:postalcode(?p) nco:country(?p) " \ + "nco:postalcode(?p) nco:country(?p) \"NOTACALL\" \"false\" " \ + "\"false\" " \ "WHERE { " \ "<%s> a nco:Contact . " \ "OPTIONAL { <%s> nco:hasPhoneNumber ?h . } " \ @@ -477,6 +483,37 @@ static int query_tracker(const char *query, int num_fields, return 0; } +static void set_call_type(struct phonebook_contact *contact, + const char *datetime, const char *is_sent, + const char *is_answered) +{ + gboolean sent, answered; + + if (g_strcmp0(datetime, "NOTACALL") == 0) { + contact->calltype = CALL_TYPE_NOT_A_CALL; + return; + } + + sent = FALSE; + if (g_strcmp0(is_sent, "true") == 0) + sent = TRUE; + + answered = FALSE; + if (g_strcmp0(is_answered, "true") == 0) + answered = TRUE; + + if (sent == FALSE) + if (answered == FALSE) + contact->calltype = CALL_TYPE_MISSED; + else + contact->calltype = CALL_TYPE_INCOMING; + else + contact->calltype = CALL_TYPE_OUTGOING; + + /* Tracker already gives time in the ISO 8601 format */ + contact->datetime = g_strdup(datetime); +} + static void pull_contacts(char **reply, int num_fields, void *user_data) { struct phonebook_data *data = user_data; @@ -523,6 +560,8 @@ add_entry: contact->postal = g_strdup(reply[14]); contact->country = g_strdup(reply[15]); + set_call_type(contact, reply[16], reply[17], reply[18]); + number = g_new0(struct phonebook_number, 1); number->tel = g_strdup(reply[0]); number->type = 0; /* HOME */ @@ -694,7 +733,7 @@ int phonebook_pull(const char *name, const struct apparam_field *params, data->user_data = user_data; data->cb = cb; - return query_tracker(query, 16, pull_contacts, data); + return query_tracker(query, 19, pull_contacts, data); } int phonebook_get_entry(const char *folder, const char *id, @@ -717,7 +756,7 @@ int phonebook_get_entry(const char *folder, const char *id, query = g_strdup_printf(CONTACTS_QUERY_FROM_URI, id, id, id, id, id, id, id, id, id, id, id); - ret = query_tracker(query, 16, pull_contacts, data); + ret = query_tracker(query, 19, pull_contacts, data); g_free(query); diff --git a/obexd/plugins/vcard.c b/obexd/plugins/vcard.c index dc6e283d3..0dd3b082a 100644 --- a/obexd/plugins/vcard.c +++ b/obexd/plugins/vcard.c @@ -215,6 +215,33 @@ static void vcard_printf_adr(GString *vcards, struct phonebook_contact *contact) contact->postal, contact->country); } +static void vcard_printf_datetime(GString *vcards, + struct phonebook_contact *contact) +{ + const char *type; + + switch (contact->calltype) { + case CALL_TYPE_MISSED: + type = "MISSED"; + break; + + case CALL_TYPE_INCOMING: + type = "RECEIVED"; + break; + + case CALL_TYPE_OUTGOING: + type = "DIALED"; + break; + + case CALL_TYPE_NOT_A_CALL: + default: + return; + } + + vcard_printf(vcards, "X-IRMC-CALL-DATETIME;%s:%s", type, + contact->datetime); +} + static void vcard_printf_end(GString *vcards) { vcard_printf(vcards, "END:VCARD"); @@ -259,6 +286,9 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact, if (filter & FILTER_ADR) vcard_printf_adr(vcards, contact); + if (filter & FILTER_X_IRMC_CALL_DATETIME) + vcard_printf_datetime(vcards, contact); + vcard_printf_end(vcards); } @@ -292,5 +322,6 @@ void phonebook_contact_free(struct phonebook_contact *contact) g_free(contact->region); g_free(contact->postal); g_free(contact->country); + g_free(contact->datetime); g_free(contact); } diff --git a/obexd/plugins/vcard.h b/obexd/plugins/vcard.h index f2b5c0930..06bcd3533 100644 --- a/obexd/plugins/vcard.h +++ b/obexd/plugins/vcard.h @@ -27,6 +27,13 @@ enum phonebook_number_type { TEL_TYPE_OTHER, }; +enum phonebook_call_type { + CALL_TYPE_NOT_A_CALL, + CALL_TYPE_MISSED, + CALL_TYPE_INCOMING, + CALL_TYPE_OUTGOING, +}; + struct phonebook_number { char *tel; int type; @@ -48,6 +55,8 @@ struct phonebook_contact { char *region; char *postal; char *country; + char *datetime; + int calltype; }; void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact, -- 2.47.3