summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--network/manager.c42
-rw-r--r--network/server.c61
2 files changed, 92 insertions, 11 deletions
diff --git a/network/manager.c b/network/manager.c
index cc13ed62..720f4eb1 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -431,6 +431,45 @@ static DBusHandlerResult create_server(DBusConnection *conn,
return create_path(conn, msg, path, "ServerCreated");
}
+static DBusHandlerResult find_server(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 = server_paths; list; list = list->next) {
+ path = (const char *) list->data;
+ if (server_find_data(conn, path, pattern) == 0)
+ break;
+ }
+
+ if (list == NULL) {
+ err_failed(conn, msg, "No such server");
+ 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 remove_server(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -561,6 +600,9 @@ static DBusHandlerResult manager_message(DBusConnection *conn,
if (strcmp(member, "CreateServer") == 0)
return create_server(conn, msg, data);
+ if (strcmp(member, "FindServer") == 0)
+ return find_server(conn, msg, data);
+
if (strcmp(member, "RemoveServer") == 0)
return remove_server(conn, msg, data);
diff --git a/network/server.c b/network/server.c
index f50d1e06..0c22a67d 100644
--- a/network/server.c
+++ b/network/server.c
@@ -751,6 +751,24 @@ static DBusHandlerResult get_uuid(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+static int record_and_listen(struct network_server *ns)
+{
+ int err;
+
+ /* Add the service record */
+ ns->record_id = add_server_record(ns);
+ if (!ns->record_id) {
+ error("Unable to register the server(0x%x) service record", ns->id);
+ return -EIO;
+ }
+
+ err = l2cap_listen(ns);
+ if (err < 0)
+ return -err;
+
+ return 0;
+}
+
static DBusHandlerResult enable(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -776,15 +794,8 @@ static DBusHandlerResult enable(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- /* Add the service record */
- ns->record_id = add_server_record(ns);
- if (!ns->record_id) {
- error("Unable to register the server(0x%x) service record", ns->id);
- return err_failed(conn, msg, "Unable to register the service record");
- }
-
- err = l2cap_listen(ns);
- if (err < 0)
+ /* Add the service record and listen l2cap */
+ if ((err = record_and_listen(ns)) < 0)
return err_failed(conn, msg, strerror(-err));
store_property(&ns->src, ns->id, "enabled", "1");
@@ -1174,10 +1185,15 @@ int server_register_from_file(DBusConnection *conn, const char *path,
ns->range = textfile_get(filename, "address_range");
ns->iface = textfile_get(filename, "routing");
- /* FIXME: Missing enabled the server(if applied) */
-
info("Registered server path:%s", path);
+ str = textfile_get(filename, "enabled");
+ if (str) {
+ if (strcmp("1", str) == 0)
+ record_and_listen(ns);
+ g_free(str);
+ }
+
return 0;
}
@@ -1228,3 +1244,26 @@ int server_remove_stored(DBusConnection *conn, const char *path)
return remove(filename);
}
+
+int server_find_data(DBusConnection *conn,
+ const char *path, const char *pattern)
+{
+ struct network_server *ns;
+
+ if (!dbus_connection_get_object_path_data(conn, path, (void *) &ns))
+ return -1;
+
+ if (strcasecmp(pattern, ns->name) == 0)
+ return 0;
+
+ if (strcasecmp(pattern, ns->iface) == 0)
+ return 0;
+
+ if (strcasecmp(pattern, bnep_name(ns->id)) == 0)
+ return 0;
+
+ if (bnep_service_id(pattern) == ns->id)
+ return 0;
+
+ return -1;
+}