void CSandboxSession::ServiceL(const RMessage2 &aMessage) { if (aMessage.Function() >= EMaxArgs) { aMessage.Complete(KErrArgument); return; } if (aMessage.Function() == EGetRecog2) { aMessage.WriteL(0, iBuf); iBuf.Close(); aMessage.Complete(KErrNone); } else if (aMessage.Function() == EGetRecog) { if (iBuf.MaxLength() == 0) { iBuf.ReAllocL(1024); // Must be > sizeof(TDataType) otherwise the reallocating logic below is flawed } TUid uid = TUid::Uid(aMessage.Int0()); TUid destructorKey; CApaDataRecognizerType* rec = static_cast<CApaDataRecognizerType*>(REComSession::CreateImplementationL(uid, destructorKey)); TInt count = rec->MimeTypesCount(); for (TInt j = 0; j < count; j++) { TDataType type = rec->SupportedDataTypeL(j); TPckg<TDataType> buf(type); if (iBuf.Length() + buf.Length() >= iBuf.MaxLength()) { iBuf.ReAllocL(iBuf.MaxLength() * 2); } iBuf.Append(buf); } aMessage.Complete(iBuf.Size()); } else if (aMessage.Function() == ECloseServer) { aMessage.Complete(KErrNone); CActiveScheduler::Stop(); } else if (aMessage.Function() == EGetVTablePtr) { TUid destructorKey; TAny* obj = NULL; obj = REComSession::CreateImplementationL(TUid::Uid(aMessage.Int0()), destructorKey); TAny* vtablePtr = *((TAny**)obj); TPckg<TAny*> res(vtablePtr); aMessage.WriteL(1, res); aMessage.Complete(KErrNone); } else { ASSERT(0); } }
void CPublishAndSubscribeHandler::getValueL(unsigned long key, RBuf8& value) { TInt err = RProperty::Get(m_uid, key, value); if (err == KErrOverflow) { value.ReAllocL(RProperty::KMaxPropertySize); err = RProperty::Get(m_uid, key, value); if (err == KErrOverflow) { value.ReAllocL(RProperty::KMaxLargePropertySize); err = RProperty::Get(m_uid, key, value); } } User::LeaveIfError(err); }
// ----------------------------------------------------------------------------- // XIMPRBuf8Helper::GrowIfNeededL() // ----------------------------------------------------------------------------- // EXPORT_C void XIMPRBuf8Helper::GrowIfNeededL( RBuf8& aBuf, const TInt aMaxLength ) { if ( aBuf.MaxLength() < aMaxLength ) { aBuf.ReAllocL( aMaxLength ); } }
void CServerCrashDataSource::DoGetListL(const TListId aListId, const TThreadId aThreadId, const TProcessId aProcessId, RBuf8 & aBuffer, TUint32 & aSize ) { LOG_MSG5( "->CServerCrashDataSource::DoGetList(aListId=%d, aThredId=%Lu, aProcessId=%Lu, aSize=%d\n", aListId, aThreadId.Id(), aProcessId.Id(), aSize ); TInt ret; TListLevel listLevel; if( ((TUint)-1 == (TUint)aThreadId) && ((TUint)-1 == (TUint)aProcessId) ) { listLevel = EListGlobal; ret = iSecSess.GetList( aListId, aBuffer, aSize ); } else if( ((TUint)-1 != (TUint)aThreadId) && ((TUint)-1 == (TUint)aProcessId) ) { listLevel = EListThread; LOG_MSG("CServerCrashDataSource::DoGetList - EListThread"); ret = iSecSess.GetList( aThreadId, aListId, aBuffer, aSize ); } else { listLevel = EListProcess; LOG_MSG("CServerCrashDataSource::DoGetList - EListProcess"); ret = iSecSess.GetList( aProcessId, aListId, aBuffer, aSize ); } while( KErrTooBig == ret ) { LOG_MSG2( "CServerCrashDataSource::DoGetListL - list too big, new size=%d\n", aSize ); // Too big, and aSize should have been modified to the required new size // Since the list could have increased in size between calls, give it an // extra margin. aSize += 256; aBuffer.ReAllocL( aSize ); if( EListGlobal == listLevel ) { ret = iSecSess.GetList( aListId, aBuffer, aSize ); } else if( EListThread == listLevel ) { ret = iSecSess.GetList( aThreadId, aListId, aBuffer, aSize ); } else { ret = iSecSess.GetList( aProcessId, aListId, aBuffer, aSize ); } } User::LeaveIfError(ret); }
void CAsn1PerOctetString::DecodeL(const TDesC8& aBuf, const TInt aStartBit, const TBool aLengthIsVariable, const TBool aLengthIsConstrained, const TInt aMinLength, const TInt aMaxLength, const TBool aIsExtensible, const TBool /*aIsPadded*/, TBool& aIsExtended, TInt& aBitsDecoded, RBuf8& aDecodedBuf) { TInt currentBitPos=aStartBit; TInt bitDecoded=0; aBitsDecoded=0; aIsExtended=EFalse; TInt stringLen=0; CAsn1PerUtil::DecodeStringEBitAndLengthL(aBuf, currentBitPos, aLengthIsVariable, aLengthIsConstrained, aMinLength, aMaxLength, aIsExtensible, aIsExtended, bitDecoded, stringLen); currentBitPos+=bitDecoded; aBitsDecoded+=bitDecoded; bitDecoded=0; //check if the input buffer is long enough if (currentBitPos+stringLen*8>aBuf.Length()*8) { User::Leave(KErrUnderflow); } //Finally, decode the string content for cases aDecodedBuf.ReAllocL(stringLen); aDecodedBuf.SetLength(stringLen); aDecodedBuf.FillZ(); TInt stringBitLength=stringLen*8; //Copy the String to the Dest Buffer . TInt destBitNum=8; TInt destOctetNum=0; //Copy ... CAsn1PerUtil::CopyDataTrunkL(aBuf, currentBitPos, stringBitLength, aDecodedBuf, destOctetNum, destBitNum); aBitsDecoded+=stringBitLength; }
EXPORT_C void SoftwareTypeRegInfoUtils::SerializeArrayL(const RPointerArray<Usif::CSoftwareTypeRegInfo>& aSwTypeRegInfoArray, RBuf8& aSerializedArray) { TInt bufLen = sizeof(TInt); const TInt count = aSwTypeRegInfoArray.Count(); for (TInt i=0; i<count; ++i) { bufLen += GetObjectSizeL(aSwTypeRegInfoArray[i]); } aSerializedArray.ReAllocL(aSerializedArray.Length()+bufLen); RDesWriteStream ws(aSerializedArray); CleanupClosePushL(ws); ExternalizePointerArrayL(aSwTypeRegInfoArray, ws); ws.CommitL(); CleanupStack::PopAndDestroy(&ws); }
void CDnsUpdateOption::ToStringL(RBuf8& aBuf8) const /** * Writes DNS update option data to a string suitable for sending out * on to the network * * @internalTechnology * */ { RBuf8 encodedDomainName; encodedDomainName.CleanupClosePushL(); TDomainNameArray domainNames; CleanupClosePushL(domainNames); domainNames.AppendL(iDomainName); CDomainNameCodec* domainNameEncoder = new(ELeave) CDomainNameCodec(); CleanupStack::PushL(domainNameEncoder); domainNameEncoder->EncodeL(domainNames, encodedDomainName); CleanupStack::PopAndDestroy(domainNameEncoder); CleanupStack::PopAndDestroy(&domainNames); // closes the RBuf8 aBuf8.Zero(); aBuf8.ReAllocL( 3 + encodedDomainName.Length() ); aBuf8.Append((TChar)(iFlags.Value())); aBuf8.Append((TChar)iRCode1); aBuf8.Append((TChar)iRCode2); aBuf8.Append(encodedDomainName); CleanupStack::PopAndDestroy(&encodedDomainName); // closes the array }
void CDomainNameCodec::EncodeL(TDomainNameArray& aNames, RBuf8& aBuf8) { TUint requiredLength = 0; TUint8 nameIdx = 0; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { // The total length required for the labels that comprise an // individual domain name needs to take into the length octet // for the initial label and the null-termination character. // Hence the '+ 2' below. requiredLength += (aNames[nameIdx].Length() + 2); // A further length check is performed on each domain name to // ensure it does not exceed the maximum length permitted according // to RFC 1035. if(aNames[nameIdx].Length() > KMaxDomainNameLength) { User::Leave(KErrArgument); } } aBuf8.Zero(); aBuf8.ReAllocL(requiredLength); TLex8 domainName; TPtrC8 currentLabel; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { domainName.Assign(aNames[nameIdx]); domainName.Mark(); while (!domainName.Eos()) { TChar ch; do { ch = domainName.Get(); } while ( ch != TChar('.') && !domainName.Eos() ); // if not the end of the string, unget the previous char to skip the trailing // dot in our marked token // if( !domainName.Eos() ) { domainName.UnGet(); } currentLabel.Set(domainName.MarkedToken()); // move past the dot again, or do nothing in particular at EOS // domainName.Get(); User::LeaveIfError(currentLabel.Length() > KMaxDnsLabelLength ? KErrArgument : KErrNone); aBuf8.Append(TChar(currentLabel.Length())); aBuf8.Append(currentLabel); domainName.Mark(); } aBuf8.Append(TChar(0)); } }
// -------------------------------------------------------------------------------------- // 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); } }