void CTcpClientTestUPnP13::NewData(TUint aCount) { RMBufChain data; RBuf8 resData; iLogger.WriteFormat(_L("<i>NewData..... </i>")); iSSP->GetOption(1,KCHMaxLength,resData); resData.Create( aCount ); iSSP->GetOption(KCHOptionLevel,KCHMaxLength,resData); TInt len = *(TUint*) resData.Ptr(); resData.Close(); iSSPData->GetData(data,aCount,0); resData.Create( aCount ); data.CopyOut(resData); resData.Close(); resData.Create( aCount ); iSSP->GetOption(KCHOptionLevel,KCHLastMessage,resData); TBool isLastMsg = *(TUint*) resData.Ptr(); resData.Close(); data.Init(); if(isLastMsg) { iLogger.WriteFormat(_L("<i>NewData.LastMsg.... </i>")); CompleteSelf ( KErrNone ); } }
int main() { __UHEAP_MARK; int retval =ESuccess; char* mycharstring = "Hello Char String"; int char_length= strlen(mycharstring); RBuf8 myRBuf; myRBuf.CreateL(30); myRBuf.CleanupClosePushL(); retval = CharToRbuf8 (mycharstring, myRBuf); int buf_len = myRBuf.Length(); if (retval ==ESuccess &&\ char_length == buf_len &&\ strncmp("Hello Char String",(char*)myRBuf.Ptr() , 17) ==0 ) { printf("CharToRbuf8 content check Passed\n"); } else { assert_failed = true; printf("CharToRbuf8 content check Failed\n"); } CleanupStack::PopAndDestroy(1); __UHEAP_MARKEND; testResultXml("test_chartorbuf8_content_check"); return 0; }
int ILibSocketWrapper_recv(int socketObject, char *buffer, int bufferLength) { RSocket *s = (RSocket*)SocketArray[socketObject]; RBuf8 *buf = new RBuf8(); TRequestStatus status; TSockXfrLength aLen; int RetVal=0; if(buf->Create(bufferLength)==KErrNone) { s->RecvOneOrMore(*buf,0,status,aLen); User::WaitForRequest(status); if(status!=KErrNone) { RetVal = 0; } else { RetVal = aLen(); Mem::Copy(buffer,(void*)buf->Ptr(),RetVal); } } buf->Close(); delete buf; return(RetVal); }
EXPORT_C SMetaDataNetCtor* SMetaDataNetCtorExt::LoadL(TPtrC8& aDes) { TUint8* ptr = const_cast<TUint8*> ( aDes.Ptr() ); TPtr8 ptr2 ( ptr, aDes.Length() ); RBuf8 buf; buf.CreateL(aDes); TPtrC8 ptr3 (buf.Ptr(), buf.Length()); CMetaDataVirtualCtorInPlace* vctr = SockManGlobals::Get()->SelfWorker()->TransportGlobals().VirtualCtor(); SMetaDataNetCtor* meta = vctr->New(ptr3, ptr2); TInt len = buf.Length() - ptr3.Length(); aDes.Set(aDes.Ptr() + len, aDes.Length() - len); buf.Close(); return meta; }
int32_t FSocket::readBuffer(int8_t* buffer, int32_t maxLen) { StringBuffer errorMsg; RBuf8 data; data.CreateL(maxLen); // Receives data from a remote host and completes when data is available. TSockXfrLength len; iSocket.RecvOneOrMore(data, 0, iStatus, len); User::WaitForRequest(iStatus); TInt msgLen = len(); if (iStatus == KErrNone) { if (msgLen <= maxLen) { // OK. Copy the message into the preallocated buffer. memcpy(buffer, data.Ptr(), msgLen); data.Close(); return msgLen; } else { errorMsg.sprintf("FSocket: error reading, message too big (%d > %d) -> rejected.", (int)msgLen, (int)maxLen); goto error; } } else if (iStatus == KErrEof) { // Either the remote connection is closed, or the socket has been shutdown. errorMsg = "FSocket: read interrupted (connection closed)"; goto error; } else { errorMsg.sprintf("FSocket: error reading on socket (status = %d)", iStatus.Int()); goto error; } error: LOG.error("%s", errorMsg.c_str()); buffer = NULL; data.Close(); return -1; }
int ILibSocketWrapper_recvfrom(int socketObject, char *buffer, int bufferLength, struct sockaddr *src) { RSocket *s = (RSocket*)SocketArray[socketObject]; TRequestStatus status; TInetAddr addr; int RetVal=0; RBuf8 *buf = new RBuf8(); if(buf->Create(bufferLength)==KErrNone) { TProtocolDesc aProtocol; s->Info(aProtocol); if(aProtocol.iSockType==KSockStream) { s->RemoteName(addr); ((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address()); src->sa_port = htons(addr.Port()); RetVal = ILibSocketWrapper_recv(socketObject, buffer, bufferLength); } else { s->RecvFrom(*buf,addr,(unsigned int)0,status); User::WaitForRequest(status); if(status!=KErrNone) { RetVal = 0; } else { ((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address()); src->sa_port = htons(addr.Port()); Mem::Copy(buffer,buf->Ptr(),buf->Length()); RetVal = buf->Length(); } } } buf->Close(); delete buf; return(RetVal); }
TInt GetRecogniserInfo(TUid aImplementationUid, RArray<TDataType>& aMimeTypes) { TInt size = SendReceive(EGetRecog, TIpcArgs(aImplementationUid.iUid)); if (size < 0) return size; TInt err = aMimeTypes.Reserve(size/sizeof(TDataType)); if (err) return err; RBuf8 buf; err = buf.Create(size); if (err) return err; err = SendReceive(EGetRecog2, TIpcArgs(&buf)); if (err) { buf.Close(); return err; } const TDataType* ptr = (const TDataType*)buf.Ptr(); for (TInt i = 0; i < size/sizeof(TDataType); i++) { err = aMimeTypes.Append(ptr[i]); if (err) break; } buf.Close(); return err; }
/** Test the driver data flow path by loopback, i.e Transmit the data and receive same data back. It runs the device @ default configuration @param aLoopback Loopback mode as internal or external aTxData Transmit Data buffer aRxSize Receive data size */ void TestExDriver::TestConcurrentTxRx(TInt aLoopback, const TDesC8& aTxData, TInt aRxSize) { TInt r; TRequestStatus stat; iTest.Printf(_L("Test Concurrent Synchronous Requests - Tx/Rx\n")); // Open channel r=iLdd.Open(KUnit1); iTest(r==KErrNone); // Create a buffer that has to be filled and returned by the driver RBuf8 rxBuf; r=rxBuf.Create(aRxSize); iTest(r==KErrNone); r=iLdd.SetIntLoopback(aLoopback); iTest(r==KErrNone); TData TData(&iLdd,&aTxData,&iSem1); // Call ldd interface ReceiveData() API to get data to rxBuf RThread TransferThread; _LIT(KThreadName, "TestThread"); TInt ret = TransferThread.Create( KThreadName, // Thread name TransferTestThread, // Function to be called KDefaultStackSize, KHeapSize, KHeapSize, (TAny *)&TData ); iTest.Printf(_L("Receive Data\n")); TransferThread.Logon(stat); TransferThread.Resume(); iSem1.Signal(); r = iLdd.ReceiveData(rxBuf); // In case of zero length request if (aRxSize==0) { // Driver should return error immediately iTest(r!=KErrNone); TransferThread.Kill(KErrNone); TransferThread.Close(); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } // Print the receive data to display. // It automatically checks the Tx and Rx data. Fails if not matched. // TInt i; iTest.Printf(_L("Received Data of size (%d):"),rxBuf.Size()); for (i=0; i<rxBuf.Size(); i++) { iTest.Printf(_L("%c"),(rxBuf.Ptr())[i]); if ((TUint8)(rxBuf.Ptr())[i] != aTxData[i]) { iTest.Printf(_L("Transmit and Receive data do not match\n")); iTest(EFalse); } } iTest.Printf(_L("\n")); User::WaitForRequest(stat); TransferThread.Close(); // Free the receive buffer rxBuf.Close(); // Close channel iLdd.Close(); }
void CServerCrashDataSource::GetCodeSegmentsL( const TUint64 aTid, RCodeSegPointerList &aCodeSegList, TUint & aTotalCodeSegListDescSize ) { LOG_MSG2("->CServerCrashDataSource::GetCodeSegmentsL(aTid=%Lu)\n", aTid ); aCodeSegList.ResetAndDestroy(); aTotalCodeSegListDescSize = 0; TUint32 size = KMaxFileName; RBuf8 buffer; buffer.CreateL(KMaxFileName); CleanupClosePushL(buffer); DoGetListL( ECodeSegs, aTid, (TUint)-1, buffer, size ); LOG_MSG2( " DoGetListL( ECodeSegs ) returned buffer.Size()=0x%X\n", buffer.Size() ); TUint8* ptr = (TUint8*)buffer.Ptr(); const TUint8* ptrEnd = ptr + size; while(ptr < ptrEnd) { TCodeSegListEntry* entry = (TCodeSegListEntry*)ptr; LOG_MSG4( " entry->CodeBase=0x%X, CodeSize=0x%X, ConstDataSize=0x%X\n", entry->iCodeBase, entry->iCodeSize, entry->iConstDataSize ); LOG_MSG4( " InitDataBase=0x%X, InitDataSize=0x%X, UnintDataSize=0x%X\n", entry->iInitialisedDataBase, entry->iInitialisedDataSize, entry->iUninitialisedDataSize ); LOG_MSG3( " IsXip=0x%X, CodeSegType=0x%X\n", entry->iIsXip, entry->iCodeSegType ); TCodeSegInfo *codeSeg = new(ELeave) TCodeSegInfo; TPtr name(&(entry->iName[0]), entry->iNameLength, entry->iNameLength); codeSeg->iName = name; codeSeg->iType = entry->iCodeSegType; codeSeg->iXIP = entry->iIsXip; codeSeg->iCodeSize = entry->iCodeSize; codeSeg->iCodeRunAddr = entry->iCodeBase; if( codeSeg->iXIP ) { codeSeg->iCodeLoadAddr = codeSeg->iCodeRunAddr; } else { codeSeg->iCodeLoadAddr = 0; //TODO } codeSeg->iRoDataSize = entry->iConstDataSize; codeSeg->iRoDataRunAddr = entry->iCodeBase + entry->iCodeSize; if( codeSeg->iXIP ) { codeSeg->iRoDataLoadAddr = codeSeg->iRoDataRunAddr; } else { codeSeg->iRoDataLoadAddr = 0; //TODO } codeSeg->iDataSize = entry->iInitialisedDataSize + entry->iUninitialisedDataSize; codeSeg->iDataRunAddr = entry->iInitialisedDataBase; if( codeSeg->iXIP ) { codeSeg->iDataLoadAddr = codeSeg->iDataRunAddr; } else { codeSeg->iDataLoadAddr = 0; //TODO } TInt err = aCodeSegList.Append(codeSeg); if(err != KErrNone) { delete codeSeg; User::Leave(err); } aTotalCodeSegListDescSize += sizeof(TCodeSegInfo); ptr += Align4(entry->GetSize()); } CleanupStack::PopAndDestroy(&buffer); }
void CServerCrashDataSource::SetRegValuesL( const TUint64 aThreadId, RRegisterList &aRegisterList ) { LOG_MSG2("->CServerCrashDataSource::SetRegValuesL(aThreadId=%Lu)\n", aThreadId); TInt numberOfRegisters = aRegisterList.Count(); RBuf8 ids; ids.CreateL( numberOfRegisters * sizeof(TFunctionalityRegister) ); ids.CleanupClosePushL(); TInt totalByteSize = 0; // Keeps track of the number of bytes that we are requesting for( TInt i=0; i < numberOfRegisters; i++ ) { TRegisterInfo reg = (TRegisterInfo)( aRegisterList[i].iId ); // iSize = (0 == 1 byte); (3 == 8 bytes) TInt byteSize = (aRegisterList[i].iSize) << 1; totalByteSize += byteSize; ids.Append( reinterpret_cast<const TUint8*>(®), sizeof(TRegisterInfo) ); } RBuf8 registerValues; registerValues.CreateL( totalByteSize ); registerValues.CleanupClosePushL(); RBuf8 registerFlags; registerFlags.CreateL( numberOfRegisters ); registerFlags.CleanupClosePushL(); LOG_MSG("CServerCrashDataSource::SetRegValuesL - reading registers\n"); User::LeaveIfError(iSecSess.ReadRegisters( aThreadId, ids, registerValues, registerFlags )); // Now copy the values back to the array and mark the availability from the flags TUint8* valuePtr = (TUint8*) registerValues.Ptr(); for( TInt i=0; i < numberOfRegisters; i++ ) { TRegisterData & reg = aRegisterList[i]; switch( reg.iSize ) { case 0: reg.iValue8 = *((TUint8 *)valuePtr); valuePtr += 1; break; case 1: reg.iValue16 = *((TUint16 *)valuePtr); valuePtr += 2; break; case 2: reg.iValue32 = *((TUint32 *)valuePtr); valuePtr += 4; break; case 3: reg.iValue64 = *((TUint64 *)valuePtr); valuePtr += 8; break; } if( EValid == registerFlags[i] ) { reg.iAvailable = ETrue; } else { reg.iAvailable = EFalse; } } CleanupStack::PopAndDestroy(®isterFlags); CleanupStack::PopAndDestroy(®isterValues); CleanupStack::PopAndDestroy(&ids); }
// // LtkUtils::W32CrackL // loads the autometric logging engine, dlogev.dll, into wserv // enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc // EXPORT_C void LtkUtils::W32CrackL() { #ifndef FSHELL_WSERV_SUPPORT User::Leave(KErrNotSupported); #else // Check if P&S says it's already enabled, if so no need to do anything if (W32CrackIsEnabled()) return; _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini"); _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini"); _LIT(KLogEv, "LOG EV\r\n"); // Open z file RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); RFile file; User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead)); CleanupClosePushL(file); TInt size; User::LeaveIfError(file.Size(size)); RBuf8 buf; buf.CreateL(size + KLogEv().Size()); CleanupClosePushL(buf); User::LeaveIfError(file.Read(buf)); TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2); buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM TInt err = KErrNone; err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist if((err != KErrNone) && (err != KErrAlreadyExists)) { User::Leave(err); } User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite)); User::LeaveIfError(file.Write(buf)); CleanupStack::PopAndDestroy(2, &file); // file, buf err = RMemoryAccess::LoadDriver(); if ((err != KErrNone) && (err != KErrAlreadyExists)) { User::Leave(err); } RMemoryAccess memAccess; User::LeaveIfError(memAccess.Open()); CleanupClosePushL(memAccess); RWsSession ws; User::LeaveIfError(ws.Connect(fs)); CleanupClosePushL(ws); #ifdef __WINS__ // On wins the binary isn't renamed _LIT(KWservMatch, "wserv*.exe*"); #else _LIT(KWservMatch, "EwSrv.exe*"); #endif TFindProcess find(KWservMatch); TFullName name; User::LeaveIfError(find.Next(name)); RProcess wservProc; User::LeaveIfError(wservProc.Open(find)); if (wservProc.ExitType() != EExitPending) { // in case wserv kicks off the preferred implementation in a new process then kills itself // (is one retry enough or should we be looping here?) wservProc.Close(); User::LeaveIfError(find.Next(name)); User::LeaveIfError(wservProc.Open(find)); } CleanupClosePushL(wservProc); name = wservProc.FileName(); name[0] = 'c'; TPtrC8 narrowName = name.Collapse(); User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName)); // Now tell wserv to reload its wsini.ini and enable logging ws.LogCommand(RWsSession::ELoggingEnable); ws.Flush(); // cleanup CleanupStack::PopAndDestroy(4, &fs); #endif // FSHELL_WSERV_SUPPORT }
void CCmdBtraceout::DoRunL() { if (iStdin) { CTextBuffer* buffer = CTextBuffer::NewLC(512); Stdin().SetReadMode(RIoReadHandle::EOneOrMore); TBuf<256> buf; while (Stdin().Read(buf) == KErrNone) { buffer->AppendL(buf); } RBuf8 data; data.CreateL(buffer->Length()); data.Copy(buffer->Descriptor()); // This will collapse us back to real 8-bit data if (iTruncate) { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_2' (%u) and all following arguments"), iArg2); } BTraceFilteredN(iCategory, iSubcategory, iFilterUid, iArg1, data.Ptr(), data.Size()); } else { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_3' (%u)"), iArg3); } BTraceN(iCategory, iSubcategory, iArg1, iArg2, data.Ptr(), data.Size()); } } else { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(2)) { PrintWarning(_L("Ignoring 'arg_1' (%u) and all following arguments"), iArg1); } BTraceFilteredBig(iCategory, iSubcategory, iFilterUid, data.Ptr(), data.Size()); } else { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_2' (%u) and all following arguments"), iArg2); } BTraceBig(iCategory, iSubcategory, iArg1, data.Ptr(), data.Size()); } } data.Close(); CleanupStack::PopAndDestroy(buffer); } else { if (iArguments.IsPresent(4)) { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_3' (%u)"), iArg3); } BTraceFiltered12(iCategory, iSubcategory, iFilterUid, iArg1, iArg2); } else { BTrace12(iCategory, iSubcategory, iArg1, iArg2, iArg3); } } else if (iArguments.IsPresent(3)) { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered12(iCategory, iSubcategory, iFilterUid, iArg1, iArg2); } else { BTrace8(iCategory, iSubcategory, iArg1, iArg2); } } else if (iArguments.IsPresent(2)) { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered8(iCategory, iSubcategory, iFilterUid, iArg1); } else { BTrace4(iCategory, iSubcategory, iArg1); } } else { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered4(iCategory, iSubcategory, iFilterUid); } else { BTrace0(iCategory, iSubcategory); } } } }
/** Test the driver data flow path by loopback, i.e Transmit the data and receive same data back. It runs the device @ default configuration @param aLoopback Loopback mode as internal or external aTxData Transmit Data buffer aRxSize Receive data size */ void TestExDriver::TestConcurrentTxRx(TInt aLoopback, const TDesC8& aTxData, TInt aRxSize) { TInt r; // Request status object for transmit and receive. These object will be // used to read the status of asynchronous requests after the notification // of request completion // TRequestStatus txStatus; TRequestStatus rxStatus; // Timers and their respective status objects for Tx and Rx RTimer timerTx; RTimer timerRx; TRequestStatus timeStatusTx; TRequestStatus timeStatusRx; iTest.Printf(_L("Test Concurrent Asynchronous Requests - Tx/Rx\n")); // Open channel r=iLdd.Open(KUnit1); iTest(r==KErrNone); // Create a buffer that has to be filled and returned by the driver RBuf8 rxBuf; r=rxBuf.Create(aRxSize); iTest(r==KErrNone); r=iLdd.SetIntLoopback(aLoopback); iTest(r==KErrNone); // Create the timer that is relative to the thread r = timerTx.CreateLocal(); iTest(r==KErrNone); r = timerRx.CreateLocal(); iTest(r==KErrNone); // Trigger timerRx expiry after KTimeOutTxRx. The status should be pending timerRx.After(timeStatusRx,KTimeOutTxRx); iTest(timeStatusRx==KRequestPending); // Call ldd interface ReceiveData() API to get data to rxBuf r = iLdd.ReceiveData(rxStatus, rxBuf); // In case of zero length request if (aRxSize==0) { // Driver should return error immediately iTest(r!=KErrNone); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } else { // Asynchronous request should be pending, with request message // posted to driver successfully // iTest((r==KErrNone)&&(rxStatus.Int()==KRequestPending)); } // Trigger timerTx expiry after KTimeOutTxRx. The status should be pending timerTx.After(timeStatusTx,KTimeOutTxRx); iTest(timeStatusTx==KRequestPending); // Call ldd interface TransmitData() API test data descriptor as parameter r = iLdd.TransmitData(txStatus, aTxData); // In case of zero length request if (aTxData.Size()==0) { // Driver should return error immediately iTest(r!=KErrNone); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } else { // Asynchronous request should be pending, with request message // posted to driver successfully // iTest(r==KErrNone); } // Wait till the request is complete on rxStatus and txStatus. User thread // is blocked with this call, till it is notified about the request // completion. // if(txStatus.Int()==KRequestPending) User::WaitForRequest(txStatus,timeStatusTx); if(rxStatus.Int()==KRequestPending) User::WaitForRequest(rxStatus,timeStatusRx); // if transmit has occured correctly, the iTimeStatus will not be KErrNone, else // no transmit complete has occured and iTimer has expired iTest (timeStatusTx!=KErrNone); iTest (timeStatusRx!=KErrNone); // Cancel the iTimer request timerTx.Cancel(); timerRx.Cancel(); // txStatus holds the request completion. TRequestStatus::Int() returns the // completion code. It will be KErrNone in case of successful completion // r = txStatus.Int(); iTest((r==KErrNone)||(r==KErrTimedOut)); r = rxStatus.Int(); iTest((r==KErrNone)||(r==KErrTimedOut)); // Close the handle to the timerTx and timerRx timerTx.Close(); timerRx.Close(); // Print the recieve data to display and verify the data received manually. TInt i; iTest.Printf(_L("Received Data of size (%d):"),rxBuf.Size()); for (i=0;i<rxBuf.Size();i++) { iTest.Printf(_L("%c"),(TUint8*)(rxBuf.Ptr())[i]); if ((rxBuf.Ptr())[i] != aTxData[i]) { iTest.Printf(_L("Transmit and Receive data do not match\n")); iTest(EFalse); } } iTest.Printf(_L("\n")); // Free the receive buffer rxBuf.Close(); // Close channel iLdd.Close(); }