lib1597.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* Testing CURLOPT_PROTOCOLS_STR */
  25. #include "test.h"
  26. #include "memdebug.h"
  27. struct pair {
  28. const char *in;
  29. CURLcode *exp;
  30. };
  31. int test(char *URL)
  32. {
  33. CURL *curl = NULL;
  34. int res = 0;
  35. CURLcode result = CURLE_OK;
  36. curl_version_info_data *curlinfo;
  37. const char *const *proto;
  38. int n;
  39. int i;
  40. static CURLcode ok = CURLE_OK;
  41. static CURLcode bad = CURLE_BAD_FUNCTION_ARGUMENT;
  42. static CURLcode unsup = CURLE_UNSUPPORTED_PROTOCOL;
  43. static CURLcode httpcode = CURLE_UNSUPPORTED_PROTOCOL;
  44. static CURLcode httpscode = CURLE_UNSUPPORTED_PROTOCOL;
  45. static char protolist[1024];
  46. static const struct pair prots[] = {
  47. {"goobar", &unsup},
  48. {"http ", &unsup},
  49. {" http", &unsup},
  50. {"http", &httpcode},
  51. {"http,", &httpcode},
  52. {"https,", &httpscode},
  53. {"https,http", &httpscode},
  54. {"http,http", &httpcode},
  55. {"HTTP,HTTP", &httpcode},
  56. {",HTTP,HTTP", &httpcode},
  57. {"http,http,ft", &unsup},
  58. {"", &bad},
  59. {",,", &bad},
  60. {protolist, &ok},
  61. {"all", &ok},
  62. {NULL, NULL},
  63. };
  64. (void)URL;
  65. global_init(CURL_GLOBAL_ALL);
  66. easy_init(curl);
  67. /* Get enabled protocols.*/
  68. curlinfo = curl_version_info(CURLVERSION_NOW);
  69. if(!curlinfo) {
  70. fputs("curl_version_info failed\n", stderr);
  71. res = (int) TEST_ERR_FAILURE;
  72. goto test_cleanup;
  73. }
  74. n = 0;
  75. for(proto = curlinfo->protocols; *proto; proto++) {
  76. if((size_t) n >= sizeof(protolist)) {
  77. puts("protolist buffer too small\n");
  78. res = (int) TEST_ERR_FAILURE;
  79. goto test_cleanup;
  80. }
  81. n += msnprintf(protolist + n, sizeof(protolist) - n, ",%s", *proto);
  82. if(curl_strequal(*proto, "http"))
  83. httpcode = CURLE_OK;
  84. if(curl_strequal(*proto, "https"))
  85. httpscode = CURLE_OK;
  86. }
  87. /* Run the tests. */
  88. for(i = 0; prots[i].in; i++) {
  89. result = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
  90. if(result != *prots[i].exp) {
  91. printf("unexpectedly '%s' returned %u\n",
  92. prots[i].in, result);
  93. break;
  94. }
  95. }
  96. printf("Tested %u strings\n", i);
  97. res = (int)result;
  98. test_cleanup:
  99. curl_easy_cleanup(curl);
  100. curl_global_cleanup();
  101. return (int)result;
  102. }