xref: /curl/tests/libtest/lib570.c (revision 25cbc2f7)
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 
test(char * URL)33 CURLcode test(char *URL)
34 {
35   CURLcode res;
36   CURL *curl;
37   int request = 1;
38   char *stream_uri = NULL;
39 
40   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
41     fprintf(stderr, "curl_global_init() failed\n");
42     return TEST_ERR_MAJOR_BAD;
43   }
44 
45   curl = curl_easy_init();
46   if(!curl) {
47     fprintf(stderr, "curl_easy_init() failed\n");
48     curl_global_cleanup();
49     return TEST_ERR_MAJOR_BAD;
50   }
51 
52   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
53   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
54   test_setopt(curl, CURLOPT_VERBOSE, 1L);
55 
56   test_setopt(curl, CURLOPT_URL, URL);
57 
58   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
59 
60   stream_uri = suburl(URL, request++);
61   if(!stream_uri) {
62     res = TEST_ERR_MAJOR_BAD;
63     goto test_cleanup;
64   }
65   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
66   curl_free(stream_uri);
67   stream_uri = NULL;
68 
69   res = curl_easy_perform(curl);
70   if(res != (int)CURLE_RTSP_CSEQ_ERROR) {
71     fprintf(stderr, "Failed to detect CSeq mismatch");
72     res = TEST_ERR_MAJOR_BAD;
73     goto test_cleanup;
74   }
75 
76   test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999L);
77   test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
78                     "RAW/RAW/UDP;unicast;client_port=3056-3057");
79   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
80 
81   stream_uri = suburl(URL, request++);
82   if(!stream_uri) {
83     res = TEST_ERR_MAJOR_BAD;
84     goto test_cleanup;
85   }
86   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
87   curl_free(stream_uri);
88   stream_uri = NULL;
89 
90   res = curl_easy_perform(curl);
91   if(res)
92     goto test_cleanup;
93 
94   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
95 
96   stream_uri = suburl(URL, request++);
97   if(!stream_uri) {
98     res = TEST_ERR_MAJOR_BAD;
99     goto test_cleanup;
100   }
101   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
102   curl_free(stream_uri);
103   stream_uri = NULL;
104 
105   res = curl_easy_perform(curl);
106   if(res == CURLE_RTSP_SESSION_ERROR) {
107     res = CURLE_OK;
108   }
109   else {
110     fprintf(stderr, "Failed to detect a Session ID mismatch");
111     res = (CURLcode)1;
112   }
113 
114 test_cleanup:
115   curl_free(stream_uri);
116 
117   curl_easy_cleanup(curl);
118   curl_global_cleanup();
119 
120   return res;
121 }
122