[Live-devel] RTSP server
RF
horos2004 at hotmail.com
Sun Feb 8 13:19:19 PST 2004
Hi,
I have experienced some troubles with the RTSP server. The problem is the
incomingRequestHandler1 function which assumes that the full RTSP header is
received in one call to readSocket, this is not always the case and the
function should call readSocket until an empty line is received (i.e
"...\r\n\r\n"). To reproduce the problem you can connect with a telnet
client and try to type a RTSP message, the server replies immediatly with a
bad request error after only receiving the first characters. I have patched
the related code, it would be nice if you could include the correction in
the next releases. The proposed correction is probably not complete, but at
least it works with my client application.
Thanks in advance,
Régis Fénéon
file: liveMedia/RTSPServer.cpp
/* ... */
void RTSPServer::RTSPClientSession::incomingRequestHandler1() {
struct sockaddr_in dummy; // 'from' address, meaningless in this case
int bytesLeft, totalBytes, endOfMsg;
unsigned char *Ptr, *lastCrLf;
Ptr = fBuffer;
lastCrLf = Ptr-1;
bytesLeft = sizeof fBuffer;
totalBytes = 0;
endOfMsg = 0;
while( !endOfMsg) {
unsigned char *tmp_ptr;
int i;
if( bytesLeft <= 0) {
// command too big
delete this;
return;
}
int bytesRead = readSocket(envir(), fClientSocket,
Ptr, bytesLeft, dummy);
if (bytesRead <= 0) {
// The client socket has apparently died - kill it:
delete this;
return;
}
#ifdef DEBUG
Ptr[bytesRead] = 0;
fprintf(stderr, "RTSPClientSession[%p]::incomingRequestHandler1() read
%d bytes:%s\n", this, bytesRead, Ptr);
#endif
/* look for end of message */
tmp_ptr = Ptr;
for( i=0; i<bytesRead; i++) {
if( *tmp_ptr == '\n') {
if( (tmp_ptr - lastCrLf) == 2) {
/* empty line */
endOfMsg = 1;
break;
}
lastCrLf = tmp_ptr;
}
tmp_ptr++;
}
bytesLeft -= bytesRead;
totalBytes += bytesRead;
Ptr += bytesRead;
}
fBuffer[totalBytes] = '\0';
// Parse the request string into command name and 'CSeq',
// then handle the command:
char cmdName[PARAM_STRING_MAX];
char urlPreSuffix[PARAM_STRING_MAX];
char urlSuffix[PARAM_STRING_MAX];
char cseq[PARAM_STRING_MAX];
if (!parseRequestString((char*)fBuffer, totalBytes /*bytesRead*/,
cmdName, sizeof cmdName,
urlPreSuffix, sizeof urlPreSuffix,
urlSuffix, sizeof urlSuffix,
cseq, sizeof cseq)) {
#ifdef DEBUG
fprintf(stderr, "parseRequestString() failed!\n");
#endif
handleCmd_bad(cseq);
} else {
/* ... */
More information about the live-devel
mailing list