示例#1
0
HRESULT PESection::addSectReloc(unsigned offset, PESection *relativeTo,
                                CeeSectionRelocType reloc, CeeSectionRelocExtra *extra) 
{
    /* dbPrintf(("******** GOT a section reloc for section %s offset 0x%x to section %x offset 0x%x\n",
       header->m_name, offset, relativeTo->m_name, *((unsigned*) dataStart + offset))); */
    _ASSERTE(offset < dataLen());
    
    if (m_relocCur >= m_relocEnd)  {
        unsigned curLen = (unsigned)(m_relocCur-m_relocStart);
        unsigned newLen = curLen * 2 + 1;
        PESectionReloc* relocNew = new (nothrow) PESectionReloc[newLen];
        if (relocNew == NULL)
        {
            return E_OUTOFMEMORY;
        }
        
        memcpy(relocNew, m_relocStart, sizeof(PESectionReloc)*curLen);
        delete m_relocStart;
        m_relocStart = relocNew;
        m_relocCur = &m_relocStart[curLen];
        m_relocEnd = &m_relocStart[newLen];
    }
    
    m_relocCur->type = reloc;
    m_relocCur->offset = offset;
    m_relocCur->section = relativeTo;
    if (extra)
        m_relocCur->extra = *extra;
    m_relocCur++;
    assert(m_relocCur <= m_relocEnd);
    return S_OK;
}
// ----------------------------------------------------------------------------
// 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 );
		}				
	}
示例#3
0
/**
Implementation of pure virtual function.
@see    MWTCacheInterface::ReadL()
*/
void CDynamicDirCache::ReadL(TInt64 aPos, TInt aLength, TDes8& aDes)
    {
#ifdef _DEBUG
    if(iCacheDisabled)
        {
        // cache is disabled for debug purposes
        __PRINT(_L("CDynamicDirCache disabled"));
        User::LeaveIfError(iDrive.ReadNonCritical(aPos, aLength, aDes));
        return;
        }
#endif //_DEBUG

    aDes.Zero();
    const TUint32 PageSz = iPageSizeInBytes;//-- cache page size

    TInt64 pageStartMedPos = CalcPageStartPos(aPos);
    const TUint32 bytesToPageEnd = (TUint32)(pageStartMedPos + PageSz - aPos); //-- number of bytes from aPos to the end of the page

//    __PRINT5(_L("CDynamicDirCache::ReadL: aPos=%lx, aLength=%x, page:%lx, pageSz:%x, bytesToPageEnd=%x"), aPos, aLength, pageStartMedPos, PageSz, bytesToPageEnd);
    // if all data needed is on a single page
    if((TUint32)aLength <= bytesToPageEnd)
        {
        ReadDataFromSinglePageL(aPos, aLength, aDes);
        }
    // or data to be read cross cache page boundary or probably we have more than 1 page to read
    else
        {
        __PRINT(_L("CDynamicDirCache::ReadL() CROSS PAGE!"));
        TUint32 dataLen(aLength);   //-- current data length
        TInt64  currMediaPos(aPos); //-- current media position

        //-- 1. read data that are already in the current page
        ReadDataFromSinglePageL(currMediaPos, bytesToPageEnd, aDes);
        dataLen -= bytesToPageEnd;
        currMediaPos += bytesToPageEnd;

        TPtr8 dataNext = aDes.MidTPtr(aDes.Length());

        //-- 2. read whole pages of data
        while (dataLen >= PageSz)
            {
            //-- find out if currMediaPos is in cache. If not, find a spare page and read data there
            ReadDataFromSinglePageL(currMediaPos, PageSz, dataNext);
            currMediaPos += PageSz;
            dataLen -= PageSz;
            dataNext = dataNext.MidTPtr(dataNext.Length());
            }

        //-- 3. read the rest of the data
        if(dataLen > 0)
            {
            ReadDataFromSinglePageL(currMediaPos, dataLen, dataNext);
            }
        } //else((TUint32)aLength <= bytesToPageEnd)
    }
EXPORT_C void CTcTestRunner::Start()
	{
	// Is there still room in the receive buffer?
	if( iRequest.Length() < iRequest.MaxLength() )
		{
		// Construct a pointer descriptor for the free data area of iRequest
		// This is done to accomplish "appending" socket read.
		TInt dataLen( iRequest.Length() );
		iFreeRequest.Set( const_cast< TUint8* >( iRequest.Ptr() ) + dataLen, 0,
						  iRequest.MaxLength() - dataLen );
		iBearer.ReceiveOneOrMore( iFreeRequest );
		}
	else
		{
		SendErrorResponse( KTcErrReceiveOverflow );
		}
	}
