liveMedia/include/RTSPCommon.hh File Reference

#include "Boolean.hh"

Include dependency graph for RTSPCommon.hh:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define _strncasecmp   strncasecmp
#define RTSP_PARAM_STRING_MAX   100

Functions

Boolean parseRTSPRequestString (char const *reqStr, unsigned reqStrSize, char *resultCmdName, unsigned resultCmdNameMaxSize, char *resultURLPreSuffix, unsigned resultURLPreSuffixMaxSize, char *resultURLSuffix, unsigned resultURLSuffixMaxSize, char *resultCSeq, unsigned resultCSeqMaxSize)
Boolean parseRangeHeader (char const *buf, float &rangeStart, float &rangeEnd)


Define Documentation

#define _strncasecmp   strncasecmp

Definition at line 32 of file RTSPCommon.hh.

Referenced by parseAuthorizationHeader(), RTSPClient::parseGetParameterHeader(), parsePlayNowHeader(), parseRangeHeader(), RTSPClient::parseRTPInfoHeader(), RTSPClient::parseRTSPURL(), RTSPClient::parseRTSPURLUsernamePassword(), parseScaleHeader(), RTSPClient::parseScaleHeader(), SIPClient::parseSIPURL(), SIPClient::parseSIPURLUsernamePassword(), parseTransportHeader(), RTSPClient::parseTransportResponse(), and RTSPClient::sendOptionsCmd().

#define RTSP_PARAM_STRING_MAX   100

Definition at line 35 of file RTSPCommon.hh.

Referenced by RTSPServer::RTSPClientSession::incomingRequestHandler1(), and RTSPClient::incomingRequestHandler1().


Function Documentation

Boolean parseRangeHeader ( char const *  buf,
float &  rangeStart,
float &  rangeEnd 
)

Definition at line 137 of file RTSPCommon.cpp.

References _strncasecmp, False, and True.

Referenced by RTSPServer::RTSPClientSession::handleCmd_PLAY(), RTSPServer::RTSPClientSession::handleCmd_SETUP(), RTSPClient::playMediaSession(), and RTSPClient::playMediaSubsession().

00137                                                                               {
00138   // First, find "Range:"
00139   while (1) {
00140     if (*buf == '\0') return False; // not found
00141     if (_strncasecmp(buf, "Range: ", 7) == 0) break;
00142     ++buf;
00143   }
00144 
00145   // Then, run through each of the fields, looking for ones we handle:
00146   char const* fields = buf + 7;
00147   while (*fields == ' ') ++fields;
00148   float start, end;
00149   Locale("C", LC_NUMERIC);
00150   if (sscanf(fields, "npt = %f - %f", &start, &end) == 2) {
00151     rangeStart = start;
00152     rangeEnd = end;
00153   } else if (sscanf(fields, "npt = %f -", &start) == 1) {
00154     rangeStart = start;
00155     rangeEnd = 0.0;
00156   } else {
00157     return False; // The header is malformed
00158   }
00159 
00160   return True;
00161 }

Boolean parseRTSPRequestString ( char const *  reqStr,
unsigned  reqStrSize,
char *  resultCmdName,
unsigned  resultCmdNameMaxSize,
char *  resultURLPreSuffix,
unsigned  resultURLPreSuffixMaxSize,
char *  resultURLSuffix,
unsigned  resultURLSuffixMaxSize,
char *  resultCSeq,
unsigned  resultCSeqMaxSize 
)

Definition at line 26 of file RTSPCommon.cpp.

References False, and True.

Referenced by RTSPServer::RTSPClientSession::incomingRequestHandler1(), and RTSPClient::incomingRequestHandler1().

