lib568.c (4787B)
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 the Client->Server ANNOUNCE functionality (PUT style) 31 */ 32 static CURLcode test_lib568(char *URL) 33 { 34 CURLcode res; 35 CURL *curl; 36 int sdp; 37 FILE *sdpf = 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 58 test_setopt(curl, CURLOPT_URL, URL); 59 60 stream_uri = tutil_suburl(URL, request++); 61 if(!stream_uri) { 62 res = TEST_ERR_MAJOR_BAD; 63 goto test_cleanup; 64 } 65 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 66 curl_free(stream_uri); 67 stream_uri = NULL; 68 69 sdp = open(libtest_arg2, O_RDONLY); 70 if(sdp == -1) { 71 curl_mfprintf(stderr, "can't open %s\n", libtest_arg2); 72 res = TEST_ERR_MAJOR_BAD; 73 goto test_cleanup; 74 } 75 fstat(sdp, &file_info); 76 close(sdp); 77 78 sdpf = fopen(libtest_arg2, "rb"); 79 if(!sdpf) { 80 curl_mfprintf(stderr, "can't fopen %s\n", libtest_arg2); 81 res = TEST_ERR_MAJOR_BAD; 82 goto test_cleanup; 83 } 84 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); 85 86 test_setopt(curl, CURLOPT_READDATA, sdpf); 87 test_setopt(curl, CURLOPT_UPLOAD, 1L); 88 test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); 89 test_setopt(curl, CURLOPT_VERBOSE, 1L); 90 91 /* Do the ANNOUNCE */ 92 res = curl_easy_perform(curl); 93 if(res) 94 goto test_cleanup; 95 96 test_setopt(curl, CURLOPT_UPLOAD, 0L); 97 fclose(sdpf); 98 sdpf = NULL; 99 100 /* Make sure we can do a normal request now */ 101 stream_uri = tutil_suburl(URL, request++); 102 if(!stream_uri) { 103 res = TEST_ERR_MAJOR_BAD; 104 goto test_cleanup; 105 } 106 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 107 curl_free(stream_uri); 108 stream_uri = NULL; 109 110 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); 111 res = curl_easy_perform(curl); 112 if(res) 113 goto test_cleanup; 114 115 /* Now do a POST style one */ 116 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 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, 135 "postyfield=postystuff&project=curl\n"); 136 137 res = curl_easy_perform(curl); 138 if(res) 139 goto test_cleanup; 140 141 test_setopt(curl, CURLOPT_POSTFIELDS, NULL); 142 test_setopt(curl, CURLOPT_RTSPHEADER, NULL); 143 curl_slist_free_all(custom_headers); 144 custom_headers = NULL; 145 146 /* Make sure we can do a normal request now */ 147 stream_uri = tutil_suburl(URL, request++); 148 if(!stream_uri) { 149 res = TEST_ERR_MAJOR_BAD; 150 goto test_cleanup; 151 } 152 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 153 curl_free(stream_uri); 154 stream_uri = NULL; 155 156 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); 157 res = curl_easy_perform(curl); 158 159 test_cleanup: 160 161 if(sdpf) 162 fclose(sdpf); 163 164 curl_free(stream_uri); 165 166 if(custom_headers) 167 curl_slist_free_all(custom_headers); 168 169 curl_easy_cleanup(curl); 170 curl_global_cleanup(); 171 172 return res; 173 }