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

Go to the source code of this file.
Defines | |
| #define | USE_SIGNALS 1 |
| #define | LISTEN_BACKLOG_SIZE 20 |
Enumerations | |
| enum | StreamingMode { RTP_UDP, RTP_TCP, RAW_UDP } |
Functions | |
| 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) |
| 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) |
Variables | |
| static char const * | allowedCommandNames = "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER" |
| #define LISTEN_BACKLOG_SIZE 20 |
| #define USE_SIGNALS 1 |
Definition at line 29 of file RTSPServer.cpp.
| enum StreamingMode |
Definition at line 661 of file RTSPServer.cpp.
00661 { 00662 RTP_UDP, 00663 RTP_TCP, 00664 RAW_UDP 00665 } StreamingMode;
| static void lookForHeader | ( | char const * | headerName, | |
| char const * | source, | |||
| unsigned | sourceLen, | |||
| char * | resultStr, | |||
| unsigned | resultMaxSize | |||
| ) | [static] |
Definition at line 1267 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientSession::parseHTTPRequestString().
01267 { 01268 resultStr[0] = '\0'; // by default, return an empty string 01269 unsigned headerNameLen = strlen(headerName); 01270 for (int i = 0; i < (int)(sourceLen-headerNameLen); ++i) { 01271 if (strncmp(&source[i], headerName, headerNameLen) == 0 && source[i+headerNameLen] == ':') { 01272 // We found the header. Skip over any whitespace, then copy the rest of the line to "resultStr": 01273 for (i += headerNameLen+1; i < (int)sourceLen && (source[i] == ' ' || source[i] == '\t'); ++i) {} 01274 for (unsigned j = i; j < sourceLen; ++j) { 01275 if (source[j] == '\r' || source[j] == '\n') { 01276 // We've found the end of the line. Copy it to the result (if it will fit): 01277 if (j-i+1 > resultMaxSize) break; 01278 char const* resultSource = &source[i]; 01279 char const* resultSourceEnd = &source[j]; 01280 while (resultSource < resultSourceEnd) *resultStr++ = *resultSource++; 01281 *resultStr = '\0'; 01282 break; 01283 } 01284 } 01285 } 01286 } 01287 }
| 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 1402 of file RTSPServer.cpp.
References _strncasecmp, False, NULL, strDup(), strDupSize(), and True.
Referenced by RTSPServer::RTSPClientSession::authenticationOK().
01406 { 01407 // Initialize the result parameters to default values: 01408 username = realm = nonce = uri = response = NULL; 01409 01410 // First, find "Authorization:" 01411 while (1) { 01412 if (*buf == '\0') return False; // not found 01413 if (_strncasecmp(buf, "Authorization: Digest ", 22) == 0) break; 01414 ++buf; 01415 } 01416 01417 // Then, run through each of the fields, looking for ones we handle: 01418 char const* fields = buf + 22; 01419 while (*fields == ' ') ++fields; 01420 char* parameter = strDupSize(fields); 01421 char* value = strDupSize(fields); 01422 while (1) { 01423 value[0] = '\0'; 01424 if (sscanf(fields, "%[^=]=\"%[^\"]\"", parameter, value) != 2 && 01425 sscanf(fields, "%[^=]=\"\"", parameter) != 1) { 01426 break; 01427 } 01428 if (strcmp(parameter, "username") == 0) { 01429 username = strDup(value); 01430 } else if (strcmp(parameter, "realm") == 0) { 01431 realm = strDup(value); 01432 } else if (strcmp(parameter, "nonce") == 0) { 01433 nonce = strDup(value); 01434 } else if (strcmp(parameter, "uri") == 0) { 01435 uri = strDup(value); 01436 } else if (strcmp(parameter, "response") == 0) { 01437 response = strDup(value); 01438 } 01439 01440 fields += strlen(parameter) + 2 /*="*/ + strlen(value) + 1 /*"*/; 01441 while (*fields == ',' || *fields == ' ') ++fields; 01442 // skip over any separating ',' and ' ' chars 01443 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 01444 } 01445 delete[] parameter; delete[] value; 01446 return True; 01447 }
| static Boolean parsePlayNowHeader | ( | char const * | buf | ) | [static] |
Definition at line 729 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
00729 { 00730 // Find "x-playNow:" header, if present 00731 while (1) { 00732 if (*buf == '\0') return False; // not found 00733 if (_strncasecmp(buf, "x-playNow:", 10) == 0) break; 00734 ++buf; 00735 } 00736 00737 return True; 00738 }
| static Boolean parseScaleHeader | ( | char const * | buf, | |
| float & | scale | |||
| ) | [static] |
Definition at line 1046 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_PLAY().
01046 { 01047 // Initialize the result parameter to a default value: 01048 scale = 1.0; 01049 01050 // First, find "Scale:" 01051 while (1) { 01052 if (*buf == '\0') return False; // not found 01053 if (_strncasecmp(buf, "Scale: ", 7) == 0) break; 01054 ++buf; 01055 } 01056 01057 // Then, run through each of the fields, looking for ones we handle: 01058 char const* fields = buf + 7; 01059 while (*fields == ' ') ++fields; 01060 float sc; 01061 if (sscanf(fields, "%f", &sc) == 1) { 01062 scale = sc; 01063 } else { 01064 return False; // The header is malformed 01065 } 01066 01067 return True; 01068 }
| 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 667 of file RTSPServer.cpp.
References _strncasecmp, NULL, RAW_UDP, RTP_TCP, RTP_UDP, strDup(), and strDupSize().
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
00676 { 00677 // Initialize the result parameters to default values: 00678 streamingMode = RTP_UDP; 00679 streamingModeString = NULL; 00680 destinationAddressStr = NULL; 00681 destinationTTL = 255; 00682 clientRTPPortNum = 0; 00683 clientRTCPPortNum = 1; 00684 rtpChannelId = rtcpChannelId = 0xFF; 00685 00686 portNumBits p1, p2; 00687 unsigned ttl, rtpCid, rtcpCid; 00688 00689 // First, find "Transport:" 00690 while (1) { 00691 if (*buf == '\0') return; // not found 00692 if (_strncasecmp(buf, "Transport: ", 11) == 0) break; 00693 ++buf; 00694 } 00695 00696 // Then, run through each of the fields, looking for ones we handle: 00697 char const* fields = buf + 11; 00698 char* field = strDupSize(fields); 00699 while (sscanf(fields, "%[^;]", field) == 1) { 00700 if (strcmp(field, "RTP/AVP/TCP") == 0) { 00701 streamingMode = RTP_TCP; 00702 } else if (strcmp(field, "RAW/RAW/UDP") == 0 || 00703 strcmp(field, "MP2T/H2221/UDP") == 0) { 00704 streamingMode = RAW_UDP; 00705 streamingModeString = strDup(field); 00706 } else if (_strncasecmp(field, "destination=", 12) == 0) { 00707 delete[] destinationAddressStr; 00708 destinationAddressStr = strDup(field+12); 00709 } else if (sscanf(field, "ttl%u", &ttl) == 1) { 00710 destinationTTL = (u_int8_t)ttl; 00711 } else if (sscanf(field, "client_port=%hu-%hu", &p1, &p2) == 2) { 00712 clientRTPPortNum = p1; 00713 clientRTCPPortNum = streamingMode == RAW_UDP ? 0 : p2; // ignore the second port number if the client asked for raw UDP 00714 } else if (sscanf(field, "client_port=%hu", &p1) == 1) { 00715 clientRTPPortNum = p1; 00716 clientRTCPPortNum = streamingMode == RAW_UDP ? 0 : p1 + 1; 00717 } else if (sscanf(field, "interleaved=%u-%u", &rtpCid, &rtcpCid) == 2) { 00718 rtpChannelId = (unsigned char)rtpCid; 00719 rtcpChannelId = (unsigned char)rtcpCid; 00720 } 00721 00722 fields += strlen(field); 00723 while (*fields == ';') ++fields; // skip over separating ';' chars 00724 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 00725 } 00726 delete[] field; 00727 }
char const* allowedCommandNames = "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER" [static] |
Definition at line 557 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientSession::handleCmd_bad(), RTSPServer::RTSPClientSession::handleCmd_notSupported(), and RTSPServer::RTSPClientSession::handleCmd_OPTIONS().
1.5.2