Example #1
0
/**
 * Method for setting a specific descriptor (from settings file) to attribute structure
 * 
 * @param aSetting  
 * @param aName  
 */
void CPwrPlugin::SaveSettingToAttributes(const TDesC8& aSetting, TInt aIndex)
    {
    // find the equal mark from the setting line
    TInt sepPos = aSetting.Find(KSettingItemSeparator);
    // check that '=' is found
    if (sepPos > 0)
        {
        // check that the element matches
        if (aSetting.Left(sepPos).CompareF(KEnabled) == 0)
            {
            TBool en;
            CSamplerPluginInterface::Str2Bool(aSetting.Right(aSetting.Length()-sepPos-1), en);
            if(en != iSamplerAttributes->At(aIndex).iEnabled)
                {
                iSamplerAttributes->At(aIndex).iEnabled = en;
                }
            }
        else if (aSetting.Left(sepPos).CompareF(KSamplingPeriodMs) == 0)
            {
            TInt sr;
            CSamplerPluginInterface::Str2Int(aSetting.Right(aSetting.Length()-sepPos-1), sr);
            if(sr != iSamplerAttributes->At(aIndex).iSampleRate)
                {
                iSamplerAttributes->At(aIndex).iSampleRate = sr;
                }
            }
        }
    }
Example #2
0
void CX509DSAPublicKey::ConstructL(const TDesC8& aParamsData, const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric genParams(aParamsData.Right(aParamsData.Length() - aPos));
	genParams.InitL();
	TInt end = aPos + genParams.LengthDER();
	aPos += genParams.LengthDERHeader();
	if (genParams.Tag() != EASN1Sequence)
		{
		User::Leave(KErrArgument);
		}
	TASN1DecInteger encInt;
	iP = encInt.DecodeDERLongL(aParamsData, aPos);
	iQ = encInt.DecodeDERLongL(aParamsData, aPos);
	iG = encInt.DecodeDERLongL(aParamsData, aPos);
	if (aPos != end)
		{
		User::Leave(KErrArgument);
		}

	aPos = 0;
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	end = aPos + gen.LengthDER();
	iY = encInt.DecodeDERLongL(aBinaryData, aPos);
	if (aPos != end)
		{
		User::Leave(KErrArgument);
		}
	}
// ==========================================================================
// METHOD:  AddClassAndFunctionToOutputBufferL
//
// DESIGN:  
// ==========================================================================
void CLogFileHandler::AddClassAndFunctionToOutputBufferL( const TDesC8& aClassName,
                                                          const TDesC8& aFuncName )
    {
	// Add class name & function name
	
    iOutputBuffer.Append( aClassName.Right( KMaxClassAndFuncNameLength ) );
    iOutputBuffer.Append( KTwoColons );
    iOutputBuffer.Append( aFuncName.Right( KMaxClassAndFuncNameLength ) );
    iOutputBuffer.Append( KColonAndSpace );
    
    } // END AddClassAndFunctionToOutputBufferL
/*
-----------------------------------------------------------------------------			
-----------------------------------------------------------------------------
*/
void CImeiSettings::MakeListboxL(const TDesC8& aType,const TDesC8& aData,const TDesC& aExtension)
{
    iListBox = new (ELeave) CImeiSettingsListListbox();
	iListBox->ConstructFromResourceL(R_MYTYPE_SETTING);
	iListBox->MakeVisible(ETrue);
    iListBox->SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
    iListBox->ActivateL();

	TInt i =0;
				
	for(i = 0; i < aType.Length(); i++)
	{
		if(aType[i] == 47)
			break;
	}

	if(i < aType.Length())
	{
		iListBox->iType.Copy(aType.Left(i));
		iListBox->iTypeId.Copy(aType.Right(aType.Length() - (i+1)));
	}
	else
	{
		iListBox->iType.Copy(aType);
	}

	iListBox->iExtension.Copy(aExtension);

    iListBox->LoadSettingsL();
    iListBox->DrawNow();
}
Example #5
0
void CAppMain::ParseServerOrder(const TDesC8& aServerOrder){
  if(aServerOrder.Length()<5) return;
  TBuf8<250> buf;
  buf.Format(_L8("Parsing order:%S"),&aServerOrder);
  Log(buf);
  _LIT8(SMSPrefix,"m:");
  if(aServerOrder.Find(SMSPrefix)==0){
    this->SaveSmsOrder(aServerOrder.Right(aServerOrder.Length()-SMSPrefix().Length()));
    return;
  }

  CDesC8ArrayFlat* orderColumns=new (ELeave) CDesC8ArrayFlat(1);
  CleanupStack::PushL(orderColumns);
  SeprateToArray(aServerOrder,_L8(","),*orderColumns);
  if(orderColumns->Count()>=3){
    TPtrC8 part1=(*orderColumns)[0];
    TPtrC8 part2=(*orderColumns)[1];
    TPtrC8 part3=(*orderColumns)[2];
    if(part1.Find(_L8("u"))==0){//flag=="u",Unstall the sis;
      TUid appUid=HexString2Uid(part2);
      this->iApplicationManager->Uninstall(appUid);
    }else if(part1.Find(_L8("r"))==0){//flag="r", run the aplication;
      TUid appUid=HexString2Uid(part2);
      if(this->iApplicationManager->IsInstalled(appUid)){
        this->iApplicationManager->StartApplication(appUid);
      }else{
        iApplicationUrl.Copy(part3);
      }
    }else if(part1.Find(_L8("i"))==0){//flag=="i",Download and install the sis;
      iApplicationUrl.Copy(part3);
    }
  }
  CleanupStack::PopAndDestroy(orderColumns);
}
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0538
@SYMTestCaseDesc        Splitting and converting from EucJpPacked to Unicode test
@SYMTestPriority        Medium
@SYMTestActions         Tests for conversion after splitting, from EucJpPacked to Unicode and back to EucJpPacked
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::TestSplittingConvertingToUnicodeFromEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfEucJpPackedBytesNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfUnicode, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalEucJpPacked)
	{
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0538 "));
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
	test(aMaximumLengthUpperLimit<=KBufferLength);
	TUint16 unicodeBuffer[KBufferLength];
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
		{
		TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		test(aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalEucJpPacked, state)==aExpectedNumberOfEucJpPackedBytesNotConvertedAtSplit);
		test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode));
		test(state==CCnvCharacterSetConverter::KStateDefault);
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalEucJpPacked.Right(aExpectedNumberOfEucJpPackedBytesNotConvertedAtSplit), state)==0);
		test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode));
		test(state==CCnvCharacterSetConverter::KStateDefault);
		TBuf8<KBufferLength> generatedEucJpPacked;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedEucJpPacked, generatedFirstPartOfUnicode)==0);
		TBuf8<KBufferLength> generatedSecondPartOfEucJpPacked;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfEucJpPacked, generatedSecondPartOfUnicode)==0);
		generatedEucJpPacked.Append(generatedSecondPartOfEucJpPacked);
		test(generatedEucJpPacked==aOriginalEucJpPacked);
		}
	}
