| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
 | 2 |  *                                  _   _ ____  _ | 
 | 3 |  *  Project                     ___| | | |  _ \| | | 
 | 4 |  *                             / __| | | | |_) | | | 
 | 5 |  *                            | (__| |_| |  _ <| |___ | 
 | 6 |  *                             \___|\___/|_| \_\_____| | 
 | 7 |  * | 
 | 8 |  * Copyright (C) 1998 - 2022, 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 "test.h" | 
 | 25 |  | 
 | 26 | #ifdef HAVE_SYS_STAT_H | 
 | 27 | #include <sys/stat.h> | 
 | 28 | #endif | 
 | 29 | #ifdef HAVE_FCNTL_H | 
 | 30 | #include <fcntl.h> | 
 | 31 | #endif | 
 | 32 |  | 
 | 33 | #include "memdebug.h" | 
 | 34 |  | 
 | 35 | /* build request url */ | 
 | 36 | static char *suburl(const char *base, int i) | 
 | 37 | { | 
 | 38 |   return curl_maprintf("%s%.4d", base, i); | 
 | 39 | } | 
 | 40 |  | 
 | 41 | /* | 
 | 42 |  * Test the Client->Server ANNOUNCE functionality (PUT style) | 
 | 43 |  */ | 
 | 44 | int test(char *URL) | 
 | 45 | { | 
 | 46 |   int res; | 
 | 47 |   CURL *curl; | 
 | 48 |   int sdp; | 
 | 49 |   FILE *sdpf = NULL; | 
 | 50 |   struct_stat file_info; | 
 | 51 |   char *stream_uri = NULL; | 
 | 52 |   int request = 1; | 
 | 53 |   struct curl_slist *custom_headers = NULL; | 
 | 54 |  | 
 | 55 |   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { | 
 | 56 |     fprintf(stderr, "curl_global_init() failed\n"); | 
 | 57 |     return TEST_ERR_MAJOR_BAD; | 
 | 58 |   } | 
 | 59 |  | 
 | 60 |   curl = curl_easy_init(); | 
 | 61 |   if(!curl) { | 
 | 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 |   stream_uri = suburl(URL, request++); | 
 | 73 |   if(!stream_uri) { | 
 | 74 |     res = TEST_ERR_MAJOR_BAD; | 
 | 75 |     goto test_cleanup; | 
 | 76 |   } | 
 | 77 |   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); | 
 | 78 |   free(stream_uri); | 
 | 79 |   stream_uri = NULL; | 
 | 80 |  | 
 | 81 |   sdp = open("log/file568.txt", O_RDONLY); | 
 | 82 |   fstat(sdp, &file_info); | 
 | 83 |   close(sdp); | 
 | 84 |  | 
 | 85 |   sdpf = fopen("log/file568.txt", "rb"); | 
 | 86 |   if(!sdpf) { | 
 | 87 |     fprintf(stderr, "can't open log/file568.txt\n"); | 
 | 88 |     res = TEST_ERR_MAJOR_BAD; | 
 | 89 |     goto test_cleanup; | 
 | 90 |   } | 
 | 91 |   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); | 
 | 92 |  | 
 | 93 |   test_setopt(curl, CURLOPT_READDATA, sdpf); | 
 | 94 |   test_setopt(curl, CURLOPT_UPLOAD, 1L); | 
 | 95 |   test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); | 
 | 96 |  | 
 | 97 |   /* Do the ANNOUNCE */ | 
 | 98 |   res = curl_easy_perform(curl); | 
 | 99 |   if(res) | 
 | 100 |     goto test_cleanup; | 
 | 101 |  | 
 | 102 |   test_setopt(curl, CURLOPT_UPLOAD, 0L); | 
 | 103 |   fclose(sdpf); | 
 | 104 |   sdpf = NULL; | 
 | 105 |  | 
 | 106 |   /* Make sure we can do a normal request now */ | 
 | 107 |   stream_uri = suburl(URL, request++); | 
 | 108 |   if(!stream_uri) { | 
 | 109 |     res = TEST_ERR_MAJOR_BAD; | 
 | 110 |     goto test_cleanup; | 
 | 111 |   } | 
 | 112 |   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); | 
 | 113 |   free(stream_uri); | 
 | 114 |   stream_uri = NULL; | 
 | 115 |  | 
 | 116 |   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); | 
 | 117 |   res = curl_easy_perform(curl); | 
 | 118 |   if(res) | 
 | 119 |     goto test_cleanup; | 
 | 120 |  | 
 | 121 |   /* Now do a POST style one */ | 
 | 122 |  | 
 | 123 |   stream_uri = suburl(URL, request++); | 
 | 124 |   if(!stream_uri) { | 
 | 125 |     res = TEST_ERR_MAJOR_BAD; | 
 | 126 |     goto test_cleanup; | 
 | 127 |   } | 
 | 128 |   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); | 
 | 129 |   free(stream_uri); | 
 | 130 |   stream_uri = NULL; | 
 | 131 |  | 
 | 132 |   custom_headers = curl_slist_append(custom_headers, | 
 | 133 |                                      "Content-Type: posty goodness"); | 
 | 134 |   if(!custom_headers) { | 
 | 135 |     res = TEST_ERR_MAJOR_BAD; | 
 | 136 |     goto test_cleanup; | 
 | 137 |   } | 
 | 138 |   test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers); | 
 | 139 |   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); | 
 | 140 |   test_setopt(curl, CURLOPT_POSTFIELDS, | 
 | 141 |               "postyfield=postystuff&project=curl\n"); | 
 | 142 |  | 
 | 143 |   res = curl_easy_perform(curl); | 
 | 144 |   if(res) | 
 | 145 |     goto test_cleanup; | 
 | 146 |  | 
 | 147 |   test_setopt(curl, CURLOPT_POSTFIELDS, NULL); | 
 | 148 |   test_setopt(curl, CURLOPT_RTSPHEADER, NULL); | 
 | 149 |   curl_slist_free_all(custom_headers); | 
 | 150 |   custom_headers = NULL; | 
 | 151 |  | 
 | 152 |   /* Make sure we can do a normal request now */ | 
 | 153 |   stream_uri = suburl(URL, request++); | 
 | 154 |   if(!stream_uri) { | 
 | 155 |     res = TEST_ERR_MAJOR_BAD; | 
 | 156 |     goto test_cleanup; | 
 | 157 |   } | 
 | 158 |   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); | 
 | 159 |   free(stream_uri); | 
 | 160 |   stream_uri = NULL; | 
 | 161 |  | 
 | 162 |   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); | 
 | 163 |   res = curl_easy_perform(curl); | 
 | 164 |  | 
 | 165 | test_cleanup: | 
 | 166 |  | 
 | 167 |   if(sdpf) | 
 | 168 |     fclose(sdpf); | 
 | 169 |  | 
 | 170 |   free(stream_uri); | 
 | 171 |  | 
 | 172 |   if(custom_headers) | 
 | 173 |     curl_slist_free_all(custom_headers); | 
 | 174 |  | 
 | 175 |   curl_easy_cleanup(curl); | 
 | 176 |   curl_global_cleanup(); | 
 | 177 |  | 
 | 178 |   return res; | 
 | 179 | } |