-
-/* 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 (fgets(buff, sizeof(buff), fp) != NULL) {
- (*linesread)++;
- if ((p = strchr(buff, '\n')) == NULL) {
- fprintf(stderr, "Line %d too long.\n", 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 ((equals = strchr(buff, '=')) == NULL) {
- fprintf(stderr, "Line %d missing equals.\n", s->start);
- return 0;
- }
- *equals++ = '\0';
-
- key = strip_spaces(buff);
- value = strip_spaces(equals);
- if (key == NULL || value == NULL) {
- fprintf(stderr, "Line %d missing field.\n", s->start);
- return 0;
- }
- s->numpairs++;
- if (s->numpairs >= MAXPAIRS) {
- fprintf(stderr, "Line %d too many lines\n", s->start);
- return 0;
- }
- pp->key = OPENSSL_strdup(key);
- pp->value = OPENSSL_strdup(value);
- 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;
-}
-