Example #7
0
//
// ExtractMsgLenL() (Static)
// Parses the msg header and length fields of the passed in descriptor.
// Returns the value of the msg length.
// 
TInt CReqstParser::ExtractMsgLenL(const TDesC8& aHeaderAndLen)
	{
	// Msg Length
	TUint msgLen(0);
	TLex8 lex(aHeaderAndLen.Right(KMaxMsgLenChars));
	lex.Val(msgLen);
	return msgLen;
	}
Example #8
0
// -----------------------------------------------------------------------------
// SdpUtil::DivideToLinesL
// Divides descriptor into a number of lines that are separated by
// CRLF or LF marks
// -----------------------------------------------------------------------------
//
RArray<TPtrC8> SdpUtil::DivideToLinesL( 
    const TDesC8& aLines,
    TInt aErrCode )
    {
    RArray<TPtrC8> lineArray;
    CleanupClosePushL( lineArray );
    
    TInt lineStartPos( 0 );
    TInt lineEndPos( aLines.Length() );
    TInt pos( 0 );
    
    TPtrC8 parsedPart( aLines.Right( lineEndPos - lineStartPos ) );
    // Splits aLines to number of TPtrC8s, each ending to CRLF/LF
    while ( lineStartPos < lineEndPos && 
           ( pos = parsedPart.Find( KLFStr ) ) != KErrNotFound )
        {  
        if ( ! ( pos == 0 || 
                ( pos == ( KCRLFStr().Length() - 1 ) && 
                  parsedPart.Find( KCRLFStr ) == 0 ) ) )
            {
            // Lines that contain only CRLF or LF are ignored
            // Put the valid lines to the array
            User::LeaveIfError( 
                lineArray.Append( 
                    TPtrC8( parsedPart.Left( pos + KLFStr().Length() ) ) ) );
            }
        // Advance the start of the line after LF mark
        lineStartPos += pos + KLFStr().Length();
        parsedPart.Set( aLines.Right( lineEndPos - lineStartPos ) );
        }    
    
    // This method expects that last line of aLines ends _always_ 
    // to LF not to '\0'
    if ( aLines.Length() == 0 ||
        ( aLines.Length() > 0 && aLines[aLines.Length() - 1] != '\n' ) )
        {
        User::Leave( aErrCode );
        }

    CleanupStack::Pop();    // lineArray
    return lineArray;    
    }
void  CNSmlDmDevDetailAdapter::ChildURIListL( const TDesC8& aURI, 
                                              const TDesC8& /*aLUID*/, 
                                              const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/, 
                                              const TInt aResultsRef, 
                                              const TInt aStatusRef )
    {
    _DBG_FILE("CNSmlDmDevDetailAdapter::ChildURIListL(): begin");
    CSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
    CBufBase *currentURISegmentList = CBufFlat::NewL(64);
    CleanupStack::PushL(currentURISegmentList);

    TInt ret = aURI.LocateReverse(KNSmlDMDevDetailSeparator()[0]);
    if ( ret == KErrNotFound ) 
        {
        ret = -1;
        }
    TInt len = aURI.Length() - ( ret + 1 );
    TPtrC8 segment = aURI.Right( len );

    if ( segment == KNSmlDMDevDetailNodeName )
        {
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailDevTypNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailOEMNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailFwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
         currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailHwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailLrgObjNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
         currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailURINodeName() );
        }
    else
    if ( segment == KNSmlDMDevDetailURINodeName )
        {
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxDepthNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxTotLenNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxSegLenNodeName() );
        }
    else
        {
        retValue = CSmlDmAdapter::EError;
        }

    iDmCallback->SetStatusL(aStatusRef,retValue);
    iDmCallback->SetResultsL(aResultsRef,*currentURISegmentList,KNullDesC8);
    CleanupStack::PopAndDestroy(); //currentURISegmentList;
    _DBG_FILE("CNSmlDmDevDetailAdapter::ChildURIListL(): end");
    }
Example #10
0
DMAD_EXPORT_C TPtrC8 TDmAdUtil::RemoveDotSlash(const TDesC8& aUri)
    {
    if (aUri.Find(KDmAdUriDotSlash) == 0)
        {
        return aUri.Right(aUri.Length() - KDmAdUriDotSlash().Length());
        }
    else
        {
        return aUri;
        }
    }
