aboutsummaryrefslogtreecommitdiff
path: root/src/npassd/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/npassd/service.c')
-rw-r--r--src/npassd/service.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/npassd/service.c b/src/npassd/service.c
index f69ac22..5996ddc 100644
--- a/src/npassd/service.c
+++ b/src/npassd/service.c
@@ -15,6 +15,8 @@ static int handle_search_items(sd_bus_message *msg, void *data,
sd_bus_error *ret_error);
static int handle_create_collection(sd_bus_message *msg, void *data,
sd_bus_error *ret_error);
+static int handle_read_alias(sd_bus_message *msg, void *data,
+ sd_bus_error *ret_error);
static const sd_bus_vtable service_vtable[] = {
SD_BUS_VTABLE_START(0),
@@ -24,6 +26,8 @@ static const sd_bus_vtable service_vtable[] = {
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("CreateCollection", "a{sv}s", "oo",
handle_create_collection, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("ReadAlias", "s", "o", handle_read_alias,
+ SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END,
};
@@ -112,6 +116,48 @@ static int handle_create_collection(sd_bus_message *msg, void *data,
return ret;
}
+static int handle_read_alias(sd_bus_message *msg, void *data,
+ __attribute__((unused)) sd_bus_error *ret_error)
+{
+ struct service *service = data;
+ struct collection *collection;
+ const char *alias;
+ int ret;
+
+ ret = sd_bus_message_read(msg, "s", &alias);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = collection_alias_search(&service->collections, alias,
+ &collection);
+ if (ret >= 0) {
+ ret = sd_bus_reply_method_return(msg, "o", collection->path);
+ if (ret < 0)
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = collection_db_alias_read(service->bus, service->db, &collection,
+ alias);
+ if (ret < 0) {
+ ret = sd_bus_reply_method_return(msg, "o", "/");
+ if (ret < 0)
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = sd_bus_reply_method_return(msg, "o", collection->path);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ LIST_INSERT_HEAD(&service->collections, collection, dlist);
+ return ret;
+}
+
static int handle_open_session(sd_bus_message *msg, void *data,
sd_bus_error *ret_error)
{