mirror of
https://github.com/curl/curl.git
synced 2026-04-14 22:51:53 +03:00
rtsp: split out a subfunction from rtsp_do
Takes complexity down from 71 to 52. Closes #18471
This commit is contained in:
parent
31659b4a7a
commit
1edead4360
1 changed files with 81 additions and 73 deletions
154
lib/rtsp.c
154
lib/rtsp.c
|
|
@ -278,6 +278,84 @@ static CURLcode rtsp_done(struct Curl_easy *data,
|
|||
return httpStatus;
|
||||
}
|
||||
|
||||
|
||||
static CURLcode rtsp_setup_body(struct Curl_easy *data,
|
||||
Curl_RtspReq rtspreq,
|
||||
struct dynbuf *reqp)
|
||||
{
|
||||
CURLcode result;
|
||||
if(rtspreq == RTSPREQ_ANNOUNCE ||
|
||||
rtspreq == RTSPREQ_SET_PARAMETER ||
|
||||
rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
curl_off_t req_clen; /* request content length */
|
||||
|
||||
if(data->state.upload) {
|
||||
req_clen = data->state.infilesize;
|
||||
data->state.httpreq = HTTPREQ_PUT;
|
||||
result = Curl_creader_set_fread(data, req_clen);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
if(data->set.postfields) {
|
||||
size_t plen = strlen(data->set.postfields);
|
||||
req_clen = (curl_off_t)plen;
|
||||
result = Curl_creader_set_buf(data, data->set.postfields, plen);
|
||||
}
|
||||
else if(data->state.infilesize >= 0) {
|
||||
req_clen = data->state.infilesize;
|
||||
result = Curl_creader_set_fread(data, req_clen);
|
||||
}
|
||||
else {
|
||||
req_clen = 0;
|
||||
result = Curl_creader_set_null(data);
|
||||
}
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
if(req_clen > 0) {
|
||||
/* As stated in the http comments, it is probably not wise to
|
||||
* actually set a custom Content-Length in the headers */
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Length"))) {
|
||||
result = curlx_dyn_addf(reqp, "Content-Length: %" FMT_OFF_T"\r\n",
|
||||
req_clen);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
if(rtspreq == RTSPREQ_SET_PARAMETER ||
|
||||
rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Type"))) {
|
||||
result = curlx_dyn_addn(reqp,
|
||||
STRCONST("Content-Type: "
|
||||
"text/parameters\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if(rtspreq == RTSPREQ_ANNOUNCE) {
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Type"))) {
|
||||
result = curlx_dyn_addn(reqp,
|
||||
STRCONST("Content-Type: "
|
||||
"application/sdp\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
/* Check for an empty GET_PARAMETER (heartbeat) request */
|
||||
data->state.httpreq = HTTPREQ_HEAD;
|
||||
data->req.no_body = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
result = Curl_creader_set_null(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
|
|
@ -561,79 +639,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
|
|||
if(result)
|
||||
goto out;
|
||||
|
||||
if(rtspreq == RTSPREQ_ANNOUNCE ||
|
||||
rtspreq == RTSPREQ_SET_PARAMETER ||
|
||||
rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
curl_off_t req_clen; /* request content length */
|
||||
|
||||
if(data->state.upload) {
|
||||
req_clen = data->state.infilesize;
|
||||
data->state.httpreq = HTTPREQ_PUT;
|
||||
result = Curl_creader_set_fread(data, req_clen);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
else {
|
||||
if(data->set.postfields) {
|
||||
size_t plen = strlen(data->set.postfields);
|
||||
req_clen = (curl_off_t)plen;
|
||||
result = Curl_creader_set_buf(data, data->set.postfields, plen);
|
||||
}
|
||||
else if(data->state.infilesize >= 0) {
|
||||
req_clen = data->state.infilesize;
|
||||
result = Curl_creader_set_fread(data, req_clen);
|
||||
}
|
||||
else {
|
||||
req_clen = 0;
|
||||
result = Curl_creader_set_null(data);
|
||||
}
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(req_clen > 0) {
|
||||
/* As stated in the http comments, it is probably not wise to
|
||||
* actually set a custom Content-Length in the headers */
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Length"))) {
|
||||
result =
|
||||
curlx_dyn_addf(&req_buffer, "Content-Length: %" FMT_OFF_T"\r\n",
|
||||
req_clen);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(rtspreq == RTSPREQ_SET_PARAMETER ||
|
||||
rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Type"))) {
|
||||
result = curlx_dyn_addn(&req_buffer,
|
||||
STRCONST("Content-Type: "
|
||||
"text/parameters\r\n"));
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if(rtspreq == RTSPREQ_ANNOUNCE) {
|
||||
if(!Curl_checkheaders(data, STRCONST("Content-Type"))) {
|
||||
result = curlx_dyn_addn(&req_buffer,
|
||||
STRCONST("Content-Type: "
|
||||
"application/sdp\r\n"));
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
/* Check for an empty GET_PARAMETER (heartbeat) request */
|
||||
data->state.httpreq = HTTPREQ_HEAD;
|
||||
data->req.no_body = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = Curl_creader_set_null(data);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
result = rtsp_setup_body(data, rtspreq, &req_buffer);
|
||||
if(result)
|
||||
goto out;
|
||||
|
||||
/* Finish the request buffer */
|
||||
result = curlx_dyn_addn(&req_buffer, STRCONST("\r\n"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue