lib666.c 3.3 KB

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