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 GET_PARAMETER: PUT, HEARTBEAT, and POST 44 */ 45int test(char *URL) 46{ 47 int res; 48 CURL *curl; 49 int params; 50 FILE *paramsf = 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 68 test_setopt(curl, CURLOPT_HEADERDATA, stdout); 69 test_setopt(curl, CURLOPT_WRITEDATA, stdout); 70 test_setopt(curl, CURLOPT_VERBOSE, 1L); 71 72 test_setopt(curl, CURLOPT_URL, URL); 73 74 /* SETUP */ 75 if((stream_uri = suburl(URL, request++)) == NULL) { 76 res = TEST_ERR_MAJOR_BAD; 77 goto test_cleanup; 78 } 79 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 80 free(stream_uri); 81 stream_uri = NULL; 82 83 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles"); 84 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); 85 res = curl_easy_perform(curl); 86 if(res) 87 goto test_cleanup; 88 89 if((stream_uri = suburl(URL, request++)) == NULL) { 90 res = TEST_ERR_MAJOR_BAD; 91 goto test_cleanup; 92 } 93 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 94 free(stream_uri); 95 stream_uri = NULL; 96 97 /* PUT style GET_PARAMETERS */ 98 params = open("log/file572.txt", O_RDONLY); 99 fstat(params, &file_info); 100 close(params); 101 102 paramsf = fopen("log/file572.txt", "rb"); 103 if(paramsf == NULL) { 104 fprintf(stderr, "can't open log/file572.txt\n"); 105 res = TEST_ERR_MAJOR_BAD; 106 goto test_cleanup; 107 } 108 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER); 109 110 test_setopt(curl, CURLOPT_READDATA, paramsf); 111 test_setopt(curl, CURLOPT_UPLOAD, 1L); 112 test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); 113 114 res = curl_easy_perform(curl); 115 if(res) 116 goto test_cleanup; 117 118 test_setopt(curl, CURLOPT_UPLOAD, 0L); 119 fclose(paramsf); 120 paramsf = NULL; 121 122 /* Heartbeat GET_PARAMETERS */ 123 if((stream_uri = suburl(URL, request++)) == NULL) { 124 res = TEST_ERR_MAJOR_BAD; 125 goto test_cleanup; 126 } 127 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 128 free(stream_uri); 129 stream_uri = NULL; 130 131 res = curl_easy_perform(curl); 132 if(res) 133 goto test_cleanup; 134 135 /* POST GET_PARAMETERS */ 136 137 if((stream_uri = suburl(URL, request++)) == NULL) { 138 res = TEST_ERR_MAJOR_BAD; 139 goto test_cleanup; 140 } 141 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 142 free(stream_uri); 143 stream_uri = NULL; 144 145 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER); 146 test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n"); 147 148 res = curl_easy_perform(curl); 149 if(res) 150 goto test_cleanup; 151 152 test_setopt(curl, CURLOPT_POSTFIELDS, NULL); 153 154 /* Make sure we can do a normal request now */ 155 if((stream_uri = suburl(URL, request++)) == NULL) { 156 res = TEST_ERR_MAJOR_BAD; 157 goto test_cleanup; 158 } 159 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 160 free(stream_uri); 161 stream_uri = NULL; 162 163 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); 164 res = curl_easy_perform(curl); 165 166test_cleanup: 167 168 if(paramsf) 169 fclose(paramsf); 170 171 if(stream_uri) 172 free(stream_uri); 173 174 if(custom_headers) 175 curl_slist_free_all(custom_headers); 176 177 curl_easy_cleanup(curl); 178 curl_global_cleanup(); 179 180 return res; 181} 182 183