SMFCredMgrErrorCode CSmfCredMgrClientSymbian::signMessageL(QString Message,
		QString Key, QString& Signature, SmfSignatureMethod AlgorithmUsed)
	{
	SMFCredMgrErrorCode signError = SmfErrNone;
	TPtr msgPtr((qt_QString2HBufC(Message))->Des());
	TPtr keyPtr((qt_QString2HBufC(Key))->Des());

	CSmfSignParameters* signMsgParams = CSmfSignParameters::NewL(
			msgPtr.Collapse(), keyPtr.Collapse());
	CleanupStack::PushL(signMsgParams);

	CBufFlat* buf = CBufFlat::NewL(KMinBufSize);
	CleanupStack::PushL(buf);
	RBufWriteStream stream(*buf);
	CleanupClosePushL(stream);

	signMsgParams->ExternalizeL(stream);
	stream.CommitL();

	TPtr8 bufPtr = buf->Ptr(0);

	TIpcArgs args;
	args.Set(0, &bufPtr);

	HBufC8* msgBuf = HBufC8::NewL(KMaxSignedMsgLength);
	TPtr8 msgBufPtr(msgBuf->Des());
	CleanupStack::PushL(msgBuf);
	args.Set(1, &msgBufPtr);

	switch (AlgorithmUsed)
		{
		case ESMFRSAProtocol:
			{
			iSession.RequestService(ESmfRSASignMessage, args);
			}
			break;
		case ESMFHMACProtocol:
			{
			iSession.RequestService(ESmfHMACSHA1SignMessage, args);
			}
			break;
		default:
			{
			RDebug::Printf("Unsupported Algo:");
			return SmfErrBadParameter;
			}
		}

	TBuf<KMaxSignedMsgLength> signedMsg;
	signedMsg.Copy(msgBufPtr);

	Signature = qt_TDesC2QString(signedMsg);

	CleanupStack::Pop(msgBuf);
	CleanupStack::PopAndDestroy(&stream);
	CleanupStack::PopAndDestroy(buf);
	CleanupStack::PopAndDestroy(signMsgParams);

	return signError;
	}
