lib572.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 GET_PARAMETER: PUT, HEARTBEAT, and POST
  38. */
  39. int test(char *URL)
  40. {
  41. int res;
  42. CURL *curl;
  43. int params;
  44. FILE *paramsf = 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_VERBOSE, 1L);
  61. test_setopt(curl, CURLOPT_URL, URL);
  62. /* SETUP */
  63. if((stream_uri = suburl(URL, request++)) == NULL) {
  64. res = TEST_ERR_MAJOR_BAD;
  65. goto test_cleanup;
  66. }
  67. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  68. free(stream_uri);
  69. stream_uri = NULL;
  70. test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
  71. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  72. res = curl_easy_perform(curl);
  73. if(res)
  74. goto test_cleanup;
  75. if((stream_uri = suburl(URL, request++)) == NULL) {
  76. res = TEST_ERR_MAJOR_BAD;
  77. goto test_cleanup;
  78. }
  79. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  80. free(stream_uri);
  81. stream_uri = NULL;
  82. /* PUT style GET_PARAMETERS */
  83. params = open("log/file572.txt", O_RDONLY);
  84. fstat(params, &file_info);
  85. close(params);
  86. paramsf = fopen("log/file572.txt", "rb");
  87. if(paramsf == NULL) {
  88. fprintf(stderr, "can't open log/file572.txt\n");
  89. res = TEST_ERR_MAJOR_BAD;
  90. goto test_cleanup;
  91. }
  92. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  93. test_setopt(curl, CURLOPT_READDATA, paramsf);
  94. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  95. test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
  96. res = curl_easy_perform(curl);
  97. if(res)
  98. goto test_cleanup;
  99. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  100. fclose(paramsf);
  101. paramsf = NULL;
  102. /* Heartbeat GET_PARAMETERS */
  103. if((stream_uri = suburl(URL, request++)) == NULL) {
  104. res = TEST_ERR_MAJOR_BAD;
  105. goto test_cleanup;
  106. }
  107. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  108. free(stream_uri);
  109. stream_uri = NULL;
  110. res = curl_easy_perform(curl);
  111. if(res)
  112. goto test_cleanup;
  113. /* POST GET_PARAMETERS */
  114. if((stream_uri = suburl(URL, request++)) == NULL) {
  115. res = TEST_ERR_MAJOR_BAD;
  116. goto test_cleanup;
  117. }
  118. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  119. free(stream_uri);
  120. stream_uri = NULL;
  121. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  122. test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
  123. res = curl_easy_perform(curl);
  124. if(res)
  125. goto test_cleanup;
  126. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  127. /* Make sure we can do a normal request now */
  128. if((stream_uri = suburl(URL, request++)) == NULL) {
  129. res = TEST_ERR_MAJOR_BAD;
  130. goto test_cleanup;
  131. }
  132. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  133. free(stream_uri);
  134. stream_uri = NULL;
  135. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  136. res = curl_easy_perform(curl);
  137. test_cleanup:
  138. if(paramsf)
  139. fclose(paramsf);
  140. if(stream_uri)
  141. free(stream_uri);
  142. if(custom_headers)
  143. curl_slist_free_all(custom_headers);
  144. curl_easy_cleanup(curl);
  145. curl_global_cleanup();
  146. return res;
  147. }