summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-16 13:13:58 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-16 13:13:58 +0000
commit417006053c2c16cd8ae5b947d0a8daae4f151b94 (patch)
tree0373b1b5a2076c1d4ae0d906822dff44525007be
parentd342f2a2b1457a25c50cb661afb56f10595b925c (diff)
Fixes storage problems with connections and fix bug of CreateConnection not checking for present connection with the same destination and profile.
-rw-r--r--network/connection.c38
-rw-r--r--network/connection.h1
-rw-r--r--network/manager.c57
3 files changed, 85 insertions, 11 deletions
diff --git a/network/connection.c b/network/connection.c
index 4f57e93a..68c53b7b 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
-
+#include <sys/stat.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
@@ -702,19 +702,21 @@ int connection_store(DBusConnection *conn, const char *path)
ba2str(&nc->src, src_addr);
create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "network");
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
err = textfile_put(filename, key, value);
g_free(value);
- return err;
+ return err;
}
int connection_find_data(DBusConnection *conn,
const char *path, const char *pattern)
{
struct network_conn *nc;
- char addr[18];
+ char addr[18], key[32];
+ const char *role;
if (!dbus_connection_get_object_user_data(conn, path, (void *) &nc))
return -1;
@@ -730,6 +732,12 @@ int connection_find_data(DBusConnection *conn,
if (strcasecmp(pattern, addr) == 0)
return 0;
+ role = bnep_name(nc->id);
+ snprintf(key, 32, "%s#%s", addr, role);
+
+ if (strcasecmp(pattern, key) == 0)
+ return 0;
+
return -1;
}
@@ -742,3 +750,27 @@ gboolean connection_has_pending(DBusConnection *conn, const char *path)
return (nc->state == CONNECTING);
}
+
+int connection_remove_stored(DBusConnection *conn, const char *path)
+{
+ struct network_conn *nc;
+ const char *role;
+ char key[32];
+ char filename[PATH_MAX + 1];
+ char src_addr[18], dst_addr[18];
+ int err;
+
+ if (!dbus_connection_get_object_user_data(conn, path, (void *) &nc))
+ return -ENOENT;
+
+ ba2str(&nc->dst, dst_addr);
+ role = bnep_name(nc->id);
+ snprintf(key, 32, "%s#%s", dst_addr, role);
+
+ ba2str(&nc->src, src_addr);
+ create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "network");
+
+ err = textfile_del(filename, key);
+
+ return err;
+}
diff --git a/network/connection.h b/network/connection.h
index 205e44da..ff33789f 100644
--- a/network/connection.h
+++ b/network/connection.h
@@ -24,6 +24,7 @@
int connection_register(DBusConnection *conn, const char *path, bdaddr_t *src,
bdaddr_t *dst, uint16_t id, const char *name, const char *desc);
int connection_store(DBusConnection *conn, const char *path);
+int connection_remove_stored(DBusConnection *conn, const char *path);
int connection_find_data(DBusConnection *conn, const char *path,
const char *pattern);
gboolean connection_has_pending(DBusConnection *conn, const char *path);
diff --git a/network/manager.c b/network/manager.c
index b61233c9..8eac0bee 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -161,8 +161,15 @@ static DBusHandlerResult remove_path(DBusConnection *conn,
if (!l)
return err_does_not_exist(conn, msg, "Path doesn't exist");
- if (*list == connection_paths && connection_has_pending (conn, path))
- return err_failed(conn, msg, "Connection is Busy");
+ /* Remove references from the storage */
+ if (*list == connection_paths) {
+ if (connection_has_pending (conn, path))
+ return err_failed(conn, msg, "Connection is Busy");
+
+ connection_remove_stored(conn, path);
+ }
+ else
+ server_remove_stored(conn, path);
g_free(l->data);
*list = g_slist_remove(*list, l->data);
@@ -171,8 +178,6 @@ static DBusHandlerResult remove_path(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- /* Remove the nap or gn file from the file system */
- server_remove_stored(conn, path);
if (!dbus_connection_destroy_object_path(conn, path))
error("Network path unregister failed");
@@ -524,6 +529,8 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
bdaddr_t src;
uint16_t id;
int dev_id;
+ char key[32];
+ GSList *l;
dbus_error_init(&derr);
if (!dbus_message_get_args(msg, &derr,
@@ -539,6 +546,17 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
if ((id != BNEP_SVC_GN) && (id != BNEP_SVC_NAP))
return err_invalid_args(conn, msg, "Not supported");
+ snprintf(key, 32, "%s#%s", addr, bnep_name(id));
+
+ /* Checks if the connection was already been made */
+ for (l = connection_paths; l; l = l->next) {
+ if (connection_find_data(conn, l->data, key) == 0) {
+ err_already_exists(conn, msg,
+ "Connection Already exists");
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+
bacpy(&src, BDADDR_ANY);
dev_id = hci_get_route(NULL);
if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0))
@@ -644,8 +662,13 @@ static void parse_stored_connection(char *key, char *value, void *data)
if (connection_register(connection, path, src,
&dst, id, name, ptr) == 0) {
- connection_paths = g_slist_append(connection_paths,
- g_strdup(path));
+ char *rpath = g_strdup(path);
+ connection_paths = g_slist_append(connection_paths, rpath);
+ dbus_connection_emit_signal(connection, NETWORK_PATH,
+ NETWORK_MANAGER_INTERFACE,
+ "ConnectionCreated",
+ DBUS_TYPE_STRING, &rpath,
+ DBUS_TYPE_INVALID);
}
g_free(name);
@@ -688,9 +711,18 @@ static void register_stored(void)
NETWORK_PATH"/server/nap%d", net_uid++);
if (server_register_from_file(connection, path,
- &src, BNEP_SVC_NAP, filename) == 0)
+ &src, BNEP_SVC_NAP, filename) == 0) {
server_paths = g_slist_append(server_paths,
g_strdup(path));
+
+ dbus_connection_emit_signal(connection,
+ NETWORK_PATH,
+ NETWORK_MANAGER_INTERFACE,
+ "ServerCreated",
+ DBUS_TYPE_STRING,
+ &path,
+ DBUS_TYPE_INVALID);
+ }
}
/* GN objects */
@@ -700,9 +732,18 @@ static void register_stored(void)
NETWORK_PATH"/server/gn%d", net_uid++);
if (server_register_from_file(connection, path,
- &src, BNEP_SVC_GN, filename) == 0)
+ &src, BNEP_SVC_GN, filename) == 0) {
server_paths = g_slist_append(server_paths,
g_strdup(path));
+
+ dbus_connection_emit_signal(connection,
+ NETWORK_PATH,
+ NETWORK_MANAGER_INTERFACE,
+ "ServerCreated",
+ DBUS_TYPE_STRING,
+ &path,
+ DBUS_TYPE_INVALID);
+ }
}
}