lib666.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 buffer[17000]; /* more than 16K */
  27. int test(char *URL)
  28. {
  29. CURL *curl = NULL;
  30. CURLcode res = CURLE_OK;
  31. curl_mime *mime = NULL;
  32. curl_mimepart *part;
  33. size_t i;
  34. /* Checks huge binary-encoded mime post. */
  35. /* Create a buffer with pseudo-binary data. */
  36. for(i = 0; i < sizeof(buffer); i++)
  37. if(i % 77 == 76)
  38. buffer[i] = '\n';
  39. else
  40. buffer[i] = (char) (0x41 + i % 26); /* A...Z */
  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. curl = curl_easy_init();
  46. if(!curl) {
  47. fprintf(stderr, "curl_easy_init() failed\n");
  48. res = (CURLcode) TEST_ERR_MAJOR_BAD;
  49. goto test_cleanup;
  50. }
  51. /* Build mime structure. */
  52. mime = curl_mime_init(curl);
  53. if(!mime) {
  54. fprintf(stderr, "curl_mime_init() failed\n");
  55. res = (CURLcode) TEST_ERR_MAJOR_BAD;
  56. goto test_cleanup;
  57. }
  58. part = curl_mime_addpart(mime);
  59. if(!part) {
  60. fprintf(stderr, "curl_mime_addpart() failed\n");
  61. res = (CURLcode) TEST_ERR_MAJOR_BAD;
  62. goto test_cleanup;
  63. }
  64. res = curl_mime_name(part, "upfile");
  65. if(res) {
  66. fprintf(stderr, "curl_mime_name() failed\n");
  67. goto test_cleanup;
  68. }
  69. res = curl_mime_filename(part, "myfile.txt");
  70. if(res) {
  71. fprintf(stderr, "curl_mime_filename() failed\n");
  72. goto test_cleanup;
  73. }
  74. res = curl_mime_data(part, buffer, sizeof(buffer));
  75. if(res) {
  76. fprintf(stderr, "curl_mime_data() failed\n");
  77. goto test_cleanup;
  78. }
  79. res = curl_mime_encoder(part, "binary");
  80. if(res) {
  81. fprintf(stderr, "curl_mime_encoder() failed\n");
  82. goto test_cleanup;
  83. }
  84. /* First set the URL that is about to receive our mime mail. */
  85. test_setopt(curl, CURLOPT_URL, URL);
  86. /* Post form */
  87. test_setopt(curl, CURLOPT_MIMEPOST, mime);
  88. /* Shorten upload buffer. */
  89. test_setopt(curl, CURLOPT_UPLOAD_BUFFERSIZE, 16411L);
  90. /* get verbose debug output please */
  91. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  92. /* include headers in the output */
  93. test_setopt(curl, CURLOPT_HEADER, 1L);
  94. /* Perform the request, res will get the return code */
  95. res = curl_easy_perform(curl);
  96. test_cleanup:
  97. /* always cleanup */
  98. curl_easy_cleanup(curl);
  99. /* now cleanup the mime structure */
  100. curl_mime_free(mime);
  101. curl_global_cleanup();
  102. return res;
  103. }