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