diff options
author | Alok Barsode <alok.barsode@azingo.com> | 2008-07-16 18:10:46 +0530 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@indt.org.br> | 2008-07-28 10:47:00 -0300 |
commit | 6d825531c184a498150203090b37f2ccb6819571 (patch) | |
tree | fdded4b378af70f37f6dab8f5575d2db5577094d | |
parent | ae88a004bbece79168f6bd2710138546e0f91cb9 (diff) |
Adding store_record, fetch_record and delete_record.
Signed-off-by: Alok Barsode <alok.barsode@azingo.com>
-rw-r--r-- | hcid/hcid.h | 4 | ||||
-rw-r--r-- | hcid/storage.c | 77 |
2 files changed, 81 insertions, 0 deletions
diff --git a/hcid/hcid.h b/hcid/hcid.h index 08276e4d..2dd522f7 100644 --- a/hcid/hcid.h +++ b/hcid/hcid.h @@ -29,6 +29,7 @@ #include <glib.h> #include <bluetooth/bluetooth.h> +#include <bluetooth/sdp.h> #include <bluetooth/hci.h> #include "logging.h" @@ -193,6 +194,9 @@ int write_trust(bdaddr_t *local, const char *addr, const char *service, gboolean GSList *list_trusts(bdaddr_t *local, const char *service); int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles); int delete_entry(bdaddr_t *src, const char *storage, const char *key); +int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec); +sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle); +int delete_record(const gchar *src, const gchar *dst, const uint32_t handle); gboolean plugin_init(GKeyFile *config); void plugin_cleanup(void); diff --git a/hcid/storage.c b/hcid/storage.c index 595e9a22..ded9a535 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -41,6 +41,8 @@ #include <glib.h> #include <bluetooth/bluetooth.h> +#include <bluetooth/sdp.h> +#include <bluetooth/sdp_lib.h> #include "textfile.h" #include "hcid.h" @@ -705,3 +707,78 @@ int delete_entry(bdaddr_t *src, const char *storage, const char *key) return textfile_del(filename, key); } + +int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec) +{ + char filename[PATH_MAX + 1], key[28]; + sdp_buf_t buf; + int err, size, i; + char *pdata, *str; + + create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp"); + + create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + snprintf(key, sizeof(key), "%17s#%08X", dst, rec->handle); + + if (sdp_gen_record_pdu(rec, &buf) < 0) + return -1; + + pdata = (char *)buf.data; + size = buf.data_size; + + str = g_malloc0(size*2+1); + + for (i = 0; i < size; i++) + sprintf(str + (i * 2), "%02X", buf.data[i]); + + err = textfile_put(filename, key, str); + + free(buf.data); + free(str); + + return err; +} + +sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle) +{ + char filename[PATH_MAX + 1], key[28], tmp[3],*str; + sdp_record_t *rec; + int size, i, len; + uint8_t *pdata; + + create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp"); + + snprintf(key, sizeof(key), "%17s#%08X", dst, handle); + + str = textfile_get(filename, key); + + if (!str) + return NULL; + + size = strlen(str)/2; + pdata = g_malloc0(size); + + for (i = 0; i < size; i++) { + memcpy(tmp, str + (i*2), 2); + pdata[i] = (uint8_t) strtol(tmp, NULL, 16); + } + + rec = sdp_extract_pdu(pdata, &len); + + free(str); + free(pdata); + + return rec; +} + +int delete_record(const gchar *src, const gchar *dst, const uint32_t handle) +{ + char filename[PATH_MAX + 1], key[28]; + + create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp"); + + snprintf(key, sizeof(key), "%17s#%08X", dst, handle); + + return textfile_del(filename, key); +} |