bus-introspect.c revision 07630cea1f3a845c09309f197ac7c4f11edd3b62
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "bus-internal.h"
#include "bus-protocol.h"
#include "bus-signature.h"
#include "string-util.h"
#include "util.h"
#include "bus-introspect.h"
assert(i);
zero(*i);
if (!i->f)
return -ENOMEM;
"<node>\n", i->f);
return 0;
}
assert(i);
if (object_manager)
return 0;
}
char *node;
assert(i);
while ((node = set_steal_first(s))) {
const char *e;
if (e && e[0])
fprintf(i->f, " <node name=\"%s\"/>\n", e);
}
return 0;
}
if (flags & SD_BUS_VTABLE_DEPRECATED)
fputs(" <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
fputs(" <annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n", i->f);
fputs(" <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
fputs(" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n", i->f);
else if (flags & SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION)
fputs(" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"invalidates\"/>\n", i->f);
else if (!(flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE))
fputs(" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"false\"/>\n", i->f);
}
if (!i->trusted &&
fputs(" <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
}
static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) {
int r;
for (;;) {
size_t l;
if (!*signature)
return 0;
r = signature_element_length(signature, &l);
if (r < 0)
return r;
if (direction)
else
fputs("/>\n", i->f);
signature += l;
}
}
assert(i);
assert(v);
for (; v->type != _SD_BUS_VTABLE_END; v++) {
/* Ignore methods, signals and properties that are
* marked "hidden", but do show the interface
* itself */
continue;
switch (v->type) {
case _SD_BUS_VTABLE_START:
if (v->flags & SD_BUS_VTABLE_DEPRECATED)
fputs(" <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
break;
case _SD_BUS_VTABLE_METHOD:
fputs(" </method>\n", i->f);
break;
case _SD_BUS_VTABLE_PROPERTY:
fprintf(i->f, " <property name=\"%s\" type=\"%s\" access=\"%s\">\n",
fputs(" </property>\n", i->f);
break;
case _SD_BUS_VTABLE_SIGNAL:
fputs(" </signal>\n", i->f);
break;
}
}
return 0;
}
int introspect_finish(struct introspect *i, sd_bus *bus, sd_bus_message *m, sd_bus_message **reply) {
sd_bus_message *q;
int r;
assert(i);
assert(m);
fputs("</node>\n", i->f);
r = fflush_and_check(i->f);
if (r < 0)
return r;
r = sd_bus_message_new_method_return(m, &q);
if (r < 0)
return r;
if (r < 0) {
return r;
}
*reply = q;
return 0;
}
void introspect_free(struct introspect *i) {
assert(i);
safe_fclose(i->f);
free(i->introspection);
zero(*i);
}