summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-04-12 18:15:13 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-04-12 18:15:13 +0000
commit1cbec5ebe8d67b1b4dcef1768efde2ac1ac51970 (patch)
treeb9ef527b7d3ff317db1cad71d5c17661dfdcad07 /network
parenta07ea139e52ab9733f6d1e9f0ab2e0bf232059ef (diff)
Add FindConnection method, bug fixes for disconnect events.
Diffstat (limited to 'network')
-rw-r--r--network/connection.c38
-rw-r--r--network/connection.h6
-rw-r--r--network/manager.c42
3 files changed, 78 insertions, 8 deletions
diff --git a/network/connection.c b/network/connection.c
index 341ffae4..278fa1cc 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -82,12 +82,16 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
struct network_conn *nc = data;
DBusMessage *signal;
- signal = dbus_message_new_signal(nc->path,
- NETWORK_CONNECTION_INTERFACE, "Disconnected");
+ if (nc->conn != NULL) {
+ signal = dbus_message_new_signal(nc->path,
+ NETWORK_CONNECTION_INTERFACE, "Disconnected");
- send_message_and_unref(nc->conn, signal);
+ send_message_and_unref(nc->conn, signal);
+ }
info("%s disconnected", nc->dev);
nc->state = DISCONNECTED;
+ memset(nc->dev, 0, 16);
+ strncpy(nc->dev, netdev, 16);
g_io_channel_close(chan);
g_io_channel_unref(chan);
return FALSE;
@@ -535,9 +539,6 @@ static void connection_free(struct network_conn *nc)
if (nc->state == CONNECTED)
bnep_kill_connection(&nc->dst);
- if (nc->dev)
- g_free(nc->dev);
-
if (nc->name)
g_free(nc->name);
@@ -545,6 +546,7 @@ static void connection_free(struct network_conn *nc)
g_free(nc->desc);
g_free(nc);
+ nc = NULL;
}
static void connection_unregister(DBusConnection *conn, void *data)
@@ -612,3 +614,27 @@ fail:
connection_free(nc);
return -1;
}
+
+int
+connection_find_data(DBusConnection *conn, const char *path,
+ const char *pattern)
+{
+ struct network_conn *nc;
+ char addr[18];
+
+ if (!dbus_connection_get_object_path_data(conn, path, &nc))
+ return -1;
+
+ if (strcmp(pattern, nc->dev) == 0)
+ return 0;
+
+ if (strcmp(pattern, nc->name) == 0)
+ return 0;
+
+ ba2str(&nc->dst, addr);
+
+ if (strcmp(pattern, addr) == 0)
+ return 0;
+
+ return -1;
+}
diff --git a/network/connection.h b/network/connection.h
index 08f36e1c..27bf2f69 100644
--- a/network/connection.h
+++ b/network/connection.h
@@ -22,5 +22,7 @@
*/
int connection_register(DBusConnection *conn, const char *path,
- const char *addr, uint16_t id,
- const sdp_record_t *rec);
+ const char *addr, uint16_t id,
+ const sdp_record_t *rec);
+int connection_find_data(DBusConnection *conn, const char *path,
+ const char *pattern);
diff --git a/network/manager.c b/network/manager.c
index 491b3845..d2b627db 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -519,6 +519,45 @@ static DBusHandlerResult list_connections(DBusConnection *conn,
return list_paths(conn, msg, connection_paths);
}
+static DBusHandlerResult find_connection(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusError derr;
+ const char *pattern;
+ const char *path;
+ GSList *list;
+ DBusMessage *reply;
+
+ dbus_error_init(&derr);
+ if (!dbus_message_get_args(msg, &derr,
+ DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID)) {
+ err_invalid_args(conn, msg, derr.message);
+ dbus_error_free(&derr);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ for (list = connection_paths; list; list = list->next) {
+ path = (const char *) list->data;
+ if (connection_find_data(conn, path, pattern) == 0)
+ break;
+ }
+
+ if (list == NULL) {
+ err_failed(conn, msg, "No such connection");
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+
+ return send_message_and_unref(conn, reply);
+}
+
static DBusHandlerResult create_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -594,6 +633,9 @@ static DBusHandlerResult manager_message(DBusConnection *conn,
if (strcmp(member, "ListConnections") == 0)
return list_connections(conn, msg, data);
+ if (strcmp(member, "FindConnection") == 0)
+ return find_connection(conn, msg, data);
+
if (strcmp(member, "CreateConnection") == 0)
return create_connection(conn, msg, data);