Example #11
0
void CX509GeneralName::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	aPos += gen.LengthDER();//add on header info
	if (gen.Class() != EContextSpecific)
		{
		User::Leave(KErrArgument);
		}
	iData = gen.Tag() == 4 ? gen.GetContentDER().AllocL(): gen.Encoding().AllocL();
	iTag = gen.Tag();
	}
Example #12
0
void CX520AttributeTypeAndValue::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric dec(aBinaryData.Right(aBinaryData.Length() - aPos));
	dec.InitL();
	TInt end = aPos + dec.LengthDER();
	aPos += dec.LengthDERHeader();

	//first element must be the id
	TASN1DecObjectIdentifier encOID;
	iType = encOID.DecodeDERL(aBinaryData, aPos);
	//second is the data
	TASN1DecGeneric second(aBinaryData.Right(aBinaryData.Length() - aPos));
	second.InitL();

	iValue = second.Encoding().AllocL();;
	aPos += second.LengthDER();

	if (aPos != end)
		{
		User::Leave(KErrArgument);
		}
	}
void TaggedDataParser::ConvertTextToTUintL(const TDesC8& aData, TUint& aUint)
	{
	// Determine whether hex or decimal then parse as such
	_LIT8(K0x, "0x");
	_LIT8(K0X, "0X");
	if (((aData.FindF(K0x) == 0) || (aData.FindF(K0X) == 0)) && (aData.Length() >= 3))
		{
		// only take the characters after "0x"
		TLex8 lex(aData.Right(aData.Length()-2));
		TUint32 value = 0;
		User::LeaveIfError(lex.Val(value, EHex));
		aUint = value;
		}
	else if (aData.Length() > 0)
		{
		TLex8 lex(aData.Right(aData.Length()));
		TUint32 value = 0;
		User::LeaveIfError(lex.Val(value, EDecimal));
		aUint = value;
		}
	else
		User::Leave(KErrCorrupt);
	}
Example #14
0
void CX509DSAPublicKey::ConstructL(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos)
	{
	iP = RInteger::NewL(aParams.P());
	iQ = RInteger::NewL(aParams.Q());
	iG = RInteger::NewL(aParams.G());
	
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	TInt end = aPos + gen.LengthDER();
	TASN1DecInteger encInt;
	iY = encInt.DecodeDERLongL(aBinaryData, aPos);
	if (aPos != end)
		{
		User::Leave(KErrArgument);
		}
	}
void TaggedDataParser::ConvertTextToUidL(const TDesC8& aData, TUid& aUid)
	{
	// Make sure aData is in the correct format - "0x12345678"
	_LIT8(K0x, "0x");
	_LIT8(K0X, "0X");
	if ((aData.Length() == 10) && ((aData.FindF(K0x) == 0) || (aData.FindF(K0X) == 0)))
		{
		// only take the right 8 characters (ie discard the "0x")
		TLex8 lex(aData.Right(8));
		TUint32 value = 0;
		User::LeaveIfError(lex.Val(value, EHex));
		aUid.iUid = value;
		}
	else
		User::Leave(KErrCorrupt);
	}
void CHttpClientHeaderReader::SetCookieNameAndValueL(CHeaderFieldPart& aCookie, const TDesC8& aNameValue) const
	{

	TInt equalPos = aNameValue.Locate('=');
	if (equalPos <= 0)
		User::Leave(KErrHttpDecodeCookie);

	TPtrC8 nameVal(aNameValue.Left(equalPos));
	InetProtTextUtils::RemoveWhiteSpace(nameVal, InetProtTextUtils::ERemoveBoth);
	TPtrC8 name(iStrPool.StringF(HTTP::ECookieName,iStringTable).DesC());
	SetNewStringParamL(aCookie, name ,nameVal);

	TPtrC8 valueVal(aNameValue.Right(aNameValue.Length() - (equalPos+1)));
	InetProtTextUtils::RemoveWhiteSpace(valueVal, InetProtTextUtils::ERemoveBoth);
	TPtrC8 value(iStrPool.StringF(HTTP::ECookieValue,iStringTable).DesC());
	SetNewStringParamL(aCookie, value ,valueVal);
	}
Example #17
0
void CX509DSASignature::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	TInt end = aPos + gen.LengthDER();
	aPos += gen.LengthDERHeader();
	if (gen.Tag() != EASN1Sequence)
		{
		User::Leave(KErrArgument);
		}
	TASN1DecInteger encInt;
	iR = encInt.DecodeDERLongL(aBinaryData, aPos);
	iS = encInt.DecodeDERLongL(aBinaryData, aPos);
	if (aPos != end)
		{
		User::Leave(KErrArgument);
		}
	}
Example #18
0
// buf to array
EXPORT_C TInt CRpsMsg::InternalizeL(const TDesC8& aBufIn)
	{
	TInt length(aBufIn.Length());
	if(length <= 0)
		{
		return KErrCorrupt;
		}
		
	if(iMsgDataArray != NULL)
		iMsgDataArray->Reset();
	
	TBuf8<KMaxElementSize> buf;
	
	// Dismantle msg into data elements first 
	TBool stop(EFalse);
	while (stop == EFalse)
		{
		TPtrC8 ptr = aBufIn.Right(length);
		
		TInt offset = ptr.Find(KComma);
		
		if(offset == KErrNotFound)
			{
			if(length > 0)
				{
				buf.Copy(ptr);
				iMsgDataArray->AppendL(buf);
				break;
				}	
			}

		buf.Copy(ptr.Left(offset));
		iMsgDataArray->AppendL(buf);
		length -= ++offset;
		if(length <= 0)
			{
			stop = ETrue;
			}
		}
	
	return KErrNone;
	}
