lib547.c 3.9 KB

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