lib568.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. int test(char *URL)
  41. {
  42. int 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. 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. /* Do the ANNOUNCE */
  85. res = curl_easy_perform(curl);
  86. if(res)
  87. goto test_cleanup;
  88. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  89. fclose(sdpf);
  90. sdpf = NULL;
  91. /* Make sure we can do a normal request now */
  92. stream_uri = suburl(URL, request++);
  93. if(!stream_uri) {
  94. res = TEST_ERR_MAJOR_BAD;
  95. goto test_cleanup;
  96. }
  97. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  98. free(stream_uri);
  99. stream_uri = NULL;
  100. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
  101. res = curl_easy_perform(curl);
  102. if(res)
  103. goto test_cleanup;
  104. /* Now do a POST style one */
  105. stream_uri = suburl(URL, request++);
  106. if(!stream_uri) {
  107. res = TEST_ERR_MAJOR_BAD;
  108. goto test_cleanup;
  109. }
  110. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  111. free(stream_uri);
  112. stream_uri = NULL;
  113. custom_headers = curl_slist_append(custom_headers,
  114. "Content-Type: posty goodness");
  115. if(!custom_headers) {
  116. res = TEST_ERR_MAJOR_BAD;
  117. goto test_cleanup;
  118. }
  119. test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
  120. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
  121. test_setopt(curl, CURLOPT_POSTFIELDS,
  122. "postyfield=postystuff&project=curl\n");
  123. res = curl_easy_perform(curl);
  124. if(res)
  125. goto test_cleanup;
  126. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  127. test_setopt(curl, CURLOPT_RTSPHEADER, NULL);
  128. curl_slist_free_all(custom_headers);
  129. custom_headers = NULL;
  130. /* Make sure we can do a normal request now */
  131. stream_uri = suburl(URL, request++);
  132. if(!stream_uri) {
  133. res = TEST_ERR_MAJOR_BAD;
  134. goto test_cleanup;
  135. }
  136. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  137. free(stream_uri);
  138. stream_uri = NULL;
  139. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  140. res = curl_easy_perform(curl);
  141. test_cleanup:
  142. if(sdpf)
  143. fclose(sdpf);
  144. free(stream_uri);
  145. if(custom_headers)
  146. curl_slist_free_all(custom_headers);
  147. curl_easy_cleanup(curl);
  148. curl_global_cleanup();
  149. return res;
  150. }