2
0

lib651.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "memdebug.h"
  26. static char testbuf[17000]; /* more than 16K */
  27. CURLcode 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(testbuf)/1000;
  37. for(i = 0; i < size ; i++)
  38. memset(&testbuf[i * 1000], 65 + i, 1000);
  39. testbuf[sizeof(testbuf)-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. CURL_IGNORE_DEPRECATION(
  45. /* Check proper name and data copying. */
  46. formrc = curl_formadd(&formpost, &lastptr,
  47. CURLFORM_COPYNAME, "hello",
  48. CURLFORM_COPYCONTENTS, testbuf,
  49. CURLFORM_END);
  50. )
  51. if(formrc)
  52. printf("curl_formadd(1) = %d\n", (int) formrc);
  53. curl = curl_easy_init();
  54. if(!curl) {
  55. fprintf(stderr, "curl_easy_init() failed\n");
  56. CURL_IGNORE_DEPRECATION(
  57. curl_formfree(formpost);
  58. )
  59. curl_global_cleanup();
  60. return TEST_ERR_MAJOR_BAD;
  61. }
  62. /* First set the URL that is about to receive our POST. */
  63. test_setopt(curl, CURLOPT_URL, URL);
  64. CURL_IGNORE_DEPRECATION(
  65. /* send a multi-part formpost */
  66. test_setopt(curl, CURLOPT_HTTPPOST, formpost);
  67. )
  68. /* get verbose debug output please */
  69. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  70. /* include headers in the output */
  71. test_setopt(curl, CURLOPT_HEADER, 1L);
  72. /* Perform the request, res will get the return code */
  73. res = curl_easy_perform(curl);
  74. test_cleanup:
  75. /* always cleanup */
  76. curl_easy_cleanup(curl);
  77. CURL_IGNORE_DEPRECATION(
  78. /* now cleanup the formpost chain */
  79. curl_formfree(formpost);
  80. )
  81. curl_global_cleanup();
  82. return res;
  83. }