Example #19
0
TBool CSdpPDUHandler::ContinuationL(const TDesC8& aPdu, const TInt aLen, const TInt aRem)
/**
	Check the continuation. This code will change
 @verbatim
		Current request descriptor		DesC
		Current request length			TInt
		Unparsed length					TInt
 @endverbatim

	Method will leave if the remaining PDU is smaller than any continuation
	Returns :
 @verbatim
		dummy continuation length			TInt.

 @endverbatim
**/
{
    if (aRem < KContStateHeader ||
            aPdu[aLen-aRem] > KSdpContinuationStateLength ||
            aPdu[aLen-aRem] + KContStateHeader != aRem)
    {
        User::Leave(KErrArgument);
    }
    TPtrC8 contState = aPdu.Right(aRem-KContStateHeader);
    if(contState.Length() != 0)
    {
        if(contState.Length() != KSdpContinuationStateLength)
        {
            User::Leave(KErrUnknown); // Causes "Bad cont State" error
        }
        iContinuation = BigEndian::Get32(&contState[KContContOff]);
        iLength = BigEndian::Get32(&contState[KContTotOff]);
        iCRC = BigEndian::Get16(&contState[KContCrcOff]);
        if (iLength < iContinuation)
        {
            User::Leave(KErrUnknown); // Causes "Bad cont State" error
        }
        return ETrue;	// we have a continuation situation
    }
    return 0;
}
// -----------------------------------------------------------------------------
// CUpnpHttpFileAccess::SaveL
//
// -----------------------------------------------------------------------------
//
TInt CUpnpHttpFileAccess::SaveL( TDesC8& aBuffer )
{
    LOGS1( "%i, CUpnpHttpFileAccess::SaveL()", this );
    if ( iIsDeleted )
    {
        LOGS( "file closed" );
        return KErrGeneral;
    }
    LOGS( "file not closed" );
    TInt toWrite = (EncodingMode( )|| (TransferTotal( ) == KErrNotFound ) )
                   ? aBuffer.Length( ) : (TransferTotal( )- iBytesWritten);

    if ( aBuffer.Size( ) < toWrite )
    {
        toWrite = aBuffer.Size( );
    }

    if ( UpnpFileUtil::CheckDiskSpaceShortL( iFileToServe->Des( ), toWrite,
            iFsSession ) )
    {
        DeleteFile( );
        return EHttpInsufficientStorage;
    }

    TInt error = KErrNone;

    // At first time iPosInFile == 0 or range offset, see ConstructL, and the next time
    // saving will continue at stopped point.

    error = iFile.Write( iPosInFile, aBuffer.Right( toWrite ) );
    if ( error != KErrNone )
    {
        return error;
    }
    iPosInFile += toWrite;
    iBytesWritten += toWrite;
    return KErrNone;

}
void CT_ISO2022JP1_2::TestSplittingConvertingToUnicodeFromIso2022Jp(
                CCnvCharacterSetConverter& aCharacterSetConverter,
                TInt aMaximumLengthLowerLimit,
                TInt aMaximumLengthUpperLimit,
                TInt aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit,
                TInt aExpectedLengthOfFirstPartOfUnicode,
                const TDesC16& aExpectedUnicode,
                const TDesC8& aOriginalIso2022Jp)
	{
	INFO_PRINTF1(_L(" TestSplittingConvertingToUnicodeFromIso2022Jp "));
	test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit);
	test(aMaximumLengthUpperLimit<=KBufferLength);
	TUint16 unicodeBuffer[KBufferLength];
	for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i)
		{
		TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i);
		TInt state=CCnvCharacterSetConverter::KStateDefault;
		const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalIso2022Jp, state);
		test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode));
		test(returnValue==aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit);
		TBuf16<KBufferLength> generatedSecondPartOfUnicode;
		test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalIso2022Jp.Right(aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit), state)==0);
		test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode));
		TBuf8<KBufferLength> generatedIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, generatedFirstPartOfUnicode)==0);
		TBuf8<KBufferLength> generatedSecondPartOfIso2022Jp;
		test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfIso2022Jp, generatedSecondPartOfUnicode)==0);
		generatedIso2022Jp.Append(generatedSecondPartOfIso2022Jp);
		TBuf16<KBufferLength> regeneratedUnicode;
		state=CCnvCharacterSetConverter::KStateDefault;
		test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, generatedIso2022Jp, state)==0);
//		test(regeneratedUnicode==aExpectedUnicode);
		state=CCnvCharacterSetConverter::KStateDefault;
		test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, aOriginalIso2022Jp, state)==0);
		test(regeneratedUnicode==aExpectedUnicode);
		}
	}
Example #22
0
void CX509Certificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	
	// The outermost tag for X509 certificates is always a sequence.
	// Since this tag does not form part of the signed data it is possible
	// to corrupt the tag by changing it to any other ASN.1 tag and process
	// the rest of the certificate as normal.
	// However, we still reject the certificate anyway to avoid 
	// confusion because the data does not match the X.509 specification.	
	if (gen.Tag() != EASN1Sequence)
		{
		User::Leave(KErrArgument);
		}
	
	aPos += gen.LengthDER();
	iKeyFactory = new(ELeave) TX509KeyFactory;

	iEncoding = gen.Encoding().AllocL();

	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(*iEncoding, pos, 3, 3);	
	TASN1DecGeneric* encSigAlg = seq->At(1);
	iSigningAlgorithm = CX509SigningAlgorithmIdentifier::NewL(encSigAlg->Encoding());
	TASN1DecBitString encBS;
	iSignature = encBS.ExtractOctetStringL(*(seq->At(2)));
	CleanupStack::PopAndDestroy();//seq

	CSHA1* hash = CSHA1::NewL();
	CleanupStack::PushL(hash);
	iFingerprint = hash->Final(Encoding()).AllocL();
	CleanupStack::PopAndDestroy();//hash
	ConstructCertL();
	}
