2010-05-13 05:07:20 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
|
|
* Copyright (C) Howard Chu, <hyc@highlandsun.com>
|
2010-05-13 05:07:20 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2010-05-13 05:07:20 +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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2010-05-13 05:07:20 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2010-05-13 05:07:20 +08:00
|
|
|
|
|
|
|
#ifdef USE_LIBRTMP
|
|
|
|
|
2017-04-30 01:17:51 +08:00
|
|
|
#include "curl_rtmp.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "nonblock.h" /* for curlx_nonblock */
|
|
|
|
#include "progress.h" /* for Curl_pgrsSetUploadSize */
|
|
|
|
#include "transfer.h"
|
|
|
|
#include "warnless.h"
|
2010-05-13 05:07:20 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <librtmp/rtmp.h>
|
2024-04-15 14:31:59 +08:00
|
|
|
|
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
2010-06-02 20:13:02 +08:00
|
|
|
#include "curl_memory.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h"
|
2010-06-02 20:13:02 +08:00
|
|
|
|
2023-11-22 00:54:49 +08:00
|
|
|
#if defined(_WIN32) && !defined(USE_LWIPSOCK)
|
2010-05-13 05:07:20 +08:00
|
|
|
#define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e)
|
|
|
|
#define SET_RCVTIMEO(tv,s) int tv = s*1000
|
rtmp: fix for compiling with lwIP
Compiling on _WIN32 and with USE_LWIPSOCK, causes this error:
curl_rtmp.c(223,3): error: use of undeclared identifier 'setsockopt'
setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO,
^
curl_rtmp.c(41,32): note: expanded from macro 'setsockopt'
#define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e)
^
Closes #3155
2018-10-22 16:33:44 +08:00
|
|
|
#elif defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD)
|
|
|
|
#define SET_RCVTIMEO(tv,s) int tv = s*1000
|
2010-05-13 05:07:20 +08:00
|
|
|
#else
|
|
|
|
#define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEF_BUFTIME (2*60*60*1000) /* 2 hours */
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn);
|
|
|
|
static CURLcode rtmp_do(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode rtmp_done(struct Curl_easy *data, CURLcode, bool premature);
|
|
|
|
static CURLcode rtmp_connect(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode rtmp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn, bool dead);
|
2010-05-13 05:07:20 +08:00
|
|
|
|
|
|
|
static Curl_recv rtmp_recv;
|
|
|
|
static Curl_send rtmp_send;
|
|
|
|
|
|
|
|
/*
|
2016-02-03 12:09:25 +08:00
|
|
|
* RTMP protocol handler.h, based on https://rtmpdump.mplayerhq.hu
|
2010-05-13 05:07:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_rtmp = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmp", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMP, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMP, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMP, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_rtmpt = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmpt", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMPT, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMPT, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMPT, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_rtmpe = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmpe", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMP, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMPE, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMPE, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_rtmpte = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmpte", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMPT, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMPTE, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMPTE, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_rtmps = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmps", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMPS, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMPS, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMP, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
2011-05-05 22:27:03 +08:00
|
|
|
|
2010-05-13 05:07:20 +08:00
|
|
|
const struct Curl_handler Curl_handler_rtmpts = {
|
2024-05-07 22:55:23 +08:00
|
|
|
"rtmpts", /* scheme */
|
2014-12-25 01:12:13 +08:00
|
|
|
rtmp_setup_connection, /* setup_connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
rtmp_do, /* do_it */
|
|
|
|
rtmp_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
rtmp_connect, /* connect_it */
|
|
|
|
ZERO_NULL, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-22 05:36:54 +08:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-13 05:07:20 +08:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
rtmp_disconnect, /* disconnect */
|
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.
The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.
Curl's protocol handler `readwrite()` method been changed:
```diff
- CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
- const char *buf, size_t blen,
- size_t *pconsumed, bool *readmore);
+ CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+ bool is_eos, bool *done);
```
The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:
* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
finished
This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.
The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.
HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.
The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:
```
static CURLcode readwrite_data(data, ...)
{
do {
Curl_xfer_recv_resp(data, buf)
...
Curl_xfer_write_resp(data, buf)
...
} while(interested);
...
}
```
All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.
All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.
Closes #12480
2023-12-01 20:50:32 +08:00
|
|
|
ZERO_NULL, /* write_resp */
|
2024-03-21 19:15:59 +08:00
|
|
|
ZERO_NULL, /* write_resp_hd */
|
2017-05-31 19:09:56 +08:00
|
|
|
ZERO_NULL, /* connection_check */
|
2021-05-17 14:54:00 +08:00
|
|
|
ZERO_NULL, /* attach connection */
|
2010-05-13 05:07:20 +08:00
|
|
|
PORT_RTMPS, /* defport */
|
2011-03-15 05:52:14 +08:00
|
|
|
CURLPROTO_RTMPTS, /* protocol */
|
2020-09-21 19:45:24 +08:00
|
|
|
CURLPROTO_RTMPT, /* family */
|
2022-10-31 00:38:16 +08:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-13 05:07:20 +08:00
|
|
|
};
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn)
|
2010-05-13 05:07:20 +08:00
|
|
|
{
|
|
|
|
RTMP *r = RTMP_Alloc();
|
2011-04-20 21:17:42 +08:00
|
|
|
if(!r)
|
2010-05-13 05:07:20 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
RTMP_Init(r);
|
|
|
|
RTMP_SetBufferMS(r, DEF_BUFTIME);
|
2021-03-26 21:25:45 +08:00
|
|
|
if(!RTMP_SetupURL(r, data->state.url)) {
|
2010-05-13 05:07:20 +08:00
|
|
|
RTMP_Free(r);
|
|
|
|
return CURLE_URL_MALFORMAT;
|
|
|
|
}
|
2019-09-03 19:31:44 +08:00
|
|
|
conn->proto.rtmp = r;
|
2010-05-13 05:07:20 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_connect(struct Curl_easy *data, bool *done)
|
2010-05-13 05:07:20 +08:00
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 19:31:44 +08:00
|
|
|
RTMP *r = conn->proto.rtmp;
|
2015-03-17 20:41:49 +08:00
|
|
|
SET_RCVTIMEO(tv, 10);
|
2010-05-13 05:07:20 +08:00
|
|
|
|
2017-07-07 17:52:48 +08:00
|
|
|
r->m_sb.sb_socket = (int)conn->sock[FIRSTSOCKET];
|
2010-05-13 05:07:20 +08:00
|
|
|
|
|
|
|
/* We have to know if it's a write before we send the
|
|
|
|
* connect request packet
|
|
|
|
*/
|
2023-04-25 14:28:01 +08:00
|
|
|
if(data->state.upload)
|
2010-05-13 05:07:20 +08:00
|
|
|
r->Link.protocol |= RTMP_FEATURE_WRITE;
|
|
|
|
|
|
|
|
/* For plain streams, use the buffer toggle trick to keep data flowing */
|
2011-04-20 21:17:42 +08:00
|
|
|
if(!(r->Link.lFlags & RTMP_LF_LIVE) &&
|
|
|
|
!(r->Link.protocol & RTMP_FEATURE_HTTP))
|
2010-05-13 05:07:20 +08:00
|
|
|
r->Link.lFlags |= RTMP_LF_BUFX;
|
|
|
|
|
2014-10-04 21:14:27 +08:00
|
|
|
(void)curlx_nonblock(r->m_sb.sb_socket, FALSE);
|
2011-04-20 21:17:42 +08:00
|
|
|
setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO,
|
|
|
|
(char *)&tv, sizeof(tv));
|
2010-05-13 05:07:20 +08:00
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
if(!RTMP_Connect1(r, NULL))
|
2010-05-13 05:07:20 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
|
|
|
|
/* Clients must send a periodic BytesReceived report to the server */
|
|
|
|
r->m_bSendCounter = true;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
conn->recv[FIRSTSOCKET] = rtmp_recv;
|
|
|
|
conn->send[FIRSTSOCKET] = rtmp_send;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_do(struct Curl_easy *data, bool *done)
|
2010-05-13 05:07:20 +08:00
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 19:31:44 +08:00
|
|
|
RTMP *r = conn->proto.rtmp;
|
2010-05-13 05:07:20 +08:00
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
if(!RTMP_ConnectStream(r, 0))
|
2010-05-13 05:07:20 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
|
2023-04-25 14:28:01 +08:00
|
|
|
if(data->state.upload) {
|
2019-02-28 18:36:26 +08:00
|
|
|
Curl_pgrsSetUploadSize(data, data->state.infilesize);
|
2024-06-10 19:32:13 +08:00
|
|
|
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
|
2011-04-20 21:17:42 +08:00
|
|
|
}
|
|
|
|
else
|
2024-06-10 19:32:13 +08:00
|
|
|
Curl_xfer_setup1(data, CURL_XFER_RECV, -1, FALSE);
|
2010-05-13 05:07:20 +08:00
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_done(struct Curl_easy *data, CURLcode status,
|
2010-05-13 05:07:20 +08:00
|
|
|
bool premature)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
(void)data; /* unused */
|
2010-05-25 21:43:41 +08:00
|
|
|
(void)status; /* unused */
|
|
|
|
(void)premature; /* unused */
|
|
|
|
|
2010-05-13 05:07:20 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static CURLcode rtmp_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2010-12-06 22:33:38 +08:00
|
|
|
bool dead_connection)
|
2010-05-13 05:07:20 +08:00
|
|
|
{
|
2019-09-03 19:31:44 +08:00
|
|
|
RTMP *r = conn->proto.rtmp;
|
2021-01-09 00:58:15 +08:00
|
|
|
(void)data;
|
2010-12-06 22:33:38 +08:00
|
|
|
(void)dead_connection;
|
2011-04-20 21:17:42 +08:00
|
|
|
if(r) {
|
2019-09-03 19:31:44 +08:00
|
|
|
conn->proto.rtmp = NULL;
|
2010-05-13 05:07:20 +08:00
|
|
|
RTMP_Close(r);
|
|
|
|
RTMP_Free(r);
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static ssize_t rtmp_recv(struct Curl_easy *data, int sockindex, char *buf,
|
2010-05-13 05:07:20 +08:00
|
|
|
size_t len, CURLcode *err)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 19:31:44 +08:00
|
|
|
RTMP *r = conn->proto.rtmp;
|
2010-05-13 05:07:20 +08:00
|
|
|
ssize_t nread;
|
|
|
|
|
2010-05-25 21:43:41 +08:00
|
|
|
(void)sockindex; /* unused */
|
|
|
|
|
2012-09-29 05:57:04 +08:00
|
|
|
nread = RTMP_Read(r, buf, curlx_uztosi(len));
|
2011-04-20 21:17:42 +08:00
|
|
|
if(nread < 0) {
|
|
|
|
if(r->m_read.status == RTMP_READ_COMPLETE ||
|
2021-01-09 00:58:15 +08:00
|
|
|
r->m_read.status == RTMP_READ_EOF) {
|
|
|
|
data->req.size = data->req.bytecount;
|
2010-05-13 05:07:20 +08:00
|
|
|
nread = 0;
|
2011-04-20 21:17:42 +08:00
|
|
|
}
|
|
|
|
else
|
2010-05-13 05:07:20 +08:00
|
|
|
*err = CURLE_RECV_ERROR;
|
|
|
|
}
|
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
static ssize_t rtmp_send(struct Curl_easy *data, int sockindex,
|
2010-05-13 05:07:20 +08:00
|
|
|
const void *buf, size_t len, CURLcode *err)
|
|
|
|
{
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 19:31:44 +08:00
|
|
|
RTMP *r = conn->proto.rtmp;
|
2010-05-13 05:07:20 +08:00
|
|
|
ssize_t num;
|
|
|
|
|
2010-05-25 21:43:41 +08:00
|
|
|
(void)sockindex; /* unused */
|
|
|
|
|
2012-09-29 05:57:04 +08:00
|
|
|
num = RTMP_Write(r, (char *)buf, curlx_uztosi(len));
|
2011-04-20 21:17:42 +08:00
|
|
|
if(num < 0)
|
2010-05-13 05:07:20 +08:00
|
|
|
*err = CURLE_SEND_ERROR;
|
2011-04-20 21:17:42 +08:00
|
|
|
|
2010-05-13 05:07:20 +08:00
|
|
|
return num;
|
|
|
|
}
|
2024-04-15 14:31:59 +08:00
|
|
|
|
|
|
|
void Curl_rtmp_version(char *version, size_t len)
|
|
|
|
{
|
|
|
|
char suff[2];
|
|
|
|
if(RTMP_LIB_VERSION & 0xff) {
|
|
|
|
suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
|
|
|
|
suff[1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
suff[0] = '\0';
|
|
|
|
|
|
|
|
msnprintf(version, len, "librtmp/%d.%d%s",
|
|
|
|
RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
|
|
|
|
suff);
|
|
|
|
}
|
|
|
|
|
2010-05-13 05:07:20 +08:00
|
|
|
#endif /* USE_LIBRTMP */
|