00035                                                            {
00036   // This parser is currently rather dumb; it should be made smarter #####
00037 
00038   // Read everything up to the first space as the command name:
00039   Boolean parseSucceeded = False;
00040   unsigned i;
00041   for (i = 0; i < resultCmdNameMaxSize-1 && i < reqStrSize; ++i) {
00042     char c = reqStr[i];
00043     if (c == ' ' || c == '\t') {
00044       parseSucceeded = True;
00045       break;
00046     }
00047 
00048     resultCmdName[i] = c;
00049   }
00050   resultCmdName[i] = '\0';
00051   if (!parseSucceeded) return False;
00052 
00053   // Skip over the prefix of any "rtsp://" or "rtsp:/" URL that follows:
00054   unsigned j = i+1;
00055   while (j < reqStrSize && (reqStr[j] == ' ' || reqStr[j] == '\t')) ++j; // skip over any additional white space
00056   for (j = i+1; (int)j < (int)(reqStrSize-8); ++j) {
00057     if ((reqStr[j] == 'r' || reqStr[j] == 'R')
00058         && (reqStr[j+1] == 't' || reqStr[j+1] == 'T')
00059         && (reqStr[j+2] == 's' || reqStr[j+2] == 'S')
00060         && (reqStr[j+3] == 'p' || reqStr[j+3] == 'P')
00061         && reqStr[j+4] == ':' && reqStr[j+5] == '/') {
00062       j += 6;
00063       if (reqStr[j] == '/') {
00064         // This is a "rtsp://" URL; skip over the host:port part that follows:
00065         ++j;
00066         while (j < reqStrSize && reqStr[j] != '/' && reqStr[j] != ' ') ++j;
00067       } else {
00068         // This is a "rtsp:/" URL; back up to the "/":
00069         --j;
00070       }
00071       i = j;
00072       break;
00073     }
00074   }
00075 
00076   // Look for the URL suffix (before the following "RTSP/"):
00077   parseSucceeded = False;
00078   for (unsigned k = i+1; (int)k < (int)(reqStrSize-5); ++k) {
00079     if (reqStr[k] == 'R' && reqStr[k+1] == 'T' &&
00080         reqStr[k+2] == 'S' && reqStr[k+3] == 'P' && reqStr[k+4] == '/') {
00081       while (--k >= i && reqStr[k] == ' ') {} // go back over all spaces before "RTSP/"
00082       unsigned k1 = k;
00083       while (k1 > i && reqStr[k1] != '/') --k1;
00084       // the URL suffix comes from [k1+1,k]
00085 
00086       // Copy "resultURLSuffix":
00087       if (k - k1 + 1 > resultURLSuffixMaxSize) return False; // there's no room
00088       unsigned n = 0, k2 = k1+1;
00089       while (k2 <= k) resultURLSuffix[n++] = reqStr[k2++];
00090       resultURLSuffix[n] = '\0';
00091 
00092       // Also look for the URL 'pre-suffix' before this:
00093       unsigned k3 = --k1;
00094       while (k3 > i && reqStr[k3] != '/') --k3;
00095       // the URL pre-suffix comes from [k3+1,k1]
00096 
00097       // Copy "resultURLPreSuffix":
00098       if (k1 - k3 + 1 > resultURLPreSuffixMaxSize) return False; // there's no room
00099       n = 0; k2 = k3+1;
00100       while (k2 <= k1) resultURLPreSuffix[n++] = reqStr[k2++];
00101       resultURLPreSuffix[n] = '\0';
00102 
00103       i = k + 7; // to go past " RTSP/"
00104       parseSucceeded = True;
00105       break;
00106     }
00107   }
00108   if (!parseSucceeded) return False;
00109 
00110   // Look for "CSeq:", skip whitespace,
00111   // then read everything up to the next \r or \n as 'CSeq':
00112   parseSucceeded = False;
00113   for (j = i; (int)j < (int)(reqStrSize-5); ++j) {
00114     if (reqStr[j] == 'C' && reqStr[j+1] == 'S' && reqStr[j+2] == 'e' &&
00115         reqStr[j+3] == 'q' && reqStr[j+4] == ':') {
00116       j += 5;
00117       unsigned n;
00118       while (j < reqStrSize && (reqStr[j] ==  ' ' || reqStr[j] == '\t')) ++j;
00119       for (n = 0; n < resultCSeqMaxSize-1 && j < reqStrSize; ++n,++j) {
00120         char c = reqStr[j];
00121         if (c == '\r' || c == '\n') {
00122           parseSucceeded = True;
00123           break;
00124         }
00125 
00126         resultCSeq[n] = c;
00127       }
00128       resultCSeq[n] = '\0';
00129       break;
00130     }
00131   }
00132   if (!parseSucceeded) return False;
00133 
00134   return True;
00135 }


Generated on Tue Oct 7 15:39:01 2008 for live by  doxygen 1.5.2