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/>.
22 #include "bus-internal.h"
24 bool object_path_is_valid(const char *p) {
37 for (slash = true, q = p+1; *q; q++)
47 (*q >= 'a' && *q <= 'z') ||
48 (*q >= 'A' && *q <= 'Z') ||
49 (*q >= '0' && *q <= '9') ||
64 bool interface_name_is_valid(const char *p) {
71 for (dot = true, q = p; *q; q++)
76 found_dot = dot = true;
81 (*q >= 'a' && *q <= 'z') ||
82 (*q >= 'A' && *q <= 'Z') ||
83 (!dot && *q >= '0' && *q <= '9') ||
104 bool service_name_is_valid(const char *p) {
106 bool dot, found_dot, unique;
111 unique = p[0] == ':';
113 for (dot = true, q = unique ? p+1 : p; *q; q++)
118 found_dot = dot = true;
123 (*q >= 'a' && *q <= 'z') ||
124 (*q >= 'A' && *q <= 'Z') ||
125 ((!dot || unique) && *q >= '0' && *q <= '9') ||
126 *q == '_' || *q == '-';
146 bool member_name_is_valid(const char *p) {
152 for (q = p; *q; q++) {
156 (*q >= 'a' && *q <= 'z') ||
157 (*q >= 'A' && *q <= 'Z') ||
158 (*q >= '0' && *q <= '9') ||
171 static bool complex_pattern_check(char c, const char *a, const char *b) {
172 bool separator = false;
182 return (separator && (*a == 0 || *b == 0)) ||
183 (*a == 0 && *b == c && b[1] == 0) ||
184 (*b == 0 && *a == c && a[1] == 0);
195 bool namespace_complex_pattern(const char *pattern, const char *value) {
196 return complex_pattern_check('.', pattern, value);
199 bool path_complex_pattern(const char *pattern, const char *value) {
200 return complex_pattern_check('/', pattern, value);
203 static bool simple_pattern_check(char c, const char *a, const char *b) {
213 return *a == 0 && *b == c;
222 bool namespace_simple_pattern(const char *pattern, const char *value) {
223 return simple_pattern_check('.', pattern, value);
226 bool path_simple_pattern(const char *pattern, const char *value) {
227 return simple_pattern_check('/', pattern, value);
230 int bus_message_type_from_string(const char *s, uint8_t *u) {
231 if (streq(s, "signal"))
232 *u = SD_BUS_MESSAGE_TYPE_SIGNAL;
233 else if (streq(s, "method_call"))
234 *u = SD_BUS_MESSAGE_TYPE_METHOD_CALL;
235 else if (streq(s, "error"))
236 *u = SD_BUS_MESSAGE_TYPE_METHOD_ERROR;
237 else if (streq(s, "method_return"))
238 *u = SD_BUS_MESSAGE_TYPE_METHOD_RETURN;
245 const char *bus_message_type_to_string(uint8_t u) {
246 if (u == SD_BUS_MESSAGE_TYPE_SIGNAL)
248 else if (u == SD_BUS_MESSAGE_TYPE_METHOD_CALL)
249 return "method_call";
250 else if (u == SD_BUS_MESSAGE_TYPE_METHOD_ERROR)
252 else if (u == SD_BUS_MESSAGE_TYPE_METHOD_RETURN)
253 return "method_return";