Git init
[external/curl.git] / tests / libtest / lib572.c
1
2 /*****************************************************************************
3  *                                  _   _ ____  _
4  *  Project                     ___| | | |  _ \| |
5  *                             / __| | | | |_) | |
6  *                            | (__| |_| |  _ <| |___
7  *                             \___|\___/|_| \_\_____|
8  */
9
10 #include "test.h"
11
12 #ifdef HAVE_SYS_STAT_H
13 #include <sys/stat.h>
14 #endif
15 #ifdef HAVE_FCNTL_H
16 #include <fcntl.h>
17 #endif
18
19 #include <curl/mprintf.h>
20
21 #include "memdebug.h"
22
23 /* build request url */
24 static char *suburl(const char *base, int i)
25 {
26   return curl_maprintf("%s%.4d", base, i);
27 }
28
29 /*
30  * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
31  */
32 int test(char *URL)
33 {
34   int res;
35   CURL *curl;
36   int params;
37   FILE *paramsf = NULL;
38   struct_stat file_info;
39   char *stream_uri = NULL;
40   int request=1;
41   struct curl_slist *custom_headers=NULL;
42
43   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
44     fprintf(stderr, "curl_global_init() failed\n");
45     return TEST_ERR_MAJOR_BAD;
46   }
47
48   if ((curl = curl_easy_init()) == NULL) {
49     fprintf(stderr, "curl_easy_init() failed\n");
50     curl_global_cleanup();
51     return TEST_ERR_MAJOR_BAD;
52   }
53
54
55   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
56   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
57   test_setopt(curl, CURLOPT_VERBOSE, 1L);
58
59   test_setopt(curl, CURLOPT_URL, URL);
60
61   /* SETUP */
62   if((stream_uri = suburl(URL, request++)) == NULL) {
63     res = TEST_ERR_MAJOR_BAD;
64     goto test_cleanup;
65   }
66   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
67   free(stream_uri);
68   stream_uri = NULL;
69
70   test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
71   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
72   res = curl_easy_perform(curl);
73   if(res)
74     goto test_cleanup;
75
76   if((stream_uri = suburl(URL, request++)) == NULL) {
77     res = TEST_ERR_MAJOR_BAD;
78     goto test_cleanup;
79   }
80   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
81   free(stream_uri);
82   stream_uri = NULL;
83
84   /* PUT style GET_PARAMETERS */
85   params = open("log/file572.txt", O_RDONLY);
86   fstat(params, &file_info);
87   close(params);
88
89   paramsf = fopen("log/file572.txt", "rb");
90   if(paramsf == NULL) {
91     fprintf(stderr, "can't open log/file572.txt\n");
92     res = TEST_ERR_MAJOR_BAD;
93     goto test_cleanup;
94   }
95   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
96
97   test_setopt(curl, CURLOPT_READDATA, paramsf);
98   test_setopt(curl, CURLOPT_UPLOAD, 1L);
99   test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
100
101   res = curl_easy_perform(curl);
102   if(res)
103     goto test_cleanup;
104
105   test_setopt(curl, CURLOPT_UPLOAD, 0L);
106   fclose(paramsf);
107   paramsf = NULL;
108
109   /* Heartbeat GET_PARAMETERS */
110   if((stream_uri = suburl(URL, request++)) == NULL) {
111     res = TEST_ERR_MAJOR_BAD;
112     goto test_cleanup;
113   }
114   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
115   free(stream_uri);
116   stream_uri = NULL;
117
118   res = curl_easy_perform(curl);
119   if(res)
120     goto test_cleanup;
121
122   /* POST GET_PARAMETERS */
123
124   if((stream_uri = suburl(URL, request++)) == NULL) {
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   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
133   test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
134
135   res = curl_easy_perform(curl);
136   if(res)
137     goto test_cleanup;
138
139   test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
140
141   /* Make sure we can do a normal request now */
142   if((stream_uri = suburl(URL, request++)) == NULL) {
143     res = TEST_ERR_MAJOR_BAD;
144     goto test_cleanup;
145   }
146   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
147   free(stream_uri);
148   stream_uri = NULL;
149
150   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
151   res = curl_easy_perform(curl);
152
153 test_cleanup:
154
155   if(paramsf)
156     fclose(paramsf);
157
158   if(stream_uri)
159     free(stream_uri);
160
161   if(custom_headers)
162     curl_slist_free_all(custom_headers);
163
164   curl_easy_cleanup(curl);
165   curl_global_cleanup();
166
167   return res;
168 }
169