Coverage Report

Created: 2026-07-30 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/curlx/strparse.h
Line
Count
Source
1
#ifndef HEADER_CURL_STRPARSE_H
2
#define HEADER_CURL_STRPARSE_H
3
/***************************************************************************
4
 *                                  _   _ ____  _
5
 *  Project                     ___| | | |  _ \| |
6
 *                             / __| | | | |_) | |
7
 *                            | (__| |_| |  _ <| |___
8
 *                             \___|\___/|_| \_\_____|
9
 *
10
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11
 *
12
 * This software is licensed as described in the file COPYING, which
13
 * you should have received as part of this distribution. The terms
14
 * are also available at https://curl.se/docs/copyright.html.
15
 *
16
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
 * copies of the Software, and permit persons to whom the Software is
18
 * furnished to do so, under the terms of the COPYING file.
19
 *
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
 * KIND, either express or implied.
22
 *
23
 * SPDX-License-Identifier: curl
24
 *
25
 ***************************************************************************/
26
#include "curl_setup.h"
27
28
1.95k
#define STRE_OK       0
29
0
#define STRE_BIG      1
30
0
#define STRE_SHORT    2
31
0
#define STRE_BEGQUOTE 3
32
0
#define STRE_ENDQUOTE 4
33
0
#define STRE_BYTE     5
34
0
#define STRE_NEWLINE  6
35
42
#define STRE_OVERFLOW 7
36
1.06k
#define STRE_NO_NUM   8
37
38
/* public struct, but all accesses should be done using the provided
39
   functions */
40
struct Curl_str {
41
  const char *str;
42
  size_t len;
43
};
44
45
void curlx_str_init(struct Curl_str *out);
46
void curlx_str_assign(struct Curl_str *out, const char *str, size_t len);
47
void curlx_str_trim(struct Curl_str *out, size_t len);
48
49
0
#define curlx_str(x)    ((x)->str)
50
0
#define curlx_strlen(x) ((x)->len)
51
52
/* Get a word until the first space
53
   return non-zero on error */
54
int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max);
55
56
/* Get a word until the first DELIM or end of string
57
   return non-zero on error */
58
int curlx_str_until(const char **linep, struct Curl_str *out, const size_t max,
59
                    char delim);
60
61
/* Get a word until a newline byte or end of string. At least one byte long.
62
   return non-zero on error */
63
int curlx_str_untilnl(const char **linep, struct Curl_str *out,
64
                      const size_t max);
65
66
/* Get a "quoted" word. Escaped quotes are supported.
67
   return non-zero on error */
68
int curlx_str_quotedword(const char **linep, struct Curl_str *out,
69
                         const size_t max);
70
71
/* Advance over a single character.
72
   return non-zero on error */
73
int curlx_str_single(const char **linep, char byte);
74
75
/* Advance over a single space.
76
   return non-zero on error */
77
int curlx_str_singlespace(const char **linep);
78
79
/* Get an unsigned decimal number. Return non-zero on error */
80
int curlx_str_number(const char **linep, curl_off_t *nump, curl_off_t max);
81
82
/* As above with CURL_OFF_T_MAX but also pass leading blanks */
83
int curlx_str_numblanks(const char **str, curl_off_t *num);
84
85
/* Get an unsigned hexadecimal number. Return non-zero on error */
86
int curlx_str_hex(const char **linep, curl_off_t *nump, curl_off_t max);
87
88
/* Get an unsigned octal number. Return non-zero on error */
89
int curlx_str_octal(const char **linep, curl_off_t *nump, curl_off_t max);
90
91
/* Check for CR or LF
92
   return non-zero on error */
93
int curlx_str_newline(const char **linep);
94
95
/* case insensitive compare that the parsed string matches the
96
   given string. */
97
int curlx_str_casecompare(struct Curl_str *str, const char *check);
98
int curlx_str_cmp(struct Curl_str *str, const char *check);
99
100
int curlx_str_nudge(struct Curl_str *str, size_t num);
101
102
int curlx_str_cspn(const char **linep, struct Curl_str *out,
103
                   const char *reject);
104
void curlx_str_trimblanks(struct Curl_str *out);
105
void curlx_str_passblanks(const char **linep);
106
107
/* given a hexadecimal letter, return the binary value. '0' returns 0, 'a'
108
   returns 10. THIS ONLY WORKS ON VALID HEXADECIMAL LETTER INPUT. Verify
109
   before calling this. */
110
extern const unsigned char curlx_hexasciitable[];
111
39.8k
#define curlx_hexval(x) (unsigned char)(curlx_hexasciitable[(x) - '0'] & 0x0f)
112
113
#endif /* HEADER_CURL_STRPARSE_H */