lib651.c 2.8 KB

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