2 This file is part of systemd.
4 Copyright 2013 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "bus-signature.h"
25 static int signature_element_length_internal(
27 bool allow_dict_entry,
29 unsigned struct_depth,
39 if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) {
44 if (*s == SD_BUS_TYPE_ARRAY) {
47 if (array_depth >= 32)
50 r = signature_element_length_internal(s + 1, true, array_depth+1, struct_depth, &t);
58 if (*s == SD_BUS_TYPE_STRUCT_BEGIN) {
59 const char *p = s + 1;
61 if (struct_depth >= 32)
64 while (*p != SD_BUS_TYPE_STRUCT_END) {
67 r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t);
78 if (*s == SD_BUS_TYPE_DICT_ENTRY_BEGIN && allow_dict_entry) {
79 const char *p = s + 1;
82 if (struct_depth >= 32)
85 while (*p != SD_BUS_TYPE_DICT_ENTRY_END) {
88 if (n == 0 && !bus_type_is_basic(*p))
91 r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t);
110 int signature_element_length(const char *s, size_t *l) {
111 return signature_element_length_internal(s, true, 0, 0, l);
114 bool signature_is_single(const char *s, bool allow_dict_entry) {
121 r = signature_element_length_internal(s, allow_dict_entry, 0, 0, &t);
128 bool signature_is_pair(const char *s) {
133 if (!bus_type_is_basic(*s))
136 return signature_is_single(s + 1, false);
139 bool signature_is_valid(const char *s, bool allow_dict_entry) {
150 r = signature_element_length_internal(p, allow_dict_entry, 0, 0, &t);