Compare commits

...

2 commits

Author SHA1 Message Date
hippoz
27a8487583
compile with address sanitizer 2022-12-26 18:05:26 +02:00
hippoz
98dcc4c630
implement more methods 2022-12-26 18:05:12 +02:00
4 changed files with 47 additions and 1 deletions

View file

@ -1,5 +1,5 @@
CC?=gcc CC?=gcc
CFLAGS+=-Werror -Wall -Wextra -std=c99 -ggdb CFLAGS+=-Werror -Wall -Wextra -std=c99 -ggdb -fsanitize=address
jitterbug: wire.c server.c main.c jitterbug: wire.c server.c main.c
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^

View file

@ -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) { if (s->names[i].client_index == -1) {
s->names[i].client_index = client_index; s->names[i].client_index = client_index;
s->names[i].name = name; s->names[i].name = name;
s->names_count++;
return i; 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].name = NULL;
} }
s->names[i].client_index = -1; 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") { _reply_begin("b") {
TRYPTR(wire_set_u32(&reply_ctx, target ? 1 : 0)); TRYPTR(wire_set_u32(&reply_ctx, target ? 1 : 0));
} _reply_end() } _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 { } else {
_reply_error("org.freedesktop.DBus.Error.UnknownMethod"); _reply_error("org.freedesktop.DBus.Error.UnknownMethod");
return 0; return 0;

View file

@ -31,6 +31,7 @@ struct jb_name {
struct jb_server { struct jb_server {
int sock_fd; int sock_fd;
int fd_num; int fd_num;
int names_count;
struct jb_client clients[JB_MAX_CLIENTS]; struct jb_client clients[JB_MAX_CLIENTS];
struct jb_name names[JB_MAX_NAMES]; struct jb_name names[JB_MAX_NAMES];
struct pollfd fds[JB_MAX_CLIENTS + 1]; struct pollfd fds[JB_MAX_CLIENTS + 1];

4
wire.c
View file

@ -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; 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) { while (c->byte_cursor < header_fields_end) {
uint8_t field_code = *(uint8_t*)TRYPTR(wire_get_u8(c)); uint8_t field_code = *(uint8_t*)TRYPTR(wire_get_u8(c));
TRYPTR(wire_get_signature(c, NULL)); 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 */ /* header ends at 8 byte boundry */
TRYPTR(wire_align(c, 8)); TRYPTR(wire_align(c, 8));