void CTorrentRecognizer::DoRecognizeL(const TDesC &aName, const TDesC8 &/*aBuffer*/) { iConfidence = ECertain; TParse parse; parse.Set(aName, NULL, NULL); TPtrC ext = parse.Ext(); if (ext.CompareF(KTorrentExtension) == 0) { iConfidence = ECertain; iDataType = TDataType(KTorrentType); } else { iConfidence = ENotRecognized; iDataType = TDataType(); } /*TFileName name=aName; name.LowerCase(); if (name.Right(KTorrentExtension().Length()) == KTorrentExtension) { iDataType = TDataType(KTorrentType); return; }*/ }
void CCustomCommandAsync::GetFileName(TPtrC path, TFileName* fileName) { TParse p; p.Set(path,NULL,NULL); fileName->Append(p.DriveAndPath()); fileName->Append(p.Name()); fileName->Append(p.Ext()); }
/* Attempts to recognize the data type, given the filename and data buffer. */ void CExampleNewRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) { _LIT8(KExampleData, "example"); _LIT(KDotExample, ".Example"); TParse parse; parse.Set(aName,NULL,NULL); TPtrC ext=parse.Ext(); // extract the extension from the filename if (ext.CompareF(KDotExample)==0 && aBuffer.FindF(KExampleData)!=KErrNotFound) { iConfidence=ECertain; iDataType=TDataType(KExampleTextMimeType); } }
// class CIconFileHandle : public CBase, public MContextBase, void FigureOutRealPathL(const TDesC& aFullPath, TDes& aRealPath, RFs& aFs) { CALLSTACKITEMSTATIC_N(_CL("JuikIcons"), _CL("FigureOutRealPathL")); if ( aFullPath == AknIconUtils::AvkonIconFileName() ) { aRealPath.Copy( aFullPath ); return; } #ifdef __S60V3__ // Change path to c:\\resource TParse p; p.Set( aFullPath, 0, 0); aRealPath=_L("c:\\resource\\"); aRealPath.Append(p.NameAndExt()); #else // Just use given path aRealPath=aFullPath; #endif #ifdef __WINS__ // in WINS, read always from Z aRealPath.Replace(0, 1, _L("z")); #else // In device, if file doesn't exist, read from E TBool try_mif=EFalse; if (p.Ext().CompareF(_L(".mbm"))==0) try_mif=ETrue; again: if (! BaflUtils::FileExists(aFs, aRealPath)) { aRealPath.Replace(0, 1, _L("e")); if (! BaflUtils::FileExists(aFs, aRealPath)) { if (try_mif) { aRealPath=_L("c:\\resource\\"); aRealPath.Append(p.Name()); aRealPath.Append(_L(".mif")); try_mif=EFalse; goto again; } User::Leave(KErrNotFound); } } #endif }
/** @internalComponent */ void CPreModifierPlugin::FsFileRenameL(TFsPluginRequest& aRequest) { TFileName oldfilename, newfilename; TParse parse; oldfilename = aRequest.Src().FullName(); newfilename = aRequest.Dest().FullName(); parse.Set(oldfilename, NULL, NULL); TPtrC extension(parse.Ext()); _LOG3(_L("CPreModifierPlugin::FsFileRenameL, old name: %S, new name: %S"), &oldfilename, &newfilename); if (aRequest.IsPostOperation()) { _LOG(_L("CPreModifierPlugin::FsFileRenameL, post intercept")); if (extension.CompareF(_L(".tst")) == 0) { TBuf8<32> tempBuf = (_L8("Rename Post Intercept")); RFilePlugin fileplugin(aRequest); TInt err = fileplugin.AdoptFromClient(); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL err = fileplugin.Write(20, tempBuf); _LOG2(_L("CPreModifierPlugin::FsFileRenameL, FileWrite returned %d"), err); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL fileplugin.Close(); } } else { User::Invariant(); } }
void CTestUpgradeRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& /*aBuffer*/) { // If an error stops CTestUpgradeRecognizer being removed as part of test cleanup, // returning ENotRecognized will avoid the possibility of impacting other test code. _LIT(KExtension , ".upr"); TParse parse; parse.Set(aName,NULL,NULL); TPtrC ext=parse.Ext(); // extract the extension from the filename if (ext.CompareF(KExtension)==0) { iDataType = TDataType(KMimeUprType); iConfidence = ECertain; } else { iDataType=TDataType(); iConfidence=ENotRecognized; } }
/** @internalComponent */ TInt CTestVirusHook::VsReadFileSection(TFsPluginRequest& aRequest) { // The t_virus test uses a filename clean.txt, a read length of 8 and a read position of 0. TFileName fileName; TInt len; TInt pos; // test getting name on read file section intercept TInt err = GetName(&aRequest, fileName); if(err != KErrNone) { return(err); } TParse parse; parse.Set(fileName,NULL,NULL); TPtrC name = parse.Name(); if(name.CompareF(_L("clean"))!=0) { return(KErrGeneral); } TPtrC ext = parse.Ext(); if(ext.CompareF(_L(".txt"))!=0) { return(KErrGeneral); } // test getting read length and required file position on read file section intercept err = GetFileAccessInfo(&aRequest, len, pos); if(err != KErrNone) { return(err); } if ((len != 8) || (pos != 0)) { return(KErrGeneral); } return KErrNone; }
void CMemDir::LoadDirL(const TDesC& aPath) // // Load a directory. // { TheLevel++; iPath=aPath.AllocL(); TFileName name=Name(_L("*.*")); test.Printf(_L("%*p%S\n"),TheLevel<<1,&name); CDir* pD; test(TheFs.GetDir(Name(_L("*.*")),KEntryAttMatchMask,EDirsFirst|ESortByName,pD)==KErrNone); TInt count=pD->Count(); TInt i=0; while (i<count) { const TEntry& e=(*pD)[i++]; TParse parse; parse.Set(e.iName,NULL,NULL); if (!parse.Ext().CompareF(_L(".NCB"))) continue; // Ignore .ncb files - cannot open/read them. CMemEntry* pE=CMemEntry::New(e); iEntryQ.AddLast(*pE); } delete pD; TDblQueIter<CMemEntry> q(iEntryQ); CMemEntry* pE; while ((pE=q++)!=NULL) { if (pE->IsDir()) { CMemDir* pM=CMemDir::NewL(); pE->SetDir(*pM); pM->LoadDirL(Name(pE->Name())); } else pE->SetDir(*this); } TheLevel--; }
/** @SYMTestCaseID APPFWK-APPARC-0080 @SYMREQ REQ7736 @SYMTestCaseDesc Tests IsClosedFileL() method for various files. @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Closed files are files whose file extensions are listed in the 10003a3f repository. Calls CApfMimeContentPolicy::IsClosedFileL(const TDesC& aFileName); for different Closed and non-closed files. Calls CApfMimeContentPolicy::IsClosedFileL(const TDesC& aFileName); with file which is already open and checks whether \n call succeeds. Calls CApfMimeContentPolicy::IsClosedFileL(const TDesC& aFileName); with Null file handle\n @SYMTestExpectedResults The test checks whether 1. IsClosedFileL() returns EFalse for Files which are not closed and ETrue for files which are closed. 2. IsClosedFileL() call succeeds even if we pass a open file handle. 3. IsClosedFileL() leaves with KErrBadHandle if a null file handle is passed. */ void CT_MimeContentPolicyStep::CCPTestIsClosedFileFileNameL() { INFO_PRINTF1(_L("Tests given files are Closed Files using the FileName")); TEST(!iCcp->IsClosedFileL(KPathjpg1)); // File passed to IsClosedFileL is already open. RFile fileHandle; TEST((fileHandle.Open(iFs, KPathjpg2, EFileShareAny)) == KErrNone); CleanupClosePushL(fileHandle); TEST(!iCcp->IsClosedFileL(KPathjpg2)); CleanupStack::PopAndDestroy(&fileHandle); // Bad File Handle is passed to IsClosedFileL API RFile nullFileHandle; INFO_PRINTF1(_L("Tests IsClosedFileL method passing null file handle")); TRAPD(err, iCcp->IsClosedFileL(nullFileHandle)); TEST(err == KErrBadHandle); // Check file extension. TParse parser; parser.Set(KPathdm2, NULL, NULL); TEST(iCcp->IsClosedExtension(parser.Ext())); INFO_PRINTF2(_L("%S is Closed File"), &KPathdm2); CApfMimeContentPolicy* mimeContentPolicy = CApfMimeContentPolicy::NewL(iFs); CleanupStack::PushL(mimeContentPolicy); TEST(!mimeContentPolicy->IsClosedFileL(KPathdcf)); INFO_PRINTF2(_L("%S is not Closed File"), &KPathdcf); CleanupStack::PopAndDestroy(mimeContentPolicy); mimeContentPolicy = CApfMimeContentPolicy::NewLC(iFs); TEST(!mimeContentPolicy->IsClosedFileL(KPathgif)); INFO_PRINTF2(_L("%S is not Closed File"), &KPathgif); CleanupStack::PopAndDestroy(mimeContentPolicy); }
/** Protected constructor. Extracts the initialisation data provided by the calling functions: ConstructSourceL() and ConstructSinkL(). Creates a file server session and sets up file name. If there is a file name and it cannot be found this function leaves. If there is no file name the function leaves. Does not attempt to open the file or check whether the file exists. If aInitData contains a TMMFFileHandleParams instead of TMMFFileParams, the source/sink is constructed from the file handle provided by the caller @param aInitData Initialisation data packaged in a TMMFFileParams or in a TMMFFileHandleParams (File Handle) */ void CFileMultimediaSource::ConstructL(const TDesC8& aInitData,TMMFileMode aFileMode) { User::LeaveIfError(iFsSession.Connect()); // on IPCv2 we auto attach User::LeaveIfError(iFsSession.ShareAuto()); User::LeaveIfError(iFsSession.ShareProtected()); TBool fileInit = EFalse; HBufC* filename = NULL; TBool filenamePushed = EFalse; iCAFParameters = new (ELeave) CCAFParameters; TBool drmContent = EFalse; RDesReadStream stream(aInitData); CleanupClosePushL(stream); TUid initUid; initUid = TUid::Uid(stream.ReadInt32L()); if (initUid == KMMFileHandleSourceUid) { TPckgBuf<RFile*> fileptr; stream.ReadL(fileptr); iHandle.Duplicate(*fileptr()); TInt length; length = stream.ReadInt32L(); if (length>0) { iCAFParameters->iUniqueId = HBufC::NewL(length); TPtr16 ptr = iCAFParameters->iUniqueId->Des(); stream.ReadL(ptr, length); } iFileHandle = ETrue; filename = HBufC::NewMaxL(KMaxFileName); TPtr ptr = filename->Des(); iHandle.Name(ptr); fileInit = ETrue; drmContent = ETrue; iCAFParameters->iEnableUI = stream.ReadInt32L(); } else if (initUid == KMMFileSourceUid) { TInt length; length = stream.ReadInt32L(); filename = HBufC::NewMaxLC(length); TPtr ptr = filename->Des(); stream.ReadL(ptr, length); length = stream.ReadInt32L(); if (length>0) { iCAFParameters->iUniqueId = HBufC::NewMaxL(length); ptr.Set(iCAFParameters->iUniqueId->Des()); stream.ReadL(ptr, length); } CleanupStack::Pop(filename); fileInit = ETrue; drmContent = ETrue; iFileHandle = EFalse; iCAFParameters->iEnableUI = stream.ReadInt32L(); } else { // TODO If the UID is unknown we should reject, but currently // code also used for older calls that just supply filename. // User::Leave(KErrNotSupported); } CleanupStack::PopAndDestroy(&stream); if (!fileInit && aInitData.Length() == sizeof(TMMFFileHandleParams)) { TMMFFileHandleParams params; TPckgC<TMMFFileHandleParams> config(params); config.Set(aInitData); params = config(); if (params.iUid == KFileHandleUid) { fileInit = ETrue; User::LeaveIfError(iHandle.Duplicate(*params.iFile)); TInt pos = 0; // make sure the duplicate handle is at the start of the file - the usage of the file handle really requires this User::LeaveIfError(iHandle.Seek(ESeekStart, pos)); iFileHandle = ETrue; filename = HBufC::NewMaxLC(KMaxFileName); filenamePushed = ETrue; TPtr ptr = filename->Des(); User::LeaveIfError(iHandle.Name(ptr)); } } if (!fileInit) // do old case as last resort { TMMFFileParams params; TPckgC<TMMFFileParams> config(params); config.Set(aInitData); params = config(); filename = params.iPath.AllocL(); fileInit = ETrue; } if (!filenamePushed) { // from now on it is assumed pushed. CleanupStack::PushL(filename); } TParse parser ; User::LeaveIfError(parser.Set(*filename, NULL, NULL)); CleanupStack::PopAndDestroy(filename); if ( !( parser.NamePresent() ) && !( parser.ExtPresent() ) ) User::Leave( KErrBadName ) ; iFullFileName.Copy( parser.FullName() ) ; iFileName = parser.Name().AllocL() ; iFileExt = parser.Ext().AllocL() ; iFilePath = parser.Path().AllocL() ; iFileDrive = parser.Drive().AllocL() ; // in order to simulate old behaviour we are not passing error out // but will try to create Content again during PrimeL() if (fileInit && drmContent && aFileMode==ESourceMode) { TInt contentError; if (iFileHandle) { TRAP(contentError, iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI); ); }
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToFileNameL(const TDesC& aFileName) { delete iMatchReqData; iMatchReqData = NULL; iMatchDataType = EMatchAny; // Extract the extension from the data passed in // Parse the path and extract the extension _LIT( KDot, "." ) ; _LIT8( KDot8, "." ); // If there is no dot "." in aFileName then assume that we have been passed the extension only (if KMaxExtLen or less) if ( (aFileName.Length() <= KMaxExtLen) && (aFileName.Find( KDot ) == KErrNotFound) ) { RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(aFileName.Length()+1); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName)); temp.Insert(0,KDot8); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } else if ( aFileName.Find( KDot ) == 0 ) // the first character is dot so assume extension only { RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(aFileName.Length()); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName)); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } else // We have been given the whole filename. Use TParse to extract the extension. { TParse parser ; parser.Set( aFileName, NULL, NULL ) ; if ( !( parser.NamePresent() ) ) User::Leave( KErrBadName ) ; if ( !( parser.PathPresent() ) ) { RFs fsSession ; User::LeaveIfError(fsSession.Connect()); TInt error = fsSession.Parse(aFileName, parser); fsSession.Close(); User::LeaveIfError(error); } // Parser should now have the full filename and path TPtrC extension = parser.Ext(); RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(extension.Length()); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, extension)); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } // If we're here, we must now have the file extension iMatchDataType = EMatchFileExtension; }
void CPreModifierPlugin::FsFileReplaceL(TFsPluginRequest& aRequest) { TFileName filename; TParse parse; filename = aRequest.Src().FullName(); TUint mode; TInt err = aRequest.Read(TFsPluginRequest::EMode, mode); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL parse.Set(filename, NULL, NULL); TPtrC extension(parse.Ext()); _LOG2(_L("CPreModifierPlugin::FsFileReplaceL, file: %S"), &filename); if (aRequest.IsPostOperation()) { _LOG(_L("CPreModifierPlugin::FsFileReplaceL, post intercept")); if ((extension.CompareF(_L(".tst")) == 0) && (aRequest.Message().Int1() != 0)) { //write to the newly replaced file TBuf8<64> wbuffer; wbuffer.Copy(_L8("TestTestTest")); RFilePlugin fileplugin(aRequest); TInt err = fileplugin.AdoptFromClient(); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL err = fileplugin.Write(0, wbuffer); _LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Write to the newly created file returned %d"), err); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL TInt length = wbuffer.Length(); HBufC8* tempBuf = HBufC8::NewMaxLC(length); TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length); err = fileplugin.Read(0, tempBufPtr); _LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Read returned %d"), err); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRe //testing the correct thing has been written to the drive err = wbuffer.Compare(tempBufPtr); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL fileplugin.Close(); CleanupStack::PopAndDestroy(); } } else { User::Invariant(); } }
/** @internalComponent */ void CPreModifierPlugin::FsFileLockL(TFsPluginRequest& aRequest) { TInt length = 0; TInt64 pos = 0; TFileName filename; TParse parse; TInt err = aRequest.FileName(filename); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL err = aRequest.Read(TFsPluginRequest::ELength, length); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL err = aRequest.Read(TFsPluginRequest::EPosition, pos); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL parse.Set(filename, NULL, NULL); TPtrC extension(parse.Ext()); _LOG4(_L("CPreModifierPlugin::FsFileLockL, file: %S, pos: %d, length: %d"), &filename, pos, length); if (aRequest.IsPostOperation()) { _LOG(_L("CPreModifierPlugin::FsFileLockL, post intercept")); // Request read from post interception if (extension.CompareF(_L(".lockread")) == 0) { length = 10; HBufC8* tempBuf = HBufC8::NewMaxLC(length); TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length); _LOG(_L("CPreModifierPlugin::FsFileLockL , calling AdoptFromClient in post intercept")); RFilePlugin fileplugin(aRequest); TInt err = fileplugin.AdoptFromClient(); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL _LOG2(_L("CPreModifierPlugin::FsFileLockL, Adopt returned %d"), err); err = fileplugin.Read(pos, tempBufPtr, length); _LOG2(_L("CPreModifierPlugin::FsFileLockL, FileRead returned %d"), err); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL fileplugin.Close(); CleanupStack::PopAndDestroy(); } // Request close from post interception if(extension.CompareF(_L(".lockclose")) == 0) { _LOG(_L("CPreModifierPlugin::FsFileLockL, file = *.lockclose post intercept ")); RFilePlugin fileplugin(aRequest); TInt err = fileplugin.AdoptFromClient(); _LOG2(_L("CPreModifierPlugin::FsFileLockL ,Open %d"), err); iLastError = err; iLineNumber = __LINE__; if(err!=KErrNone) User::Leave(err); //trapped in DoRequestL fileplugin.Close(); _LOG(_L("CPreModifierPlugin::FsFileLockL, Close")); } } else { User::Invariant(); } }
// ----------------------------------------------------------------------------- // CheckFileL() // check if it is target file // ----------------------------------------------------------------------------- // void CDcfRepSrv::CheckFileL(const TDesC& aFile , TInt& aType) { #ifdef _DRM_TESTING WriteL(_L8("CheckFileL")); #endif RFile f; TInt pos = 0; TBuf8<256> buf; switch(iState) { case EStateFullScan: case EStateScan: { User::LeaveIfError(f.Open(iFs,aFile,EFileRead|EFileShareReadersOrWriters)); CleanupClosePushL(f); User::LeaveIfError(f.Seek(ESeekStart,pos)); User::LeaveIfError(f.Read(0,buf)); CleanupStack::PopAndDestroy(&f); if (COma1Dcf::IsValidDcf(buf)) { aType = EOma1Dcf; } #ifdef __DRM_OMA2 else if (COma2Dcf::IsValidDcf(buf)) { aType = EOma2Dcf; } #endif else { aType = ENoDcf; } } break; case EStateSetTtid: { TParse p; User::LeaveIfError(p.Set(aFile,NULL,NULL)); if ( !p.Ext().Compare( KOma2DcfExtension ) || !p.Ext().Compare( KOma2DcfExtensionAudio ) || !p.Ext().Compare( KOma2DcfExtensionVideo ) ) { User::LeaveIfError(f.Open(iFs,aFile,EFileRead|EFileShareReadersOrWriters)); CleanupClosePushL(f); User::LeaveIfError(f.Seek(ESeekStart,pos)); User::LeaveIfError(f.Read(0,buf)); CleanupStack::PopAndDestroy(&f); if (COma1Dcf::IsValidDcf(buf)) { aType = EOma1Dcf; } #ifdef __DRM_OMA2 else if (COma2Dcf::IsValidDcf(buf)) { aType = EOma2Dcf; } #endif else { aType = ENoDcf; } } } break; default: ; } }