1 | /*************************************************************************** |
2 | * _ _ ____ _ |
3 | * Project ___| | | | _ \| | |
4 | * / __| | | | |_) | | |
5 | * | (__| |_| | _ <| |___ |
6 | * \___|\___/|_| \_\_____| |
7 | * |
8 | * Copyright (C) 1998 - 2019, 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.haxx.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 | ***************************************************************************/ |
22 | #include "tool_setup.h" |
23 | |
24 | #include "strcase.h" |
25 | |
26 | #define ENABLE_CURLX_PRINTF |
27 | /* use our own printf() functions */ |
28 | #include "curlx.h" |
29 | |
30 | #include "tool_cfgable.h" |
31 | #include "tool_msgs.h" |
32 | #include "tool_getparam.h" |
33 | #include "tool_helpers.h" |
34 | |
35 | #include "memdebug.h" /* keep this as LAST include */ |
36 | |
37 | /* |
38 | ** Helper functions that are used from more than one source file. |
39 | */ |
40 | |
41 | const char *param2text(int res) |
42 | { |
43 | ParameterError error = (ParameterError)res; |
44 | switch(error) { |
45 | case PARAM_GOT_EXTRA_PARAMETER: |
46 | return "had unsupported trailing garbage" ; |
47 | case PARAM_OPTION_UNKNOWN: |
48 | return "is unknown" ; |
49 | case PARAM_OPTION_AMBIGUOUS: |
50 | return "is ambiguous" ; |
51 | case PARAM_REQUIRES_PARAMETER: |
52 | return "requires parameter" ; |
53 | case PARAM_BAD_USE: |
54 | return "is badly used here" ; |
55 | case PARAM_BAD_NUMERIC: |
56 | return "expected a proper numerical parameter" ; |
57 | case PARAM_NEGATIVE_NUMERIC: |
58 | return "expected a positive numerical parameter" ; |
59 | case PARAM_LIBCURL_DOESNT_SUPPORT: |
60 | return "the installed libcurl version doesn't support this" ; |
61 | case PARAM_LIBCURL_UNSUPPORTED_PROTOCOL: |
62 | return "a specified protocol is unsupported by libcurl" ; |
63 | case PARAM_NO_MEM: |
64 | return "out of memory" ; |
65 | case PARAM_NO_PREFIX: |
66 | return "the given option can't be reversed with a --no- prefix" ; |
67 | case PARAM_NUMBER_TOO_LARGE: |
68 | return "too large number" ; |
69 | case PARAM_NO_NOT_BOOLEAN: |
70 | return "used '--no-' for option that isn't a boolean" ; |
71 | default: |
72 | return "unknown error" ; |
73 | } |
74 | } |
75 | |
76 | int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store) |
77 | { |
78 | /* this mirrors the HttpReq enum in tool_sdecls.h */ |
79 | const char *reqname[]= { |
80 | "" , /* unspec */ |
81 | "GET (-G, --get)" , |
82 | "HEAD (-I, --head)" , |
83 | "multipart formpost (-F, --form)" , |
84 | "POST (-d, --data)" |
85 | }; |
86 | |
87 | if((*store == HTTPREQ_UNSPEC) || |
88 | (*store == req)) { |
89 | *store = req; |
90 | return 0; |
91 | } |
92 | warnf(config->global, "You can only select one HTTP request method! " |
93 | "You asked for both %s and %s.\n" , |
94 | reqname[req], reqname[*store]); |
95 | |
96 | return 1; |
97 | } |
98 | |
99 | void customrequest_helper(struct OperationConfig *config, HttpReq req, |
100 | char *method) |
101 | { |
102 | /* this mirrors the HttpReq enum in tool_sdecls.h */ |
103 | const char *dflt[]= { |
104 | "GET" , |
105 | "GET" , |
106 | "HEAD" , |
107 | "POST" , |
108 | "POST" |
109 | }; |
110 | |
111 | if(!method) |
112 | ; |
113 | else if(curl_strequal(method, dflt[req])) { |
114 | notef(config->global, "Unnecessary use of -X or --request, %s is already " |
115 | "inferred.\n" , dflt[req]); |
116 | } |
117 | else if(curl_strequal(method, "head" )) { |
118 | warnf(config->global, |
119 | "Setting custom HTTP method to HEAD with -X/--request may not work " |
120 | "the way you want. Consider using -I/--head instead.\n" ); |
121 | } |
122 | } |
123 | |