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#ifdef HAVE_SYS_STAT_H
25#include <sys/stat.h>
26#endif
27#ifdef HAVE_FCNTL_H
28#include <fcntl.h>
29#endif
30
31#include <curl/mprintf.h>
32
33#include "memdebug.h"
34
35/* build request url */
36static char *suburl(const char *base, int i)
37{
38  return curl_maprintf("%s%.4d", base, i);
39}
40
41/*
42 * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
43 */
44int test(char *URL)
45{
46  int res;
47  CURL *curl;
48  int params;
49  FILE *paramsf = 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  if ((curl = curl_easy_init()) == NULL) {
61    fprintf(stderr, "curl_easy_init() failed\n");
62    curl_global_cleanup();
63    return TEST_ERR_MAJOR_BAD;
64  }
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  /* SETUP */
74  if((stream_uri = suburl(URL, request++)) == NULL) {
75    res = TEST_ERR_MAJOR_BAD;
76    goto test_cleanup;
77  }
78  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
79  free(stream_uri);
80  stream_uri = NULL;
81
82  test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
83  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
84  res = curl_easy_perform(curl);
85  if(res)
86    goto test_cleanup;
87
88  if((stream_uri = suburl(URL, request++)) == NULL) {
89    res = TEST_ERR_MAJOR_BAD;
90    goto test_cleanup;
91  }
92  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
93  free(stream_uri);
94  stream_uri = NULL;
95
96  /* PUT style GET_PARAMETERS */
97  params = open("log/file572.txt", O_RDONLY);
98  fstat(params, &file_info);
99  close(params);
100
101  paramsf = fopen("log/file572.txt", "rb");
102  if(paramsf == NULL) {
103    fprintf(stderr, "can't open log/file572.txt\n");
104    res = TEST_ERR_MAJOR_BAD;
105    goto test_cleanup;
106  }
107  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
108
109  test_setopt(curl, CURLOPT_READDATA, paramsf);
110  test_setopt(curl, CURLOPT_UPLOAD, 1L);
111  test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
112
113  res = curl_easy_perform(curl);
114  if(res)
115    goto test_cleanup;
116
117  test_setopt(curl, CURLOPT_UPLOAD, 0L);
118  fclose(paramsf);
119  paramsf = NULL;
120
121  /* Heartbeat GET_PARAMETERS */
122  if((stream_uri = suburl(URL, request++)) == NULL) {
123    res = TEST_ERR_MAJOR_BAD;
124    goto test_cleanup;
125  }
126  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
127  free(stream_uri);
128  stream_uri = NULL;
129
130  res = curl_easy_perform(curl);
131  if(res)
132    goto test_cleanup;
133
134  /* POST GET_PARAMETERS */
135
136  if((stream_uri = suburl(URL, request++)) == NULL) {
137    res = TEST_ERR_MAJOR_BAD;
138    goto test_cleanup;
139  }
140  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
141  free(stream_uri);
142  stream_uri = NULL;
143
144  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
145  test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
146
147  res = curl_easy_perform(curl);
148  if(res)
149    goto test_cleanup;
150
151  test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
152
153  /* Make sure we can do a normal request now */
154  if((stream_uri = suburl(URL, request++)) == NULL) {
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
165test_cleanup:
166
167  if(paramsf)
168    fclose(paramsf);
169
170  if(stream_uri)
171    free(stream_uri);
172
173  if(custom_headers)
174    curl_slist_free_all(custom_headers);
175
176  curl_easy_cleanup(curl);
177  curl_global_cleanup();
178
179  return res;
180}
181
182