summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md31
-rw-r--r--binding/bluetooth-pbap-binding.c61
2 files changed, 66 insertions, 26 deletions
diff --git a/README.md b/README.md
index 5d72482..8520dcd 100644
--- a/README.md
+++ b/README.md
@@ -6,19 +6,30 @@ Bluetooth PBAP service reports respective vCard phonebook data from BlueZ via co
## Verbs
-| Name | Description | JSON Response |
-|-------------|-------------------------------------------|----------------------------------------------------|
-| subscribe | subscribe to Bluetooth PBAP events | *Request:* {"value": "status"} |
-| unsubscribe | unsubscribe to Bluetooth PBAP events | *Request:* {"value": "status"} |
-| contacts | return all contacts from connected device | see **contacts verb section** |
-| entry | return vCard data from handle | see **entry verb section** |
-| history | return call history list | see **history verb section** |
-| search | search for respective vCard handle | see **search verb section** |
-| status | current device connection status | same response as noted in **status event section** |
+| Name | Description | JSON Response |
+|-------------|--------------------------------------------|----------------------------------------------------|
+| subscribe | subscribe to Bluetooth PBAP events | *Request:* {"value": "status"} |
+| unsubscribe | unsubscribe to Bluetooth PBAP events | *Request:* {"value": "status"} |
+| import | request contact data from connected device | see **import verb section** |
+| contacts | return all contacts from connected device | see **contacts verb section** |
+| entry | return vCard data from handle | see **entry verb section** |
+| history | return call history list | see **history verb section** |
+| search | search for respective vCard handle | see **search verb section** |
+| status | current device connection status | same response as noted in **status event section** |
+
+
+### import Verb
+
+Requests phonebook from connected device via OBEX transfers, caches the results to a database, and
+returns a response as documented in the **contacts verb section**
+
### contacts Verb
-Returns all vCards that are accessible from respective connected device in concatenated output:
+Returns all vCards that are accessible from respective connected device in concatenated output
+from the cached database.
+
+NOTE: This doesn't request refreshed data from device
<pre>
diff --git a/binding/bluetooth-pbap-binding.c b/binding/bluetooth-pbap-binding.c
index 8dfba3d..cf39851 100644
--- a/binding/bluetooth-pbap-binding.c
+++ b/binding/bluetooth-pbap-binding.c
@@ -356,25 +356,54 @@ void contacts(afb_req_t request)
{
struct json_object *jresp;
const char *cached = NULL;
+
+ if (!connected) {
+ afb_req_fail(request, "not connected", NULL);
+ return;
+ }
+
+ if (!read_cached_value(connected_address, &cached)) {
+ jresp = json_tokener_parse(cached);
+ } else {
+ afb_req_fail(request, "no imported contacts", NULL);
+ }
+
+ afb_req_success(request, jresp, "contacts");
+}
+
+void import(afb_req_t request)
+{
+ struct json_object *jresp;
int max_entries = -1;
+ gchar *address;
+ g_mutex_lock(&connected_mutex);
if (!connected) {
afb_req_fail(request, "not connected", NULL);
+ g_mutex_unlock(&connected_mutex);
return;
}
+ address = g_strdup(connected_address);
+ g_mutex_unlock(&connected_mutex);
+
if (!parse_max_entries_parameter(request, &max_entries))
return;
- if (max_entries == -1 && !read_cached_value(connected_address, &cached)) {
- jresp = json_tokener_parse(cached);
- } else {
- org_bluez_obex_phonebook_access1_call_select_sync(
- phonebook, INTERNAL, CONTACTS, NULL, NULL);
- jresp = get_vcards(max_entries);
+ if (!org_bluez_obex_phonebook_access1_call_select_sync(
+ phonebook, INTERNAL, CONTACTS, NULL, NULL)) {
+ afb_req_fail(request, "cannot import contacts", NULL);
+ goto out_free;
}
+ jresp = get_vcards(max_entries);
+ update_or_insert(address,
+ json_object_to_json_string_ext(jresp, JSON_C_TO_STRING_PLAIN));
+
afb_req_success(request, jresp, "contacts");
+
+out_free:
+ g_free(address);
}
void entry(afb_req_t request)
@@ -651,24 +680,22 @@ static gboolean is_pbap_dev_and_init(struct json_object *dev)
g_mutex_lock(&connected_mutex);
if (connected_address)
g_free(connected_address);
- connected_address = g_strdup(address);
connected = TRUE;
json_object_object_add(jresp, "connected",
json_object_new_boolean(connected));
+
+ json_object_object_get_ex(dev, "device", &val1);
+ connected_address = g_strdup(json_object_get_string(val1));
+
+ json_object_object_add(jresp, "device",
+ json_object_new_string(connected_address));
+
g_mutex_unlock(&connected_mutex);
afb_event_push(status_event, jresp);
- json_object_object_get_ex(dev, "device", &val1);
- AFB_NOTICE("PBAP device connected: %s", json_object_get_string(val1));
-
- /* probably should be made async */
- org_bluez_obex_phonebook_access1_call_select_sync(
- phonebook, INTERNAL, CONTACTS, NULL, NULL);
- update_or_insert(address,
- json_object_to_json_string_ext(get_vcards(-1),
- JSON_C_TO_STRING_PLAIN));
+ AFB_NOTICE("PBAP device connected: %s", connected_address);
return TRUE;
}
@@ -714,6 +741,7 @@ static void init_bt(afb_api_t api)
static const afb_verb_t binding_verbs[] = {
{ .verb = "contacts", .callback = contacts, .info = "List contacts" },
+ { .verb = "import", .callback = import, .info = "Import contacts" },
{ .verb = "entry", .callback = entry, .info = "List call entry" },
{ .verb = "history", .callback = history, .info = "List call history" },
{ .verb = "search", .callback = search, .info = "Search for entry" },
@@ -792,6 +820,7 @@ static void process_connection_event(afb_api_t api, struct json_object *object)
g_mutex_lock(&connected_mutex);
connected = FALSE;
json_object_object_add(jresp, "connected", json_object_new_boolean(connected));
+ json_object_object_add(jresp, "device", json_object_new_string(device));
g_mutex_unlock(&connected_mutex);
afb_event_push(status_event, jresp);