Home | History | Annotate | Download | only in libtest
      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel (at) 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 #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 
     50   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     51     fprintf(stderr, "curl_global_init() failed\n");
     52     fclose(idfile);
     53     return TEST_ERR_MAJOR_BAD;
     54   }
     55 
     56   if ((curl = curl_easy_init()) == NULL) {
     57     fprintf(stderr, "curl_easy_init() failed\n");
     58     curl_global_cleanup();
     59     fclose(idfile);
     60     return TEST_ERR_MAJOR_BAD;
     61   }
     62 
     63   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
     64   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
     65   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     66 
     67   test_setopt(curl, CURLOPT_URL, URL);
     68 
     69   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
     70   res = curl_easy_perform(curl);
     71   if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
     72     fprintf(stderr, "This should have failed. "
     73             "Cannot setup without a Transport: header");
     74     res = TEST_ERR_MAJOR_BAD;
     75     goto test_cleanup;
     76   }
     77 
     78   /* Go through the various Session IDs */
     79   for(i = 0; i < 3; i++) {
     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     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
     89     test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Fake/NotReal/JustATest;foo=baz");
     90     res = curl_easy_perform(curl);
     91     if(res)
     92       goto test_cleanup;
     93 
     94     curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
     95     fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
     96     rtsp_session_id = NULL;
     97 
     98     if((stream_uri = suburl(URL, request++)) == NULL) {
     99       res = TEST_ERR_MAJOR_BAD;
    100       goto test_cleanup;
    101     }
    102     test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
    103     free(stream_uri);
    104     stream_uri = NULL;
    105 
    106     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
    107     res = curl_easy_perform(curl);
    108 
    109     /* Clear for the next go-round */
    110     test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
    111   }
    112 
    113 test_cleanup:
    114 
    115   if(idfile)
    116     fclose(idfile);
    117 
    118   free(stream_uri);
    119   curl_easy_cleanup(curl);
    120   curl_global_cleanup();
    121 
    122   return res;
    123 }
    124 
    125