Debian Codegraph @

extra/curl/curl-8.14.1/lib/curlx/strparse.h

raw
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, <[email protected]>, 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 #define STRE_OK 0
29 #define STRE_BIG 1
30 #define STRE_SHORT 2
31 #define STRE_BEGQUOTE 3
32 #define STRE_ENDQUOTE 4
33 #define STRE_BYTE 5
34 #define STRE_NEWLINE 6
35 #define STRE_OVERFLOW 7
36 #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
48 #define curlx_str(x) ((x)->str)
49 #define curlx_strlen(x) ((x)->len)
50
51 /* Get a word until the first space
52 return non-zero on error */
53 int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max);
54
55 /* Get a word until the first DELIM or end of string
56 return non-zero on error */
57 int curlx_str_until(const char **linep, struct Curl_str *out, const size_t max,
58 char delim);
59
60 /* Get a word until a newline byte or end of string. At least one byte long.
61 return non-zero on error */
62 int curlx_str_untilnl(const char **linep, struct Curl_str *out,
63 const size_t max);
64
65 /* Get a "quoted" word. No escaping possible.
66 return non-zero on error */
67 int curlx_str_quotedword(const char **linep, struct Curl_str *out,
68 const size_t max);
69
70 /* Advance over a single character.
71 return non-zero on error */
72 int curlx_str_single(const char **linep, char byte);
73
74 /* Advance over a single space.
75 return non-zero on error */
76 int curlx_str_singlespace(const char **linep);
77
78 /* Get an unsigned decimal number. Return non-zero on error */
79 int curlx_str_number(const char **linep, curl_off_t *nump, curl_off_t max);
80
81 /* As above with CURL_OFF_T_MAX but also pass leading blanks */
82 int curlx_str_numblanks(const char **str, curl_off_t *num);
83
84 /* Get an unsigned hexadecimal number. Return non-zero on error */
85 int curlx_str_hex(const char **linep, curl_off_t *nump, curl_off_t max);
86
87 /* Get an unsigned octal number. Return non-zero on error */
88 int curlx_str_octal(const char **linep, curl_off_t *nump, curl_off_t max);
89
90 /* Check for CR or LF
91 return non-zero on error */
92 int curlx_str_newline(const char **linep);
93
94 /* case insensitive compare that the parsed string matches the
95 given string. */
96 int curlx_str_casecompare(struct Curl_str *str, const char *check);
97 int curlx_str_cmp(struct Curl_str *str, const char *check);
98
99 int curlx_str_nudge(struct Curl_str *str, size_t num);
100
101 int curlx_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
102 void curlx_str_trimblanks(struct Curl_str *out);
103 void curlx_str_passblanks(const char **linep);
104
105 /* given a hexadecimal letter, return the binary value. '0' returns 0, 'a'
106 returns 10. THIS ONLY WORKS ON VALID HEXADECIMAL LETTER INPUT. Verify
107 before calling this!
108 */
109 extern const unsigned char Curl_hexasciitable[];
110 #define Curl_hexval(x) (unsigned char)(Curl_hexasciitable[(x) - '0'] & 0x0f)
111
112 #endif /* HEADER_CURL_STRPARSE_H */