Projects
Essentials
rtmpdump
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 8
View file
rtmpdump.changes
Changed
@@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Thu Nov 1 16:30:15 UTC 2012 - i@margueirte.su + +- update to 2.4.git20121102. + * Aside from various minor bugfixes since 2.3, RTMPE type 9 handshakes + are now supported. + +------------------------------------------------------------------- Thu Dec 15 14:15:45 UTC 2011 - ismail@namtrac.org - Update to latest git as of 14.11.2011
View file
rtmpdump.spec
Changed
@@ -4,7 +4,7 @@ # Name: rtmpdump -Version: 2.3.99.git20111114 +Version: 2.4.git20121102 Release: 0 License: GPL-2.0 %define soname 0
View file
rtmpdump-2.3.99.git20111114.tar.bz2/Makefile -> rtmpdump-2.4.git20121102.tar.bz2/Makefile
Changed
@@ -12,7 +12,7 @@ #CRYPTO=POLARSSL #CRYPTO=GNUTLS LIBZ=-lz -LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ) +LIB_GNUTLS=-lgnutls -lhogweed -lnettle -lgmp $(LIBZ) LIB_OPENSSL=-lssl -lcrypto $(LIBZ) LIB_POLARSSL=-lpolarssl $(LIBZ) CRYPTO_LIB=$(LIB_$(CRYPTO))
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/Makefile -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/Makefile
Changed
@@ -28,7 +28,7 @@ LIBS_posix= LIBS_darwin= LIBS_mingw=-lws2_32 -lwinmm -lgdi32 -LIB_GNUTLS=-lgnutls -lgcrypt $(LIBZ) +LIB_GNUTLS=-lgnutls -lhogweed -lnettle -lgmp $(LIBZ) LIB_OPENSSL=-lssl -lcrypto $(LIBZ) LIB_POLARSSL=-lpolarssl $(LIBZ) PRIVATE_LIBS=$(LIBS_$(SYS)) @@ -39,11 +39,11 @@ SO_VERSION=0 SOX_posix=so SOX_darwin=dylib -SOX_mingw=so # useless +SOX_mingw=dll SOX=$(SOX_$(SYS)) -SO_posix=$(SOX).$(SO_VERSION) -SO_darwin=$(SO_VERSION).$(SOX) -SO_mingw=dll +SO_posix=.$(SOX).$(SO_VERSION) +SO_darwin=.$(SO_VERSION).$(SOX) +SO_mingw=-$(SO_VERSION).$(SOX) SO_EXT=$(SO_$(SYS)) SODIR_posix=$(LIBDIR) @@ -64,7 +64,7 @@ SHARED=yes SODEF_yes=-fPIC -SOLIB_yes=librtmp.$(SO_EXT) +SOLIB_yes=librtmp$(SO_EXT) SOINST_yes=install_so SO_DEF=$(SODEF_$(SHARED)) SO_LIB=$(SOLIB_$(SHARED)) @@ -81,12 +81,12 @@ all: librtmp.a $(SO_LIB) clean: - rm -f *.o *.a *.$(SOX) *.$(SO_EXT) librtmp.pc + rm -f *.o *.a *.$(SOX) *$(SO_EXT) librtmp.pc librtmp.a: $(OBJS) $(AR) rs $@ $? -librtmp.$(SO_EXT): $(OBJS) +librtmp$(SO_EXT): $(OBJS) $(CC) $(SO_LDFLAGS) $(LDFLAGS) -o $@ $^ $> $(CRYPTO_LIB) ln -sf $@ librtmp.$(SOX) @@ -111,8 +111,8 @@ cp librtmp.pc $(LIBDIR)/pkgconfig cp librtmp.3 $(MANDIR)/man3 -install_so: librtmp.$(SO_EXT) - cp librtmp.$(SO_EXT) $(SODIR) +install_so: librtmp$(SO_EXT) + cp librtmp$(SO_EXT) $(SODIR) $(INSTALL_IMPLIB) - cd $(SODIR); ln -sf librtmp.$(SO_EXT) librtmp.$(SOX) + cd $(SODIR); ln -sf librtmp$(SO_EXT) librtmp.$(SOX)
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/amf.c -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/amf.c
Changed
@@ -396,6 +396,14 @@ pBuffer = AMF_Encode(&prop->p_vu.p_object, pBuffer, pBufEnd); break; + case AMF_ECMA_ARRAY: + pBuffer = AMF_EncodeEcmaArray(&prop->p_vu.p_object, pBuffer, pBufEnd); + break; + + case AMF_STRICT_ARRAY: + pBuffer = AMF_EncodeArray(&prop->p_vu.p_object, pBuffer, pBufEnd); + break; + default: RTMP_Log(RTMP_LOGERROR, "%s, invalid type. %d", __FUNCTION__, prop->p_type); pBuffer = NULL; @@ -700,7 +708,6 @@ if (nRes == -1) return -1; nSize -= nRes; - prop->p_type = AMF_OBJECT; break; } case AMF_OBJECT_END: @@ -718,7 +725,6 @@ if (nRes == -1) return -1; nSize -= nRes; - prop->p_type = AMF_OBJECT; break; } case AMF_DATE: @@ -735,13 +741,15 @@ break; } case AMF_LONG_STRING: + case AMF_XML_DOC: { unsigned int nStringSize = AMF_DecodeInt32(pBuffer); if (nSize < (long)nStringSize + 4) return -1; AMF_DecodeLongString(pBuffer, &prop->p_vu.p_aval); nSize -= (4 + nStringSize); - prop->p_type = AMF_STRING; + if (prop->p_type == AMF_LONG_STRING) + prop->p_type = AMF_STRING; break; } case AMF_RECORDSET: @@ -750,12 +758,6 @@ return -1; break; } - case AMF_XML_DOC: - { - RTMP_Log(RTMP_LOGERROR, "AMF_XML_DOC not supported!"); - return -1; - break; - } case AMF_TYPED_OBJECT: { RTMP_Log(RTMP_LOGERROR, "AMF_TYPED_OBJECT not supported!"); @@ -819,6 +821,18 @@ AMF_Dump(&prop->p_vu.p_object); return; } + else if (prop->p_type == AMF_ECMA_ARRAY) + { + RTMP_Log(RTMP_LOGDEBUG, "Property: <%sECMA_ARRAY>", strRes); + AMF_Dump(&prop->p_vu.p_object); + return; + } + else if (prop->p_type == AMF_STRICT_ARRAY) + { + RTMP_Log(RTMP_LOGDEBUG, "Property: <%sSTRICT_ARRAY>", strRes); + AMF_Dump(&prop->p_vu.p_object); + return; + } switch (prop->p_type) { @@ -892,6 +906,76 @@ return pBuffer; } +char * +AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd) +{ + int i; + + if (pBuffer+4 >= pBufEnd) + return NULL; + + *pBuffer++ = AMF_ECMA_ARRAY; + + pBuffer = AMF_EncodeInt32(pBuffer, pBufEnd, obj->o_num); + + for (i = 0; i < obj->o_num; i++) + { + char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd); + if (res == NULL) + { + RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d", + i); + break; + } + else + { + pBuffer = res; + } + } + + if (pBuffer + 3 >= pBufEnd) + return NULL; /* no room for the end marker */ + + pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END); + + return pBuffer; +} + +char * +AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd) +{ + int i; + + if (pBuffer+4 >= pBufEnd) + return NULL; + + *pBuffer++ = AMF_STRICT_ARRAY; + + pBuffer = AMF_EncodeInt32(pBuffer, pBufEnd, obj->o_num); + + for (i = 0; i < obj->o_num; i++) + { + char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd); + if (res == NULL) + { + RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d", + i); + break; + } + else + { + pBuffer = res; + } + } + + //if (pBuffer + 3 >= pBufEnd) + // return NULL; /* no room for the end marker */ + + //pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END); + + return pBuffer; +} + int AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize, int nArrayLen, int bDecodeName) @@ -1125,7 +1209,7 @@ { if (nIndex >= 0) { - if (nIndex <= obj->o_num) + if (nIndex < obj->o_num) return &obj->o_props[nIndex]; } else
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/amf.h -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/amf.h
Changed
@@ -104,6 +104,9 @@ double AMF_DecodeNumber(const char *data); char *AMF_Encode(AMFObject * obj, char *pBuffer, char *pBufEnd); + char *AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd); + char *AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd); + int AMF_Decode(AMFObject * obj, const char *pBuffer, int nSize, int bDecodeName); int AMF_DecodeArray(AMFObject * obj, const char *pBuffer, int nSize,
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/dh.h -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/dh.h
Changed
@@ -61,7 +61,7 @@ MP_set(&dh->ctx.P, dh->p); MP_set(&dh->ctx.G, dh->g); dh->ctx.len = 128; - dhm_make_public(&dh->ctx, 1024, out, 1, havege_rand, &RTMP_TLS_ctx->hs); + dhm_make_public(&dh->ctx, 1024, out, 1, havege_random, &RTMP_TLS_ctx->hs); MP_new(dh->pub_key); MP_new(dh->priv_key); MP_set(dh->pub_key, &dh->ctx.GX); @@ -77,20 +77,21 @@ } #elif defined(USE_GNUTLS) -#include <gcrypt.h> -typedef gcry_mpi_t MP_t; -#define MP_new(m) m = gcry_mpi_new(1) -#define MP_set_w(mpi, w) gcry_mpi_set_ui(mpi, w) -#define MP_cmp(u, v) gcry_mpi_cmp(u, v) -#define MP_set(u, v) gcry_mpi_set(u, v) -#define MP_sub_w(mpi, w) gcry_mpi_sub_ui(mpi, mpi, w) -#define MP_cmp_1(mpi) gcry_mpi_cmp_ui(mpi, 1) -#define MP_modexp(r, y, q, p) gcry_mpi_powm(r, y, q, p) -#define MP_free(mpi) gcry_mpi_release(mpi) -#define MP_gethex(u, hex, res) res = (gcry_mpi_scan(&u, GCRYMPI_FMT_HEX, hex, 0, 0) == 0) -#define MP_bytes(u) (gcry_mpi_get_nbits(u) + 7) / 8 -#define MP_setbin(u,buf,len) gcry_mpi_print(GCRYMPI_FMT_USG,buf,len,NULL,u) -#define MP_getbin(u,buf,len) gcry_mpi_scan(&u,GCRYMPI_FMT_USG,buf,len,NULL) +#include <gmp.h> +#include <nettle/bignum.h> +typedef mpz_ptr MP_t; +#define MP_new(m) m = malloc(sizeof(*m)); mpz_init2(m, 1) +#define MP_set_w(mpi, w) mpz_set_ui(mpi, w) +#define MP_cmp(u, v) mpz_cmp(u, v) +#define MP_set(u, v) mpz_set(u, v) +#define MP_sub_w(mpi, w) mpz_sub_ui(mpi, mpi, w) +#define MP_cmp_1(mpi) mpz_cmp_ui(mpi, 1) +#define MP_modexp(r, y, q, p) mpz_powm(r, y, q, p) +#define MP_free(mpi) mpz_clear(mpi); free(mpi) +#define MP_gethex(u, hex, res) u = malloc(sizeof(*u)); mpz_init2(u, 1); res = (mpz_set_str(u, hex, 16) == 0) +#define MP_bytes(u) (mpz_sizeinbase(u, 2) + 7) / 8 +#define MP_setbin(u,buf,len) nettle_mpz_get_str_256(len,buf,u) +#define MP_getbin(u,buf,len) u = malloc(sizeof(*u)); mpz_init2(u, 1); nettle_mpz_set_str_256_u(u,len,buf) typedef struct MDH { MP_t p;
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/handshake.h -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/handshake.h
Changed
@@ -43,21 +43,24 @@ #define RC4_free(h) free(h) #elif defined(USE_GNUTLS) -#include <gcrypt.h> +#include <nettle/hmac.h> +#include <nettle/arcfour.h> #ifndef SHA256_DIGEST_LENGTH #define SHA256_DIGEST_LENGTH 32 #endif -#define HMAC_CTX gcry_md_hd_t -#define HMAC_setup(ctx, key, len) gcry_md_open(&ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); gcry_md_setkey(ctx, key, len) -#define HMAC_crunch(ctx, buf, len) gcry_md_write(ctx, buf, len) -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; memcpy(dig, gcry_md_read(ctx, 0), dlen); gcry_md_close(ctx) - -typedef gcry_cipher_hd_t RC4_handle; -#define RC4_alloc(h) gcry_cipher_open(h, GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM, 0) -#define RC4_setkey(h,l,k) gcry_cipher_setkey(h,k,l) -#define RC4_encrypt(h,l,d) gcry_cipher_encrypt(h,(void *)d,l,NULL,0) -#define RC4_encrypt2(h,l,s,d) gcry_cipher_encrypt(h,(void *)d,l,(void *)s,l) -#define RC4_free(h) gcry_cipher_close(h) +#undef HMAC_CTX +#define HMAC_CTX struct hmac_sha256_ctx +#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key) +#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf) +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig) +#define HMAC_close(ctx) + +typedef struct arcfour_ctx* RC4_handle; +#define RC4_alloc(h) *h = malloc(sizeof(struct arcfour_ctx)) +#define RC4_setkey(h,l,k) arcfour_set_key(h, l, k) +#define RC4_encrypt(h,l,d) arcfour_crypt(h,l,(uint8_t *)d,(uint8_t *)d) +#define RC4_encrypt2(h,l,s,d) arcfour_crypt(h,l,(uint8_t *)d,(uint8_t *)s) +#define RC4_free(h) free(h) #else /* USE_OPENSSL */ #include <openssl/sha.h>
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/hashswf.c -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/hashswf.c
Changed
@@ -42,16 +42,16 @@ #define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(&ctx, dig) #define HMAC_close(ctx) #elif defined(USE_GNUTLS) -#include <gnutls/gnutls.h> -#include <gcrypt.h> +#include <nettle/hmac.h> #ifndef SHA256_DIGEST_LENGTH #define SHA256_DIGEST_LENGTH 32 #endif -#define HMAC_CTX gcry_md_hd_t -#define HMAC_setup(ctx, key, len) gcry_md_open(&ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); gcry_md_setkey(ctx, key, len) -#define HMAC_crunch(ctx, buf, len) gcry_md_write(ctx, buf, len) -#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; memcpy(dig, gcry_md_read(ctx, 0), dlen) -#define HMAC_close(ctx) gcry_md_close(ctx) +#undef HMAC_CTX +#define HMAC_CTX struct hmac_sha256_ctx +#define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key) +#define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf) +#define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig) +#define HMAC_close(ctx) #else /* USE_OPENSSL */ #include <openssl/ssl.h> #include <openssl/sha.h>
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/parseurl.c -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/parseurl.c
Changed
@@ -137,12 +137,14 @@ * application = app[/appinstance] */ - char *slash2, *slash3 = NULL; + char *slash2, *slash3 = NULL, *slash4 = NULL; int applen, appnamelen; slash2 = strchr(p, '/'); if(slash2) slash3 = strchr(slash2+1, '/'); + if(slash3) + slash4 = strchr(slash3+1, '/'); applen = end-p; /* ondemand, pass all parameters as app */ appnamelen = applen; /* ondemand length */ @@ -156,7 +158,9 @@ appnamelen = 8; } else { /* app!=ondemand, so app is app[/appinstance] */ - if(slash3) + if(slash4) + appnamelen = slash4-p; + else if(slash3) appnamelen = slash3-p; else if(slash2) appnamelen = slash2-p;
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/rtmp.c -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/rtmp.c
Changed
@@ -27,6 +27,7 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <time.h> #include "rtmp_sys.h" #include "log.h" @@ -34,11 +35,33 @@ #ifdef CRYPTO #ifdef USE_POLARSSL #include <polarssl/havege.h> +#include <polarssl/md5.h> +#include <polarssl/base64.h> +#define MD5_DIGEST_LENGTH 16 + +static const char *my_dhm_P = + "E4004C1F94182000103D883A448B3F80" \ + "2CE4B44A83301270002C20D0321CFD00" \ + "11CCEF784C26A400F43DFB901BCA7538" \ + "F2C6B176001CF5A0FD16D2C48B1D0C1C" \ + "F6AC8E1DA6BCC3B4E1F96B0564965300" \ + "FFA1D0B601EB2800F489AA512C4B248C" \ + "01F76949A60BB7F00A40B1EAB64BDD48" \ + "E8A700D60B7F1200FA8E77B0A979DABF"; + +static const char *my_dhm_G = "4"; + #elif defined(USE_GNUTLS) #include <gnutls/gnutls.h> +#define MD5_DIGEST_LENGTH 16 +#include <nettle/base64.h> +#include <nettle/md5.h> #else /* USE_OPENSSL */ #include <openssl/ssl.h> #include <openssl/rc4.h> +#include <openssl/md5.h> +#include <openssl/bio.h> +#include <openssl/buffer.h> #endif TLS_CTX RTMP_TLS_ctx; #endif @@ -227,6 +250,64 @@ #endif } +void * +RTMP_TLS_AllocServerContext(const char* cert, const char* key) +{ + void *ctx = NULL; +#ifdef CRYPTO + if (!RTMP_TLS_ctx) + RTMP_TLS_Init(); +#ifdef USE_POLARSSL + tls_server_ctx *tc = ctx = calloc(1, sizeof(struct tls_server_ctx)); + tc->dhm_P = my_dhm_P; + tc->dhm_G = my_dhm_G; + tc->hs = &RTMP_TLS_ctx->hs; + if (x509parse_crtfile(&tc->cert, cert)) { + free(tc); + return NULL; + } + if (x509parse_keyfile(&tc->key, key, NULL)) { + x509_free(&tc->cert); + free(tc); + return NULL; + } +#elif defined(USE_GNUTLS) && !defined(NO_SSL) + gnutls_certificate_allocate_credentials((gnutls_certificate_credentials*) &ctx); + if (gnutls_certificate_set_x509_key_file(ctx, cert, key, GNUTLS_X509_FMT_PEM) != 0) { + gnutls_certificate_free_credentials(ctx); + return NULL; + } +#elif !defined(NO_SSL) /* USE_OPENSSL */ + ctx = SSL_CTX_new(SSLv23_server_method()); + if (!SSL_CTX_use_certificate_chain_file(ctx, cert)) { + SSL_CTX_free(ctx); + return NULL; + } + if (!SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM)) { + SSL_CTX_free(ctx); + return NULL; + } +#endif +#endif + return ctx; +} + +void +RTMP_TLS_FreeServerContext(void *ctx) +{ +#ifdef CRYPTO +#ifdef USE_POLARSSL + x509_free(&((tls_server_ctx*)ctx)->cert); + rsa_free(&((tls_server_ctx*)ctx)->key); + free(ctx); +#elif defined(USE_GNUTLS) && !defined(NO_SSL) + gnutls_certificate_free_credentials(ctx); +#elif !defined(NO_SSL) /* USE_OPENSSL */ + SSL_CTX_free(ctx); +#endif +#endif +} + RTMP * RTMP_Alloc() { @@ -320,6 +401,31 @@ const AVal RTMP_DefaultFlashVer = { (char *)DEFAULT_FLASH_VER, sizeof(DEFAULT_FLASH_VER) - 1 }; +static void +SocksSetup(RTMP *r, AVal *sockshost) +{ + if (sockshost->av_len) + { + const char *socksport = strchr(sockshost->av_val, ':'); + char *hostname = strdup(sockshost->av_val); + + if (socksport) + hostname[socksport - sockshost->av_val] = '\0'; + r->Link.sockshost.av_val = hostname; + r->Link.sockshost.av_len = strlen(hostname); + + r->Link.socksport = socksport ? atoi(socksport + 1) : 1080; + RTMP_Log(RTMP_LOGDEBUG, "Connecting via SOCKS proxy: %s:%d", r->Link.sockshost.av_val, + r->Link.socksport); + } + else + { + r->Link.sockshost.av_val = NULL; + r->Link.sockshost.av_len = 0; + r->Link.socksport = 0; + } +} + void RTMP_SetupStream(RTMP *r, int protocol, @@ -384,26 +490,7 @@ } #endif - if (sockshost->av_len) - { - const char *socksport = strchr(sockshost->av_val, ':'); - char *hostname = strdup(sockshost->av_val); - - if (socksport) - hostname[socksport - sockshost->av_val] = '\0'; - r->Link.sockshost.av_val = hostname; - r->Link.sockshost.av_len = strlen(hostname); - - r->Link.socksport = socksport ? atoi(socksport + 1) : 1080; - RTMP_Log(RTMP_LOGDEBUG, "Connecting via SOCKS proxy: %s:%d", r->Link.sockshost.av_val, - r->Link.socksport); - } - else - { - r->Link.sockshost.av_val = NULL; - r->Link.sockshost.av_len = 0; - r->Link.socksport = 0; - } + SocksSetup(r, sockshost); if (tcUrl && tcUrl->av_len) r->Link.tcUrl = *tcUrl; @@ -499,6 +586,10 @@ "Buffer time in milliseconds" }, { AVC("timeout"), OFF(Link.timeout), OPT_INT, 0, "Session timeout in seconds" }, + { AVC("pubUser"), OFF(Link.pubUser), OPT_STR, 0, + "Publisher username" }, + { AVC("pubPasswd"), OFF(Link.pubPasswd), OPT_STR, 0, + "Publisher password" }, { {NULL,0}, 0, 0} }; @@ -756,6 +847,8 @@ (unsigned char *)r->Link.SWFHash, r->Link.swfAge); #endif + SocksSetup(r, &r->Link.sockshost); + if (r->Link.port == 0) { if (r->Link.protocol & RTMP_FEATURE_SSL) @@ -859,6 +952,23 @@ } int +RTMP_TLS_Accept(RTMP *r, void *ctx) +{ +#if defined(CRYPTO) && !defined(NO_SSL) + TLS_server(ctx, r->m_sb.sb_ssl); + TLS_setfd(r->m_sb.sb_ssl, r->m_sb.sb_socket); + if (TLS_accept(r->m_sb.sb_ssl) < 0) + { + RTMP_Log(RTMP_LOGERROR, "%s, TLS_Connect failed", __FUNCTION__); + return FALSE; + } + return TRUE; +#else + return FALSE; +#endif +} + +int RTMP_Connect1(RTMP *r, RTMPPacket *cp) { if (r->Link.protocol & RTMP_FEATURE_SSL) @@ -1091,6 +1201,7 @@ packet->m_nTimeStamp, packet->m_hasAbsTimestamp, r->m_mediaStamp); #endif + RTMPPacket_Free(packet); continue; } r->m_pausing = 0; @@ -1100,7 +1211,8 @@ if (bHasMediaPacket) r->m_bPlaying = TRUE; else if (r->m_sb.sb_timedout && !r->m_pausing) - r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + r->m_pauseStamp = r->m_mediaChannel < r->m_channelsAllocatedIn ? + r->m_channelTimestamp[r->m_mediaChannel] : 0; return bHasMediaPacket; } @@ -1288,9 +1400,11 @@ int nBytes = 0, nRead; if (r->Link.protocol & RTMP_FEATURE_HTTP) { + int refill = 0; while (!r->m_resplen) { - if (r->m_sb.sb_size < 144) + int ret; + if (r->m_sb.sb_size < 13 || refill) { if (!r->m_unackd) HTTP_Post(r, RTMPT_IDLE, "", 1); @@ -1301,12 +1415,20 @@ return 0; } } - if (HTTP_read(r, 0) == -1) + if ((ret = HTTP_read(r, 0)) == -1) { RTMP_Log(RTMP_LOGDEBUG, "%s, No valid HTTP response found", __FUNCTION__); RTMP_Close(r); return 0; } + else if (ret == -2) + { + refill = 1; + } + else + { + refill = 0; + } } if (r->m_resplen && !r->m_sb.sb_size) RTMPSockBuf_Fill(&r->m_sb); @@ -1872,7 +1994,8 @@ int RTMP_Pause(RTMP *r, int DoPause) { if (DoPause) - r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + r->m_pauseStamp = r->m_mediaChannel < r->m_channelsAllocatedIn ? + r->m_channelTimestamp[r->m_mediaChannel] : 0; return RTMP_SendPause(r, DoPause, r->m_pauseStamp); } @@ -2305,6 +2428,452 @@ free(vals); } + +#ifdef CRYPTO +static int +b64enc(const unsigned char *input, int length, char *output, int maxsize) +{ +#ifdef USE_POLARSSL + size_t buf_size = maxsize; + if(base64_encode((unsigned char *) output, &buf_size, input, length) == 0) + { + output[buf_size] = '\0'; + return 1; + } + else + { + RTMP_Log(RTMP_LOGDEBUG, "%s, error", __FUNCTION__); + return 0; + } +#elif defined(USE_GNUTLS) + if (BASE64_ENCODE_RAW_LENGTH(length) <= maxsize) + base64_encode_raw((uint8_t*) output, length, input); + else + { + RTMP_Log(RTMP_LOGDEBUG, "%s, error", __FUNCTION__); + return 0; + } +#else /* USE_OPENSSL */ + BIO *bmem, *b64; + BUF_MEM *bptr; + + b64 = BIO_new(BIO_f_base64()); + bmem = BIO_new(BIO_s_mem()); + b64 = BIO_push(b64, bmem); + BIO_write(b64, input, length); + if (BIO_flush(b64) == 1) + { + BIO_get_mem_ptr(b64, &bptr); + memcpy(output, bptr->data, bptr->length-1); + output[bptr->length-1] = '\0'; + } + else + { + RTMP_Log(RTMP_LOGDEBUG, "%s, error", __FUNCTION__); + return 0; + } + BIO_free_all(b64); +#endif + return 1; +} + +#ifdef USE_POLARSSL +#define MD5_CTX md5_context +#define MD5_Init(ctx) md5_starts(ctx) +#define MD5_Update(ctx,data,len) md5_update(ctx,(unsigned char *)data,len) +#define MD5_Final(dig,ctx) md5_finish(ctx,dig) +#elif defined(USE_GNUTLS) +typedef struct md5_ctx MD5_CTX +#define MD5_Init(ctx) md5_init(ctx) +#define MD5_Update(ctx,data,len) md5_update(ctx,len,data) +#define MD5_Final(dig,ctx) md5_digest(ctx,MD5_DIGEST_LENGTH,dig) +#else +#endif + +static const AVal av_authmod_adobe = AVC("authmod=adobe"); +static const AVal av_authmod_llnw = AVC("authmod=llnw"); + +static void hexenc(unsigned char *inbuf, int len, char *dst) +{ + char *ptr = dst; + while(len--) { + sprintf(ptr, "%02x", *inbuf++); + ptr += 2; + } + *ptr = '\0'; +} + +static int +PublisherAuth(RTMP *r, AVal *description) +{ + char *token_in = NULL; + char *ptr; + unsigned char md5sum_val[MD5_DIGEST_LENGTH+1]; + MD5_CTX md5ctx; + int challenge2_data; +#define RESPONSE_LEN 32 +#define CHALLENGE2_LEN 16 +#define SALTED2_LEN (32+8+8+8) +#define B64DIGEST_LEN 22 /* 16 byte digest => 22 b64 chars */ +#define B64INT_LEN 6 /* 4 byte int => 6 b64 chars */ +#define HEXHASH_LEN (2*MD5_DIGEST_LENGTH) + char response[RESPONSE_LEN]; + char challenge2[CHALLENGE2_LEN]; + char salted2[SALTED2_LEN]; + AVal pubToken; + + if (strstr(description->av_val, av_authmod_adobe.av_val) != NULL) + { + if(strstr(description->av_val, "code=403 need auth") != NULL) + { + if (strstr(r->Link.app.av_val, av_authmod_adobe.av_val) != NULL) { + RTMP_Log(RTMP_LOGERROR, "%s, wrong pubUser & pubPasswd for publisher auth", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } else if(r->Link.pubUser.av_len && r->Link.pubPasswd.av_len) { + pubToken.av_val = malloc(r->Link.pubUser.av_len + av_authmod_adobe.av_len + 8); + pubToken.av_len = sprintf(pubToken.av_val, "?%s&user=%s", + av_authmod_adobe.av_val, + r->Link.pubUser.av_val); + RTMP_Log(RTMP_LOGDEBUG, "%s, pubToken1: %s", __FUNCTION__, pubToken.av_val); + r->Link.pFlags |= RTMP_PUB_NAME; + } else { + RTMP_Log(RTMP_LOGERROR, "%s, need to set pubUser & pubPasswd for publisher auth", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + } + else if((token_in = strstr(description->av_val, "?reason=needauth")) != NULL) + { + char *par, *val = NULL, *orig_ptr; + AVal user, salt, opaque, challenge, *aptr = NULL; + opaque.av_len = 0; + challenge.av_len = 0; + + ptr = orig_ptr = strdup(token_in); + while (ptr) + { + par = ptr; + ptr = strchr(par, '&'); + if(ptr) + *ptr++ = '\0'; + + val = strchr(par, '='); + if(val) + *val++ = '\0'; + + if (aptr) { + aptr->av_len = par - aptr->av_val - 1; + aptr = NULL; + } + if (strcmp(par, "user") == 0){ + user.av_val = val; + aptr = &user; + } else if (strcmp(par, "salt") == 0){ + salt.av_val = val; + aptr = &salt; + } else if (strcmp(par, "opaque") == 0){ + opaque.av_val = val; + aptr = &opaque; + } else if (strcmp(par, "challenge") == 0){ + challenge.av_val = val; + aptr = &challenge; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s, par:\"%s\" = val:\"%s\"", __FUNCTION__, par, val); + } + if (aptr) + aptr->av_len = strlen(aptr->av_val); + + /* hash1 = base64enc(md5(user + _aodbeAuthSalt + password)) */ + MD5_Init(&md5ctx); + MD5_Update(&md5ctx, user.av_val, user.av_len); + MD5_Update(&md5ctx, salt.av_val, salt.av_len); + MD5_Update(&md5ctx, r->Link.pubPasswd.av_val, r->Link.pubPasswd.av_len); + MD5_Final(md5sum_val, &md5ctx); + RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s%s%s) =>", __FUNCTION__, + user.av_val, salt.av_val, r->Link.pubPasswd.av_val); + RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH); + + b64enc(md5sum_val, MD5_DIGEST_LENGTH, salted2, SALTED2_LEN); + RTMP_Log(RTMP_LOGDEBUG, "%s, b64(md5_1) = %s", __FUNCTION__, salted2); + + /* FIXME: what byte order does this depend on? */ + challenge2_data = rand(); + + b64enc((unsigned char *) &challenge2_data, sizeof(int), challenge2, CHALLENGE2_LEN); + RTMP_Log(RTMP_LOGDEBUG, "%s, b64(%d) = %s", __FUNCTION__, challenge2_data, challenge2); + + MD5_Init(&md5ctx); + MD5_Update(&md5ctx, salted2, B64DIGEST_LEN); + /* response = base64enc(md5(hash1 + opaque + challenge2)) */ + if (opaque.av_len) + MD5_Update(&md5ctx, opaque.av_val, opaque.av_len); + if (challenge.av_len) + MD5_Update(&md5ctx, challenge.av_val, challenge.av_len); + MD5_Update(&md5ctx, challenge2, B64INT_LEN); + MD5_Final(md5sum_val, &md5ctx); + + RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s%s%s) =>", __FUNCTION__, + salted2, opaque.av_len ? opaque.av_val : "", challenge2); + RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH); + + b64enc(md5sum_val, MD5_DIGEST_LENGTH, response, RESPONSE_LEN); + RTMP_Log(RTMP_LOGDEBUG, "%s, b64(md5_2) = %s", __FUNCTION__, response); + + /* have all hashes, create auth token for the end of app */ + pubToken.av_val = malloc(32 + B64INT_LEN + B64DIGEST_LEN + opaque.av_len); + pubToken.av_len = sprintf(pubToken.av_val, + "&challenge=%s&response=%s&opaque=%s", + challenge2, + response, + opaque.av_len ? opaque.av_val : ""); + RTMP_Log(RTMP_LOGDEBUG, "%s, pubToken2: %s", __FUNCTION__, pubToken.av_val); + free(orig_ptr); + r->Link.pFlags |= RTMP_PUB_RESP|RTMP_PUB_CLATE; + } + else if(strstr(description->av_val, "?reason=authfailed") != NULL) + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed: wrong password", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + else if(strstr(description->av_val, "?reason=nosuchuser") != NULL) + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed: no such user", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + else + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed: unknown auth mode: %s", + __FUNCTION__, description->av_val); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + + ptr = malloc(r->Link.app.av_len + pubToken.av_len); + strncpy(ptr, r->Link.app.av_val, r->Link.app.av_len); + strncpy(ptr + r->Link.app.av_len, pubToken.av_val, pubToken.av_len); + r->Link.app.av_len += pubToken.av_len; + if(r->Link.pFlags & RTMP_PUB_ALLOC) + free(r->Link.app.av_val); + r->Link.app.av_val = ptr; + + ptr = malloc(r->Link.tcUrl.av_len + pubToken.av_len); + strncpy(ptr, r->Link.tcUrl.av_val, r->Link.tcUrl.av_len); + strncpy(ptr + r->Link.tcUrl.av_len, pubToken.av_val, pubToken.av_len); + r->Link.tcUrl.av_len += pubToken.av_len; + if(r->Link.pFlags & RTMP_PUB_ALLOC) + free(r->Link.tcUrl.av_val); + r->Link.tcUrl.av_val = ptr; + + free(pubToken.av_val); + r->Link.pFlags |= RTMP_PUB_ALLOC; + + RTMP_Log(RTMP_LOGDEBUG, "%s, new app: %.*s tcUrl: %.*s playpath: %s", __FUNCTION__, + r->Link.app.av_len, r->Link.app.av_val, + r->Link.tcUrl.av_len, r->Link.tcUrl.av_val, + r->Link.playpath.av_val); + } + else if (strstr(description->av_val, av_authmod_llnw.av_val) != NULL) + { + if(strstr(description->av_val, "code=403 need auth") != NULL) + { + /* This part seems to be the same for llnw and adobe */ + + if (strstr(r->Link.app.av_val, av_authmod_llnw.av_val) != NULL) { + RTMP_Log(RTMP_LOGERROR, "%s, wrong pubUser & pubPasswd for publisher auth", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } else if(r->Link.pubUser.av_len && r->Link.pubPasswd.av_len) { + pubToken.av_val = malloc(r->Link.pubUser.av_len + av_authmod_llnw.av_len + 8); + pubToken.av_len = sprintf(pubToken.av_val, "?%s&user=%s", + av_authmod_llnw.av_val, + r->Link.pubUser.av_val); + RTMP_Log(RTMP_LOGDEBUG, "%s, pubToken1: %s", __FUNCTION__, pubToken.av_val); + r->Link.pFlags |= RTMP_PUB_NAME; + } else { + RTMP_Log(RTMP_LOGERROR, "%s, need to set pubUser & pubPasswd for publisher auth", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + } + else if((token_in = strstr(description->av_val, "?reason=needauth")) != NULL) + { + char *orig_ptr; + char *par, *val = NULL; + char hash1[HEXHASH_LEN+1], hash2[HEXHASH_LEN+1], hash3[HEXHASH_LEN+1]; + AVal user, nonce, *aptr = NULL; + AVal apptmp; + + /* llnw auth method + * Seems to be closely based on HTTP Digest Auth: + * http://tools.ietf.org/html/rfc2617 + * http://en.wikipedia.org/wiki/Digest_access_authentication + */ + + const char authmod[] = "llnw"; + const char realm[] = "live"; + const char method[] = "publish"; + const char qop[] = "auth"; + /* nc = 1..connection count (or rather, number of times cnonce has been reused) */ + int nc = 1; + /* nchex = hexenc(nc) (8 hex digits according to RFC 2617) */ + char nchex[9]; + /* cnonce = hexenc(4 random bytes) (initialized on first connection) */ + char cnonce[9]; + + ptr = orig_ptr = strdup(token_in); + /* Extract parameters (we need user and nonce) */ + while (ptr) + { + par = ptr; + ptr = strchr(par, '&'); + if(ptr) + *ptr++ = '\0'; + + val = strchr(par, '='); + if(val) + *val++ = '\0'; + + if (aptr) { + aptr->av_len = par - aptr->av_val - 1; + aptr = NULL; + } + if (strcmp(par, "user") == 0){ + user.av_val = val; + aptr = &user; + } else if (strcmp(par, "nonce") == 0){ + nonce.av_val = val; + aptr = &nonce; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s, par:\"%s\" = val:\"%s\"", __FUNCTION__, par, val); + } + if (aptr) + aptr->av_len = strlen(aptr->av_val); + + /* FIXME: handle case where user==NULL or nonce==NULL */ + + sprintf(nchex, "%08x", nc); + sprintf(cnonce, "%08x", rand()); + + /* hash1 = hexenc(md5(user + ":" + realm + ":" + password)) */ + MD5_Init(&md5ctx); + MD5_Update(&md5ctx, user.av_val, user.av_len); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, realm, sizeof(realm)-1); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, r->Link.pubPasswd.av_val, r->Link.pubPasswd.av_len); + MD5_Final(md5sum_val, &md5ctx); + RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s:%s:%s) =>", __FUNCTION__, + user.av_val, realm, r->Link.pubPasswd.av_val); + RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH); + hexenc(md5sum_val, MD5_DIGEST_LENGTH, hash1); + + /* hash2 = hexenc(md5(method + ":/" + app + "/" + appInstance)) */ + /* Extract appname + appinstance without query parameters */ + apptmp = r->Link.app; + ptr = strchr(apptmp.av_val, '?'); + if (ptr) + apptmp.av_len = ptr - apptmp.av_val; + + MD5_Init(&md5ctx); + MD5_Update(&md5ctx, method, sizeof(method)-1); + MD5_Update(&md5ctx, ":/", 2); + MD5_Update(&md5ctx, apptmp.av_val, apptmp.av_len); + MD5_Final(md5sum_val, &md5ctx); + RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s:/%.*s) =>", __FUNCTION__, + method, apptmp.av_len, apptmp.av_val); + RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH); + hexenc(md5sum_val, MD5_DIGEST_LENGTH, hash2); + + /* hash3 = hexenc(md5(hash1 + ":" + nonce + ":" + nchex + ":" + cnonce + ":" + qop + ":" + hash2)) */ + MD5_Init(&md5ctx); + MD5_Update(&md5ctx, hash1, HEXHASH_LEN); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, nonce.av_val, nonce.av_len); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, nchex, sizeof(nchex)-1); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, cnonce, sizeof(cnonce)-1); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, qop, sizeof(qop)-1); + MD5_Update(&md5ctx, ":", 1); + MD5_Update(&md5ctx, hash2, HEXHASH_LEN); + MD5_Final(md5sum_val, &md5ctx); + RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s:%s:%s:%s:%s:%s) =>", __FUNCTION__, + hash1, nonce.av_val, nchex, cnonce, qop, hash2); + RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH); + hexenc(md5sum_val, MD5_DIGEST_LENGTH, hash3); + + /* pubToken = &authmod=<authmod>&user=<username>&nonce=<nonce>&cnonce=<cnonce>&nc=<nchex>&response=<hash3> */ + /* Append nonces and response to query string which already contains + * user + authmod */ + pubToken.av_val = malloc(64 + sizeof(authmod)-1 + user.av_len + nonce.av_len + sizeof(cnonce)-1 + sizeof(nchex)-1 + HEXHASH_LEN); + sprintf(pubToken.av_val, + "&nonce=%s&cnonce=%s&nc=%s&response=%s", + nonce.av_val, cnonce, nchex, hash3); + pubToken.av_len = strlen(pubToken.av_val); + RTMP_Log(RTMP_LOGDEBUG, "%s, pubToken2: %s", __FUNCTION__, pubToken.av_val); + r->Link.pFlags |= RTMP_PUB_RESP|RTMP_PUB_CLATE; + + free(orig_ptr); + } + else if(strstr(description->av_val, "?reason=authfail") != NULL) + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + else if(strstr(description->av_val, "?reason=nosuchuser") != NULL) + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed: no such user", __FUNCTION__); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + else + { + RTMP_Log(RTMP_LOGERROR, "%s, Authentication failed: unknown auth mode: %s", + __FUNCTION__, description->av_val); + r->Link.pFlags |= RTMP_PUB_CLEAN; + return 0; + } + + ptr = malloc(r->Link.app.av_len + pubToken.av_len); + strncpy(ptr, r->Link.app.av_val, r->Link.app.av_len); + strncpy(ptr + r->Link.app.av_len, pubToken.av_val, pubToken.av_len); + r->Link.app.av_len += pubToken.av_len; + if(r->Link.pFlags & RTMP_PUB_ALLOC) + free(r->Link.app.av_val); + r->Link.app.av_val = ptr; + + ptr = malloc(r->Link.tcUrl.av_len + pubToken.av_len); + strncpy(ptr, r->Link.tcUrl.av_val, r->Link.tcUrl.av_len); + strncpy(ptr + r->Link.tcUrl.av_len, pubToken.av_val, pubToken.av_len); + r->Link.tcUrl.av_len += pubToken.av_len; + if(r->Link.pFlags & RTMP_PUB_ALLOC) + free(r->Link.tcUrl.av_val); + r->Link.tcUrl.av_val = ptr; + + free(pubToken.av_val); + r->Link.pFlags |= RTMP_PUB_ALLOC; + + RTMP_Log(RTMP_LOGDEBUG, "%s, new app: %.*s tcUrl: %.*s playpath: %s", __FUNCTION__, + r->Link.app.av_len, r->Link.app.av_val, + r->Link.tcUrl.av_len, r->Link.tcUrl.av_val, + r->Link.playpath.av_val); + } + else + { + return 0; + } + return 1; +} +#endif + + SAVC(onBWDone); SAVC(onFCSubscribe); SAVC(onFCUnsubscribe); @@ -2314,6 +2883,7 @@ SAVC(close); SAVC(code); SAVC(level); +SAVC(description); SAVC(onStatus); SAVC(playlist_ready); static const AVal av_NetStream_Failed = AVC("NetStream.Failed"); @@ -2332,6 +2902,8 @@ static const AVal av_NetStream_Play_UnpublishNotify = AVC("NetStream.Play.UnpublishNotify"); static const AVal av_NetStream_Publish_Start = AVC("NetStream.Publish.Start"); +static const AVal av_NetConnection_Connect_Rejected = +AVC("NetConnection.Connect.Rejected"); /* Returns 0 for OK/Failed/error, 1 for 'Stop or Complete' */ static int @@ -2473,12 +3045,73 @@ } else if (AVMATCH(&method, &av__error)) { +#ifdef CRYPTO + AVal methodInvoked = {0}; + int i; + + if (r->Link.protocol & RTMP_FEATURE_WRITE) + { + for (i=0; i<r->m_numCalls; i++) + { + if (r->m_methodCalls[i].num == txn) + { + methodInvoked = r->m_methodCalls[i].name; + AV_erase(r->m_methodCalls, &r->m_numCalls, i, FALSE); + break; + } + } + if (!methodInvoked.av_val) + { + RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request", + __FUNCTION__, txn); + goto leave; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s, received error for method call <%s>", __FUNCTION__, + methodInvoked.av_val); + + if (AVMATCH(&methodInvoked, &av_connect)) + { + AMFObject obj2; + AVal code, level, description; + AMFProp_GetObject(AMF_GetProp(&obj, NULL, 3), &obj2); + AMFProp_GetString(AMF_GetProp(&obj2, &av_code, -1), &code); + AMFProp_GetString(AMF_GetProp(&obj2, &av_level, -1), &level); + AMFProp_GetString(AMF_GetProp(&obj2, &av_description, -1), &description); + RTMP_Log(RTMP_LOGDEBUG, "%s, error description: %s", __FUNCTION__, description.av_val); + /* if PublisherAuth returns 1, then reconnect */ + PublisherAuth(r, &description); + } + } + else + { + RTMP_Log(RTMP_LOGERROR, "rtmp server sent error"); + } + free(methodInvoked.av_val); +#else RTMP_Log(RTMP_LOGERROR, "rtmp server sent error"); +#endif } else if (AVMATCH(&method, &av_close)) { RTMP_Log(RTMP_LOGERROR, "rtmp server requested close"); RTMP_Close(r); +#ifdef CRYPTO + if ((r->Link.protocol & RTMP_FEATURE_WRITE) && + !(r->Link.pFlags & RTMP_PUB_CLEAN) && + ( !(r->Link.pFlags & RTMP_PUB_NAME) || + !(r->Link.pFlags & RTMP_PUB_RESP) || + (r->Link.pFlags & RTMP_PUB_CLATE) ) ) + { + /* clean later */ + if(r->Link.pFlags & RTMP_PUB_CLATE) + r->Link.pFlags |= RTMP_PUB_CLEAN; + RTMP_Log(RTMP_LOGERROR, "authenticating publisher"); + + if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) + goto leave; + } +#endif } else if (AVMATCH(&method, &av_onStatus)) { @@ -2827,7 +3460,8 @@ break; if (!r->m_pausing) { - r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + r->m_pauseStamp = r->m_mediaChannel < r->m_channelsAllocatedIn ? + r->m_channelTimestamp[r->m_mediaChannel] : 0; RTMP_SendPause(r, TRUE, r->m_pauseStamp); r->m_pausing = 1; } @@ -2972,6 +3606,26 @@ nSize = packetSize[packet->m_headerType]; + if (packet->m_nChannel >= r->m_channelsAllocatedIn) + { + int n = packet->m_nChannel + 10; + int *timestamp = realloc(r->m_channelTimestamp, sizeof(int) * n); + RTMPPacket **packets = realloc(r->m_vecChannelsIn, sizeof(RTMPPacket*) * n); + if (!timestamp) + free(r->m_channelTimestamp); + if (!packets) + free(r->m_vecChannelsIn); + r->m_channelTimestamp = timestamp; + r->m_vecChannelsIn = packets; + if (!timestamp || !packets) { + r->m_channelsAllocatedIn = 0; + return FALSE; + } + memset(r->m_channelTimestamp + r->m_channelsAllocatedIn, 0, sizeof(int) * (n - r->m_channelsAllocatedIn)); + memset(r->m_vecChannelsIn + r->m_channelsAllocatedIn, 0, sizeof(RTMPPacket*) * (n - r->m_channelsAllocatedIn)); + r->m_channelsAllocatedIn = n; + } + if (nSize == RTMP_LARGE_HEADER_SIZE) /* if we get a full header the timestamp is absolute */ packet->m_hasAbsTimestamp = TRUE; @@ -3247,7 +3901,7 @@ int RTMP_SendPacket(RTMP *r, RTMPPacket *packet, int queue) { - const RTMPPacket *prevPacket = r->m_vecChannelsOut[packet->m_nChannel]; + const RTMPPacket *prevPacket; uint32_t last = 0; int nSize; int hSize, cSize; @@ -3257,6 +3911,22 @@ int nChunkSize; int tlen; + if (packet->m_nChannel >= r->m_channelsAllocatedOut) + { + int n = packet->m_nChannel + 10; + RTMPPacket **packets = realloc(r->m_vecChannelsOut, sizeof(RTMPPacket*) * n); + if (!packets) { + free(r->m_vecChannelsOut); + r->m_vecChannelsOut = NULL; + r->m_channelsAllocatedOut = 0; + return FALSE; + } + r->m_vecChannelsOut = packets; + memset(r->m_vecChannelsOut + r->m_channelsAllocatedOut, 0, sizeof(RTMPPacket*) * (n - r->m_channelsAllocatedOut)); + r->m_channelsAllocatedOut = n; + } + + prevPacket = r->m_vecChannelsOut[packet->m_nChannel]; if (prevPacket && packet->m_headerType != RTMP_PACKET_SIZE_LARGE) { /* compress a bit by using the prev packet's attributes */ @@ -3493,7 +4163,7 @@ r->m_write.m_nBytesRead = 0; RTMPPacket_Free(&r->m_write); - for (i = 0; i < RTMP_CHANNELS; i++) + for (i = 0; i < r->m_channelsAllocatedIn; i++) { if (r->m_vecChannelsIn[i]) { @@ -3501,12 +4171,23 @@ free(r->m_vecChannelsIn[i]); r->m_vecChannelsIn[i] = NULL; } + } + free(r->m_vecChannelsIn); + r->m_vecChannelsIn = NULL; + free(r->m_channelTimestamp); + r->m_channelTimestamp = NULL; + r->m_channelsAllocatedIn = 0; + for (i = 0; i < r->m_channelsAllocatedOut; i++) + { if (r->m_vecChannelsOut[i]) { free(r->m_vecChannelsOut[i]); r->m_vecChannelsOut[i] = NULL; } } + free(r->m_vecChannelsOut); + r->m_vecChannelsOut = NULL; + r->m_channelsAllocatedOut = 0; AV_clear(r->m_methodCalls, r->m_numCalls); r->m_methodCalls = NULL; r->m_numCalls = 0; @@ -3519,9 +4200,6 @@ r->m_resplen = 0; r->m_unackd = 0; - free(r->Link.playpath0.av_val); - r->Link.playpath0.av_val = NULL; - if (r->Link.lFlags & RTMP_LF_FTCU) { free(r->Link.tcUrl.av_val); @@ -3530,6 +4208,20 @@ } #ifdef CRYPTO + if (!(r->Link.protocol & RTMP_FEATURE_WRITE) || (r->Link.pFlags & RTMP_PUB_CLEAN)) + { + free(r->Link.playpath0.av_val); + r->Link.playpath0.av_val = NULL; + } + if ((r->Link.protocol & RTMP_FEATURE_WRITE) && + (r->Link.pFlags & RTMP_PUB_CLEAN) && + (r->Link.pFlags & RTMP_PUB_ALLOC)) + { + free(r->Link.app.av_val); + r->Link.app.av_val = NULL; + free(r->Link.tcUrl.av_val); + r->Link.tcUrl.av_val = NULL; + } if (r->Link.dh) { MDH_free(r->Link.dh); @@ -3545,6 +4237,9 @@ RC4_free(r->Link.rc4keyOut); r->Link.rc4keyOut = NULL; } +#else + free(r->Link.playpath0.av_val); + r->Link.playpath0.av_val = NULL; #endif } @@ -3558,7 +4253,7 @@ while (1) { - nBytes = sizeof(sb->sb_buf) - sb->sb_size - (sb->sb_start - sb->sb_buf); + nBytes = sizeof(sb->sb_buf) - 1 - sb->sb_size - (sb->sb_start - sb->sb_buf); #if defined(CRYPTO) && !defined(NO_SSL) if (sb->sb_ssl) { @@ -3710,8 +4405,8 @@ int hlen = snprintf(hbuf, sizeof(hbuf), "POST /%s%s/%d HTTP/1.1\r\n" "Host: %.*s:%d\r\n" "Accept: */*\r\n" - "User-Agent: Shockwave Flash\n" - "Connection: Keep-Alive\n" + "User-Agent: Shockwave Flash\r\n" + "Connection: Keep-Alive\r\n" "Cache-Control: no-cache\r\n" "Content-type: application/x-fcs\r\n" "Content-length: %d\r\n\r\n", RTMPT_cmds[cmd], @@ -3731,12 +4426,23 @@ char *ptr; int hlen; +restart: if (fill) RTMPSockBuf_Fill(&r->m_sb); - if (r->m_sb.sb_size < 144) + if (r->m_sb.sb_size < 13) { + if (fill) + goto restart; return -2; + } if (strncmp(r->m_sb.sb_start, "HTTP/1.1 200 ", 13)) return -1; + r->m_sb.sb_start[r->m_sb.sb_size] = '\0'; + if (!strstr(r->m_sb.sb_start, "\r\n\r\n")) { + if (fill) + goto restart; + return -2; + } + ptr = r->m_sb.sb_start + sizeof("HTTP/1.1 200"); while ((ptr = strstr(ptr, "Content-"))) { if (!strncasecmp(ptr+8, "length:", 7)) break; @@ -3749,6 +4455,12 @@ if (!ptr) return -1; ptr += 4; + if (ptr + (r->m_clientID.av_val ? 1 : hlen) > r->m_sb.sb_start + r->m_sb.sb_size) + { + if (fill) + goto restart; + return -2; + } r->m_sb.sb_size -= ptr - r->m_sb.sb_start; r->m_sb.sb_start = ptr; r->m_unackd--;
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/rtmp.h -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/rtmp.h
Changed
@@ -157,6 +157,8 @@ AVal subscribepath; AVal usherToken; AVal token; + AVal pubUser; + AVal pubPasswd; AMFObject extras; int edepth; @@ -176,6 +178,13 @@ int protocol; int timeout; /* connection timeout in seconds */ +#define RTMP_PUB_NAME 0x0001 /* send login to server */ +#define RTMP_PUB_RESP 0x0002 /* send salted password hash */ +#define RTMP_PUB_ALLOC 0x0004 /* allocated data for new tcUrl & app */ +#define RTMP_PUB_CLEAN 0x0008 /* need to free allocated data for newer tcUrl & app at exit */ +#define RTMP_PUB_CLATE 0x0010 /* late clean tcUrl & app at exit */ + int pFlags; + unsigned short socksport; unsigned short port; @@ -253,9 +262,11 @@ int m_numCalls; RTMP_METHOD *m_methodCalls; /* remote method calls queue */ - RTMPPacket *m_vecChannelsIn[RTMP_CHANNELS]; - RTMPPacket *m_vecChannelsOut[RTMP_CHANNELS]; - int m_channelTimestamp[RTMP_CHANNELS]; /* abs timestamp of last packet */ + int m_channelsAllocatedIn; + int m_channelsAllocatedOut; + RTMPPacket **m_vecChannelsIn; + RTMPPacket **m_vecChannelsOut; + int *m_channelTimestamp; /* abs timestamp of last packet */ double m_fAudioCodecs; /* audioCodecs for the connect packet */ double m_fVideoCodecs; /* videoCodecs for the connect packet */ @@ -307,6 +318,7 @@ int RTMP_Connect0(RTMP *r, struct sockaddr *svc); int RTMP_Connect1(RTMP *r, RTMPPacket *cp); int RTMP_Serve(RTMP *r); + int RTMP_TLS_Accept(RTMP *r, void *ctx); int RTMP_ReadPacket(RTMP *r, RTMPPacket *packet); int RTMP_SendPacket(RTMP *r, RTMPPacket *packet, int queue); @@ -329,6 +341,9 @@ void RTMP_Free(RTMP *r); void RTMP_EnableWrite(RTMP *r); + void *RTMP_TLS_AllocServerContext(const char* cert, const char* key); + void RTMP_TLS_FreeServerContext(void *ctx); + int RTMP_LibVersion(void); void RTMP_UserInterrupt(void); /* user typed Ctrl-C */
View file
rtmpdump-2.3.99.git20111114.tar.bz2/librtmp/rtmp_sys.h -> rtmpdump-2.4.git20121102.tar.bz2/librtmp/rtmp_sys.h
Changed
@@ -61,21 +61,41 @@ #include "rtmp.h" #ifdef USE_POLARSSL +#include <polarssl/version.h> #include <polarssl/net.h> #include <polarssl/ssl.h> #include <polarssl/havege.h> +#if POLARSSL_VERSION_NUMBER < 0x01010000 +#define havege_random havege_rand +#endif typedef struct tls_ctx { havege_state hs; ssl_session ssn; } tls_ctx; +typedef struct tls_server_ctx { + havege_state *hs; + x509_cert cert; + rsa_context key; + ssl_session ssn; + const char *dhm_P, *dhm_G; +} tls_server_ctx; + #define TLS_CTX tls_ctx * #define TLS_client(ctx,s) s = malloc(sizeof(ssl_context)); ssl_init(s);\ ssl_set_endpoint(s, SSL_IS_CLIENT); ssl_set_authmode(s, SSL_VERIFY_NONE);\ - ssl_set_rng(s, havege_rand, &ctx->hs);\ + ssl_set_rng(s, havege_random, &ctx->hs);\ ssl_set_ciphersuites(s, ssl_default_ciphersuites);\ ssl_set_session(s, 1, 600, &ctx->ssn) +#define TLS_server(ctx,s) s = malloc(sizeof(ssl_context)); ssl_init(s);\ + ssl_set_endpoint(s, SSL_IS_SERVER); ssl_set_authmode(s, SSL_VERIFY_NONE);\ + ssl_set_rng(s, havege_random, ((tls_server_ctx*)ctx)->hs);\ + ssl_set_ciphersuites(s, ssl_default_ciphersuites);\ + ssl_set_session(s, 1, 600, &((tls_server_ctx*)ctx)->ssn);\ + ssl_set_own_cert(s, &((tls_server_ctx*)ctx)->cert, &((tls_server_ctx*)ctx)->key);\ + ssl_set_dh_param(s, ((tls_server_ctx*)ctx)->dhm_P, ((tls_server_ctx*)ctx)->dhm_G) #define TLS_setfd(s,fd) ssl_set_bio(s, net_recv, &fd, net_send, &fd) #define TLS_connect(s) ssl_handshake(s) +#define TLS_accept(s) ssl_handshake(s) #define TLS_read(s,b,l) ssl_read(s,(unsigned char *)b,l) #define TLS_write(s,b,l) ssl_write(s,(unsigned char *)b,l) #define TLS_shutdown(s) ssl_close_notify(s) @@ -89,8 +109,10 @@ } tls_ctx; #define TLS_CTX tls_ctx * #define TLS_client(ctx,s) gnutls_init((gnutls_session_t *)(&s), GNUTLS_CLIENT); gnutls_priority_set(s, ctx->prios); gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, ctx->cred) +#define TLS_server(ctx,s) gnutls_init((gnutls_session_t *)(&s), GNUTLS_SERVER); gnutls_priority_set_direct(s, "NORMAL", NULL); gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, ctx) #define TLS_setfd(s,fd) gnutls_transport_set_ptr(s, (gnutls_transport_ptr_t)(long)fd) #define TLS_connect(s) gnutls_handshake(s) +#define TLS_accept(s) gnutls_handshake(s) #define TLS_read(s,b,l) gnutls_record_recv(s,b,l) #define TLS_write(s,b,l) gnutls_record_send(s,b,l) #define TLS_shutdown(s) gnutls_bye(s, GNUTLS_SHUT_RDWR) @@ -99,8 +121,10 @@ #else /* USE_OPENSSL */ #define TLS_CTX SSL_CTX * #define TLS_client(ctx,s) s = SSL_new(ctx) +#define TLS_server(ctx,s) s = SSL_new(ctx) #define TLS_setfd(s,fd) SSL_set_fd(s,fd) #define TLS_connect(s) SSL_connect(s) +#define TLS_accept(s) SSL_accept(s) #define TLS_read(s,b,l) SSL_read(s,b,l) #define TLS_write(s,b,l) SSL_write(s,b,l) #define TLS_shutdown(s) SSL_shutdown(s)
View file
rtmpdump-2.3.99.git20111114.tar.bz2/rtmpdump.1 -> rtmpdump-2.4.git20121102.tar.bz2/rtmpdump.1
Changed
@@ -1,4 +1,4 @@ -.TH RTMPDUMP 1 "2011-07-20" "RTMPDump v2.4" +.TH RTMPDUMP 1 "2012-07-24" "RTMPDump v2.4" .\" Copyright 2011 Howard Chu. .\" Copying permitted according to the GNU General Public License V2. .SH NAME @@ -177,6 +177,12 @@ Name of live stream to subscribe to. Defaults to .IR playpath . .TP +.B \-\-realtime \-R +Download approximately in realtime, without attempting to speed up via +Pause/Unpause commands ("the BUFX hack"). +Useful for servers that jump backwards in time at the Unpause command. +Resuming and seeking in realtime streams is still possible. +.TP .B \-\-resume \-e Resume an incomplete RTMP download. .TP
View file
rtmpdump-2.3.99.git20111114.tar.bz2/rtmpdump.1.html -> rtmpdump-2.4.git20121102.tar.bz2/rtmpdump.1.html
Changed
@@ -6,7 +6,7 @@ <tr><td>RTMPDUMP(1)<td align="center"><td align="right">RTMPDUMP(1) </thead> <tfoot> -<tr><td>RTMPDump v2.4<td align="center">2011-07-20<td align="right">RTMPDUMP(1) +<tr><td>RTMPDump v2.4<td align="center">2012-07-24<td align="right">RTMPDUMP(1) </tfoot> <tbody><tr><td colspan="3"><br><br><ul> <!-- Copyright 2011 Howard Chu. @@ -34,6 +34,7 @@ [<b>−y</b><i> playpath</i>] [<b>−Y</b>] [<b>−v</b>] +[<b>−R</b>] [<b>−d</b><i> subscription</i>] [<b>−e</b>] [<b>−k</b><i> skip</i>] @@ -218,6 +219,15 @@ </dl> <p> <dl compact><dt> +<b>−−realtime −R</b> +<dd> +Download approximately in realtime, without attempting to speed up via +Pause/Unpause commands ("the BUFX hack"). +Useful for servers that jump backwards in time at the Unpause command. +Resuming and seeking in realtime streams is still possible. +</dl> +<p> +<dl compact><dt> <b>−−resume −e</b> <dd> Resume an incomplete RTMP download.
View file
rtmpdump-2.3.99.git20111114.tar.bz2/rtmpdump.c -> rtmpdump-2.4.git20121102.tar.bz2/rtmpdump.c
Changed
@@ -441,7 +441,7 @@ int Download(RTMP * rtmp, // connected RTMP object - FILE * file, uint32_t dSeek, uint32_t dStopOffset, double duration, int bResume, char *metaHeader, uint32_t nMetaHeaderSize, char *initialFrame, int initialFrameType, uint32_t nInitialFrameSize, int nSkipKeyFrames, int bStdoutMode, int bLiveStream, int bHashes, int bOverrideBufferTime, uint32_t bufferTime, double *percent) // percentage downloaded [out] + FILE * file, uint32_t dSeek, uint32_t dStopOffset, double duration, int bResume, char *metaHeader, uint32_t nMetaHeaderSize, char *initialFrame, int initialFrameType, uint32_t nInitialFrameSize, int nSkipKeyFrames, int bStdoutMode, int bLiveStream, int bRealtimeStream, int bHashes, int bOverrideBufferTime, uint32_t bufferTime, double *percent) // percentage downloaded [out] { int32_t now, lastUpdate; int bufferSize = 64 * 1024; @@ -492,6 +492,8 @@ bResume ? "Resuming" : "Starting", (double) size / 1024.0); } + if (bRealtimeStream) + RTMP_LogPrintf(" in approximately realtime (disabled BUFX speedup hack)\n"); } if (dStopOffset > 0) @@ -578,12 +580,14 @@ } } } -#ifdef _DEBUG else { +#ifdef _DEBUG RTMP_Log(RTMP_LOGDEBUG, "zero read!"); - } #endif + if (rtmp->m_read.status == RTMP_READ_EOF) + break; + } } while (!RTMP_ctrlC && nRead > -1 && RTMP_IsConnected(rtmp) && !RTMP_IsTimedout(rtmp)); @@ -638,6 +642,8 @@ ("\n%s: This program dumps the media content streamed over RTMP.\n\n", prog); RTMP_LogPrintf("--help|-h Prints this help screen.\n"); RTMP_LogPrintf + ("--url|-i url URL with options included (e.g. rtmp://host[:port]/path swfUrl=url tcUrl=url)\n"); + RTMP_LogPrintf ("--rtmp|-r url URL (e.g. rtmp://host[:port]/path)\n"); RTMP_LogPrintf ("--host|-n hostname Overrides the hostname in the rtmp url\n"); @@ -682,6 +688,8 @@ RTMP_LogPrintf ("--subscribe|-d string Stream name to subscribe to (otherwise defaults to playpath if live is specifed)\n"); RTMP_LogPrintf + ("--realtime|-R Don't attempt to speed up download via the Pause/Unpause BUFX hack\n"); + RTMP_LogPrintf ("--flv|-o string FLV output file name, if the file name is - print stream to stdout\n"); RTMP_LogPrintf ("--resume|-e Resume a partial RTMP download\n"); @@ -748,6 +756,7 @@ int protocol = RTMP_PROTOCOL_UNDEFINED; int retries = 0; int bLiveStream = FALSE; // is it a live stream? then we can't seek/resume + int bRealtimeStream = FALSE; // If true, disable the BUFX hack (be patient) int bHashes = FALSE; // display byte counters not hashes by default long int timeout = DEF_TIMEOUT; // timeout connection after 120 seconds @@ -755,6 +764,7 @@ uint32_t dStopOffset = 0; RTMP rtmp = { 0 }; + AVal fullUrl = { 0, 0 }; AVal swfUrl = { 0, 0 }; AVal tcUrl = { 0, 0 }; AVal pageUrl = { 0, 0 }; @@ -817,6 +827,7 @@ {"protocol", 1, NULL, 'l'}, {"playpath", 1, NULL, 'y'}, {"playlist", 0, NULL, 'Y'}, + {"url", 1, NULL, 'i'}, {"rtmp", 1, NULL, 'r'}, {"swfUrl", 1, NULL, 's'}, {"tcUrl", 1, NULL, 't'}, @@ -832,6 +843,7 @@ #endif {"flashVer", 1, NULL, 'f'}, {"live", 0, NULL, 'v'}, + {"realtime", 0, NULL, 'R'}, {"flv", 1, NULL, 'o'}, {"resume", 0, NULL, 'e'}, {"timeout", 1, NULL, 'm'}, @@ -851,7 +863,7 @@ while ((opt = getopt_long(argc, argv, - "hVveqzr:s:t:p:a:b:f:o:u:C:n:c:l:y:Ym:k:d:A:B:T:w:x:W:X:S:#j:", + "hVveqzRr:s:t:i:p:a:b:f:o:u:C:n:c:l:y:Ym:k:d:A:B:T:w:x:W:X:S:#j:", longopts, NULL)) != -1) { switch (opt) @@ -936,6 +948,9 @@ case 'v': bLiveStream = TRUE; // no seeking or resuming possible! break; + case 'R': + bRealtimeStream = TRUE; // seeking and resuming is still possible + break; case 'd': STR2AVAL(subscribepath, optarg); break; @@ -991,6 +1006,9 @@ } break; } + case 'i': + STR2AVAL(fullUrl, optarg); + break; case 's': STR2AVAL(swfUrl, optarg); break; @@ -1069,32 +1087,32 @@ } } - if (!hostname.av_len) + if (!hostname.av_len && !fullUrl.av_len) { RTMP_Log(RTMP_LOGERROR, "You must specify a hostname (--host) or url (-r \"rtmp://host[:port]/playpath\") containing a hostname"); return RD_FAILED; } - if (playpath.av_len == 0) + if (playpath.av_len == 0 && !fullUrl.av_len) { RTMP_Log(RTMP_LOGERROR, "You must specify a playpath (--playpath) or url (-r \"rtmp://host[:port]/playpath\") containing a playpath"); return RD_FAILED; } - if (protocol == RTMP_PROTOCOL_UNDEFINED) + if (protocol == RTMP_PROTOCOL_UNDEFINED && !fullUrl.av_len) { RTMP_Log(RTMP_LOGWARNING, "You haven't specified a protocol (--protocol) or rtmp url (-r), using default protocol RTMP"); protocol = RTMP_PROTOCOL_RTMP; } - if (port == -1) + if (port == -1 && !fullUrl.av_len) { RTMP_Log(RTMP_LOGWARNING, "You haven't specified a port (--port) or rtmp url (-r), using default port 1935"); port = 0; } - if (port == 0) + if (port == 0 && !fullUrl.av_len) { if (protocol & RTMP_FEATURE_SSL) port = 443; @@ -1176,12 +1194,23 @@ } } - RTMP_SetupStream(&rtmp, protocol, &hostname, port, &sockshost, &playpath, - &tcUrl, &swfUrl, &pageUrl, &app, &auth, &swfHash, swfSize, - &flashVer, &subscribepath, &usherToken, dSeek, dStopOffset, bLiveStream, timeout); + if (!fullUrl.av_len) + { + RTMP_SetupStream(&rtmp, protocol, &hostname, port, &sockshost, &playpath, + &tcUrl, &swfUrl, &pageUrl, &app, &auth, &swfHash, swfSize, + &flashVer, &subscribepath, &usherToken, dSeek, dStopOffset, bLiveStream, timeout); + } + else + { + if (RTMP_SetupURL(&rtmp, fullUrl.av_val) == FALSE) + { + RTMP_Log(RTMP_LOGERROR, "Couldn't parse URL: %s", fullUrl.av_val); + return RD_FAILED; + } + } /* Try to keep the stream moving if it pauses on us */ - if (!bLiveStream && !(protocol & RTMP_FEATURE_HTTP)) + if (!bLiveStream && !bRealtimeStream && !(protocol & RTMP_FEATURE_HTTP)) rtmp.Link.lFlags |= RTMP_LF_BUFX; off_t size = 0; @@ -1348,8 +1377,8 @@ nStatus = Download(&rtmp, file, dSeek, dStopOffset, duration, bResume, metaHeader, nMetaHeaderSize, initialFrame, - initialFrameType, nInitialFrameSize, - nSkipKeyFrames, bStdoutMode, bLiveStream, bHashes, + initialFrameType, nInitialFrameSize, nSkipKeyFrames, + bStdoutMode, bLiveStream, bRealtimeStream, bHashes, bOverrideBufferTime, bufferTime, &percent); free(initialFrame); initialFrame = NULL;
View file
rtmpdump-2.3.99.git20111114.tar.bz2/rtmpgw.c -> rtmpdump-2.4.git20121102.tar.bz2/rtmpgw.c
Changed
@@ -85,6 +85,7 @@ uint32_t bufferTime; char *rtmpurl; + AVal fullUrl; AVal playpath; AVal swfUrl; AVal tcUrl; @@ -469,14 +470,14 @@ } // do necessary checks right here to make sure the combined request of default values and GET parameters is correct - if (!req.hostname.av_len) + if (!req.hostname.av_len && !req.fullUrl.av_len) { RTMP_Log(RTMP_LOGERROR, "You must specify a hostname (--host) or url (-r \"rtmp://host[:port]/playpath\") containing a hostname"); status = "400 Missing Hostname"; goto filenotfound; } - if (req.playpath.av_len == 0) + if (req.playpath.av_len == 0 && !req.fullUrl.av_len) { RTMP_Log(RTMP_LOGERROR, "You must specify a playpath (--playpath) or url (-r \"rtmp://host[:port]/playpath\") containing a playpath"); @@ -484,19 +485,19 @@ goto filenotfound;; } - if (req.protocol == RTMP_PROTOCOL_UNDEFINED) + if (req.protocol == RTMP_PROTOCOL_UNDEFINED && !req.fullUrl.av_len) { RTMP_Log(RTMP_LOGWARNING, "You haven't specified a protocol (--protocol) or rtmp url (-r), using default protocol RTMP"); req.protocol = RTMP_PROTOCOL_RTMP; } - if (req.rtmpport == -1) + if (req.rtmpport == -1 && !req.fullUrl.av_len) { RTMP_Log(RTMP_LOGWARNING, "You haven't specified a port (--port) or rtmp url (-r), using default port"); req.rtmpport = 0; } - if (req.rtmpport == 0) + if (req.rtmpport == 0 && !req.fullUrl.av_len) { if (req.protocol & RTMP_FEATURE_SSL) req.rtmpport = 443; @@ -552,9 +553,20 @@ RTMP_Log(RTMP_LOGDEBUG, "Setting buffer time to: %dms", req.bufferTime); RTMP_Init(&rtmp); RTMP_SetBufferMS(&rtmp, req.bufferTime); - RTMP_SetupStream(&rtmp, req.protocol, &req.hostname, req.rtmpport, &req.sockshost, - &req.playpath, &req.tcUrl, &req.swfUrl, &req.pageUrl, &req.app, &req.auth, &req.swfHash, req.swfSize, &req.flashVer, &req.subscribepath, &req.usherToken, dSeek, req.dStopOffset, - req.bLiveStream, req.timeout); + if (!req.fullUrl.av_len) + { + RTMP_SetupStream(&rtmp, req.protocol, &req.hostname, req.rtmpport, &req.sockshost, + &req.playpath, &req.tcUrl, &req.swfUrl, &req.pageUrl, &req.app, &req.auth, &req.swfHash, req.swfSize, &req.flashVer, &req.subscribepath, &req.usherToken, dSeek, req.dStopOffset, + req.bLiveStream, req.timeout); + } + else + { + if (RTMP_SetupURL(&rtmp, req.fullUrl.av_val) == FALSE) + { + RTMP_Log(RTMP_LOGERROR, "Couldn't parse URL: %s", req.fullUrl.av_val); + return; + } + } /* backward compatibility, we always sent this as true before */ if (req.auth.av_len) rtmp.Link.lFlags |= RTMP_LF_AUTH; @@ -908,6 +920,9 @@ } break; } + case 'i': + STR2AVAL(req->fullUrl, arg); + break; case 's': STR2AVAL(req->swfUrl, arg); break; @@ -927,7 +942,7 @@ STR2AVAL(req->auth, arg); break; case 'C': - parseAMF(&req->extras, optarg, &req->edepth); + parseAMF(&req->extras, arg, &req->edepth); break; case 'm': req->timeout = atoi(arg); @@ -993,6 +1008,7 @@ int opt; struct option longopts[] = { {"help", 0, NULL, 'h'}, + {"url", 1, NULL, 'i'}, {"host", 1, NULL, 'n'}, {"port", 1, NULL, 'c'}, {"socks", 1, NULL, 'S'}, @@ -1040,7 +1056,7 @@ while ((opt = getopt_long(argc, argv, - "hvqVzr:s:t:p:a:f:u:n:c:l:y:m:d:D:A:B:T:g:w:x:W:X:S:j:", longopts, + "hvqVzr:s:t:i:p:a:f:u:n:c:l:y:m:d:D:A:B:T:g:w:x:W:X:S:j:", longopts, NULL)) != -1) { switch (opt) @@ -1050,6 +1066,8 @@ ("\nThis program serves media content streamed from RTMP onto HTTP.\n\n"); RTMP_LogPrintf("--help|-h Prints this help screen.\n"); RTMP_LogPrintf + ("--url|-i url URL with options included (e.g. rtmp://host[:port]/path swfUrl=url tcUrl=url)\n"); + RTMP_LogPrintf ("--rtmp|-r url URL (e.g. rtmp://host[:port]/path)\n"); RTMP_LogPrintf ("--host|-n hostname Overrides the hostname in the rtmp url\n");
View file
rtmpdump-2.3.99.git20111114.tar.bz2/rtmpsrv.c -> rtmpdump-2.4.git20121102.tar.bz2/rtmpsrv.c
Changed
@@ -92,6 +92,7 @@ } STREAMING_SERVER; STREAMING_SERVER *rtmpServer = 0; // server structure pointer +void *sslCtx = NULL; STREAMING_SERVER *startStreaming(const char *address, int port); void stopStreaming(STREAMING_SERVER * server); @@ -223,9 +224,6 @@ *enc++ = 0; *enc++ = 0; *enc++ = AMF_OBJECT_END; - *enc++ = 0; - *enc++ = 0; - *enc++ = AMF_OBJECT_END; packet.m_nBodySize = enc - packet.m_body; @@ -770,47 +768,40 @@ switch (packet->m_packetType) { - case 0x01: - // chunk size + case RTMP_PACKET_TYPE_CHUNK_SIZE: // HandleChangeChunkSize(r, packet); break; - case 0x03: - // bytes read report + case RTMP_PACKET_TYPE_BYTES_READ_REPORT: break; - case 0x04: - // ctrl + case RTMP_PACKET_TYPE_CONTROL: // HandleCtrl(r, packet); break; - case 0x05: - // server bw + case RTMP_PACKET_TYPE_SERVER_BW: // HandleServerBW(r, packet); break; - case 0x06: - // client bw + case RTMP_PACKET_TYPE_CLIENT_BW: // HandleClientBW(r, packet); break; - case 0x08: - // audio data + case RTMP_PACKET_TYPE_AUDIO: //RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize); break; - case 0x09: - // video data + case RTMP_PACKET_TYPE_VIDEO: //RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize); break; - case 0x0F: // flex stream send + case RTMP_PACKET_TYPE_FLEX_STREAM_SEND: break; - case 0x10: // flex shared object + case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT: break; - case 0x11: // flex message + case RTMP_PACKET_TYPE_FLEX_MESSAGE: { RTMP_Log(RTMP_LOGDEBUG, "%s, flex message, size %u bytes, not fully supported", __FUNCTION__, packet->m_nBodySize); @@ -830,16 +821,13 @@ RTMP_Close(r); break; } - case 0x12: - // metadata (notify) + case RTMP_PACKET_TYPE_INFO: break; - case 0x13: - /* shared object */ + case RTMP_PACKET_TYPE_SHARED_OBJECT: break; - case 0x14: - // invoke + case RTMP_PACKET_TYPE_INVOKE: RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %u bytes", __FUNCTION__, packet->m_nBodySize); //RTMP_LogHex(packet.m_body, packet.m_nBodySize); @@ -848,8 +836,7 @@ RTMP_Close(r); break; - case 0x16: - /* flv */ + case RTMP_PACKET_TYPE_FLASH_VIDEO: break; default: RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__, @@ -889,7 +876,7 @@ { server->state = STREAMING_IN_PROGRESS; - RTMP rtmp = { 0 }; /* our session with the real client */ + RTMP *rtmp = RTMP_Alloc(); /* our session with the real client */ RTMPPacket packet = { 0 }; // timeout for http requests @@ -909,38 +896,44 @@ } else { - RTMP_Init(&rtmp); - rtmp.m_sb.sb_socket = sockfd; - if (!RTMP_Serve(&rtmp)) + RTMP_Init(rtmp); + rtmp->m_sb.sb_socket = sockfd; + if (sslCtx && !RTMP_TLS_Accept(rtmp, sslCtx)) + { + RTMP_Log(RTMP_LOGERROR, "TLS handshake failed"); + goto cleanup; + } + if (!RTMP_Serve(rtmp)) { RTMP_Log(RTMP_LOGERROR, "Handshake failed"); goto cleanup; } } server->arglen = 0; - while (RTMP_IsConnected(&rtmp) && RTMP_ReadPacket(&rtmp, &packet)) + while (RTMP_IsConnected(rtmp) && RTMP_ReadPacket(rtmp, &packet)) { if (!RTMPPacket_IsReady(&packet)) continue; - ServePacket(server, &rtmp, &packet); + ServePacket(server, rtmp, &packet); RTMPPacket_Free(&packet); } cleanup: RTMP_LogPrintf("Closing connection... "); - RTMP_Close(&rtmp); + RTMP_Close(rtmp); /* Should probably be done by RTMP_Close() ... */ - rtmp.Link.playpath.av_val = NULL; - rtmp.Link.tcUrl.av_val = NULL; - rtmp.Link.swfUrl.av_val = NULL; - rtmp.Link.pageUrl.av_val = NULL; - rtmp.Link.app.av_val = NULL; - rtmp.Link.flashVer.av_val = NULL; - if (rtmp.Link.usherToken.av_val) + rtmp->Link.playpath.av_val = NULL; + rtmp->Link.tcUrl.av_val = NULL; + rtmp->Link.swfUrl.av_val = NULL; + rtmp->Link.pageUrl.av_val = NULL; + rtmp->Link.app.av_val = NULL; + rtmp->Link.flashVer.av_val = NULL; + if (rtmp->Link.usherToken.av_val) { - free(rtmp.Link.usherToken.av_val); - rtmp.Link.usherToken.av_val = NULL; + free(rtmp->Link.usherToken.av_val); + rtmp->Link.usherToken.av_val = NULL; } + RTMP_Free(rtmp); RTMP_LogPrintf("done!\n\n"); quit: @@ -1074,20 +1067,32 @@ main(int argc, char **argv) { int nStatus = RD_SUCCESS; + int i; // http streaming server char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0"; // 0.0.0.0 is any device char *rtmpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE; // streaming device, default 0.0.0.0 int nRtmpStreamingPort = 1935; // port + char *cert = NULL, *key = NULL; RTMP_LogPrintf("RTMP Server %s\n", RTMPDUMP_VERSION); RTMP_LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n"); RTMP_debuglevel = RTMP_LOGINFO; - if (argc > 1 && !strcmp(argv[1], "-z")) - RTMP_debuglevel = RTMP_LOGALL; + for (i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "-z")) + RTMP_debuglevel = RTMP_LOGALL; + else if (!strcmp(argv[i], "-c") && i + 1 < argc) + cert = argv[++i]; + else if (!strcmp(argv[i], "-k") && i + 1 < argc) + key = argv[++i]; + } + + if (cert && key) + sslCtx = RTMP_TLS_AllocServerContext(cert, key); // init request memset(&defaultRTMPRequest, 0, sizeof(RTMP_REQUEST)); @@ -1131,6 +1136,9 @@ } RTMP_Log(RTMP_LOGDEBUG, "Done, exiting..."); + if (sslCtx) + RTMP_TLS_FreeServerContext(sslCtx); + CleanupSockets(); #ifdef _DEBUG
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.