Пример #1
0
// ----------------------------------------------------------------------------
// TTCPCompMsgEnd::DataReceivedL
// ----------------------------------------------------------------------------
//
void TTCPCompMsgEnd::DataReceivedL( TPtr8 aData, TUint&  aNextLength )
	{
	// panic if sigcomp is not supported in debug mode.leaves in release mode.
	__SIP_ASSERT_LEAVE(	iMsgAssembler.SigComp().IsSupported(), KErrGeneral );
	// panic if received data is not compressed in debug mode.
	// leaves in release mode.
	__SIP_ASSERT_LEAVE(	iMsgAssembler.SigComp().IsSigCompMsg( aData ), 
	                    KErrGeneral );
	// panic if received data is not completed compressed msg in debug mode.
	// leaves in release mode.
	__SIP_ASSERT_LEAVE(	
			iMsgAssembler.SigComp().IsCompleteSigCompMessageL( aData ), 
	        KErrGeneral );
	        
	TUint bytesConsumed( 0 );
	CBufBase* decompressedData = iMsgAssembler.SigComp().DecompressL( 
											aData, bytesConsumed, ETrue);

    TUint dataLen( static_cast<TUint>( aData.Length() ) );
    
    // Whole data was not decompressed and non-decompressed data might
	// be part of next sigcomp message, remember amount of non-decompressed
	// data
	iMsgAssembler.SetUnConsumedBytes( dataLen - bytesConsumed );
		
	if ( bytesConsumed < dataLen )
		{	
    	CleanupStack::PushL(decompressedData);
		aData.Delete(0, bytesConsumed);

		HBufC8* newData = 
		   HBufC8::NewL( decompressedData->Size() + aData.Length() );
	    // copy the msg buffer data and the received data to new data buffer
	    TPtr8 newDataPtr = newData->Des();
	    newDataPtr.Append(decompressedData->Ptr(0));
 	    CleanupStack::PopAndDestroy(decompressedData);
	    newDataPtr.Append(aData);
	    // delete all content of received data
	    aData.Delete( 0, aData.Length() );
  	    CleanupStack::PushL(newData);
  	    DecideNextStateL( newDataPtr, aNextLength );
	    CleanupStack::PopAndDestroy(newData);	
		}	
	else if ( bytesConsumed == dataLen )
		{
		CleanupStack::PushL( decompressedData );
		aData.Delete(0, bytesConsumed);	
		TPtr8 decompressedDataPtr = decompressedData->Ptr(0);
	    DecideNextStateL( decompressedDataPtr, aNextLength );
	    CleanupStack::PopAndDestroy( decompressedData );
		}
	else // bytesConsumed > dataLen error happens, reset the state
		{
		delete decompressedData;
		iMsgAssembler.ChangeState( MMsgAssemblerContext::EMsgInit );
		}				
	}
Пример #2
0
/**
	Updates the strings specified in step c of section 5.2.4 of RFC 3986
	
	@param aInputBuf A reference to the inputBuf needs to be modified 
	@param aOutPutBuf A reference to the outPutBuf needs to be modified
	@param aLength length of the string to be replaced.
 */
void  updateStrings(TPtr8& aInputBuf, TPtr8& aOutPutBuf, TInt aLength)
	{
	aInputBuf.Replace(0,aLength,KSlash);

	//In outPutBuf to remove the last segment starting with / (if exist)
	//eg: /abc/def/fgh --> /abc/def
	TInt outputBufLength = aOutPutBuf.Length();
	TInt pos = aOutPutBuf.LocateReverse('/');	
	//remove the last segment including '/'
	pos != KErrNotFound ? aOutPutBuf.Delete( pos, outputBufLength - pos ) : aOutPutBuf.Delete( 0,outputBufLength );
	}
