lib572.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #ifdef HAVE_SYS_STAT_H
  26. #include <sys/stat.h>
  27. #endif
  28. #ifdef HAVE_FCNTL_H
  29. #include <fcntl.h>
  30. #endif
  31. #include "memdebug.h"
  32. /* build request url */
  33. static char *suburl(const char *base, int i)
  34. {
  35. return curl_maprintf("%s%.4d", base, i);
  36. }
  37. /*
  38. * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
  39. */
  40. int test(char *URL)
  41. {
  42. int res;
  43. CURL *curl;
  44. int params;
  45. FILE *paramsf = NULL;
  46. struct_stat file_info;
  47. char *stream_uri = NULL;
  48. int request = 1;
  49. struct curl_slist *custom_headers = NULL;
  50. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  51. fprintf(stderr, "curl_global_init() failed\n");
  52. return TEST_ERR_MAJOR_BAD;
  53. }
  54. curl = curl_easy_init();
  55. if(!curl) {
  56. fprintf(stderr, "curl_easy_init() failed\n");
  57. curl_global_cleanup();
  58. return TEST_ERR_MAJOR_BAD;
  59. }
  60. test_setopt(curl, CURLOPT_HEADERDATA, stdout);
  61. test_setopt(curl, CURLOPT_WRITEDATA, stdout);
  62. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  63. test_setopt(curl, CURLOPT_URL, URL);
  64. /* SETUP */
  65. stream_uri = suburl(URL, request++);
  66. if(!stream_uri) {
  67. res = TEST_ERR_MAJOR_BAD;
  68. goto test_cleanup;
  69. }
  70. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  71. curl_free(stream_uri);
  72. stream_uri = NULL;
  73. test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
  74. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  75. res = curl_easy_perform(curl);
  76. if(res)
  77. goto test_cleanup;
  78. stream_uri = suburl(URL, request++);
  79. if(!stream_uri) {
  80. res = TEST_ERR_MAJOR_BAD;
  81. goto test_cleanup;
  82. }
  83. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  84. curl_free(stream_uri);
  85. stream_uri = NULL;
  86. /* PUT style GET_PARAMETERS */
  87. params = open(libtest_arg2, O_RDONLY);
  88. fstat(params, &file_info);
  89. close(params);
  90. paramsf = fopen(libtest_arg2, "rb");
  91. if(!paramsf) {
  92. fprintf(stderr, "can't open %s\n", libtest_arg2);
  93. res = TEST_ERR_MAJOR_BAD;
  94. goto test_cleanup;
  95. }
  96. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  97. test_setopt(curl, CURLOPT_READDATA, paramsf);
  98. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  99. test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
  100. res = curl_easy_perform(curl);
  101. if(res)
  102. goto test_cleanup;
  103. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  104. fclose(paramsf);
  105. paramsf = NULL;
  106. /* Heartbeat GET_PARAMETERS */
  107. stream_uri = suburl(URL, request++);
  108. if(!stream_uri) {
  109. res = TEST_ERR_MAJOR_BAD;
  110. goto test_cleanup;
  111. }
  112. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  113. curl_free(stream_uri);
  114. stream_uri = NULL;
  115. res = curl_easy_perform(curl);
  116. if(res)
  117. goto test_cleanup;
  118. /* POST GET_PARAMETERS */
  119. stream_uri = suburl(URL, request++);
  120. if(!stream_uri) {
  121. res = TEST_ERR_MAJOR_BAD;
  122. goto test_cleanup;
  123. }
  124. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  125. curl_free(stream_uri);
  126. stream_uri = NULL;
  127. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  128. test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
  129. res = curl_easy_perform(curl);
  130. if(res)
  131. goto test_cleanup;
  132. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  133. /* Make sure we can do a normal request now */
  134. stream_uri = suburl(URL, request++);
  135. if(!stream_uri) {
  136. res = TEST_ERR_MAJOR_BAD;
  137. goto test_cleanup;
  138. }
  139. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  140. curl_free(stream_uri);
  141. stream_uri = NULL;
  142. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  143. res = curl_easy_perform(curl);
  144. test_cleanup:
  145. if(paramsf)
  146. fclose(paramsf);
  147. curl_free(stream_uri);
  148. if(custom_headers)
  149. curl_slist_free_all(custom_headers);
  150. curl_easy_cleanup(curl);
  151. curl_global_cleanup();
  152. return res;
  153. }