diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-08-29 17:50:49 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-08-29 17:50:49 +0000 |
commit | 1b9cc018822ca0edde9d0485c382a13a90253e43 (patch) | |
tree | 3f198887f78f527d508f4bb45a2ff8897843181f | |
parent | 1dfdcaaccb924c36d6ab8380fb52ea5a9691a872 (diff) |
network: concat remote name and service name to the connection name
-rw-r--r-- | network/common.c | 19 | ||||
-rw-r--r-- | network/common.h | 2 | ||||
-rw-r--r-- | network/manager.c | 17 |
3 files changed, 32 insertions, 6 deletions
diff --git a/network/common.c b/network/common.c index 0a11d306..d818829a 100644 --- a/network/common.c +++ b/network/common.c @@ -40,6 +40,7 @@ #include "logging.h" #include "common.h" +#include "textfile.h" static int ctl; @@ -204,3 +205,21 @@ int bnep_if_up(const char *devname, int up) return 0; } + +int read_remote_name(bdaddr_t *src, bdaddr_t *dst, char *buf, size_t size) +{ + char filename[PATH_MAX + 1], addr[18], *str; + + ba2str(src, addr); + create_name(filename, PATH_MAX, STORAGEDIR, addr, "names"); + + ba2str(dst, addr); + str = textfile_get(filename, addr); + if (!str) + return -ENOENT; + + snprintf(buf, size, "%s", str); + free(str); + + return 0; +} diff --git a/network/common.h b/network/common.h index bfbe83d2..1d8b57de 100644 --- a/network/common.h +++ b/network/common.h @@ -33,3 +33,5 @@ int bnep_kill_all_connections(void); int bnep_connadd(int sk, uint16_t role, char *dev); int bnep_if_up(const char *devname, int up); + +int read_remote_name(bdaddr_t *src, bdaddr_t *dst, char *buf, size_t size); diff --git a/network/manager.c b/network/manager.c index 0ac6228f..78d65431 100644 --- a/network/manager.c +++ b/network/manager.c @@ -54,6 +54,8 @@ #include "connection.h" #include "common.h" +#define MAX_NAME_SIZE 256 + struct pending_reply { DBusConnection *conn; DBusMessage *msg; @@ -222,7 +224,7 @@ static void pan_record_reply(DBusPendingCall *call, void *data) uint8_t *rec_bin; sdp_data_t *d; sdp_record_t *rec = NULL; - char *name = NULL, *desc = NULL; + char name[MAX_NAME_SIZE], *desc = NULL; dbus_error_init(&derr); if (dbus_set_error_from_message(&derr, reply)) { @@ -253,11 +255,16 @@ static void pan_record_reply(DBusPendingCall *call, void *data) rec = sdp_extract_pdu(rec_bin, &scanned); - /* Extract service name from record */ + /* Concat remote name and service name */ + memset(name, 0, MAX_NAME_SIZE); + if (read_remote_name(&pr->src, &pr->dst, name, MAX_NAME_SIZE) < 0) + len = 0; + else + len = strlen(name); + d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY); if (d) { - name = g_new0(char, d->unitSize); - snprintf(name, d->unitSize, "%.*s", + snprintf(name + len, MAX_NAME_SIZE - len, "(%.*s)", d->unitSize, d->val.str); } @@ -281,8 +288,6 @@ static void pan_record_reply(DBusPendingCall *call, void *data) create_path(pr->conn, pr->msg, pr->path, "ConnectionCreated"); fail: - if (name) - g_free(name); if (desc) g_free(desc); |