lib570.c 3.2 KB

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