• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 #include "tool_setup.h"
25 
26 #include "strcase.h"
27 
28 #define ENABLE_CURLX_PRINTF
29 /* use our own printf() functions */
30 #include "curlx.h"
31 
32 #include "tool_cfgable.h"
33 #include "tool_msgs.h"
34 #include "tool_getparam.h"
35 #include "tool_helpers.h"
36 
37 #include "memdebug.h" /* keep this as LAST include */
38 
39 /*
40 ** Helper functions that are used from more than one source file.
41 */
42 
param2text(ParameterError error)43 const char *param2text(ParameterError error)
44 {
45   switch(error) {
46   case PARAM_GOT_EXTRA_PARAMETER:
47     return "had unsupported trailing garbage";
48   case PARAM_OPTION_UNKNOWN:
49     return "is unknown";
50   case PARAM_OPTION_AMBIGUOUS:
51     return "is ambiguous";
52   case PARAM_REQUIRES_PARAMETER:
53     return "requires parameter";
54   case PARAM_BAD_USE:
55     return "is badly used here";
56   case PARAM_BAD_NUMERIC:
57     return "expected a proper numerical parameter";
58   case PARAM_NEGATIVE_NUMERIC:
59     return "expected a positive numerical parameter";
60   case PARAM_LIBCURL_DOESNT_SUPPORT:
61     return "the installed libcurl version doesn't support this";
62   case PARAM_LIBCURL_UNSUPPORTED_PROTOCOL:
63     return "a specified protocol is unsupported by libcurl";
64   case PARAM_NO_MEM:
65     return "out of memory";
66   case PARAM_NO_PREFIX:
67     return "the given option can't be reversed with a --no- prefix";
68   case PARAM_NUMBER_TOO_LARGE:
69     return "too large number";
70   case PARAM_NO_NOT_BOOLEAN:
71     return "used '--no-' for option that isn't a boolean";
72   case PARAM_CONTDISP_SHOW_HEADER:
73     return "showing headers and --remote-header-name cannot be combined";
74   case PARAM_CONTDISP_RESUME_FROM:
75     return "--continue-at and --remote-header-name cannot be combined";
76   case PARAM_READ_ERROR:
77     return "error encountered when reading a file";
78   case PARAM_EXPAND_ERROR:
79     return "variable expansion failure";
80   case PARAM_BLANK_STRING:
81     return "blank argument where content is expected";
82   default:
83     return "unknown error";
84   }
85 }
86 
SetHTTPrequest(struct OperationConfig * config,HttpReq req,HttpReq * store)87 int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
88 {
89   /* this mirrors the HttpReq enum in tool_sdecls.h */
90   const char *reqname[]= {
91     "", /* unspec */
92     "GET (-G, --get)",
93     "HEAD (-I, --head)",
94     "multipart formpost (-F, --form)",
95     "POST (-d, --data)",
96     "PUT (-T, --upload-file)"
97   };
98 
99   if((*store == HTTPREQ_UNSPEC) ||
100      (*store == req)) {
101     *store = req;
102     return 0;
103   }
104   warnf(config->global, "You can only select one HTTP request method! "
105         "You asked for both %s and %s.",
106         reqname[req], reqname[*store]);
107 
108   return 1;
109 }
110 
customrequest_helper(struct OperationConfig * config,HttpReq req,char * method)111 void customrequest_helper(struct OperationConfig *config, HttpReq req,
112                           char *method)
113 {
114   /* this mirrors the HttpReq enum in tool_sdecls.h */
115   const char *dflt[]= {
116     "GET",
117     "GET",
118     "HEAD",
119     "POST",
120     "POST",
121     "PUT"
122   };
123 
124   if(!method)
125     ;
126   else if(curl_strequal(method, dflt[req])) {
127     notef(config->global, "Unnecessary use of -X or --request, %s is already "
128           "inferred.", dflt[req]);
129   }
130   else if(curl_strequal(method, "head")) {
131     warnf(config->global,
132           "Setting custom HTTP method to HEAD with -X/--request may not work "
133           "the way you want. Consider using -I/--head instead.");
134   }
135 }
136