Skip to content

Commit

Permalink
ksv's patch
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Sep 4, 2013
1 parent 5ba573a commit 7491f32
Show file tree
Hide file tree
Showing 16 changed files with 6,936 additions and 395 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -32,7 +32,7 @@ BINDIR=$(DESTDIR)$(bindir)
SBINDIR=$(DESTDIR)$(sbindir)
MANDIR=$(DESTDIR)$(mandir)

LIBS_posix=
LIBS_posix=-lm
LIBS_darwin=
LIBS_mingw=-lws2_32 -lwinmm -lgdi32
LIB_RTMP=-Llibrtmp -lrtmp
Expand Down
2 changes: 1 addition & 1 deletion librtmp/Makefile
Expand Up @@ -25,7 +25,7 @@ DEF_=-DNO_CRYPTO
REQ_GNUTLS=gnutls
REQ_OPENSSL=libssl,libcrypto
LIBZ=-lz
LIBS_posix=
LIBS_posix=-lm
LIBS_darwin=
LIBS_mingw=-lws2_32 -lwinmm -lgdi32
LIB_GNUTLS=-lgnutls -lhogweed -lnettle -lgmp $(LIBZ)
Expand Down
25 changes: 16 additions & 9 deletions librtmp/amf.c
Expand Up @@ -618,6 +618,9 @@ AMFProp_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize,
return -1;
}

if (*pBuffer == AMF_NULL)
bDecodeName = 0;

if (bDecodeName && nSize < 4)
{ /* at least name (length + at least 1 byte) and 1 byte of data */
RTMP_Log(RTMP_LOGDEBUG,
Expand Down Expand Up @@ -729,13 +732,13 @@ AMFProp_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize,
}
case AMF_DATE:
{
RTMP_Log(RTMP_LOGDEBUG, "AMF_DATE");

if (nSize < 10)
return -1;

prop->p_vu.p_number = AMF_DecodeNumber(pBuffer);
prop->p_UTCoffset = AMF_DecodeInt16(pBuffer + 8);
RTMP_Log(RTMP_LOGDEBUG, "AMF_DATE: %f, UTC offset: %d", prop->p_vu.p_number,
prop->p_UTCoffset);

nSize -= 10;
break;
Expand Down Expand Up @@ -807,8 +810,8 @@ AMFProp_Dump(AMFObjectProperty *prop)
}
else
{
name.av_val = "no-name.";
name.av_len = sizeof("no-name.") - 1;
name.av_val = "no-name";
name.av_len = sizeof ("no-name") - 1;
}
if (name.av_len > 18)
name.av_len = 18;
Expand Down Expand Up @@ -1074,10 +1077,13 @@ AMF3_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bAMFData)

for (i = 0; i < cd.cd_num; i++)
{
AVal memberName;
len = AMF3ReadString(pBuffer, &memberName);
RTMP_Log(RTMP_LOGDEBUG, "Member: %s", memberName.av_val);
AMF3CD_AddProp(&cd, &memberName);
AVal memberName = {NULL, 0};
len = AMF3ReadString(pBuffer, &memberName);
if (memberName.av_val)
{
RTMP_Log(RTMP_LOGDEBUG, "Member: %s", memberName.av_val);
AMF3CD_AddProp(&cd, &memberName);
}
nSize -= len;
pBuffer += len;
}
Expand Down Expand Up @@ -1258,7 +1264,8 @@ AMF3CD_AddProp(AMF3ClassDef *cd, AVal *prop)
{
if (!(cd->cd_num & 0x0f))
cd->cd_props = realloc(cd->cd_props, (cd->cd_num + 16) * sizeof(AVal));
cd->cd_props[cd->cd_num++] = *prop;
if (cd->cd_props)
cd->cd_props[cd->cd_num++] = *prop;
}

AVal *
Expand Down
22 changes: 16 additions & 6 deletions librtmp/handshake.h
Expand Up @@ -760,7 +760,7 @@ HandShake(RTMP * r, int FP9HandShake)
#else
ip = (int32_t *)(clientsig+8);
for (i = 2; i < RTMP_SIG_SIZE/4; i++)
*ip++ = rand();
*ip++ = ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
#endif

