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
27 /* build request url */
suburl(const char * base,int i)28 static char *suburl(const char *base, int i)
29 {
30 return curl_maprintf("%s%.4d", base, i);
31 }
32
33 /*
34 * Test Session ID capture
35 */
test(char * URL)36 CURLcode test(char *URL)
37 {
38 CURLcode res;
39 CURL *curl;
40 char *stream_uri = NULL;
41 char *rtsp_session_id;
42 int request = 1;
43 int i;
44
45 FILE *idfile = fopen(libtest_arg2, "wb");
46 if(!idfile) {
47 fprintf(stderr, "couldn't open the Session ID File\n");
48 return TEST_ERR_MAJOR_BAD;
49 }
50
51 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
52 fprintf(stderr, "curl_global_init() failed\n");
53 fclose(idfile);
54 return TEST_ERR_MAJOR_BAD;
55 }
56
57 curl = curl_easy_init();
58 if(!curl) {
59 fprintf(stderr, "curl_easy_init() failed\n");
60 curl_global_cleanup();
61 fclose(idfile);
62 return TEST_ERR_MAJOR_BAD;
63 }
64
65 test_setopt(curl, CURLOPT_HEADERDATA, stdout);
66 test_setopt(curl, CURLOPT_WRITEDATA, stdout);
67 test_setopt(curl, CURLOPT_VERBOSE, 1L);
68
69 test_setopt(curl, CURLOPT_URL, URL);
70
71 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
72 res = curl_easy_perform(curl);
73 if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
74 fprintf(stderr, "This should have failed. "
75 "Cannot setup without a Transport: header");
76 res = TEST_ERR_MAJOR_BAD;
77 goto test_cleanup;
78 }
79
80 /* Go through the various Session IDs */
81 for(i = 0; i < 3; i++) {
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
91 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
92 test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
93 "Fake/NotReal/JustATest;foo=baz");
94 res = curl_easy_perform(curl);
95 if(res)
96 goto test_cleanup;
97
98 curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
99 fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
100 rtsp_session_id = NULL;
101
102 stream_uri = suburl(URL, request++);
103 if(!stream_uri) {
104 res = TEST_ERR_MAJOR_BAD;
105 goto test_cleanup;
106 }
107 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
108 curl_free(stream_uri);
109 stream_uri = NULL;
110
111 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
112 res = curl_easy_perform(curl);
113
114 /* Clear for the next go-round */
115 test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
116 }
117
118 test_cleanup:
119
120 if(idfile)
121 fclose(idfile);
122
123 curl_free(stream_uri);
124 curl_easy_cleanup(curl);
125 curl_global_cleanup();
126
127 return res;
128 }
129