// ============================================================================
// Get the property descriptiont by finding entry for name.
//
// @param aPropName The name of the prop: <prop>propName</prop>
// @since 5.0
// @return prop type.
// ============================================================================
//
TInt CWidgetBackupRegistryXml::GetPropertyId(
    const TDesC& aPropName )
    {
    TInt i = 0;
    for (; i < iProperties.Count(); ++i )
        {
        // use case insensitive match for property names
        if ( 0 == aPropName.CompareF( iProperties[i].name ) )
            {
            return iProperties[i].id;
            }
        }
    TUint16* name = NULL;
    name = new TUint16 [aPropName.Length()];
    if (name)
        {
        TPtr namePtr(name, aPropName.Length());
        namePtr.Copy(aPropName);
        TWidgetProperty property;
        property.id = iProperties.Count();
        property.name.Set( namePtr );
        property.type = EWidgetPropTypeUnknown;
        TInt err = iProperties.Append(property);
        if (err == KErrNone)
            {
            return iProperties.Count() - 1;
            }
        delete name;
        }
    return EWidgetPropertyIdInvalid;
    }
/**
 Private Setter, used by the constructor and the assignment operator
 @param aNameRecord TNameRecord to create extended inquiry response from
 */
EXPORT_C void TExtendedInquiryResponseDataCodec::Set(TNameRecord& aNameRecord)
	{
	LOG_FUNC
	TUint8* name = (TUint8*)(aNameRecord.iName.Ptr());
	TPtr8 namePtr(name, aNameRecord.iName.Size(), aNameRecord.iName.MaxSize());
	iNameRecord = &aNameRecord; 
	Set(namePtr);
	}
