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#include <curl/mprintf.h> 26 27#include "memdebug.h" 28 29/* build request url */ 30static char *suburl(const char *base, int i) 31{ 32 return curl_maprintf("%s%.4d", base, i); 33} 34 35/* 36 * Test Session ID capture 37 */ 38int test(char *URL) 39{ 40 int res; 41 CURL *curl; 42 char *stream_uri = NULL; 43 char *rtsp_session_id; 44 int request=1; 45 int i; 46 FILE *idfile = NULL; 47 48 idfile = fopen(libtest_arg2, "wb"); 49 if(idfile == NULL) { 50 fprintf(stderr, "couldn't open the Session ID File\n"); 51 return TEST_ERR_MAJOR_BAD; 52 } 53 54 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 55 fprintf(stderr, "curl_global_init() failed\n"); 56 fclose(idfile); 57 return TEST_ERR_MAJOR_BAD; 58 } 59 60 if ((curl = curl_easy_init()) == NULL) { 61 fprintf(stderr, "curl_easy_init() failed\n"); 62 curl_global_cleanup(); 63 fclose(idfile); 64 return TEST_ERR_MAJOR_BAD; 65 } 66 67 test_setopt(curl, CURLOPT_HEADERDATA, stdout); 68 test_setopt(curl, CURLOPT_WRITEDATA, stdout); 69 test_setopt(curl, CURLOPT_VERBOSE, 1L); 70 71 test_setopt(curl, CURLOPT_URL, URL); 72 73 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); 74 res = curl_easy_perform(curl); 75 if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) { 76 fprintf(stderr, "This should have failed. " 77 "Cannot setup without a Transport: header"); 78 res = TEST_ERR_MAJOR_BAD; 79 goto test_cleanup; 80 } 81 82 /* Go through the various Session IDs */ 83 for(i = 0; i < 3; i++) { 84 if((stream_uri = suburl(URL, request++)) == NULL) { 85 res = TEST_ERR_MAJOR_BAD; 86 goto test_cleanup; 87 } 88 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 89 free(stream_uri); 90 stream_uri = NULL; 91 92 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); 93 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Fake/NotReal/JustATest;foo=baz"); 94 res = curl_easy_perform(curl); 95 if(res) 96 goto test_cleanup; 97 98 curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id); 99 fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id); 100 rtsp_session_id = NULL; 101 102 if((stream_uri = suburl(URL, request++)) == NULL) { 103 res = TEST_ERR_MAJOR_BAD; 104 goto test_cleanup; 105 } 106 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri); 107 free(stream_uri); 108 stream_uri = NULL; 109 110 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); 111 res = curl_easy_perform(curl); 112 113 /* Clear for the next go-round */ 114 test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL); 115 } 116 117test_cleanup: 118 119 if(idfile) 120 fclose(idfile); 121 122 if(stream_uri) 123 free(stream_uri); 124 125 curl_easy_cleanup(curl); 126 curl_global_cleanup(); 127 128 return res; 129} 130 131