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,
36 assert_return(s, -EINVAL);
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) {
118 assert_return(s, false);
120 r = signature_element_length_internal(s, allow_dict_entry, 0, 0, &t);
127 bool signature_is_pair(const char *s) {
129 assert_return(s, false);
131 if (!bus_type_is_basic(*s))
134 return signature_is_single(s + 1, false);
137 bool signature_is_valid(const char *s, bool allow_dict_entry) {
141 assert_return(s, false);
147 r = signature_element_length_internal(p, allow_dict_entry, 0, 0, &t);