-
-/* Delete leading and trailing spaces from a string */
-static char *strip_spaces(char *p)
-{
- char *q;
-
- /* Skip over leading spaces */
- while (*p && isspace(*p))
- p++;
- if (!*p)
- return NULL;
-
- for (q = p + strlen(p) - 1; q != p && isspace(*q); )
- *q-- = '\0';
- return *p ? p : NULL;
-}
-
-/*
- * Read next test stanza; return 1 if found, 0 on EOF or error.
- */
-static int readstanza(STANZA *s, int *linesread)
-{
- PAIR *pp = s->pairs;
- char *p, *equals, *key, *value;
- char buff[1024];
-
- while (BIO_gets(fp, buff, sizeof(buff))) {
- (*linesread)++;
- if (!TEST_ptr(p = strchr(buff, '\n'))) {
- TEST_info("Line %d too long", s->start);
- return 0;
- }
- *p = '\0';
-
- /* Blank line marks end of tests. */
- if (buff[0] == '\0')
- break;
-
- /* Lines starting with a pound sign are ignored. */
- if (buff[0] == '#')
- continue;
-
- if (!TEST_ptr(equals = strchr(buff, '=')))
- return 0;
- *equals++ = '\0';
-
- if (!TEST_ptr(key = strip_spaces(buff))
- || !TEST_ptr(value = strip_spaces(equals))
- || !TEST_int_lt(s->numpairs++, MAXPAIRS)
- || !TEST_ptr(pp->key = OPENSSL_strdup(key))
- || !TEST_ptr(pp->value = OPENSSL_strdup(value)))
- return 0;
- pp++;
- }
-
- /* If we read anything, return ok. */
- return 1;
-}
-
-static void clearstanza(STANZA *s)
-{
- PAIR *pp = s->pairs;
- int i = s->numpairs;
- int start = s->start;
-
- for ( ; --i >= 0; pp++) {
- OPENSSL_free(pp->key);
- OPENSSL_free(pp->value);
- }
- memset(s, 0, sizeof(*s));
- s->start = start;
-}
-