Git init
[external/curl.git] / tests / libtest / lib568.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
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 the Client->Server ANNOUNCE functionality (PUT style)
31  */
32 int test(char *URL)
33 {
34   int res;
35   CURL *curl;
36   int sdp;
37   FILE *sdpf = 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   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
55   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
56
57   test_setopt(curl, CURLOPT_URL, URL);
58
59   if((stream_uri = suburl(URL, request++)) == NULL) {
60     res = TEST_ERR_MAJOR_BAD;
61     goto test_cleanup;
62   }
63   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
64   free(stream_uri);
65   stream_uri = NULL;
66
67   sdp = open("log/file568.txt", O_RDONLY);
68   fstat(sdp, &file_info);
69   close(sdp);
70
71   sdpf = fopen("log/file568.txt", "rb");
72   if(sdpf == NULL) {
73     fprintf(stderr, "can't open log/file568.txt\n");
74     res = TEST_ERR_MAJOR_BAD;
75     goto test_cleanup;
76   }
77   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
78
79   test_setopt(curl, CURLOPT_READDATA, sdpf);
80   test_setopt(curl, CURLOPT_UPLOAD, 1L);
81   test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
82
83   /* Do the ANNOUNCE */
84   res = curl_easy_perform(curl);
85   if(res)
86     goto test_cleanup;
87
88   test_setopt(curl, CURLOPT_UPLOAD, 0L);
89   fclose(sdpf);
90   sdpf = NULL;
91
92   /* Make sure we can do a normal request now */
93   if((stream_uri = suburl(URL, request++)) == NULL) {
94     res = TEST_ERR_MAJOR_BAD;
95     goto test_cleanup;
96   }
97   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
98   free(stream_uri);
99   stream_uri = NULL;
100
101   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
102   res = curl_easy_perform(curl);
103   if(res)
104     goto test_cleanup;
105
106   /* Now do a POST style one */
107
108   if((stream_uri = suburl(URL, request++)) == NULL) {
109     res = TEST_ERR_MAJOR_BAD;
110     goto test_cleanup;
111   }
112   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
113   free(stream_uri);
114   stream_uri = NULL;
115
116   custom_headers = curl_slist_append(custom_headers,
117                                      "Content-Type: posty goodness");
118   if(!custom_headers) {
119     res = TEST_ERR_MAJOR_BAD;
120     goto test_cleanup;
121   }
122   test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
123   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
124   test_setopt(curl, CURLOPT_POSTFIELDS, "postyfield=postystuff&project=curl\n");
125
126   res = curl_easy_perform(curl);
127   if(res)
128     goto test_cleanup;
129
130   test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
131   test_setopt(curl, CURLOPT_RTSPHEADER, NULL);
132   curl_slist_free_all(custom_headers);
133   custom_headers = NULL;
134
135   /* Make sure we can do a normal request now */
136   if((stream_uri = suburl(URL, request++)) == NULL) {
137     res = TEST_ERR_MAJOR_BAD;
138     goto test_cleanup;
139   }
140   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
141   free(stream_uri);
142   stream_uri = NULL;
143
144   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
145   res = curl_easy_perform(curl);
146
147 test_cleanup:
148
149   if(sdpf)
150     fclose(sdpf);
151
152   if(stream_uri)
153     free(stream_uri);
154
155   if(custom_headers)
156     curl_slist_free_all(custom_headers);
157
158   curl_easy_cleanup(curl);
159   curl_global_cleanup();
160
161   return res;
162 }
163