2
0

lib568.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 the Client->Server ANNOUNCE functionality (PUT style)
  39. */
  40. CURLcode test(char *URL)
  41. {
  42. CURLcode res;
  43. CURL *curl;
  44. int sdp;
  45. FILE *sdpf = 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_URL, URL);
  63. stream_uri = suburl(URL, request++);
  64. if(!stream_uri) {
  65. res = TEST_ERR_MAJOR_BAD;
  66. goto test_cleanup;
  67. }
  68. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  69. curl_free(stream_uri);
  70. stream_uri = NULL;
  71. sdp = open(libtest_arg2, O_RDONLY);
  72. fstat(sdp, &file_info);
  73. close(sdp);
  74. sdpf = fopen(libtest_arg2, "rb");
  75. if(!sdpf) {
  76. fprintf(stderr, "can't open %s\n", libtest_arg2);
  77. res = TEST_ERR_MAJOR_BAD;
  78. goto test_cleanup;
  79. }
  80. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
  81. test_setopt(curl, CURLOPT_READDATA, sdpf);
  82. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  83. test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
  84. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  85. /* Do the ANNOUNCE */
  86. res = curl_easy_perform(curl);
  87. if(res)
  88. goto test_cleanup;
  89. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  90. fclose(sdpf);
  91. sdpf = NULL;
  92. /* Make sure we can do a normal request now */
  93. stream_uri = suburl(URL, request++);
  94. if(!stream_uri) {
  95. res = TEST_ERR_MAJOR_BAD;
  96. goto test_cleanup;
  97. }
  98. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  99. curl_free(stream_uri);
  100. stream_uri = NULL;
  101. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
  102. res = curl_easy_perform(curl);
  103. if(res)
  104. goto test_cleanup;
  105. /* Now do a POST style one */
  106. stream_uri = suburl(URL, request++);
  107. if(!stream_uri) {
  108. res = TEST_ERR_MAJOR_BAD;
  109. goto test_cleanup;
  110. }
  111. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  112. curl_free(stream_uri);
  113. stream_uri = NULL;
  114. custom_headers = curl_slist_append(custom_headers,
  115. "Content-Type: posty goodness");
  116. if(!custom_headers) {
  117. res = TEST_ERR_MAJOR_BAD;
  118. goto test_cleanup;
  119. }
  120. test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
  121. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
  122. test_setopt(curl, CURLOPT_POSTFIELDS,
  123. "postyfield=postystuff&project=curl\n");
  124. res = curl_easy_perform(curl);
  125. if(res)
  126. goto test_cleanup;
  127. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  128. test_setopt(curl, CURLOPT_RTSPHEADER, NULL);
  129. curl_slist_free_all(custom_headers);
  130. custom_headers = NULL;
  131. /* Make sure we can do a normal request now */
  132. stream_uri = suburl(URL, request++);
  133. if(!stream_uri) {
  134. res = TEST_ERR_MAJOR_BAD;
  135. goto test_cleanup;
  136. }
  137. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  138. curl_free(stream_uri);
  139. stream_uri = NULL;
  140. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  141. res = curl_easy_perform(curl);
  142. test_cleanup:
  143. if(sdpf)
  144. fclose(sdpf);
  145. curl_free(stream_uri);
  146. if(custom_headers)
  147. curl_slist_free_all(custom_headers);
  148. curl_easy_cleanup(curl);
  149. curl_global_cleanup();
  150. return res;
  151. }