TUint32 RBufHashFunction( const RBuf8& aObject ) { return DefaultHash::Integer( aObject.Length() ); }
// --------------------------------------------------------------------------- // Something has been read from EP0 // --------------------------------------------------------------------------- // void CStateMachine::ReadEP0L(RBuf8& aBuffer, const TRequestStatus& aStatus) { FTRACE(FPrint( _L("[USBDEVCON]\tCStateMachine::ReadEP0: BufferLength = %d, aStatus = %d" ),aBuffer.Length(), aStatus.Int())); // all errors while reading data lead to idle state (ESetupStage in our case) if(KErrNone != aStatus.Int()) { // restart StartL(); return; } TInt err(KErrNone); switch(iState) { case ESetupStage: // setup transaction received { FLOG( _L( "[USBDEVCON]\tCStateMachine::ReadEP0 processing ESetupStage" ) ); if(aBuffer.Length() != KSetupPacketLength) // SetupPacket is always 8 bytes { StartL(); return; } ProcessSetupPacketL(aBuffer); break; } case EDataStage: // some data received from host. This data is required for the request, received on setup stage { FLOG( _L( "[USBDEVCON]\tCStateMachine::ReadEP0 processing EDataStage" ) ); // handle request, providing data together with request descriptor // iBuffer == request, aBuffer == data from host err = iRequestsHandler.Handle(iBuffer, aBuffer); if(KErrNone != err) // some error happened while handling request { iLdd.EndpointZeroRequestError(); // stall EP0 } else { // send Status Packet, indicating that we received request, data, and handled request. OK iLdd.SendEp0StatusPacket(); } // all done, go to idle state iState = ESetupStage; iEP0Reader->ReadSetupPacketL(); break; } default: { FLOG( _L( "[USBDEVCON]\tCStateMachine::ReadEP0 processing ***NOT_DEFINED state***" ) ); } } }
// --------------------------------------------------------------------------- // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL // --------------------------------------------------------------------------- // void CRoHandlerDMgrWrapper::DoSaveRoapTriggerL( TMeterState aNextState ) { // Check success of download DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() ); try { // Fetch download created in DoDownloadRoapTriggerL QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); //uncomment iDownload = NULL; //iDlMgr->findDownload( downloadUrl ); } catch(const std::exception& exception) { qt_symbian_exception2LeaveL(exception); } // Delete trigger URL so that it is possible to check // whether or not meteringResponse has PrUrl. delete iTriggerUrl; iTriggerUrl = NULL; RFile roapTrigger; if ( !iDownloadSuccess ) { if ( iConnectionError ) { User::Leave( KErrCouldNotConnect ); } else { User::Leave( KErrGeneral ); } } User::LeaveIfError( roapTrigger.Open( iFs, *iFileName, EFileShareReadersOrWriters ) ); CleanupClosePushL( roapTrigger ); // Get filehandle of ROAP trigger const TInt KReadBufSize = 512; RBuf8 readBuf; readBuf.CleanupClosePushL(); readBuf.CreateL( KReadBufSize ); // Read file to buffer TInt triggerFileSize( 0 ); User::LeaveIfError( roapTrigger.Size( triggerFileSize ) ); if ( iTriggerBuf ) { delete iTriggerBuf; iTriggerBuf = NULL; } iTriggerBuf = HBufC8::NewL( triggerFileSize ); User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) ); iTriggerBuf->Des().Copy( readBuf ); while ( readBuf.Length() == KReadBufSize ) { User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) ); iTriggerBuf->Des().Append( readBuf ); } // And let ROAP handle it... CleanupStack::PopAndDestroy( &readBuf ); CleanupStack::PopAndDestroy( &roapTrigger ); iFs.Delete( *iFileName ); delete iFileName; iFileName=NULL; Continue( aNextState, KErrNone ); }
// ----------------------------------------------------------------------------- // XIMPRBuf8Helper::ExternalizeL() // ----------------------------------------------------------------------------- // EXPORT_C void XIMPRBuf8Helper::ExternalizeL( const RBuf8& aBuf, RWriteStream& aStream ) { aStream.WriteInt32L( aBuf.Length() ); aStream.WriteL( aBuf ); }
// -------------------------------------------------------------------------------------- // Serializes TXmlEngNode to buffer // -------------------------------------------------------------------------------------- // TInt CXmlEngSerializerXOP::SerializeL( RBuf8& aBuffer, const TXmlEngNode aRoot, const TXmlEngSerializationOptions& aOptions ) { if(aBuffer.Length()) { aBuffer.Close(); } LeaveIfXopIncludeL(aRoot); iDataContainerArray.Reset(); if(aOptions.iDataSerializer) { return CXmlEngSerializer::SerializeL(aBuffer, aRoot, aOptions); } TXmlEngSerializationOptions opt = aOptions; opt.iDataSerializer = this; RBuf8 xopDocument; CleanupClosePushL(xopDocument); aRoot.OwnerDocument().SaveL(xopDocument, aRoot, opt); if( iCleanXOPInfoset ) { if(xopDocument.Size() > aBuffer.MaxSize()) { aBuffer.ReAllocL( xopDocument.Size() ); } aBuffer.Append(xopDocument); } else { // adjust buffer size TInt bufSize = KXOPDocumentStart().Size() + KMimeRoot().Size() + xopDocument.Size() + KXOPDocumentEnd().Size(); for(TInt j = 0; j < iDataContainerArray.Count(); j++) { TPtrC8 contentTypeStr; if(GetContentTypeValue(iDataContainerArray[j], contentTypeStr)) { bufSize += KMimeHeaderContentType().Size() + contentTypeStr.Size() + KNewLine().Size(); } bufSize += KMimeHeaderStart().Size() + KMimeHeaderContentIdStart().Size() + iDataContainerArray[j].Cid().Length() + KMimeHeaderContentIdEnd().Size() + KNewLine().Size() + iDataContainerArray[j].Size(); } if (bufSize > aBuffer.MaxSize()) { aBuffer.ReAllocL( bufSize ); } // write to buffer aBuffer.Append(KXOPDocumentStart()); aBuffer.Append(KMimeRoot()); aBuffer.Append(xopDocument); for(TInt i = 0; i < iDataContainerArray.Count(); i++) { aBuffer.Append(KMimeHeaderStart); TPtrC8 contentTypeStr; if(GetContentTypeValue(iDataContainerArray[i], contentTypeStr)) { aBuffer.Append(KMimeHeaderContentType); aBuffer.Append(contentTypeStr); aBuffer.Append(KNewLine); } aBuffer.Append(KMimeHeaderContentIdStart); aBuffer.Append(iDataContainerArray[i].Cid()); aBuffer.Append(KMimeHeaderContentIdEnd); aBuffer.Append(KNewLine); switch(iDataContainerArray[i].NodeType()) { case TXmlEngNode::EBinaryContainer: { if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(iDataContainerArray[i].AsBinaryContainer().Contents()); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(iDataContainerArray[i].AsBinaryContainer().Contents()); } break; } case TXmlEngNode::EChunkContainer: { TPtrC8 data = TPtrC8( ((RChunk&)iDataContainerArray[i].AsChunkContainer().Chunk()).Base() + iDataContainerArray[i].AsChunkContainer().ChunkOffset(), iDataContainerArray[i].AsChunkContainer().Size()); if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(data); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(data); } break; } case TXmlEngNode::EFileContainer: { TInt size = iDataContainerArray[i].AsFileContainer().Size(); HBufC8* data = HBufC8::NewLC(size); TPtr8 dataPtr = data->Des(); iDataContainerArray[i].AsFileContainer().File().Read(dataPtr, size); if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(dataPtr); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(dataPtr); } CleanupStack::PopAndDestroy(); //data break; } } } aBuffer.Append(KXOPDocumentEnd); } CleanupStack::PopAndDestroy(); //xopDocument return aBuffer.Size(); }
void CDHCPMessageHeaderIP4::FinishL(TDesC8& aClientId) /** * Put finishing touches to message for sending * Basically copies in the magic cookie (99.130.83.99) * and the end marker then set the length of the descriptor * as we have been pushing data into the descriptor manually * * @param aClientId The client ID string to be added to the message * @see RFC 2131 for explanation of the magic cookie! * * @internalTechnology */ #endif //SYMBIAN_NETWORKING_DHCP_MSG_HEADERS { __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPMessageBase::FinishL"))); #ifdef SYMBIAN_NETWORKING_DHCPSERVER if(!iDHCPServerImpl) { #endif // SYMBIAN_NETWORKING_DHCPSERVER TUint8 reqListArray[KDhcpParameterRequestListLen] = {EDHCPHostName, EDHCPDomainNameServer, EDHCPDomainName, EDHCPSubnetMask, EDHCPRouter, EDHCPBroadcastAddr, EDHCPSIPServers}; TPtr8 ptr(reqListArray, KDhcpParameterRequestListLen, KDhcpParameterRequestListLen); // +++++++++++++++++++++++ Client ID +++++++++++++++++++++++++++++++++++++++++/ AddOptionL(EDHCPClientID, aClientId.Length())->GetBodyDes().Copy(aClientId); #ifdef SYMBIAN_NETWORKING_DHCP_MSG_HEADERS RBuf8 appendOpCodeList; appendOpCodeList.CreateL(ptr); if (aOptionsPtr) { TInt optLen=aOptionsPtr->Length(); appendOpCodeList.ReAllocL(KDhcpParameterRequestListLen+optLen); appendOpCodeList.Append(aOptionsPtr->Ptr(),optLen); } AddOptionL(EDHCPParameterReqList, appendOpCodeList.Length())->GetBodyDes().Copy(appendOpCodeList); appendOpCodeList.Close(); #else // +++++++++++++++++++++++ Parameter Request List ++++++++++++++++++++++++++++/ AddOptionL(EDHCPParameterReqList, ptr.Length())->GetBodyDes().Copy(ptr); #endif // +++++++++++++++++++++++ Maximum message size (2 bytes) ++++++++++++++++++++/ AddOptionL(EDHCPMaxMsgSize, 2)->SetBigEndian(KDhcpMaxMsgSizeIP4); #ifdef SYMBIAN_NETWORKING_DHCPSERVER } #endif // SYMBIAN_NETWORKING_DHCPSERVER TInetAddr magic; _LIT(magicCookie, "99.83.130.99"); User::LeaveIfError(magic.Input(magicCookie)); // essential the magic cookie is correct iCookie.SetLittleEndian(magic.Address()); ASSERT(!iOptions.FindOption(EDHCPEnd)); AddOptionL(EDHCPEnd, 0); //add padding if msg shorter than 300 bytes TInt len=iMsg->Length(); TPtr8 des=iMsg->Des(); if (len<300) { des.AppendFill(EDHCPPad, 300-len); } }
/** * Write the file to the hard drive. * * @param aFileName * @param aBodyPartArray */ void CMultipartTestContainer::WriteFileL( const TDesC& aFileName, RPointerArray<CBodyPart>& aBodyPartArray ) { RFs fs; fs.Connect(); CleanupClosePushL(fs); RFile output; TInt err = output.Open(fs, aFileName, EFileWrite); if (err == KErrNotFound) { User::LeaveIfError(output.Create(fs, aFileName, EFileWrite)); } // output file TInt size = aBodyPartArray.Count(); TInt i; _LIT8(KEol, "\r\n"); for (i = 0; i < size; i++) { CBodyPart* bodyPart = aBodyPartArray[i]; if( bodyPart->Url().Ptr() ) { output.Write(_L8("***************Ur")); output.Write(KEol); RBuf8 narrow; err = narrow.Create(bodyPart->Url().Length()*2); if (err != KErrNone) { INFO_PRINTF1(_L("Error printing Url to output file; continueing...")); } narrow.Copy(bodyPart->Url()); output.Write(narrow.Left(narrow.Length())); output.Write(KEol); } if( bodyPart->ContentID().Ptr() ) { output.Write(_L8("***************ContentID")); output.Write(KEol); output.Write(bodyPart->ContentID() ); output.Write(KEol); } if( bodyPart->Charset().Ptr() ) { output.Write(_L8("***************Charset")); output.Write(KEol); output.Write( bodyPart->Charset() ); output.Write(KEol); } if( bodyPart->ContentType().Ptr() ) { output.Write(_L8("***************ContentType")); output.Write(KEol); output.Write( bodyPart->ContentType() ); output.Write(KEol); } if( bodyPart->Headers().Ptr() ) { output.Write(_L8("***************Headers")); output.Write(KEol); output.Write(bodyPart->Headers() ); output.Write(KEol); } if( bodyPart->Body().Ptr() ) { output.Write(_L8("***************Body")); output.Write(KEol); output.Write(bodyPart->Body() ); output.Write(KEol); } output.Write(_L8("=========================================part ends")); output.Write(KEol); } // end of loop output.Close(); CleanupStack::PopAndDestroy(1, &fs); fs.Close(); }