2011-09-17 19:58:18 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2019-05-20 04:51:53 -04:00
|
|
|
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-09-17 19:58:18 -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.
|
2011-09-17 19:58:18 -04: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
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-04-06 17:35:15 -04:00
|
|
|
#include "tool_setup.h"
|
2011-09-17 19:58:18 -04:00
|
|
|
|
2016-09-30 12:54:02 -04:00
|
|
|
#include "strcase.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2011-09-17 19:58:18 -04:00
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* use our own printf() functions */
|
|
|
|
#include "curlx.h"
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
#include "tool_cfgable.h"
|
|
|
|
#include "tool_msgs.h"
|
|
|
|
#include "tool_getparam.h"
|
|
|
|
#include "tool_helpers.h"
|
2011-09-17 19:58:18 -04:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
2011-09-17 19:58:18 -04:00
|
|
|
|
|
|
|
/*
|
2016-09-03 17:14:07 -04:00
|
|
|
** Helper functions that are used from more than one source file.
|
2011-10-04 18:03:20 -04:00
|
|
|
*/
|
2011-09-17 19:58:18 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
const char *param2text(int res)
|
2011-09-17 19:58:18 -04:00
|
|
|
{
|
2011-10-04 18:03:20 -04:00
|
|
|
ParameterError error = (ParameterError)res;
|
|
|
|
switch(error) {
|
|
|
|
case PARAM_GOT_EXTRA_PARAMETER:
|
|
|
|
return "had unsupported trailing garbage";
|
|
|
|
case PARAM_OPTION_UNKNOWN:
|
|
|
|
return "is unknown";
|
|
|
|
case PARAM_OPTION_AMBIGUOUS:
|
|
|
|
return "is ambiguous";
|
|
|
|
case PARAM_REQUIRES_PARAMETER:
|
|
|
|
return "requires parameter";
|
|
|
|
case PARAM_BAD_USE:
|
|
|
|
return "is badly used here";
|
|
|
|
case PARAM_BAD_NUMERIC:
|
|
|
|
return "expected a proper numerical parameter";
|
2012-07-10 17:11:30 -04:00
|
|
|
case PARAM_NEGATIVE_NUMERIC:
|
|
|
|
return "expected a positive numerical parameter";
|
2011-10-04 18:03:20 -04:00
|
|
|
case PARAM_LIBCURL_DOESNT_SUPPORT:
|
|
|
|
return "the installed libcurl version doesn't support this";
|
2015-08-22 21:49:26 -04:00
|
|
|
case PARAM_LIBCURL_UNSUPPORTED_PROTOCOL:
|
|
|
|
return "a specified protocol is unsupported by libcurl";
|
2011-10-04 18:03:20 -04:00
|
|
|
case PARAM_NO_MEM:
|
|
|
|
return "out of memory";
|
2017-04-30 19:23:53 -04:00
|
|
|
case PARAM_NO_PREFIX:
|
|
|
|
return "the given option can't be reversed with a --no- prefix";
|
2017-08-06 14:10:40 -04:00
|
|
|
case PARAM_NUMBER_TOO_LARGE:
|
|
|
|
return "too large number";
|
2019-05-20 04:51:53 -04:00
|
|
|
case PARAM_NO_NOT_BOOLEAN:
|
|
|
|
return "used '--no-' for option that isn't a boolean";
|
2011-10-04 18:03:20 -04:00
|
|
|
default:
|
|
|
|
return "unknown error";
|
|
|
|
}
|
|
|
|
}
|
2011-09-17 19:58:18 -04:00
|
|
|
|
2014-02-23 07:59:59 -05:00
|
|
|
int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
|
2011-10-04 18:03:20 -04:00
|
|
|
{
|
2015-08-25 03:20:56 -04:00
|
|
|
/* this mirrors the HttpReq enum in tool_sdecls.h */
|
|
|
|
const char *reqname[]= {
|
|
|
|
"", /* unspec */
|
|
|
|
"GET (-G, --get)",
|
|
|
|
"HEAD (-I, --head)",
|
|
|
|
"multipart formpost (-F, --form)",
|
|
|
|
"POST (-d, --data)"
|
|
|
|
};
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if((*store == HTTPREQ_UNSPEC) ||
|
|
|
|
(*store == req)) {
|
|
|
|
*store = req;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-25 03:20:56 -04:00
|
|
|
warnf(config->global, "You can only select one HTTP request method! "
|
|
|
|
"You asked for both %s and %s.\n",
|
|
|
|
reqname[req], reqname[*store]);
|
2015-02-27 15:48:38 -05:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
return 1;
|
2011-09-17 19:58:18 -04:00
|
|
|
}
|
2015-08-29 17:56:28 -04:00
|
|
|
|
|
|
|
void customrequest_helper(struct OperationConfig *config, HttpReq req,
|
|
|
|
char *method)
|
|
|
|
{
|
|
|
|
/* this mirrors the HttpReq enum in tool_sdecls.h */
|
|
|
|
const char *dflt[]= {
|
|
|
|
"GET",
|
|
|
|
"GET",
|
|
|
|
"HEAD",
|
|
|
|
"POST",
|
|
|
|
"POST"
|
|
|
|
};
|
|
|
|
|
2015-09-11 12:49:28 -04:00
|
|
|
if(!method)
|
|
|
|
;
|
2016-10-31 16:49:38 -04:00
|
|
|
else if(curl_strequal(method, dflt[req])) {
|
2015-08-29 17:56:28 -04:00
|
|
|
notef(config->global, "Unnecessary use of -X or --request, %s is already "
|
|
|
|
"inferred.\n", dflt[req]);
|
|
|
|
}
|
2016-10-31 16:49:38 -04:00
|
|
|
else if(curl_strequal(method, "head")) {
|
2015-08-29 17:56:28 -04:00
|
|
|
warnf(config->global,
|
2015-11-24 04:11:06 -05:00
|
|
|
"Setting custom HTTP method to HEAD with -X/--request may not work "
|
|
|
|
"the way you want. Consider using -I/--head instead.\n");
|
2015-08-29 17:56:28 -04:00
|
|
|
}
|
|
|
|
}
|