lib555.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, 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.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. /* 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. #ifdef CURL_DOES_CONVERSIONS
  36. /* ASCII representation with escape sequences for non-ASCII platforms */
  37. "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62\x6c\x75\x72"
  38. "\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20\x74\x6f\x20\x75\x70\x6c"
  39. "\x6f\x61\x64\x0a";
  40. #else
  41. "this is the blurb we want to upload\n";
  42. #endif
  43. static size_t readcallback(void *ptr,
  44. size_t size,
  45. size_t nmemb,
  46. void *clientp)
  47. {
  48. int *counter = (int *)clientp;
  49. if(*counter) {
  50. /* only do this once and then require a clearing of this */
  51. fprintf(stderr, "READ ALREADY DONE!\n");
  52. return 0;
  53. }
  54. (*counter)++; /* bump */
  55. if(size * nmemb > strlen(uploadthis)) {
  56. fprintf(stderr, "READ!\n");
  57. strcpy(ptr, uploadthis);
  58. return strlen(uploadthis);
  59. }
  60. fprintf(stderr, "READ NOT FINE!\n");
  61. return 0;
  62. }
  63. static curlioerr ioctlcallback(CURL *handle,
  64. int cmd,
  65. void *clientp)
  66. {
  67. int *counter = (int *)clientp;
  68. (void)handle; /* unused */
  69. if(cmd == CURLIOCMD_RESTARTREAD) {
  70. fprintf(stderr, "REWIND!\n");
  71. *counter = 0; /* clear counter to make the read callback restart */
  72. }
  73. return CURLIOE_OK;
  74. }
  75. int test(char *URL)
  76. {
  77. int res = 0;
  78. CURL *curl = NULL;
  79. int counter = 0;
  80. CURLM *m = NULL;
  81. int running = 1;
  82. start_test_timing();
  83. global_init(CURL_GLOBAL_ALL);
  84. easy_init(curl);
  85. easy_setopt(curl, CURLOPT_URL, URL);
  86. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  87. easy_setopt(curl, CURLOPT_HEADER, 1L);
  88. /* read the POST data from a callback */
  89. easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
  90. easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
  91. easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
  92. easy_setopt(curl, CURLOPT_READDATA, &counter);
  93. /* We CANNOT do the POST fine without setting the size (or choose
  94. chunked)! */
  95. easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis));
  96. easy_setopt(curl, CURLOPT_POST, 1L);
  97. easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  98. easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
  99. easy_setopt(curl, CURLOPT_PROXYAUTH,
  100. (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
  101. multi_init(m);
  102. multi_add_handle(m, curl);
  103. while(running) {
  104. struct timeval timeout;
  105. fd_set fdread, fdwrite, fdexcep;
  106. int maxfd = -99;
  107. timeout.tv_sec = 0;
  108. timeout.tv_usec = 100000L; /* 100 ms */
  109. multi_perform(m, &running);
  110. abort_on_test_timeout();
  111. #ifdef TPF
  112. sleep(1); /* avoid ctl-10 dump */
  113. #endif
  114. if(!running)
  115. break; /* done */
  116. FD_ZERO(&fdread);
  117. FD_ZERO(&fdwrite);
  118. FD_ZERO(&fdexcep);
  119. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  120. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  121. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  122. abort_on_test_timeout();
  123. }
  124. test_cleanup:
  125. /* proper cleanup sequence - type PA */
  126. curl_multi_remove_handle(m, curl);
  127. curl_multi_cleanup(m);
  128. curl_easy_cleanup(curl);
  129. curl_global_cleanup();
  130. return res;
  131. }