lib568.c 4.6 KB

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