Compare commits

..

2 commits

Author SHA1 Message Date
hippoz
05f7a1ae41
implement GetNameOwner 2022-12-24 16:03:55 +02:00
hippoz
3da74dd1ae
remove old debug logging 2022-12-24 00:52:12 +02:00
2 changed files with 39 additions and 6 deletions

View file

@ -277,6 +277,44 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
if (status_code == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { if (status_code == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
printf("client '%s' (index=%d) now owns name '%s'\n", s->names[client->unique_name_index].name, i, name_str); printf("client '%s' (index=%d) now owns name '%s'\n", s->names[client->unique_name_index].name, i, name_str);
} }
} else if (strcmp(member, "GetNameOwner") == 0) {
char *name = TRY_NONNULL(char*, wire_get_string(&ctx, NULL), -1);
int name_len = strlen(name);
if (name_len < 1 || name_len > 256) {
return -1;
}
char *name_str = string_dup(name);
if (!name_str) {
return -1;
}
struct jb_client *target = jb_server_name_find_client(s, destination_field->t.str);
if (!target || target->unique_name_index < 0) {
uint8_t error_reply_data[512];
memset(error_reply_data, 0, 512);
wire_context_t error_reply_ctx = {
.byte_cursor = 0,
.data = error_reply_data,
.data_len = 511,
};
TRY_NONNEGATIVE(int, wire_compose_error(&error_reply_ctx, &msg, "org.freedesktop.DBus.Error.NameHasNoOwner"), -1);
if (send(s->fds[i].fd, error_reply_data, error_reply_ctx.byte_cursor, 0) != error_reply_ctx.byte_cursor) {
return -1;
}
return 0;
}
uint32_t *body_length;
TRY_NONNEGATIVE(int, wire_compose_reply(&reply_ctx, &msg, "s", &body_length), -1);
uint32_t body_start = reply_ctx.byte_cursor;
TRY_NONNULL(char*, wire_set_string(&reply_ctx, s->names[target->unique_name_index].name), -1);
*body_length = reply_ctx.byte_cursor - body_start;
if (send(s->fds[i].fd, reply_data, reply_ctx.byte_cursor, 0) != reply_ctx.byte_cursor) {
return -1;
}
printf("%s\n", s->names[target->unique_name_index].name);
} else { } else {
TRY_NONNEGATIVE(int, wire_compose_error(&reply_ctx, &msg, "org.freedesktop.DBus.Error.UnknownMethod"), -1); TRY_NONNEGATIVE(int, wire_compose_error(&reply_ctx, &msg, "org.freedesktop.DBus.Error.UnknownMethod"), -1);
if (send(s->fds[i].fd, reply_data, reply_ctx.byte_cursor, 0) != reply_ctx.byte_cursor) { if (send(s->fds[i].fd, reply_data, reply_ctx.byte_cursor, 0) != reply_ctx.byte_cursor) {
@ -307,7 +345,6 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
if (client->unique_name_index < 0 || !destination_field->present) { if (client->unique_name_index < 0 || !destination_field->present) {
return -1; return -1;
} }
printf("sending unicast message from %s\n", s->names[client->unique_name_index].name);
struct jb_client *target = jb_server_name_find_client(s, destination_field->t.str); struct jb_client *target = jb_server_name_find_client(s, destination_field->t.str);
if (!target) { if (!target) {
uint8_t error_reply_data[512]; uint8_t error_reply_data[512];
@ -317,7 +354,7 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
.data = error_reply_data, .data = error_reply_data,
.data_len = 511, .data_len = 511,
}; };
TRY_NONNEGATIVE(int, wire_compose_error(&error_reply_ctx, &msg, "xyz.hippoz.jitterbug.NotImplemented"), -1); TRY_NONNEGATIVE(int, wire_compose_error(&error_reply_ctx, &msg, "org.freedesktop.DBus.Error.NameHasNoOwner"), -1);
if (send(s->fds[i].fd, error_reply_data, error_reply_ctx.byte_cursor, 0) != error_reply_ctx.byte_cursor) { if (send(s->fds[i].fd, error_reply_data, error_reply_ctx.byte_cursor, 0) != error_reply_ctx.byte_cursor) {
return -1; return -1;
} }

4
wire.c
View file

@ -130,8 +130,6 @@ int wire_parse_message(wire_context_t *c, wire_message_t *msg)
size_t header_fields_end = c->byte_cursor + msg->header_fields_length; size_t header_fields_end = c->byte_cursor + msg->header_fields_length;
printf(" > start parse!\n");
while (c->byte_cursor < header_fields_end) { while (c->byte_cursor < header_fields_end) {
uint8_t field_code = *TRY_NONNULL(uint8_t*, wire_get_u8(c), -1); uint8_t field_code = *TRY_NONNULL(uint8_t*, wire_get_u8(c), -1);
TRY_NONNULL(char*, wire_get_signature(c, NULL), -1); TRY_NONNULL(char*, wire_get_signature(c, NULL), -1);
@ -171,8 +169,6 @@ int wire_parse_message(wire_context_t *c, wire_message_t *msg)
} }
} }
printf(" > parsed!!\n");
/* header ends at 8 byte boundry */ /* header ends at 8 byte boundry */
TRY_NONNULL(bool, wire_align(c, 8), -1); TRY_NONNULL(bool, wire_align(c, 8), -1);