From 98dcc4c630b4065784b7dc1325dd558b60453fe4 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Mon, 26 Dec 2022 18:05:12 +0200 Subject: [PATCH] implement more methods --- server.c | 41 +++++++++++++++++++++++++++++++++++++++++ server.h | 1 + wire.c | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/server.c b/server.c index ce3248f..e6c29c0 100644 --- a/server.c +++ b/server.c @@ -90,6 +90,7 @@ int jb_server_name_add(struct jb_server *s, char *name, int client_index) if (s->names[i].client_index == -1) { s->names[i].client_index = client_index; s->names[i].name = name; + s->names_count++; return i; } } @@ -154,6 +155,7 @@ void jb_server_name_remove(struct jb_server *s, int i) s->names[i].name = NULL; } s->names[i].client_index = -1; + s->names_count--; } } @@ -322,6 +324,45 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data, _reply_begin("b") { TRYPTR(wire_set_u32(&reply_ctx, target ? 1 : 0)); } _reply_end() + } else if (strcmp(member, "ListNames") == 0) { + _reply_begin("as") { + TRYPTR(wire_set_u32(&reply_ctx, s->names_count)); + + int left = s->names_count; + for (int i = 0; i < JB_MAX_NAMES; i++) { + if (s->names[i].name && s->names[i].client_index >= 0) { + left--; + TRYPTR(wire_set_string(&reply_ctx, s->names[i].name)); + } + if (left <= 0) { + break; + } + } + } _reply_end() + } else if (strcmp(member, "ListActivatableNames") == 0) { + // TODO: stub (always returns empty array) + printf("STUB: ListActivatableNames\n"); + + _reply_begin("as") { + TRYPTR(wire_set_u32(&reply_ctx, 0)); + // empty arrays still need to align + TRYPTR(wire_write_align(&reply_ctx, 4)); + } _reply_end() + } else if (strcmp(member, "StartServiceByName") == 0) { + // TODO: stub (does nothing and always returns success) + + char *name = TRYPTR(wire_get_string(&ctx, NULL)); + int name_len = strlen(name); + if (name_len < 1 || name_len > 256) { + return -1; + } + + printf("STUB: StartServiceByName: %s\n", name); + + _reply_begin("u") { + TRYPTR(wire_set_u32(&reply_ctx, 1)); + } _reply_end() + return 0; } else { _reply_error("org.freedesktop.DBus.Error.UnknownMethod"); return 0; diff --git a/server.h b/server.h index e7b4180..daf1ee3 100644 --- a/server.h +++ b/server.h @@ -31,6 +31,7 @@ struct jb_name { struct jb_server { int sock_fd; int fd_num; + int names_count; struct jb_client clients[JB_MAX_CLIENTS]; struct jb_name names[JB_MAX_NAMES]; struct pollfd fds[JB_MAX_CLIENTS + 1]; diff --git a/wire.c b/wire.c index 028691b..7669e40 100644 --- a/wire.c +++ b/wire.c @@ -130,6 +130,8 @@ int wire_parse_message(wire_context_t *c, wire_message_t *msg) size_t header_fields_end = c->byte_cursor + msg->header_fields_length; + printf("start parse message: type=%d\n", msg->type); + while (c->byte_cursor < header_fields_end) { uint8_t field_code = *(uint8_t*)TRYPTR(wire_get_u8(c)); TRYPTR(wire_get_signature(c, NULL)); @@ -169,6 +171,8 @@ int wire_parse_message(wire_context_t *c, wire_message_t *msg) } } + printf("end parse message\n"); + /* header ends at 8 byte boundry */ TRYPTR(wire_align(c, 8));