lib572.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #ifdef HAVE_SYS_STAT_H
00025 #include <sys/stat.h>
00026 #endif
00027 #ifdef HAVE_FCNTL_H
00028 #include <fcntl.h>
00029 #endif
00030 
00031 #include "memdebug.h"
00032 
00033 /* build request url */
00034 static char *suburl(const char *base, int i)
00035 {
00036   return curl_maprintf("%s%.4d", base, i);
00037 }
00038 
00039 /*
00040  * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
00041  */
00042 int test(char *URL)
00043 {
00044   int res;
00045   CURL *curl;
00046   int params;
00047   FILE *paramsf = NULL;
00048   struct_stat file_info;
00049   char *stream_uri = NULL;
00050   int request=1;
00051   struct curl_slist *custom_headers=NULL;
00052 
00053   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00054     fprintf(stderr, "curl_global_init() failed\n");
00055     return TEST_ERR_MAJOR_BAD;
00056   }
00057 
00058   curl = curl_easy_init();
00059   if(!curl) {
00060     fprintf(stderr, "curl_easy_init() failed\n");
00061     curl_global_cleanup();
00062     return TEST_ERR_MAJOR_BAD;
00063   }
00064 
00065 
00066   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
00067   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
00068   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00069 
00070   test_setopt(curl, CURLOPT_URL, URL);
00071 
00072   /* SETUP */
00073   stream_uri = suburl(URL, request++);
00074   if(!stream_uri) {
00075     res = TEST_ERR_MAJOR_BAD;
00076     goto test_cleanup;
00077   }
00078   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00079   free(stream_uri);
00080   stream_uri = NULL;
00081 
00082   test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
00083   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
00084   res = curl_easy_perform(curl);
00085   if(res)
00086     goto test_cleanup;
00087 
00088   stream_uri = suburl(URL, request++);
00089   if(!stream_uri) {
00090     res = TEST_ERR_MAJOR_BAD;
00091     goto test_cleanup;
00092   }
00093   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00094   free(stream_uri);
00095   stream_uri = NULL;
00096 
00097   /* PUT style GET_PARAMETERS */
00098   params = open("log/file572.txt", O_RDONLY);
00099   fstat(params, &file_info);
00100   close(params);
00101 
00102   paramsf = fopen("log/file572.txt", "rb");
00103   if(paramsf == NULL) {
00104     fprintf(stderr, "can't open log/file572.txt\n");
00105     res = TEST_ERR_MAJOR_BAD;
00106     goto test_cleanup;
00107   }
00108   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
00109 
00110   test_setopt(curl, CURLOPT_READDATA, paramsf);
00111   test_setopt(curl, CURLOPT_UPLOAD, 1L);
00112   test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
00113 
00114   res = curl_easy_perform(curl);
00115   if(res)
00116     goto test_cleanup;
00117 
00118   test_setopt(curl, CURLOPT_UPLOAD, 0L);
00119   fclose(paramsf);
00120   paramsf = NULL;
00121 
00122   /* Heartbeat GET_PARAMETERS */
00123   stream_uri = suburl(URL, request++);
00124   if(!stream_uri) {
00125     res = TEST_ERR_MAJOR_BAD;
00126     goto test_cleanup;
00127   }
00128   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00129   free(stream_uri);
00130   stream_uri = NULL;
00131 
00132   res = curl_easy_perform(curl);
00133   if(res)
00134     goto test_cleanup;
00135 
00136   /* POST GET_PARAMETERS */
00137 
00138   stream_uri = suburl(URL, request++);
00139   if(!stream_uri) {
00140     res = TEST_ERR_MAJOR_BAD;
00141     goto test_cleanup;
00142   }
00143   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00144   free(stream_uri);
00145   stream_uri = NULL;
00146 
00147   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
00148   test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
00149 
00150   res = curl_easy_perform(curl);
00151   if(res)
00152     goto test_cleanup;
00153 
00154   test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
00155 
00156   /* Make sure we can do a normal request now */
00157   stream_uri = suburl(URL, request++);
00158   if(!stream_uri) {
00159     res = TEST_ERR_MAJOR_BAD;
00160     goto test_cleanup;
00161   }
00162   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00163   free(stream_uri);
00164   stream_uri = NULL;
00165 
00166   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
00167   res = curl_easy_perform(curl);
00168 
00169 test_cleanup:
00170 
00171   if(paramsf)
00172     fclose(paramsf);
00173 
00174   free(stream_uri);
00175 
00176   if(custom_headers)
00177     curl_slist_free_all(custom_headers);
00178 
00179   curl_easy_cleanup(curl);
00180   curl_global_cleanup();
00181 
00182   return res;
00183 }
00184 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05