2
0

lib1662.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 data[]="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(data);
  33. if(size*nmemb < len)
  34. return 0;
  35. if(pooh->sizeleft) {
  36. memcpy(ptr, data, strlen(data));
  37. pooh->sizeleft = 0;
  38. return len;
  39. }
  40. return 0; /* no more data left to deliver */
  41. }
  42. int 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 (int)res;
  78. }