lib572.c (4794B)
1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 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 https://curl.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 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 #include "first.h" 25 26 #include "testutil.h" 27 #include "memdebug.h" 28 29 /* 30 * Test GET_PARAMETER: PUT, HEARTBEAT, and POST 31 */ 32 static CURLcode test_lib572(char *URL) 33 { 34 CURLcode res; 35 CURL *curl; 36 int params; 37 FILE *paramsf = 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 curl_mfprintf(stderr, "curl_global_init() failed\n"); 45 return TEST_ERR_MAJOR_BAD; 46 } 47 48 curl = curl_easy_init(); 49 if(!curl) { 50 curl_mfprintf(stderr, "curl_easy_init() failed\n"); 51 curl_global_cleanup(); 52 return TEST_ERR_MAJOR_BAD; 53 } 54 55 test_setopt(curl, CURLOPT_HEADERDATA, stdout); 56 test_setopt(curl, CURLOPT_WRITEDATA, stdout); 57 test_setopt(curl, CURLOPT_VERBOSE, 1L); 58 59 test_setopt(curl, CURLOPT_URL, URL); 60 61 /* SETUP */ 62 stream_uri = tutil_suburl(URL, request++); 63 if(!stream_uri) { 64 res = TEST_ERR_MAJOR_BAD; 65 goto test_cleanup; 66 } 67 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 68 curl_free(stream_uri); 69 stream_uri = NULL; 70 71 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles"); 72 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); 73 res = curl_easy_perform(curl); 74 if(res) 75 goto test_cleanup; 76 77 stream_uri = tutil_suburl(URL, request++); 78 if(!stream_uri) { 79 res = TEST_ERR_MAJOR_BAD; 80 goto test_cleanup; 81 } 82 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 83 curl_free(stream_uri); 84 stream_uri = NULL; 85 86 /* PUT style GET_PARAMETERS */ 87 params = open(libtest_arg2, O_RDONLY); 88 if(params == -1) { 89 curl_mfprintf(stderr, "can't open %s\n", libtest_arg2); 90 res = TEST_ERR_MAJOR_BAD; 91 goto test_cleanup; 92 } 93 fstat(params, &file_info); 94 close(params); 95 96 paramsf = fopen(libtest_arg2, "rb"); 97 if(!paramsf) { 98 curl_mfprintf(stderr, "can't fopen %s\n", libtest_arg2); 99 res = TEST_ERR_MAJOR_BAD; 100 goto test_cleanup; 101 } 102 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER); 103 104 test_setopt(curl, CURLOPT_READDATA, paramsf); 105 test_setopt(curl, CURLOPT_UPLOAD, 1L); 106 test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); 107 108 res = curl_easy_perform(curl); 109 if(res) 110 goto test_cleanup; 111 112 test_setopt(curl, CURLOPT_UPLOAD, 0L); 113 fclose(paramsf); 114 paramsf = NULL; 115 116 /* Heartbeat GET_PARAMETERS */ 117 stream_uri = tutil_suburl(URL, request++); 118 if(!stream_uri) { 119 res = TEST_ERR_MAJOR_BAD; 120 goto test_cleanup; 121 } 122 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 123 curl_free(stream_uri); 124 stream_uri = NULL; 125 126 res = curl_easy_perform(curl); 127 if(res) 128 goto test_cleanup; 129 130 /* POST GET_PARAMETERS */ 131 132 stream_uri = tutil_suburl(URL, request++); 133 if(!stream_uri) { 134 res = TEST_ERR_MAJOR_BAD; 135 goto test_cleanup; 136 } 137 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 138 curl_free(stream_uri); 139 stream_uri = NULL; 140 141 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER); 142 test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n"); 143 144 res = curl_easy_perform(curl); 145 if(res) 146 goto test_cleanup; 147 148 test_setopt(curl, CURLOPT_POSTFIELDS, NULL); 149 150 /* Make sure we can do a normal request now */ 151 stream_uri = tutil_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 curl_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(paramsf) 166 fclose(paramsf); 167 168 curl_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 }