Пример #3
0
TReal CGpsDataHandler::ParseCoordinateData() {
	TPtr8 pBuffer = iBuffer->Des();
	TReal aAngle;
	TReal aResult = 0.0;
	TInt aFindResult;

	aFindResult = pBuffer.Find(_L8(","));
	if(aFindResult != KErrNotFound) {
		HBufC8* aField = HBufC8::NewL(aFindResult);
		CleanupStack::PushL(aField);
		TPtr8 pField = aField->Des();

		pField.Copy(pBuffer.Ptr(), aFindResult);
		pBuffer.Delete(0, aFindResult+1);

		TLex8 aFieldLex(pField.Ptr());
		if(aFieldLex.Val(aAngle, '.') == KErrNone) {
			TInt32 aDegrees;
			Math::Int(aDegrees, aAngle / 100.0);

			TInt32 aMinutes;
			Math::Int(aMinutes, aAngle - aDegrees * 100);

			TReal aDecimal;
			Math::Frac(aDecimal, aAngle);

			aResult = aDegrees + (aMinutes + aDecimal) / 60.0;

			if(pBuffer[0] == TUint('S') || pBuffer[0] == TUint('W')) {
				aResult = -aResult;
			}

			aFindResult = pBuffer.Find(_L8(","));

			if(aFindResult != KErrNotFound) {
				pBuffer.Delete(0, aFindResult+1);
			}
		}

		CleanupStack::PopAndDestroy();
	}

	return aResult;
}
Пример #4
0
// ----------------------------------------------------------------------------
// TTCPCompMsgStart::DataReceivedL
// ----------------------------------------------------------------------------
//
void TTCPCompMsgStart::DataReceivedL( TPtr8 aData, TUint&  aNextLength )
	{
	// panic if sigcomp is not supported in debug mode.leaves in release mode.
	__SIP_ASSERT_LEAVE(	iMsgAssembler.SigComp().IsSupported(), KErrGeneral );
	     
	if ( iMsgAssembler.MsgBuffer().Size() > 0 )
		{
		// insert the received data to msg buffer.
		iMsgAssembler.MsgBuffer().InsertL(
									iMsgAssembler.MsgBuffer().Size(), aData );
		iMsgAssembler.MsgBuffer().Compress();
		// clean the content of received data.
		aData.Delete( 0, aData.Length() );
		TPtr8 bufPtr = iMsgAssembler.MsgBuffer().Ptr( 0 );
		
		// check if the msg buffer a complete sig comp message, if so
		// copy the msg buffer to a new data buf, clean the msg buffer
		// and enter to comp msg end state.
		if ( iMsgAssembler.SigComp().IsCompleteSigCompMessageL( bufPtr ) )
			{
			HBufC8* newData = HBufC8::NewLC( bufPtr.Length() );
			// copy the msg buffer data and the received data to new buffer
			TPtr8 newDataPtr = newData->Des();
			newDataPtr.Append(bufPtr);
			// clean the msg buffer
			iMsgAssembler.MsgBuffer().Reset();
			iMsgAssembler.MsgBuffer().Compress();
			
			iMsgAssembler.ChangeState( MMsgAssemblerContext::ECompMsgEnd );
			iMsgAssembler.CurrentState().DataReceivedL( newDataPtr, 
			                                            aNextLength );
	    	CleanupStack::PopAndDestroy(newData);
			}
		}
	else if (iMsgAssembler.SigComp().IsCompleteSigCompMessageL( aData ) )
		{
		iMsgAssembler.ChangeState( MMsgAssemblerContext::ECompMsgEnd );
		iMsgAssembler.CurrentState().DataReceivedL( aData, aNextLength );
		}
	else
		{
		iMsgAssembler.MsgBuffer().InsertL(
									iMsgAssembler.MsgBuffer().Size(), aData );
		iMsgAssembler.MsgBuffer().Compress();
		}
	}
Пример #5
0
void CRuleManager::ReadFavFromFile()
	{
	TFileName filename;
	GetAppPath(filename);
	filename.Append(KFavRuleFile);

	RFile file;
	TInt err;
	
	err = file.Open(CCoeEnv::Static()->FsSession(), filename, EFileRead);
	CleanupClosePushL(file);
	
	if (KErrNone != err)
		{
		CleanupStack::PopAndDestroy(); // file
		return;
		}
	
	TInt size;
	file.Size(size);
	
	if (size > 0)
		{
		HBufC8* text = HBufC8::NewL(size);
		TPtr8 ptr = text->Des();
		file.Read(ptr);
	
		TInt pos = ptr.Locate(KCharRuleSymbolEnd);
		if (pos != KErrNotFound)
			{
			ReadFromFile(ptr,pos,iFavRule);		
			ptr.Delete(0,pos+1);
			
			TInt num = CCommonUtils::StrToInt(ptr);
			iFavRule->SetFavCount(num);
			}
	
		delete text;
		}
	
	CleanupStack::PopAndDestroy(); // file
	}
