lib569.c 3.5 KB

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