/* set handshake digest */
Expand Down Expand Up @@ -914,7 +914,7 @@ HandShake(RTMP * r, int FP9HandShake)
#else
ip = (int32_t *)reply;
for (i = 0; i < RTMP_SIG_SIZE/4; i++)
*ip++ = rand();
*ip++ = ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
#endif
/* calculate response now */
signatureResp = reply+RTMP_SIG_SIZE-SHA256_DIGEST_LENGTH;
Expand Down Expand Up @@ -965,8 +965,18 @@ HandShake(RTMP * r, int FP9HandShake)
__FUNCTION__);
RTMP_LogHex(RTMP_LOGDEBUG, reply, RTMP_SIG_SIZE);
#endif
if (!WriteN(r, (char *)reply, RTMP_SIG_SIZE))
return FALSE;
if (r->Link.CombineConnectPacket)
{
char *HandshakeResponse = malloc(RTMP_SIG_SIZE);
memcpy(HandshakeResponse, (char *) reply, RTMP_SIG_SIZE);
r->Link.HandshakeResponse.av_val = HandshakeResponse;
r->Link.HandshakeResponse.av_len = RTMP_SIG_SIZE;
}
else
{
if (!WriteN(r, (char *) reply, RTMP_SIG_SIZE))
return FALSE;
}

/* 2nd part of handshake */
if (ReadN(r, (char *)serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE)
Expand Down Expand Up @@ -1099,7 +1109,7 @@ SHandShake(RTMP * r)
{
encrypted = FALSE;
}
else if (type == 6 || type == 8)
else if (type == 6 || type == 8 || type == 9)
{
offalg = 1;
encrypted = TRUE;
Expand Down Expand Up @@ -1148,7 +1158,7 @@ SHandShake(RTMP * r)
#else
ip = (int32_t *)(serversig+8);
for (i = 2; i < RTMP_SIG_SIZE/4; i++)
*ip++ = rand();
*ip++ = ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
#endif

/* set handshake digest */
Expand Down
12 changes: 8 additions & 4 deletions librtmp/hashswf.c
Expand Up @@ -70,7 +70,7 @@ extern TLS_CTX RTMP_TLS_ctx;

#endif /* CRYPTO */

#define AGENT "Mozilla/5.0"
#define AGENT "Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1"

HTTPResult
HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb)
Expand Down Expand Up @@ -116,6 +116,8 @@ HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb)

host = p1 + 3;
path = strchr(host, '/');
if (!path)
return HTTPRES_BAD_REQUEST;
hlen = path - host;
strncpy(hbuf, host, hlen);
hbuf[hlen] = '\0';
Expand Down Expand Up @@ -200,7 +202,7 @@ HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb)
}

p1 = strchr(sb.sb_buf, ' ');
rc = atoi(p1 + 1);
rc = p1 ? atoi(p1 + 1) : 400;
http->status = rc;

if (rc >= 300)
Expand Down Expand Up @@ -528,9 +530,11 @@ RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,

if (strncmp(buf, "url: ", 5))
continue;
if (strncmp(buf + 5, url, hlen))
if (strncmp(buf + 5, url, strlen(buf + 5) - 1))
continue;
r1 = strrchr(buf, '/');
if (!r1)
continue;
i = strlen(r1);
r1[--i] = '\0';
if (strncmp(r1, file, i))
Expand Down Expand Up @@ -640,7 +644,7 @@ RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
HMAC_finish(in.ctx, hash, hlen);
*size = in.size;

fprintf(f, "date: %s\n", date);
fprintf(f, "date: %s\n", date[0] ? date : cctim);
fprintf(f, "size: %08x\n", in.size);
fprintf(f, "hash: ");
for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
Expand Down
4 changes: 2 additions & 2 deletions librtmp/log.c
Expand Up @@ -52,8 +52,8 @@ static void rtmp_log_default(int level, const char *format, va_list vl)
vsnprintf(str, MAX_PRINT_LEN-1, format, vl);

/* Filter out 'no-name' */
if ( RTMP_debuglevel<RTMP_LOGALL && strstr(str, "no-name" ) != NULL )
return;
if (RTMP_debuglevel < RTMP_LOGDEBUG && strstr(str, "no-name") != NULL)
return;

if ( !fmsg ) fmsg = stderr;

Expand Down
19 changes: 13 additions & 6 deletions librtmp/parseurl.c
Expand Up @@ -140,11 +140,16 @@ int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port
char *slash2, *slash3 = NULL, *slash4 = NULL;
int applen, appnamelen;

slash2 = strchr(p, '/');
if(slash2)
slash3 = strchr(slash2+1, '/');
if(slash3)
slash4 = strchr(slash3+1, '/');
if ((slash2 = strstr(p, "//")))
slash2 += 1;
else
{
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 */
Expand All @@ -170,7 +175,9 @@ int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port

app->av_val = p;
app->av_len = applen;
RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p);
if (app->av_val[app->av_len - 1] == '/')
app->av_len -= 1;
RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", app->av_len, app->av_val);

p += appnamelen;
}
Expand Down

0 comments on commit 7491f32

Please sign in to comment.