// ----------------------------------------------------------------------------
// TNATFWUNSAFMsgStateHeaderEnd::DataReceivedL
// ----------------------------------------------------------------------------
//
TBool TNATFWUNSAFMsgStateHeaderEnd::DataReceivedL( TPtr8 aData,
    TUint& aNextLength )
    {
    __ASSERT_ALWAYS( aData.Length() >= iMsgAssembler.MessageLength(),
                     User::Leave( KErrUnderflow ) );

    TPtrC8 headerDescriptor = aData.Left( iMsgAssembler.MessageLength() );

    CNATFWUNSAFMessage* message =
        iMsgAssembler.MsgFactory().DecodeL( headerDescriptor );

    iMsgAssembler.SetMessage( message );
    message = 0;

    // delete the header part from the received data,
    aData.Delete( 0, iMsgAssembler.MessageLength() );

    iMsgAssembler.ChangeState( TNATFWUNSAFMsgStateBase::EMsgComplete );
    return iMsgAssembler.CurrentState().DataReceivedL( aData, aNextLength );
    }
Пример #7
0
void CRuleManager::ReadFromFile(RFile& file)
	{
	TInt size;
	file.Size(size);
	
	HBufC8* text = HBufC8::NewL(size);
	TPtr8 ptr = text->Des();
	file.Read(ptr);

	TInt pos = ptr.Locate(KCharRuleSymbolEnd);
	while (pos != KErrNotFound)
		{
		CRule* rule = CRule::NewL();
		ReadFromFile(ptr,pos,rule);
		iRules->Append(rule);
		
		ptr.Delete(0,pos+1);
		pos = ptr.Locate(KCharRuleSymbolEnd);
		}

	delete text;
	}
void CSmtpAuthCramMd5MechanismHelper::GetNextClientMessageL(TDes8& aNextMessage)
	{
	iNextClientMessage.Zero();

	if(iInProgress)
		{
		HBufC8* authbuffer = HBufC8::NewMaxLC(KImMailMaxBufferSize);//? 
		TPtr8 authbufferptr = authbuffer->Des();
		HBufC8* authbuffer2 = HBufC8::NewMaxLC(KImMailMaxBufferSize);//? 
		TPtr8 authbufferptr2 = authbuffer2->Des();
		HBufC8* authbuffer3 = HBufC8::NewMaxLC(KImMailMaxBufferSize);//? 
		TPtr8 authbufferptr3 = authbuffer3->Des();
		
		authbufferptr = iLastServerMessage;
		authbufferptr.Delete(0,4); //remove 334 from the begining of server response
		iEncoder.Decode(authbufferptr,authbufferptr2);
		//timestamp info now in authbufferptr2

		authbufferptr.Zero();
		authbufferptr3.Zero();
		authbufferptr = iSettings.Password();
		authbufferptr3 = FormSharedSecret(authbufferptr);
		authbufferptr.Zero();
		authbufferptr = authbufferptr3;  //now authbufferptr and authbufferptr3 contain the shared secret null padded to 64 bytes.
		TInt i=0;
		for (i=0; i<KMd5BlockLength; i++) 
			{
			authbufferptr[i] ^= 0x36; //ipad
			authbufferptr3[i] ^= 0x5c; //opad
			}

		authbufferptr.Append(authbufferptr2);

    	iMd5Hash->Reset();                                                                                                                                                                                                                                                                                                                ;
		authbufferptr2 = iMd5Hash->Hash(authbufferptr);

		authbufferptr3.Append(authbufferptr2);
		
		authbufferptr.Zero();
		iMd5Hash->Reset();
		authbufferptr = iMd5Hash->Hash(authbufferptr3);

		// MD5 algorithm ALWAYS returns 16 bytes of data - which will be converted into
		// 32 characters; each byte represented by a 2 character hex representation, 
		// eg 255="ff"
		TBuf<32> hexHash; 
		for (i=0;i<16;i++)
			{
			hexHash.AppendNumFixedWidth(authbufferptr[i],EHex,2);
			}

		authbufferptr3.Zero();
		authbufferptr3.Append(iSettings.LoginName());
		authbufferptr3.Append(_L8(" "));
		authbufferptr3.Append(hexHash);

		iEncoder.Encode(authbufferptr3, iNextClientMessage);
		iNextClientMessage.Append(KSmtpCrLf);
		CleanupStack::PopAndDestroy(3);	// authbufferptr3 ,authbufferptr2, authbufferptr
		aNextMessage = iNextClientMessage;
		}
	else
		{
		iNextClientMessage.Append(KSmtpAuthCommand);
		iNextClientMessage.Append(KCramMD5Mechanism);
		iNextClientMessage.Append(KSmtpCrLf);
		iInProgress=ETrue;
		aNextMessage = iNextClientMessage;
		}
	}
