diff options
author | David Goulet <dgoulet@torproject.org> | 2020-03-30 13:31:56 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-03-30 13:31:56 -0400 |
commit | 27e2989fe9877d52e2e1ce0855b67165bff7f455 (patch) | |
tree | 27698295ffd789ba92d2e6294f8e867a7ab02c40 /src/lib/encoding | |
parent | 9061303080e6b707ae6c9d77a05e27bf86ec948f (diff) | |
parent | 0dc25a4b66aedc804360c10a6f710d69f0b17bfe (diff) | |
download | tor-27e2989fe9877d52e2e1ce0855b67165bff7f455.tar.gz tor-27e2989fe9877d52e2e1ce0855b67165bff7f455.zip |
Merge branch 'tor-github/pr/1775'
Diffstat (limited to 'src/lib/encoding')
-rw-r--r-- | src/lib/encoding/confline.c | 29 | ||||
-rw-r--r-- | src/lib/encoding/confline.h | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/encoding/confline.c b/src/lib/encoding/confline.c index ff8bacba3c..eb1a4e30f0 100644 --- a/src/lib/encoding/confline.c +++ b/src/lib/encoding/confline.c @@ -253,6 +253,35 @@ config_lines_dup_and_filter(const config_line_t *inp, return result; } +/** + * Given a linelist <b>inp</b> beginning with the key <b>header</b>, find the + * next line with that key, and remove that instance and all following lines + * from the list. Return the lines that were removed. Operate + * case-insensitively. + * + * For example, if the header is "H", and <b>inp</b> contains "H, A, B, H, C, + * H, D", this function will alter <b>inp</b> to contain only "H, A, B", and + * return the elements "H, C, H, D" as a separate list. + **/ +config_line_t * +config_lines_partition(config_line_t *inp, const char *header) +{ + if (BUG(inp == NULL)) + return NULL; + if (BUG(strcasecmp(inp->key, header))) + return NULL; + + /* Advance ptr until it points to the link to the next segment of this + list. */ + config_line_t **ptr = &inp->next; + while (*ptr && strcasecmp((*ptr)->key, header)) { + ptr = &(*ptr)->next; + } + config_line_t *remainder = *ptr; + *ptr = NULL; + return remainder; +} + /** Return true iff a and b contain identical keys and values in identical * order. */ int diff --git a/src/lib/encoding/confline.h b/src/lib/encoding/confline.h index cd343e0e99..ce0d6c6e17 100644 --- a/src/lib/encoding/confline.h +++ b/src/lib/encoding/confline.h @@ -50,6 +50,7 @@ const config_line_t *config_line_find(const config_line_t *lines, const char *key); const config_line_t *config_line_find_case(const config_line_t *lines, const char *key); +config_line_t *config_lines_partition(config_line_t *inp, const char *header); int config_lines_eq(const config_line_t *a, const config_line_t *b); int config_count_key(const config_line_t *a, const char *key); void config_free_lines_(config_line_t *front); |