struct dynbuf buf;
Curl_dyn_init(&buf, MAX_ALTSVC_LINE);
while(Curl_get_line(&buf, fp)) {
- char *lineptr = Curl_dyn_ptr(&buf);
- while(ISBLANK(*lineptr))
- lineptr++;
- if(*lineptr == '#')
- /* skip commented lines */
- continue;
-
- altsvc_add(asi, lineptr);
+ const char *lineptr = Curl_dyn_ptr(&buf);
+ Curl_str_passblanks(&lineptr);
+ if(Curl_str_single(&lineptr, '#'))
+ altsvc_add(asi, lineptr);
}
Curl_dyn_free(&buf); /* free the line buffer */
fclose(fp);
name = enclist;
for(namelen = 0; *enclist && *enclist != ','; enclist++)
- if(!ISSPACE(*enclist))
+ if(*enclist > ' ')
namelen = enclist - name + 1;
if(namelen) {
struct dynbuf buf;
Curl_dyn_init(&buf, MAX_COOKIE_LINE);
while(Curl_get_line(&buf, fp)) {
- char *lineptr = Curl_dyn_ptr(&buf);
+ const char *lineptr = Curl_dyn_ptr(&buf);
bool headerline = FALSE;
if(checkprefix("Set-Cookie:", lineptr)) {
/* This is a cookie line, get it! */
lineptr += 11;
headerline = TRUE;
- while(ISBLANK(*lineptr))
- lineptr++;
+ Curl_str_passblanks(&lineptr);
}
Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL, NULL, TRUE);
else if(charset[CURLFNM_PRINT])
found = ISPRINT(*s);
else if(charset[CURLFNM_SPACE])
- found = ISSPACE(*s);
+ found = ISBLANK(*s);
else if(charset[CURLFNM_UPPER])
found = ISUPPER(*s);
else if(charset[CURLFNM_LOWER])
else if(c == '\n') {
mem[parser->item_length - 1] = 0;
if(!strncmp("total ", mem, 6)) {
- char *endptr = mem + 6;
+ const char *endptr = mem + 6;
/* here we can deal with directory size, pass the leading
whitespace and then the digits */
- while(ISBLANK(*endptr))
- endptr++;
+ Curl_str_passblanks(&endptr);
while(ISDIGIT(*endptr))
endptr++;
if(*endptr) {
#include "strcase.h"
#include "sendf.h"
#include "headers.h"
+#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
else
return CURLE_BAD_FUNCTION_ARGUMENT;
- /* skip all leading space letters */
- while(ISBLANK(*header))
- header++;
+ /* skip all leading blank letters */
+ Curl_str_passblanks((const char **)&header);
*value = header;
/* skip all trailing space letters */
- while((end > header) && ISSPACE(*end))
+ while((end > header) && ISBLANK(*end))
*end-- = 0; /* nul terminate */
return CURLE_OK;
}
oalloc = olen + offset + 1;
/* skip all trailing space letters */
- while(vlen && ISSPACE(value[vlen - 1]))
+ while(vlen && ISBLANK(value[vlen - 1]))
vlen--;
/* save only one leading space */
return CURLE_OK;
do {
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
if(strncasecompare("max-age", p, 7)) {
bool quoted = FALSE;
int rc;
return CURLE_BAD_FUNCTION_ARGUMENT;
p += 7;
- while(ISBLANK(*p))
- p++;
- if(*p++ != '=')
+ Curl_str_passblanks(&p);
+ if(Curl_str_single(&p, '='))
return CURLE_BAD_FUNCTION_ARGUMENT;
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
- if(*p == '\"') {
- p++;
+ if(!Curl_str_single(&p, '\"'))
quoted = TRUE;
- }
+
rc = Curl_str_number(&p, &expires, TIME_T_MAX);
if(rc == STRE_OVERFLOW)
expires = CURL_OFF_T_MAX;
p++;
}
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
if(*p == ';')
p++;
} while(*p);
struct dynbuf buf;
Curl_dyn_init(&buf, MAX_HSTS_LINE);
while(Curl_get_line(&buf, fp)) {
- char *lineptr = Curl_dyn_ptr(&buf);
- while(ISBLANK(*lineptr))
- lineptr++;
+ const char *lineptr = Curl_dyn_ptr(&buf);
+ Curl_str_passblanks(&lineptr);
+
/*
* Skip empty or commented lines, since we know the line will have a
* trailing newline from Curl_get_line we can treat length 1 as empty.
auth++;
else
break;
- while(ISBLANK(*auth))
- auth++;
+ Curl_str_passblanks(&auth);
}
#else
(void) proxy;
*/
const char *p = hd;
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
if(!strncmp(p, "HTTP/", 5)) {
p += 5;
switch(*p) {
k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 +
(p[2] - '0');
p += 3;
- if(ISSPACE(*p))
+ if(ISBLANK(*p))
fine_statusline = TRUE;
}
}
k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 +
(p[2] - '0');
p += 3;
- if(!ISSPACE(*p))
+ if(!ISBLANK(*p))
break;
fine_statusline = TRUE;
}
scheme = Curl_checkheaders(data, STRCONST(HTTP_PSEUDO_SCHEME));
if(scheme) {
scheme += sizeof(HTTP_PSEUDO_SCHEME);
- while(ISBLANK(*scheme))
- scheme++;
+ Curl_str_passblanks(&scheme);
infof(data, "set pseudo header %s to %s", HTTP_PSEUDO_SCHEME, scheme);
}
else {
{
struct curl_slist *l;
for(l = head; l; l = l->next) {
- char *value; /* to read from */
+ const char *value; /* to read from */
char *store;
size_t colon = strcspn(l->data, ":");
Curl_strntolower(l->data, l->data, colon);
if(!*value)
continue;
++value;
- store = value;
+ store = (char *)value;
/* skip leading whitespace */
- while(ISBLANK(*value))
- value++;
+ Curl_str_passblanks(&value);
while(*value) {
int space = 0;
sep = strchr(l->data, ';');
if(!sep || (*sep == ':' && !*(sep + 1)))
continue;
- for(ptr = sep + 1; ISSPACE(*ptr); ++ptr)
+ for(ptr = sep + 1; ISBLANK(*ptr); ++ptr)
;
if(!*ptr && ptr != sep + 1) /* a value of whitespace only */
continue;
*date_header = aprintf("%s: %s\r\n", date_hdr_key, timestamp);
}
else {
- char *value;
- char *endp;
+ const char *value;
+ const char *endp;
value = strchr(*date_header, ':');
if(!value) {
*date_header = NULL;
goto fail;
}
++value;
- while(ISBLANK(*value))
- ++value;
+ Curl_str_passblanks(&value);
endp = value;
while(*endp && ISALNUM(*endp))
++endp;
SHA256_HEX_LENGTH)
/* try to parse a payload hash from the content-sha256 header */
-static char *parse_content_sha_hdr(struct Curl_easy *data,
- const char *provider1,
- size_t plen,
- size_t *value_len)
+static const char *parse_content_sha_hdr(struct Curl_easy *data,
+ const char *provider1,
+ size_t plen,
+ size_t *value_len)
{
char key[CONTENT_SHA256_KEY_LEN];
size_t key_len;
- char *value;
+ const char *value;
size_t len;
key_len = msnprintf(key, sizeof(key), "x-%.*s-content-sha256",
return NULL;
++value;
- while(ISBLANK(*value))
- ++value;
+ Curl_str_passblanks(&value);
len = strlen(value);
while(len > 0 && ISBLANK(value[len-1]))
char *date_header = NULL;
Curl_HttpReq httpreq;
const char *method = NULL;
- char *payload_hash = NULL;
+ const char *payload_hash = NULL;
size_t payload_hash_len = 0;
unsigned char sha_hash[CURL_SHA256_DIGEST_LENGTH];
char sha_hex[SHA256_HEX_LENGTH];
#include "strcase.h"
#include "vauth/vauth.h"
#include "http_digest.h"
+#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
return CURLE_BAD_CONTENT_ENCODING;
header += strlen("Digest");
- while(ISBLANK(*header))
- header++;
+ Curl_str_passblanks(&header);
return Curl_auth_decode_digest_http_message(header, digest);
}
#include "http_negotiate.h"
#include "vauth/vauth.h"
#include "vtls/vtls.h"
+#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
/* Obtain the input token, if any */
header += strlen("Negotiate");
- while(ISBLANK(*header))
- header++;
+ Curl_str_passblanks(&header);
len = strlen(header);
neg_ctx->havenegdata = len != 0;
#include "curl_base64.h"
#include "vauth/vauth.h"
#include "url.h"
+#include "strparse.h"
/* SSL backend-specific #if branches in this file must be kept in the order
documented in curl_ntlm_core. */
if(checkprefix("NTLM", header)) {
header += strlen("NTLM");
- while(ISSPACE(*header))
- header++;
-
+ Curl_str_passblanks(&header);
if(*header) {
unsigned char *hdr;
size_t hdrlen;
#include "transfer.h"
#include "multiif.h"
#include "vauth/vauth.h"
+#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
struct dynhds *hds)
{
struct connectdata *conn = data->conn;
- char *ptr;
+ const char *ptr;
struct curl_slist *h[2];
struct curl_slist *headers;
int numlists = 1; /* by default */
name = headers->data;
namelen = ptr - headers->data;
ptr++; /* pass the colon */
- while(ISSPACE(*ptr))
- ptr++;
+ Curl_str_passblanks(&ptr);
if(*ptr) {
value = ptr;
valuelen = strlen(value);
name = headers->data;
namelen = ptr - headers->data;
ptr++; /* pass the semicolon */
- while(ISSPACE(*ptr))
- ptr++;
+ Curl_str_passblanks(&ptr);
if(!*ptr) {
/* quirk #2, send an empty header */
value = "";
#include "netrc.h"
#include "strcase.h"
#include "curl_get_line.h"
+#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
CURLcode result;
const char *line = Curl_dyn_ptr(&linebuf);
/* skip comments on load */
- while(ISBLANK(*line))
- line++;
+ Curl_str_passblanks(&line);
if(*line == '#')
continue;
result = Curl_dyn_add(filebuf, line);
netrcbuffer = Curl_dyn_ptr(filebuf);
while(!done) {
- char *tok = netrcbuffer;
+ const char *tok = netrcbuffer;
while(tok && !done) {
- char *tok_end;
+ const char *tok_end;
bool quoted;
Curl_dyn_reset(&token);
- while(ISBLANK(*tok))
- tok++;
+ Curl_str_passblanks(&tok);
/* tok is first non-space letter */
if(state == MACDEF) {
if((*tok == '\n') || (*tok == '\r'))
if(!quoted) {
size_t len = 0;
CURLcode result;
- while(!ISSPACE(*tok_end)) {
+ while(*tok_end > ' ') {
tok_end++;
len++;
}
#include "inet_pton.h"
#include "strcase.h"
#include "noproxy.h"
+#include "strparse.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
bool match = FALSE;
/* pass blanks */
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
token = p;
/* pass over the pattern */
return TRUE;
} /* if(tokenlen) */
/* pass blanks after pattern */
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
/* if not a comma, this ends the loop */
if(*p != ',')
break;
curl_off_t CSeq = 0;
struct RTSP *rtsp = data->req.p.rtsp;
const char *p = &header[5];
- while(ISBLANK(*p))
- p++;
+ Curl_str_passblanks(&p);
if(Curl_str_number(&p, &CSeq, LONG_MAX)) {
failf(data, "Unable to read the CSeq header: [%s]", header);
return CURLE_RTSP_CSEQ_ERROR;
/* Find the first non-space letter */
start = header + 8;
- while(ISBLANK(*start))
- start++;
+ Curl_str_passblanks(&start);
if(!*start) {
failf(data, "Got a blank Session ID");
* gstreamer does url-encoded session ID's not covered by the standard.
*/
end = start;
- while(*end && *end != ';' && !ISSPACE(*end))
+ while((*end > ' ') && (*end != ';'))
end++;
idlen = end - start;
const char *start, *end;
start = transport;
while(start && *start) {
- while(ISBLANK(*start) )
- start++;
+ Curl_str_passblanks(&start);
end = strchr(start, ';');
if(checkprefix("interleaved=", start)) {
curl_off_t chan1, chan2, chan;
while(out->len && ISBLANK(out->str[out->len - 1]))
out->len--;
}
+
+/* increase the pointer until it has moved over all blanks */
+void Curl_str_passblanks(const char **linep)
+{
+ while(ISBLANK(**linep))
+ (*linep)++; /* move over it */
+}
int Curl_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
void Curl_str_trimblanks(struct Curl_str *out);
+void Curl_str_passblanks(const char **linep);
#endif /* HEADER_CURL_STRPARSE_H */
*num = 0; /* clear by default */
DEBUGASSERT((base == 10) || (base == 16));
- while(ISBLANK(*str))
- str++;
-
+ Curl_str_passblanks(&str);
rc = base == 10 ?
Curl_str_number(&str, &number, CURL_OFF_T_MAX) :
Curl_str_hex(&str, &number, CURL_OFF_T_MAX);
/* convert CURLcode to CURLUcode */
#define cc2cu(x) ((x) == CURLE_TOO_LARGE ? CURLUE_TOO_LARGE : \
CURLUE_OUT_OF_MEMORY)
-/*
- * Decide whether a character in a URL must be escaped.
- */
-#define urlchar_needs_escaping(c) (!(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c)))
static const char hexdigits[] = "0123456789abcdef";
/* urlencode_str() writes data into an output dynbuf and URL-encodes the
else
result = Curl_dyn_addn(o, "+", 1);
}
- else if(urlchar_needs_escaping(*iptr)) {
+ else if((*iptr < ' ') || (*iptr >= 0x7f)) {
char out[3]={'%'};
out[1] = hexdigits[*iptr >> 4];
out[2] = hexdigits[*iptr & 0xf];