bus-internal.c revision f5d8989ce5fc4e6eb338ec7b1b2c6d6a74c44c63
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering This file is part of systemd.
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering Copyright 2013 Lennart Poettering
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering systemd is free software; you can redistribute it and/or modify it
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering under the terms of the GNU Lesser General Public License as published by
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering (at your option) any later version.
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering systemd is distributed in the hope that it will be useful, but
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering Lesser General Public License for more details.
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering You should have received a copy of the GNU Lesser General Public License
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool object_path_is_valid(const char *p) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *q;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (p[0] != '/')
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (p[1] == 0)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (*q == '/') {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringchar* object_path_startswith(const char *a, const char *b) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *p;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (char*) a + 1;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (char*) p;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (*p == '/')
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (char*) p + 1;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool interface_name_is_valid(const char *p) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *q;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering for (dot = true, q = p; *q; q++)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (*q == '.') {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (q - p > 255)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool service_name_is_valid(const char *p) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *q;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering for (dot = true, q = unique ? p+1 : p; *q; q++)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (*q == '.') {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering ((!dot || unique) && *q >= '0' && *q <= '9') ||
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (q - p > 255)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringchar* service_name_startswith(const char *a, const char *b) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *p;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (char*) p;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (*p == '.')
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (char*) p + 1;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool member_name_is_valid(const char *p) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *q;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering for (q = p; *q; q++) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering if (q - p > 255)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringstatic bool complex_pattern_check(char c, const char *a, const char *b) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return (separator && (*a == 0 || *b == 0)) ||
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering (*a == 0 && *b == c && b[1] == 0) ||
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering (*b == 0 && *a == c && a[1] == 0);
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool namespace_complex_pattern(const char *pattern, const char *value) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return complex_pattern_check('.', pattern, value);
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool path_complex_pattern(const char *pattern, const char *value) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return complex_pattern_check('/', pattern, value);
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringstatic bool simple_pattern_check(char c, const char *a, const char *b) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return *a == 0 && *b == c;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool namespace_simple_pattern(const char *pattern, const char *value) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return simple_pattern_check('.', pattern, value);
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringbool path_simple_pattern(const char *pattern, const char *value) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return simple_pattern_check('/', pattern, value);
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringint bus_message_type_from_string(const char *s, uint8_t *u) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringconst char *bus_message_type_to_string(uint8_t u) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return "signal";
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering else if (u == SD_BUS_MESSAGE_METHOD_CALL)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return "method_call";
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering else if (u == SD_BUS_MESSAGE_METHOD_ERROR)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return "error";
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering else if (u == SD_BUS_MESSAGE_METHOD_RETURN)
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering return "method_return";
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poetteringchar *bus_address_escape(const char *v) {
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering const char *a;
0284adc6a60ce0af1107cb0b50041a65d731f39eLennart Poettering for (a = v, b = r; *a; a++) {