tool_helpers.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, 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 http://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. #include "rawstr.h"
  24. #define ENABLE_CURLX_PRINTF
  25. /* use our own printf() functions */
  26. #include "curlx.h"
  27. #include "tool_cfgable.h"
  28. #include "tool_msgs.h"
  29. #include "tool_getparam.h"
  30. #include "tool_helpers.h"
  31. #include "memdebug.h" /* keep this as LAST include */
  32. /*
  33. ** Helper functions that are used from more tha one source file.
  34. */
  35. const char *param2text(int res)
  36. {
  37. ParameterError error = (ParameterError)res;
  38. switch(error) {
  39. case PARAM_GOT_EXTRA_PARAMETER:
  40. return "had unsupported trailing garbage";
  41. case PARAM_OPTION_UNKNOWN:
  42. return "is unknown";
  43. case PARAM_OPTION_AMBIGUOUS:
  44. return "is ambiguous";
  45. case PARAM_REQUIRES_PARAMETER:
  46. return "requires parameter";
  47. case PARAM_BAD_USE:
  48. return "is badly used here";
  49. case PARAM_BAD_NUMERIC:
  50. return "expected a proper numerical parameter";
  51. case PARAM_NEGATIVE_NUMERIC:
  52. return "expected a positive numerical parameter";
  53. case PARAM_LIBCURL_DOESNT_SUPPORT:
  54. return "the installed libcurl version doesn't support this";
  55. case PARAM_NO_MEM:
  56. return "out of memory";
  57. default:
  58. return "unknown error";
  59. }
  60. }
  61. int SetHTTPrequest(struct Configurable *config, HttpReq req, HttpReq *store)
  62. {
  63. if((*store == HTTPREQ_UNSPEC) ||
  64. (*store == req)) {
  65. *store = req;
  66. return 0;
  67. }
  68. warnf(config, "You can only select one HTTP request!\n");
  69. return 1;
  70. }