#include "RTSPServer.hh"#include "RTSPCommon.hh"#include "Base64.hh"#include <GroupsockHelper.hh>Include dependency graph for RTSPServer.cpp:

Go to the source code of this file.
Defines | |
| #define | LISTEN_BACKLOG_SIZE 20 |
Enumerations | |
| enum | StreamingMode { RTP_UDP, RTP_TCP, RAW_UDP } |
Functions | |
| static void | lookForHeader (char const *headerName, char const *source, unsigned sourceLen, char *resultStr, unsigned resultMaxSize) |
| static Boolean | parseAuthorizationHeader (char const *buf, char const *&username, char const *&realm, char const *&nonce, char const *&uri, char const *&response) |
| static void | parseTransportHeader (char const *buf, StreamingMode &streamingMode, char *&streamingModeString, char *&destinationAddressStr, u_int8_t &destinationTTL, portNumBits &clientRTPPortNum, portNumBits &clientRTCPPortNum, unsigned char &rtpChannelId, unsigned char &rtcpChannelId) |
| static Boolean | parsePlayNowHeader (char const *buf) |
| static Boolean | parseScaleHeader (char const *buf, float &scale) |
Variables | |
| static char const * | allowedCommandNames = "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER" |
| #define LISTEN_BACKLOG_SIZE 20 |
| enum StreamingMode |
Definition at line 1133 of file RTSPServer.cpp.
01133 { 01134 RTP_UDP, 01135 RTP_TCP, 01136 RAW_UDP 01137 } StreamingMode;
| static void lookForHeader | ( | char const * | headerName, | |
| char const * | source, | |||
| unsigned | sourceLen, | |||
| char * | resultStr, | |||
| unsigned | resultMaxSize | |||
| ) | [static] |
Definition at line 432 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientConnection::parseHTTPRequestString().
00432 { 00433 resultStr[0] = '\0'; // by default, return an empty string 00434 unsigned headerNameLen = strlen(headerName); 00435 for (int i = 0; i < (int)(sourceLen-headerNameLen); ++i) { 00436 if (strncmp(&source[i], headerName, headerNameLen) == 0 && source[i+headerNameLen] == ':') { 00437 // We found the header. Skip over any whitespace, then copy the rest of the line to "resultStr": 00438 for (i += headerNameLen+1; i < (int)sourceLen && (source[i] == ' ' || source[i] == '\t'); ++i) {} 00439 for (unsigned j = i; j < sourceLen; ++j) { 00440 if (source[j] == '\r' || source[j] == '\n') { 00441 // We've found the end of the line. Copy it to the result (if it will fit): 00442 if (j-i+1 > resultMaxSize) break; 00443 char const* resultSource = &source[i]; 00444 char const* resultSourceEnd = &source[j]; 00445 while (resultSource < resultSourceEnd) *resultStr++ = *resultSource++; 00446 *resultStr = '\0'; 00447 break; 00448 } 00449 } 00450 } 00451 } 00452 }
| static Boolean parseAuthorizationHeader | ( | char const * | buf, | |
| char const *& | username, | |||
| char const *& | realm, | |||
| char const *& | nonce, | |||
| char const *& | uri, | |||
| char const *& | response | |||
| ) | [static] |
Definition at line 885 of file RTSPServer.cpp.
References _strncasecmp, False, NULL, strDup(), strDupSize(), and True.
Referenced by RTSPServer::RTSPClientConnection::authenticationOK().
00889 { 00890 // Initialize the result parameters to default values: 00891 username = realm = nonce = uri = response = NULL; 00892 00893 // First, find "Authorization:" 00894 while (1) { 00895 if (*buf == '\0') return False; // not found 00896 if (_strncasecmp(buf, "Authorization: Digest ", 22) == 0) break; 00897 ++buf; 00898 } 00899 00900 // Then, run through each of the fields, looking for ones we handle: 00901 char const* fields = buf + 22; 00902 while (*fields == ' ') ++fields; 00903 char* parameter = strDupSize(fields); 00904 char* value = strDupSize(fields); 00905 while (1) { 00906 value[0] = '\0'; 00907 if (sscanf(fields, "%[^=]=\"%[^\"]\"", parameter, value) != 2 && 00908 sscanf(fields, "%[^=]=\"\"", parameter) != 1) { 00909 break; 00910 } 00911 if (strcmp(parameter, "username") == 0) { 00912 username = strDup(value); 00913 } else if (strcmp(parameter, "realm") == 0) { 00914 realm = strDup(value); 00915 } else if (strcmp(parameter, "nonce") == 0) { 00916 nonce = strDup(value); 00917 } else if (strcmp(parameter, "uri") == 0) { 00918 uri = strDup(value); 00919 } else if (strcmp(parameter, "response") == 0) { 00920 response = strDup(value); 00921 } 00922 00923 fields += strlen(parameter) + 2 /*="*/ + strlen(value) + 1 /*"*/; 00924 while (*fields == ',' || *fields == ' ') ++fields; 00925 // skip over any separating ',' and ' ' chars 00926 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 00927 } 00928 delete[] parameter; delete[] value; 00929 return True; 00930 }
| static Boolean parsePlayNowHeader | ( | char const * | buf | ) | [static] |
Definition at line 1203 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
01203 { 01204 // Find "x-playNow:" header, if present 01205 while (1) { 01206 if (*buf == '\0') return False; // not found 01207 if (_strncasecmp(buf, "x-playNow:", 10) == 0) break; 01208 ++buf; 01209 } 01210 01211 return True; 01212 }
| static Boolean parseScaleHeader | ( | char const * | buf, | |
| float & | scale | |||
| ) | [static] |
Definition at line 1554 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_PLAY().
01554 { 01555 // Initialize the result parameter to a default value: 01556 scale = 1.0; 01557 01558 // First, find "Scale:" 01559 while (1) { 01560 if (*buf == '\0') return False; // not found 01561 if (_strncasecmp(buf, "Scale:", 6) == 0) break; 01562 ++buf; 01563 } 01564 01565 // Then, run through each of the fields, looking for ones we handle: 01566 char const* fields = buf + 6; 01567 while (*fields == ' ') ++fields; 01568 float sc; 01569 if (sscanf(fields, "%f", &sc) == 1) { 01570 scale = sc; 01571 } else { 01572 return False; // The header is malformed 01573 } 01574 01575 return True; 01576 }
| static void parseTransportHeader | ( | char const * | buf, | |
| StreamingMode & | streamingMode, | |||
| char *& | streamingModeString, | |||
| char *& | destinationAddressStr, | |||
| u_int8_t & | destinationTTL, | |||
| portNumBits & | clientRTPPortNum, | |||
| portNumBits & | clientRTCPPortNum, | |||
| unsigned char & | rtpChannelId, | |||
| unsigned char & | rtcpChannelId | |||
| ) | [static] |
Definition at line 1139 of file RTSPServer.cpp.
References _strncasecmp, NULL, RAW_UDP, RTP_TCP, RTP_UDP, strDup(), and strDupSize().
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
01148 { 01149 // Initialize the result parameters to default values: 01150 streamingMode = RTP_UDP; 01151 streamingModeString = NULL; 01152 destinationAddressStr = NULL; 01153 destinationTTL = 255; 01154 clientRTPPortNum = 0; 01155 clientRTCPPortNum = 1; 01156 rtpChannelId = rtcpChannelId = 0xFF; 01157 01158 portNumBits p1, p2; 01159 unsigned ttl, rtpCid, rtcpCid; 01160 01161 // First, find "Transport:" 01162 while (1) { 01163 if (*buf == '\0') return; // not found 01164 if (*buf == '\r' && *(buf+1) == '\n' && *(buf+2) == '\r') return; // end of the headers => not found 01165 if (_strncasecmp(buf, "Transport:", 10) == 0) break; 01166 ++buf; 01167 } 01168 01169 // Then, run through each of the fields, looking for ones we handle: 01170 char const* fields = buf + 10; 01171 while (*fields == ' ') ++fields; 01172 char* field = strDupSize(fields); 01173 while (sscanf(fields, "%[^;\r\n]", field) == 1) { 01174 if (strcmp(field, "RTP/AVP/TCP") == 0) { 01175 streamingMode = RTP_TCP; 01176 } else if (strcmp(field, "RAW/RAW/UDP") == 0 || 01177 strcmp(field, "MP2T/H2221/UDP") == 0) { 01178 streamingMode = RAW_UDP; 01179 streamingModeString = strDup(field); 01180 } else if (_strncasecmp(field, "destination=", 12) == 0) { 01181 delete[] destinationAddressStr; 01182 destinationAddressStr = strDup(field+12); 01183 } else if (sscanf(field, "ttl%u", &ttl) == 1) { 01184 destinationTTL = (u_int8_t)ttl; 01185 } else if (sscanf(field, "client_port=%hu-%hu", &p1, &p2) == 2) { 01186 clientRTPPortNum = p1; 01187 clientRTCPPortNum = streamingMode == RAW_UDP ? 0 : p2; // ignore the second port number if the client asked for raw UDP 01188 } else if (sscanf(field, "client_port=%hu", &p1) == 1) { 01189 clientRTPPortNum = p1; 01190 clientRTCPPortNum = streamingMode == RAW_UDP ? 0 : p1 + 1; 01191 } else if (sscanf(field, "interleaved=%u-%u", &rtpCid, &rtcpCid) == 2) { 01192 rtpChannelId = (unsigned char)rtpCid; 01193 rtcpChannelId = (unsigned char)rtcpCid; 01194 } 01195 01196 fields += strlen(field); 01197 while (*fields == ';') ++fields; // skip over separating ';' chars 01198 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 01199 } 01200 delete[] field; 01201 }
char const* allowedCommandNames = "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER" [static] |
Definition at line 347 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientConnection::handleCmd_bad(), RTSPServer::RTSPClientConnection::handleCmd_notSupported(), and RTSPServer::RTSPClientConnection::handleCmd_OPTIONS().
1.5.2