lib569.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <curl/mprintf.h>
  24. #include "memdebug.h"
  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. * Test Session ID capture
  32. */
  33. int test(char *URL)
  34. {
  35. int res;
  36. CURL *curl;
  37. char *stream_uri = NULL;
  38. char *rtsp_session_id;
  39. int request=1;
  40. int i;
  41. FILE *idfile = NULL;
  42. idfile = fopen(libtest_arg2, "wb");
  43. if(idfile == NULL) {
  44. fprintf(stderr, "couldn't open the Session ID File\n");
  45. return TEST_ERR_MAJOR_BAD;
  46. }
  47. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  48. fprintf(stderr, "curl_global_init() failed\n");
  49. fclose(idfile);
  50. return TEST_ERR_MAJOR_BAD;
  51. }
  52. if ((curl = curl_easy_init()) == NULL) {
  53. fprintf(stderr, "curl_easy_init() failed\n");
  54. curl_global_cleanup();
  55. fclose(idfile);
  56. return TEST_ERR_MAJOR_BAD;
  57. }
  58. test_setopt(curl, CURLOPT_HEADERDATA, stdout);
  59. test_setopt(curl, CURLOPT_WRITEDATA, stdout);
  60. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  61. test_setopt(curl, CURLOPT_URL, URL);
  62. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  63. res = curl_easy_perform(curl);
  64. if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
  65. fprintf(stderr, "This should have failed. "
  66. "Cannot setup without a Transport: header");
  67. res = TEST_ERR_MAJOR_BAD;
  68. goto test_cleanup;
  69. }
  70. /* Go through the various Session IDs */
  71. for(i = 0; i < 3; i++) {
  72. if((stream_uri = suburl(URL, request++)) == NULL) {
  73. res = TEST_ERR_MAJOR_BAD;
  74. goto test_cleanup;
  75. }
  76. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  77. free(stream_uri);
  78. stream_uri = NULL;
  79. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  80. test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Fake/NotReal/JustATest;foo=baz");
  81. res = curl_easy_perform(curl);
  82. if(res)
  83. goto test_cleanup;
  84. curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
  85. fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
  86. rtsp_session_id = NULL;
  87. if((stream_uri = suburl(URL, request++)) == NULL) {
  88. res = TEST_ERR_MAJOR_BAD;
  89. goto test_cleanup;
  90. }
  91. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  92. free(stream_uri);
  93. stream_uri = NULL;
  94. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
  95. res = curl_easy_perform(curl);
  96. /* Clear for the next go-round */
  97. test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
  98. }
  99. test_cleanup:
  100. if(idfile)
  101. fclose(idfile);
  102. if(stream_uri)
  103. free(stream_uri);
  104. curl_easy_cleanup(curl);
  105. curl_global_cleanup();
  106. return res;
  107. }