lib569.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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.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 #include "memdebug.h"
24 
25 /* build request url */
26 static char *suburl(const char *base, int i)
27 {
28  return curl_maprintf("%s%.4d", base, i);
29 }
30 
31 /*
32  * Test Session ID capture
33  */
34 int test(char *URL)
35 {
36  int res;
37  CURL *curl;
38  char *stream_uri = NULL;
39  char *rtsp_session_id;
40  int request = 1;
41  int i;
42  FILE *idfile = NULL;
43 
44  idfile = fopen(libtest_arg2, "wb");
45  if(idfile == NULL) {
46  fprintf(stderr, "couldn't open the Session ID File\n");
47  return TEST_ERR_MAJOR_BAD;
48  }
49 
51  fprintf(stderr, "curl_global_init() failed\n");
52  fclose(idfile);
53  return TEST_ERR_MAJOR_BAD;
54  }
55 
56  curl = curl_easy_init();
57  if(!curl) {
58  fprintf(stderr, "curl_easy_init() failed\n");
60  fclose(idfile);
61  return TEST_ERR_MAJOR_BAD;
62  }
63 
64  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
65  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
66  test_setopt(curl, CURLOPT_VERBOSE, 1L);
67 
68  test_setopt(curl, CURLOPT_URL, URL);
69 
70  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
71  res = curl_easy_perform(curl);
72  if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
73  fprintf(stderr, "This should have failed. "
74  "Cannot setup without a Transport: header");
75  res = TEST_ERR_MAJOR_BAD;
76  goto test_cleanup;
77  }
78 
79  /* Go through the various Session IDs */
80  for(i = 0; i < 3; i++) {
81  stream_uri = suburl(URL, request++);
82  if(!stream_uri) {
83  res = TEST_ERR_MAJOR_BAD;
84  goto test_cleanup;
85  }
86  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
87  free(stream_uri);
88  stream_uri = NULL;
89 
90  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
91  test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
92  "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  stream_uri = suburl(URL, request++);
102  if(!stream_uri) {
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 
117 test_cleanup:
118 
119  if(idfile)
120  fclose(idfile);
121 
122  free(stream_uri);
123  curl_easy_cleanup(curl);
125 
126  return res;
127 }
128 
#define free(ptr)
Definition: curl_memory.h:130
#define test_setopt(A, B, C)
Definition: test.h:47
auto base
static int res
unsigned int i
Definition: unit1303.c:79
static char * suburl(const char *base, int i)
Definition: lib569.c:26
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
#define curl_easy_getinfo(handle, info, arg)
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
int test(char *URL)
Definition: lib569.c:34
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
CURL_EXTERN char * curl_maprintf(const char *format,...)
Definition: mprintf.c:1066
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15