return PARAM_OK;
}
+static ParameterError getstrn(char **str, const char *val,
+ size_t len, bool allowblank)
+{
+ if(*str) {
+ free(*str);
+ *str = NULL;
+ }
+ if(val) {
+ if(!allowblank && !val[0])
+ return PARAM_BLANK_STRING;
+
+ *str = malloc(len + 1);
+ if(!*str)
+ return PARAM_NO_MEM;
+
+ memcpy(*str, val, len);
+ (*str)[len] = 0; /* null terminate */
+ }
+ return PARAM_OK;
+}
+
/* this array MUST be alphasorted based on the 'lname' */
static const struct LongShort aliases[]= {
{"abstract-unix-socket", ARG_FILE, ' ', C_ABSTRACT_UNIX_SOCKET},
}
static void
-GetFileAndPassword(char *nextarg, char **file, char **password)
+GetFileAndPassword(const char *nextarg, char **file, char **password)
{
char *certname, *passphrase;
if(nextarg) {
/* --data-urlencode */
static ParameterError data_urlencode(struct GlobalConfig *global,
- char *nextarg,
+ const char *nextarg,
char **postp,
size_t *lenp)
{
}
#define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
-static ParameterError url_query(char *nextarg,
+static ParameterError url_query(const char *nextarg,
struct GlobalConfig *global,
struct OperationConfig *config)
{
}
static ParameterError set_data(cmdline_t cmd,
- char *nextarg,
+ const char *nextarg,
struct GlobalConfig *global,
struct OperationConfig *config)
{
}
static ParameterError set_rate(struct GlobalConfig *global,
- char *nextarg)
+ const char *nextarg)
{
/* --rate */
/* support a few different suffixes, extract the suffix first, then
static ParameterError parse_localport(struct OperationConfig *config,
- char *nextarg)
+ const char *nextarg)
{
- char *pp = NULL;
- char *p = nextarg;
+ const char *pp = NULL;
+ const char *p = nextarg;
+ char buffer[22];
+ size_t plen = 0;
while(ISDIGIT(*p))
p++;
+ plen = p - nextarg;
if(*p) {
pp = p;
/* check for ' - [end]' */
pp++;
if(*pp && ISSPACE(*pp))
pp++;
- *p = 0; /* null-terminate to make str2unum() work below */
}
-
- if(str2unummax(&config->localport, nextarg, 65535))
+ msnprintf(buffer, sizeof(buffer), "%.*s", (int)plen, nextarg);
+ if(str2unummax(&config->localport, buffer, 65535))
return PARAM_BAD_USE;
if(!pp)
config->localportrange = 1; /* default number of ports to try */
}
ParameterError getparameter(const char *flag, /* f or -long-flag */
- char *nextarg, /* NULL if unset */
+ const char *nextarg, /* NULL if unset */
argv_item_t cleararg1,
argv_item_t cleararg2,
bool *usedarg, /* set to TRUE if the arg
err = getstr(&config->headerfile, nextarg, DENY_BLANK);
break;
case C_REFERER: { /* --referer */
- char *ptr = strstr(nextarg, ";auto");
+ const char *ptr = strstr(nextarg, ";auto");
+ size_t len;
if(ptr) {
/* Automatic referer requested, this may be combined with a
set initial one */
config->autoreferer = TRUE;
- *ptr = 0; /* null-terminate here */
+ len = ptr - nextarg;
}
- else
+ else {
config->autoreferer = FALSE;
- ptr = *nextarg ? nextarg : NULL;
- err = getstr(&config->referer, ptr, ALLOW_BLANK);
+ len = strlen(nextarg);
+ }
+ ptr = len ? nextarg : NULL;
+ err = getstrn(&config->referer, ptr, len, ALLOW_BLANK);
}
break;
case C_CERT: /* --cert */
error:
if(nextalloc)
- free(nextarg);
+ free((char *)nextarg);
return err;
}
{
int i;
bool stillflags;
- char *orig_opt = NULL;
+ const char *orig_opt = NULL;
ParameterError result = PARAM_OK;
struct OperationConfig *config = global->first;
for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
-#ifdef UNDER_CE
- orig_opt = strdup(argv[i]);
-#else
- orig_opt = curlx_convert_tchar_to_UTF8(argv[i]);
-#endif
+ orig_opt = convert_tchar_to_UTF8(argv[i]);
if(!orig_opt)
return PARAM_NO_MEM;
following (URL) argument to start with -. */
stillflags = FALSE;
else {
- char *nextarg = NULL;
+ const char *nextarg = NULL;
if(i < (argc - 1)) {
-#ifdef UNDER_CE
- nextarg = strdup(argv[i + 1]);
-#else
- nextarg = curlx_convert_tchar_to_UTF8(argv[i + 1]);
-#endif
+ nextarg = convert_tchar_to_UTF8(argv[i + 1]);
if(!nextarg) {
- curlx_unicodefree(orig_opt);
+ unicodefree(orig_opt);
return PARAM_NO_MEM;
}
}
result = getparameter(orig_opt, nextarg, argv[i], argv[i + 1],
&passarg, global, config);
- curlx_unicodefree(nextarg);
+ unicodefree(nextarg);
config = global->last;
if(result == PARAM_NEXT_OPERATION) {
/* Reset result as PARAM_NEXT_OPERATION is only used here and not
}
if(!result)
- curlx_unicodefree(orig_opt);
+ unicodefree(orig_opt);
}
if(!result && config->content_disposition) {
helpf(tool_stderr, "%s", reason);
}
- curlx_unicodefree(orig_opt);
+ unicodefree(orig_opt);
return result;
}