chiark / gitweb /
Fix service file to match installed elogind binary location
[elogind.git] / src / libelogind / sd-bus / bus-message.c
index 7b121698998e6691dcb231093919f05e23a78e27..a9853e326558f8b50af6c99175255ca8d4cb4f6f 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#include "util.h"
-#include "utf8.h"
-#include "strv.h"
-#include "time-util.h"
-#include "memfd-util.h"
-
 #include "sd-bus.h"
-#include "bus-message.h"
+
+#include "alloc-util.h"
+#include "bus-gvariant.h"
 #include "bus-internal.h"
-#include "bus-type.h"
+#include "bus-message.h"
 #include "bus-signature.h"
-#include "bus-gvariant.h"
+#include "bus-type.h"
 #include "bus-util.h"
+#include "fd-util.h"
+#include "io-util.h"
+#include "memfd-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "time-util.h"
+#include "utf8.h"
+#include "util.h"
 
 static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
 
@@ -179,7 +181,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, b
                 if (!np)
                         goto poison;
         } else {
-                /* Initially, the header is allocated as part of of
+                /* Initially, the header is allocated as part of
                  * the sd_bus_message itself, let's replace it by
                  * dynamic data */
 
@@ -798,7 +800,7 @@ _public_ int sd_bus_message_new_method_errorf(
                 const char *format,
                 ...) {
 
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         va_list ap;
 
         assert_return(name, -EINVAL);
@@ -817,7 +819,7 @@ _public_ int sd_bus_message_new_method_errno(
                 int error,
                 const sd_bus_error *p) {
 
-        _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
 
         if (sd_bus_error_is_set(p))
                 return sd_bus_message_new_method_error(call, m, p);
@@ -827,8 +829,6 @@ _public_ int sd_bus_message_new_method_errno(
         return sd_bus_message_new_method_error(call, m, &berror);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_new_method_errnof(
                 sd_bus_message *call,
                 sd_bus_message **m,
@@ -836,7 +836,7 @@ _public_ int sd_bus_message_new_method_errnof(
                 const char *format,
                 ...) {
 
-        _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
         va_list ap;
 
         va_start(ap, format);
@@ -845,7 +845,6 @@ _public_ int sd_bus_message_new_method_errnof(
 
         return sd_bus_message_new_method_error(call, m, &berror);
 }
-#endif // 0
 
 void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
         assert(bus);
@@ -918,7 +917,9 @@ fail:
 }
 
 _public_ sd_bus_message* sd_bus_message_ref(sd_bus_message *m) {
-        assert_return(m, NULL);
+
+        if (!m)
+                return NULL;
 
         assert(m->n_ref > 0);
         m->n_ref++;
@@ -941,8 +942,6 @@ _public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
         return NULL;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type) {
         assert_return(m, -EINVAL);
         assert_return(type, -EINVAL);
@@ -988,7 +987,6 @@ _public_ int sd_bus_message_get_auto_start(sd_bus_message *m) {
 
         return !(m->header->flags & BUS_MESSAGE_NO_AUTO_START);
 }
-#endif // 0
 
 _public_ int sd_bus_message_get_allow_interactive_authorization(sd_bus_message *m) {
         assert_return(m, -EINVAL);
@@ -1036,8 +1034,6 @@ _public_ const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m) {
         return &m->error;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_get_monotonic_usec(sd_bus_message *m, uint64_t *usec) {
         assert_return(m, -EINVAL);
         assert_return(usec, -EINVAL);
@@ -1070,7 +1066,6 @@ _public_ int sd_bus_message_get_seqnum(sd_bus_message *m, uint64_t *seqnum) {
         *seqnum = m->seqnum;
         return 0;
 }
-#endif // 0
 
 _public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
         assert_return(m, NULL);
@@ -1081,8 +1076,6 @@ _public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
         return &m->creds;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_is_signal(
                 sd_bus_message *m,
                 const char *interface,
@@ -1101,7 +1094,6 @@ _public_ int sd_bus_message_is_signal(
 
         return 1;
 }
-#endif // 0
 
 _public_ int sd_bus_message_is_method_call(
                 sd_bus_message *m,
@@ -1134,17 +1126,12 @@ _public_ int sd_bus_message_is_method_error(sd_bus_message *m, const char *name)
         return 1;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_set_expect_reply(sd_bus_message *m, int b) {
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
         assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EPERM);
 
-        if (b)
-                m->header->flags &= ~BUS_MESSAGE_NO_REPLY_EXPECTED;
-        else
-                m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_NO_REPLY_EXPECTED, !b);
 
         return 0;
 }
@@ -1153,10 +1140,7 @@ _public_ int sd_bus_message_set_auto_start(sd_bus_message *m, int b) {
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
 
-        if (b)
-                m->header->flags &= ~BUS_MESSAGE_NO_AUTO_START;
-        else
-                m->header->flags |= BUS_MESSAGE_NO_AUTO_START;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_NO_AUTO_START, !b);
 
         return 0;
 }
@@ -1165,14 +1149,10 @@ _public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message *
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
 
-        if (b)
-                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
-        else
-                m->header->flags &= ~BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION, b);
 
         return 0;
 }
-#endif // 0
 
 static struct bus_container *message_get_container(sd_bus_message *m) {
         assert(m);
@@ -1209,7 +1189,7 @@ struct bus_body_part *message_append_part(sd_bus_message *m) {
 
         part->memfd = -1;
         m->body_end = part;
-        m->n_body_parts ++;
+        m->n_body_parts++;
 
         return part;
 }
@@ -1654,7 +1634,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         }
 
         if (type == SD_BUS_TYPE_UNIX_FD)
-                m->n_fds ++;
+                m->n_fds++;
 
         if (c->enclosing != SD_BUS_TYPE_ARRAY)
                 c->index++;
@@ -1667,8 +1647,6 @@ _public_ int sd_bus_message_append_basic(sd_bus_message *m, char type, const voi
         return message_append_basic(m, type, p, NULL);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_append_string_space(
                 sd_bus_message *m,
                 size_t size,
@@ -1759,7 +1737,6 @@ _public_ int sd_bus_message_append_string_iovec(
 
         return 0;
 }
-#endif // 0
 
 static int bus_message_open_array(
                 sd_bus_message *m,
@@ -2364,7 +2341,7 @@ static int type_stack_pop(TypeStack *stack, unsigned max, unsigned *i, const cha
         return 1;
 }
 
-int bus_message_append_ap(
+_public_ int sd_bus_message_appendv(
                 sd_bus_message *m,
                 const char *types,
                 va_list ap) {
@@ -2374,10 +2351,10 @@ int bus_message_append_ap(
         unsigned stack_ptr = 0;
         int r;
 
-        assert(m);
-
-        if (!types)
-                return 0;
+        assert_return(m, -EINVAL);
+        assert_return(types, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->poisoned, -ESTALE);
 
         n_array = (unsigned) -1;
         n_struct = strlen(types);
@@ -2401,9 +2378,9 @@ int bus_message_append_ap(
 
                 t = types;
                 if (n_array != (unsigned) -1)
-                        n_array --;
+                        n_array--;
                 else {
-                        types ++;
+                        types++;
                         n_struct--;
                 }
 
@@ -2578,14 +2555,12 @@ _public_ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
         assert_return(!m->poisoned, -ESTALE);
 
         va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
+        r = sd_bus_message_appendv(m, types, ap);
         va_end(ap);
 
         return r;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_append_array_space(
                 sd_bus_message *m,
                 char type,
@@ -2647,8 +2622,7 @@ _public_ int sd_bus_message_append_array(
         if (r < 0)
                 return r;
 
-        if (size > 0)
-                memcpy(p, ptr, size);
+        memcpy_safe(p, ptr, size);
 
         return 0;
 }
@@ -2863,7 +2837,6 @@ _public_ int sd_bus_message_append_string_memfd(
 
         return 0;
 }
-#endif // 0
 
 _public_ int sd_bus_message_append_strv(sd_bus_message *m, char **l) {
         char **i;
@@ -2892,7 +2865,7 @@ static int bus_message_close_header(sd_bus_message *m) {
 
         /* The actual user data is finished now, we just complete the
            variant and struct now (at least on gvariant). Remember
-           this position, so that during parsing we know where to to
+           this position, so that during parsing we know where to
            put the outer container end. */
         m->user_body_size = m->body_size;
 
@@ -3164,8 +3137,6 @@ static bool message_end_of_array(sd_bus_message *m, size_t index) {
         }
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
         assert_return(m, -EINVAL);
         assert_return(m->sealed, -EPERM);
@@ -3181,7 +3152,6 @@ _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
 
         return false;
 }
-#endif // 0
 
 static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) {
         struct bus_body_part *part;
@@ -3887,7 +3857,7 @@ static int build_struct_offsets(
                 if (r < 0)
                         return r;
                 if (r == 0 && p[n] != 0) /* except the last item */
-                        n_variable ++;
+                        n_variable++;
                 n_total++;
 
                 p += n;
@@ -4487,9 +4457,9 @@ static int message_read_ap(
 
                 t = types;
                 if (n_array != (unsigned) -1)
-                        n_array --;
+                        n_array--;
                 else {
-                        types ++;
+                        types++;
                         n_struct--;
                 }
 
@@ -5565,8 +5535,7 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti
         return message_append_field_string(m, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
         size_t total;
         void *p, *e;
@@ -5691,8 +5660,8 @@ int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str) {
         assert(str);
 
         r = bus_message_get_arg_skip(m, i, &type, NULL);
-                if (r < 0)
-                        return r;
+        if (r < 0)
+                return r;
 
         if (!IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH, SD_BUS_TYPE_SIGNATURE))
                 return -ENXIO;
@@ -5709,8 +5678,8 @@ int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv) {
         assert(strv);
 
         r = bus_message_get_arg_skip(m, i, &type, &contents);
-                if (r < 0)
-                        return r;
+        if (r < 0)
+                return r;
 
         if (type != SD_BUS_TYPE_ARRAY)
                 return -ENXIO;
@@ -5738,8 +5707,6 @@ _public_ const char* sd_bus_message_get_signature(sd_bus_message *m, int complet
         return strempty(c->signature);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_is_empty(sd_bus_message *m) {
         assert_return(m, -EINVAL);
 
@@ -5751,7 +5718,6 @@ _public_ int sd_bus_message_has_signature(sd_bus_message *m, const char *signatu
 
         return streq(strempty(m->root_container.signature), strempty(signature));
 }
-#endif // 0
 
 _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all) {
         bool done_something = false;
@@ -5832,8 +5798,6 @@ _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int
         return done_something;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char *contents) {
         const char *c;
         char t;
@@ -5858,7 +5822,6 @@ _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char
 
         return 1;
 }
-#endif // 0
 
 _public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
         assert_return(m, NULL);
@@ -5867,7 +5830,7 @@ _public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
 }
 
 int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
-        _cleanup_bus_message_unref_ sd_bus_message *n = NULL;
+        _cleanup_(sd_bus_message_unrefp) sd_bus_message *n = NULL;
         usec_t timeout;
         int r;
 
@@ -5951,8 +5914,7 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 int bus_message_append_sender(sd_bus_message *m, const char *sender) {
         assert(m);
         assert(sender);
@@ -5962,6 +5924,7 @@ int bus_message_append_sender(sd_bus_message *m, const char *sender) {
 
         return message_append_field_string(m, BUS_MESSAGE_HEADER_SENDER, SD_BUS_TYPE_STRING, sender, &m->sender);
 }
+#endif // 0
 
 _public_ int sd_bus_message_get_priority(sd_bus_message *m, int64_t *priority) {
         assert_return(m, -EINVAL);
@@ -5978,4 +5941,3 @@ _public_ int sd_bus_message_set_priority(sd_bus_message *m, int64_t priority) {
         m->priority = priority;
         return 0;
 }
-#endif // 0