tool_helpers.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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) {
46  return "had unsupported trailing garbage";
48  return "is unknown";
50  return "is ambiguous";
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";
58  return "expected a positive numerical parameter";
60  return "the installed libcurl version doesn't support this";
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";
68  return "too large number";
69  default:
70  return "unknown error";
71  }
72 }
73 
75 {
76  /* this mirrors the HttpReq enum in tool_sdecls.h */
77  const char *reqname[]= {
78  "", /* unspec */
79  "GET (-G, --get)",
80  "HEAD (-I, --head)",
81  "multipart formpost (-F, --form)",
82  "POST (-d, --data)"
83  };
84 
85  if((*store == HTTPREQ_UNSPEC) ||
86  (*store == req)) {
87  *store = req;
88  return 0;
89  }
90  warnf(config->global, "You can only select one HTTP request method! "
91  "You asked for both %s and %s.\n",
92  reqname[req], reqname[*store]);
93 
94  return 1;
95 }
96 
98  char *method)
99 {
100  /* this mirrors the HttpReq enum in tool_sdecls.h */
101  const char *dflt[]= {
102  "GET",
103  "GET",
104  "HEAD",
105  "POST",
106  "POST"
107  };
108 
109  if(!method)
110  ;
111  else if(curl_strequal(method, dflt[req])) {
112  notef(config->global, "Unnecessary use of -X or --request, %s is already "
113  "inferred.\n", dflt[req]);
114  }
115  else if(curl_strequal(method, "head")) {
116  warnf(config->global,
117  "Setting custom HTTP method to HEAD with -X/--request may not work "
118  "the way you want. Consider using -I/--head instead.\n");
119  }
120 }
Definition: ws_ssl.c:25
HttpReq
Definition: tool_sdecls.h:134
static int res
struct GlobalConfig * global
Definition: tool_cfgable.h:251
int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
Definition: tool_helpers.c:74
void customrequest_helper(struct OperationConfig *config, HttpReq req, char *method)
Definition: tool_helpers.c:97
ParameterError
Definition: tool_getparam.h:26
CURL_EXTERN int curl_strequal(const char *s1, const char *s2)
Definition: strcase.c:170
const char * param2text(int res)
Definition: tool_helpers.c:41
void notef(struct GlobalConfig *config, const char *fmt,...)
Definition: tool_msgs.c:81
void warnf(struct GlobalConfig *config, const char *fmt,...)
Definition: tool_msgs.c:95


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16