lib555.c 4.1 KB

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