/** @publishedPartner @prototype Sets this object to match to uri scheme and file extension specified by a URI. The Uri scheme and extension are saved in iMatchReqData. Further,iMatchData contains uri extension, iMatchUriScheme contains uri scheme. @param aUri The URI containing the scheme and uri extension to be matched. */ EXPORT_C void CMMFFormatSelectionParameters::SetMatchToUriSupportL(const TDesC& aUrl) { delete iMatchReqData; iMatchReqData = NULL; iMatchDataType = EMatchAny; CUri8* uri = UriUtils::CreateUriL(aUrl); //Converts the TDesC16 aUrl to TDesC8 type CleanupStack::PushL(uri); const TDesC8& scheme = uri->Uri().Extract(EUriScheme); //get the uri scheme iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchUriSchemeL(scheme); const TDesC8& path = uri->Uri().Extract(EUriPath); // Now parse the file name TInt pos = path.LocateReverse('.'); if(pos != KErrNotFound) // if not found, by default match data is NULL { TPtrC8 extension(path.Right(path.Length()-pos)); iMatchReqData->SetMatchDataL(extension); } CleanupStack::PopAndDestroy(uri); // If we're here, we must now have the uri saved in iMatchData. Now, set match type // to EMatchUri for checking schema and uri extension iMatchDataType = EMatchUri; }
/** Create a new transaction. Generate the full uri from a partial uri. Also, generates the file path where the contents to be saved. Adds the transaction object into array. @param aUri [in] URI to download. @param aParseHtml [in] Parse the downloaded HTML content. Default value: EFalse. ETrue value to parse the HTML content. Typically the value will be set to ETrue only for the main page. */ void CTestWebBrowser::CreateTransactionL ( const TDesC8& aUri, TBool aParseHtml /* = EFalse */ ) { TUriParser8 baseUri; baseUri.Parse ( iBaseUri->Des() ); TUriParser8 refUri; refUri.Parse ( aUri ); // Resolve uri CUri8* uriPtr = CUri8::ResolveL( baseUri, refUri ); CleanupStack::PushL ( uriPtr ); // Generate the file path from the full http uri. HBufC* filePath = GenerateFilePathL ( uriPtr->Uri() ); CleanupStack::PushL ( filePath ); // Create a new HTTP transaction object. CBrowserTransaction* newTrans = CBrowserTransaction::NewL ( iHttpSession, iTestUtils, this, *filePath, aParseHtml ); CleanupStack::PopAndDestroy ( filePath ); CleanupStack::PushL ( newTrans ); iTransArray.AppendL ( newTrans ); // Open and submit the transaction. newTrans->CreateTransactionL ( uriPtr->Uri().UriDes() ); newTrans->StartTransactionL (); CleanupStack::Pop ( newTrans ); CleanupStack::PopAndDestroy ( uriPtr ); return; }
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToUriL(const TDesC& aUrl) { delete iMatchReqData; iMatchReqData = NULL; iMatchDataType = EMatchAny; CUri8* uri = UriUtils::CreateUriL(aUrl); //Converts the TDesC16 aUrl to TDesC8 type CleanupStack::PushL(uri); const TDesC8& path = uri->Uri().Extract(EUriPath); // Now parse the file name TInt pos = path.LocateReverse('.'); if(pos != KErrNotFound) // if not found, then by default match data is NULL { TPtrC8 extension(path.Right(path.Length()-pos)); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(extension); } CleanupStack::PopAndDestroy(uri); // If we're here, we must now have the file extension // Use match file extension, because we are matching to the file extension of the file specified by the URI iMatchDataType = EMatchFileExtension; }
// ----------------------------------------------------------------------------- // LocalHostCheckL // If the host is a local host, then remove the proxy property. Returns ETrue // if the transaction request URI was for a localhost. // ----------------------------------------------------------------------------- // TBool LocalHostCheckL(RHTTPTransaction& aTransaction, RStringPool& aStringPool) { _LIT8(KLoopbackIPv4Url, "http://127.0.0.1"); RHTTPRequest request = aTransaction.Request(); TUriC8 uri = request.URI(); TUriParser8 parserLoopBack; parserLoopBack.Parse(KLoopbackIPv4Url()); TInt match = parserLoopBack.Compare(uri, EUriHost); if (KErrNone != match) { _LIT8(KLocalHostUrl, "http://localhost"); // try another compare - compare against the "localhost". TUriParser8 parserLocalHost; parserLocalHost.Parse(KLocalHostUrl()); match = parserLocalHost.Compare(uri, EUriHost); if (KErrNone == match) { _LIT8(KLoopbackIPv4, "127.0.0.1"); // "localhost" resolves to "::1", manually, replace with "127.0.0.1" CUri8* newUri = CUri8::NewLC(uri); newUri->SetComponentL(KLoopbackIPv4(), EUriHost); request.SetURIL(newUri->Uri()); CleanupStack::PopAndDestroy(newUri); } } if (KErrNone == match) { // request is for localhost, explicitly state that this transaction // must not be sent to proxy. RStringF proxyUsageStrF = aStringPool.StringF(HTTP::EProxyUsage, RHTTPSession::GetTable()); RStringF dontUseProxyStrF = aStringPool.StringF(HTTP::EDoNotUseProxy, RHTTPSession::GetTable()); aTransaction.PropertySet().RemoveProperty(proxyUsageStrF); aTransaction.PropertySet().SetPropertyL(proxyUsageStrF, dontUseProxyStrF); //RStringF proxyAddrStrF = aStringPool.StringF(HTTP::EProxyAddress, // RHTTPSession::GetTable()); //aTransaction.PropertySet().RemoveProperty(proxyAddrStrF); return ETrue; } return EFalse; }
// ----------------------------------------------------------------------------- // MceSip::CompareUri // ----------------------------------------------------------------------------- // TInt MceSip::CompareUri( const CUri8& aRemoteUriOne, const CUri8& aRemoteUriTwo ) { TInt ret = KErrGeneral; if ( aRemoteUriOne.Uri().Compare( aRemoteUriTwo.Uri(), EUriScheme ) == KErrNone && aRemoteUriOne.Uri().Compare( aRemoteUriTwo.Uri(), EUriUserinfo ) == KErrNone && aRemoteUriOne.Uri().Compare( aRemoteUriTwo.Uri(), EUriHost ) == KErrNone ) { ret = KErrNone; } return ret; }
//Modify URI components void CExampleInetProtUtil::ModifyUriComponentsL() { TUriParser8 parser1; CUri8* aUri = CUri8::NewL(parser1); _LIT(KText3, "\n\n\nAdding Uri components one by one...."); iConsole->Printf ( KText3 ); // Adding components to the Uri //Setting and displaying SCHEME _LIT8(KScheme, "http"); _LIT(KScheme1, "\nSCHEME : http"); iConsole->Printf ( KScheme1 ); aUri->SetComponentL(KScheme, EUriScheme); //Setting and displaying HOST _LIT8(KHost, "www.symbian.com"); _LIT(KHost1, "\nHOST : www.symbian.com"); iConsole->Printf ( KHost1 ); aUri->SetComponentL(KHost, EUriHost); //Setting and displaying PORT _LIT8(KPort, "80"); _LIT(KPort1, "\nPORT : 80"); iConsole->Printf ( KPort1 ); aUri->SetComponentL(KPort, EUriPort); //Setting and displaying PATH _LIT8(KPath, "/developer/techlib/turic8class.html"); _LIT(KPath1, "\nPATH : /developer/techlib/turic8class.html"); iConsole->Printf ( KPath1 ); aUri->SetComponentL(KPath, EUriPath); //Display the constucted Uri _LIT(KText4, "\nThe fully constructed Uri...."); iConsole->Printf ( KText4 ); const TDesC8& desUriDisplay = aUri->Uri().UriDes(); TBuf16<100> desFullUri; desFullUri.Copy (desUriDisplay); iConsole->Printf( KLeaveALine ); iConsole->Printf ( desFullUri ); // Removal of component from the Uri iConsole->Getch (); _LIT(KText5, "\n\nUri with the Port number removed....\n"); iConsole->Printf ( KText5 ); aUri->RemoveComponentL(EUriPort); //Display the modified Uri const TDesC8& desRemovedComponentDisplay =aUri->Uri().UriDes(); TBuf16<100> desRemovedComponent; desRemovedComponent.Copy (desRemovedComponentDisplay); iConsole->Printf ( desRemovedComponent ); delete aUri; iConsole->Getch (); }
//Validate URI components void CExampleInetProtUtil::ValidateUriComponentsL() { TUriParser8 parser1; CUri8* aUri = CUri8::NewL(parser1); _LIT(KTextf, "\n\n\nValidating the Uri....\n"); iConsole->Printf ( KTextf ); // Adding components to the Uri //Adding Scheme _LIT8(KScheme, "http"); aUri->SetComponentL(KScheme,EUriScheme); //Adding Host _LIT8(KHost, "waterlang.org"); aUri->SetComponentL(KHost,EUriHost); //Adding Port _LIT8(KPort, "90"); aUri->SetComponentL(KPort,EUriPort); //Adding Path _LIT8(KPath, "/turic8class.html"); aUri->SetComponentL(KPath,EUriPath); //Adding Query _LIT8(KQuery, "bar=2&x=3"); aUri->SetComponentL(KQuery,EUriQuery); //Adding Fragment _LIT8(KFragment, "fragment"); aUri->SetComponentL(KFragment,EUriFragment); //Display the constructed Uri const TDesC8& desUriDisplays =aUri->Uri().UriDes(); TBuf16<100> desValidate; desValidate.Copy (desUriDisplays); iConsole->Printf ( desValidate ); // Validate() is not supported for HTTP, but only SIP and SIPS. //The Parse() function itself validates the components and returns the //appropriate result. TInt res = parser1.Parse(desUriDisplays); if (res==KErrNone) { _LIT(KText8, "\nThis Uri is VALID"); iConsole->Printf ( KText8 ); } delete aUri; iConsole->Getch(); }
// ----------------------------------------------------------------------------- // CUpnpElementBean::ValAsUriL // (other items were commented in a header). // ----------------------------------------------------------------------------- // HBufC8* CUpnpElementBean::ValAsUriL() const { // uris have to be properly escaped HBufC* tmp = UpnpCdUtils::Des8ToDesLC(*iElmValue); TUriParser uripar; uripar.Parse(*tmp); CUri8* uri = uri = UriUtils::ConvertToInternetFormL(uripar); CleanupStack::PopAndDestroy(tmp); if (uri->Uri().UriDes().Length()) { HBufC8* tmp2 = UpnpString::StringReplaceL(uri->Uri().UriDes(),KHash8,KHashASCII8); delete uri; return tmp2; } HBufC8* uriDes = uri->Uri().UriDes().Alloc(); delete uri; return uriDes; }
/** 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; }
void CHttpClientFilter::EnsurePathExistsL(RHTTPTransaction aTransaction) { RHTTPRequest request = aTransaction.Request(); TUriC8 originalUri = request.URI(); // There is alwaya a path in a uri - ensure that it is not empty. const TDesC8& path = originalUri.Extract(EUriPath); TBool pathPresent = (path.Length() > 0); TBool hostPresent = originalUri.IsPresent(EUriHost); // If there is no path then make sure the uri // ends in '/' - server root path. if( hostPresent && !pathPresent ) { _LIT8(KDefaultUriPath, "/"); CUri8* uri = CUri8::NewLC(originalUri); uri->SetComponentL(KDefaultUriPath, EUriPath); request.SetURIL(uri->Uri()); CleanupStack::PopAndDestroy(uri); } }
// ----------------------------------------------------------------------------- // LocalHostCheckL // If the host is a local host. Returns ETrue // if the transaction request URI was for a localhost. // ----------------------------------------------------------------------------- // TBool LocalHostCheckL(RHTTPTransaction& aTransaction) { _LIT8(KLoopbackIPv4Url, "http://127.0.0.1"); RHTTPRequest request = aTransaction.Request(); TUriC8 uri = request.URI(); TUriParser8 parserLoopBack; parserLoopBack.Parse(KLoopbackIPv4Url()); TInt match = parserLoopBack.Compare(uri, EUriHost); if (KErrNone != match) { _LIT8(KLocalHostUrl, "http://localhost"); // try another compare - compare against the "localhost". TUriParser8 parserLocalHost; parserLocalHost.Parse(KLocalHostUrl()); match = parserLocalHost.Compare(uri, EUriHost); if (KErrNone == match) { _LIT8(KLoopbackIPv4, "127.0.0.1"); // "localhost" resolves to "::1", manually, replace with "127.0.0.1" CUri8* newUri = CUri8::NewLC(uri); newUri->SetComponentL(KLoopbackIPv4(), EUriHost); request.SetURIL(newUri->Uri()); CleanupStack::PopAndDestroy(newUri); } } if (KErrNone == match) { return ETrue; } return EFalse; }
//Extract URI components void CExampleInetProtUtil::RetrieveFileNameL() { _LIT(KTextRet, "\n\n\nRetrieving filename from....\n"); iConsole->Printf ( KTextRet ); //Create a Uri _LIT(KUriRetName, "K:\\ws\\direct\\direct.mmp"); TBuf<40> desUriRetName(KUriRetName); CUri8* uriRetName = CUri8::CreateFileUriL(desUriRetName); //Display the Uri const TDesC8& uriDisp = uriRetName->Uri().UriDes(); TBuf16<100> desRetrieve; desRetrieve.Copy (uriDisp); iConsole->Printf ( desRetrieve ); //Parse the Uri TUriParser8* uriComp = new(ELeave) TUriParser8(); uriComp->Parse(uriDisp); //Get or Extract the Filename from the Uri _LIT(KTextGetFilename, "\nGetting the filename....\n"); iConsole->Printf ( KTextGetFilename ); HBufC* fileName = uriComp->GetFileNameL(); TPtr uriFileNameDisplay = fileName->Des(); TBuf16<100> desFileName; desFileName.Copy (uriFileNameDisplay); iConsole->Printf ( desFileName ); delete fileName; delete uriComp; delete uriRetName; iConsole->Getch(); }
//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(); }
void ParseUriTests16BitL() { test.Next(_L("Parsing 16 bit URIs")); gFullUri16.Copy(KUri0); CUri8* uri = UriUtils::CreateUriL(gFullUri16); CleanupStack::PushL(uri); gUriComponent16.Copy(KScheme0); HBufC* text = uri->Uri().DisplayFormL(EUriScheme); TInt result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentScheme; delete text; User::LeaveIfError(result); gUriComponent16.Copy(KUserInfo0); text = uri->Uri().DisplayFormL(EUriUserinfo); result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentUserInfo; delete text; User::LeaveIfError(result); gUriComponent16.Copy(KHost0); text = uri->Uri().DisplayFormL(EUriHost); result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentHost; delete text; User::LeaveIfError(result); gUriComponent16.Copy(KPort0); text = uri->Uri().DisplayFormL(EUriPort); result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentPort; delete text; User::LeaveIfError(result); gUriComponent16.Copy(KParams0); text = uri->Uri().DisplayFormL(EUriPath); result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentPath; delete text; User::LeaveIfError(result); gUriComponent16.Copy(KHeaders0); text = uri->Uri().DisplayFormL(EUriQuery); result = text->Compare(gUriComponent16) == 0? KErrNone : KUriUtilsErrDifferentQuery; delete text; User::LeaveIfError(result); CleanupStack::PopAndDestroy(uri); }
//Resolve the Uri w.r.t a Base and a refernce Uri void CExampleInetProtUtil::ResolveUriL() { _LIT(KTextResolve1, "\n\n\nThe Base and reference Uris are\n"); iConsole->Printf ( KTextResolve1 ); TUriParser8 parserResolve1; CUri8* aUriBase = CUri8::NewL(parserResolve1); //Adding Scheme _LIT8(KScheme, "http"); aUriBase->SetComponentL(KScheme,EUriScheme); //Adding Host _LIT8(KHost, "symbian.com"); aUriBase->SetComponentL(KHost,EUriHost); //Adding Port _LIT8(KPort, "90"); aUriBase->SetComponentL(KPort,EUriPort); //Adding Path _LIT8(KPath, "/resolve.aspx"); aUriBase->SetComponentL(KPath,EUriPath); const TDesC8& desBaseUri =aUriBase->Uri().UriDes(); TBuf16<100> desBase; desBase.Copy (desBaseUri); iConsole->Printf ( desBase ); iConsole->Printf( KLeaveALine ); CUri8* aUriRef = CUri8::NewL(parserResolve1); //Adding Path _LIT8(KPath1, "/uris/base/reference/resolve.aspx"); aUriRef->SetComponentL(KPath1,EUriPath); //Adding Query _LIT8(KQuery1, "bar=2&x=3"); aUriRef->SetComponentL(KQuery1,EUriQuery); const TDesC8& desRefUri =aUriRef->Uri().UriDes(); TBuf16<100> desRef; desRef.Copy (desRefUri); iConsole->Printf ( desRef ); _LIT(KTextResolve, "\nThe Resolved Uri is....\n"); iConsole->Printf ( KTextResolve ); //Resolve the 2 Uri's to get a resultant uri CUri8* Uri8 = CUri8::ResolveL(aUriBase->Uri(),aUriRef->Uri()); // Display the resultant Uri const TDesC8& desDisplayReslovedUri = Uri8->Uri().UriDes(); TBuf16<100> desResolve; desResolve.Copy (desDisplayReslovedUri); iConsole->Printf ( desResolve ); delete Uri8; delete aUriRef; delete aUriBase; iConsole->Getch (); }