Example #2
0
void MpiSlaveProxy::sendCommand(mpi::Command& cmd, std::shared_ptr<MpiOperatorContext>& ctx)
{
    if (!_connection) {
        throw (InvalidStateException(REL_FILE, __FUNCTION__, __LINE__)
               << "No connection to MPI slave");
    }

    // set command
    std::shared_ptr<scidb_msg::MpiSlaveCommand> cmdPtr(new scidb_msg::MpiSlaveCommand());
    cmdPtr->set_command(cmd.getCmd());

    // set args
    const std::vector<std::string>& args = cmd.getArgs();
    google::protobuf::RepeatedPtrField<std::string>* msgArgs = cmdPtr->mutable_args();
    assert(msgArgs);
    msgArgs->Reserve(args.size());
    for (std::vector<std::string>::const_iterator iter = args.begin(); iter != args.end(); ++iter) {
        cmdPtr->add_args(*iter);
    }
    // send to slave
    scidb::MessagePtr msgPtr(cmdPtr);
    boost::asio::const_buffer binary(NULL,0);
    try {
        scidb::sendAsyncClient(_connection, scidb::mtMpiSlaveCommand, msgPtr, binary);

    } catch (const scidb::SystemException& e) {
        LOG4CXX_ERROR(logger, "MpiSlaveProxy::sendCommand: "
                      << "FAILED to send MpiSlaveCommand to slave because: "
                      << e.what());
        throw;
    }
    LOG4CXX_DEBUG(logger, "MpiSlaveProxy::sendCommand: MpiSlaveCommand "
                  << cmd.toString() << " sent to slave");
}
// Show a simple Symbian Info win with Msg & exit
void FatalError(const char *msg) {
	TPtrC8 msgPtr((const TUint8 *)msg); 
	TBuf<512> msg16Bit;
	msg16Bit.Copy(msgPtr);
	CEikonEnv::Static()->InfoWinL(_L("ScummVM Fatal Error"), msg16Bit);
	
	if (g_system)
		g_system->quit();
}
// virtual
MessageHandler::SocketMessage *MessageHandler::getMessage(int clientKey)
{
  MessageHandler::SocketMessage *msgPtr(NULL);

  ResponseMessageMapType::iterator iter = responseMessageMap_.find(clientKey);
  if(iter != responseMessageMap_.end())
  {
    msgPtr = iter->second;
  }

  return msgPtr;
}
Example #5
0
void CTMessage::OnMessageReceived(const TWsEvent& aEvent, TInt& aMsgCount)
	{
	aMsgCount++;
	if(aMsgCount>MsgCountCheck)
		{
		return;
		}
	if (MESSAGES_READ*(aMsgCount/MESSAGES_READ)<aMsgCount)
		{
		return;
		}
	TPtr8 msgPtr(NULL,0);
	//TPtr16 msgPtr2(NULL,0);
	TUid uid;
	TInt retValue=TheClient->iWs.FetchMessage(uid, msgPtr, aEvent);
	TEST(retValue==KErrNone);
	//GroupWin()->FetchMessage(uid, msgPtr2);
	if(TestNeedsExtraCheck)
		{
		TEST(uid==(aMsgCount==1?UidAtFirstLocation:UidAtLastLocation));
		}
	TInt msgLength=(uid.iUid)&0xFFFFFF;
	TUint8 uidFactor=(TUint8)((uid.iUid&0xFF000000)>>24);
	TBool retVal = msgPtr.Length()==msgLength;
	TEST(retVal);
	if (!retVal)
		INFO_PRINTF3(_L("msgPtr.Length()==msgLength  - Expected: %d, Actual: %d"), msgLength, msgPtr.Length());

	TUint8 check=0;
	for(TInt index=0;index<msgLength;index++)
		{
		check=(TUint8)(check+uidFactor);
		retVal = msgPtr[index]==check;
		TEST(retVal);
		if (!retVal)
			INFO_PRINTF3(_L("msgPtr[index]==check  - Expected: %d, Actual: %d"), check, msgPtr[index]);

		}
	/*CTestBase::Test(msgPtr.Length()/2==msgPtr2.Length());
	TPtrC8 data2((const TUint8*) msgPtr2.Ptr(),msgPtr2.Size());
	CTestBase::Test(data2==msgPtr.Left(msgPtr2.Size()));*/
	User::Free((TAny *)msgPtr.Ptr());
	//User::Free((TAny *)msgPtr2.Ptr());
	}
Example #6
0
/**
Externalizes this drawsection to a message buffer to send over IPC.

@param aMsgBuf The message buffer to add this drawsection to.
*/
void CDrawSection::ExternalizeL(RWsGraphicMsgBuf& aMsgBuf)
	{
	const TInt length = sizeof(TRect)*2 + iSectionSegBuf->Size();
	TPtr8 msgPtr(NULL, 0);
	User::LeaveIfError(aMsgBuf.Append(KDrawSection, length, msgPtr));
	
	// Add drawRect to aMsgBuf
	const TPckgBuf<TRect> drawRect(iDrawRect);
	msgPtr.Append(drawRect);
	
	// Add boundingRect to aMsgBuf
	const TPckgBuf<TRect> boundingRect(iBoundingRect);
	msgPtr.Append(boundingRect);
	
	// Add drawcommands to aMsgBuf
	TInt count = 0;
	const TInt sectionSegBufSize = iSectionSegBuf->Size();
	while(count < sectionSegBufSize)
		{		
		TPtr8 ptr = iSectionSegBuf->Ptr(count);
		msgPtr.Append(ptr);
		count += ptr.Size();
		}	
	}
Example #7
0
/**
 Test delivery group messages in case when event queue is overflow
 */
