lib569.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /*
  32. * Test Session ID capture
  33. */
  34. int test(char *URL)
  35. {
  36. int res;
  37. CURL *curl;
  38. char *stream_uri = NULL;
  39. char *rtsp_session_id;
  40. int request = 1;
  41. int i;
  42. FILE *idfile = fopen(libtest_arg2, "wb");
  43. if(!idfile) {
  44. fprintf(stderr, "couldn't open the Session ID File\n");
  45. return TEST_ERR_MAJOR_BAD;
  46. }
  47. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  48. fprintf(stderr, "curl_global_init() failed\n");
  49. fclose(idfile);
  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. fclose(idfile);
  57. return TEST_ERR_MAJOR_BAD;
  58. }
  59. test_setopt(curl, CURLOPT_HEADERDATA, stdout);
  60. test_setopt(curl, CURLOPT_WRITEDATA, stdout);
  61. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  62. test_setopt(curl, CURLOPT_URL, URL);
  63. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  64. res = curl_easy_perform(curl);
  65. if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
  66. fprintf(stderr, "This should have failed. "
  67. "Cannot setup without a Transport: header");
  68. res = TEST_ERR_MAJOR_BAD;
  69. goto test_cleanup;
  70. }
  71. /* Go through the various Session IDs */
  72. for(i = 0; i < 3; i++) {
  73. stream_uri = suburl(URL, request++);
  74. if(!stream_uri) {
  75. res = TEST_ERR_MAJOR_BAD;
  76. goto test_cleanup;
  77. }
  78. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  79. curl_free(stream_uri);
  80. stream_uri = NULL;
  81. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  82. test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
  83. "Fake/NotReal/JustATest;foo=baz");
  84. res = curl_easy_perform(curl);
  85. if(res)
  86. goto test_cleanup;
  87. curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
  88. fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
  89. rtsp_session_id = NULL;
  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. curl_free(stream_uri);
  97. stream_uri = NULL;
  98. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
  99. res = curl_easy_perform(curl);
  100. /* Clear for the next go-round */
  101. test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
  102. }
  103. test_cleanup:
  104. if(idfile)
  105. fclose(idfile);
  106. curl_free(stream_uri);
  107. curl_easy_cleanup(curl);
  108. curl_global_cleanup();
  109. return res;
  110. }