-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
#include <errno.h>
#include <string.h>
+#include <assert.h>
-#include "unit.h"
+#include "util.h"
#include "unit-name.h"
#define VALID_CHARS \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
-UnitType unit_name_to_type(const char *n) {
- UnitType t;
-
- assert(n);
-
- for (t = 0; t < _UNIT_TYPE_MAX; t++)
- if (endswith(n, unit_vtable[t]->suffix))
- return t;
-
- return _UNIT_TYPE_INVALID;
-}
-
-bool unit_name_is_valid(const char *n) {
- UnitType t;
+bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
const char *e, *i, *at;
/* Valid formats:
if (strlen(n) >= UNIT_NAME_MAX)
return false;
- t = unit_name_to_type(n);
- if (t < 0 || t >= _UNIT_TYPE_MAX)
- return false;
-
- assert_se(e = strrchr(n, '.'));
-
- if (e == n)
+ e = strrchr(n, '.');
+ if (!e || e == n)
return false;
for (i = n, at = NULL; i < e; i++) {
if (at == n)
return false;
- if (at[1] == '.')
+ if (!template_ok && at+1 == e)
return false;
}
size_t a, b;
assert(n);
- assert(unit_name_is_valid(n));
+ assert(unit_name_is_valid_no_type(n, true));
assert(suffix);
assert_se(e = strrchr(n, '.'));
assert(unit_prefix_is_valid(prefix));
assert(!instance || unit_instance_is_valid(instance));
assert(suffix);
- assert(unit_name_to_type(suffix) >= 0);
if (!instance)
return strappend(prefix, suffix);
else if (*f == '-' || *f == '\\' || !strchr(VALID_CHARS, *f)) {
*(t++) = '\\';
*(t++) = 'x';
- *(t++) = hexchar(*f > 4);
+ *(t++) = hexchar(*f >> 4);
*(t++) = hexchar(*f);
} else
*(t++) = *f;
assert(prefix);
assert(suffix);
- assert(unit_name_to_type(suffix) >= 0);
/* Takes a arbitrary string for prefix and instance plus a
* suffix and makes a nice string suitable as unit name of it,