summaryrefslogtreecommitdiffstats
path: root/network/connection.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-14 01:12:34 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-14 01:12:34 +0000
commite5ba646776ba7c5c5c9c9d630bbfc8793f1c3b4e (patch)
treec30409abf02102827427a5d4a07e578e80a122db /network/connection.c
parent47895f4ab3f4de2682088dfba156106c772a92da (diff)
network: added connection_store
Diffstat (limited to 'network/connection.c')
-rw-r--r--network/connection.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/network/connection.c b/network/connection.c
index c7f22f4b..0bd255d2 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -39,6 +39,8 @@
#include "logging.h"
#include "dbus.h"
+#include "textfile.h"
+
#include "error.h"
#include "common.h"
#include "connection.h"
@@ -60,7 +62,7 @@ struct network_conn {
char dev[16]; /* BNEP interface name */
char *name;
char *desc;
- uint16_t id; /* Service Class Identifier */
+ uint16_t id; /* Role: Service Class Identifier */
conn_state state;
int sk;
};
@@ -593,6 +595,41 @@ int connection_register(DBusConnection *conn, const char *path, bdaddr_t *src,
return 0;
}
+int connection_store(DBusConnection *conn, const char *path)
+{
+ struct network_conn *nc;
+ const char *role;
+ char key[32], *value;
+ char filename[PATH_MAX + 1];
+ char src_addr[18], dst_addr[18];
+ int len, err;
+
+ if (!dbus_connection_get_object_path_data(conn, path, (void *) &nc))
+ return -ENOENT;
+
+ if (!nc->name || !nc->desc)
+ return -EINVAL;
+
+ /* FIXME: name and desc validation - remove ':' */
+
+ ba2str(&nc->dst, dst_addr);
+ role = bnep_name(nc->id);
+ snprintf(key, 32, "%s#%s", dst_addr, role);
+
+ len = strlen(nc->name) + strlen(nc->desc) + 2;
+ value = g_malloc0(len);
+ snprintf(value, len, "%s:%s", nc->name, nc->desc);
+
+ ba2str(&nc->src, src_addr);
+ create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "network");
+
+ err = textfile_put(filename, key, value);
+
+ g_free(value);
+
+ return err;
+}
+
int connection_find_data(DBusConnection *conn,
const char *path, const char *pattern)
{