2002-09-03 07:52:59 -04:00
|
|
|
/***************************************************************************
|
2004-07-02 08:28:57 -04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
1999-12-29 09:20:26 -05:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2017-06-10 08:35:07 -04:00
|
|
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
1999-12-29 09:20:26 -05:00
|
|
|
*
|
2002-09-03 07:52:59 -04:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-07-02 08:28:57 -04:00
|
|
|
*
|
2001-01-03 04:29:33 -05:00
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
2002-09-03 07:52:59 -04:00
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
1999-12-29 09:20:26 -05:00
|
|
|
*
|
2001-01-03 04:29:33 -05:00
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
1999-12-29 09:20:26 -05:00
|
|
|
*
|
2002-09-03 07:52:59 -04:00
|
|
|
***************************************************************************/
|
2012-04-06 17:35:15 -04:00
|
|
|
#include "tool_setup.h"
|
2001-11-29 07:47:41 -05:00
|
|
|
|
2015-03-03 17:08:02 -05:00
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* use our own printf() functions */
|
|
|
|
#include "curlx.h"
|
2016-02-05 01:44:27 -05:00
|
|
|
#include "tool_cfgable.h"
|
|
|
|
#include "tool_doswin.h"
|
2011-10-05 14:16:16 -04:00
|
|
|
#include "tool_urlglob.h"
|
2011-09-19 12:18:17 -04:00
|
|
|
#include "tool_vms.h"
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
2000-10-09 07:13:17 -04:00
|
|
|
|
2013-09-06 17:27:47 -04:00
|
|
|
#define GLOBERROR(string, column, code) \
|
2014-07-11 19:39:56 -04:00
|
|
|
glob->error = string, glob->pos = column, code
|
2013-09-06 17:27:47 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
void glob_cleanup(URLGlob* glob);
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
static CURLcode glob_fixed(URLGlob *glob, char *fixed, size_t len)
|
2013-08-15 07:05:25 -04:00
|
|
|
{
|
|
|
|
URLPattern *pat = &glob->pattern[glob->size];
|
|
|
|
pat->type = UPTSet;
|
|
|
|
pat->content.Set.size = 1;
|
|
|
|
pat->content.Set.ptr_s = 0;
|
|
|
|
pat->globindex = -1;
|
|
|
|
|
2016-11-23 02:30:18 -05:00
|
|
|
pat->content.Set.elements = malloc(sizeof(char *));
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2013-09-06 17:27:47 -04:00
|
|
|
if(!pat->content.Set.elements)
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
2013-09-06 17:27:47 -04:00
|
|
|
|
2017-09-09 17:55:08 -04:00
|
|
|
pat->content.Set.elements[0] = malloc(len + 1);
|
2013-09-06 17:27:47 -04:00
|
|
|
if(!pat->content.Set.elements[0])
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2013-10-21 18:01:17 -04:00
|
|
|
memcpy(pat->content.Set.elements[0], fixed, len);
|
|
|
|
pat->content.Set.elements[0][len] = 0;
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
return CURLE_OK;
|
2013-08-15 07:05:25 -04:00
|
|
|
}
|
|
|
|
|
2013-08-16 05:52:59 -04:00
|
|
|
/* multiply
|
|
|
|
*
|
|
|
|
* Multiplies and checks for overflow.
|
|
|
|
*/
|
|
|
|
static int multiply(unsigned long *amount, long with)
|
|
|
|
{
|
|
|
|
unsigned long sum = *amount * with;
|
2017-06-10 08:35:07 -04:00
|
|
|
if(!with) {
|
|
|
|
*amount = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-16 05:52:59 -04:00
|
|
|
if(sum/with != *amount)
|
|
|
|
return 1; /* didn't fit, bail out */
|
|
|
|
*amount = sum;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
static CURLcode glob_set(URLGlob *glob, char **patternp,
|
2013-09-06 17:27:47 -04:00
|
|
|
size_t *posp, unsigned long *amount,
|
2013-08-15 07:05:25 -04:00
|
|
|
int globindex)
|
2000-12-06 05:10:31 -05:00
|
|
|
{
|
1999-12-29 09:20:26 -05:00
|
|
|
/* processes a set expression with the point behind the opening '{'
|
|
|
|
','-separated elements are collected until the next closing '}'
|
|
|
|
*/
|
2011-10-05 14:16:16 -04:00
|
|
|
URLPattern *pat;
|
2006-04-07 08:10:34 -04:00
|
|
|
bool done = FALSE;
|
2013-08-15 07:05:25 -04:00
|
|
|
char *buf = glob->glob_buffer;
|
|
|
|
char *pattern = *patternp;
|
|
|
|
char *opattern = pattern;
|
2013-09-06 17:27:47 -04:00
|
|
|
size_t opos = *posp-1;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
pat = &glob->pattern[glob->size];
|
1999-12-29 09:20:26 -05:00
|
|
|
/* patterns 0,1,2,... correspond to size=1,3,5,... */
|
|
|
|
pat->type = UPTSet;
|
|
|
|
pat->content.Set.size = 0;
|
|
|
|
pat->content.Set.ptr_s = 0;
|
2011-06-02 16:19:39 -04:00
|
|
|
pat->content.Set.elements = NULL;
|
2013-08-15 07:05:25 -04:00
|
|
|
pat->globindex = globindex;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2011-04-25 16:44:39 -04:00
|
|
|
while(!done) {
|
1999-12-29 09:20:26 -05:00
|
|
|
switch (*pattern) {
|
2004-10-06 03:50:18 -04:00
|
|
|
case '\0': /* URL ended while set was still open */
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("unmatched brace", opos, CURLE_URL_MALFORMAT);
|
2001-01-23 05:14:43 -05:00
|
|
|
|
1999-12-29 09:20:26 -05:00
|
|
|
case '{':
|
2004-10-06 03:50:18 -04:00
|
|
|
case '[': /* no nested expressions at this time */
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("nested brace", *posp, CURLE_URL_MALFORMAT);
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2004-10-06 03:50:18 -04:00
|
|
|
case '}': /* set element completed */
|
2013-09-06 17:27:47 -04:00
|
|
|
if(opattern == pattern)
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("empty string within braces", *posp,
|
|
|
|
CURLE_URL_MALFORMAT);
|
2013-09-06 17:27:47 -04:00
|
|
|
|
2013-08-16 05:52:59 -04:00
|
|
|
/* add 1 to size since it'll be incremented below */
|
2017-09-09 17:55:08 -04:00
|
|
|
if(multiply(amount, pat->content.Set.size + 1))
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("range overflow", 0, CURLE_URL_MALFORMAT);
|
2013-09-06 17:27:47 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
/* fall-through */
|
|
|
|
case ',':
|
|
|
|
|
1999-12-29 09:20:26 -05:00
|
|
|
*buf = '\0';
|
2011-09-10 12:46:05 -04:00
|
|
|
if(pat->content.Set.elements) {
|
|
|
|
char **new_arr = realloc(pat->content.Set.elements,
|
2016-11-23 02:30:18 -05:00
|
|
|
(pat->content.Set.size + 1) * sizeof(char *));
|
2013-09-06 17:27:47 -04:00
|
|
|
if(!new_arr)
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2011-09-10 12:46:05 -04:00
|
|
|
pat->content.Set.elements = new_arr;
|
|
|
|
}
|
2011-06-02 16:19:39 -04:00
|
|
|
else
|
2016-11-23 02:30:18 -05:00
|
|
|
pat->content.Set.elements = malloc(sizeof(char *));
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2013-09-06 17:27:47 -04:00
|
|
|
if(!pat->content.Set.elements)
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2000-12-06 05:10:31 -05:00
|
|
|
pat->content.Set.elements[pat->content.Set.size] =
|
|
|
|
strdup(glob->glob_buffer);
|
2013-09-06 17:27:47 -04:00
|
|
|
if(!pat->content.Set.elements[pat->content.Set.size])
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
1999-12-29 09:20:26 -05:00
|
|
|
++pat->content.Set.size;
|
|
|
|
|
2011-04-25 16:44:39 -04:00
|
|
|
if(*pattern == '}') {
|
2013-08-15 07:05:25 -04:00
|
|
|
pattern++; /* pass the closing brace */
|
2006-04-07 08:10:34 -04:00
|
|
|
done = TRUE;
|
|
|
|
continue;
|
2001-01-23 05:14:43 -05:00
|
|
|
}
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2000-12-06 05:10:31 -05:00
|
|
|
buf = glob->glob_buffer;
|
1999-12-29 09:20:26 -05:00
|
|
|
++pattern;
|
2013-09-06 17:27:47 -04:00
|
|
|
++(*posp);
|
1999-12-29 09:20:26 -05:00
|
|
|
break;
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2004-10-06 03:50:18 -04:00
|
|
|
case ']': /* illegal closing bracket */
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("unexpected close bracket", *posp, CURLE_URL_MALFORMAT);
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2004-10-06 03:50:18 -04:00
|
|
|
case '\\': /* escaped character, skip '\' */
|
2010-06-28 18:17:38 -04:00
|
|
|
if(pattern[1]) {
|
2004-12-15 04:23:24 -05:00
|
|
|
++pattern;
|
2013-09-06 17:27:47 -04:00
|
|
|
++(*posp);
|
2004-12-15 04:23:24 -05:00
|
|
|
}
|
|
|
|
/* intentional fallthrough */
|
1999-12-29 09:20:26 -05:00
|
|
|
default:
|
2004-10-06 03:50:18 -04:00
|
|
|
*buf++ = *pattern++; /* copy character to set element */
|
2013-09-06 17:27:47 -04:00
|
|
|
++(*posp);
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
|
|
|
|
*patternp = pattern; /* return with the new position */
|
2014-12-15 19:00:23 -05:00
|
|
|
return CURLE_OK;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
static CURLcode glob_range(URLGlob *glob, char **patternp,
|
2013-09-06 17:27:47 -04:00
|
|
|
size_t *posp, unsigned long *amount,
|
2013-08-15 07:05:25 -04:00
|
|
|
int globindex)
|
2000-12-06 05:10:31 -05:00
|
|
|
{
|
1999-12-29 09:20:26 -05:00
|
|
|
/* processes a range expression with the point behind the opening '['
|
|
|
|
- char range: e.g. "a-z]", "B-Q]"
|
|
|
|
- num range: e.g. "0-9]", "17-2000]"
|
|
|
|
- num range with leading zeros: e.g. "001-999]"
|
|
|
|
expression is checked for well-formedness and collected until the next ']'
|
|
|
|
*/
|
|
|
|
URLPattern *pat;
|
2005-11-10 17:11:01 -05:00
|
|
|
int rc;
|
2013-08-15 07:05:25 -04:00
|
|
|
char *pattern = *patternp;
|
|
|
|
char *c;
|
2004-07-02 08:28:57 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
pat = &glob->pattern[glob->size];
|
|
|
|
pat->globindex = globindex;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2011-10-05 14:16:16 -04:00
|
|
|
if(ISALPHA(*pattern)) {
|
|
|
|
/* character range detected */
|
2005-11-10 17:11:01 -05:00
|
|
|
char min_c;
|
|
|
|
char max_c;
|
2016-10-04 11:25:09 -04:00
|
|
|
char end_c;
|
2017-02-15 02:31:09 -05:00
|
|
|
unsigned long step = 1;
|
2005-11-10 17:11:01 -05:00
|
|
|
|
1999-12-29 09:20:26 -05:00
|
|
|
pat->type = UPTCharRange;
|
2011-10-05 14:16:16 -04:00
|
|
|
|
2016-10-04 11:25:09 -04:00
|
|
|
rc = sscanf(pattern, "%c-%c%c", &min_c, &max_c, &end_c);
|
|
|
|
|
|
|
|
if(rc == 3) {
|
|
|
|
if(end_c == ':') {
|
|
|
|
char *endp;
|
|
|
|
errno = 0;
|
2017-02-15 02:31:09 -05:00
|
|
|
step = strtoul(&pattern[4], &endp, 10);
|
2016-11-24 22:25:14 -05:00
|
|
|
if(errno || &pattern[4] == endp || *endp != ']')
|
2017-02-15 02:31:09 -05:00
|
|
|
step = 0;
|
|
|
|
else
|
2017-09-09 17:55:08 -04:00
|
|
|
pattern = endp + 1;
|
2013-08-15 07:05:25 -04:00
|
|
|
}
|
2016-10-04 11:25:09 -04:00
|
|
|
else if(end_c != ']')
|
|
|
|
/* then this is wrong */
|
|
|
|
rc = 0;
|
2016-11-15 02:22:54 -05:00
|
|
|
else
|
|
|
|
/* end_c == ']' */
|
|
|
|
pattern += 4;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2013-09-06 17:27:47 -04:00
|
|
|
*posp += (pattern - *patternp);
|
|
|
|
|
2017-02-15 02:31:09 -05:00
|
|
|
if(rc != 3 || !step || step > (unsigned)INT_MAX ||
|
|
|
|
(min_c == max_c && step != 1) ||
|
|
|
|
(min_c != max_c && (min_c > max_c || step > (unsigned)(max_c - min_c) ||
|
|
|
|
(max_c - min_c) > ('z' - 'a'))))
|
2013-08-15 07:05:25 -04:00
|
|
|
/* the pattern is not well-formed */
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2005-11-10 17:11:01 -05:00
|
|
|
/* if there was a ":[num]" thing, use that as step or else use 1 */
|
2017-02-15 02:31:09 -05:00
|
|
|
pat->content.CharRange.step = (int)step;
|
2005-11-10 17:11:01 -05:00
|
|
|
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
|
|
|
|
pat->content.CharRange.max_c = max_c;
|
2013-08-15 07:05:25 -04:00
|
|
|
|
2017-02-15 02:31:09 -05:00
|
|
|
if(multiply(amount, ((pat->content.CharRange.max_c -
|
2015-03-25 07:23:42 -04:00
|
|
|
pat->content.CharRange.min_c) /
|
2017-02-15 02:31:09 -05:00
|
|
|
pat->content.CharRange.step + 1)))
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2011-10-05 14:16:16 -04:00
|
|
|
else if(ISDIGIT(*pattern)) {
|
|
|
|
/* numeric range detected */
|
2013-08-15 07:05:25 -04:00
|
|
|
unsigned long min_n;
|
2013-08-26 06:41:35 -04:00
|
|
|
unsigned long max_n = 0;
|
|
|
|
unsigned long step_n = 0;
|
2013-08-15 07:05:25 -04:00
|
|
|
char *endp;
|
2001-01-23 05:14:43 -05:00
|
|
|
|
1999-12-29 09:20:26 -05:00
|
|
|
pat->type = UPTNumRange;
|
|
|
|
pat->content.NumRange.padlength = 0;
|
2005-11-10 17:11:01 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
if(*pattern == '0') {
|
|
|
|
/* leading zero specified, count them! */
|
|
|
|
c = pattern;
|
|
|
|
while(ISDIGIT(*c)) {
|
|
|
|
c++;
|
|
|
|
++pat->content.NumRange.padlength; /* padding length is set for all
|
|
|
|
instances of this pattern */
|
|
|
|
}
|
|
|
|
}
|
2005-11-10 17:11:01 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
errno = 0;
|
|
|
|
min_n = strtoul(pattern, &endp, 10);
|
|
|
|
if(errno || (endp == pattern))
|
2017-09-09 17:09:06 -04:00
|
|
|
endp = NULL;
|
2013-08-15 07:05:25 -04:00
|
|
|
else {
|
|
|
|
if(*endp != '-')
|
|
|
|
endp = NULL;
|
|
|
|
else {
|
2017-09-09 17:55:08 -04:00
|
|
|
pattern = endp + 1;
|
2016-10-03 11:27:16 -04:00
|
|
|
while(*pattern && ISBLANK(*pattern))
|
|
|
|
pattern++;
|
|
|
|
if(!ISDIGIT(*pattern)) {
|
|
|
|
endp = NULL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
errno = 0;
|
|
|
|
max_n = strtoul(pattern, &endp, 10);
|
2017-08-01 11:16:07 -04:00
|
|
|
if(errno)
|
|
|
|
/* overflow */
|
|
|
|
endp = NULL;
|
|
|
|
else if(*endp == ':') {
|
2017-09-09 17:55:08 -04:00
|
|
|
pattern = endp + 1;
|
2013-08-15 07:05:25 -04:00
|
|
|
errno = 0;
|
|
|
|
step_n = strtoul(pattern, &endp, 10);
|
|
|
|
if(errno)
|
|
|
|
/* over/underflow situation */
|
|
|
|
endp = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
step_n = 1;
|
2013-09-06 08:12:44 -04:00
|
|
|
if(endp && (*endp == ']')) {
|
2017-09-09 17:55:08 -04:00
|
|
|
pattern = endp + 1;
|
2013-08-15 07:05:25 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
endp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 11:27:16 -04:00
|
|
|
fail:
|
2013-09-06 17:27:47 -04:00
|
|
|
*posp += (pattern - *patternp);
|
|
|
|
|
2017-02-15 02:31:09 -05:00
|
|
|
if(!endp || !step_n ||
|
|
|
|
(min_n == max_n && step_n != 1) ||
|
|
|
|
(min_n != max_n && (min_n > max_n || step_n > (max_n - min_n))))
|
2004-07-02 08:28:57 -04:00
|
|
|
/* the pattern is not well-formed */
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
|
2013-09-06 17:27:47 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
/* typecasting to ints are fine here since we make sure above that we
|
|
|
|
are within 31 bits */
|
2011-10-05 14:16:16 -04:00
|
|
|
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n;
|
2005-11-10 17:11:01 -05:00
|
|
|
pat->content.NumRange.max_n = max_n;
|
2013-08-15 07:05:25 -04:00
|
|
|
pat->content.NumRange.step = step_n;
|
2005-11-10 17:11:01 -05:00
|
|
|
|
2017-02-15 02:31:09 -05:00
|
|
|
if(multiply(amount, ((pat->content.NumRange.max_n -
|
|
|
|
pat->content.NumRange.min_n) /
|
|
|
|
pat->content.NumRange.step + 1)))
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
|
2005-11-10 17:11:01 -05:00
|
|
|
}
|
2013-09-06 17:27:47 -04:00
|
|
|
else
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("bad range specification", *posp, CURLE_URL_MALFORMAT);
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
*patternp = pattern;
|
2014-12-15 19:00:23 -05:00
|
|
|
return CURLE_OK;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2014-03-30 01:50:37 -04:00
|
|
|
static bool peek_ipv6(const char *str, size_t *skip)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Scan for a potential IPv6 literal.
|
|
|
|
* - Valid globs contain a hyphen and <= 1 colon.
|
|
|
|
* - IPv6 literals contain no hyphens and >= 2 colons.
|
|
|
|
*/
|
|
|
|
size_t i = 0;
|
|
|
|
size_t colons = 0;
|
|
|
|
if(str[i++] != '[') {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
for(;;) {
|
|
|
|
const char c = str[i++];
|
|
|
|
if(ISALNUM(c) || c == '.' || c == '%') {
|
|
|
|
/* ok */
|
|
|
|
}
|
|
|
|
else if(c == ':') {
|
|
|
|
colons++;
|
|
|
|
}
|
|
|
|
else if(c == ']') {
|
|
|
|
*skip = i;
|
2014-05-09 08:15:59 -04:00
|
|
|
return colons >= 2 ? TRUE : FALSE;
|
2014-03-30 01:50:37 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
static CURLcode glob_parse(URLGlob *glob, char *pattern,
|
2013-08-15 07:05:25 -04:00
|
|
|
size_t pos, unsigned long *amount)
|
2000-12-06 05:10:31 -05:00
|
|
|
{
|
1999-12-29 09:20:26 -05:00
|
|
|
/* processes a literal string component of a URL
|
|
|
|
special characters '{' and '[' branch to set/range processing functions
|
2004-07-02 08:28:57 -04:00
|
|
|
*/
|
2014-12-15 19:00:23 -05:00
|
|
|
CURLcode res = CURLE_OK;
|
2013-08-15 07:05:25 -04:00
|
|
|
int globindex = 0; /* count "actual" globs */
|
|
|
|
|
2013-11-28 17:31:31 -05:00
|
|
|
*amount = 1;
|
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
while(*pattern && !res) {
|
2013-10-21 18:01:17 -04:00
|
|
|
char *buf = glob->glob_buffer;
|
2014-03-30 01:50:37 -04:00
|
|
|
size_t sublen = 0;
|
|
|
|
while(*pattern && *pattern != '{') {
|
|
|
|
if(*pattern == '[') {
|
2017-11-03 09:04:53 -04:00
|
|
|
/* skip over IPv6 literals and [] */
|
|
|
|
size_t skip = 0;
|
|
|
|
if(!peek_ipv6(pattern, &skip) && (pattern[1] == ']'))
|
|
|
|
skip = 2;
|
|
|
|
if(skip) {
|
2014-03-30 01:50:37 -04:00
|
|
|
memcpy(buf, pattern, skip);
|
|
|
|
buf += skip;
|
|
|
|
pattern += skip;
|
|
|
|
sublen += skip;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-09-06 17:27:47 -04:00
|
|
|
if(*pattern == '}' || *pattern == ']')
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("unmatched close brace/bracket", pos,
|
|
|
|
CURLE_URL_MALFORMAT);
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
/* only allow \ to escape known "special letters" */
|
|
|
|
if(*pattern == '\\' &&
|
2017-09-09 17:55:08 -04:00
|
|
|
(*(pattern + 1) == '{' || *(pattern + 1) == '[' ||
|
|
|
|
*(pattern + 1) == '}' || *(pattern + 1) == ']') ) {
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
/* escape character, skip '\' */
|
|
|
|
++pattern;
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
*buf++ = *pattern++; /* copy character to literal */
|
|
|
|
++pos;
|
|
|
|
sublen++;
|
|
|
|
}
|
|
|
|
if(sublen) {
|
|
|
|
/* we got a literal string, add it as a single-item list */
|
|
|
|
*buf = '\0';
|
2013-11-28 17:31:31 -05:00
|
|
|
res = glob_fixed(glob, glob->glob_buffer, sublen);
|
2010-10-08 17:12:34 -04:00
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
else {
|
|
|
|
switch (*pattern) {
|
|
|
|
case '\0': /* done */
|
|
|
|
break;
|
2002-03-06 17:52:00 -05:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
case '{':
|
|
|
|
/* process set pattern */
|
|
|
|
pattern++;
|
2013-09-06 17:27:47 -04:00
|
|
|
pos++;
|
|
|
|
res = glob_set(glob, &pattern, &pos, amount, globindex++);
|
2013-08-15 07:05:25 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
/* process range pattern */
|
|
|
|
pattern++;
|
2013-09-06 17:27:47 -04:00
|
|
|
pos++;
|
|
|
|
res = glob_range(glob, &pattern, &pos, amount, globindex++);
|
2013-08-15 07:05:25 -04:00
|
|
|
break;
|
|
|
|
}
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2016-06-03 05:26:20 -04:00
|
|
|
if(++glob->size >= GLOB_PATTERN_NUM)
|
2014-12-15 19:00:23 -05:00
|
|
|
return GLOBERROR("too many globs", pos, CURLE_URL_MALFORMAT);
|
2013-08-15 07:05:25 -04:00
|
|
|
}
|
2011-10-05 14:16:16 -04:00
|
|
|
return res;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2016-11-23 01:53:24 -05:00
|
|
|
CURLcode glob_url(URLGlob **glob, char *url, unsigned long *urlnum,
|
2014-12-15 19:00:23 -05:00
|
|
|
FILE *error)
|
2000-05-09 08:29:28 -04:00
|
|
|
{
|
2000-11-20 03:54:32 -05:00
|
|
|
/*
|
|
|
|
* We can deal with any-size, just make a buffer with the same length
|
|
|
|
* as the specified URL!
|
|
|
|
*/
|
2000-12-06 05:10:31 -05:00
|
|
|
URLGlob *glob_expand;
|
2013-08-15 07:05:25 -04:00
|
|
|
unsigned long amount = 0;
|
2011-10-05 14:16:16 -04:00
|
|
|
char *glob_buffer;
|
2014-12-15 19:00:23 -05:00
|
|
|
CURLcode res;
|
2001-01-23 05:14:43 -05:00
|
|
|
|
2004-03-08 07:47:37 -05:00
|
|
|
*glob = NULL;
|
2011-10-05 14:16:16 -04:00
|
|
|
|
|
|
|
glob_buffer = malloc(strlen(url) + 1);
|
|
|
|
if(!glob_buffer)
|
2000-11-20 03:54:32 -05:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2017-09-09 17:09:06 -04:00
|
|
|
glob_buffer[0] = 0;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2009-11-18 05:33:54 -05:00
|
|
|
glob_expand = calloc(1, sizeof(URLGlob));
|
2011-10-05 14:16:16 -04:00
|
|
|
if(!glob_expand) {
|
2011-09-15 14:03:30 -04:00
|
|
|
Curl_safefree(glob_buffer);
|
2000-12-06 05:10:31 -05:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
glob_expand->urllen = strlen(url);
|
|
|
|
glob_expand->glob_buffer = glob_buffer;
|
2011-10-05 14:16:16 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
res = glob_parse(glob_expand, url, 1, &amount);
|
2011-10-05 14:16:16 -04:00
|
|
|
if(!res)
|
2001-01-23 05:14:43 -05:00
|
|
|
*urlnum = amount;
|
|
|
|
else {
|
2013-09-06 17:27:47 -04:00
|
|
|
if(error && glob_expand->error) {
|
|
|
|
char text[128];
|
|
|
|
const char *t;
|
|
|
|
if(glob_expand->pos) {
|
|
|
|
snprintf(text, sizeof(text), "%s in column %zu", glob_expand->error,
|
|
|
|
glob_expand->pos);
|
|
|
|
t = text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
t = glob_expand->error;
|
|
|
|
|
2004-03-08 07:47:37 -05:00
|
|
|
/* send error description to the error-stream */
|
2013-09-06 17:27:47 -04:00
|
|
|
fprintf(error, "curl: (%d) [globbing] %s\n", res, t);
|
2004-03-08 07:47:37 -05:00
|
|
|
}
|
2001-01-23 05:14:43 -05:00
|
|
|
/* it failed, we cleanup */
|
2013-08-15 07:05:25 -04:00
|
|
|
glob_cleanup(glob_expand);
|
2001-01-23 05:14:43 -05:00
|
|
|
*urlnum = 1;
|
2013-09-06 08:20:03 -04:00
|
|
|
return res;
|
2001-01-23 05:14:43 -05:00
|
|
|
}
|
|
|
|
|
1999-12-29 09:20:26 -05:00
|
|
|
*glob = glob_expand;
|
2000-05-22 10:12:12 -04:00
|
|
|
return CURLE_OK;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2000-12-06 05:10:31 -05:00
|
|
|
void glob_cleanup(URLGlob* glob)
|
|
|
|
{
|
2004-07-02 08:28:57 -04:00
|
|
|
size_t i;
|
|
|
|
int elem;
|
2000-10-12 05:12:24 -04:00
|
|
|
|
2014-12-14 17:32:53 -05:00
|
|
|
for(i = 0; i < glob->size; i++) {
|
2013-08-15 07:05:25 -04:00
|
|
|
if((glob->pattern[i].type == UPTSet) &&
|
|
|
|
(glob->pattern[i].content.Set.elements)) {
|
|
|
|
for(elem = glob->pattern[i].content.Set.size - 1;
|
|
|
|
elem >= 0;
|
|
|
|
--elem) {
|
|
|
|
Curl_safefree(glob->pattern[i].content.Set.elements[elem]);
|
2000-10-12 05:12:24 -04:00
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
Curl_safefree(glob->pattern[i].content.Set.elements);
|
2000-10-12 05:12:24 -04:00
|
|
|
}
|
|
|
|
}
|
2011-09-15 14:03:30 -04:00
|
|
|
Curl_safefree(glob->glob_buffer);
|
|
|
|
Curl_safefree(glob);
|
2000-10-12 05:12:24 -04:00
|
|
|
}
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
CURLcode glob_next_url(char **globbed, URLGlob *glob)
|
2000-05-09 08:29:28 -04:00
|
|
|
{
|
1999-12-29 09:20:26 -05:00
|
|
|
URLPattern *pat;
|
2004-07-02 08:28:57 -04:00
|
|
|
size_t i;
|
2006-03-28 02:51:59 -05:00
|
|
|
size_t len;
|
2011-10-05 14:16:16 -04:00
|
|
|
size_t buflen = glob->urllen + 1;
|
|
|
|
char *buf = glob->glob_buffer;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2011-10-05 16:01:42 -04:00
|
|
|
*globbed = NULL;
|
|
|
|
|
2011-04-25 16:44:39 -04:00
|
|
|
if(!glob->beenhere)
|
2001-01-08 02:37:44 -05:00
|
|
|
glob->beenhere = 1;
|
1999-12-29 09:20:26 -05:00
|
|
|
else {
|
2005-11-10 17:11:01 -05:00
|
|
|
bool carry = TRUE;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2014-12-15 18:51:22 -05:00
|
|
|
/* implement a counter over the index ranges of all patterns, starting
|
|
|
|
with the rightmost pattern */
|
2014-12-16 03:01:56 -05:00
|
|
|
for(i = 0; carry && (i < glob->size); i++) {
|
2005-11-10 17:11:01 -05:00
|
|
|
carry = FALSE;
|
2014-12-16 03:01:56 -05:00
|
|
|
pat = &glob->pattern[glob->size - 1 - i];
|
2016-12-13 17:34:59 -05:00
|
|
|
switch(pat->type) {
|
1999-12-29 09:20:26 -05:00
|
|
|
case UPTSet:
|
2011-09-10 12:46:05 -04:00
|
|
|
if((pat->content.Set.elements) &&
|
|
|
|
(++pat->content.Set.ptr_s == pat->content.Set.size)) {
|
2004-10-06 03:50:18 -04:00
|
|
|
pat->content.Set.ptr_s = 0;
|
2005-11-10 17:11:01 -05:00
|
|
|
carry = TRUE;
|
2004-10-06 03:50:18 -04:00
|
|
|
}
|
|
|
|
break;
|
1999-12-29 09:20:26 -05:00
|
|
|
case UPTCharRange:
|
2014-12-14 17:32:53 -05:00
|
|
|
pat->content.CharRange.ptr_c =
|
|
|
|
(char)(pat->content.CharRange.step +
|
|
|
|
(int)((unsigned char)pat->content.CharRange.ptr_c));
|
2011-04-25 16:44:39 -04:00
|
|
|
if(pat->content.CharRange.ptr_c > pat->content.CharRange.max_c) {
|
2004-10-06 03:50:18 -04:00
|
|
|
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c;
|
2005-11-10 17:11:01 -05:00
|
|
|
carry = TRUE;
|
2004-10-06 03:50:18 -04:00
|
|
|
}
|
|
|
|
break;
|
1999-12-29 09:20:26 -05:00
|
|
|
case UPTNumRange:
|
2005-11-10 17:11:01 -05:00
|
|
|
pat->content.NumRange.ptr_n += pat->content.NumRange.step;
|
2011-04-25 16:44:39 -04:00
|
|
|
if(pat->content.NumRange.ptr_n > pat->content.NumRange.max_n) {
|
2004-10-06 03:50:18 -04:00
|
|
|
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n;
|
2005-11-10 17:11:01 -05:00
|
|
|
carry = TRUE;
|
2004-10-06 03:50:18 -04:00
|
|
|
}
|
|
|
|
break;
|
1999-12-29 09:20:26 -05:00
|
|
|
default:
|
2004-10-06 03:50:18 -04:00
|
|
|
printf("internal error: invalid pattern type (%d)\n", (int)pat->type);
|
2011-10-05 16:01:42 -04:00
|
|
|
return CURLE_FAILED_INIT;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
}
|
2011-10-05 16:01:42 -04:00
|
|
|
if(carry) { /* first pattern ptr has run into overflow, done! */
|
|
|
|
/* TODO: verify if this should actally return CURLE_OK. */
|
|
|
|
return CURLE_OK; /* CURLE_OK to match previous behavior */
|
|
|
|
}
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2014-12-14 17:32:53 -05:00
|
|
|
for(i = 0; i < glob->size; ++i) {
|
|
|
|
pat = &glob->pattern[i];
|
2013-08-15 07:05:25 -04:00
|
|
|
switch(pat->type) {
|
|
|
|
case UPTSet:
|
|
|
|
if(pat->content.Set.elements) {
|
|
|
|
snprintf(buf, buflen, "%s",
|
|
|
|
pat->content.Set.elements[pat->content.Set.ptr_s]);
|
2016-10-03 12:23:22 -04:00
|
|
|
len = strlen(buf);
|
2006-03-28 02:51:59 -05:00
|
|
|
buf += len;
|
|
|
|
buflen -= len;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
break;
|
|
|
|
case UPTCharRange:
|
2016-10-03 12:23:22 -04:00
|
|
|
if(buflen) {
|
|
|
|
*buf++ = pat->content.CharRange.ptr_c;
|
|
|
|
*buf = '\0';
|
|
|
|
buflen--;
|
|
|
|
}
|
2013-08-15 07:05:25 -04:00
|
|
|
break;
|
|
|
|
case UPTNumRange:
|
2018-05-11 11:34:55 -04:00
|
|
|
snprintf(buf, buflen, "%0*lu",
|
2016-10-03 12:23:22 -04:00
|
|
|
pat->content.NumRange.padlength,
|
|
|
|
pat->content.NumRange.ptr_n);
|
|
|
|
len = strlen(buf);
|
2013-08-15 07:05:25 -04:00
|
|
|
buf += len;
|
|
|
|
buflen -= len;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("internal error: invalid pattern type (%d)\n", (int)pat->type);
|
|
|
|
return CURLE_FAILED_INIT;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
}
|
2011-10-05 16:01:42 -04:00
|
|
|
|
|
|
|
*globbed = strdup(glob->glob_buffer);
|
|
|
|
if(!*globbed)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
|
|
|
|
2014-12-15 19:00:23 -05:00
|
|
|
CURLcode glob_match_url(char **result, char *filename, URLGlob *glob)
|
2000-12-06 05:10:31 -05:00
|
|
|
{
|
|
|
|
char *target;
|
2004-03-23 04:12:51 -05:00
|
|
|
size_t allocsize;
|
2000-12-06 05:10:31 -05:00
|
|
|
char numbuf[18];
|
2004-01-16 04:17:04 -05:00
|
|
|
char *appendthis = NULL;
|
2004-03-23 04:12:51 -05:00
|
|
|
size_t appendlen = 0;
|
2011-10-05 14:16:16 -04:00
|
|
|
size_t stringlen = 0;
|
2000-12-06 05:10:31 -05:00
|
|
|
|
2011-10-05 16:01:42 -04:00
|
|
|
*result = NULL;
|
|
|
|
|
2000-12-06 05:10:31 -05:00
|
|
|
/* We cannot use the glob_buffer for storage here since the filename may
|
|
|
|
* be longer than the URL we use. We allocate a good start size, then
|
|
|
|
* we need to realloc in case of need.
|
|
|
|
*/
|
2011-10-05 14:16:16 -04:00
|
|
|
allocsize = strlen(filename) + 1; /* make it at least one byte to store the
|
|
|
|
trailing zero */
|
2000-12-06 05:10:31 -05:00
|
|
|
target = malloc(allocsize);
|
2011-10-05 14:16:16 -04:00
|
|
|
if(!target)
|
2011-10-05 16:01:42 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
1999-12-29 09:20:26 -05:00
|
|
|
|
2011-04-25 16:44:39 -04:00
|
|
|
while(*filename) {
|
|
|
|
if(*filename == '#' && ISDIGIT(filename[1])) {
|
2004-03-23 04:12:51 -05:00
|
|
|
unsigned long i;
|
2004-07-26 05:11:10 -04:00
|
|
|
char *ptr = filename;
|
2003-08-14 07:53:09 -04:00
|
|
|
unsigned long num = strtoul(&filename[1], &filename, 10);
|
2017-09-09 17:09:06 -04:00
|
|
|
URLPattern *pat = NULL;
|
2013-08-15 07:05:25 -04:00
|
|
|
|
|
|
|
if(num < glob->size) {
|
|
|
|
num--; /* make it zero based */
|
|
|
|
/* find the correct glob entry */
|
2017-09-09 17:09:06 -04:00
|
|
|
for(i = 0; i<glob->size; i++) {
|
2013-08-15 07:05:25 -04:00
|
|
|
if(glob->pattern[i].globindex == (int)num) {
|
|
|
|
pat = &glob->pattern[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-14 07:53:09 -04:00
|
|
|
|
2013-08-15 07:05:25 -04:00
|
|
|
if(pat) {
|
2016-12-13 17:34:59 -05:00
|
|
|
switch(pat->type) {
|
2003-08-14 07:53:09 -04:00
|
|
|
case UPTSet:
|
2013-08-15 07:05:25 -04:00
|
|
|
if(pat->content.Set.elements) {
|
|
|
|
appendthis = pat->content.Set.elements[pat->content.Set.ptr_s];
|
2011-09-10 12:46:05 -04:00
|
|
|
appendlen =
|
2013-08-15 07:05:25 -04:00
|
|
|
strlen(pat->content.Set.elements[pat->content.Set.ptr_s]);
|
2011-09-10 12:46:05 -04:00
|
|
|
}
|
2003-08-14 07:53:09 -04:00
|
|
|
break;
|
|
|
|
case UPTCharRange:
|
2013-08-15 07:05:25 -04:00
|
|
|
numbuf[0] = pat->content.CharRange.ptr_c;
|
2011-10-05 14:16:16 -04:00
|
|
|
numbuf[1] = 0;
|
|
|
|
appendthis = numbuf;
|
|
|
|
appendlen = 1;
|
2003-08-14 07:53:09 -04:00
|
|
|
break;
|
|
|
|
case UPTNumRange:
|
2017-02-19 08:10:54 -05:00
|
|
|
snprintf(numbuf, sizeof(numbuf), "%0*lu",
|
2013-08-15 07:05:25 -04:00
|
|
|
pat->content.NumRange.padlength,
|
|
|
|
pat->content.NumRange.ptr_n);
|
2003-08-14 07:53:09 -04:00
|
|
|
appendthis = numbuf;
|
2004-03-23 04:12:51 -05:00
|
|
|
appendlen = strlen(numbuf);
|
2003-08-14 07:53:09 -04:00
|
|
|
break;
|
|
|
|
default:
|
2013-08-15 07:05:25 -04:00
|
|
|
fprintf(stderr, "internal error: invalid pattern type (%d)\n",
|
|
|
|
(int)pat->type);
|
2011-09-15 14:03:30 -04:00
|
|
|
Curl_safefree(target);
|
2011-10-05 16:01:42 -04:00
|
|
|
return CURLE_FAILED_INIT;
|
2003-08-14 07:53:09 -04:00
|
|
|
}
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2004-07-26 05:11:10 -04:00
|
|
|
else {
|
|
|
|
/* #[num] out of range, use the #[num] in the output */
|
|
|
|
filename = ptr;
|
2011-10-05 14:16:16 -04:00
|
|
|
appendthis = filename++;
|
|
|
|
appendlen = 1;
|
2004-07-26 05:11:10 -04:00
|
|
|
}
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2000-12-06 05:10:31 -05:00
|
|
|
else {
|
2011-10-05 14:16:16 -04:00
|
|
|
appendthis = filename++;
|
|
|
|
appendlen = 1;
|
2000-12-06 05:10:31 -05:00
|
|
|
}
|
|
|
|
if(appendlen + stringlen >= allocsize) {
|
|
|
|
char *newstr;
|
2008-10-13 17:39:12 -04:00
|
|
|
/* we append a single byte to allow for the trailing byte to be appended
|
|
|
|
at the end of this function outside the while() loop */
|
2011-10-05 14:16:16 -04:00
|
|
|
allocsize = (appendlen + stringlen) * 2;
|
|
|
|
newstr = realloc(target, allocsize + 1);
|
|
|
|
if(!newstr) {
|
2011-09-15 14:03:30 -04:00
|
|
|
Curl_safefree(target);
|
2011-10-05 16:01:42 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2000-12-06 05:10:31 -05:00
|
|
|
}
|
2011-10-05 14:16:16 -04:00
|
|
|
target = newstr;
|
2000-12-06 05:10:31 -05:00
|
|
|
}
|
|
|
|
memcpy(&target[stringlen], appendthis, appendlen);
|
|
|
|
stringlen += appendlen;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|
2000-12-06 05:10:31 -05:00
|
|
|
target[stringlen]= '\0';
|
2016-02-05 01:44:27 -05:00
|
|
|
|
|
|
|
#if defined(MSDOS) || defined(WIN32)
|
|
|
|
{
|
|
|
|
char *sanitized;
|
|
|
|
SANITIZEcode sc = sanitize_file_name(&sanitized, target,
|
2016-02-08 15:09:42 -05:00
|
|
|
(SANITIZE_ALLOW_PATH |
|
|
|
|
SANITIZE_ALLOW_RESERVED));
|
2016-02-05 01:44:27 -05:00
|
|
|
Curl_safefree(target);
|
|
|
|
if(sc)
|
|
|
|
return CURLE_URL_MALFORMAT;
|
|
|
|
target = sanitized;
|
|
|
|
}
|
|
|
|
#endif /* MSDOS || WIN32 */
|
|
|
|
|
2011-10-05 16:01:42 -04:00
|
|
|
*result = target;
|
|
|
|
return CURLE_OK;
|
1999-12-29 09:20:26 -05:00
|
|
|
}
|