lib572.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, 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 https://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 "memdebug.h"
  30. /* build request url */
  31. static char *suburl(const char *base, int i)
  32. {
  33. return curl_maprintf("%s%.4d", base, i);
  34. }
  35. /*
  36. * Test GET_PARAMETER: PUT, HEARTBEAT, and POST
  37. */
  38. int test(char *URL)
  39. {
  40. int res;
  41. CURL *curl;
  42. int params;
  43. FILE *paramsf = NULL;
  44. struct_stat file_info;
  45. char *stream_uri = NULL;
  46. int request=1;
  47. struct curl_slist *custom_headers=NULL;
  48. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  49. fprintf(stderr, "curl_global_init() failed\n");
  50. return TEST_ERR_MAJOR_BAD;
  51. }
  52. curl = curl_easy_init();
  53. if(!curl) {
  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. stream_uri = suburl(URL, request++);
  64. if(!stream_uri) {
  65. res = TEST_ERR_MAJOR_BAD;
  66. goto test_cleanup;
  67. }
  68. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  69. free(stream_uri);
  70. stream_uri = NULL;
  71. test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Planes/Trains/Automobiles");
  72. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  73. res = curl_easy_perform(curl);
  74. if(res)
  75. goto test_cleanup;
  76. stream_uri = suburl(URL, request++);
  77. if(!stream_uri) {
  78. res = TEST_ERR_MAJOR_BAD;
  79. goto test_cleanup;
  80. }
  81. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  82. free(stream_uri);
  83. stream_uri = NULL;
  84. /* PUT style GET_PARAMETERS */
  85. params = open("log/file572.txt", O_RDONLY);
  86. fstat(params, &file_info);
  87. close(params);
  88. paramsf = fopen("log/file572.txt", "rb");
  89. if(paramsf == NULL) {
  90. fprintf(stderr, "can't open log/file572.txt\n");
  91. res = TEST_ERR_MAJOR_BAD;
  92. goto test_cleanup;
  93. }
  94. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  95. test_setopt(curl, CURLOPT_READDATA, paramsf);
  96. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  97. test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
  98. res = curl_easy_perform(curl);
  99. if(res)
  100. goto test_cleanup;
  101. test_setopt(curl, CURLOPT_UPLOAD, 0L);
  102. fclose(paramsf);
  103. paramsf = NULL;
  104. /* Heartbeat GET_PARAMETERS */
  105. stream_uri = suburl(URL, request++);
  106. if(!stream_uri) {
  107. res = TEST_ERR_MAJOR_BAD;
  108. goto test_cleanup;
  109. }
  110. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  111. free(stream_uri);
  112. stream_uri = NULL;
  113. res = curl_easy_perform(curl);
  114. if(res)
  115. goto test_cleanup;
  116. /* POST GET_PARAMETERS */
  117. stream_uri = suburl(URL, request++);
  118. if(!stream_uri) {
  119. res = TEST_ERR_MAJOR_BAD;
  120. goto test_cleanup;
  121. }
  122. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  123. free(stream_uri);
  124. stream_uri = NULL;
  125. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_GET_PARAMETER);
  126. test_setopt(curl, CURLOPT_POSTFIELDS, "packets_received\njitter\n");
  127. res = curl_easy_perform(curl);
  128. if(res)
  129. goto test_cleanup;
  130. test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  131. /* Make sure we can do a normal request now */
  132. stream_uri = suburl(URL, request++);
  133. if(!stream_uri) {
  134. res = TEST_ERR_MAJOR_BAD;
  135. goto test_cleanup;
  136. }
  137. test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
  138. free(stream_uri);
  139. stream_uri = NULL;
  140. test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  141. res = curl_easy_perform(curl);
  142. test_cleanup:
  143. if(paramsf)
  144. fclose(paramsf);
  145. free(stream_uri);
  146. if(custom_headers)
  147. curl_slist_free_all(custom_headers);
  148. curl_easy_cleanup(curl);
  149. curl_global_cleanup();
  150. return res;
  151. }