summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-12 18:42:47 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-12 18:42:47 +0000
commit4d8f5eb37c895d875a7fdcce45f03c406adfa668 (patch)
tree4d50342ba94930c47875d5febecfb3aea8b0da65 /network
parent1cbec5ebe8d67b1b4dcef1768efde2ac1ac51970 (diff)
network: changed the server D-Bus path and moved storage functions to manager.c
Diffstat (limited to 'network')
-rw-r--r--network/main.c2
-rw-r--r--network/manager.c73
-rw-r--r--network/manager.h3
-rw-r--r--network/server.c73
4 files changed, 70 insertions, 81 deletions
diff --git a/network/main.c b/network/main.c
index 74675184..2d9d44b6 100644
--- a/network/main.c
+++ b/network/main.c
@@ -33,6 +33,8 @@
#include <signal.h>
#include <glib.h>
+#include <bluetooth/bluetooth.h>
+
#include "dbus.h"
#include "logging.h"
diff --git a/network/manager.c b/network/manager.c
index d2b627db..c09cbc8b 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -28,6 +28,8 @@
#include <ctype.h>
#include <dirent.h>
+#include <sys/stat.h>
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@@ -53,9 +55,6 @@
#define MAX_PATH_LENGTH 64 /* D-Bus path */
-static GSList *server_paths = NULL; /* Network registered servers paths */
-static GSList *connection_paths = NULL; /* Network registered connections paths */
-
struct pending_reply {
DBusConnection *conn;
DBusMessage *msg;
@@ -65,8 +64,13 @@ struct pending_reply {
uint16_t id;
};
+static GSList *server_paths = NULL; /* Network registered servers paths */
+static GSList *connection_paths = NULL; /* Network registered connections paths */
+
static DBusConnection *connection = NULL;
+static int net_uid = 0; /* Network objects identifier */
+
static void pending_reply_free(struct pending_reply *pr)
{
if (pr->addr)
@@ -342,6 +346,7 @@ static void get_address_reply(DBusPendingCall *call, void *data)
DBusMessage *reply = dbus_pending_call_steal_reply(call);
DBusError derr;
const char *address;
+ bdaddr_t src;
dbus_error_init(&derr);
if (dbus_set_error_from_message(&derr, reply)) {
@@ -361,6 +366,9 @@ static void get_address_reply(DBusPendingCall *call, void *data)
goto fail;
}
+ str2ba(address, &src);
+ network_store_info(&src, pr->id, FALSE);
+
server_paths = g_slist_append(server_paths, g_strdup(pr->path));
create_path(pr->conn, pr->msg, pr->path, "ServerCreated");
@@ -490,7 +498,8 @@ static DBusHandlerResult create_server(DBusConnection *conn,
pr->addr = NULL;
pr->id = id;
pr->path = g_new0(char, MAX_PATH_LENGTH);
- snprintf(pr->path, MAX_PATH_LENGTH, NETWORK_PATH "/server/%s", bnep_name(id));
+ snprintf(pr->path, MAX_PATH_LENGTH, NETWORK_PATH"/server/%s%d",
+ bnep_name(id), net_uid++);
if (g_slist_find_custom(server_paths, pr->path,
(GCompareFunc) strcmp)) {
@@ -510,6 +519,7 @@ static DBusHandlerResult create_server(DBusConnection *conn,
static DBusHandlerResult remove_server(DBusConnection *conn,
DBusMessage *msg, void *data)
{
+ /* FIXME: Remove from the storage */
return remove_path(conn, msg, &server_paths, "ServerRemoved");
}
@@ -562,7 +572,6 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct pending_reply *pr;
- static int uid = 0;
DBusError derr;
const char *addr;
const char *str;
@@ -588,7 +597,8 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
pr->addr = g_strdup(addr);
pr->id = id;
pr->path = g_new0(char, MAX_PATH_LENGTH);
- snprintf(pr->path, MAX_PATH_LENGTH, NETWORK_PATH "/connection%d", uid++);
+ snprintf(pr->path, MAX_PATH_LENGTH,
+ NETWORK_PATH"/connection%d", net_uid++);
if (get_default_adapter(pr, default_adapter_reply) < 0) {
err_failed(conn, msg, "D-Bus path registration failed");
@@ -601,6 +611,7 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
static DBusHandlerResult remove_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
+ /* FIXME: Remove from the storage */
return remove_path(conn, msg, &connection_paths, "ConnectionRemoved");
}
@@ -677,14 +688,12 @@ static void stored_server(char *key, char *value, void *data)
const bdaddr_t *src = data;
uint16_t id;
- /* FIXME: we need change the path to support multiple sources */
-
ba2str(src, addr);
id = bnep_service_id(key);
- snprintf(path, MAX_PATH_LENGTH, "%s/server/%s", NETWORK_PATH, bnep_name(id));
+ snprintf(path, MAX_PATH_LENGTH, NETWORK_PATH"/server/%s%d",
+ bnep_name(id), net_uid++);
- if (server_register(connection, addr, path, id) < 0)
- error("Register (%s, %s) path failed", addr, path);
+ server_register(connection, addr, path, id);
}
static void register_stored_servers(void)
@@ -766,3 +775,45 @@ void network_exit(void)
bnep_cleanup();
bridge_cleanup();
}
+
+static inline int create_filename(char *buf, size_t size,
+ bdaddr_t *bdaddr, const char *name)
+{
+ char addr[18];
+
+ ba2str(bdaddr, addr);
+
+ return create_name(buf, size, STORAGEDIR, addr, name);
+}
+
+int network_del_stored_info(bdaddr_t *src, uint16_t uuid)
+{
+ char filename[PATH_MAX + 1];
+ const char *str;
+ int err;
+
+ create_filename(filename, PATH_MAX, src, "network");
+
+ str = bnep_uuid(uuid);
+
+ err = textfile_del(filename, str);
+
+ return err;
+}
+
+int network_store_info(bdaddr_t *src, uint16_t uuid, gboolean enable)
+{
+ char filename[PATH_MAX + 1];
+ const char *str;
+ int err;
+
+ create_filename(filename, PATH_MAX, src, "network");
+
+ str = bnep_uuid(uuid);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ err = textfile_put(filename, str, enable ? "1" : "0");
+
+ return err;
+}
diff --git a/network/manager.h b/network/manager.h
index d37ca3cd..d20b8dbd 100644
--- a/network/manager.h
+++ b/network/manager.h
@@ -23,3 +23,6 @@
int network_init(DBusConnection *conn);
void network_exit(void);
+
+int network_del_stored_info(bdaddr_t *src, uint16_t uuid);
+int network_store_info(bdaddr_t *src, uint16_t uuid, gboolean enable);
diff --git a/network/server.c b/network/server.c
index 2a3961ca..e1e27341 100644
--- a/network/server.c
+++ b/network/server.c
@@ -30,8 +30,6 @@
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
-#include <sys/file.h>
-#include <sys/stat.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/bnep.h>
@@ -51,8 +49,8 @@
#include "bridge.h"
#include "common.h"
+#include "manager.h"
#include "server.h"
-#include "textfile.h"
/* Pending Authorization */
struct pending_auth {
@@ -77,48 +75,6 @@ struct network_server {
static char netdev[16] = "bnep%d";
-static inline int create_filename(char *buf, size_t size,
- bdaddr_t *bdaddr, const char *name)
-{
- char addr[18];
-
- ba2str(bdaddr, addr);
-
- return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-static int del_stored_server_info(bdaddr_t *src, uint16_t uuid)
-{
- char filename[PATH_MAX + 1];
- const char *str;
- int err;
-
- create_filename(filename, PATH_MAX, src, "network");
-
- str = bnep_uuid(uuid);
-
- err = textfile_del(filename, str);
-
- return err;
-}
-
-static int store_server_info(bdaddr_t *src, uint16_t uuid, gboolean enable)
-{
- char filename[PATH_MAX + 1];
- const char *str;
- int err;
-
- create_filename(filename, PATH_MAX, src, "network");
-
- str = bnep_uuid(uuid);
-
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
- err = textfile_put(filename, str, enable ? "1" : "0");
-
- return err;
-}
-
static void pending_auth_free(struct pending_auth *pauth)
{
if (!pauth)
@@ -753,7 +709,7 @@ static DBusHandlerResult enable(DBusConnection *conn,
if (err < 0)
return err_failed(conn, msg, strerror(-err));
- store_server_info(&ns->src, ns->id, TRUE);
+ network_store_info(&ns->src, ns->id, TRUE);
return send_message_and_unref(conn, reply);
}
@@ -781,7 +737,7 @@ static DBusHandlerResult disable(DBusConnection *conn,
g_io_channel_unref(ns->io);
ns->io = NULL;
- store_server_info(&ns->src, ns->id, FALSE);
+ network_store_info(&ns->src, ns->id, FALSE);
return send_message_and_unref(conn, reply);
}
@@ -1002,8 +958,6 @@ static void server_free(struct network_server *ns)
g_io_channel_unref(ns->io);
}
- del_stored_server_info(&ns->src, ns->id);
-
g_free(ns);
}
@@ -1055,29 +1009,8 @@ int server_register(DBusConnection *conn, const char *addr, const char *path,
info("Registered server path:%s", ns->path);
- store_server_info(&ns->src, ns->id, FALSE);
-
return 0;
fail:
server_free(ns);
return -1;
}
-
-int read_server_uuid(bdaddr_t *src, uint16_t uuid, gboolean *enable)
-{
- char filename[PATH_MAX + 1], *buff;
- const char *str;
-
- create_filename(filename, PATH_MAX, src, "network");
-
- str = bnep_uuid(uuid);
- buff = textfile_get(filename, str);
- if (!buff)
- return -ENOENT;
-
- *enable = (strtol(buff, NULL, 10)) ? TRUE : FALSE;
-
- g_free(buff);
-
- return 0;
-}