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 23#include "test.h" 24 25#ifdef HAVE_SYS_STAT_H 26#include <sys/stat.h> 27#endif 28#ifdef HAVE_FCNTL_H 29#include <fcntl.h> 30#endif 31 32#include <curl/mprintf.h> 33 34#include "memdebug.h" 35 36/* build request url */ 37static char *suburl(const char *base, int i) 38{ 39 return curl_maprintf("%s%.4d", base, i); 40} 41 42/* 43 * Test the Client->Server ANNOUNCE functionality (PUT style) 44 */ 45int test(char *URL) 46{ 47 int res; 48 CURL *curl; 49 int sdp; 50 FILE *sdpf = NULL; 51 struct_stat file_info; 52 char *stream_uri = NULL; 53 int request=1; 54 struct curl_slist *custom_headers=NULL; 55 56 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 57 fprintf(stderr, "curl_global_init() failed\n"); 58 return TEST_ERR_MAJOR_BAD; 59 } 60 61 if ((curl = curl_easy_init()) == NULL) { 62 fprintf(stderr, "curl_easy_init() failed\n"); 63 curl_global_cleanup(); 64 return TEST_ERR_MAJOR_BAD; 65 } 66 67 test_setopt(curl, CURLOPT_HEADERDATA, stdout); 68 test_setopt(curl, CURLOPT_WRITEDATA, stdout); 69 70 test_setopt(curl, CURLOPT_URL, URL); 71 72 if((stream_uri = suburl(URL, request++)) == NULL) { 73 res = TEST_ERR_MAJOR_BAD; 74 goto test_cleanup; 75 } 76 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 77 free(stream_uri); 78 stream_uri = NULL; 79 80 sdp = open("log/file568.txt", O_RDONLY); 81 fstat(sdp, &file_info); 82 close(sdp); 83 84 sdpf = fopen("log/file568.txt", "rb"); 85 if(sdpf == NULL) { 86 fprintf(stderr, "can't open log/file568.txt\n"); 87 res = TEST_ERR_MAJOR_BAD; 88 goto test_cleanup; 89 } 90 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); 91 92 test_setopt(curl, CURLOPT_READDATA, sdpf); 93 test_setopt(curl, CURLOPT_UPLOAD, 1L); 94 test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); 95 96 /* Do the ANNOUNCE */ 97 res = curl_easy_perform(curl); 98 if(res) 99 goto test_cleanup; 100 101 test_setopt(curl, CURLOPT_UPLOAD, 0L); 102 fclose(sdpf); 103 sdpf = NULL; 104 105 /* Make sure we can do a normal request now */ 106 if((stream_uri = suburl(URL, request++)) == NULL) { 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 if((stream_uri = suburl(URL, request++)) == NULL) { 122 res = TEST_ERR_MAJOR_BAD; 123 goto test_cleanup; 124 } 125 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 126 free(stream_uri); 127 stream_uri = NULL; 128 129 custom_headers = curl_slist_append(custom_headers, 130 "Content-Type: posty goodness"); 131 if(!custom_headers) { 132 res = TEST_ERR_MAJOR_BAD; 133 goto test_cleanup; 134 } 135 test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers); 136 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); 137 test_setopt(curl, CURLOPT_POSTFIELDS, "postyfield=postystuff&project=curl\n"); 138 139 res = curl_easy_perform(curl); 140 if(res) 141 goto test_cleanup; 142 143 test_setopt(curl, CURLOPT_POSTFIELDS, NULL); 144 test_setopt(curl, CURLOPT_RTSPHEADER, NULL); 145 curl_slist_free_all(custom_headers); 146 custom_headers = NULL; 147 148 /* Make sure we can do a normal request now */ 149 if((stream_uri = suburl(URL, request++)) == NULL) { 150 res = TEST_ERR_MAJOR_BAD; 151 goto test_cleanup; 152 } 153 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 154 free(stream_uri); 155 stream_uri = NULL; 156 157 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); 158 res = curl_easy_perform(curl); 159 160test_cleanup: 161 162 if(sdpf) 163 fclose(sdpf); 164 165 if(stream_uri) 166 free(stream_uri); 167 168 if(custom_headers) 169 curl_slist_free_all(custom_headers); 170 171 curl_easy_cleanup(curl); 172 curl_global_cleanup(); 173 174 return res; 175} 176 177