lib544.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, 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.haxx.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 teststring[] =
  25. #ifdef CURL_DOES_CONVERSIONS
  26. /* ASCII representation with escape sequences for non-ASCII platforms */
  27. { '\x54', '\x68', '\x69', '\x73', '\x00', '\x20', '\x69', '\x73', '\x20',
  28. '\x74', '\x65', '\x73', '\x74', '\x20', '\x62', '\x69', '\x6e', '\x61',
  29. '\x72', '\x79', '\x20', '\x64', '\x61', '\x74', '\x61', '\x20', '\x77',
  30. '\x69', '\x74', '\x68', '\x20', '\x61', '\x6e', '\x20', '\x65', '\x6d',
  31. '\x62', '\x65', '\x64', '\x64', '\x65', '\x64', '\x20', '\x4e', '\x55',
  32. '\x4c'};
  33. #else
  34. { 'T', 'h', 'i', 's', '\0', ' ', 'i', 's', ' ', 't', 'e', 's', 't', ' ',
  35. 'b', 'i', 'n', 'a', 'r', 'y', ' ', 'd', 'a', 't', 'a', ' ',
  36. 'w', 'i', 't', 'h', ' ', 'a', 'n', ' ',
  37. 'e', 'm', 'b', 'e', 'd', 'd', 'e', 'd', ' ', 'N', 'U', 'L'};
  38. #endif
  39. int test(char *URL)
  40. {
  41. CURL *curl;
  42. CURLcode res = CURLE_OK;
  43. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  44. fprintf(stderr, "curl_global_init() failed\n");
  45. return TEST_ERR_MAJOR_BAD;
  46. }
  47. curl = curl_easy_init();
  48. if(!curl) {
  49. fprintf(stderr, "curl_easy_init() failed\n");
  50. curl_global_cleanup();
  51. return TEST_ERR_MAJOR_BAD;
  52. }
  53. /* First set the URL that is about to receive our POST. */
  54. test_setopt(curl, CURLOPT_URL, URL);
  55. #ifdef LIB545
  56. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(teststring));
  57. #endif
  58. test_setopt(curl, CURLOPT_COPYPOSTFIELDS, teststring);
  59. test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
  60. test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
  61. /* Update the original data to detect non-copy. */
  62. strcpy(teststring, "FAIL");
  63. #ifdef LIB545
  64. {
  65. CURL *handle2;
  66. handle2 = curl_easy_duphandle(curl);
  67. curl_easy_cleanup(curl);
  68. curl = handle2;
  69. }
  70. #endif
  71. /* Now, this is a POST request with binary 0 embedded in POST data. */
  72. res = curl_easy_perform(curl);
  73. test_cleanup:
  74. /* always cleanup */
  75. curl_easy_cleanup(curl);
  76. curl_global_cleanup();
  77. return (int)res;
  78. }