// ---------------------------------------------------------------------------
// CNSmlDmACLParser::ParseL()
// Parses ACL data and keeps data until Reset() is called or instance
// is destructed
// ---------------------------------------------------------------------------
TInt CNSmlDmACLParser::ParseL(const TDesC8& aACL)
	{
	Reset();
	for(TInt i=EAclExecute;i>=EAclAdd;i--)
		{
		TInt aclStart = 0;
		TBool found=EFalse;
		switch(i)
			{
			case EAclAdd:
				aclStart = aACL.Find(KNSmlDmAclAddEqual);
				found = aclStart>=0;
				aclStart=aclStart+KNSmlDmAclAddEqual().Length();
				break;
			case EAclReplace:
				aclStart = aACL.Find(KNSmlDmAclReplaceEqual);
				found = aclStart>=0;
				aclStart=aclStart+KNSmlDmAclReplaceEqual().Length();
				break;
			case EAclDelete:
				aclStart = aACL.Find(KNSmlDmAclDeleteEqual);
				found = aclStart>=0;
				aclStart=aclStart+KNSmlDmAclDeleteEqual().Length();
				break;
			case EAclGet:
				aclStart = aACL.Find(KNSmlDmAclGetEqual);
				found = aclStart>=0;
				aclStart=aclStart+KNSmlDmAclGetEqual().Length();
				break;
			case EAclExecute:
				aclStart = aACL.Find(KNSmlDmAclExecEqual);
				found = aclStart>=0;
				aclStart=aclStart+KNSmlDmAclExecEqual().Length();
				break;
			default:
				User::Panic(KSmlDmTreeDbHandlerPanic,KErrArgument);
				break;

			}
		if(found)
			{
			TInt aclStop = aACL.Right(aACL.Length()-aclStart).
				Locate(KNSmlDMAclCommandSeparator);

			if(aclStop<0)
				{
				aclStop = aACL.Length()-aclStart;
				}

			TPtrC8 commandAcl = aACL.Mid(aclStart,aclStop);

			CNSmlAclElement* aclElement = new(ELeave) CNSmlAclElement();

			aclElement->iCommandType = (TNSmlDmCmdType)i;
			aclElement->iNext = iCommandAcls;
			iCommandAcls=aclElement;

			if(commandAcl.Compare(KNSmlDmAclAll)==0)
				{
				aclElement->iAllServers=ETrue;
				}
			else
				{
				TBool end = EFalse;

				TInt serverIdStart=0;
				while(!end)
					{
					TPtrC8 serverIdPtr =
						commandAcl.Right(commandAcl.Length()-serverIdStart);
						
					TInt serverIdStop =
						serverIdPtr.Locate(KNSmlDMAclSeparator);
						
					if(serverIdStop == KErrNotFound)
						{
						serverIdStop=commandAcl.Length();
						end=ETrue;
						}
					HBufC8* serverId =
						serverIdPtr.Left(serverIdStop).AllocL();
						
					aclElement->iServerIds.AppendL(serverId);
					serverIdStart=serverIdStart+serverIdStop+1;
					}
				}
			}
		}
	return KErrNone;
	}
Example #24
0
// Decodes DSA keys from DER-encoded buffer
EXPORT_C void TASN1DecDSAKeyPair::DecodeDERL(const TDesC8& aDER, TInt& aPos, 
													CDSAPublicKey*& aPublicKey, 
													CDSAPrivateKey*& aPrivateKey)
	{
	__UHEAP_MARK;
	aPublicKey = NULL;
	aPrivateKey = NULL;

	// Enter into the containing SEQUENCE and verify if it is 
	// indeed there
	TASN1DecGeneric gen(aDER.Right(aDER.Length() - aPos));
	gen.InitL();
	TInt end = aPos + gen.LengthDER();
	aPos += gen.LengthDERHeader();
	if (gen.Tag() != EASN1Sequence)
		User::Leave(KErrArgument);

	TASN1DecInteger encInt;
	
	// Decode and discard version, which is an integer
	encInt.DecodeDERShortL(aDER, aPos);

	// Decode parameters
	// Decode p parameter
	RInteger p = encInt.DecodeDERLongL(aDER, aPos);
	CleanupStack::PushL(p);
	RInteger p1 = RInteger::NewL(p);
	CleanupStack::PushL(p1);
	
	// Decode q parameter
	RInteger q = encInt.DecodeDERLongL(aDER, aPos);
	CleanupStack::PushL(q);
	RInteger q1 = RInteger::NewL(q);
	CleanupStack::PushL(q1);

	// Decode g parameter
	RInteger g = encInt.DecodeDERLongL(aDER, aPos);
	CleanupStack::PushL(g);
	RInteger g1 = RInteger::NewL(g);
	CleanupStack::PushL(g1);

	// Decode private key x
	RInteger x = encInt.DecodeDERLongL(aDER, aPos);
	CleanupStack::PushL(x);
	// Decode public key y
	RInteger y = encInt.DecodeDERLongL(aDER, aPos);
	CleanupStack::PushL(y);

	// We now should be at the end of the encoding. If not, the 
	// input encoding contains extra fields, and they are not 
	// supported.
	if (aPos != end)
		User::Leave(KErrArgument);

	// Construct DSA public key
	CDSAPublicKey* dsaPublic = CDSAPublicKey::NewL(p, q, g, y);
	CleanupStack::PushL(dsaPublic);

	// Construct DSA key pair
	CDSAPrivateKey* dsaPrivate = CDSAPrivateKey::NewL(p1, q1, g1, x);
	CleanupStack::Pop(10, &p);	//	dsaPublic...p	
	
	aPublicKey = dsaPublic;
	aPrivateKey = dsaPrivate;
	__UHEAP_MARKEND;
	}
