You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 line
2.3KB

  1. /*
  2. S->C:
  3. GET_PARAMETER rtsp://example.com/fizzle/foo RTSP/1.0
  4. CSeq: 431
  5. Content-Type: text/parameters
  6. Session: 12345678
  7. Content-Length: 15
  8. packets_received
  9. jitter
  10. C->S:
  11. RTSP/1.0 200 OK
  12. CSeq: 431
  13. Content-Length: 46
  14. Content-Type: text/parameters
  15. packets_received: 10
  16. jitter: 0.3838
  17. */
  18. #include "rtsp-client-internal.h"
  19. #include <assert.h>
  20. static const char* sc_format =
  21. "GET_PARAMETER %s RTSP/1.0\r\n"
  22. "CSeq: %u\r\n"
  23. "%s" // Session: %s\r\n
  24. "%s" // Authorization: Digest xxx
  25. "User-Agent: %s\r\n"
  26. "Content-Type: text/parameters\r\n"
  27. "Content-Length: %u\r\n"
  28. "\r\n"
  29. "%s";
  30. int rtsp_client_get_parameter(struct rtsp_client_t *rtsp, int media, const char* parameter)
  31. {
  32. int r;
  33. char session[128];
  34. rtsp->state = RTSP_GET_PARAMETER;
  35. parameter = parameter ? parameter : "";
  36. if (media < rtsp->media_count && rtsp->media[media].uri[0] && rtsp->session[media].session[0])
  37. {
  38. r = snprintf(session, sizeof(session), "Session: %s\r\n", rtsp->session[media].session);
  39. if (r < 12 || r >= sizeof(session)) session[0] = '\0';
  40. r = rtsp_client_authenrization(rtsp, "GET_PARAMETER", rtsp->media[media].uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization));
  41. r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->media[media].uri, rtsp->cseq++, session, rtsp->authenrization, USER_AGENT, strlen(parameter), parameter);
  42. return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->media[media].uri, rtsp->req, r)) ? 0 : -1;
  43. }
  44. else
  45. {
  46. r = rtsp_client_authenrization(rtsp, "GET_PARAMETER", rtsp->aggregate_uri[0] ? rtsp->aggregate_uri : rtsp->uri, NULL, 0, rtsp->authenrization, sizeof(rtsp->authenrization));
  47. r = snprintf(rtsp->req, sizeof(rtsp->req), sc_format, rtsp->aggregate_uri[0] ? rtsp->aggregate_uri : rtsp->uri, rtsp->cseq++, "", rtsp->authenrization, USER_AGENT, strlen(parameter), parameter);
  48. return (r > 0 && r < sizeof(rtsp->req) && r == rtsp->handler.send(rtsp->param, rtsp->uri, rtsp->req, r)) ? 0 : -1;
  49. }
  50. }
  51. int rtsp_client_get_parameter_onreply(struct rtsp_client_t* rtsp, void* parser)
  52. {
  53. int code;
  54. const void* content;
  55. assert(RTSP_GET_PARAMETER == rtsp->state);
  56. code = http_get_status_code(parser);
  57. if (200 == code)
  58. {
  59. content = http_get_content(parser);
  60. (void)content; // TODO: callback(content)
  61. return 0; // next step
  62. }
  63. else
  64. {
  65. return -1;
  66. }
  67. }