inline void ParseAuthNameAndPassword(StrPtrLen *codedStrPtr, StrPtrLen* namePtr, StrPtrLen* passwordPtr) { if (!codedStrPtr || (codedStrPtr->Len >= kAuthNameAndPasswordBuffSize) ) { return; } StrPtrLen codedLineStr; StrPtrLen nameAndPassword; memset(decodedLine,0,kAuthNameAndPasswordBuffSize); memset(codedLine,0,kAuthNameAndPasswordBuffSize); memcpy (codedLine,codedStrPtr->Ptr,codedStrPtr->Len); codedLineStr.Set((char*) codedLine, codedStrPtr->Len); (void) Base64decode(decodedLine, codedLineStr.Ptr); nameAndPassword.Set((char*) decodedLine, strlen(decodedLine)); StringParser parsedNameAndPassword(&nameAndPassword); parsedNameAndPassword.ConsumeUntil(namePtr,':'); parsedNameAndPassword.ConsumeLength(NULL, 1); // password can have whitespace, so read until the end of the line, not just until whitespace parsedNameAndPassword.ConsumeUntil(passwordPtr, StringParser::sEOLMask); namePtr->Ptr[namePtr->Len]= 0; passwordPtr->Ptr[passwordPtr->Len]= 0; //qtss_printf("decoded nameAndPassword="******"decoded name="); PRINT_STR(namePtr); //qtss_printf("decoded password="); PRINT_STR(passwordPtr); return; };
QTSS_Error RTSPRequest::ParseBasicHeader(StringParser *inParsedAuthLinePtr) { QTSS_Error theErr = QTSS_NoErr; fAuthScheme = qtssAuthBasic; StrPtrLen authWord; inParsedAuthLinePtr->ConsumeWhitespace(); inParsedAuthLinePtr->ConsumeUntilWhitespace(&authWord); if (0 == authWord.Len ) return theErr; char* encodedStr = authWord.GetAsCString(); OSCharArrayDeleter encodedStrDeleter(encodedStr); char *decodedAuthWord = NEW char[Base64decode_len(encodedStr) + 1]; OSCharArrayDeleter decodedAuthWordDeleter(decodedAuthWord); (void) Base64decode(decodedAuthWord, encodedStr); StrPtrLen nameAndPassword; nameAndPassword.Set(decodedAuthWord, ::strlen(decodedAuthWord)); StrPtrLen name(""); StrPtrLen password(""); StringParser parsedNameAndPassword(&nameAndPassword); parsedNameAndPassword.ConsumeUntil(&name,':'); parsedNameAndPassword.ConsumeLength(NULL, 1); parsedNameAndPassword.GetThruEOL(&password); // Set the qtssRTSPReqUserName and qtssRTSPReqUserPassword attributes in the Request object (void) this->SetValue(qtssRTSPReqUserName, 0, name.Ptr , name.Len, QTSSDictionary::kDontObeyReadOnly); (void) this->SetValue(qtssRTSPReqUserPassword, 0, password.Ptr , password.Len, QTSSDictionary::kDontObeyReadOnly); // Also set the qtssUserName attribute in the qtssRTSPReqUserProfile object attribute of the Request Object (void) fUserProfile.SetValue(qtssUserName, 0, name.Ptr, name.Len, QTSSDictionary::kDontObeyReadOnly); return theErr; }