diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2008-09-14 11:23:57 -0700 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-09-14 11:26:18 -0700 |
commit | a92bd8322b41a1002fba89386019ff2bd3cc5493 (patch) | |
tree | e75faab2d6464eaf9070789ffe9bb3d4c19a7b3d /src/storage.c | |
parent | 16e602617d194c65ac641d1835bab6c58503cdcc (diff) |
move read_records() to storage.c where it belongs
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c index f6d94bd2..5e4e3062 100644 --- a/src/storage.c +++ b/src/storage.c @@ -810,6 +810,53 @@ int delete_record(const gchar *src, const gchar *dst, const uint32_t handle) return textfile_del(filename, key); } +struct record_list { + sdp_list_t *recs; + const gchar *addr; +}; + +static void create_stored_records_from_keys(char *key, char *value, + void *user_data) +{ + struct record_list *rec_list = user_data; + const gchar *addr = rec_list->addr; + sdp_record_t *rec; + int size, i, len; + uint8_t *pdata; + char tmp[3] = ""; + + if (strncmp(key, addr, 17)) + return; + + size = strlen(value)/2; + pdata = g_malloc0(size); + + for (i = 0; i < size; i++) { + memcpy(tmp, value + (i * 2), 2); + pdata[i] = (uint8_t) strtol(tmp, NULL, 16); + } + + rec = sdp_extract_pdu(pdata, size, &len); + free(pdata); + + rec_list->recs = sdp_list_append(rec_list->recs, rec); +} + +sdp_list_t *read_records(const gchar *src, const gchar *dst) +{ + char filename[PATH_MAX + 1]; + struct record_list rec_list; + + rec_list.addr = dst; + rec_list.recs = NULL; + + create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp"); + textfile_foreach(filename, create_stored_records_from_keys, &rec_list); + + return rec_list.recs; +} + + int store_device_id(const gchar *src, const gchar *dst, const uint16_t source, const uint16_t vendor, const uint16_t product, const uint16_t version) |