diff options
Diffstat (limited to 'libs/libcurl/src/curl_rtmp.c')
-rw-r--r-- | libs/libcurl/src/curl_rtmp.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/libs/libcurl/src/curl_rtmp.c b/libs/libcurl/src/curl_rtmp.c index 9e1d578db1..6eb41040c2 100644 --- a/libs/libcurl/src/curl_rtmp.c +++ b/libs/libcurl/src/curl_rtmp.c @@ -29,10 +29,11 @@ #include "curl_rtmp.h"
#include "urldata.h"
-#include "nonblock.h" /* for curlx_nonblock */
+#include "url.h"
+#include "curlx/nonblock.h" /* for curlx_nonblock */
#include "progress.h" /* for Curl_pgrsSetUploadSize */
#include "transfer.h"
-#include "warnless.h"
+#include "curlx/warnless.h"
#include <curl/curl.h>
#include <librtmp/rtmp.h>
@@ -52,6 +53,10 @@ #define DEF_BUFTIME (2*60*60*1000) /* 2 hours */
+/* meta key for storing RTMP* at connection */
+#define CURL_META_RTMP_CONN "meta:proto:rtmp:conn"
+
+
static CURLcode rtmp_setup_connection(struct Curl_easy *data,
struct connectdata *conn);
static CURLcode rtmp_do(struct Curl_easy *data, bool *done);
@@ -85,6 +90,7 @@ const struct Curl_handler Curl_handler_rtmp = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMP, /* defport */
CURLPROTO_RTMP, /* protocol */
CURLPROTO_RTMP, /* family */
@@ -109,6 +115,7 @@ const struct Curl_handler Curl_handler_rtmpt = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPT, /* protocol */
CURLPROTO_RTMPT, /* family */
@@ -133,6 +140,7 @@ const struct Curl_handler Curl_handler_rtmpe = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMP, /* defport */
CURLPROTO_RTMPE, /* protocol */
CURLPROTO_RTMPE, /* family */
@@ -157,6 +165,7 @@ const struct Curl_handler Curl_handler_rtmpte = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPTE, /* protocol */
CURLPROTO_RTMPTE, /* family */
@@ -181,6 +190,7 @@ const struct Curl_handler Curl_handler_rtmps = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPS, /* protocol */
CURLPROTO_RTMP, /* family */
@@ -205,17 +215,28 @@ const struct Curl_handler Curl_handler_rtmpts = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPTS, /* protocol */
CURLPROTO_RTMPT, /* family */
PROTOPT_NONE /* flags */
};
+static void rtmp_conn_dtor(void *key, size_t klen, void *entry)
+{
+ RTMP *r = entry;
+ (void)key;
+ (void)klen;
+ RTMP_Close(r);
+ RTMP_Free(r);
+}
+
static CURLcode rtmp_setup_connection(struct Curl_easy *data,
struct connectdata *conn)
{
RTMP *r = RTMP_Alloc();
- if(!r)
+ if(!r ||
+ Curl_conn_meta_set(conn, CURL_META_RTMP_CONN, r, rtmp_conn_dtor))
return CURLE_OUT_OF_MEMORY;
RTMP_Init(r);
@@ -224,16 +245,18 @@ static CURLcode rtmp_setup_connection(struct Curl_easy *data, RTMP_Free(r);
return CURLE_URL_MALFORMAT;
}
- conn->proto.rtmp = r;
return CURLE_OK;
}
static CURLcode rtmp_connect(struct Curl_easy *data, bool *done)
{
struct connectdata *conn = data->conn;
- RTMP *r = conn->proto.rtmp;
+ RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN);
SET_RCVTIMEO(tv, 10);
+ if(!r)
+ return CURLE_FAILED_INIT;
+
r->m_sb.sb_socket = (int)conn->sock[FIRSTSOCKET];
/* We have to know if it is a write before we send the
@@ -266,9 +289,9 @@ static CURLcode rtmp_connect(struct Curl_easy *data, bool *done) static CURLcode rtmp_do(struct Curl_easy *data, bool *done)
{
struct connectdata *conn = data->conn;
- RTMP *r = conn->proto.rtmp;
+ RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN);
- if(!RTMP_ConnectStream(r, 0))
+ if(!r || !RTMP_ConnectStream(r, 0))
return CURLE_FAILED_INIT;
if(data->state.upload) {
@@ -295,14 +318,11 @@ static CURLcode rtmp_disconnect(struct Curl_easy *data, struct connectdata *conn,
bool dead_connection)
{
- RTMP *r = conn->proto.rtmp;
+ RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN);
(void)data;
(void)dead_connection;
- if(r) {
- conn->proto.rtmp = NULL;
- RTMP_Close(r);
- RTMP_Free(r);
- }
+ if(r)
+ Curl_conn_meta_remove(conn, CURL_META_RTMP_CONN);
return CURLE_OK;
}
@@ -310,10 +330,14 @@ static ssize_t rtmp_recv(struct Curl_easy *data, int sockindex, char *buf, size_t len, CURLcode *err)
{
struct connectdata *conn = data->conn;
- RTMP *r = conn->proto.rtmp;
+ RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN);
ssize_t nread;
(void)sockindex; /* unused */
+ if(!r) {
+ *err = CURLE_FAILED_INIT;
+ return -1;
+ }
nread = RTMP_Read(r, buf, curlx_uztosi(len));
if(nread < 0) {
@@ -332,13 +356,17 @@ static ssize_t rtmp_send(struct Curl_easy *data, int sockindex, const void *buf, size_t len, bool eos, CURLcode *err)
{
struct connectdata *conn = data->conn;
- RTMP *r = conn->proto.rtmp;
+ RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN);
ssize_t num;
(void)sockindex; /* unused */
(void)eos; /* unused */
+ if(!r) {
+ *err = CURLE_FAILED_INIT;
+ return -1;
+ }
- num = RTMP_Write(r, (char *)buf, curlx_uztosi(len));
+ num = RTMP_Write(r, (const char *)buf, curlx_uztosi(len));
if(num < 0)
*err = CURLE_SEND_ERROR;
|