void CTMessage::TestMessageQueueOverflowL()
	{
	const TInt numMaxMessages = 60;
	TInt numWasteMessages = 0;
	TInt numWgMessages = 5;

	TInt gotRealWasteMessages = 0;
	TInt gotRealWgMessages = 0;

	const TInt oneSecond = 1000000;
	const TInt allPossibleMessages = 500;

	RWsSession senderWsSession;
	RWindowGroup senderGroupWin;
	TInt sndrHanGrpWin = 7777;

	RWsSession receiverWsSession;
	RWindowGroup receiverGroupWin;
	TInt rcvrHanGrpWin = 8888;

	TRequestStatus testStatus;
	TRequestStatus timerStatus;
	TWsEvent wasteEvent;
	TWsEvent event;

	RTimer timer;
	timer.CreateLocal();
	CleanupClosePushL(timer);

	// Create sender WsSession and the window group
	User::LeaveIfError(senderWsSession.Connect());
	CleanupClosePushL(senderWsSession);

	senderGroupWin = RWindowGroup(senderWsSession);
	User::LeaveIfError(senderGroupWin.Construct(sndrHanGrpWin));
	CleanupClosePushL(senderGroupWin);

	// Create reciever WsSession and the window group
	User::LeaveIfError(receiverWsSession.Connect());
	CleanupClosePushL(receiverWsSession);

	receiverGroupWin = RWindowGroup(receiverWsSession);
	User::LeaveIfError(receiverGroupWin.Construct(rcvrHanGrpWin));
	CleanupClosePushL(receiverGroupWin);

	TInt err = KErrNone;

	// Send waste events to the receiver and overflow the event queue
	for (TInt ind = 0; ind < numMaxMessages; ind++)
		{
		wasteEvent.SetType(sndrHanGrpWin);
		err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent);
		if (err != KErrNone)
			{
			numWasteMessages = ind; // Real number waste messages that was sent
			break;
			}
		}

	// Send messages to the receiver
	for (TInt ind = 0; ind < numWgMessages; ind++)
		{
		TInt uidData = ind + sndrHanGrpWin;
		TPtr8 msg((unsigned char*) &uidData, sizeof(uidData));
		err = senderWsSession.SendMessageToWindowGroup(receiverGroupWin.Identifier(), TUid::Uid(uidData), msg);
		if (err != KErrNone)
			{
			LOG_MESSAGE2(_L("UnExpected Error Code = %d"),err);
			numWgMessages = ind; // Real number window group messages that was sent
			}
		}

	// Check and count sent messages 
	for (TInt ind = 0; ind < allPossibleMessages; ind++)
		{
		receiverWsSession.EventReady(&testStatus);
		timer.After(timerStatus, oneSecond);
		User::WaitForRequest(testStatus, timerStatus);
		if (testStatus == 0)
			{
			// Test incoming events
			receiverWsSession.GetEvent(event);
			if (event.Type() == sndrHanGrpWin)
				{
				++gotRealWasteMessages;
				}
			else if (event.Type() == EEventMessageReady)
				{
				if (gotRealWgMessages == 0)
					{
					for (TInt ind = 0; ind < numMaxMessages; ind++)
						{
						wasteEvent.SetType(sndrHanGrpWin);
						err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent);
						if (err == KErrNone)
							{
							++numWasteMessages;
							}
						else
							{
							break;
							}
						}
					}
				++gotRealWgMessages;
				TUid uid;
				TPtr8 msgPtr(NULL,0);
				err = receiverWsSession.FetchMessage(uid, msgPtr, event);
				User::Free((TAny *) msgPtr.Ptr());
				}
			// testStatus has been completed. Hence, Cancel the timer.
			timer.Cancel();
			User::WaitForRequest(timerStatus);
			}
		else
			{
			// Times out, cancel the event notification
			receiverWsSession.EventReadyCancel();
			User::WaitForRequest(testStatus);
			// All events were recieved
			break;
			}
		}

	LOG_MESSAGE3(_L("Got Waste message = %d expected =%d"),gotRealWasteMessages,numWasteMessages);
	LOG_MESSAGE3(_L("Got Group message = %d expected =%d"),gotRealWgMessages,numWgMessages);
	TEST(gotRealWasteMessages == numWasteMessages);
	TEST(gotRealWgMessages == numWgMessages);

	CleanupStack::PopAndDestroy(&receiverGroupWin);
	CleanupStack::PopAndDestroy(&receiverWsSession);
	CleanupStack::PopAndDestroy(&senderGroupWin);
	CleanupStack::PopAndDestroy(&senderWsSession);
	CleanupStack::PopAndDestroy(&timer);

	TheClient->iWs.Flush();

	}