Grab a list of tokens of the format 1#token (from RFC7230) */
| 1560 | |
| 1561 | /* Grab a list of tokens of the format 1#token (from RFC7230) */ |
| 1562 | AP_DECLARE(const char *) ap_parse_token_list_strict(apr_pool_t *p, |
| 1563 | const char *str_in, |
| 1564 | apr_array_header_t **tokens, |
| 1565 | int skip_invalid) |
| 1566 | { |
| 1567 | int in_leading_space = 1; |
| 1568 | int in_trailing_space = 0; |
| 1569 | int string_end = 0; |
| 1570 | const char *tok_begin; |
| 1571 | const char *cur; |
| 1572 | |
| 1573 | if (!str_in) { |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | |
| 1577 | tok_begin = cur = str_in; |
| 1578 | |
| 1579 | while (!string_end) { |
| 1580 | const unsigned char c = (unsigned char)*cur; |
| 1581 | |
| 1582 | if (!TEST_CHAR(c, T_HTTP_TOKEN_STOP)) { |
| 1583 | /* Non-separator character; we are finished with leading |
| 1584 | * whitespace. We must never have encountered any trailing |
| 1585 | * whitespace before the delimiter (comma) */ |
| 1586 | in_leading_space = 0; |
| 1587 | if (in_trailing_space) { |
| 1588 | return "Encountered illegal whitespace in token"; |
| 1589 | } |
| 1590 | } |
| 1591 | else if (c == ' ' || c == '\t') { |
| 1592 | /* "Linear whitespace" only includes ASCII CRLF, space, and tab; |
| 1593 | * we can't get a CRLF since headers are split on them already, |
| 1594 | * so only look for a space or a tab */ |
| 1595 | if (in_leading_space) { |
| 1596 | /* We're still in leading whitespace */ |
| 1597 | ++tok_begin; |
| 1598 | } |
| 1599 | else { |
| 1600 | /* We must be in trailing whitespace */ |
| 1601 | ++in_trailing_space; |
| 1602 | } |
| 1603 | } |
| 1604 | else if (c == ',' || c == '\0') { |
| 1605 | if (!in_leading_space) { |
| 1606 | /* If we're out of the leading space, we know we've read some |
| 1607 | * characters of a token */ |
| 1608 | if (*tokens == NULL) { |
| 1609 | *tokens = apr_array_make(p, 4, sizeof(char *)); |
| 1610 | } |
| 1611 | APR_ARRAY_PUSH(*tokens, char *) = |
| 1612 | apr_pstrmemdup((*tokens)->pool, tok_begin, |
| 1613 | (cur - tok_begin) - in_trailing_space); |
| 1614 | } |
| 1615 | /* We're allowed to have null elements, just don't add them to the |
| 1616 | * array */ |
| 1617 | |
| 1618 | tok_begin = cur + 1; |
| 1619 | in_leading_space = 1; |
no test coverage detected