// ----------------------------------------------------------------------------
// TTCPMsgContentStart::DataReceivedL
// ----------------------------------------------------------------------------
//
void TTCPMsgContentStart::DataReceivedL( TPtr8 aData, TUint&  aNextLength )
	{
	CSIPMessage* message = iMsgAssembler.Message();
	
	// panic if message == 0 in debug mode. leaves in release mode.
	__SIP_ASSERT_LEAVE( message, KErrGeneral );
	// panic if there is no content length in debug mode. 
	// leaves in release mode.                
	__SIP_ASSERT_LEAVE( message->HasAnnouncedContentLength(), 
	                    KErrGeneral );	     

	TUint contentLen = message->AnnouncedContentLength();
	
	// panic if content length <= 0 in debug mode. 
	// leaves in release mode.                
	__SIP_ASSERT_LEAVE( contentLen > 0, KErrGeneral );	 
	
    // if message contains already some content, received data is complementing
	// it. this kind of situation might occur when sigcomp splits too big sip 
	// message to pieces
	if ( message->Content().Length() > 0 )
	    {
        iMsgAssembler.MsgBuffer().InsertL( iMsgAssembler.MsgBuffer().Size(), 
                                           message->Content() ); 
        iMsgAssembler.MsgBuffer().Compress();
                                           
        // remove old uncomplete content
        HBufC8* uncompletedContent = message->TakeContentOwnershipL(); 
        delete uncompletedContent;          
	    }
		
	if ( iMsgAssembler.SigComp().IsSupported() &&
	     iMsgAssembler.IsSigComp() &&
	     HandleComplementingSigCompDataL( aData, aNextLength, contentLen ) )
		{
	    return;
		}
	
	if ( iMsgAssembler.MsgBuffer().Size() > 0 )
		{
		// insert received data to msg buffer.
		iMsgAssembler.MsgBuffer().InsertL(
						        	iMsgAssembler.MsgBuffer().Size(), aData );
		iMsgAssembler.MsgBuffer().Compress();
		// delete the content of received data
		aData.Delete( 0, aData.Length() ); 

		TPtr8 bufPtr = iMsgAssembler.MsgBuffer().Ptr( 0 );
		
		// check if the msg buffer contains the whole content, if so
		// copy the msg buffer to new data buffer, clean the msg buffer
		// and enter to msg content end state.
		if ( contentLen <= static_cast< TUint >( bufPtr.Length() ) )
			{
			HBufC8* newData = HBufC8::NewLC( bufPtr.Length() );
		    // copy the msg buffer data  new data 
	    	TPtr8 newDataPtr = newData->Des();		    
	   		// delete the content of received data
			aData.Delete( 0, aData.Length() ); 
		    newDataPtr.Append(iMsgAssembler.MsgBuffer().Ptr(0));
		    // clean the msg buffer
			iMsgAssembler.MsgBuffer().Reset();
			iMsgAssembler.MsgBuffer().Compress();	
			
		    iMsgAssembler.ChangeState( MMsgAssemblerContext::EMsgContentEnd );
			iMsgAssembler.CurrentState().DataReceivedL( newDataPtr, 
			                                            aNextLength );
		    CleanupStack::PopAndDestroy( newData );
			}
		// if the msg buffer contains not enough content, ask the next
		// length to be received.
		else
			{
			aNextLength = contentLen - aData.Length();
			}
		}
	else if ( contentLen <= static_cast< TUint >( aData.Length() ) )
		{
		iMsgAssembler.ChangeState(MMsgAssemblerContext::EMsgContentEnd);
		iMsgAssembler.CurrentState().DataReceivedL( aData, aNextLength );
		}
	else
		{
		iMsgAssembler.MsgBuffer().InsertL(
									iMsgAssembler.MsgBuffer().Size(), aData );
		iMsgAssembler.MsgBuffer().Compress();
		aNextLength = contentLen - aData.Length();
		}
	}
