2
0

lib555.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. /* This test case is supposed to be identical to 547 except that this uses the
  25. * multi interface and 547 is easy interface.
  26. *
  27. * argv1 = URL
  28. * argv2 = proxy
  29. * argv3 = proxyuser:password
  30. */
  31. #include "test.h"
  32. #include "testutil.h"
  33. #include "warnless.h"
  34. #include "memdebug.h"
  35. #define TEST_HANG_TIMEOUT 60 * 1000
  36. static const char uploadthis[] =
  37. "this is the blurb we want to upload\n";
  38. static size_t readcallback(char *ptr,
  39. size_t size,
  40. size_t nmemb,
  41. void *clientp)
  42. {
  43. int *counter = (int *)clientp;
  44. if(*counter) {
  45. /* only do this once and then require a clearing of this */
  46. fprintf(stderr, "READ ALREADY DONE!\n");
  47. return 0;
  48. }
  49. (*counter)++; /* bump */
  50. if(size * nmemb >= strlen(uploadthis)) {
  51. fprintf(stderr, "READ!\n");
  52. strcpy(ptr, uploadthis);
  53. return strlen(uploadthis);
  54. }
  55. fprintf(stderr, "READ NOT FINE!\n");
  56. return 0;
  57. }
  58. static curlioerr ioctlcallback(CURL *handle,
  59. int cmd,
  60. void *clientp)
  61. {
  62. int *counter = (int *)clientp;
  63. (void)handle; /* unused */
  64. if(cmd == CURLIOCMD_RESTARTREAD) {
  65. fprintf(stderr, "REWIND!\n");
  66. *counter = 0; /* clear counter to make the read callback restart */
  67. }
  68. return CURLIOE_OK;
  69. }
  70. CURLcode test(char *URL)
  71. {
  72. CURLcode res = CURLE_OK;
  73. CURL *curl = NULL;
  74. int counter = 0;
  75. CURLM *m = NULL;
  76. int running = 1;
  77. start_test_timing();
  78. global_init(CURL_GLOBAL_ALL);
  79. easy_init(curl);
  80. easy_setopt(curl, CURLOPT_URL, URL);
  81. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  82. easy_setopt(curl, CURLOPT_HEADER, 1L);
  83. /* read the POST data from a callback */
  84. CURL_IGNORE_DEPRECATION(
  85. easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
  86. easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
  87. )
  88. easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
  89. easy_setopt(curl, CURLOPT_READDATA, &counter);
  90. /* We CANNOT do the POST fine without setting the size (or choose
  91. chunked)! */
  92. easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis));
  93. easy_setopt(curl, CURLOPT_POST, 1L);
  94. easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  95. easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
  96. easy_setopt(curl, CURLOPT_PROXYAUTH,
  97. (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
  98. multi_init(m);
  99. multi_add_handle(m, curl);
  100. while(running) {
  101. struct timeval timeout;
  102. fd_set fdread, fdwrite, fdexcep;
  103. int maxfd = -99;
  104. timeout.tv_sec = 0;
  105. timeout.tv_usec = 100000L; /* 100 ms */
  106. multi_perform(m, &running);
  107. abort_on_test_timeout();
  108. if(!running)
  109. break; /* done */
  110. FD_ZERO(&fdread);
  111. FD_ZERO(&fdwrite);
  112. FD_ZERO(&fdexcep);
  113. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  114. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  115. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  116. abort_on_test_timeout();
  117. }
  118. test_cleanup:
  119. /* proper cleanup sequence - type PA */
  120. curl_multi_remove_handle(m, curl);
  121. curl_multi_cleanup(m);
  122. curl_easy_cleanup(curl);
  123. curl_global_cleanup();
  124. return res;
  125. }