41 if (as_keyless_val && *s == 0)
44 if (as_keyless_val && strchr(s,
'='))
48 if (*s >= 127 || TOR_ISSPACE(*s) || ! TOR_ISPRINT(*s) ||
49 *s ==
'\'' || *s ==
'\"') {
62 return line->key == NULL || strlen(line->key) == 0;
71 return line->value == NULL || strlen(line->value) == 0;
81 for ( ; line; line = line->next) {
83 if (keyless && ! (flags & KV_OMIT_KEYS)) {
88 if (
needs_escape(line->value, keyless) && ! (flags & (KV_QUOTED|KV_RAW))) {
131 tor_assert((flags & (KV_OMIT_KEYS|KV_OMIT_VALS)) !=
132 (KV_OMIT_KEYS|KV_OMIT_VALS));
133 tor_assert((flags & (KV_QUOTED|KV_RAW)) != (KV_QUOTED|KV_RAW));
140 for (; line; line = line->next) {
143 const char *eq =
"=";
158 }
else if (!(flags & KV_RAW) && esc) {
172 smartlist_free(elements);
201 tor_assert((flags & (KV_OMIT_KEYS|KV_OMIT_VALS)) !=
202 (KV_OMIT_KEYS|KV_OMIT_VALS));
205 const char *cp = line, *cplast = NULL;
206 const bool omit_keys = (flags & KV_OMIT_KEYS) != 0;
207 const bool omit_vals = (flags & KV_OMIT_VALS) != 0;
208 const bool quoted = (flags & (KV_QUOTED|KV_QUOTED_QSTRING)) != 0;
209 const bool c_quoted = (flags & (KV_QUOTED)) != 0;
221 size_t idx = strspn(cp,
" \t\r\v\n");
224 if (BUG(cp == cplast)) {
237 size_t idx = strcspn(cp,
" \t\r\v\n=");
239 if (cp[idx] ==
'=') {
240 key = tor_memdup_nulterm(cp, idx);
242 }
else if (omit_vals) {
243 key = tor_memdup_nulterm(cp, idx);
262 if (cp == NULL || len != strlen(val)) {
267 size_t idx = strcspn(cp,
" \t\r\v\n");
268 val = tor_memdup_nulterm(cp, idx);
273 if (key && strlen(key) == 0) {
279 (*next_line)->key = key ? key : tor_strdup(
"");
280 (*next_line)->value = val ? val : tor_strdup(
"");
281 next_line = &(*next_line)->next;
285 if (! (flags & KV_QUOTED_QSTRING)) {
295 config_free_lines(result);
Locale-independent character-type inspection (header)
const char * unescape_string(const char *s, char **result, size_t *size_out)
char * esc_for_log(const char *s)
static bool needs_escape(const char *s, bool as_keyless_val)
config_line_t * kvline_parse(const char *line, unsigned flags)
static bool kvline_can_encode_lines(const config_line_t *line, unsigned flags)
char * kvline_encode(const config_line_t *line, unsigned flags)
static bool line_has_no_key(const config_line_t *line)
static bool line_has_no_val(const config_line_t *line)
Headers for util_malloc.c.
const char * decode_qstring(const char *start, size_t in_len_max, char **out, size_t *out_len)
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
smartlist_t * smartlist_new(void)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Macros to manage assertions, fatal and non-fatal.
Header for util_string.c.