COCSPTransportDefault::TTransportScheme COCSPTransportDefault::IdentifySchemeL(const TDesC8& aURI) { TTransportScheme ret = ETransportSchemeNotSupported; TUriParser8 uri; TInt error = uri.Parse(aURI); if (error != KErrNone || !uri.IsPresent(EUriScheme)) { return ret; } const TPtrC8 scheme = uri.Extract(EUriScheme); RStringPool stringPool; stringPool.OpenL(); CleanupClosePushL(stringPool); RStringF schemeF = stringPool.OpenFStringL(scheme); CleanupClosePushL(schemeF); RStringF httpF = stringPool.OpenFStringL(KHttpString); CleanupClosePushL(httpF); if (schemeF == httpF) { ret = ETransportSchemeHTTP; } CleanupStack::PopAndDestroy(3); // close httpF, schemeF, stringPool return ret; }
void CHttpController::SendRequestL( TInt aMethodIndex, const TDesC8& aUri, CHttpHeaders* aHeaders ) { if ( !iObserver ) { User::Leave( KErrHttpInvalidObserver ); } RStringF method = iSession.StringPool().StringF( aMethodIndex, RHTTPSession::GetTable() ); TUriParser8 uri; uri.Parse( aUri ); iTransaction = iSession.OpenTransactionL( uri, *this, method ); RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); RArray< TInt > addedElements; CleanupClosePushL( addedElements ); SetHeaderL( HTTP::EUserAgent, hdr, KUserAgent, addedElements ); SetHeaderL( HTTP::EConnection, hdr, KClose, addedElements ); SetHeaderL( HTTP::EAccept, hdr, KAccept, addedElements ); SetHeaderL( HTTP::EHost, hdr, uri.Extract( EUriHost ), addedElements ); TInt count( iPersistentHeaders->Count() ); for ( TInt i( 0 ); i < count; ++i ) { if ( addedElements.FindInOrder( i ) >= 0 ) { continue; } SetHeaderL( hdr, iPersistentHeaders->Key( i ), iPersistentHeaders->Value( i ) ); } CleanupStack::PopAndDestroy( &addedElements ); if ( aHeaders ) { TInt count( aHeaders->Count() ); for ( TInt i( 0 ); i < count; ++i ) { SetHeaderL( hdr, aHeaders->Key( i ), aHeaders->Value( i ) ); } } if ( aMethodIndex == HTTP::EPOST ) { const TInt KMaxContentLenBufferLength = 100; TBuf8< KMaxContentLenBufferLength > contentLength; contentLength.Num( iOutputEncoder->OverallDataSize() ); SetHeaderL( hdr, HTTP::EContentLength, contentLength ); SetHeaderL( hdr, HTTP::EContentType, KUrlEncodedContentType ); iTransaction.Request().SetBody( *iOutputEncoder ); } iTransaction.SubmitL(); StartTimeout(); iState = EHttpActive; }
// ---------------------------------------------------------------------------- // CURIContainer::CreateUri8L // ---------------------------------------------------------------------------- // CUri8* CURIContainer::CreateUri8L(const TDesC8& aValue) { TUriParser8 parser; User::LeaveIfError(parser.Parse(aValue)); TPtrC8 scheme(parser.Extract(EUriScheme)); if (scheme.CompareF(SIPStrings::StringF(SipStrConsts::ESip).DesC()) == 0) { User::LeaveIfError(parser.Validate()); } return CUri8::NewL(parser); }
/** Converts a 16-bit format uri into its internet form. Any Unicode characters are converted into Utf8 representation and then any excluded characters are escape encoded. Reserved characters specified in RFC2396 will not be escape encoded however, these include ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ",". For example http://localhost will not be encoded to http%3A%2F%2Flocalhost. @since 6.0 @deprecated Deprecated in 9.1 @leave KUriUtilsCannotConvert. When the input data cannot be converted. @leave KUriUtilsErr16BitChar. When the input data has a 16-Bit character to be escape encoded. @param aUri The 16-bit format uri. @return A pointer to a newly created 8-bit uri. */ EXPORT_C CUri8* UriUtils::ConvertToInternetFormL(const TUriC16& aUri) { // Need to convert to utf8 HBufC8* utf8Buf = EscapeUtils::ConvertFromUnicodeToUtf8L(aUri.UriDes()); CleanupStack::PushL(utf8Buf); // Ok need to parse for the uri without the fragment TUriParser8 parser; parser.Parse(*utf8Buf); TPtrC8 uriNoFragment; parser.UriWithoutFragment(uriNoFragment); // Now escape encode the uri without the fragment HBufC8* escapedBuf = EscapeUtils::EscapeEncodeL(uriNoFragment, EscapeUtils::EEscapeNormal); CleanupStack::PushL(escapedBuf); // Now escape encode the fragment if there is one... HBufC8* escapedFragmentBuf = NULL; if( parser.IsPresent(EUriFragment) ) { escapedFragmentBuf = EscapeUtils::EscapeEncodeL(parser.Extract(EUriFragment), EscapeUtils::EEscapeNormal); CleanupStack::PushL(escapedFragmentBuf); } // Parse and then create the CUri8 object parser.Parse(*escapedBuf); CUri8* netForm = CUri8::NewL(parser); // Set the fragment if there was one... if( escapedFragmentBuf != NULL ) { CleanupStack::PushL(netForm); netForm->SetComponentL(*escapedFragmentBuf, EUriFragment); CleanupStack::Pop(netForm); CleanupStack::PopAndDestroy(escapedFragmentBuf); } // Cleanup and return CleanupStack::PopAndDestroy(2, utf8Buf); // utf8Buf, escapedBuf return netForm; }
//Extract URI components void CExampleInetProtUtil::ExtractUriComponentsL() { _LIT(KTextExtract, "\n\n\nExtracting from....\n"); iConsole->Printf ( KTextExtract ); //Create a Uri _LIT(KUriName, "K:\\ws\\direct\\direct.mmp"); TBuf<40> desUriName(KUriName); CUri8* uriName = CUri8::CreateFileUriL(desUriName); //Display the Uri const TDesC8& uriDisplay = uriName->Uri().UriDes(); TBuf16<100> desExtract; desExtract.Copy (uriDisplay); iConsole->Printf ( desExtract ); //Parse the Uri TUriParser8* uriComponent = new(ELeave) TUriParser8(); uriComponent->Parse(uriDisplay); //Extract the Scheme component from this Uri const TDesC8& host = uriComponent->Extract(EUriScheme); TBuf16<100> desEx; desEx.Copy (host); //Display the Component extracted _LIT(KTextEx, "\nThe extracted Scheme component is....\n"); iConsole->Printf ( KTextEx ); iConsole->Printf ( desEx ); //delete fileName; delete uriComponent; delete uriName; iConsole->Getch(); }