Imported Upstream version 7.59.0
[platform/upstream/curl.git] / tests / libtest / lib572.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 */
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  */
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   curl = curl_easy_init();
59   if(!curl) {
60     fprintf(stderr, "curl_easy_init() failed\n");
61     curl_global_cleanup();
62     return TEST_ERR_MAJOR_BAD;
63   }
64
65
66   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
67   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
68   test_setopt(curl, CURLOPT_VERBOSE, 1L);
69
70   test_setopt(curl, CURLOPT_URL, URL);
71
72   /* SETUP */
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   free(stream_uri);
80   stream_uri = NULL;
81
82   test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
83   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
84   res = curl_easy_perform(curl);
85   if(res)
86     goto test_cleanup;
87
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
97   /* PUT style GET_PARAMETERS */
98   params = open("log/file572.txt", O_RDONLY);
99   fstat(params, &file_info);
100   close(params);
101
102   paramsf = fopen("log/file572.txt", "rb");
103   if(paramsf == NULL) {
104     fprintf(stderr, "can't open log/file572.txt\n");
105     res = TEST_ERR_MAJOR_BAD;
106     goto test_cleanup;
107   }
108   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
109
110   test_setopt(curl, CURLOPT_READDATA, paramsf);
111   test_setopt(curl, CURLOPT_UPLOAD, 1L);
112   test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
113
114   res = curl_easy_perform(curl);
115   if(res)
116     goto test_cleanup;
117
118   test_setopt(curl, CURLOPT_UPLOAD, 0L);
119   fclose(paramsf);
120   paramsf = NULL;
121
122   /* Heartbeat GET_PARAMETERS */
123   stream_uri = suburl(URL, request++);
124   if(!stream_uri) {
125     res = TEST_ERR_MAJOR_BAD;
126     goto test_cleanup;
127   }
128   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
129   free(stream_uri);
130   stream_uri = NULL;
131
132   res = curl_easy_perform(curl);
133   if(res)
134     goto test_cleanup;
135
136   /* POST GET_PARAMETERS */
137
138   stream_uri = suburl(URL, request++);
139   if(!stream_uri) {
140     res = TEST_ERR_MAJOR_BAD;
141     goto test_cleanup;
142   }
143   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
144   free(stream_uri);
145   stream_uri = NULL;
146
147   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
148   test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
149
150   res = curl_easy_perform(curl);
151   if(res)
152     goto test_cleanup;
153
154   test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
155
156   /* Make sure we can do a normal request now */
157   stream_uri = suburl(URL, request++);
158   if(!stream_uri) {
159     res = TEST_ERR_MAJOR_BAD;
160     goto test_cleanup;
161   }
162   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
163   free(stream_uri);
164   stream_uri = NULL;
165
166   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
167   res = curl_easy_perform(curl);
168
169 test_cleanup:
170
171   if(paramsf)
172     fclose(paramsf);
173
174   free(stream_uri);
175
176   if(custom_headers)
177     curl_slist_free_all(custom_headers);
178
179   curl_easy_cleanup(curl);
180   curl_global_cleanup();
181
182   return res;
183 }
184