From 347c00e05fd9bb795bab948e05843d8575865b6e Mon Sep 17 00:00:00 2001 From: hyc Date: Mon, 4 Jan 2010 06:59:48 +0000 Subject: [PATCH] Cleanup filename some more, close immediately if client goes away and we don't have an active stream from the server. git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@179 400ebc74-4327-4243-bc38-086b20814532 --- rtmpsuck.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/rtmpsuck.c b/rtmpsuck.c index 4168deb..0b1e092 100644 --- a/rtmpsuck.c +++ b/rtmpsuck.c @@ -307,25 +307,33 @@ ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *b } else if (AVMATCH(&method, &av_play)) { - char *file, *p; + AVal av; + char *file, *p, *q; char flvHeader[] = { 'F', 'L', 'V', 0x01, 0x05, // video + audio, we finalize later if the value is different 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00 // first prevTagSize=0 }; - AMFProp_GetString(AMF_GetProp(&obj, NULL, 3), &server->rc.Link.playpath); - file = malloc(server->rc.Link.playpath.av_len+1); - memcpy(file, server->rc.Link.playpath.av_val, server->rc.Link.playpath.av_len); - file[server->rc.Link.playpath.av_len] = '\0'; - for (p=file; *p; p++) - if (*p == '/' || *p == ':') - *p = '_'; - else if (*p == '?') + AMFProp_GetString(AMF_GetProp(&obj, NULL, 3), &av); + server->rc.Link.playpath = av; + q = strchr(av.av_val, '?'); + if (q) + av.av_len = q - av.av_val; + for (p=av.av_val+av.av_len-1; p>=av.av_val; p--) + if (*p == '/') { - *p = '\0'; + p++; + av.av_len -= p - av.av_val; + av.av_val = p; break; } + file = malloc(av.av_len+1); + memcpy(file, av.av_val, av.av_len); + file[av.av_len] = '\0'; + for (p=file; *p; p++) + if (*p == ':') + *p = '_'; LogPrintf("Playpath: %.*s\nSaving as: %s\n", server->rc.Link.playpath.av_len, server->rc.Link.playpath.av_val, file); @@ -334,6 +342,7 @@ ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *b ret = 1; else fwrite(flvHeader, 1, sizeof(flvHeader), server->out); + free(file); } else if (AVMATCH(&method, &av_onStatus)) { @@ -870,6 +879,9 @@ void doServe(STREAMING_SERVER * server, // server socket and state (our listenin break; } } + if (!RTMP_IsConnected(&server->rs) && RTMP_IsConnected(&server->rc) + && !server->out) + RTMP_Close(&server->rc); } cleanup: -- 2.40.0