lib570.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include "memdebug.h"
  26. /* build request url */
  27. static char *suburl(const char *base, int i)
  28. {
  29. return curl_maprintf("%s%.4d", base, i);
  30. }
  31. CURLcode test(char *URL)
  32. {
  33. CURLcode res;
  34. CURL *curl;
  35. int request = 1;
  36. char *stream_uri = NULL;
  37. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  38. fprintf(stderr, "curl_global_init() failed\n");
  39. return TEST_ERR_MAJOR_BAD;
  40. }
  41. curl = curl_easy_init();
  42. if(!curl) {
  43. fprintf(stderr, "curl_easy_init() failed\n");
  44. curl_global_cleanup();
  45. return TEST_ERR_MAJOR_BAD;
  46. }
  47. test_setopt(curl, CURLOPT_HEADERDATA, stdout);
  48. test_setopt(curl, CURLOPT_WRITEDATA, stdout);
  49. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  50. test_setopt(curl, CURLOPT_URL, URL);
  51. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  52. stream_uri = suburl(URL, request++);
  53. if(!stream_uri) {
  54. res = TEST_ERR_MAJOR_BAD;
  55. goto test_cleanup;
  56. }
  57. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  58. curl_free(stream_uri);
  59. stream_uri = NULL;
  60. res = curl_easy_perform(curl);
  61. if(res != (int)CURLE_RTSP_CSEQ_ERROR) {
  62. fprintf(stderr, "Failed to detect CSeq mismatch");
  63. res = TEST_ERR_MAJOR_BAD;
  64. goto test_cleanup;
  65. }
  66. test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999L);
  67. test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
  68. "RAW/RAW/UDP;unicast;client_port=3056-3057");
  69. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  70. stream_uri = suburl(URL, request++);
  71. if(!stream_uri) {
  72. res = TEST_ERR_MAJOR_BAD;
  73. goto test_cleanup;
  74. }
  75. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  76. curl_free(stream_uri);
  77. stream_uri = NULL;
  78. res = curl_easy_perform(curl);
  79. if(res)
  80. goto test_cleanup;
  81. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
  82. stream_uri = suburl(URL, request++);
  83. if(!stream_uri) {
  84. res = TEST_ERR_MAJOR_BAD;
  85. goto test_cleanup;
  86. }
  87. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  88. curl_free(stream_uri);
  89. stream_uri = NULL;
  90. res = curl_easy_perform(curl);
  91. if(res == CURLE_RTSP_SESSION_ERROR) {
  92. res = CURLE_OK;
  93. }
  94. else {
  95. fprintf(stderr, "Failed to detect a Session ID mismatch");
  96. res = (CURLcode)1;
  97. }
  98. test_cleanup:
  99. curl_free(stream_uri);
  100. curl_easy_cleanup(curl);
  101. curl_global_cleanup();
  102. return res;
  103. }