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