示例#1
0
文件: rtsp.c 项目: Memphiz/tvheadend
/*
 * Utils
 */
int
rtsp_send( http_client_t *hc, http_cmd_t cmd,
           const char *path, const char *query,
           http_arg_list_t *hdr )
{
  http_arg_list_t h;
  size_t blen = 7 + strlen(hc->hc_host) +
                (hc->hc_port != 554 ? 7 : 0) +
                (path ? strlen(path) : 1) + 1;
  char *buf = alloca(blen);
  char buf2[7];

  if (hc->hc_rtsp_session) {
    if (hdr == NULL) {
      hdr = &h;
      http_arg_init(&h);
    }
    http_arg_set(hdr, "Session", hc->hc_rtsp_session);
  }
  http_client_basic_auth(hc, hdr, hc->hc_rtsp_user, hc->hc_rtsp_pass);
  if (hc->hc_port != 554)
    snprintf(buf2, sizeof(buf2), ":%d", hc->hc_port);
  else
    buf2[0] = '\0';
  snprintf(buf, blen, "rtsp://%s%s%s", hc->hc_host, buf2, path ? path : "/");
  return http_client_send(hc, cmd, buf, query, hdr, NULL, 0);
}
示例#2
0
文件: rtsp.c 项目: Leyorus/tvheadend
/*
 * Utils
 */
int
rtsp_send_ext( http_client_t *hc, http_cmd_t cmd,
           const char *path, const char *query,
           http_arg_list_t *hdr,
           const char *body, size_t size )
{
  http_arg_list_t h;
  size_t blen = 7 + strlen(hc->hc_host) +
                (hc->hc_port != 554 ? 7 : 0) +
                (path ? strlen(path) : 1) + 1;
  char *buf = alloca(blen);
  char buf2[7];
  char buf_body[size + 3];

  if (hc->hc_rtsp_session) {
    if (hdr == NULL) {
      hdr = &h;
      http_arg_init(&h);
    }
    http_arg_set(hdr, "Session", hc->hc_rtsp_session);
  }

  if (size > 0) {
    if (hdr == NULL) {
      hdr = &h;
      http_arg_init(&h);
    }
    strncpy(buf_body, body, sizeof(buf_body));
    strncat(buf_body, "\r\n", 2);
    snprintf(buf2, sizeof(buf2), "%"PRIu64, (uint64_t)(size + 2));
    http_arg_set(hdr, "Content-Length", buf2);
  }

  http_client_basic_auth(hc, hdr, hc->hc_rtsp_user, hc->hc_rtsp_pass);
  if (hc->hc_port != 554)
    snprintf(buf2, sizeof(buf2), ":%d", hc->hc_port);
  else
    buf2[0] = '\0';
  snprintf(buf, blen, "rtsp://%s%s%s", hc->hc_host, buf2, path ? path : "/");
  if(size > 0)
    return http_client_send(hc, cmd, buf, query, hdr, buf_body, size + 2);
  else
    return http_client_send(hc, cmd, buf, query, hdr, NULL, 0);
}