implement NameHasOwner

This commit is contained in:
hippoz 2022-12-25 21:42:40 +02:00
parent 0586219267
commit 18ec9899f7
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED

View file

@ -297,12 +297,9 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
return -1; return -1;
} }
char *name_str = string_dup(name); char *name_str = TRYPTR(string_dup(name));
if (!name_str) {
return -1;
}
struct jb_client *target = jb_server_name_find_client(s, destination_field->t.str); struct jb_client *target = jb_server_name_find_client(s, name_str);
if (!target || target->unique_name_index < 0) { if (!target || target->unique_name_index < 0) {
_reply_error("org.freedesktop.DBus.Error.NameHasNoOwner"); _reply_error("org.freedesktop.DBus.Error.NameHasNoOwner");
return 0; return 0;
@ -311,6 +308,20 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
_reply_begin("s") { _reply_begin("s") {
TRYPTR(wire_set_string(&reply_ctx, s->names[target->unique_name_index].name)); TRYPTR(wire_set_string(&reply_ctx, s->names[target->unique_name_index].name));
} _reply_end() } _reply_end()
} else if (strcmp(member, "NameHasOwner") == 0) {
char *name = TRYPTR(wire_get_string(&ctx, NULL));
int name_len = strlen(name);
if (name_len < 1 || name_len > 256) {
return -1;
}
char *name_str = TRYPTR(string_dup(name));
struct jb_client *target = jb_server_name_find_client(s, name_str);
_reply_begin("b") {
TRYPTR(wire_set_u32(&reply_ctx, target ? 1 : 0));
} _reply_end()
} else { } else {
_reply_error("org.freedesktop.DBus.Error.UnknownMethod"); _reply_error("org.freedesktop.DBus.Error.UnknownMethod");
return 0; return 0;
@ -327,7 +338,7 @@ int jb_server_client_process_message(struct jb_server *s, int i, uint8_t *data,
default: { default: {
_reply_error("xyz.hippoz.jitterbug.NotImplemented"); _reply_error("xyz.hippoz.jitterbug.NotImplemented");
return -1; return 0;
} break; } break;
} }