lib547.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /* argv1 = URL
  25. * argv2 = proxy
  26. * argv3 = proxyuser:password
  27. */
  28. #include "test.h"
  29. #include "memdebug.h"
  30. #define UPLOADTHIS "this is the blurb we want to upload\n"
  31. #ifndef LIB548
  32. static size_t readcallback(char *ptr,
  33. size_t size,
  34. size_t nmemb,
  35. void *clientp)
  36. {
  37. int *counter = (int *)clientp;
  38. if(*counter) {
  39. /* only do this once and then require a clearing of this */
  40. fprintf(stderr, "READ ALREADY DONE!\n");
  41. return 0;
  42. }
  43. (*counter)++; /* bump */
  44. if(size * nmemb >= strlen(UPLOADTHIS)) {
  45. fprintf(stderr, "READ!\n");
  46. strcpy(ptr, UPLOADTHIS);
  47. return strlen(UPLOADTHIS);
  48. }
  49. fprintf(stderr, "READ NOT FINE!\n");
  50. return 0;
  51. }
  52. static curlioerr ioctlcallback(CURL *handle,
  53. int cmd,
  54. void *clientp)
  55. {
  56. int *counter = (int *)clientp;
  57. (void)handle; /* unused */
  58. if(cmd == CURLIOCMD_RESTARTREAD) {
  59. fprintf(stderr, "REWIND!\n");
  60. *counter = 0; /* clear counter to make the read callback restart */
  61. }
  62. return CURLIOE_OK;
  63. }
  64. #endif
  65. int test(char *URL)
  66. {
  67. CURLcode res;
  68. CURL *curl;
  69. #ifndef LIB548
  70. int counter = 0;
  71. #endif
  72. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  73. fprintf(stderr, "curl_global_init() failed\n");
  74. return TEST_ERR_MAJOR_BAD;
  75. }
  76. curl = curl_easy_init();
  77. if(!curl) {
  78. fprintf(stderr, "curl_easy_init() failed\n");
  79. curl_global_cleanup();
  80. return TEST_ERR_MAJOR_BAD;
  81. }
  82. test_setopt(curl, CURLOPT_URL, URL);
  83. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  84. test_setopt(curl, CURLOPT_HEADER, 1L);
  85. #ifdef LIB548
  86. /* set the data to POST with a mere pointer to a null-terminated string */
  87. test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
  88. #else
  89. /* 547 style, which means reading the POST data from a callback */
  90. CURL_IGNORE_DEPRECATION(
  91. test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
  92. test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
  93. )
  94. test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
  95. test_setopt(curl, CURLOPT_READDATA, &counter);
  96. /* We CANNOT do the POST fine without setting the size (or choose
  97. chunked)! */
  98. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
  99. #endif
  100. test_setopt(curl, CURLOPT_POST, 1L);
  101. test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  102. test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
  103. test_setopt(curl, CURLOPT_PROXYAUTH,
  104. (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
  105. res = curl_easy_perform(curl);
  106. test_cleanup:
  107. curl_easy_cleanup(curl);
  108. curl_global_cleanup();
  109. return (int)res;
  110. }