lib568.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifdef HAVE_SYS_STAT_H
  24. #include <sys/stat.h>
  25. #endif
  26. #ifdef HAVE_FCNTL_H
  27. #include <fcntl.h>
  28. #endif
  29. #include <curl/mprintf.h>
  30. #include "memdebug.h"
  31. /* build request url */
  32. static char *suburl(const char *base, int i)
  33. {
  34. return curl_maprintf("%s%.4d", base, i);
  35. }
  36. /*
  37. * Test the Client->Server ANNOUNCE functionality (PUT style)
  38. */
  39. int test(char *URL)
  40. {
  41. int res;
  42. CURL *curl;
  43. int sdp;
  44. FILE *sdpf = NULL;
  45. struct_stat file_info;
  46. char *stream_uri = NULL;
  47. int request=1;
  48. struct curl_slist *custom_headers=NULL;
  49. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  50. fprintf(stderr, "curl_global_init() failed\n");
  51. return TEST_ERR_MAJOR_BAD;
  52. }
  53. if ((curl = curl_easy_init()) == NULL) {
  54. fprintf(stderr, "curl_easy_init() failed\n");
  55. curl_global_cleanup();
  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_URL, URL);
  61. if((stream_uri = suburl(URL, request++)) == NULL) {
  62. res = TEST_ERR_MAJOR_BAD;
  63. goto test_cleanup;
  64. }
  65. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  66. free(stream_uri);
  67. stream_uri = NULL;
  68. sdp = open("log/file568.txt", O_RDONLY);
  69. fstat(sdp, &file_info);
  70. close(sdp);
  71. sdpf = fopen("log/file568.txt", "rb");
  72. if(sdpf == NULL) {
  73. fprintf(stderr, "can't open log/file568.txt\n");
  74. res = TEST_ERR_MAJOR_BAD;
  75. goto test_cleanup;
  76. }
  77. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
  78. test_setopt(curl, CURLOPT_READDATA, sdpf);
  79. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  80. test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
  81. /* Do the ANNOUNCE */
  82. res = curl_easy_perform(curl);
  83. if(res)
  84. goto test_cleanup;
  85. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  86. fclose(sdpf);
  87. sdpf = NULL;
  88. /* Make sure we can do a normal request now */
  89. if((stream_uri = suburl(URL, request++)) == NULL) {
  90. res = TEST_ERR_MAJOR_BAD;
  91. goto test_cleanup;
  92. }
  93. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  94. free(stream_uri);
  95. stream_uri = NULL;
  96. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
  97. res = curl_easy_perform(curl);
  98. if(res)
  99. goto test_cleanup;
  100. /* Now do a POST style one */
  101. if((stream_uri = suburl(URL, request++)) == NULL) {
  102. res = TEST_ERR_MAJOR_BAD;
  103. goto test_cleanup;
  104. }
  105. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  106. free(stream_uri);
  107. stream_uri = NULL;
  108. custom_headers = curl_slist_append(custom_headers,
  109. "Content-Type: posty goodness");
  110. if(!custom_headers) {
  111. res = TEST_ERR_MAJOR_BAD;
  112. goto test_cleanup;
  113. }
  114. test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
  115. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
  116. test_setopt(curl, CURLOPT_POSTFIELDS, "postyfield=postystuff&project=curl\n");
  117. res = curl_easy_perform(curl);
  118. if(res)
  119. goto test_cleanup;
  120. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  121. test_setopt(curl, CURLOPT_RTSPHEADER, NULL);
  122. curl_slist_free_all(custom_headers);
  123. custom_headers = NULL;
  124. /* Make sure we can do a normal request now */
  125. if((stream_uri = suburl(URL, request++)) == NULL) {
  126. res = TEST_ERR_MAJOR_BAD;
  127. goto test_cleanup;
  128. }
  129. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  130. free(stream_uri);
  131. stream_uri = NULL;
  132. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  133. res = curl_easy_perform(curl);
  134. test_cleanup:
  135. if(sdpf)
  136. fclose(sdpf);
  137. if(stream_uri)
  138. free(stream_uri);
  139. if(custom_headers)
  140. curl_slist_free_all(custom_headers);
  141. curl_easy_cleanup(curl);
  142. curl_global_cleanup();
  143. return res;
  144. }