lib651.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. #include "memdebug.h"
  26. static char buffer[17000]; /* more than 16K */
  27. int test(char *URL)
  28. {
  29. CURL *curl;
  30. CURLcode res = CURLE_OK;
  31. CURLFORMcode formrc;
  32. struct curl_httppost *formpost = NULL;
  33. struct curl_httppost *lastptr = NULL;
  34. /* create a buffer with AAAA...BBBBB...CCCC...etc */
  35. int i;
  36. int size = (int)sizeof(buffer)/1000;
  37. for(i = 0; i < size ; i++)
  38. memset(&buffer[i * 1000], 65 + i, 1000);
  39. buffer[ sizeof(buffer)-1] = 0; /* null-terminate */
  40. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  41. fprintf(stderr, "curl_global_init() failed\n");
  42. return TEST_ERR_MAJOR_BAD;
  43. }
  44. /* Check proper name and data copying. */
  45. formrc = curl_formadd(&formpost, &lastptr,
  46. CURLFORM_COPYNAME, "hello",
  47. CURLFORM_COPYCONTENTS, buffer,
  48. CURLFORM_END);
  49. if(formrc)
  50. printf("curl_formadd(1) = %d\n", (int) formrc);
  51. curl = curl_easy_init();
  52. if(!curl) {
  53. fprintf(stderr, "curl_easy_init() failed\n");
  54. curl_formfree(formpost);
  55. curl_global_cleanup();
  56. return TEST_ERR_MAJOR_BAD;
  57. }
  58. /* First set the URL that is about to receive our POST. */
  59. test_setopt(curl, CURLOPT_URL, URL);
  60. /* send a multi-part formpost */
  61. test_setopt(curl, CURLOPT_HTTPPOST, formpost);
  62. /* get verbose debug output please */
  63. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  64. /* include headers in the output */
  65. test_setopt(curl, CURLOPT_HEADER, 1L);
  66. /* Perform the request, res will get the return code */
  67. res = curl_easy_perform(curl);
  68. test_cleanup:
  69. /* always cleanup */
  70. curl_easy_cleanup(curl);
  71. /* now cleanup the formpost chain */
  72. curl_formfree(formpost);
  73. curl_global_cleanup();
  74. return res;
  75. }