StringTableEntry* CeeSectionString::createEntry(__in_z LPWSTR target, ULONG hashId) 
{
    StringTableEntry *entry = new StringTableEntry;
    if (!entry)
        return NULL;
    entry->m_next = NULL;
    entry->m_hashId = hashId;
    entry->m_offset = dataLen();
    ULONG len = (lstrlenW(target)+1) * sizeof(wchar_t);
    void *buf = getBlock(len);
    if (!buf) {
        delete entry;
        return NULL;
    }
    memcpy(buf, target, len);
    return entry;
}
示例#6
0
/**
    Read data from the media through the directory cache.
    
    @param  aPos    linear media position to start reading with
    @param  aLength how many bytes to read
    @param  aDes    data will be placed there
*/
void CMediaWTCache::ReadL(TInt64 aPos,TInt aLength,TDes8& aDes)
    {
    
#ifdef _DEBUG
    if(iCacheDisabled)
        {//-- cache is disabled for debug purposes
        User::LeaveIfError(iDrive.ReadNonCritical(aPos, aLength, aDes));
        return;
        }
#endif //_DEBUG

    const TUint32 PageSz = PageSize();//-- cache page size

    //-- find out if aPos is in cache. If not, find a spare page and read data there
    TInt nPage = FindOrGrabReadPageL(aPos);
    CWTCachePage* pPage = iPages[nPage];

    const TUint32 bytesToPageEnd = (TUint32)(pPage->iStartPos+PageSz - aPos); //-- number of bytes from aPos to the end of the page

//    __PRINT5(_L("CMediaWTCache::ReadL: aPos=%lx, aLength=%x, page:%lx, pageSz:%x, bytesToPageEnd=%x"), aPos, aLength, pPage->iStartPos, PageSz, bytesToPageEnd);
    if((TUint32)aLength <= bytesToPageEnd) 
        {//-- the data section is in the cache page entirely, take data directly from the cache
        aDes.Copy(pPage->PtrInCachePage(aPos), aLength);
        }
    else
        {//-- Data to be read cross cache page boundary or probably we have more than 1 page to read

        TUint32 dataLen(aLength);   //-- current data length
        TInt64  currMediaPos(aPos); //-- current media position

        //-- 1. read data that are already in the current page
        aDes.Copy(pPage->PtrInCachePage(currMediaPos), bytesToPageEnd);

        dataLen -= bytesToPageEnd;
        currMediaPos += bytesToPageEnd;

        //-- 2. read whole pages of data
        while(dataLen >= PageSz)
            {
            nPage = FindOrGrabReadPageL(currMediaPos); //-- find out if currMediaPos is in cache. If not, find a spare page and read data there
            pPage = iPages[nPage];

            aDes.Append(pPage->PtrInCachePage(currMediaPos),PageSz);
        
            dataLen -= PageSz;
            currMediaPos += PageSz;
        
            MakePageLRU(nPage); //-- push the page to the top of the priority list
            }

        //-- 3. read the rest of the data
        if(dataLen >0)
            {
            nPage = FindOrGrabReadPageL(currMediaPos); //-- find out if currMediaPos is in cache. If not, find a spare page and read data there
            pPage = iPages[nPage];

            aDes.Append(pPage->PtrInCachePage(currMediaPos), dataLen);
            }

        } //else((TUint32)aLength <= bytesToPageEnd) 


    MakePageLRU(nPage); //-- push the page to the top of the priority list
    
    }
示例#7
0
void PESection::writeSectReloc(unsigned val, CeeSection& relativeTo, CeeSectionRelocType reloc, CeeSectionRelocExtra *extra) 
{
    addSectReloc(dataLen(), relativeTo, reloc, extra);
    unsigned* ptr = (unsigned*) getBlock(4);
    *ptr = val;
}
示例#8
0
			virtual bool Run()
			{
				Network::TcpServer s;
				bool res = s.Listen(address_);
				if (!res)
				{
					return false;
				}

				SMPP::SessionManager m;
				bool tmo = false;
				for(;;)
				{
					bool res = s.WaitForNewConnection(10, &tmo);

					if (!res && tmo)
					{
						FILE_LOG(logDEBUG4) << "Timeout !";
						tmo = false;
						continue;
					}

					Network::TcpSocket* client = s.NextPendingConnection();
					if (NULL == client)
					{
						FILE_LOG(logERROR) << "Cannot connect with the SMPP client !";
					}

                    /*
                    */
                    unsigned char lenbuf[4];
                    client->Read(&lenbuf[0], 4);
                    SMPP::FourByteInteger dataLen(&lenbuf[0]);

                    FILE_LOG(logINFO) << "Data len: " << dataLen.Value();

                    unsigned char* data = new unsigned char[dataLen.Value()];
                    memcpy(data, &lenbuf[0], 4);
                    ssize_t count = client->Read(data + 4, dataLen.Value() - 4);
                    FILE_LOG(logINFO) << "Read " << count << " bytes !";

                    std::stringstream ss;
                    for (size_t i = 0; i < count + 4; ++i)
                    {
                        ss << std::setfill('0') << std::setw(2) << std::hex << int(data[i]);
                    }
                    FILE_LOG(logINFO) << "Bytes received: " << ss.str();

                    int tmp = 0;
                    memcpy((void*)&tmp, data + 4, sizeof(tmp));
                    FILE_LOG(logINFO) << "Command ID: " << std::setfill('0') << std::setw(2 * sizeof(tmp)) << std::hex << ntohl(tmp);
                    if (0x00000002 == ntohl(tmp))
                    {
                        FILE_LOG(logINFO) << "BindTransmitter message received !";
                        try
                        {
                            SMPP::BindTransmitter t(data, dataLen.Value());
                            FILE_LOG(logINFO) << t;

                            SMPP::BindTransmitterResp tr;
                            SMPP::PduHeader& trh = tr.GetHeader();

                            trh.SetSequenceNumber(t.GetHeader().GetSequenceNumber());
                            tr.SetSystemId("EUGEN");

                            FILE_LOG(logINFO) << tr;

                            const unsigned char* toSend = tr.Data();
                            std::stringstream ss;
                            for (size_t i = 0; i < tr.Size(); ++i)
                            {
                                ss << std::setfill('0') << std::setw(2) << std::hex << int(toSend[i]);
                            }
                            FILE_LOG(logINFO) << "Bytes to send: " << ss.str();

                            ssize_t count = client->Write(toSend, tr.Size());
                            FILE_LOG(logINFO) << "Sent: " << count;
                        }
                        catch (std::exception& e)
                        {
                            FILE_LOG(logINFO) << "Exception !" << e.what();
                        }
                    }

                    /*
					*/
				}

				return true;
			}