lib555.c 4.2 KB

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