strparse: switch the API to work on 'const char *'
The functions are not meant to touch the input anyway. Closes #16316
This commit is contained in:
parent
c1341813bd
commit
92611f2a56
@ -149,7 +149,7 @@ static struct altsvc *altsvc_create(struct Curl_str *srchost,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only returns SERIOUS errors */
|
/* only returns SERIOUS errors */
|
||||||
static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
|
static CURLcode altsvc_add(struct altsvcinfo *asi, const char *line)
|
||||||
{
|
{
|
||||||
/* Example line:
|
/* Example line:
|
||||||
h2 example.com 443 h3 shiny.example.com 8443 "20191231 10:00:00" 1
|
h2 example.com 443 h3 shiny.example.com 8443 "20191231 10:00:00" 1
|
||||||
|
|||||||
@ -87,7 +87,7 @@
|
|||||||
|
|
||||||
#if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR)
|
#if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR)
|
||||||
|
|
||||||
enum alpnid Curl_alpn2alpnid(char *name, size_t len)
|
enum alpnid Curl_alpn2alpnid(const char *name, size_t len)
|
||||||
{
|
{
|
||||||
if(len == 2) {
|
if(len == 2) {
|
||||||
if(strncasecompare(name, "h1", 2))
|
if(strncasecompare(name, "h1", 2))
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
struct Curl_dns_entry;
|
struct Curl_dns_entry;
|
||||||
struct ip_quadruple;
|
struct ip_quadruple;
|
||||||
|
|
||||||
enum alpnid Curl_alpn2alpnid(char *name, size_t len);
|
enum alpnid Curl_alpn2alpnid(const char *name, size_t len);
|
||||||
|
|
||||||
/* generic function that returns how much time there is left to run, according
|
/* generic function that returns how much time there is left to run, according
|
||||||
to the timeouts set */
|
to the timeouts set */
|
||||||
|
|||||||
@ -416,7 +416,7 @@ skipsave:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only returns SERIOUS errors */
|
/* only returns SERIOUS errors */
|
||||||
static CURLcode hsts_add(struct hsts *h, char *line)
|
static CURLcode hsts_add(struct hsts *h, const char *line)
|
||||||
{
|
{
|
||||||
/* Example lines:
|
/* Example lines:
|
||||||
example.com "20191231 10:00:00"
|
example.com "20191231 10:00:00"
|
||||||
|
|||||||
@ -390,7 +390,8 @@ static CURLcode calc_payload_hash(struct Curl_easy *data,
|
|||||||
#define S3_UNSIGNED_PAYLOAD "UNSIGNED-PAYLOAD"
|
#define S3_UNSIGNED_PAYLOAD "UNSIGNED-PAYLOAD"
|
||||||
|
|
||||||
static CURLcode calc_s3_payload_hash(struct Curl_easy *data,
|
static CURLcode calc_s3_payload_hash(struct Curl_easy *data,
|
||||||
Curl_HttpReq httpreq, char *provider1,
|
Curl_HttpReq httpreq,
|
||||||
|
const char *provider1,
|
||||||
size_t plen,
|
size_t plen,
|
||||||
unsigned char *sha_hash,
|
unsigned char *sha_hash,
|
||||||
char *sha_hex, char *header)
|
char *sha_hex, char *header)
|
||||||
@ -576,7 +577,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data, bool proxy)
|
|||||||
CURLcode result = CURLE_OUT_OF_MEMORY;
|
CURLcode result = CURLE_OUT_OF_MEMORY;
|
||||||
struct connectdata *conn = data->conn;
|
struct connectdata *conn = data->conn;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *line;
|
const char *line;
|
||||||
struct Curl_str provider0;
|
struct Curl_str provider0;
|
||||||
struct Curl_str provider1;
|
struct Curl_str provider1;
|
||||||
struct Curl_str region = { NULL, 0};
|
struct Curl_str region = { NULL, 0};
|
||||||
|
|||||||
@ -26,10 +26,10 @@
|
|||||||
|
|
||||||
/* Get a word until the first DELIM or end of string. At least one byte long.
|
/* Get a word until the first DELIM or end of string. At least one byte long.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_until(char **linep, struct Curl_str *out,
|
int Curl_str_until(const char **linep, struct Curl_str *out,
|
||||||
const size_t max, char delim)
|
const size_t max, char delim)
|
||||||
{
|
{
|
||||||
char *s = *linep;
|
const char *s = *linep;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
DEBUGASSERT(linep && *linep && out && max && delim);
|
DEBUGASSERT(linep && *linep && out && max && delim);
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ int Curl_str_until(char **linep, struct Curl_str *out,
|
|||||||
|
|
||||||
/* Get a word until the first space or end of string. At least one byte long.
|
/* Get a word until the first space or end of string. At least one byte long.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_word(char **linep, struct Curl_str *out,
|
int Curl_str_word(const char **linep, struct Curl_str *out,
|
||||||
const size_t max)
|
const size_t max)
|
||||||
{
|
{
|
||||||
return Curl_str_until(linep, out, max, ' ');
|
return Curl_str_until(linep, out, max, ' ');
|
||||||
@ -60,10 +60,10 @@ int Curl_str_word(char **linep, struct Curl_str *out,
|
|||||||
|
|
||||||
/* Get a "quoted" word. No escaping possible.
|
/* Get a "quoted" word. No escaping possible.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_quotedword(char **linep, struct Curl_str *out,
|
int Curl_str_quotedword(const char **linep, struct Curl_str *out,
|
||||||
const size_t max)
|
const size_t max)
|
||||||
{
|
{
|
||||||
char *s = *linep;
|
const char *s = *linep;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
DEBUGASSERT(linep && *linep && out && max);
|
DEBUGASSERT(linep && *linep && out && max);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ int Curl_str_quotedword(char **linep, struct Curl_str *out,
|
|||||||
|
|
||||||
/* Advance over a single character.
|
/* Advance over a single character.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_single(char **linep, char byte)
|
int Curl_str_single(const char **linep, char byte)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(linep && *linep);
|
DEBUGASSERT(linep && *linep);
|
||||||
if(**linep != byte)
|
if(**linep != byte)
|
||||||
@ -98,14 +98,14 @@ int Curl_str_single(char **linep, char byte)
|
|||||||
|
|
||||||
/* Advance over a single space.
|
/* Advance over a single space.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_singlespace(char **linep)
|
int Curl_str_singlespace(const char **linep)
|
||||||
{
|
{
|
||||||
return Curl_str_single(linep, ' ');
|
return Curl_str_single(linep, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get an unsigned number. Leading zeroes are accepted.
|
/* Get an unsigned number. Leading zeroes are accepted.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_number(char **linep, size_t *nump, size_t max)
|
int Curl_str_number(const char **linep, size_t *nump, size_t max)
|
||||||
{
|
{
|
||||||
size_t num = 0;
|
size_t num = 0;
|
||||||
DEBUGASSERT(linep && *linep && nump);
|
DEBUGASSERT(linep && *linep && nump);
|
||||||
@ -125,7 +125,7 @@ int Curl_str_number(char **linep, size_t *nump, size_t max)
|
|||||||
|
|
||||||
/* CR or LF
|
/* CR or LF
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_newline(char **linep)
|
int Curl_str_newline(const char **linep)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(linep && *linep);
|
DEBUGASSERT(linep && *linep);
|
||||||
if(ISNEWLINE(**linep)) {
|
if(ISNEWLINE(**linep)) {
|
||||||
|
|||||||
@ -35,37 +35,38 @@
|
|||||||
#define STRE_OVERFLOW 7
|
#define STRE_OVERFLOW 7
|
||||||
|
|
||||||
struct Curl_str {
|
struct Curl_str {
|
||||||
char *str;
|
const char *str;
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get a word until the first space
|
/* Get a word until the first space
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_word(char **linep, struct Curl_str *out, const size_t max);
|
int Curl_str_word(const char **linep, struct Curl_str *out, const size_t max);
|
||||||
|
|
||||||
/* Get a word until the first DELIM or end of string
|
/* Get a word until the first DELIM or end of string
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_until(char **linep, struct Curl_str *out, const size_t max,
|
int Curl_str_until(const char **linep, struct Curl_str *out, const size_t max,
|
||||||
char delim);
|
char delim);
|
||||||
|
|
||||||
/* Get a "quoted" word. No escaping possible.
|
/* Get a "quoted" word. No escaping possible.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_quotedword(char **linep, struct Curl_str *out, const size_t max);
|
int Curl_str_quotedword(const char **linep, struct Curl_str *out,
|
||||||
|
const size_t max);
|
||||||
|
|
||||||
/* Advance over a single character.
|
/* Advance over a single character.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_single(char **linep, char byte);
|
int Curl_str_single(const char **linep, char byte);
|
||||||
|
|
||||||
/* Advance over a single space.
|
/* Advance over a single space.
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_singlespace(char **linep);
|
int Curl_str_singlespace(const char **linep);
|
||||||
|
|
||||||
/* Get an unsigned number
|
/* Get an unsigned number
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_number(char **linep, size_t *nump, size_t max);
|
int Curl_str_number(const char **linep, size_t *nump, size_t max);
|
||||||
|
|
||||||
/* Check for CR or LF
|
/* Check for CR or LF
|
||||||
return non-zero on error */
|
return non-zero on error */
|
||||||
int Curl_str_newline(char **linep);
|
int Curl_str_newline(const char **linep);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_STRPARSE_H */
|
#endif /* HEADER_CURL_STRPARSE_H */
|
||||||
|
|||||||
@ -67,8 +67,8 @@ UNITTEST_START
|
|||||||
printf("Curl_str_word\n");
|
printf("Curl_str_word\n");
|
||||||
for(i = 0; wordparse[i]; i++) {
|
for(i = 0; wordparse[i]; i++) {
|
||||||
struct Curl_str out;
|
struct Curl_str out;
|
||||||
char *line = (char *)wordparse[i];
|
const char *line = wordparse[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_word(&line, &out, 7);
|
int rc = Curl_str_word(&line, &out, 7);
|
||||||
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
||||||
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
||||||
@ -78,8 +78,8 @@ UNITTEST_START
|
|||||||
printf("Curl_str_until\n");
|
printf("Curl_str_until\n");
|
||||||
for(i = 0; wordparse[i]; i++) {
|
for(i = 0; wordparse[i]; i++) {
|
||||||
struct Curl_str out;
|
struct Curl_str out;
|
||||||
char *line = (char *)wordparse[i];
|
const char *line = wordparse[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_until(&line, &out, 7, 'd');
|
int rc = Curl_str_until(&line, &out, 7, 'd');
|
||||||
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
||||||
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
||||||
@ -106,8 +106,8 @@ UNITTEST_START
|
|||||||
printf("Curl_str_quotedword\n");
|
printf("Curl_str_quotedword\n");
|
||||||
for(i = 0; qwords[i]; i++) {
|
for(i = 0; qwords[i]; i++) {
|
||||||
struct Curl_str out;
|
struct Curl_str out;
|
||||||
char *line = (char *)qwords[i];
|
const char *line = qwords[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_quotedword(&line, &out, 7);
|
int rc = Curl_str_quotedword(&line, &out, 7);
|
||||||
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
|
||||||
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
i, orgline, rc, (int)out.len, out.str, (int)out.len,
|
||||||
@ -128,8 +128,8 @@ UNITTEST_START
|
|||||||
};
|
};
|
||||||
printf("Curl_str_single\n");
|
printf("Curl_str_single\n");
|
||||||
for(i = 0; single[i]; i++) {
|
for(i = 0; single[i]; i++) {
|
||||||
char *line = (char *)single[i];
|
const char *line = single[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_single(&line, 'a');
|
int rc = Curl_str_single(&line, 'a');
|
||||||
printf("%u: (\"%s\") %d, line %d\n",
|
printf("%u: (\"%s\") %d, line %d\n",
|
||||||
i, orgline, rc, (int)(line - orgline));
|
i, orgline, rc, (int)(line - orgline));
|
||||||
@ -150,8 +150,8 @@ UNITTEST_START
|
|||||||
};
|
};
|
||||||
printf("Curl_str_singlespace\n");
|
printf("Curl_str_singlespace\n");
|
||||||
for(i = 0; single[i]; i++) {
|
for(i = 0; single[i]; i++) {
|
||||||
char *line = (char *)single[i];
|
const char *line = single[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_singlespace(&line);
|
int rc = Curl_str_singlespace(&line);
|
||||||
printf("%u: (\"%s\") %d, line %d\n",
|
printf("%u: (\"%s\") %d, line %d\n",
|
||||||
i, orgline, rc, (int)(line - orgline));
|
i, orgline, rc, (int)(line - orgline));
|
||||||
@ -171,8 +171,8 @@ UNITTEST_START
|
|||||||
};
|
};
|
||||||
printf("Curl_str_single\n");
|
printf("Curl_str_single\n");
|
||||||
for(i = 0; single[i]; i++) {
|
for(i = 0; single[i]; i++) {
|
||||||
char *line = (char *)single[i];
|
const char *line = single[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_single(&line, 'a');
|
int rc = Curl_str_single(&line, 'a');
|
||||||
printf("%u: (\"%s\") %d, line %d\n",
|
printf("%u: (\"%s\") %d, line %d\n",
|
||||||
i, orgline, rc, (int)(line - orgline));
|
i, orgline, rc, (int)(line - orgline));
|
||||||
@ -197,8 +197,8 @@ UNITTEST_START
|
|||||||
printf("Curl_str_number\n");
|
printf("Curl_str_number\n");
|
||||||
for(i = 0; nums[i]; i++) {
|
for(i = 0; nums[i]; i++) {
|
||||||
size_t num;
|
size_t num;
|
||||||
char *line = (char *)nums[i];
|
const char *line = nums[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_number(&line, &num, 1235);
|
int rc = Curl_str_number(&line, &num, 1235);
|
||||||
printf("%u: (\"%s\") %d, [%u] line %d\n",
|
printf("%u: (\"%s\") %d, [%u] line %d\n",
|
||||||
i, orgline, rc, (int)num, (int)(line - orgline));
|
i, orgline, rc, (int)num, (int)(line - orgline));
|
||||||
@ -218,8 +218,8 @@ UNITTEST_START
|
|||||||
printf("Curl_str_number / max\n");
|
printf("Curl_str_number / max\n");
|
||||||
for(i = 0; nums[i]; i++) {
|
for(i = 0; nums[i]; i++) {
|
||||||
size_t num;
|
size_t num;
|
||||||
char *line = (char *)nums[i];
|
const char *line = nums[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_number(&line, &num, SIZE_T_MAX);
|
int rc = Curl_str_number(&line, &num, SIZE_T_MAX);
|
||||||
printf("%u: (\"%s\") %d, [%zu] line %d\n",
|
printf("%u: (\"%s\") %d, [%zu] line %d\n",
|
||||||
i, orgline, rc, num, (int)(line - orgline));
|
i, orgline, rc, num, (int)(line - orgline));
|
||||||
@ -242,8 +242,8 @@ UNITTEST_START
|
|||||||
};
|
};
|
||||||
printf("Curl_str_newline\n");
|
printf("Curl_str_newline\n");
|
||||||
for(i = 0; newl[i]; i++) {
|
for(i = 0; newl[i]; i++) {
|
||||||
char *line = (char *)newl[i];
|
const char *line = newl[i];
|
||||||
char *orgline = line;
|
const char *orgline = line;
|
||||||
int rc = Curl_str_newline(&line);
|
int rc = Curl_str_newline(&line);
|
||||||
printf("%u: (\"%s\") %d, line %d\n",
|
printf("%u: (\"%s\") %d, line %d\n",
|
||||||
i, orgline, rc, (int)(line - orgline));
|
i, orgline, rc, (int)(line - orgline));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user