lib547.c 3.6 KB

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