Compare commits

..

No commits in common. "50f5e2e2817d3435a1d6c0ce0d434efe5dcc2748" and "0fc659eea9aef031d1aa6cf729f3927abcfcb922" have entirely different histories.

4 changed files with 30 additions and 52 deletions

4
TODO
View File

@ -117,8 +117,7 @@ Features:
* systemd-repart: allow config of partition uuid * systemd-repart: allow config of partition uuid
* userdb: allow username prefix searches in varlink API, allow realname and * userdb: allow username prefix searches in varlink API
realname substr searches in varlink API
* userdb: allow existence checks * userdb: allow existence checks
@ -865,7 +864,6 @@ Features:
make assumptions about their slice anymore. make assumptions about their slice anymore.
- follow PropertiesChanged state more closely, to deal with quick logouts and - follow PropertiesChanged state more closely, to deal with quick logouts and
relogins relogins
- (optionally?) spawn seat-manager@$SEAT.service whenever a seat shows up that as CanGraphical set
* journal: * journal:
- consider introducing implicit _TTY= + _PPID= + _EUID= + _EGID= + _FSUID= + _FSGID= fields - consider introducing implicit _TTY= + _PPID= + _EUID= + _EGID= + _FSUID= + _FSGID= fields

View File

@ -113,7 +113,7 @@ static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false; bool escaped = false;
int n; int n;
for (n = 0; s[n] != '\0'; n++) { for (n=0; s[n]; n++) {
if (escaped) if (escaped)
escaped = false; escaped = false;
else if (s[n] == '\\') else if (s[n] == '\\')
@ -122,44 +122,35 @@ static size_t strcspn_escaped(const char *s, const char *reject) {
break; break;
} }
return n; /* if s ends in \, return index of previous char */
return n - escaped;
} }
/* Split a string into words. */ /* Split a string into words. */
const char* split( const char* split(const char **state, size_t *l, const char *separator, SplitFlags flags) {
const char **state,
size_t *l,
const char *separator,
SplitFlags flags) {
const char *current; const char *current;
assert(state);
assert(l);
if (!separator)
separator = WHITESPACE;
current = *state; current = *state;
if (*current == '\0') /* already at the end? */ if (!*current) {
assert(**state == '\0');
return NULL; return NULL;
}
current += strspn(current, separator); /* skip leading separators */ current += strspn(current, separator);
if (*current == '\0') { /* at the end now? */ if (!*current) {
*state = current; *state = current;
return NULL; return NULL;
} }
if (FLAGS_SET(flags, SPLIT_QUOTES)) { if (flags & SPLIT_QUOTES && strchr("\'\"", *current)) {
char quotechars[2] = {*current, '\0'};
if (strchr(QUOTES, *current)) { *l = strcspn_escaped(current + 1, quotechars);
/* We are looking at a quote */ if (current[*l + 1] == '\0' || current[*l + 1] != quotechars[0] ||
*l = strcspn_escaped(current + 1, CHAR_TO_STR(*current)); (current[*l + 2] && !strchr(separator, current[*l + 2]))) {
if (current[*l + 1] != *current ||
(current[*l + 2] != 0 && !strchr(separator, current[*l + 2]))) {
/* right quote missing or garbage at the end */ /* right quote missing or garbage at the end */
if (FLAGS_SET(flags, SPLIT_RELAX)) { if (flags & SPLIT_RELAX) {
*state = current + *l + 1 + (current[*l + 1] != '\0'); *state = current + *l + 1 + (current[*l + 1] != '\0');
return current + 1; return current + 1;
} }
@ -167,17 +158,14 @@ const char* split(
return NULL; return NULL;
} }
*state = current++ + *l + 2; *state = current++ + *l + 2;
} else if (flags & SPLIT_QUOTES) {
} else {
/* We are looking at a something that is not a quote */
*l = strcspn_escaped(current, separator); *l = strcspn_escaped(current, separator);
if (current[*l] && !strchr(separator, current[*l]) && !FLAGS_SET(flags, SPLIT_RELAX)) { if (current[*l] && !strchr(separator, current[*l]) && !(flags & SPLIT_RELAX)) {
/* unfinished escape */ /* unfinished escape */
*state = current; *state = current;
return NULL; return NULL;
} }
*state = current + *l; *state = current + *l;
}
} else { } else {
*l = strcspn(current, separator); *l = strcspn(current, separator);
*state = current + *l; *state = current + *l;

View File

@ -112,10 +112,8 @@ typedef enum SplitFlags {
SPLIT_RELAX = 0x01 << 1, SPLIT_RELAX = 0x01 << 1,
} SplitFlags; } SplitFlags;
/* Smelly. Do not use this anymore. Use extract_first_word() instead! */
const char* split(const char **state, size_t *l, const char *separator, SplitFlags flags); const char* split(const char **state, size_t *l, const char *separator, SplitFlags flags);
/* Similar, don't use this anymore */
#define FOREACH_WORD(word, length, s, state) \ #define FOREACH_WORD(word, length, s, state) \
_FOREACH_WORD(word, length, s, WHITESPACE, 0, state) _FOREACH_WORD(word, length, s, WHITESPACE, 0, state)

View File

@ -307,12 +307,6 @@ static void test_strv_split(void) {
l = strv_split_full(" 'one' \" two\t three \"' four five", NULL, SPLIT_QUOTES | SPLIT_RELAX); l = strv_split_full(" 'one' \" two\t three \"' four five", NULL, SPLIT_QUOTES | SPLIT_RELAX);
assert_se(l); assert_se(l);
assert_se(strv_equal(l, (char**) input_table_quoted)); assert_se(strv_equal(l, (char**) input_table_quoted));
strv_free_erase(l);
l = strv_split_full("\\", NULL, SPLIT_QUOTES | SPLIT_RELAX);
assert_se(l);
assert_se(strv_equal(l, STRV_MAKE("\\")));
} }
static void test_strv_split_empty(void) { static void test_strv_split_empty(void) {