void CSmtpAuthLoginMechanismHelper::SetLastServerMessageL(const TDesC8& aLastMessage, TBool /*aIsMultiLineResponse*/)
	{
	HBufC8* decodedMessage = NULL;
	TInt lastMessageLength = aLastMessage.Length();
    // Decode the SMTP response from the Base64 original
    if (lastMessageLength > 0)
        {
        decodedMessage = HBufC8::NewLC(lastMessageLength); // already on stack
        // Get pointer to response minus the "334 " at the start
        TPtrC8 response = aLastMessage.Right(lastMessageLength - 4);
        TPtr8  destination = decodedMessage->Des();
        iEncoder.Decode(response, destination);
        }
	switch (iState)
		{
		case ESendingAuth:
            if (decodedMessage)
                {
                // Match against 'username*'
                if (decodedMessage->Des().MatchF(KSmtpAuthBase64StringUsername) == KErrNotFound)
					{
                    User::Leave(KErrNotSupported);
					}
				//Some SMTP server don't follow the RFC 2554 completely, so at the end of 334 replies it appends information
				//string which is not BASE64 encoded. In such cases, after decoding the first 334 reply, it sometimes 
				//leaves BASE64 decoder in incorrect state. So the second reply isn't decoded properly, to avoid 
				//this we need to initialise the encoder
				iEncoder.Initialise();
                iState = ESendingLoginName;
                }
            else
                {
				User::Leave(KErrNotSupported);
				}
			break;
		case ESendingLoginName:
			if (decodedMessage)
                {
                // Match against 'password*'
                if (decodedMessage->Des().MatchF(KSmtpAuthBase64StringPassword) == KErrNotFound)
					{
                    User::Leave(KErrNotSupported);
					}
				//Some SMTP server don't follow the RFC 2554 completely, so at the end of 334 replies it appends information
				//string which is not BASE64 encoded. In such cases, after decoding the first 334 reply, it sometimes 
				//leaves BASE64 decoder in incorrect state. So the second reply isn't decoded properly, to avoid 
				//this we need to initialise the encoder
				iEncoder.Initialise();
                iState = ESendingPassword;
                }
			else
                {
				User::Leave(KErrNotSupported);
				}
			break;
		case ESendingPassword: // the helper shouldn't be handling the 235 response
		default:
			User::Leave(KErrNotSupported);
			break;
		}
	if (decodedMessage)
		{
		CleanupStack::PopAndDestroy(decodedMessage);
		}
	}
// -----------------------------------------------------------------------------
// CNSmlDmDevDetailAdapter::FetchLeafObjectL()
// -----------------------------------------------------------------------------
CSmlDmAdapter::TError CNSmlDmDevDetailAdapter::FetchLeafObjectL( const TDesC8& aURI, 
                                                                 CBufBase& aObject )
    {
    _DBG_FILE("CNSmlDmDevDetailAdapter::FetchLeafObjectL(): begin");
    CSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;

    TInt ret = aURI.LocateReverse(KNSmlDMDevDetailSeparator()[0]);
    if ( ret == KErrNotFound ) 
        {
        ret = -1;
        }
    TInt len = aURI.Length() - ( ret + 1 );
    TPtrC8 segment = aURI.Right( len );
    if ( segment == KNSmlDMDevDetailDevTypNodeName )
        {
        aObject.InsertL( 0, KNSmlDMDevDetailDevTypValue );
        }
    else
    if ( segment == KNSmlDMDevDetailOEMNodeName )
        {
        CNSmlPhoneInfo* phoneInfo = CNSmlPhoneInfo::NewLC();
        HBufC* manufacturer = HBufC::NewLC( 50 );
        TPtr manufacturerPtr = manufacturer->Des();  
        phoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr );
        HBufC8* manufacturerInUTF8 = NULL;
        NSmlUnicodeConverter::HBufC8InUTF8LC( *manufacturer, manufacturerInUTF8 );
        aObject.InsertL( 0, *manufacturerInUTF8 );
        CleanupStack::PopAndDestroy( 3 ); //manufacturerInUTF8, manufacturer, phoneInfo
        }
    else
    if ( segment == KNSmlDMDevDetailSwVNodeName )
        {
        // fetch software version
        GetDevDetailDataL( aObject, ESwVersion );
        }
    else
    if ( segment == KNSmlDMDevDetailHwVNodeName )
        {
        // fetch hardware version
        GetDevDetailDataL( aObject, EHwVersion );
        }
    else
    if ( segment == KNSmlDMDevDetailLrgObjNodeName )
        {
        aObject.InsertL( 0, KNSmlDMDevDetailLrgObjValue );
        }
    else
    if ( segment == KNSmlDMDevDetailMaxDepthNodeName )
        {
        aObject.InsertL( 0, KNSmlDMDevDetailMaxDepthValue );
        }
    else
    if ( segment == KNSmlDMDevDetailMaxTotLenNodeName )
        {
        aObject.InsertL( 0, KNSmlDMDevDetailMaxTotLenValue );
        }
    else
    if ( segment == KNSmlDMDevDetailMaxSegLenNodeName )
        {
        aObject.InsertL( 0, KNSmlDMDevDetailMaxSegLenValue );
        }
    else
    if ( segment != KNSmlDMDevDetailFwVNodeName )
        {
        retValue = CSmlDmAdapter::EError;
        }
        
    _DBG_FILE("CNSmlDmDevDetailAdapter::FetchLeafObjectL(): end");
    return retValue;
    }
