1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2016, 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
24 #ifdef HAVE_SYS_STAT_H
25 #include <sys/stat.h>
26 #endif
27 #ifdef HAVE_FCNTL_H
28 #include <fcntl.h>
29 #endif
30
31 #include "memdebug.h"
32
33 /* build request url */
suburl(const char * base,int i)34 static char *suburl(const char *base, int i)
35 {
36 return curl_maprintf("%s%.4d", base, i);
37 }
38
39 /*
40 * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
41 */
test(char * URL)42 int test(char *URL)
43 {
44 int res;
45 CURL *curl;
46 int params;
47 FILE *paramsf = NULL;
48 struct_stat file_info;
49 char *stream_uri = NULL;
50 int request=1;
51 struct curl_slist *custom_headers=NULL;
52
53 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
54 fprintf(stderr, "curl_global_init() failed\n");
55 return TEST_ERR_MAJOR_BAD;
56 }
57
58 if((curl = curl_easy_init()) == NULL) {
59 fprintf(stderr, "curl_easy_init() failed\n");
60 curl_global_cleanup();
61 return TEST_ERR_MAJOR_BAD;
62 }
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 /* SETUP */
72 if((stream_uri = suburl(URL, request++)) == NULL) {
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
80 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
81 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
82 res = curl_easy_perform(curl);
83 if(res)
84 goto test_cleanup;
85
86 if((stream_uri = suburl(URL, request++)) == NULL) {
87 res = TEST_ERR_MAJOR_BAD;
88 goto test_cleanup;
89 }
90 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
91 free(stream_uri);
92 stream_uri = NULL;
93
94 /* PUT style GET_PARAMETERS */
95 params = open("log/file572.txt", O_RDONLY);
96 fstat(params, &file_info);
97 close(params);
98
99 paramsf = fopen("log/file572.txt", "rb");
100 if(paramsf == NULL) {
101 fprintf(stderr, "can't open log/file572.txt\n");
102 res = TEST_ERR_MAJOR_BAD;
103 goto test_cleanup;
104 }
105 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
106
107 test_setopt(curl, CURLOPT_READDATA, paramsf);
108 test_setopt(curl, CURLOPT_UPLOAD, 1L);
109 test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
110
111 res = curl_easy_perform(curl);
112 if(res)
113 goto test_cleanup;
114
115 test_setopt(curl, CURLOPT_UPLOAD, 0L);
116 fclose(paramsf);
117 paramsf = NULL;
118
119 /* Heartbeat GET_PARAMETERS */
120 if((stream_uri = suburl(URL, request++)) == NULL) {
121 res = TEST_ERR_MAJOR_BAD;
122 goto test_cleanup;
123 }
124 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
125 free(stream_uri);
126 stream_uri = NULL;
127
128 res = curl_easy_perform(curl);
129 if(res)
130 goto test_cleanup;
131
132 /* POST GET_PARAMETERS */
133
134 if((stream_uri = suburl(URL, request++)) == NULL) {
135 res = TEST_ERR_MAJOR_BAD;
136 goto test_cleanup;
137 }
138 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
139 free(stream_uri);
140 stream_uri = NULL;
141
142 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
143 test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
144
145 res = curl_easy_perform(curl);
146 if(res)
147 goto test_cleanup;
148
149 test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
150
151 /* Make sure we can do a normal request now */
152 if((stream_uri = suburl(URL, request++)) == NULL) {
153 res = TEST_ERR_MAJOR_BAD;
154 goto test_cleanup;
155 }
156 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
157 free(stream_uri);
158 stream_uri = NULL;
159
160 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
161 res = curl_easy_perform(curl);
162
163 test_cleanup:
164
165 if(paramsf)
166 fclose(paramsf);
167
168 free(stream_uri);
169
170 if(custom_headers)
171 curl_slist_free_all(custom_headers);
172
173 curl_easy_cleanup(curl);
174 curl_global_cleanup();
175
176 return res;
177 }
178
179