TSymbianFileEntry*	CreateSymbianFileEntry(const char* name, const char* mode) {
	TSymbianFileEntry* fileEntry = new TSymbianFileEntry;
	fileEntry->_inputPos = KErrNotFound;
	fileEntry->_lastError = 0;
	fileEntry->_eofReached = EFalse;

	if (fileEntry != NULL) {
		TInt modeLen = strlen(mode);

		TPtrC8 namePtr((unsigned char*) name, strlen(name));
		TFileName tempFileName;
		tempFileName.Copy(namePtr);

		TInt fileMode = EFileRead;

		if (mode[0] == 'a')
			fileMode = EFileWrite;

		if (!((modeLen > 1 && mode[1] == 'b') || (modeLen > 2 && mode[2] == 'b'))) {
			fileMode |= EFileStreamText;
		}

		if ((modeLen > 1 && mode[1] == '+') || (modeLen > 2 && mode[2] == '+')) {
			fileMode = fileMode| EFileWrite;
		}

		fileMode = fileMode| EFileShareAny;

		switch (mode[0]) {
		case 'a':
			if (fileEntry->_fileHandle.Open(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
				if (fileEntry->_fileHandle.Create(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
					delete fileEntry;
					fileEntry = NULL;
				}
			}
			break;
		case 'r':
			if (fileEntry->_fileHandle.Open(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
				delete fileEntry;
				fileEntry = NULL;
			}
			break;

		case 'w':
			if (fileEntry->_fileHandle.Replace(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
				delete fileEntry;
				fileEntry = NULL;
			}
			break;
		}
	}
	return fileEntry;
}
void UPPayHttpConnection::setRequestProperty(const char *property, const char *value)
{
	TInt len = User::StringLength((const TUint8*) property);
	if (!len)
		return;
	TPtr8 namePtr((TUint8 *) property, len, len);
	len = User::StringLength((const TUint8*) value);
	if (!len)
		return;
	TPtr8 valuePtr((TUint8 *) value, len, len);
	//CommonUtils::WriteLogL(namePtr, valuePtr);
	RStringF val;
	val = stringPool.OpenFStringL(namePtr);
	headers.SetRawFieldL(val, valuePtr, _L8(";"));
	val.Close();
}
// ---------------------------------------------------------------------------
// CAppMngr2FileRecognizer::RecognizeNextFileL()
// ---------------------------------------------------------------------------
//
void CAppMngr2FileRecognizer::RecognizeNextFileL()
    {
    if( iIndex < iDirEntries->Count() )
        {
        // recognize the file which index is iIndex
        const TEntry& file = ( *iDirEntries )[ iIndex ];
        
        HBufC* fullName = HBufC::NewLC( iDirPath->Length() + file.iName.Length() );
        TPtr namePtr( fullName->Des() );
        namePtr.Copy( *iDirPath );
        namePtr.Append( file.iName );
        
        ContentAccess::CContent* content = ContentAccess::CContent::NewLC(
                *fullName, ContentAccess::EContentShareReadWrite );
        
        HBufC* mimeType = HBufC::NewLC( KMaxDataTypeLength );
        TPtr mimePtr( mimeType->Des() );
        User::LeaveIfError( content->GetStringAttribute( ContentAccess::EMimeType, mimePtr ) );

        CAppMngr2RecognizedFile* recFile = CAppMngr2RecognizedFile::NewL( fullName, mimeType );
        CleanupStack::Pop( mimeType );		// CAppMngr2RecognizedFile takes ownership
        CleanupStack::PopAndDestroy( content );
        CleanupStack::Pop( fullName );
        
        CleanupStack::PushL( recFile );
        iResultArray.AppendL( recFile );
        CleanupStack::Pop( recFile );

        // and then recognize the next file
        iIndex++;
        SetActive();
        TRequestStatus* fileStatus = &iStatus;
        User::RequestComplete( fileStatus, KErrNone );
        }
    else
        {
        // all done, directory has been processed
        User::RequestComplete( iDirStatus, KErrNone );
        iDirStatus = NULL;
        }
    }
void CTe_LbsIniFileReader::ReadExecutableNameL(TDes& aExecutableName)
{
    TUint16* buffer = new (ELeave) TUint16[KPositionModuleMaxNameLength];
    CleanupStack::PushL(buffer);

    TPtrC16 namePtr(reinterpret_cast<const TUint16*>(buffer),KPositionModuleMaxNameLength);
    TBool success = FindVar(KExecutableNameStr, namePtr);

    TBuf<KPositionModuleMaxNameLength> executableName;

    if(success)
    {
        aExecutableName.Copy(namePtr);
    }
    else
    {
        aExecutableName.Copy(KNullDesC);
    }

    CleanupStack::PopAndDestroy(buffer);

}
Beispiel #7
0
	void FileStream::open(const char* filename, bool write, bool append, bool exist) {
		mOpenResult = mFs.Connect();
		if(mOpenResult != KErrNone)
			return;

		TPtrC8 namePtr(CBP filename);
		mFilename = HBufC8::New(namePtr.Length() + 1);
		if(!mFilename) {
			mOpenResult = KErrNoMemory;
			return;
		}
		mFilename->Des().Copy(namePtr);
		mFilename->Des().PtrZ();	//set the zero terminator, for getFilename().

		TCleaner<HBufC16> unicodeName(CreateHBufC16FromDesC8LC(namePtr));
		if(write) {
			if(append || exist) {
				LOG("AFO %s\n", filename);
				TSNR(mOpenResult = mFile.Open(mFs, *unicodeName, EFileShareExclusive | EFileWrite));
				if(IS_SYMBIAN_ERROR(mOpenResult))
					return;
				TInt offset = 0;
				if(append) {
					// TODO: set a flag so that every write goes to the end of the file,
					// even if you seek to another position.
					TSNR(mOpenResult = mFile.Seek(ESeekEnd, offset));
				}
			} else {
				LOG("WFO %s\n", filename);
				TSNR(mOpenResult = mFile.Replace(mFs, *unicodeName, EFileShareExclusive | EFileWrite));
			}
		} else {
			LOG("RFO %s\n", filename);
			TSNR(mOpenResult = mFile.Open(mFs, *unicodeName, EFileShareReadersOnly));
		}
	}
TVerdict CAppFwkStartSafeTestStepProcStartMon::doTestStepL( void )
	{
	
	CStartSafe* startSafe = CStartSafe::NewL();	
	CleanupStack::PushL( startSafe );
	
	CStartupProperties* prop = CStartupProperties::NewL();
	CleanupStack::PushL( prop );

	RProcess proc;	
	CleanupClosePushL( proc );
	
	// KLaunchServerCommandLineOption makes the process listen for remote control connections
	prop->SetFileParamsL( KTestProcGood, KLaunchServerCommandLineOption ); 
	prop->SetStartupType( EStartProcess );
	prop->SetStartMethod( EWaitForStart ); // EFireAndForget is disallowed
	prop->SetMonitored( ETrue ); // the process death will be monitored
	prop->SetNoOfRetries( 1 );   // Must be non-zero in order to invoke a restart


		
	INFO_PRINTF1( _L("Starting the Test-process") );
		
	TInt tried = 0;	
		
	TRAPD( err, startSafe->StartAndMonitorL( *prop, proc, tried) );
	User::After( KPoliteInterval );

	// Produce the process-name search-term
	TPtrC namePtr( KTestProcGood() );
	namePtr.Set( namePtr.Ptr(), namePtr.Find(_L(".")) );


	// See if StartSafe thinks it's been successful _and that the process can be found. (if, line 73)
	// Then check to see that it has been restarted after being Kill()ed (if, line 85)
	if( (KErrNone == err) && ProcessExists(namePtr) )
		{
		
		INFO_PRINTF2( _L("Process \"%S\" started"), &namePtr );
		
			
		proc.Kill( KStartSafeTestKillCode );
		proc.Close();
		// Process should be restarted here
		User::After( KThrottleTime );
		
		
		if( ProcessExists( namePtr, proc ) )
			{
			INFO_PRINTF2( _L("Process \"%S\" REstarted successfully"), &namePtr );
			
			// RTestProcGoodSession is used to remotely control the process, allowing this process to cancel the monitoring of the target process, 
			// otherwise it keeps being restarted
			RTestProcGoodSession testProc;
			testProc.Connect();
			testProc.CancelMonitor();
			testProc.Close();
			
			proc.Kill( KStartSafeTestFinalKillCode );
		
			SetTestStepResult( EPass );	
			}
		else
			{
			ERR_PRINTF1( _L("Process was _not restarted") );
			
			SetTestStepResult( EFail );	
			}
			
		}
	else 
		{
		ERR_PRINTF2( _L("StartAndMonitorL left with"), err );	
		
		SetTestStepResult( EFail );
		}
		
		
	CleanupStack::PopAndDestroy( 3, startSafe ); // proc, prop, startSafe
	
	return TestStepResult();	
	}
// ============================================================================
// CWidgetEntry::InternalizeXmlL()
// read from persistent storage(file)
//
// @since 5.0
// ============================================================================
//
void CWidgetEntry::InternalizeXmlL( RFs& aFileSession,
                                    xmlDocPtr aDoc,
                                    xmlNode* n,
                                    CWidgetRegistryXml* aXmlProcessor )
{
    // <prop>name<val>value<type>typename</type></val></prop>
    //
    // prop subtree traversal assumes strict adherence to the
    // prototype structure, otherwise code leaves with corrupt code
    for ( ;
            n;
        )
    {
        // permit some non element stuff (comment, whitespace...) before <prop>
        while ( n && ( n->type != XML_ELEMENT_NODE ) )
        {
            n = n->next;
        }
        if ( NULL == n )
        {
            for (TInt i = iPropertyValues.Count(); i < EWidgetPropertyIdCount; i++)
            {
                CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
                CleanupStack::PushL(val);
                iPropertyValues.AppendL( val );
                CleanupStack::Pop(); // val
            }
            return;
        }
        TPtrC8 propTag( n->name );
        if ( 0 != propTag.Compare( KXmlPropTag() ) )
        {
            // TODO unrecognized subtree?
            return;
        }
        // TODO validate n->children != NULL and type XML_TEXT_NODE
        HBufC* name;
        aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &name );

        // get value array index (TWidgetPropertyId) for name
        TPtr namePtr( name->Des() );
        TInt propId =
            aXmlProcessor->GetPropertyId( namePtr );
        delete name;
        name = NULL;
        if ( EWidgetPropertyIdInvalid == propId )
        {
            User::Leave( KErrNoMemory );
        }

        for (TInt i = iPropertyValues.Count(); i <= propId; i++)
        {
            CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
            CleanupStack::PushL(val);
            iPropertyValues.AppendL( val );
            CleanupStack::Pop(); // val
        }

        n = n->children->next; // down to val
        if ( NULL == n )
        {
            User::Leave( KErrCorrupt );
        }
        TPtrC8 valTag( n->name );
        if ( 0 != valTag.Compare( KXmlValTag() ) )
        {
            User::Leave( KErrCorrupt );
        }
        if (propId >= EWidgetPropertyIdCount) // unsupported property
        {
            HBufC* value = NULL;
            if (n->children)
            {
                aXmlProcessor->GetTextContentAsStringL( aFileSession, aDoc, n->children, &value );
            }
            else
            {
                value = KNullDesC().AllocL();
            }
            (*this)[propId].iValue.s = value;
            (*this)[propId].iType = EWidgetPropTypeBlob;
            n = (n->parent)->next; // up two and next sibling
            continue;
        }
        // TODO validate n->children != NULL and type XML_TEXT_NODE
        HBufC* value;
        aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &value );
        CleanupStack::PushL( value );

        n = n->children->next; // down to type
        if ( NULL == n )
        {
            User::Leave( KErrCorrupt );
        }
        TPtrC8 typeTag( n->name );
        if ( 0 != typeTag.Compare( KXmlTypeTag() ) )
        {
            User::Leave( KErrCorrupt );
        }
        // TODO validate n->children != NULL and type XML_TEXT_NODE
        HBufC* type;
        aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &type );
        CleanupStack::PushL( type );

        // now have: name, value, type
        // convert type string to TWidgetPropertyType
        //
        // assume void/unknown is not put in XML format so anything
        // not recognized should be handled like other unrecognized
        // subtree
        TWidgetPropertyType typeEnum = EWidgetPropTypeUnknown;
        if ( 0 == type->Des().Compare( KXmlDataTypeBool() ) )
        {
            typeEnum = EWidgetPropTypeBool;
        }
        else if ( 0 == type->Des().Compare( KXmlDataTypeInt() ) )
        {
            typeEnum = EWidgetPropTypeInt;
        }
        else if ( 0 == type->Des().Compare( KXmlDataTypeString() ) )
        {
            typeEnum = EWidgetPropTypeString;
        }
        else if ( 0 == type->Des().Compare( KXmlDataTypeUid() ) )
        {
            typeEnum = EWidgetPropTypeUid;
        }
        CleanupStack::PopAndDestroy( type );

        // TODO handle unknown type due to future extensions: add prop
        // subtree to list of unrecognized subtrees

        // set prop according to type
        switch ( typeEnum )
        {
        case EWidgetPropTypeBool:
            if ( 0 == value->Des().Compare( _L("0") ) )
            {
                (*this)[propId].iValue.i = 0;
            }
            else
            {
                (*this)[propId].iValue.i = 1;
            }
            break;
        case EWidgetPropTypeInt:
        {
            TLex toInt( value->Des() );
            TInt k;
            if ( KErrNone != toInt.Val( k ) )
            {
                User::Leave( KErrCorrupt );
            }
            (*this)[propId].iValue.i = k;
        }
        break;
        case EWidgetPropTypeString:
            (*this)[propId].iValue.s = value;
            break;
        case EWidgetPropTypeUid:
        {
            TLex toUid( value->Des() );
            TInt u;
            if ( KErrNone != toUid.Val( u ) )
            {
                User::Leave( KErrCorrupt );
            }
            (*this)[propId].iValue.uid = TUid::Uid( u );
        }
        break;
        };

        (*this)[propId].iType = typeEnum;

        CleanupStack::Pop( value );
        if ( EWidgetPropTypeString != typeEnum )
        {
            delete value;
        }

        n = ((n->parent)->parent)->next; // up two and next sibling
    }
}