2010-01-21 21:58:30 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-04-29 21:46:40 +08:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2010-01-21 21:58:30 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 07:19:02 +08:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2010-01-21 21:58:30 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
#ifndef CURL_DISABLE_RTSP
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
2010-01-21 21:58:30 +08:00
|
|
|
#include <curl/curl.h>
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "transfer.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "http.h"
|
|
|
|
#include "url.h"
|
|
|
|
#include "progress.h"
|
|
|
|
#include "rtsp.h"
|
2016-10-01 00:54:02 +08:00
|
|
|
#include "strcase.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "select.h"
|
|
|
|
#include "connect.h"
|
2016-11-07 17:55:25 +08:00
|
|
|
#include "strdup.h"
|
2016-04-29 21:46:40 +08:00
|
|
|
/* The last 3 #include files should be in this order */
|
2015-03-03 19:36:18 +08:00
|
|
|
#include "curl_printf.h"
|
2015-03-25 06:12:03 +08:00
|
|
|
#include "curl_memory.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h"
|
2010-01-21 21:58:30 +08:00
|
|
|
|
2015-11-24 16:32:42 +08:00
|
|
|
/*
|
|
|
|
* TODO (general)
|
|
|
|
* -incoming server requests
|
|
|
|
* -server CSeq counter
|
|
|
|
* -digest authentication
|
|
|
|
* -connect thru proxy
|
|
|
|
* -pipelining?
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-02-03 14:49:27 +08:00
|
|
|
#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
|
|
|
|
|
|
|
|
#define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
|
|
|
|
((int)((unsigned char)((p)[3]))))
|
|
|
|
|
2011-05-05 22:53:05 +08:00
|
|
|
/* protocol-specific functions set up to be called by the main engine */
|
|
|
|
static CURLcode rtsp_do(struct connectdata *conn, bool *done);
|
|
|
|
static CURLcode rtsp_done(struct connectdata *conn, CURLcode, bool premature);
|
|
|
|
static CURLcode rtsp_connect(struct connectdata *conn, bool *done);
|
|
|
|
static CURLcode rtsp_disconnect(struct connectdata *conn, bool dead);
|
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
static int rtsp_getsock_do(struct connectdata *conn,
|
|
|
|
curl_socket_t *socks,
|
|
|
|
int numsocks);
|
|
|
|
|
2011-05-05 22:27:03 +08:00
|
|
|
/*
|
|
|
|
* Parse and write out any available RTP data.
|
|
|
|
*
|
|
|
|
* nread: amount of data left after k->str. will be modified if RTP
|
|
|
|
* data is parsed and k->str is moved up
|
|
|
|
* readmore: whether or not the RTP parser needs more data right away
|
|
|
|
*/
|
2016-06-21 21:47:12 +08:00
|
|
|
static CURLcode rtsp_rtp_readwrite(struct Curl_easy *data,
|
2011-05-05 22:27:03 +08:00
|
|
|
struct connectdata *conn,
|
|
|
|
ssize_t *nread,
|
|
|
|
bool *readmore);
|
|
|
|
|
2013-08-05 01:34:16 +08:00
|
|
|
static CURLcode rtsp_setup_connection(struct connectdata *conn);
|
|
|
|
|
2011-05-05 22:27:03 +08:00
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
/* this returns the socket to wait for in the DO and DOING state for the multi
|
|
|
|
interface and then we're always _sending_ a request and thus we wait for
|
|
|
|
the single socket to become writable only */
|
|
|
|
static int rtsp_getsock_do(struct connectdata *conn,
|
|
|
|
curl_socket_t *socks,
|
|
|
|
int numsocks)
|
|
|
|
{
|
|
|
|
/* write mode */
|
|
|
|
(void)numsocks; /* unused, we trust it to be at least 1 */
|
|
|
|
socks[0] = conn->sock[FIRSTSOCKET];
|
|
|
|
return GETSOCK_WRITESOCK(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CURLcode rtp_client_write(struct connectdata *conn, char *ptr, size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RTSP handler interface.
|
|
|
|
*/
|
|
|
|
const struct Curl_handler Curl_handler_rtsp = {
|
|
|
|
"RTSP", /* scheme */
|
2013-08-05 01:34:16 +08:00
|
|
|
rtsp_setup_connection, /* setup_connection */
|
2011-05-05 22:53:05 +08:00
|
|
|
rtsp_do, /* do_it */
|
|
|
|
rtsp_done, /* done */
|
2010-01-21 21:58:30 +08:00
|
|
|
ZERO_NULL, /* do_more */
|
2011-05-05 22:53:05 +08:00
|
|
|
rtsp_connect, /* connect_it */
|
2010-01-21 21:58:30 +08:00
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
rtsp_getsock_do, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-01-21 21:58:30 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
2011-05-05 22:53:05 +08:00
|
|
|
rtsp_disconnect, /* disconnect */
|
2011-05-05 22:27:03 +08:00
|
|
|
rtsp_rtp_readwrite, /* readwrite */
|
2010-01-21 21:58:30 +08:00
|
|
|
PORT_RTSP, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTSP, /* protocol */
|
2011-03-15 05:22:22 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-01-21 21:58:30 +08:00
|
|
|
};
|
|
|
|
|
2013-08-05 01:34:16 +08:00
|
|
|
|
|
|
|
static CURLcode rtsp_setup_connection(struct connectdata *conn)
|
|
|
|
{
|
|
|
|
struct RTSP *rtsp;
|
|
|
|
|
2013-08-05 16:32:08 +08:00
|
|
|
conn->data->req.protop = rtsp = calloc(1, sizeof(struct RTSP));
|
2013-08-05 01:34:16 +08:00
|
|
|
if(!rtsp)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-24 00:27:58 +08:00
|
|
|
/*
|
|
|
|
* The server may send us RTP data at any point, and RTSPREQ_RECEIVE does not
|
|
|
|
* want to block the application forever while receiving a stream. Therefore,
|
|
|
|
* we cannot assume that an RTSP socket is dead just because it is readable.
|
|
|
|
*
|
2016-12-07 06:39:08 +08:00
|
|
|
* Instead, if it is readable, run Curl_connalive() to peek at the socket
|
2011-03-24 00:27:58 +08:00
|
|
|
* and distinguish between closed and data.
|
|
|
|
*/
|
|
|
|
bool Curl_rtsp_connisdead(struct connectdata *check)
|
|
|
|
{
|
|
|
|
int sval;
|
|
|
|
bool ret_val = TRUE;
|
|
|
|
|
2016-10-18 16:58:58 +08:00
|
|
|
sval = SOCKET_READABLE(check->sock[FIRSTSOCKET], 0);
|
2011-03-24 00:27:58 +08:00
|
|
|
if(sval == 0) {
|
|
|
|
/* timeout */
|
|
|
|
ret_val = FALSE;
|
|
|
|
}
|
2011-04-20 21:17:42 +08:00
|
|
|
else if(sval & CURL_CSELECT_ERR) {
|
2011-03-24 00:27:58 +08:00
|
|
|
/* socket is in an error state */
|
|
|
|
ret_val = TRUE;
|
|
|
|
}
|
2016-12-07 06:39:08 +08:00
|
|
|
else if(sval & CURL_CSELECT_IN) {
|
|
|
|
/* readable with no error. could still be closed */
|
|
|
|
ret_val = !Curl_connalive(check);
|
2011-03-24 00:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
2011-05-05 22:53:05 +08:00
|
|
|
static CURLcode rtsp_connect(struct connectdata *conn, bool *done)
|
2010-01-21 21:58:30 +08:00
|
|
|
{
|
|
|
|
CURLcode httpStatus;
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
httpStatus = Curl_http_connect(conn, done);
|
|
|
|
|
|
|
|
/* Initialize the CSeq if not already done */
|
|
|
|
if(data->state.rtsp_next_client_CSeq == 0)
|
|
|
|
data->state.rtsp_next_client_CSeq = 1;
|
|
|
|
if(data->state.rtsp_next_server_CSeq == 0)
|
|
|
|
data->state.rtsp_next_server_CSeq = 1;
|
|
|
|
|
|
|
|
conn->proto.rtspc.rtp_channel = -1;
|
|
|
|
|
|
|
|
return httpStatus;
|
|
|
|
}
|
|
|
|
|
2011-05-05 22:53:05 +08:00
|
|
|
static CURLcode rtsp_disconnect(struct connectdata *conn, bool dead)
|
2010-11-19 20:43:20 +08:00
|
|
|
{
|
2011-05-05 22:53:05 +08:00
|
|
|
(void) dead;
|
2010-01-21 21:58:30 +08:00
|
|
|
Curl_safefree(conn->proto.rtspc.rtp_buf);
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 22:53:05 +08:00
|
|
|
static CURLcode rtsp_done(struct connectdata *conn,
|
|
|
|
CURLcode status, bool premature)
|
2010-01-21 21:58:30 +08:00
|
|
|
{
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy *data = conn->data;
|
2013-08-05 16:32:08 +08:00
|
|
|
struct RTSP *rtsp = data->req.protop;
|
2010-02-06 21:21:45 +08:00
|
|
|
CURLcode httpStatus;
|
2010-01-21 21:58:30 +08:00
|
|
|
long CSeq_sent;
|
|
|
|
long CSeq_recv;
|
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
/* Bypass HTTP empty-reply checks on receive */
|
|
|
|
if(data->set.rtspreq == RTSPREQ_RECEIVE)
|
|
|
|
premature = TRUE;
|
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
httpStatus = Curl_http_done(conn, status, premature);
|
|
|
|
|
2010-02-06 21:21:45 +08:00
|
|
|
if(rtsp) {
|
|
|
|
/* Check the sequence numbers */
|
|
|
|
CSeq_sent = rtsp->CSeq_sent;
|
|
|
|
CSeq_recv = rtsp->CSeq_recv;
|
|
|
|
if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) {
|
2011-04-20 21:17:42 +08:00
|
|
|
failf(data,
|
|
|
|
"The CSeq of this request %ld did not match the response %ld",
|
2010-02-06 21:21:45 +08:00
|
|
|
CSeq_sent, CSeq_recv);
|
|
|
|
return CURLE_RTSP_CSEQ_ERROR;
|
|
|
|
}
|
|
|
|
else if(data->set.rtspreq == RTSPREQ_RECEIVE &&
|
|
|
|
(conn->proto.rtspc.rtp_channel == -1)) {
|
|
|
|
infof(data, "Got an RTP Receive with a CSeq of %ld\n", CSeq_recv);
|
2015-11-24 16:32:42 +08:00
|
|
|
/* TODO CPC: Server -> Client logic here */
|
2010-02-06 21:21:45 +08:00
|
|
|
}
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return httpStatus;
|
|
|
|
}
|
|
|
|
|
2011-05-05 22:53:05 +08:00
|
|
|
static CURLcode rtsp_do(struct connectdata *conn, bool *done)
|
2010-01-21 21:58:30 +08:00
|
|
|
{
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-01-21 21:58:30 +08:00
|
|
|
CURLcode result=CURLE_OK;
|
|
|
|
Curl_RtspReq rtspreq = data->set.rtspreq;
|
2013-08-05 16:32:08 +08:00
|
|
|
struct RTSP *rtsp = data->req.protop;
|
2010-01-21 21:58:30 +08:00
|
|
|
struct HTTP *http;
|
|
|
|
Curl_send_buffer *req_buffer;
|
|
|
|
curl_off_t postsize = 0; /* for ANNOUNCE and SET_PARAMETER */
|
|
|
|
curl_off_t putsize = 0; /* for ANNOUNCE and SET_PARAMETER */
|
|
|
|
|
|
|
|
const char *p_request = NULL;
|
|
|
|
const char *p_session_id = NULL;
|
|
|
|
const char *p_accept = NULL;
|
|
|
|
const char *p_accept_encoding = NULL;
|
|
|
|
const char *p_range = NULL;
|
|
|
|
const char *p_referrer = NULL;
|
|
|
|
const char *p_stream_uri = NULL;
|
|
|
|
const char *p_transport = NULL;
|
|
|
|
const char *p_uagent = NULL;
|
2015-08-21 05:02:28 +08:00
|
|
|
const char *p_proxyuserpwd = NULL;
|
|
|
|
const char *p_userpwd = NULL;
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
http = &(rtsp->http_wrapper);
|
|
|
|
/* Assert that no one has changed the RTSP struct in an evil way */
|
|
|
|
DEBUGASSERT((void *)http == (void *)rtsp);
|
|
|
|
|
|
|
|
rtsp->CSeq_sent = data->state.rtsp_next_client_CSeq;
|
|
|
|
rtsp->CSeq_recv = 0;
|
|
|
|
|
|
|
|
/* Setup the 'p_request' pointer to the proper p_request string
|
|
|
|
* Since all RTSP requests are included here, there is no need to
|
|
|
|
* support custom requests like HTTP.
|
|
|
|
**/
|
|
|
|
data->set.opt_no_body = TRUE; /* most requests don't contain a body */
|
|
|
|
switch(rtspreq) {
|
2015-05-22 22:32:42 +08:00
|
|
|
default:
|
|
|
|
failf(data, "Got invalid RTSP request");
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
case RTSPREQ_OPTIONS:
|
|
|
|
p_request = "OPTIONS";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_DESCRIBE:
|
|
|
|
p_request = "DESCRIBE";
|
|
|
|
data->set.opt_no_body = FALSE;
|
|
|
|
break;
|
|
|
|
case RTSPREQ_ANNOUNCE:
|
|
|
|
p_request = "ANNOUNCE";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_SETUP:
|
|
|
|
p_request = "SETUP";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_PLAY:
|
|
|
|
p_request = "PLAY";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_PAUSE:
|
|
|
|
p_request = "PAUSE";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_TEARDOWN:
|
|
|
|
p_request = "TEARDOWN";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_GET_PARAMETER:
|
2010-03-24 13:35:03 +08:00
|
|
|
/* GET_PARAMETER's no_body status is determined later */
|
2010-01-21 21:58:30 +08:00
|
|
|
p_request = "GET_PARAMETER";
|
2011-08-15 01:07:54 +08:00
|
|
|
data->set.opt_no_body = FALSE;
|
2010-01-21 21:58:30 +08:00
|
|
|
break;
|
|
|
|
case RTSPREQ_SET_PARAMETER:
|
|
|
|
p_request = "SET_PARAMETER";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_RECORD:
|
|
|
|
p_request = "RECORD";
|
|
|
|
break;
|
|
|
|
case RTSPREQ_RECEIVE:
|
|
|
|
p_request = "";
|
|
|
|
/* Treat interleaved RTP as body*/
|
|
|
|
data->set.opt_no_body = FALSE;
|
|
|
|
break;
|
|
|
|
case RTSPREQ_LAST:
|
|
|
|
failf(data, "Got invalid RTSP request: RTSPREQ_LAST");
|
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rtspreq == RTSPREQ_RECEIVE) {
|
2010-04-17 05:43:04 +08:00
|
|
|
Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
|
|
|
|
&http->readbytecount, -1, NULL);
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_session_id = data->set.str[STRING_RTSP_SESSION_ID];
|
|
|
|
if(!p_session_id &&
|
|
|
|
(rtspreq & ~(RTSPREQ_OPTIONS | RTSPREQ_DESCRIBE | RTSPREQ_SETUP))) {
|
|
|
|
failf(data, "Refusing to issue an RTSP request [%s] without a session ID.",
|
2015-06-15 15:05:07 +08:00
|
|
|
p_request);
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:32:42 +08:00
|
|
|
/* TODO: proxy? */
|
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
/* Stream URI. Default to server '*' if not specified */
|
|
|
|
if(data->set.str[STRING_RTSP_STREAM_URI]) {
|
|
|
|
p_stream_uri = data->set.str[STRING_RTSP_STREAM_URI];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p_stream_uri = "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transport Header for SETUP requests */
|
2014-01-31 15:10:07 +08:00
|
|
|
p_transport = Curl_checkheaders(conn, "Transport:");
|
2010-01-21 21:58:30 +08:00
|
|
|
if(rtspreq == RTSPREQ_SETUP && !p_transport) {
|
|
|
|
/* New Transport: setting? */
|
|
|
|
if(data->set.str[STRING_RTSP_TRANSPORT]) {
|
|
|
|
Curl_safefree(conn->allocptr.rtsp_transport);
|
|
|
|
|
|
|
|
conn->allocptr.rtsp_transport =
|
|
|
|
aprintf("Transport: %s\r\n",
|
|
|
|
data->set.str[STRING_RTSP_TRANSPORT]);
|
|
|
|
if(!conn->allocptr.rtsp_transport)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data,
|
|
|
|
"Refusing to issue an RTSP SETUP without a Transport: header.");
|
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_transport = conn->allocptr.rtsp_transport;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Accept Headers for DESCRIBE requests */
|
|
|
|
if(rtspreq == RTSPREQ_DESCRIBE) {
|
|
|
|
/* Accept Header */
|
2014-01-31 15:10:07 +08:00
|
|
|
p_accept = Curl_checkheaders(conn, "Accept:")?
|
2010-01-21 21:58:30 +08:00
|
|
|
NULL:"Accept: application/sdp\r\n";
|
|
|
|
|
|
|
|
/* Accept-Encoding header */
|
2014-01-31 15:10:07 +08:00
|
|
|
if(!Curl_checkheaders(conn, "Accept-Encoding:") &&
|
2010-01-21 21:58:30 +08:00
|
|
|
data->set.str[STRING_ENCODING]) {
|
|
|
|
Curl_safefree(conn->allocptr.accept_encoding);
|
|
|
|
conn->allocptr.accept_encoding =
|
|
|
|
aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
|
|
|
|
|
|
|
|
if(!conn->allocptr.accept_encoding)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
p_accept_encoding = conn->allocptr.accept_encoding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
/* The User-Agent string might have been allocated in url.c already, because
|
|
|
|
it might have been used in the proxy connect, but if we have got a header
|
|
|
|
with the user-agent string specified, we erase the previously made string
|
|
|
|
here. */
|
2014-01-31 15:10:07 +08:00
|
|
|
if(Curl_checkheaders(conn, "User-Agent:") && conn->allocptr.uagent) {
|
2010-01-21 21:58:30 +08:00
|
|
|
Curl_safefree(conn->allocptr.uagent);
|
|
|
|
conn->allocptr.uagent = NULL;
|
|
|
|
}
|
2014-01-31 15:10:07 +08:00
|
|
|
else if(!Curl_checkheaders(conn, "User-Agent:") &&
|
2010-01-21 21:58:30 +08:00
|
|
|
data->set.str[STRING_USERAGENT]) {
|
|
|
|
p_uagent = conn->allocptr.uagent;
|
|
|
|
}
|
|
|
|
|
2015-08-21 05:02:28 +08:00
|
|
|
/* setup the authentication headers */
|
|
|
|
result = Curl_http_output_auth(conn, p_request, p_stream_uri, FALSE);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
p_proxyuserpwd = conn->allocptr.proxyuserpwd;
|
|
|
|
p_userpwd = conn->allocptr.userpwd;
|
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
/* Referrer */
|
|
|
|
Curl_safefree(conn->allocptr.ref);
|
2014-01-31 15:10:07 +08:00
|
|
|
if(data->change.referer && !Curl_checkheaders(conn, "Referer:"))
|
2010-01-21 21:58:30 +08:00
|
|
|
conn->allocptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
|
|
|
|
else
|
|
|
|
conn->allocptr.ref = NULL;
|
|
|
|
|
|
|
|
p_referrer = conn->allocptr.ref;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range Header
|
|
|
|
* Only applies to PLAY, PAUSE, RECORD
|
|
|
|
*
|
|
|
|
* Go ahead and use the Range stuff supplied for HTTP
|
|
|
|
*/
|
|
|
|
if(data->state.use_range &&
|
|
|
|
(rtspreq & (RTSPREQ_PLAY | RTSPREQ_PAUSE | RTSPREQ_RECORD))) {
|
|
|
|
|
|
|
|
/* Check to see if there is a range set in the custom headers */
|
2014-01-31 15:10:07 +08:00
|
|
|
if(!Curl_checkheaders(conn, "Range:") && data->state.range) {
|
2010-01-21 21:58:30 +08:00
|
|
|
Curl_safefree(conn->allocptr.rangeline);
|
|
|
|
conn->allocptr.rangeline = aprintf("Range: %s\r\n", data->state.range);
|
|
|
|
p_range = conn->allocptr.rangeline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check the custom headers
|
|
|
|
*/
|
2014-01-31 15:10:07 +08:00
|
|
|
if(Curl_checkheaders(conn, "CSeq:")) {
|
2010-01-21 21:58:30 +08:00
|
|
|
failf(data, "CSeq cannot be set as a custom header.");
|
|
|
|
return CURLE_RTSP_CSEQ_ERROR;
|
|
|
|
}
|
2014-01-31 15:10:07 +08:00
|
|
|
if(Curl_checkheaders(conn, "Session:")) {
|
2010-01-21 21:58:30 +08:00
|
|
|
failf(data, "Session ID cannot be set as a custom header.");
|
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize a dynamic send buffer */
|
|
|
|
req_buffer = Curl_add_buffer_init();
|
|
|
|
|
|
|
|
if(!req_buffer)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
result =
|
|
|
|
Curl_add_bufferf(req_buffer,
|
|
|
|
"%s %s RTSP/1.0\r\n" /* Request Stream-URI RTSP/1.0 */
|
2010-01-28 23:34:18 +08:00
|
|
|
"CSeq: %ld\r\n", /* CSeq */
|
2015-06-18 20:29:57 +08:00
|
|
|
p_request, p_stream_uri, rtsp->CSeq_sent);
|
2010-01-21 21:58:30 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rather than do a normal alloc line, keep the session_id unformatted
|
|
|
|
* to make comparison easier
|
|
|
|
*/
|
|
|
|
if(p_session_id) {
|
2010-01-28 09:39:16 +08:00
|
|
|
result = Curl_add_bufferf(req_buffer, "Session: %s\r\n", p_session_id);
|
2010-01-21 21:58:30 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shared HTTP-like options
|
|
|
|
*/
|
|
|
|
result = Curl_add_bufferf(req_buffer,
|
|
|
|
"%s" /* transport */
|
|
|
|
"%s" /* accept */
|
|
|
|
"%s" /* accept-encoding */
|
|
|
|
"%s" /* range */
|
|
|
|
"%s" /* referrer */
|
|
|
|
"%s" /* user-agent */
|
2015-08-21 05:02:28 +08:00
|
|
|
"%s" /* proxyuserpwd */
|
|
|
|
"%s" /* userpwd */
|
2010-01-21 21:58:30 +08:00
|
|
|
,
|
|
|
|
p_transport ? p_transport : "",
|
|
|
|
p_accept ? p_accept : "",
|
|
|
|
p_accept_encoding ? p_accept_encoding : "",
|
|
|
|
p_range ? p_range : "",
|
|
|
|
p_referrer ? p_referrer : "",
|
2015-08-21 05:02:28 +08:00
|
|
|
p_uagent ? p_uagent : "",
|
|
|
|
p_proxyuserpwd ? p_proxyuserpwd : "",
|
|
|
|
p_userpwd ? p_userpwd : "");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free userpwd now --- cannot reuse this for Negotiate and possibly NTLM
|
|
|
|
* with basic and digest, it will be freed anyway by the next request
|
|
|
|
*/
|
2016-12-14 06:34:59 +08:00
|
|
|
Curl_safefree(conn->allocptr.userpwd);
|
2015-08-21 05:02:28 +08:00
|
|
|
conn->allocptr.userpwd = NULL;
|
|
|
|
|
2010-02-06 21:21:45 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
if((rtspreq == RTSPREQ_SETUP) || (rtspreq == RTSPREQ_DESCRIBE)) {
|
|
|
|
result = Curl_add_timecondition(data, req_buffer);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-31 15:10:07 +08:00
|
|
|
result = Curl_add_custom_headers(conn, FALSE, req_buffer);
|
2010-01-21 21:58:30 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2010-03-24 13:35:03 +08:00
|
|
|
if(rtspreq == RTSPREQ_ANNOUNCE ||
|
|
|
|
rtspreq == RTSPREQ_SET_PARAMETER ||
|
|
|
|
rtspreq == RTSPREQ_GET_PARAMETER) {
|
|
|
|
|
2010-01-21 21:58:30 +08:00
|
|
|
if(data->set.upload) {
|
2014-04-15 19:49:18 +08:00
|
|
|
putsize = data->state.infilesize;
|
2010-01-21 21:58:30 +08:00
|
|
|
data->set.httpreq = HTTPREQ_PUT;
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2015-06-08 05:52:34 +08:00
|
|
|
postsize = (data->state.infilesize != -1)?
|
|
|
|
data->state.infilesize:
|
2010-01-21 21:58:30 +08:00
|
|
|
(data->set.postfields? (curl_off_t)strlen(data->set.postfields):0);
|
|
|
|
data->set.httpreq = HTTPREQ_POST;
|
|
|
|
}
|
|
|
|
|
2010-03-24 13:35:03 +08:00
|
|
|
if(putsize > 0 || postsize > 0) {
|
|
|
|
/* As stated in the http comments, it is probably not wise to
|
|
|
|
* actually set a custom Content-Length in the headers */
|
2014-01-31 15:10:07 +08:00
|
|
|
if(!Curl_checkheaders(conn, "Content-Length:")) {
|
2010-01-21 21:58:30 +08:00
|
|
|
result = Curl_add_bufferf(req_buffer,
|
2013-12-31 19:10:25 +08:00
|
|
|
"Content-Length: %" CURL_FORMAT_CURL_OFF_T"\r\n",
|
2010-03-24 13:35:03 +08:00
|
|
|
(data->set.upload ? putsize : postsize));
|
2010-02-07 01:30:06 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
2010-03-24 13:35:03 +08:00
|
|
|
if(rtspreq == RTSPREQ_SET_PARAMETER ||
|
|
|
|
rtspreq == RTSPREQ_GET_PARAMETER) {
|
2014-01-31 15:10:07 +08:00
|
|
|
if(!Curl_checkheaders(conn, "Content-Type:")) {
|
2010-03-24 13:35:03 +08:00
|
|
|
result = Curl_add_bufferf(req_buffer,
|
|
|
|
"Content-Type: text/parameters\r\n");
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rtspreq == RTSPREQ_ANNOUNCE) {
|
2014-01-31 15:10:07 +08:00
|
|
|
if(!Curl_checkheaders(conn, "Content-Type:")) {
|
2010-03-24 13:35:03 +08:00
|
|
|
result = Curl_add_bufferf(req_buffer,
|
|
|
|
"Content-Type: application/sdp\r\n");
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
data->state.expect100header = FALSE; /* RTSP posts are simple/small */
|
|
|
|
}
|
|
|
|
else if(rtspreq == RTSPREQ_GET_PARAMETER) {
|
2010-03-24 13:35:03 +08:00
|
|
|
/* Check for an empty GET_PARAMETER (heartbeat) request */
|
|
|
|
data->set.httpreq = HTTPREQ_HEAD;
|
|
|
|
data->set.opt_no_body = TRUE;
|
|
|
|
}
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RTSP never allows chunked transfer */
|
|
|
|
data->req.forbidchunk = TRUE;
|
|
|
|
/* Finish the request buffer */
|
|
|
|
result = Curl_add_buffer(req_buffer, "\r\n", 2);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if(postsize > 0) {
|
|
|
|
result = Curl_add_buffer(req_buffer, data->set.postfields,
|
|
|
|
(size_t)postsize);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* issue the request */
|
|
|
|
result = Curl_add_buffer_send(req_buffer, conn,
|
|
|
|
&data->info.request_size, 0, FIRSTSOCKET);
|
|
|
|
if(result) {
|
|
|
|
failf(data, "Failed sending RTSP request");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-17 05:43:04 +08:00
|
|
|
Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, &http->readbytecount,
|
|
|
|
putsize?FIRSTSOCKET:-1,
|
|
|
|
putsize?&http->writebytecount:NULL);
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
/* Increment the CSeq on success */
|
|
|
|
data->state.rtsp_next_client_CSeq++;
|
|
|
|
|
|
|
|
if(http->writebytecount) {
|
|
|
|
/* if a request-body has been sent off, we make sure this progress is
|
|
|
|
noted properly */
|
|
|
|
Curl_pgrsSetUploadCounter(data, http->writebytecount);
|
|
|
|
if(Curl_pgrsUpdate(conn))
|
|
|
|
result = CURLE_ABORTED_BY_CALLBACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-05 22:27:03 +08:00
|
|
|
|
2016-06-21 21:47:12 +08:00
|
|
|
static CURLcode rtsp_rtp_readwrite(struct Curl_easy *data,
|
2011-05-05 22:27:03 +08:00
|
|
|
struct connectdata *conn,
|
|
|
|
ssize_t *nread,
|
|
|
|
bool *readmore) {
|
2010-01-21 21:58:30 +08:00
|
|
|
struct SingleRequest *k = &data->req;
|
|
|
|
struct rtsp_conn *rtspc = &(conn->proto.rtspc);
|
|
|
|
|
|
|
|
char *rtp; /* moving pointer to rtp data */
|
|
|
|
ssize_t rtp_dataleft; /* how much data left to parse in this round */
|
|
|
|
char *scratch;
|
|
|
|
CURLcode result;
|
|
|
|
|
|
|
|
if(rtspc->rtp_buf) {
|
|
|
|
/* There was some leftover data the last time. Merge buffers */
|
2016-11-07 17:55:25 +08:00
|
|
|
char *newptr = Curl_saferealloc(rtspc->rtp_buf,
|
|
|
|
rtspc->rtp_bufsize + *nread);
|
2010-02-03 21:28:47 +08:00
|
|
|
if(!newptr) {
|
|
|
|
rtspc->rtp_buf = NULL;
|
|
|
|
rtspc->rtp_bufsize = 0;
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2010-02-03 21:28:47 +08:00
|
|
|
}
|
|
|
|
rtspc->rtp_buf = newptr;
|
2010-01-21 21:58:30 +08:00
|
|
|
memcpy(rtspc->rtp_buf + rtspc->rtp_bufsize, k->str, *nread);
|
|
|
|
rtspc->rtp_bufsize += *nread;
|
|
|
|
rtp = rtspc->rtp_buf;
|
|
|
|
rtp_dataleft = rtspc->rtp_bufsize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Just parse the request buffer directly */
|
|
|
|
rtp = k->str;
|
|
|
|
rtp_dataleft = *nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((rtp_dataleft > 0) &&
|
|
|
|
(rtp[0] == '$')) {
|
|
|
|
if(rtp_dataleft > 4) {
|
|
|
|
int rtp_length;
|
|
|
|
|
|
|
|
/* Parse the header */
|
|
|
|
/* The channel identifier immediately follows and is 1 byte */
|
2010-02-03 14:49:27 +08:00
|
|
|
rtspc->rtp_channel = RTP_PKT_CHANNEL(rtp);
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
/* The length is two bytes */
|
2010-02-03 14:49:27 +08:00
|
|
|
rtp_length = RTP_PKT_LENGTH(rtp);
|
2010-01-21 21:58:30 +08:00
|
|
|
|
|
|
|
if(rtp_dataleft < rtp_length + 4) {
|
|
|
|
/* Need more - incomplete payload*/
|
|
|
|
*readmore = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* We have the full RTP interleaved packet
|
2010-02-02 06:13:55 +08:00
|
|
|
* Write out the header including the leading '$' */
|
2010-01-28 09:39:16 +08:00
|
|
|
DEBUGF(infof(data, "RTP write channel %d rtp_length %d\n",
|
|
|
|
rtspc->rtp_channel, rtp_length));
|
2010-02-02 06:13:55 +08:00
|
|
|
result = rtp_client_write(conn, &rtp[0], rtp_length + 4);
|
2010-01-21 21:58:30 +08:00
|
|
|
if(result) {
|
2010-01-28 09:39:16 +08:00
|
|
|
failf(data, "Got an error writing an RTP packet");
|
|
|
|
*readmore = FALSE;
|
|
|
|
Curl_safefree(rtspc->rtp_buf);
|
|
|
|
rtspc->rtp_buf = NULL;
|
|
|
|
rtspc->rtp_bufsize = 0;
|
|
|
|
return result;
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move forward in the buffer */
|
|
|
|
rtp_dataleft -= rtp_length + 4;
|
|
|
|
rtp += rtp_length + 4;
|
|
|
|
|
|
|
|
if(data->set.rtspreq == RTSPREQ_RECEIVE) {
|
|
|
|
/* If we are in a passive receive, give control back
|
|
|
|
* to the app as often as we can.
|
|
|
|
*/
|
|
|
|
k->keepon &= ~KEEP_RECV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Need more - incomplete header */
|
|
|
|
*readmore = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
if(rtp_dataleft != 0 && rtp[0] == '$') {
|
2013-07-24 22:43:13 +08:00
|
|
|
DEBUGF(infof(data, "RTP Rewinding %zd %s\n", rtp_dataleft,
|
2010-01-28 09:39:16 +08:00
|
|
|
*readmore ? "(READMORE)" : ""));
|
2010-01-21 21:58:30 +08:00
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
/* Store the incomplete RTP packet for a "rewind" */
|
|
|
|
scratch = malloc(rtp_dataleft);
|
2010-02-03 21:28:47 +08:00
|
|
|
if(!scratch) {
|
|
|
|
Curl_safefree(rtspc->rtp_buf);
|
|
|
|
rtspc->rtp_buf = NULL;
|
|
|
|
rtspc->rtp_bufsize = 0;
|
2010-01-28 09:39:16 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2010-02-03 21:28:47 +08:00
|
|
|
}
|
2010-01-28 09:39:16 +08:00
|
|
|
memcpy(scratch, rtp, rtp_dataleft);
|
|
|
|
Curl_safefree(rtspc->rtp_buf);
|
|
|
|
rtspc->rtp_buf = scratch;
|
|
|
|
rtspc->rtp_bufsize = rtp_dataleft;
|
|
|
|
|
|
|
|
/* As far as the transfer is concerned, this data is consumed */
|
|
|
|
*nread = 0;
|
|
|
|
return CURLE_OK;
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
else {
|
2010-01-28 09:39:16 +08:00
|
|
|
/* Fix up k->str to point just after the last RTP packet */
|
|
|
|
k->str += *nread - rtp_dataleft;
|
2010-01-21 21:58:30 +08:00
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
/* either all of the data has been read or...
|
|
|
|
* rtp now points at the next byte to parse
|
|
|
|
*/
|
|
|
|
if(rtp_dataleft > 0)
|
2010-01-21 21:58:30 +08:00
|
|
|
DEBUGASSERT(k->str[0] == rtp[0]);
|
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
DEBUGASSERT(rtp_dataleft <= *nread); /* sanity check */
|
2010-01-21 21:58:30 +08:00
|
|
|
|
2010-01-28 09:39:16 +08:00
|
|
|
*nread = rtp_dataleft;
|
2010-01-21 21:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, we have finished with the leftover/merge buffer */
|
|
|
|
Curl_safefree(rtspc->rtp_buf);
|
|
|
|
rtspc->rtp_buf = NULL;
|
|
|
|
rtspc->rtp_bufsize = 0;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-25 12:36:13 +08:00
|
|
|
static
|
2010-01-21 21:58:30 +08:00
|
|
|
CURLcode rtp_client_write(struct connectdata *conn, char *ptr, size_t len)
|
|
|
|
{
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-01-21 21:58:30 +08:00
|
|
|
size_t wrote;
|
|
|
|
curl_write_callback writeit;
|
|
|
|
|
|
|
|
if(len == 0) {
|
2016-12-14 06:34:59 +08:00
|
|
|
failf(data, "Cannot write a 0 size RTP packet.");
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
writeit = data->set.fwrite_rtp?data->set.fwrite_rtp:data->set.fwrite_func;
|
|
|
|
wrote = writeit(ptr, 1, len, data->set.rtp_out);
|
|
|
|
|
|
|
|
if(CURL_WRITEFUNC_PAUSE == wrote) {
|
2016-12-14 06:34:59 +08:00
|
|
|
failf(data, "Cannot pause RTP");
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(wrote != len) {
|
2016-12-14 06:34:59 +08:00
|
|
|
failf(data, "Failed writing RTP data");
|
2010-01-21 21:58:30 +08:00
|
|
|
return CURLE_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_rtsp_parseheader(struct connectdata *conn,
|
|
|
|
char *header)
|
|
|
|
{
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-01-21 21:58:30 +08:00
|
|
|
long CSeq = 0;
|
|
|
|
|
|
|
|
if(checkprefix("CSeq:", header)) {
|
|
|
|
/* Store the received CSeq. Match is verified in rtsp_done */
|
2012-06-16 04:51:45 +08:00
|
|
|
int nc = sscanf(&header[4], ": %ld", &CSeq);
|
2010-01-21 21:58:30 +08:00
|
|
|
if(nc == 1) {
|
2013-08-05 16:32:08 +08:00
|
|
|
struct RTSP *rtsp = data->req.protop;
|
|
|
|
rtsp->CSeq_recv = CSeq; /* mark the request */
|
2010-01-21 21:58:30 +08:00
|
|
|
data->state.rtsp_CSeq_recv = CSeq; /* update the handle */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "Unable to read the CSeq header: [%s]", header);
|
|
|
|
return CURLE_RTSP_CSEQ_ERROR;
|
|
|
|
}
|
2010-01-28 09:39:16 +08:00
|
|
|
}
|
2010-01-21 21:58:30 +08:00
|
|
|
else if(checkprefix("Session:", header)) {
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
/* Find the first non-space letter */
|
2014-03-20 18:52:27 +08:00
|
|
|
start = header + 8;
|
2010-09-06 22:03:37 +08:00
|
|
|
while(*start && ISSPACE(*start))
|
2010-01-21 21:58:30 +08:00
|
|
|
start++;
|
|
|
|
|
2010-09-06 22:03:37 +08:00
|
|
|
if(!*start) {
|
2010-01-21 21:58:30 +08:00
|
|
|
failf(data, "Got a blank Session ID");
|
|
|
|
}
|
|
|
|
else if(data->set.str[STRING_RTSP_SESSION_ID]) {
|
|
|
|
/* If the Session ID is set, then compare */
|
|
|
|
if(strncmp(start, data->set.str[STRING_RTSP_SESSION_ID],
|
|
|
|
strlen(data->set.str[STRING_RTSP_SESSION_ID])) != 0) {
|
|
|
|
failf(data, "Got RTSP Session ID Line [%s], but wanted ID [%s]",
|
|
|
|
start, data->set.str[STRING_RTSP_SESSION_ID]);
|
|
|
|
return CURLE_RTSP_SESSION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-08-10 14:58:10 +08:00
|
|
|
/* If the Session ID is not set, and we find it in a response, then set
|
|
|
|
* it.
|
2010-01-21 21:58:30 +08:00
|
|
|
*
|
2016-08-11 17:37:00 +08:00
|
|
|
* Allow any non whitespace content, up to the field seperator or end of
|
|
|
|
* line. RFC 2326 isn't 100% clear on the session ID and for example
|
|
|
|
* gstreamer does url-encoded session ID's not covered by the standard.
|
2016-08-10 14:58:10 +08:00
|
|
|
*/
|
2010-01-21 21:58:30 +08:00
|
|
|
char *end = start;
|
2016-08-11 17:37:00 +08:00
|
|
|
while(*end && *end != ';' && !ISSPACE(*end))
|
2010-01-21 21:58:30 +08:00
|
|
|
end++;
|
|
|
|
|
|
|
|
/* Copy the id substring into a new buffer */
|
|
|
|
data->set.str[STRING_RTSP_SESSION_ID] = malloc(end - start + 1);
|
2010-02-03 21:28:47 +08:00
|
|
|
if(data->set.str[STRING_RTSP_SESSION_ID] == NULL)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2010-01-21 21:58:30 +08:00
|
|
|
memcpy(data->set.str[STRING_RTSP_SESSION_ID], start, end - start);
|
|
|
|
(data->set.str[STRING_RTSP_SESSION_ID])[end - start] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CURL_DISABLE_RTSP */
|