// ----------------------------------------------------------------------------
// TTCPMsgContentStart::HandleComplementingSigCompDataL
// ----------------------------------------------------------------------------
//
TBool TTCPMsgContentStart::HandleComplementingSigCompDataL( 
    TPtr8 aData, 
    TUint& aNextLength,
    TInt aAnnouncedContentLen )
    {
    // If still receiving compressed data, current contents have to be
    // stored until we come back from comp states, in sigcomp point of
    // view message can be complete but it ain't necessary complete
    // in sip point of view. All data in aData or msgbuffer are not 
    // necessarily decompressed - these have to be taken with us when 
    // going back to decompression states
    
    TInt unconsumedBytes( iMsgAssembler.UnConsumedBytes() );
    
    TPtr8 msgBufPtr( iMsgAssembler.MsgBuffer().Ptr( 0 ) );
    HBufC8* content = NULL;
    
    TInt decompressedDataLen = aData.Length() - unconsumedBytes;
    
   	__SIP_ASSERT_LEAVE( decompressedDataLen > 0, KErrGeneral );
   	
   	TInt msgBufLen( msgBufPtr.Length() );
    TInt decompressedLen( msgBufLen + decompressedDataLen );
   	if ( aAnnouncedContentLen <= decompressedLen )
   	    {
   	    // Enough decompressed content data
   	    return EFalse;
   	    }
      
    // Store decompressed data to message content
    if ( msgBufLen > 0 )
        {
        content = HBufC8::NewL( decompressedLen );
        TPtr8 contentPtr( content->Des() );
        contentPtr.Copy( msgBufPtr );
        contentPtr.Append( aData.Left( decompressedDataLen ) );
        }
    else
        {
        content = aData.Left( decompressedDataLen ).AllocL();
        }
    
    // Remove decompressed data which was stored to content   
    aData.Delete( 0, decompressedDataLen ); 
        
     // Clean msgbuffer
   	iMsgAssembler.MsgBuffer().Reset();
    iMsgAssembler.MsgBuffer().Compress();
    	   
    iMsgAssembler.SetUnConsumedBytes( 0 );
    
    CSIPMessage* message = iMsgAssembler.Message();
    message->SetContent( content ); // ownership is transferred
	content = NULL;
	
	aNextLength = CSIPMsgAssembler::EMsgBufferSize;
	
	iMsgAssembler.ChangeState( MMsgAssemblerContext::ECompMsgStart );
	iMsgAssembler.CurrentState().DataReceivedL( aData, aNextLength );
	
	return ETrue;
    }
Пример #11
0
void CGpsDataHandler::ProcessData() {
	TPtr8 pBuffer = iBuffer->Des();

	// Check sentence is complete
	if(pBuffer[0] != TUint('$')) {
		// Burn invalid data
		pBuffer.Delete(0, 1);

		iEngineStatus = EGpsReading;
		iSocket.Recv(iChar, 0, iStatus);
		SetActive();
	}
	else if(pBuffer[pBuffer.Length()-1] == TUint('\n')) {
		// Sentence is complete
		TInt aStartField;
		TInt aFindResult;

		// Ready to parse data
		if(pBuffer.Find(_L8("$GPGLL")) != KErrNotFound) {
			aStartField = 1;
		}
		else if(pBuffer.Find(_L8("$GPGGA")) != KErrNotFound) {
			aStartField = 2;
		}
		else if(pBuffer.Find(_L8("$GPRMC")) != KErrNotFound) {
			aStartField = 3;
		}
		else {
			pBuffer.Zero();

			iEngineStatus = EGpsReading;
			iSocket.Recv(iChar, 0, iStatus);
			SetActive();

			return;
		}

		// Burn useless data
		for(TInt i = 0;i < aStartField;i++) {
			aFindResult = pBuffer.Find(_L8(","));

			if(aFindResult != KErrNotFound) {
				pBuffer.Delete(0, aFindResult+1);
			}
		}

		// Read latitude
		TReal aLatitude = ParseCoordinateData();
		TReal aLongitude = ParseCoordinateData();

		pBuffer.Zero();

		if(aLatitude != 0.0 || aLongitude != 0.0) {
			iObserver->GpsData(aLatitude, aLongitude, 10.0);

			iSocket.Close();
			iSocketServ.Close();
			iEngineStatus = EGpsDisconnected;
		}
	}
	else {
		iEngineStatus = EGpsReading;
		iSocket.Recv(iChar, 0, iStatus);
		SetActive();
	}
}