lib1662.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. static char testdata[]="mooaaa";
  26. struct WriteThis {
  27. size_t sizeleft;
  28. };
  29. static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp)
  30. {
  31. struct WriteThis *pooh = (struct WriteThis *)userp;
  32. size_t len = strlen(testdata);
  33. if(size*nmemb < len)
  34. return 0;
  35. if(pooh->sizeleft) {
  36. memcpy(ptr, testdata, strlen(testdata));
  37. pooh->sizeleft = 0;
  38. return len;
  39. }
  40. return 0; /* no more data left to deliver */
  41. }
  42. CURLcode test(char *URL)
  43. {
  44. CURLcode res = CURLE_OK;
  45. CURL *hnd;
  46. curl_mime *mime1;
  47. curl_mimepart *part1;
  48. struct WriteThis pooh = { 1 };
  49. mime1 = NULL;
  50. global_init(CURL_GLOBAL_ALL);
  51. hnd = curl_easy_init();
  52. if(hnd) {
  53. curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  54. curl_easy_setopt(hnd, CURLOPT_URL, URL);
  55. curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
  56. mime1 = curl_mime_init(hnd);
  57. if(mime1) {
  58. part1 = curl_mime_addpart(mime1);
  59. curl_mime_data_cb(part1, -1, read_callback, NULL, NULL, &pooh);
  60. curl_mime_filename(part1, "poetry.txt");
  61. curl_mime_name(part1, "content");
  62. curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
  63. curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000");
  64. curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
  65. curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  66. curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION,
  67. (long)CURL_HTTP_VERSION_2TLS);
  68. curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
  69. curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
  70. curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
  71. res = curl_easy_perform(hnd);
  72. }
  73. }
  74. curl_easy_cleanup(hnd);
  75. curl_mime_free(mime1);
  76. curl_global_cleanup();
  77. return res;
  78. }