1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "bus-signature.h"
27 static int signature_element_length_internal(
29 bool allow_dict_entry,
31 unsigned struct_depth,
38 if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) {
43 if (*s == SD_BUS_TYPE_ARRAY) {
46 if (array_depth >= 32)
49 r = signature_element_length_internal(s + 1, true, array_depth+1, struct_depth, &t);
57 if (*s == SD_BUS_TYPE_STRUCT_BEGIN) {
58 const char *p = s + 1;
60 if (struct_depth >= 32)
63 while (*p != SD_BUS_TYPE_STRUCT_END) {
66 r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t);
77 if (*s == SD_BUS_TYPE_DICT_ENTRY_BEGIN && allow_dict_entry) {
78 const char *p = s + 1;
81 if (struct_depth >= 32)
84 while (*p != SD_BUS_TYPE_DICT_ENTRY_END) {
87 if (n == 0 && !bus_type_is_basic(*p))
90 r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t);
109 int signature_element_length(const char *s, size_t *l) {
110 return signature_element_length_internal(s, true, 0, 0, l);
113 bool signature_is_single(const char *s) {
119 r = signature_element_length(s, &t);
126 bool signature_is_pair(const char *s) {
129 if (!bus_type_is_basic(*s))
132 return signature_is_single(s + 1);
135 bool signature_is_valid(const char *s, bool allow_dict_entry) {
145 r = signature_element_length_internal(p, allow_dict_entry, 0, 0, &t);