void* RTSPRequestInterface::GetFileName(QTSSDictionary* inRequest, UInt32* /*outLen*/) { // This function always gets called RTSPRequestInterface* theRequest = (RTSPRequestInterface*)inRequest; theRequest->SetVal(qtssRTSPReqFileName, theRequest->GetValue(qtssRTSPReqFilePath)); StrPtrLen* theFileNameParam = theRequest->GetValue(qtssRTSPReqFileName); //paranoid check if (theFileNameParam->Len == 0) return theFileNameParam; //walk back in the file name until we hit a / SInt32 x = theFileNameParam->Len - 1; for (; x > 0; x--) if (theFileNameParam->Ptr[x] == kPathDelimiterChar) break; //once we do, make the tempPtr point to the next character after the slash, //and adjust the length accordingly if (theFileNameParam->Ptr[x] == kPathDelimiterChar ) { theFileNameParam->Ptr = (&theFileNameParam->Ptr[x]) + 1; theFileNameParam->Len -= (x + 1); } return NULL; }
void* RTSPRequestInterface::GetLocalPath(QTSSDictionary* inRequest, UInt32* outLen) { // This function always gets called RTSPRequestInterface* theRequest = (RTSPRequestInterface*)inRequest; QTSS_AttributeID theID = qtssRTSPReqFilePath; // Get the truncated path on a setup, because setups have the trackID appended if (theRequest->GetMethod() == qtssSetupMethod) { theID = qtssRTSPReqFilePathTrunc; // invoke the param retrieval function here so that we can use the internal GetValue function later RTSPRequestInterface::GetTruncatedPath(inRequest, outLen); } StrPtrLen* thePath = theRequest->GetValue(theID); StrPtrLen filePath(thePath->Ptr, thePath->Len); StrPtrLen* theRootDir = theRequest->GetValue(qtssRTSPReqRootDir); if (theRootDir->Len && theRootDir->Ptr[theRootDir->Len -1] == kPathDelimiterChar && thePath->Len && thePath->Ptr[0] == kPathDelimiterChar) { char *thePathEnd = &(filePath.Ptr[filePath.Len]); while (filePath.Ptr != thePathEnd) { if (*filePath.Ptr != kPathDelimiterChar) break; filePath.Ptr ++; filePath.Len --; } } char rootDir[512] = { 0 }; ::strncpy(rootDir, theRootDir->Ptr, theRootDir->Len); OS::RecursiveMakeDir(rootDir); UInt32 fullPathLen = filePath.Len + theRootDir->Len; char* theFullPath = NEW char[fullPathLen+1]; theFullPath[fullPathLen] = '\0'; ::memcpy(theFullPath, theRootDir->Ptr, theRootDir->Len); ::memcpy(theFullPath + theRootDir->Len, filePath.Ptr, filePath.Len); (void)theRequest->SetValue(qtssRTSPReqLocalPath, 0, theFullPath,fullPathLen , QTSSDictionary::kDontObeyReadOnly); // delete our copy of the data delete [] theFullPath; *outLen = 0; return NULL; }
//param retrieval functions described in .h file void* RTSPRequestInterface::GetAbsTruncatedPath(QTSSDictionary* inRequest, UInt32* /*outLen*/) { // This function gets called only once RTSPRequestInterface* theRequest = (RTSPRequestInterface*)inRequest; theRequest->SetVal(qtssRTSPReqTruncAbsoluteURL, theRequest->GetValue(qtssRTSPReqAbsoluteURL)); //Adjust the length to truncate off the last file in the path StrPtrLen* theAbsTruncPathParam = theRequest->GetValue(qtssRTSPReqTruncAbsoluteURL); theAbsTruncPathParam->Len--; while (theAbsTruncPathParam->Ptr[theAbsTruncPathParam->Len] != kPathDelimiterChar) theAbsTruncPathParam->Len--; return NULL; }
void* RTSPRequestInterface::GetTruncatedPath(QTSSDictionary* inRequest, UInt32* /*outLen*/) { // This function always gets called RTSPRequestInterface* theRequest = (RTSPRequestInterface*)inRequest; theRequest->SetVal(qtssRTSPReqFilePathTrunc, theRequest->GetValue(qtssRTSPReqFilePath)); //Adjust the length to truncate off the last file in the path StrPtrLen* theTruncPathParam = theRequest->GetValue(qtssRTSPReqFilePathTrunc); if (theTruncPathParam->Len > 0) { theTruncPathParam->Len--; while ( (theTruncPathParam->Len != 0) && (theTruncPathParam->Ptr[theTruncPathParam->Len] != kPathDelimiterChar) ) theTruncPathParam->Len--; } return NULL; }
void RTSPRequestInterface::AppendRTPInfoHeader(QTSS_RTSPHeader inHeader, StrPtrLen* url, StrPtrLen* seqNumber, StrPtrLen* ssrc, StrPtrLen* rtpTime, Bool16 lastRTPInfo) { static StrPtrLen sURL("url=", 4); static StrPtrLen sSeq(";seq=", 5); static StrPtrLen sSsrc(";ssrc=", 6); static StrPtrLen sRTPTime(";rtptime=", 9); if (!fStandardHeadersWritten) this->WriteStandardHeaders(); fOutputStream->Put(RTSPProtocol::GetHeaderString(inHeader)); if (inHeader != qtssSameAsLastHeader) fOutputStream->Put(sColonSpace); //Only append the various bits of RTP information if they actually have been //providied if ((url != NULL) && (url->Len > 0)) { fOutputStream->Put(sURL); if (true) //3gpp requires this and it follows RTSP RFC. { RTSPRequestInterface* theRequest = (RTSPRequestInterface*)this; StrPtrLen *path = (StrPtrLen *) theRequest->GetValue(qtssRTSPReqAbsoluteURL); if (path != NULL && path->Len > 0) { fOutputStream->Put(*path); if(path->Ptr[path->Len-1] != '/') fOutputStream->PutChar('/'); } } fOutputStream->Put(*url); } if ((seqNumber != NULL) && (seqNumber->Len > 0)) { fOutputStream->Put(sSeq); fOutputStream->Put(*seqNumber); } if ((ssrc != NULL) && (ssrc->Len > 0)) { fOutputStream->Put(sSsrc); fOutputStream->Put(*ssrc); } if ((rtpTime != NULL) && (rtpTime->Len > 0)) { fOutputStream->Put(sRTPTime); fOutputStream->Put(*rtpTime); } if (lastRTPInfo) fOutputStream->PutEOL(); }
void* RTSPRequestInterface::GetFileDigit(QTSSDictionary* inRequest, UInt32* /*outLen*/) { // This function always gets called RTSPRequestInterface* theRequest = (RTSPRequestInterface*)inRequest; theRequest->SetVal(qtssRTSPReqFileDigit, theRequest->GetValue(qtssRTSPReqFilePath)); StrPtrLen* theFileDigit = theRequest->GetValue(qtssRTSPReqFileDigit); UInt32 theFilePathLen = theRequest->GetValue(qtssRTSPReqFilePath)->Len; theFileDigit->Ptr += theFilePathLen - 1; theFileDigit->Len = 0; while ((StringParser::sDigitMask[(unsigned int) *(*theFileDigit).Ptr] != '\0') && (theFileDigit->Len <= theFilePathLen)) { theFileDigit->Ptr--; theFileDigit->Len++; } //termination condition means that we aren't actually on a digit right now. //Move pointer back onto the digit theFileDigit->Ptr++; return NULL; }
QTSS_Error QTSSCallbacks::QTSS_Authorize(QTSS_RTSPRequestObject inAuthRequestObject, char** outAuthRealm, Bool16* outAuthUserAllowed) { RTSPRequestInterface* request = (RTSPRequestInterface *) inAuthRequestObject; if (request == NULL) return QTSS_BadArgument; // Because this is a role being executed from inside a callback, we need to // make sure that QTSS_RequestEvent will not work. Task* curTask = NULL; QTSS_ModuleState* theState = (QTSS_ModuleState*)OSThread::GetMainThreadData(); if (OSThread::GetCurrent() != NULL) theState = (QTSS_ModuleState*)OSThread::GetCurrent()->GetThreadData(); if (theState != NULL) curTask = theState->curTask; QTSS_RoleParams theParams; theParams.rtspRequestParams.inRTSPSession = NULL; theParams.rtspRequestParams.inRTSPRequest = request; theParams.rtspRequestParams.inClientSession = NULL; QTSS_Error theErr = QTSS_RequestFailed; UInt32 x = 0; UInt32 numModules = QTSServerInterface::GetNumModulesInRole(QTSSModule::kRTSPAuthRole); QTSSModule* theModulePtr = NULL; Bool16 allowedDefault = QTSServerInterface::GetServer()->GetPrefs()->GetAllowGuestDefault(); *outAuthUserAllowed = allowedDefault; Bool16 allowed = allowedDefault; //server pref? Bool16 hasUser = false; Bool16 handled = false; // Call all the modules that are registered for the RTSP Authorize Role for ( ; x < numModules; x++) { request->SetAllowed(true); request->SetHasUser(false); request->SetAuthHandled(false); debug_printf(" QTSSCallbacks::QTSS_Authorize calling module module = %lu numModules=%lu\n", x,numModules); theModulePtr = QTSServerInterface::GetModule(QTSSModule::kRTSPAuthRole, x); theErr = QTSS_NoErr; if (theModulePtr) { if (__QTSSCALLBACKS_DEBUG__) theModulePtr->GetValue(qtssModName)->PrintStr("QTSSModule::CallDispatch ENTER module=", "\n"); theErr = theModulePtr->CallDispatch(QTSS_RTSPAuthorize_Role, &theParams); debug_printf(" QTSSCallbacks::QTSS_Authorize calling module module = %lu numModules=%lu ModuleError=%ld\n", x,numModules, theErr); } else { debug_printf(" QTSSCallbacks::QTSS_Authorize calling module module = %lu is NULL! numModules=%lu\n", x,numModules); continue; } allowed = request->GetAllowed(); hasUser = request->GetHasUser(); handled = request->GetAuthHandled(); debug_printf("QTSSCallbacks::QTSS_Authorize allowedDefault =%d allowed= %d hasUser = %d handled=%d \n",allowedDefault, allowed,hasUser, handled); *outAuthUserAllowed = allowed; //notes: //if (allowed && !handled) break; //old module //if (!allowed && handled) /new module handled the request but not authorized keep trying //if (allowed && handled) //new module allowed but keep trying in case someone denies. if (!allowed && !handled) //old module break on !allowed { debug_printf("RTSPSession.cpp::Run(kAuthorizingRequest) skipping other modules fCurrentModule = %lu numModules=%lu\n", x,numModules); break; } } // outAuthRealm is set to the realm that is given by the module that has denied authentication StrPtrLen* realm = request->GetValue(qtssRTSPReqURLRealm); *outAuthRealm = realm->GetAsCString(); return theErr; }