/** This method is a notification of the beginning of the scope of a prefix-URI Namespace mapping. This method is always called before the corresponding OnStartElementL method. @param aPrefix is the Namespace prefix being declared. @param aUri is the Namespace URI the prefix is mapped to. @param aErrorCode is the error code. If this is not KErrNone then special action may be required. */ void CTestHandler::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode) { _LIT8(KOnStartPrefMapFuncName,"OnStartPrefixMapping()\r\n"); _LIT8(KInfoOnStartPref,"\tPrefix mapping start prefix: %S \t uri: %S \r\n"); _LIT8(KInfoOnError,"Error occurs %d \r\n"); iLog.Write(KOnStartPrefMapFuncName); if (aErrorCode == KErrNone) { TBuf8<KShortInfoSize> info; TBuf8<KShortInfoSize> info2; TBuf8<KShortInfoSize> info3; info2.Copy(aPrefix.DesC()); info3.Copy(aUri.DesC()); info.Format(KInfoOnStartPref,&info2,&info3); iLog.Write(info); } else { TBuf8<KShortInfoSize> info; info.Format(KInfoOnError,aErrorCode); iLog.Write(info); } }
void CSenXmlReader::OnStartPrefixMappingL( const RString& aPrefix, const RString& aUri, TInt /*aErrorCode*/) { if(!iContentHandler) { SENDEBUG_L("OnStartPrefixMappingL: KErrSenXmlContentHandlerNotSet"); User::Leave(KErrSenXmlContentHandlerNotSet); } if(!ipNsPrefixes) { ipNsPrefixes = new (ELeave) CDesC8ArrayFlat(KArraySize); } if(!ipNsUris) { ipNsUris = new (ELeave) CDesC8ArrayFlat(KArraySize); } ipNsPrefixes->AppendL(aPrefix.DesC()); ipNsUris->AppendL(aUri.DesC()); iContentHandler->StartPrefixMappingL(aPrefix.DesC(), aUri.DesC()); }
void TNamespaceContentHandler::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aError) { TSimpleContentHandler::OnStartPrefixMappingL(aPrefix, aUri, aError); TPtrC8 prefix = aPrefix.DesC(); TPtrC8 uri = aUri.DesC(); switch(iState) { case KNothingMapped: test(prefix.Length()==0 && uri==iDefaultUri); iState = KDefaultNsMapped; break; case KDefaultNsMapped: test(prefix==iElementPrefix && uri==iElementUri); iState = KElementNsMapped; break; case KElementNsMapped: test(prefix==iAttributePrefix && uri==iAttributeUri); iState = KAttributeNsMapped; break; case KAttributeNsMapped: test(0); } }
/** This method is a notification of a skipped entity. If the parser encounters an external entity it does not need to expand it - it can return the entity as aName for the client to deal with. @param aName is the name of the skipped entity. @param aErrorCode is the error code. If this is not KErrNone then special action may be required. */ void CTestHandler::OnSkippedEntityL(const RString& aName, TInt aErrorCode) { _LIT8(KOnSkipEntFuncName,"OnSkippedEntity()\r\n"); _LIT8(KInfoOnEndPref,"\tSkipped entity: %S \r\n"); _LIT8(KInfoOnError,"Error occurs %d \r\n"); iLog.Write(KOnSkipEntFuncName); if (aErrorCode == KErrNone) { TBuf8<KShortInfoSize> info; TBuf8<KShortInfoSize> info2; info2.Copy(aName.DesC()); info.Format(KInfoOnEndPref,&info2); iLog.Write(info); } else { TBuf8<KShortInfoSize> info; info.Format(KInfoOnError,aErrorCode); iLog.Write(info); } }
/** Get the credentials from the user. @param aURI [in] The URI being requested @param aRealm [out] The realm being requested @param aAuthenticationType [out] The type of authentication. @param aUsername [out] User name @param aPassword [out] Pass word @return TBool ETrue if credentials being returned else EFalse */ TBool CTestWebBrowser::GetCredentialsL( const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword ) { // Convert to 16 bit to display HBufC* uriDesBuf = HBufC::NewLC( aURI.UriDes().Length() ); TPtr uriDesPtr( uriDesBuf->Des() ); uriDesPtr.Copy( aURI.UriDes() ); HBufC* uriRealmBuf = HBufC::NewLC( aRealm.DesC().Length() ); TPtr uriRealmPtr( uriRealmBuf->Des() ); uriRealmPtr.Copy( aRealm.DesC() ); HBufC* uriAuthenticationType = HBufC::NewLC ( aAuthenticationType.DesC().Length() ); TPtr uriAuthenticationPtr( uriAuthenticationType->Des() ); uriAuthenticationPtr.Copy ( aAuthenticationType.DesC() ); // Prompt user for input iTestUtils.Test().Printf ( _L( "Enter credentials for URL %S, realm %S\n"), &uriDesPtr, &uriRealmPtr ); iTestUtils.Test().Printf ( _L("Using %S authentication\n"), &uriAuthenticationPtr ); CleanupStack::PopAndDestroy ( 3 ); // Pop and destroy uriDesBuf, uriRealmBuf and uriAuthenticationType HBufC* userDetails16 = HBufC::NewLC ( KMaxUserEntrySize ); HBufC8* userDetails8 = HBufC8::NewLC ( KMaxUserEntrySize ); TPtr userDetailsPtr16( userDetails16->Des() ); TPtr8 userDetailsPtr8( userDetails8->Des() ); iTestUtils.GetAnEntry ( _L( "Username (or QUIT to give up): " ), userDetailsPtr16 ); TBool set = EFalse; if ( userDetailsPtr16.CompareF ( KQuit ) ) { userDetailsPtr8.Copy ( userDetailsPtr16 ); aUsername = aRealm.Pool().OpenStringL ( userDetailsPtr8 ); iTestUtils.GetAnEntry( _L( "Password: " ), userDetailsPtr16 ); userDetailsPtr8.Copy ( userDetailsPtr16 ); aPassword = aRealm.Pool().OpenStringL ( userDetailsPtr8 ); set = ETrue; } CleanupStack::PopAndDestroy ( 2 ); // Pop and destroy userDetails16 & userDetails8 return set; }
void CSenXmlReader::OnEndPrefixMappingL(const RString& aPrefix, TInt /*aErrorCode*/) { if(!iContentHandler) { SENDEBUG_L("OnEndPrefixMappingL: KErrSenXmlContentHandlerNotSet"); User::Leave(KErrSenXmlContentHandlerNotSet); } iContentHandler->EndPrefixMappingL(aPrefix.DesC()); }
TBool CHttpTestCaseGet12::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) { iEngine->Utils().LogIt(_L("Supplying credentials")); iEngine->Utils().DumpData(aURI.UriDes()); iEngine->Utils().DumpData(aRealm.DesC()); iEngine->Utils().DumpData(aAuthenticationType.DesC()); _LIT8(KScooby, "scooby"); _LIT8(KDoo, "doo"); RStringPool p = aRealm.Pool(); aUsername = p.OpenStringL(KScooby); aPassword = p.OpenStringL(KDoo); return ETrue; }
void CSenXmlReader::OnSkippedEntityL(const RString& aName, TInt /*aErrorCode*/) { if(!iContentHandler) { SENDEBUG_L("OnSkippedEntityL: KErrSenXmlContentHandlerNotSet"); User::Leave(KErrSenXmlContentHandlerNotSet); } iContentHandler->SkippedEntity(aName.DesC()); //TInt retVal = iContentHandler->SkippedEntity(aName.DesC()); // content handler spesific code returned error //User::LeaveIfError(retVal); }
void CTestFilter::EncodeBasicAuthL(RString& aUsername, RString& aPW, RHTTPTransaction& aTransaction) { // Standard, plain-text HTTP - Base 64 the name and password TBase64 codec; HBufC8* nameAndPW = HBufC8::NewMaxLC(aUsername.DesC().Length() + aPW.DesC().Length() + 1); _LIT8(KBasicAuthFormatString, "%S:%S"); nameAndPW->Des().Format(KBasicAuthFormatString, &aUsername.DesC(), &aPW.DesC()); // Conservatively allocate a buffer twice as big as the unencoded // buffer for the encoded string. HBufC8* encoded = HBufC8::NewMaxLC(nameAndPW->Des().Length() * 2); TPtr8 encodedPtr(encoded->Des()); codec.Encode(*nameAndPW, encodedPtr); RString encodedString = iStringPool.OpenStringL(*encoded); CleanupStack::PopAndDestroy(2, nameAndPW); CleanupClosePushL(encodedString); RHTTPHeaders requestHeaders(aTransaction.Request().GetHeaderCollection()); requestHeaders.RemoveField(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable())); requestHeaders.SetFieldL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(iStringPool.StringF(HTTP::EBasic,RHTTPSession::GetTable()))); requestHeaders.SetFieldL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(encodedString)); aTransaction.PropertySet().SetPropertyL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(encodedString)); CleanupStack::PopAndDestroy(&encodedString); }
TBool TSimpleContentHandler::IsForbiddenTagL ( const TDesC8& aTag ) { for ( TInt i = HtmlTagsStringTable::EArea; i <= HtmlTagsStringTable::EParam; ++i ) { RString string = iStringPool->String( i, HtmlTagsStringTable::Table ); CleanupClosePushL ( string ); TInt result = aTag.Compare ( string.DesC() ); CleanupStack::PopAndDestroy ( 1 ); if ( !result ) { return ETrue; } } return EFalse; }
TBool CHttpEventHandler::GetHdrVal( THTTPHdrVal& hdrVal, RStringPool& pool) { TBool retval = ETrue; TPtrC8 auth_token((const TUint8*)"auth_token"); switch (hdrVal.Type()) { case THTTPHdrVal::KStrFVal: { RStringF fieldNameStr = pool.StringF(hdrVal.StrF()); const TDesC8& fieldNameDesC = fieldNameStr.DesC(); if (iVerbose) { TBuf<CHttpConstants::KMaxHeaderValueLen> value; value.Copy(fieldNameDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S:\n"), &value); } if ( fieldNameDesC.Length() > 0 && fieldNameDesC.Compare(auth_token) ) iCookies.Append(fieldNameDesC); else retval = EFalse; } break; case THTTPHdrVal::KStrVal: { RString fieldNameStr = pool.String(hdrVal.Str()); const TDesC8& fieldNameDesC = fieldNameStr.DesC(); if (iVerbose) { TBuf<CHttpConstants::KMaxHeaderValueLen> value; value.Copy(fieldNameDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S:\n"), &value); } if ( fieldNameDesC.Length() > 0 && fieldNameDesC.Compare(auth_token) ) iCookies.Append(fieldNameDesC); else retval = EFalse; } break; } return retval; }
void CSLContentHandler::HandleElementL ( const RString& /* aTag */, const RString& aAttributeName, const RString& aAttributeValue ) { __LOG_PTR_DEBUG("CSIContentHandler:: HandleElementL Called"); switch ( aAttributeName.Index ( slattributetable::Table ) ) { case slattributetable::EHref: delete iHrefBuf; iHrefBuf = NULL; iHrefBuf = EscapeUtils::ConvertToUnicodeFromUtf8L ( aAttributeValue.DesC() ); break; case slattributetable::EAction1: case slattributetable::EAction2: case slattributetable::EAction3: { switch ( aAttributeValue.Index ( slattributevaluetable::Table ) ) { // execute-low case slattributevaluetable::EAction1: iPushMsgAction = CSLPushMsgEntry::ESLPushMsgExecuteLow; break; case slattributevaluetable::EAction2: iPushMsgAction = CSLPushMsgEntry::ESLPushMsgExecuteHigh; break; case slattributevaluetable::EAction3: iPushMsgAction = CSLPushMsgEntry::ESLPushMsgExecuteCache; break; default: // shouldn't come here. User::Invariant (); } } break; default: // shouldn't come here. User::Invariant (); } }
TBool CHttpTestCaseGet14::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) { if(iCallsNum++) { iTestFail=1; iEngine->Utils().LogIt(_L("The test will fail: the credential haven't been kept(the GetCredential function has been called again)")); return EFalse; } iEngine->Utils().LogIt(_L("Supplying credentials")); iEngine->Utils().DumpData(aURI.UriDes()); iEngine->Utils().DumpData(aRealm.DesC()); iEngine->Utils().DumpData(aAuthenticationType.DesC()); _LIT8(KScooby, "scooby"); _LIT8(KDoo, "doo"); RStringPool p = aRealm.Pool(); aUsername = p.OpenStringL(KScooby); aPassword = p.OpenStringL(KDoo); return ETrue; }
void CHttpTestSingleTrans::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { // Handle the event switch (aEvent.iStatus) { case THTTPEvent::EGotResponseHeaders: { if (iLogCipherSuite) { RString cipherSuite = aTransaction.CipherSuite(); iEngine->Utils().LogIt(_L("Cipher Suite = %s\n"), &cipherSuite.DesC()); } } break; default: ; } CHttpAcceptTestBase::MHFRunL(aTransaction,aEvent); }
CTldListInitializer::TParserState CTldListInitializer::ParserStateL ( const RString& aTag, TBool aEndElement /* =EFalse */ ) { // Open a RString from the string pool RString myTagString = iStringPool.OpenStringL ( aTag.DesC() ); TInt tblIndex = myTagString.Index ( TLDXMLTAGS::Table ); TParserState parserState( EInitial ); switch ( tblIndex ) { case TLDXMLTAGS::EPolicyData: { parserState = aEndElement ? EEndOfPolicyData : EStartOfPolicyData; break; } case TLDXMLTAGS::EWhitelist: case TLDXMLTAGS::EBlacklist: { parserState = aEndElement ? EEndOfListtype : EStartOfListtype; SetListType ( tblIndex ); break; } case TLDXMLTAGS::ETLD: { parserState = aEndElement ? EEndOfTLD : EStartOfTLD; break; } default: { // Do nothing break; } } myTagString.Close (); return parserState; }
void CHttpController::ParseHeadersL( RHTTPTransaction& aTransaction ) { const TInt KMaxNumericLen = 32; RStringPool stringPool = aTransaction.Session().StringPool(); RHTTPHeaders header = aTransaction.Response().GetHeaderCollection(); THTTPHdrFieldIter iterator = header.Fields(); HBufC8* fieldName8 = NULL; HBufC8* fieldVal8 = NULL; CHttpHeaders* headers = CHttpHeaders::NewLC(); while ( !iterator.AtEnd() ) { RStringTokenF fieldName = iterator(); RStringF fieldNameStr = stringPool.StringF( fieldName ); THTTPHdrVal fieldVal; if ( header.GetField( fieldNameStr, 0, fieldVal ) == KErrNone ) { fieldName8 = fieldNameStr.DesC().AllocLC(); switch ( fieldVal.Type() ) { case THTTPHdrVal::KTIntVal: { fieldVal8 = HBufC8::NewLC( KMaxNumericLen ); TPtr8 ptr( fieldVal8->Des() ); ptr.Num( fieldVal.Int() ); break; } case THTTPHdrVal::KStrFVal: { RStringF fieldValStr = stringPool.StringF( fieldVal.StrF() ); fieldVal8 = fieldValStr.DesC().AllocLC(); break; } case THTTPHdrVal::KStrVal: { RString fieldValStr = stringPool.String( fieldVal.Str() ); fieldVal8 = fieldValStr.DesC().AllocLC(); break; } case THTTPHdrVal::KDateVal: { _LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3"); TDateTime date = fieldVal.DateTime(); const TInt KMaxDateBuferLength = 100; TBuf< KMaxDateBuferLength > dateBuffer; TTime time( date ); time.FormatL( dateBuffer, KDateFormat ); fieldVal8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( dateBuffer ); CleanupDeletePushL( fieldVal8 ); break; } default: User::Leave( KErrNotSupported );//new field types will be added in future break; } if ( !fieldVal8 ) { CleanupStack::PopAndDestroy( fieldName8 ); } else { headers->AddL( *fieldName8, *fieldVal8 ); CleanupStack::PopAndDestroy( 2, fieldName8 ); } fieldVal8 = NULL; fieldName8 = NULL; } ++iterator; } iObserver->HeadersReceivedL( headers ); CleanupStack::Pop( headers ); }
//------------------------------------------------------------------------ // CTestFilter::CheckHeadersL // Check HTTP headers and extract MIME type //------------------------------------------------------------------------ // void CTestFilter::CheckHeadersL( RHTTPTransaction& aTrans ) { // read the header data and check the MIME type here // check the status and body RHTTPResponse response = aTrans.Response(); TInt status = response.StatusCode(); THTTPHdrVal fieldVal; // check if status == 401 and realm is 3GPP then we need to bootstrap, if we are already bootstrappign this is the second call if( status == HTTPStatus::EUnauthorized ) { TInt headerPart=0; THTTPHdrVal headerVal; RStringF wwwAuthHeader = iStringPool.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); RHTTPHeaders headers(aTrans.Response().GetHeaderCollection()); RString realm; THTTPHdrVal hdrVal; if (!headers.GetParam(wwwAuthHeader, iStringPool.StringF(HTTP::ERealm,RHTTPSession::GetTable()), hdrVal, headerPart)) { realm = hdrVal; const TDesC8& val = realm.DesC(); if (headerPart == KErrNotFound) return; THTTPHdrVal authTypeParam; RHTTPTransactionPropertySet propSet = aTrans.PropertySet(); // if we are already bootstrapping results will be retrieved when request is resubmitted iBootstrapPending = ETrue; TTimeIntervalMicroSeconds32 aInterval(20000000); iTimeOut->Start(aInterval); //Start the http post request timer, aInterval - timeout in micro-seconds if(!iBootstrapWait.IsStarted()) { iBootstrapWait.Start(); } if( iHaveCredentials ) { RHTTPTransactionPropertySet propSet = aTrans.PropertySet(); //user name/pass word for accessing http://replab.nrln.net/digest/ //username: dummy, password: dummy TBuf8<KB64KeySize> keyBase64(_L8("Aladdin")); TBuf8<KB64KeySize> keyBase64Username(_L8("open sesame"));; RString username = iStringPool.OpenStringL( keyBase64 ); CleanupClosePushL<RString>( username ); RString password = iStringPool.OpenStringL( keyBase64Username ); CleanupClosePushL<RString>( password ); propSet.SetPropertyL( iUsernameStr, username ); propSet.SetPropertyL( iPasswordStr, password ); CleanupStack::PopAndDestroy(&password); CleanupStack::PopAndDestroy(&username); //Cancel the transaction aTrans.Cancel(); // Re-submit the http request with much needed credentials aTrans.SubmitL(); } else { //Since bootstrapping failed,Do not have to resubmit the http request ? return; } } } }
void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) { RHTTPResponse resp = aTrans.Response(); RStringPool strP = aTrans.Session().StringPool(); RHTTPHeaders hdr = resp.GetHeaderCollection(); THTTPHdrFieldIter it = hdr.Fields(); TBuf<CHttpConstants::KMaxHeaderNameLen> fieldName16; TBuf<CHttpConstants::KMaxHeaderValueLen> fieldVal16; while (it.AtEnd() == EFalse) { RStringTokenF fieldName = it(); RStringF fieldNameStr = strP.StringF(fieldName); THTTPHdrVal fieldVal; if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) { const TDesC8& fieldNameDesC = fieldNameStr.DesC(); fieldName16.Copy(fieldNameDesC.Left(CHttpConstants::KMaxHeaderNameLen)); switch (fieldVal.Type()) { case THTTPHdrVal::KTIntVal: iTest->Console()->Printf(_L("%S: %d\n"), &fieldName16, fieldVal.Int()); break; case THTTPHdrVal::KStrFVal: { RStringF fieldValStr = strP.StringF(fieldVal.StrF()); const TDesC8& fieldValDesC = fieldValStr.DesC(); fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); } break; case THTTPHdrVal::KStrVal: { RString fieldValStr = strP.String(fieldVal.Str()); const TDesC8& fieldValDesC = fieldValStr.DesC(); fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); } break; case THTTPHdrVal::KDateVal: { TDateTime date = fieldVal.DateTime(); TBuf<40> dateTimeString; TTime t(date); t.FormatL(dateTimeString,CHttpConstants::KDateFormat); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &dateTimeString); } break; default: iTest->Console()->Printf(_L("%S: <unrecognised value type>\n"), &fieldName16); break; } // Display realm for WWW-Authenticate header RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); if (fieldNameStr == wwwAuth) { // check the auth scheme is 'basic' RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable()); RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable()); THTTPHdrVal realmVal; if ((fieldVal.StrF() == basic) && (!hdr.GetParam(wwwAuth, realm, realmVal))) { RStringF realmValStr = strP.StringF(realmVal.StrF()); fieldVal16.Copy(realmValStr.DesC()); iTest->Console()->Printf(_L("Realm is: %S\n"), &fieldVal16); } } } ++it; } }