}
int bus_message_from_header(
+ sd_bus *bus,
void *buffer,
size_t length,
int *fds,
memcpy(m->label, label, label_sz + 1);
}
+ if (bus)
+ m->bus = sd_bus_ref(bus);
+
*ret = m;
return 0;
}
int bus_message_from_malloc(
+ sd_bus *bus,
void *buffer,
size_t length,
int *fds,
sd_bus_message *m;
int r;
- r = bus_message_from_header(buffer, length, fds, n_fds, ucred, label, 0, &m);
+ r = bus_message_from_header(bus, buffer, length, fds, n_fds, ucred, label, 0, &m);
if (r < 0)
return r;
}
static int message_new_reply(
- sd_bus *bus,
sd_bus_message *call,
uint8_t type,
sd_bus_message **m) {
sd_bus_message *t;
int r;
- assert_return(!bus || bus->state != BUS_UNSET, -ENOTCONN);
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
+ assert_return(!call->bus || call->bus->state != BUS_UNSET, -ENOTCONN);
assert_return(m, -EINVAL);
- t = message_new(bus, type);
+ t = message_new(call->bus, type);
if (!t)
return -ENOMEM;
}
_public_ int sd_bus_message_new_method_return(
- sd_bus *bus,
sd_bus_message *call,
sd_bus_message **m) {
- return message_new_reply(bus, call, SD_BUS_MESSAGE_METHOD_RETURN, m);
+ return message_new_reply(call, SD_BUS_MESSAGE_METHOD_RETURN, m);
}
_public_ int sd_bus_message_new_method_error(
- sd_bus *bus,
sd_bus_message *call,
const sd_bus_error *e,
sd_bus_message **m) {
assert_return(sd_bus_error_is_set(e), -EINVAL);
assert_return(m, -EINVAL);
- r = message_new_reply(bus, call, SD_BUS_MESSAGE_METHOD_ERROR, &t);
+ r = message_new_reply(call, SD_BUS_MESSAGE_METHOD_ERROR, &t);
if (r < 0)
return r;
}
_public_ int sd_bus_message_new_method_errorf(
- sd_bus *bus,
sd_bus_message *call,
sd_bus_message **m,
const char *name,
_cleanup_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
va_list ap;
- int r;
assert_return(name, -EINVAL);
assert_return(m, -EINVAL);
va_start(ap, format);
- r = bus_error_setfv(&error, name, format, ap);
+ bus_error_setfv(&error, name, format, ap);
va_end(ap);
- if (r < 0)
- return r;
-
- return sd_bus_message_new_method_error(bus, call, &error, m);
+ return sd_bus_message_new_method_error(call, &error, m);
}
_public_ int sd_bus_message_new_method_errno(
- sd_bus *bus,
sd_bus_message *call,
int error,
const sd_bus_error *p,
_cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
if (sd_bus_error_is_set(p))
- return sd_bus_message_new_method_error(bus, call, p, m);
+ return sd_bus_message_new_method_error(call, p, m);
sd_bus_error_set_errno(&berror, error);
- return sd_bus_message_new_method_error(bus, call, &berror, m);
+ return sd_bus_message_new_method_error(call, &berror, m);
}
_public_ int sd_bus_message_new_method_errnof(
- sd_bus *bus,
sd_bus_message *call,
sd_bus_message **m,
int error,
_cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
va_list ap;
- int r;
va_start(ap, format);
- r = bus_error_set_errnofv(&berror, error, format, ap);
+ bus_error_set_errnofv(&berror, error, format, ap);
va_end(ap);
- if (r < 0)
- return r;
-
- return sd_bus_message_new_method_error(bus, call, &berror, m);
+ return sd_bus_message_new_method_error(call, &berror, m);
}
int bus_message_new_synthetic_error(
return m->header->type == SD_BUS_MESSAGE_METHOD_CALL ? !!(m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) : 0;
}
+_public_ int sd_bus_message_get_no_auto_start(sd_bus_message *m) {
+ assert_return(m, -EINVAL);
+
+ return !!(m->header->flags & SD_BUS_MESSAGE_NO_AUTO_START);
+}
+
_public_ const char *sd_bus_message_get_path(sd_bus_message *m) {
assert_return(m, NULL);
return 0;
}
+_public_ int sd_bus_message_set_no_auto_start(sd_bus_message *m, int b) {
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+
+ if (b)
+ m->header->flags |= SD_BUS_MESSAGE_NO_AUTO_START;
+ else
+ m->header->flags &= ~SD_BUS_MESSAGE_NO_AUTO_START;
+
+ return 0;
+}
+
static struct bus_container *message_get_container(sd_bus_message *m) {
assert(m);
return message_append_basic(m, type, p, NULL);
}
-_public_ int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s) {
+_public_ int sd_bus_message_append_string_space(
+ sd_bus_message *m,
+ size_t size,
+ char **s) {
+
struct bus_container *c;
void *a;
return 0;
}
+_public_ int sd_bus_message_append_string_iovec(
+ sd_bus_message *m,
+ const struct iovec *iov,
+ unsigned n) {
+
+ size_t size;
+ unsigned i;
+ char *p;
+ int r;
+
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+ assert_return(iov || n == 0, -EINVAL);
+ assert_return(!m->poisoned, -ESTALE);
+
+ size = IOVEC_TOTAL_SIZE(iov, n);
+
+ r = sd_bus_message_append_string_space(m, size, &p);
+ if (r < 0)
+ return r;
+
+ for (i = 0; i < n; i++) {
+
+ if (iov[i].iov_base)
+ memcpy(p, iov[i].iov_base, iov[i].iov_len);
+ else
+ memset(p, ' ', iov[i].iov_len);
+
+ p += iov[i].iov_len;
+ }
+
+ return 0;
+}
+
static int bus_message_open_array(
sd_bus_message *m,
struct bus_container *c,
return r;
}
- return 0;
+ return 1;
}
_public_ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
return 0;
}
+_public_ int sd_bus_message_append_array_iovec(
+ sd_bus_message *m,
+ char type,
+ const struct iovec *iov,
+ unsigned n) {
+
+ size_t size;
+ unsigned i;
+ void *p;
+ int r;
+
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+ assert_return(bus_type_is_trivial(type), -EINVAL);
+ assert_return(iov || n == 0, -EINVAL);
+ assert_return(!m->poisoned, -ESTALE);
+
+ size = IOVEC_TOTAL_SIZE(iov, n);
+
+ r = sd_bus_message_append_array_space(m, type, size, &p);
+ if (r < 0)
+ return r;
+
+ for (i = 0; i < n; i++) {
+
+ if (iov[i].iov_base)
+ memcpy(p, iov[i].iov_base, iov[i].iov_len);
+ else
+ memset(p, 0, iov[i].iov_len);
+
+ p = (uint8_t*) p + iov[i].iov_len;
+ }
+
+ return 0;
+}
+
_public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
char type,
sd_memfd *memfd) {
return index >= c->begin + BUS_MESSAGE_BSWAP32(m, *c->array_size);
}
-int sd_bus_message_at_end(sd_bus_message *m, int complete) {
+_public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
- assert_return(m->n_containers > 0, -EINVAL);
+ assert_return(m->n_containers > 0, -ENXIO);
c = message_get_container(m);
if (c->enclosing == SD_BUS_TYPE_ARRAY) {
} else {
if (c->signature && c->signature[c->index] != 0)
- return -EINVAL;
+ return -EBUSY;
}
free(c->signature);
return !isempty(c->signature);
}
+
static int message_read_ap(
sd_bus_message *m,
const char *types,
return message_append_field_string(m, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
}
-int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
- const char *u = NULL, *uu = NULL, *s = NULL;
- char **cmdline = NULL;
- unsigned level = 1;
- int r;
- uid_t owner, audit_loginuid;
- uint32_t audit_sessionid;
-
- assert(m);
-
- if (!f)
- f = stdout;
-
- if (with_header) {
- fprintf(f,
- "Message %p\n"
- "\tn_ref=%u\n"
- "\tendian=%c\n"
- "\ttype=%i\n"
- "\tflags=%u\n"
- "\tversion=%u\n"
- "\tserial=%u\n"
- "\tfields_size=%u\n"
- "\tbody_size=%u\n"
- "\tpath=%s\n"
- "\tinterface=%s\n"
- "\tmember=%s\n"
- "\tdestination=%s\n"
- "\tsender=%s\n"
- "\tsignature=%s\n"
- "\treply_serial=%u\n"
- "\tsealed=%s\n"
- "\tn_body_parts=%u\n",
- m,
- m->n_ref,
- m->header->endian,
- m->header->type,
- m->header->flags,
- m->header->version,
- BUS_MESSAGE_SERIAL(m),
- BUS_MESSAGE_FIELDS_SIZE(m),
- BUS_MESSAGE_BODY_SIZE(m),
- strna(m->path),
- strna(m->interface),
- strna(m->member),
- strna(m->destination),
- strna(m->sender),
- strna(m->root_container.signature),
- m->reply_serial,
- yes_no(m->sealed),
- m->n_body_parts);
-
- if (sd_bus_error_is_set(&m->error))
- fprintf(f,
- "\terror.name=%s\n"
- "\terror.message=%s\n",
- strna(m->error.name),
- strna(m->error.message));
-
- if (m->pid != 0)
- fprintf(f, "\tpid=%lu\n", (unsigned long) m->pid);
- if (m->tid != 0)
- fprintf(f, "\ttid=%lu\n", (unsigned long) m->tid);
- if (m->uid_valid)
- fprintf(f, "\tuid=%lu\n", (unsigned long) m->uid);
- if (m->gid_valid)
- fprintf(f, "\tgid=%lu\n", (unsigned long) m->gid);
- if (m->pid_starttime != 0)
- fprintf(f, "\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime);
- if (m->monotonic != 0)
- fprintf(f, "\tmonotonic=%llu\n", (unsigned long long) m->monotonic);
- if (m->realtime != 0)
- fprintf(f, "\trealtime=%llu\n", (unsigned long long) m->realtime);
- if (m->exe)
- fprintf(f, "\texe=[%s]\n", m->exe);
- if (m->comm)
- fprintf(f, "\tcomm=[%s]\n", m->comm);
- if (m->tid_comm)
- fprintf(f, "\ttid_comm=[%s]\n", m->tid_comm);
- if (m->label)
- fprintf(f, "\tlabel=[%s]\n", m->label);
- if (m->cgroup)
- fprintf(f, "\tcgroup=[%s]\n", m->cgroup);
-
- sd_bus_message_get_unit(m, &u);
- if (u)
- fprintf(f, "\tunit=[%s]\n", u);
- sd_bus_message_get_user_unit(m, &uu);
- if (uu)
- fprintf(f, "\tuser_unit=[%s]\n", uu);
- sd_bus_message_get_session(m, &s);
- if (s)
- fprintf(f, "\tsession=[%s]\n", s);
- if (sd_bus_message_get_owner_uid(m, &owner) >= 0)
- fprintf(f, "\towner_uid=%lu\n", (unsigned long) owner);
- if (sd_bus_message_get_audit_loginuid(m, &audit_loginuid) >= 0)
- fprintf(f, "\taudit_loginuid=%lu\n", (unsigned long) audit_loginuid);
- if (sd_bus_message_get_audit_sessionid(m, &audit_sessionid) >= 0)
- fprintf(f, "\taudit_sessionid=%lu\n", (unsigned long) audit_sessionid);
-
- r = sd_bus_message_has_effective_cap(m, 5);
- if (r >= 0)
- fprintf(f, "\tCAP_KILL=%s\n", yes_no(r));
-
- if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
- char **c;
-
- fputs("\tcmdline=[", f);
- STRV_FOREACH(c, cmdline) {
- if (c != cmdline)
- fputc(' ', f);
-
- fputs(*c, f);
- }
-
- fputs("]\n", f);
- }
- }
-
- r = sd_bus_message_rewind(m, true);
- if (r < 0) {
- log_error("Failed to rewind: %s", strerror(-r));
- return r;
- }
-
- fprintf(f, "MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
-
- for(;;) {
- _cleanup_free_ char *prefix = NULL;
- const char *contents = NULL;
- char type;
- union {
- uint8_t u8;
- uint16_t u16;
- int16_t s16;
- uint32_t u32;
- int32_t s32;
- uint64_t u64;
- int64_t s64;
- double d64;
- const char *string;
- int i;
- } basic;
-
- r = sd_bus_message_peek_type(m, &type, &contents);
- if (r < 0) {
- log_error("Failed to peek type: %s", strerror(-r));
- return r;
- }
-
- if (r == 0) {
- if (level <= 1)
- break;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0) {
- log_error("Failed to exit container: %s", strerror(-r));
- return r;
- }
-
- level--;
-
- prefix = strrep("\t", level);
- if (!prefix)
- return log_oom();
-
- fprintf(f, "%s};\n", prefix);
- continue;
- }
-
- prefix = strrep("\t", level);
- if (!prefix)
- return log_oom();
-
- if (bus_type_is_container(type) > 0) {
- r = sd_bus_message_enter_container(m, type, contents);
- if (r < 0) {
- log_error("Failed to enter container: %s", strerror(-r));
- return r;
- }
-
- if (type == SD_BUS_TYPE_ARRAY)
- fprintf(f, "%sARRAY \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_VARIANT)
- fprintf(f, "%sVARIANT \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_STRUCT)
- fprintf(f, "%sSTRUCT \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_DICT_ENTRY)
- fprintf(f, "%sDICT_ENTRY \"%s\" {\n", prefix, contents);
-
- level ++;
-
- continue;
- }
-
- r = sd_bus_message_read_basic(m, type, &basic);
- if (r < 0) {
- log_error("Failed to get basic: %s", strerror(-r));
- return r;
- }
-
- assert(r > 0);
-
- switch (type) {
-
- case SD_BUS_TYPE_BYTE:
- fprintf(f, "%sBYTE %u;\n", prefix, basic.u8);
- break;
-
- case SD_BUS_TYPE_BOOLEAN:
- fprintf(f, "%sBOOLEAN %s;\n", prefix, yes_no(basic.i));
- break;
-
- case SD_BUS_TYPE_INT16:
- fprintf(f, "%sINT16 %i;\n", prefix, basic.s16);
- break;
-
- case SD_BUS_TYPE_UINT16:
- fprintf(f, "%sUINT16 %u;\n", prefix, basic.u16);
- break;
-
- case SD_BUS_TYPE_INT32:
- fprintf(f, "%sINT32 %i;\n", prefix, basic.s32);
- break;
-
- case SD_BUS_TYPE_UINT32:
- fprintf(f, "%sUINT32 %u;\n", prefix, basic.u32);
- break;
-
- case SD_BUS_TYPE_INT64:
- fprintf(f, "%sINT64 %lli;\n", prefix, (long long) basic.s64);
- break;
-
- case SD_BUS_TYPE_UINT64:
- fprintf(f, "%sUINT64 %llu;\n", prefix, (unsigned long long) basic.u64);
- break;
-
- case SD_BUS_TYPE_DOUBLE:
- fprintf(f, "%sDOUBLE %g;\n", prefix, basic.d64);
- break;
-
- case SD_BUS_TYPE_STRING:
- fprintf(f, "%sSTRING \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_OBJECT_PATH:
- fprintf(f, "%sOBJECT_PATH \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_SIGNATURE:
- fprintf(f, "%sSIGNATURE \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_UNIX_FD:
- fprintf(f, "%sUNIX_FD %i;\n", prefix, basic.i);
- break;
-
- default:
- assert_not_reached("Unknown basic type.");
- }
- }
-
- fprintf(f, "};\n");
- return 0;
-}
-
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
size_t total;
void *p, *e;
return 1;
}
+
+_public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
+ assert_return(m, NULL);
+
+ return m->bus;
+}