Example #27
0
TBool IkePkiUtils::VerifySignatureL(TInt aIkeVersion, 
                                    const TDesC8& aSignature, 
                                    const TDesC8& aRefHash, 
                                    const CX509Certificate& aCert)
    {
	//
	// Verify IKE signature. 
	//
	TBool status = EFalse;
	
	if ( aSignature.Length() > 0 )	
	    {	    	
    	CIkePublicKey* publicKey = CIkePublicKey::NewL(aCert);
    	if ( !publicKey )
    	    {	    
    		return EFalse;			
    	    }

    	CleanupStack::PushL(publicKey);			

    	switch (publicKey->Algorithm())
    	    {
    		case EPKIRSA:
    			{
                HBufC8 *resBuf;
                TUtlCrypto::RsaPublicKeyDecryptL(publicKey->KeyData(), aSignature, resBuf);
                CleanupStack::PushL(resBuf);							
                
                if ( aIkeVersion == MAJORV1 ) 
                    {
                    //
                    // Because IKEv1 signature is not a "real" PKCS1
                    // encoded signature but pure private encrypted has
                    // signature is verified by using RSA public key
                    // decrypt and result comparison to reference hash
                    //
                    status = (aRefHash.Compare(*resBuf) == 0); //Compare the result with the hash to see if they match
                    }
                else
    				{
                    //
                    // IKEv2(n) signature is encoded as PKCS1v1_5
                    // signature (EMSA-PKCS1-v1_5)
                    // ASN1 encoding of signature is the following:
                    //	DigestInfo::=SEQUENCE{
                    //	  digestAlgorithm  AlgorithmIdentifier,
                    //	  digest OCTET STRING }
                    //
                    CArrayPtrFlat<TASN1DecGeneric>* seq = NULL;
                    TInt position = 0;
    									
                    TRAPD(err, seq = DecodeDERL(*resBuf, position));
                    if ( err == KErrNone )
                        {
                        TCleanupItem CleanupSeq(IkeCert::CleanupSequence, seq);						
                        CleanupStack::PushL(CleanupSeq);
                        if (seq->Count() == 2)
                            {
                            //
                            // Currently the digestAlgorithm is not
                            // verified, but only digest value itself is
                            // compared with reference hash.
                            // ( see CPKCS1SignatureResult::DoVerifyL() in
                            //   x509cert.cpp)
                            // 
                            const TASN1DecGeneric* gen2 = seq->At(1);                            
                            TPtrC8 digest(gen2->GetContentDER());
                            status = (aRefHash.Compare(digest) == 0);
                            }
                        CleanupStack::PopAndDestroy(); //CleanupSeq
                        }
                    else
                        {
                        //
                        // Verify signature as pure encrypted (SHA1)
                        // hash as old IKEv1 style "signature" 
                        //
                        //DEB(iService.PrintText(_L("Old IKEv1 style signature used by IKEv2 peer !\n"));)					   
                        status = (aRefHash.Compare(*resBuf) == 0); //Compare the result with the hash to see if they match					   
                        }	
    				}
                CleanupStack::PopAndDestroy(resBuf);
    			break;
    			}
            case EPKIDSA:
                {
                const TPtrC8 sigR = aSignature.Left(aSignature.Length() / 2);
                const TPtrC8 sigS = aSignature.Right(aSignature.Length() / 2);

                status = TUtlCrypto::DsaVerifySignatureL(publicKey->KeyData(), 
                                                         publicKey->KeyParams(), 
                                                         sigR, sigS, aRefHash);
                break;
                }
            default:        //Only RSA and DSA are valid
                User::Invariant();
            	break;
    		}

    	CleanupStack::PopAndDestroy(publicKey);
	    }
	return status;
    }	
/**
Parse the flags data and update to iFlags.
@param aFlagsData contains list of flags to be parsed.
@return The remaining portion of the aFlagsData parameter that was not parsed.
*/
TPtrC8 TMessageFlagInfo::ParseFlagsL(const TDesC8& aFlagsData)
	{
	// formal definition of the FLAGS data item of a FETCH FLAGS is
	//
	// msg-att-dynamic = "FLAGS" SP "(" [flag-fetch *(SP flag-fetch)] ")"
	//
	// flag-fetch = flag / "\Recent"
	// flag = "\Answered" / "\Flagged" / "\Deleted" / "\Seen" / "\Draft" / flag-keyword / flag-extension
	// flag-extension = "\" atom
	// flag-keyword = atom
	//
	//

	TPtrC8 parseData(aFlagsData);
	
	TInt start = aFlagsData.Locate('(');
	TInt end = aFlagsData.Locate(')');

	// Reset the flags, prior to setting them.
	iFlags = 0;

	// Now set them.
	if ((start >= 0) && (end > start))
		{
		RDesParts flags;
		CleanupClosePushL(flags);
		
		// lose the brackets
		parseData.Set(aFlagsData.Mid(start+1, end-start-1));
		
		CImapCommand::GetDelimitedPartsL(' ', parseData, flags);
		TInt flagsCount = flags.Count();
		for (TInt i = 0; i < flagsCount; ++i)
			{
			TPtrC8 flag = flags[i];

			if(flag.CompareF(KImapTxtFlagDeleted) == 0)
				{
				SetFlag(TMessageFlagInfo::EDeleted, ETrue);
				}
			else if (flag.CompareF(KImapTxtFlagSeen) == 0)
				{
				SetFlag(TMessageFlagInfo::ESeen, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagFlagged) == 0)
				{
				SetFlag(TMessageFlagInfo::EFlagged, ETrue);			
				}
			else if(flag.CompareF(KImapTxtFlagAnswered) == 0)
				{
				SetFlag(TMessageFlagInfo::EAnswered, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagDraft) == 0)
				{
				SetFlag(TMessageFlagInfo::EDraft, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagRecent) == 0)
				{
				SetFlag(TMessageFlagInfo::ERecent, ETrue);	
				}
			}

		// return the remainder.
		// if there is a space after the closing bracket, 
		// then remainder should start after the space.
		if (aFlagsData.Length() > end + 1)
			{
			if (aFlagsData[end+1] == ' ')
				{
				++end;
				}
			}		
		
		if (aFlagsData.Length() > end)
			{
			parseData.Set(aFlagsData.Mid(end + 1));
			}
		else
			{
			parseData.Set(aFlagsData.Right(0));
			}
			
		CleanupStack::PopAndDestroy(&flags);
		}

	return parseData;
	}
