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
34int test(char *URL)
35{
36  int res;
37  CURL *curl;
38  int request=1;
39  char *stream_uri = NULL;
40
41  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
42    fprintf(stderr, "curl_global_init() failed\n");
43    return TEST_ERR_MAJOR_BAD;
44  }
45
46  if ((curl = curl_easy_init()) == NULL) {
47    fprintf(stderr, "curl_easy_init() failed\n");
48    curl_global_cleanup();
49    return TEST_ERR_MAJOR_BAD;
50  }
51
52  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
53  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
54  test_setopt(curl, CURLOPT_VERBOSE, 1L);
55
56  test_setopt(curl, CURLOPT_URL, URL);
57
58  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
59
60  if((stream_uri = suburl(URL, request++)) == NULL) {
61    res = TEST_ERR_MAJOR_BAD;
62    goto test_cleanup;
63  }
64  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
65  free(stream_uri);
66  stream_uri = NULL;
67
68  res = curl_easy_perform(curl);
69  if(res != (int)CURLE_RTSP_CSEQ_ERROR) {
70    fprintf(stderr, "Failed to detect CSeq mismatch");
71    res = TEST_ERR_MAJOR_BAD;
72    goto test_cleanup;
73  }
74
75  test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999);
76  test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
77                    "RAW/RAW/UDP;unicast;client_port=3056-3057");
78  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
79
80  if((stream_uri = suburl(URL, request++)) == NULL) {
81    res = TEST_ERR_MAJOR_BAD;
82    goto test_cleanup;
83  }
84  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
85  free(stream_uri);
86  stream_uri = NULL;
87
88  res = curl_easy_perform(curl);
89  if(res)
90    goto test_cleanup;
91
92  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
93
94  if((stream_uri = suburl(URL, request++)) == NULL) {
95    res = TEST_ERR_MAJOR_BAD;
96    goto test_cleanup;
97  }
98  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
99  free(stream_uri);
100  stream_uri = NULL;
101
102  res = curl_easy_perform(curl);
103  if(res != CURLE_RTSP_SESSION_ERROR) {
104    fprintf(stderr, "Failed to detect a Session ID mismatch");
105  }
106
107test_cleanup:
108
109  if(stream_uri)
110    free(stream_uri);
111
112  curl_easy_cleanup(curl);
113  curl_global_cleanup();
114
115  return res;
116}
117
118