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.

76 lines
2.3KB

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