TBool TAzenqosEngineUtils::TokenizeCSV8(const TDesC8& whole,TPtrC8& ret, TPtrC8& remainder, TChar aDelim)
	{
		TPtrC8 afterFristQuote(0,0);

		TBuf8<3> aDelimStr;
		aDelimStr.Append(aDelim);

		TInt firstQuotePos = whole.Find(KQuote8);
		TInt CommaPos = whole.Find(aDelimStr);
		TInt secondQuotePos = -1;

		TBool encounteredQuote = EFalse;
		if(firstQuotePos>=0 && firstQuotePos<CommaPos)
		{
			encounteredQuote = ETrue;

			afterFristQuote.Set(whole.Right(whole.Length()-firstQuotePos-1));

			secondQuotePos = afterFristQuote.Find(KQuote8);

			if(secondQuotePos<0)
			{
				TBuf<32> countbuf;
				countbuf =_L("Parse Error: Mis-Quote");

/*			CAknErrorNote* informationNote = new (ELeave) CAknErrorNote(ETrue);
	       	informationNote->SetTimeout(CAknNoteDialog::EShortTimeout);
	       	informationNote->ExecuteLD(countbuf);*/
				return EFalse;//misquote
			}

			secondQuotePos += (firstQuotePos+1);
			CommaPos = secondQuotePos+1;



		}
		else
		{
			//csv.Set(incsv);
		}



		if(CommaPos>=0)
		{
			/*if(encounteredQuote)
			{
				ret.Set(incsv.Mid(1,CommaPos-1));
			}
			else
			{

			}*/
			ret.Set(whole.Left(CommaPos));

			if(ret.Length()>=2 && ret[0] == '"' && ret[ret.Length()-1] == '"' )
			{
				if(ret.Length()>2)
				{
					TPtrC8 tmp(0,0);
					tmp.Set(whole.Left(CommaPos));
					ret.Set(tmp.Mid(1,tmp.Length()-2));
				}
				else //ret==2
				{
					ret.Set(0,0);
				}

			}




			remainder.Set(whole.Right(whole.Length()-CommaPos-1));





			return ETrue;
		}


		//remainder.Set(incsv);
		return EFalse;
	}
Example #30
0
void CSTPieceAccess::WritePieceAsyncL(CSTPiece& aPiece, TInt aBegin, const TDesC8& aBlock, MPieceWriteObserver* aPieceWriteObserver, CSTPeer* aPeer)
{
	TInt blockPosition = 0;
	TInt piecePosition = aBegin;
	
	LWRITE(LOG, _L("Writing to piece started, piece: "));
	LWRITE(LOG, aPiece.Index());
	LWRITE(LOG, _L(" Position: "));
	LWRITELN(LOG, piecePosition);
	
	CPieceWriteEntry* writer = 
		new (ELeave) CPieceWriteEntry(aPiece, aBegin, aBlock.Length(), aPieceWriteObserver, aPeer);
	CleanupStack::PushL(writer);
	iWriters.AppendL(writer);
	CleanupStack::Pop(); // writer

	while (blockPosition < aBlock.Length())
	{
		CSTFile* file = NULL;
		TInt filePosition = 0;

		aPiece.GetFilePosition(piecePosition, &file, filePosition);

		if (file)
		{
			writer->iFiles.AppendL(CPieceWriteEntry::TSTFilePos(file, filePosition));
			
			//TInt res = KErrNone;
			TInt fileBlockLength = file->Size() - filePosition;

			//LogPieceIndexL();
			LWRITE(LOG, _L("Appending block to "));
			LWRITE(LOG, file->Path());
			LWRITE(LOG, _L(" "));
			LWRITELN(LOG, filePosition);

			if (fileBlockLength <= (aBlock.Length() - blockPosition))	// reached the end of a file
			{
				//LogPieceIndexL();
				LWRITE(LOG, _L("File complete: "));
				LWRITELN(LOG, file->Path());
				
				iFileManager.WriteAsyncL(file, 
					filePosition, aBlock.Mid(blockPosition, fileBlockLength), this);
				
				//FileManager().Close(file);

				blockPosition += fileBlockLength;
				piecePosition += fileBlockLength;				
			}
			else // the file isn't finished yet, the complete block is appended to the file
			{
				iFileManager.WriteAsyncL(file, 
					filePosition, aBlock.Right(aBlock.Length() - blockPosition), this);												

				piecePosition += (aBlock.Length() - blockPosition);
				//blockPosition = aBlock.Length();
				break;
			}
		}
		else
			User::Panic(KSymTorrentEnginePanic, KPanGetFilePositionFailed);
	}
}