tool_helpers.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "tool_setup.h"
00023 
00024 #include "strcase.h"
00025 
00026 #define ENABLE_CURLX_PRINTF
00027 /* use our own printf() functions */
00028 #include "curlx.h"
00029 
00030 #include "tool_cfgable.h"
00031 #include "tool_msgs.h"
00032 #include "tool_getparam.h"
00033 #include "tool_helpers.h"
00034 
00035 #include "memdebug.h" /* keep this as LAST include */
00036 
00037 /*
00038 ** Helper functions that are used from more than one source file.
00039 */
00040 
00041 const char *param2text(int res)
00042 {
00043   ParameterError error = (ParameterError)res;
00044   switch(error) {
00045   case PARAM_GOT_EXTRA_PARAMETER:
00046     return "had unsupported trailing garbage";
00047   case PARAM_OPTION_UNKNOWN:
00048     return "is unknown";
00049   case PARAM_OPTION_AMBIGUOUS:
00050     return "is ambiguous";
00051   case PARAM_REQUIRES_PARAMETER:
00052     return "requires parameter";
00053   case PARAM_BAD_USE:
00054     return "is badly used here";
00055   case PARAM_BAD_NUMERIC:
00056     return "expected a proper numerical parameter";
00057   case PARAM_NEGATIVE_NUMERIC:
00058     return "expected a positive numerical parameter";
00059   case PARAM_LIBCURL_DOESNT_SUPPORT:
00060     return "the installed libcurl version doesn't support this";
00061   case PARAM_LIBCURL_UNSUPPORTED_PROTOCOL:
00062     return "a specified protocol is unsupported by libcurl";
00063   case PARAM_NO_MEM:
00064     return "out of memory";
00065   default:
00066     return "unknown error";
00067   }
00068 }
00069 
00070 int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
00071 {
00072   /* this mirrors the HttpReq enum in tool_sdecls.h */
00073   const char *reqname[]= {
00074     "", /* unspec */
00075     "GET (-G, --get)",
00076     "HEAD (-I, --head)",
00077     "multipart formpost (-F, --form)",
00078     "POST (-d, --data)"
00079   };
00080 
00081   if((*store == HTTPREQ_UNSPEC) ||
00082      (*store == req)) {
00083     *store = req;
00084     return 0;
00085   }
00086   warnf(config->global, "You can only select one HTTP request method! "
00087         "You asked for both %s and %s.\n",
00088         reqname[req], reqname[*store]);
00089 
00090   return 1;
00091 }
00092 
00093 void customrequest_helper(struct OperationConfig *config, HttpReq req,
00094                           char *method)
00095 {
00096   /* this mirrors the HttpReq enum in tool_sdecls.h */
00097   const char *dflt[]= {
00098     "GET",
00099     "GET",
00100     "HEAD",
00101     "POST",
00102     "POST"
00103   };
00104 
00105   if(!method)
00106     ;
00107   else if(curl_strequal(method, dflt[req])) {
00108     notef(config->global, "Unnecessary use of -X or --request, %s is already "
00109           "inferred.\n", dflt[req]);
00110   }
00111   else if(curl_strequal(method, "head")) {
00112     warnf(config->global,
00113           "Setting custom HTTP method to HEAD with -X/--request may not work "
00114           "the way you want. Consider using -I/--head instead.\n");
00115   }
00116 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07