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

Go to the source code of this file.
Defines | |
| #define | USE_SIGNALS 1 |
| #define | RTPINFO_INCLUDE_RTPTIME 1 |
| #define | LISTEN_BACKLOG_SIZE 20 |
Enumerations | |
| enum | StreamingMode { RTP_UDP, RTP_TCP, RAW_UDP } |
Functions | |
| static char const * | dateHeader () |
| 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 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" |
| #define LISTEN_BACKLOG_SIZE 20 |
Definition at line 139 of file RTSPServer.cpp.
| #define RTPINFO_INCLUDE_RTPTIME 1 |
Definition at line 32 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientSession::handleCmd_PLAY().
| #define USE_SIGNALS 1 |
Definition at line 28 of file RTSPServer.cpp.
| enum StreamingMode |
Definition at line 529 of file RTSPServer.cpp.
00529 { 00530 RTP_UDP, 00531 RTP_TCP, 00532 RAW_UDP 00533 } StreamingMode;
| static char const* dateHeader | ( | ) | [static] |
Definition at line 408 of file RTSPServer.cpp.
Referenced by RTSPServer::RTSPClientSession::authenticationOK(), RTSPServer::RTSPClientSession::handleCmd_bad(), RTSPServer::RTSPClientSession::handleCmd_DESCRIBE(), RTSPServer::RTSPClientSession::handleCmd_GET_PARAMETER(), RTSPServer::RTSPClientSession::handleCmd_notFound(), RTSPServer::RTSPClientSession::handleCmd_notSupported(), RTSPServer::RTSPClientSession::handleCmd_OPTIONS(), RTSPServer::RTSPClientSession::handleCmd_PAUSE(), RTSPServer::RTSPClientSession::handleCmd_PLAY(), RTSPServer::RTSPClientSession::handleCmd_SETUP(), RTSPServer::RTSPClientSession::handleCmd_TEARDOWN(), and RTSPServer::RTSPClientSession::handleCmd_unsupportedTransport().
00408 { 00409 static char buf[200]; 00410 #if !defined(_WIN32_WCE) 00411 time_t tt = time(NULL); 00412 strftime(buf, sizeof buf, "Date: %a, %b %d %Y %H:%M:%S GMT\r\n", gmtime(&tt)); 00413 #else 00414 // WinCE apparently doesn't have "time()", "strftime()", or "gmtime()", 00415 // so generate the "Date:" header a different, WinCE-specific way. 00416 // (Thanks to Pierre l'Hussiez for this code) 00417 SYSTEMTIME SystemTime; 00418 GetSystemTime(&SystemTime); 00419 WCHAR dateFormat[] = L"ddd, MMM dd yyyy"; 00420 WCHAR timeFormat[] = L"HH:mm:ss GMT\r\n"; 00421 WCHAR inBuf[200]; 00422 DWORD locale = LOCALE_NEUTRAL; 00423 00424 int ret = GetDateFormat(locale, 0, &SystemTime, 00425 (LPTSTR)dateFormat, (LPTSTR)inBuf, sizeof inBuf); 00426 inBuf[ret - 1] = ' '; 00427 ret = GetTimeFormat(locale, 0, &SystemTime, 00428 (LPTSTR)timeFormat, 00429 (LPTSTR)inBuf + ret, (sizeof inBuf) - ret); 00430 wcstombs(buf, inBuf, wcslen(inBuf)); 00431 #endif 00432 return buf; 00433 }
| 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 1072 of file RTSPServer.cpp.
References _strncasecmp, False, NULL, strDup(), strDupSize(), and True.
Referenced by RTSPServer::RTSPClientSession::authenticationOK().
01076 { 01077 // Initialize the result parameters to default values: 01078 username = realm = nonce = uri = response = NULL; 01079 01080 // First, find "Authorization:" 01081 while (1) { 01082 if (*buf == '\0') return False; // not found 01083 if (_strncasecmp(buf, "Authorization: Digest ", 22) == 0) break; 01084 ++buf; 01085 } 01086 01087 // Then, run through each of the fields, looking for ones we handle: 01088 char const* fields = buf + 22; 01089 while (*fields == ' ') ++fields; 01090 char* parameter = strDupSize(fields); 01091 char* value = strDupSize(fields); 01092 while (1) { 01093 value[0] = '\0'; 01094 if (sscanf(fields, "%[^=]=\"%[^\"]\"", parameter, value) != 2 && 01095 sscanf(fields, "%[^=]=\"\"", parameter) != 1) { 01096 break; 01097 } 01098 if (strcmp(parameter, "username") == 0) { 01099 username = strDup(value); 01100 } else if (strcmp(parameter, "realm") == 0) { 01101 realm = strDup(value); 01102 } else if (strcmp(parameter, "nonce") == 0) { 01103 nonce = strDup(value); 01104 } else if (strcmp(parameter, "uri") == 0) { 01105 uri = strDup(value); 01106 } else if (strcmp(parameter, "response") == 0) { 01107 response = strDup(value); 01108 } 01109 01110 fields += strlen(parameter) + 2 /*="*/ + strlen(value) + 1 /*"*/; 01111 while (*fields == ',' || *fields == ' ') ++fields; 01112 // skip over any separating ',' and ' ' chars 01113 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 01114 } 01115 delete[] parameter; delete[] value; 01116 return True; 01117 }
| static Boolean parsePlayNowHeader | ( | char const * | buf | ) | [static] |
Definition at line 597 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
00597 { 00598 // Find "x-playNow:" header, if present 00599 while (1) { 00600 if (*buf == '\0') return False; // not found 00601 if (_strncasecmp(buf, "x-playNow:", 10) == 0) break; 00602 ++buf; 00603 } 00604 00605 return True; 00606 }
| static Boolean parseScaleHeader | ( | char const * | buf, | |
| float & | scale | |||
| ) | [static] |
Definition at line 872 of file RTSPServer.cpp.
References _strncasecmp, False, and True.
Referenced by RTSPServer::RTSPClientSession::handleCmd_PLAY().
00872 { 00873 // Initialize the result parameter to a default value: 00874 scale = 1.0; 00875 00876 // First, find "Scale:" 00877 while (1) { 00878 if (*buf == '\0') return False; // not found 00879 if (_strncasecmp(buf, "Scale: ", 7) == 0) break; 00880 ++buf; 00881 } 00882 00883 // Then, run through each of the fields, looking for ones we handle: 00884 char const* fields = buf + 7; 00885 while (*fields == ' ') ++fields; 00886 float sc; 00887 if (sscanf(fields, "%f", &sc) == 1) { 00888 scale = sc; 00889 } else { 00890 return False; // The header is malformed 00891 } 00892 00893 return True; 00894 }
| 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 535 of file RTSPServer.cpp.
References _strncasecmp, NULL, RAW_UDP, RTP_TCP, RTP_UDP, strDup(), and strDupSize().
Referenced by RTSPServer::RTSPClientSession::handleCmd_SETUP().
00544 { 00545 // Initialize the result parameters to default values: 00546 streamingMode = RTP_UDP; 00547 streamingModeString = NULL; 00548 destinationAddressStr = NULL; 00549 destinationTTL = 255; 00550 clientRTPPortNum = 0; 00551 clientRTCPPortNum = 1; 00552 rtpChannelId = rtcpChannelId = 0xFF; 00553 00554 portNumBits p1, p2; 00555 unsigned ttl, rtpCid, rtcpCid; 00556 00557 // First, find "Transport:" 00558 while (1) { 00559 if (*buf == '\0') return; // not found 00560 if (_strncasecmp(buf, "Transport: ", 11) == 0) break; 00561 ++buf; 00562 } 00563 00564 // Then, run through each of the fields, looking for ones we handle: 00565 char const* fields = buf + 11; 00566 char* field = strDupSize(fields); 00567 while (sscanf(fields, "%[^;]", field) == 1) { 00568 if (strcmp(field, "RTP/AVP/TCP") == 0) { 00569 streamingMode = RTP_TCP; 00570 } else if (strcmp(field, "RAW/RAW/UDP") == 0 || 00571 strcmp(field, "MP2T/H2221/UDP") == 0) { 00572 streamingMode = RAW_UDP; 00573 streamingModeString = strDup(field); 00574 } else if (_strncasecmp(field, "destination=", 12) == 0) { 00575 delete[] destinationAddressStr; 00576 destinationAddressStr = strDup(field+12); 00577 } else if (sscanf(field, "ttl%u", &ttl) == 1) { 00578 destinationTTL = (u_int8_t)ttl; 00579 } else if (sscanf(field, "client_port=%hu-%hu", &p1, &p2) == 2) { 00580 clientRTPPortNum = p1; 00581 clientRTCPPortNum = p2; 00582 } else if (sscanf(field, "client_port=%hu", &p1) == 1) { 00583 clientRTPPortNum = p1; 00584 clientRTCPPortNum = streamingMode == RAW_UDP ? 0 : p1 + 1; 00585 } else if (sscanf(field, "interleaved=%u-%u", &rtpCid, &rtcpCid) == 2) { 00586 rtpChannelId = (unsigned char)rtpCid; 00587 rtcpChannelId = (unsigned char)rtcpCid; 00588 } 00589 00590 fields += strlen(field); 00591 while (*fields == ';') ++fields; // skip over separating ';' chars 00592 if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; 00593 } 00594 delete[] field; 00595 }
char const* allowedCommandNames = "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE" [static] |
Definition at line 436 of file RTSPServer.cpp.
1.5.2