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