add support for routing errors
This commit is contained in:
parent
c397e37a05
commit
edbc927b79
3 changed files with 40 additions and 8 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ CFLAGS_RELEASE=-O2 -ggdb
|
|||
|
||||
CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99
|
||||
|
||||
CFLAGS+=$(CFLAGS_RELEASE)
|
||||
CFLAGS+=$(CFLAGS_DEV)
|
||||
|
||||
jitterbug: util.c wire.c match.c server.c main.c
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
|
14
server.c
14
server.c
|
@ -224,10 +224,7 @@ int bus_client_assign_own_name(bus_t *s, int i, char *name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int name_index = bus_name_add(s, name, i);
|
||||
if (name_index < 0) {
|
||||
return -1;
|
||||
}
|
||||
int name_index = TRYST(bus_name_add(s, name, i));
|
||||
c->owned_name_index = name_index;
|
||||
|
||||
return 0;
|
||||
|
@ -429,16 +426,19 @@ int handle_request_name(bus_t *s, int i, wire_message_t *msg, wire_context_t *ct
|
|||
}
|
||||
|
||||
char *name = TRYPTR(wire_get_name_string(ctx));
|
||||
TRYPTR(wire_get_u32(ctx)); // unused flags
|
||||
uint32_t flags = *(uint32_t*)TRYPTR(wire_get_u32(ctx)); // unused flags
|
||||
|
||||
char *name_str = TRYPTR(string_dup(name));
|
||||
|
||||
int status_code = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
|
||||
|
||||
if (bus_client_assign_own_name(s, i, name_str) < 0) {
|
||||
free(name_str);
|
||||
// TODO: report the actual error
|
||||
status_code = DBUS_REQUEST_NAME_REPLY_EXISTS;
|
||||
|
||||
WARN("client '%s' (index=%d) couldn't acquire name '%s'\n", s->names[s->clients[i].owned_name_index].name, i, name_str);
|
||||
|
||||
free(name_str);
|
||||
}
|
||||
|
||||
_reply_begin("u") {
|
||||
|
@ -786,7 +786,7 @@ int bus_client_drain_messages(bus_t *s, int ci, uint8_t *data, uint32_t data_len
|
|||
#define _client_die(m) do { bus_client_error(s,i,m); continue; } while(0)
|
||||
int bus_turn(bus_t *s)
|
||||
{
|
||||
static const char agree_unix_fd[] = "AGREE_UNIX_FD\r\n";
|
||||
static const char agree_unix_fd[] = "ERROR\r\n";
|
||||
static const char auth_ok[] = "OK aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n";
|
||||
static const char auth_list[] = "REJECTED EXTERNAL\r\n";
|
||||
static const char auth_data[] = "DATA\r\n";
|
||||
|
|
32
wire.c
32
wire.c
|
@ -125,6 +125,7 @@ int wire_parse_message(wire_context_t *c, wire_message_t *msg)
|
|||
case DBUS_HEADER_FIELD_PATH: /* through */
|
||||
case DBUS_HEADER_FIELD_INTERFACE: /* through */
|
||||
case DBUS_HEADER_FIELD_MEMBER: /* through */
|
||||
case DBUS_HEADER_FIELD_ERROR_NAME: /* through */
|
||||
case DBUS_HEADER_FIELD_DESTINATION: {
|
||||
char *str = TRYPTR(wire_get_string(c));
|
||||
VERBOSE("field: %s\n", str);
|
||||
|
@ -470,6 +471,37 @@ int wire_compose_unicast_reply(wire_context_t *c, wire_context_t *msg_c, wire_me
|
|||
// last element, don't align
|
||||
} break;
|
||||
|
||||
case DBUS_MESSAGE_ERROR: {
|
||||
wire_message_field_t *reply_serial_field = &msg->fields[DBUS_HEADER_FIELD_REPLY_SERIAL];
|
||||
wire_message_field_t *error_name_field = &msg->fields[DBUS_HEADER_FIELD_ERROR_NAME];
|
||||
if (!reply_serial_field->present || !error_name_field->present) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TRYPTR(wire_set_u8(c, DBUS_HEADER_FIELD_REPLY_SERIAL));
|
||||
TRYPTR(wire_set_signature(c, "u"));
|
||||
TRYPTR(wire_set_u32(c, reply_serial_field->t.u32));
|
||||
TRYPTR(wire_write_align(c, 8));
|
||||
|
||||
wire_message_field_t *signature_field = &msg->fields[DBUS_HEADER_FIELD_SIGNATURE];
|
||||
if (signature_field->present) {
|
||||
TRYPTR(wire_set_u8(c, DBUS_HEADER_FIELD_SIGNATURE));
|
||||
TRYPTR(wire_set_signature(c, "g"));
|
||||
TRYPTR(wire_set_signature(c, signature_field->t.str));
|
||||
TRYPTR(wire_write_align(c, 8));
|
||||
}
|
||||
|
||||
TRYPTR(wire_set_u8(c, DBUS_HEADER_FIELD_ERROR_NAME));
|
||||
TRYPTR(wire_set_signature(c, "s"));
|
||||
TRYPTR(wire_set_string(c, error_name_field->t.str));
|
||||
TRYPTR(wire_write_align(c, 8));
|
||||
|
||||
TRYPTR(wire_set_u8(c, DBUS_HEADER_FIELD_SENDER));
|
||||
TRYPTR(wire_set_signature(c, "s"));
|
||||
TRYPTR(wire_set_string(c, sender_unique_name));
|
||||
// last element, don't align
|
||||
} break;
|
||||
|
||||
default: {
|
||||
return -1;
|
||||
} break;
|
||||
|
|
Loading…
Reference in a new issue