コード例 #1
0
void RPC_SYSFreeResultDataBuffer(ResultDataBufHandle_t dataBufHandle)
{
	ResultDataBuffer_t* dataBuf = (ResultDataBuffer_t*)dataBufHandle;
	
	_DBG_(RPC_TRACE_INFO("RPC_SYSFreeResultDataBuffer ref=%d", (dataBuf)?dataBuf->refCount:-1));
	if(dataBuf && dataBuf->refCount > 0)
	{
		--(dataBuf->refCount);
		if(dataBuf->refCount == 0)
	    {
		    /* Free up the memory allocated during deserialization of the pointers */
		    dataBuf->xdrs.x_op = XDR_FREE;
		    xdr_RPC_InternalMsg_t( &dataBuf->xdrs, &dataBuf->rsp );
		    xdr_destroy(&dataBuf->xdrs);
            capi2_free(dataBuf);
			// coverity[deref_after_free]: Dereferencing freed pointer "dataBuf"
			_DBG_(RPC_TRACE_INFO("RPC_SYSFreeResultDataBuffer ( FREE ) ref=%d", (dataBuf)?dataBuf->refCount:-1));
		}
	}
}
コード例 #2
0
ファイル: rpc_sys.c プロジェクト: emreharbutoglu/i9105Sammy
UInt8 GetClientIndex(ResultDataBuffer_t *pDataBuf, Boolean *isUnsolicited)
{
	RPC_Msg_t *pMsg = &(pDataBuf->rsp.rootMsg);
	/*coverity[var_decl], entry will be initialized in the function rpc_fast_lookup() below */
	RPC_InternalXdrInfo_t entry;
	bool_t ret = 0;
	UInt8 index;

	*isUnsolicited = FALSE;

	/*Check if message is unsolicited */
	if (pDataBuf->rsp.rootMsg.msgId != MSG_CAPI2_ACK_RSP) {
		ret =
		    rpc_fast_lookup((UInt16)pDataBuf->rsp.rootMsg.msgId,
				    &entry);
		if (ret) {
			*isUnsolicited =
			    (entry.
			     mask & RPC_XDR_INFO_MASK_UNSOLICITED) ? TRUE :
			    FALSE;

			_DBG_(RPC_TRACE_INFO
			      ("RPC GetClientIndex msgId=0x%x xdrClient=%d mask=%x unsol=%d",
			       pDataBuf->rsp.rootMsg.msgId, entry.clientIndex,
			       entry.mask, *isUnsolicited));
			/* *isUnsolicited = FALSE; */
		}
	}

	/*Lookup index on registered clients */
	index = gClientIDs[pMsg->clientID];

	if (index > 0 && index < MAX_RPC_CLIENTS)
		return index;

	index = 0;

	if (pDataBuf->rsp.rootMsg.msgId == MSG_CAPI2_ACK_RSP) {
		index = pDataBuf->rsp.clientIndex;
	} else {
		/*Lookup clientIndex based on XDR table registered client */
		if (ret && entry.clientIndex < MAX_RPC_CLIENTS)
			index = entry.clientIndex;
	}
	return index;
}
コード例 #3
0
Result_t RPC_SerializeMsg(RPC_InternalMsg_t* rpcMsg, char* stream, UInt32 streamLen, UInt32 *outLen)
{
	XDR xdrs;
	Result_t result = RESULT_OK;
	
	Boolean isValid = SYS_IsRegisteredClientID(rpcMsg->rootMsg.clientID);

	if(!isValid)
		_DBG_(RPC_TRACE_INFO("RPC_SYS_isValidClientID (Invalid)  %d", rpcMsg->rootMsg.clientID));

	//assert(isValid);

	if(DETAIL_LOG_ENABLED)
		xdrmem_create(&xdrs, stream, streamLen, log_buf, MAX_LOG_BUFFER_SIZE, XDR_ENCODE);
	else
		xdrmem_create(&xdrs, stream, streamLen, NULL, 0, XDR_ENCODE);

	result = (xdr_RPC_InternalMsg_t(&xdrs, rpcMsg)) ? RESULT_OK : RESULT_ERROR;

#ifdef DEVELOPMENT_RPC_XDR_DETAIL_LOG
			if(DETAIL_LOG_ENABLED)
			{
				if(rpcMsg->rootMsg.msgId != MSG_CAPI2_ACK_RSP && (xdrs.x_op == XDR_ENCODE || xdrs.x_op == XDR_DECODE))
				{
					if((strlen(log_buf)+3) < MAX_LOG_BUFFER_SIZE)
						strncat(log_buf,"}\r\n",3);
					_DBG_(Rpc_DebugOutputString(log_buf));
				}
			}
#endif

	*outLen = xdr_getpos(&xdrs);
	xdr_destroy(&xdrs);

	return(result);
}
コード例 #4
0
ファイル: rpc_sys.c プロジェクト: manoranjan2050/Compact
void RPC_DispatchMsg(ResultDataBuffer_t* pDataBuf)
{
	UInt8 clientIndex;
	Boolean isUnsolicited = FALSE;
	RPC_Msg_t* pMsg = &(pDataBuf->rsp.rootMsg);
	int i;
	
	pDataBuf->refCount = 1;//set

	//Handle Ack first
	if(pMsg->msgId == MSG_CAPI2_ACK_RSP)
	{
		RPC_Ack_t	*ackRsp = (RPC_Ack_t*)pMsg->dataBuf;
		clientIndex = GetClientIndex(pDataBuf, &isUnsolicited);
		
		if(gClientMap[clientIndex].ackCb)
		{
			gClientMap[clientIndex].ackCb(pMsg->tid, pMsg->clientID, ackRsp->ackResult, ackRsp->ackUsrData);
			RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
		}
	}
	else
	{
		clientIndex = GetClientIndex(pDataBuf, &isUnsolicited);

		if(pDataBuf->rsp.msgType == RPC_TYPE_REQUEST)
		{
			if(gClientMap[clientIndex].reqCb != NULL)
			{
				(gClientMap[clientIndex].reqCb)(pMsg, (ResultDataBufHandle_t)pDataBuf, gClientMap[clientIndex].userData);
			}
		}
		else //RPC_TYPE_RESPONSE
		{
			if(clientIndex > 0 && (pMsg->tid != 0 || pMsg->clientID != 0) && !(isUnsolicited))
			{
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Unicast msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				if(gClientMap[clientIndex].respCb != NULL)
				{
					(gClientMap[clientIndex].respCb)(pMsg, (ResultDataBufHandle_t)pDataBuf,gClientMap[clientIndex].userData);
				}
			}
			else if((pMsg->tid == 0 && pMsg->clientID == 0) || isUnsolicited)//unsolicited
			{
				UInt32 numClients = 0;
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast msgId=0x%x xdrClient=%d tid=%d cid=%d unsol=%d ", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				//Set the ref count first
				pDataBuf->refCount = 0;//reset
				for(i=1;i<=gClientIndex;i++)
				{
					if(gClientMap[i].respCb != NULL && (gClientLocalMap[i].notifyUnsolicited || clientIndex == i) )
						pDataBuf->refCount++;
				}
				
				numClients = pDataBuf->refCount;
				//Broadcast the message
				for(i=1;i<=gClientIndex;i++)
				{
					if(gClientMap[i].respCb != NULL && (gClientLocalMap[i].notifyUnsolicited || clientIndex == i) )
					{
						_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Client ( Notify ) msgId=0x%x index=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
						(gClientMap[i].respCb)(pMsg, (ResultDataBufHandle_t)pDataBuf,gClientMap[i].userData);
					}
					else
					{
						_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Client ( Skip ) msgId=0x%x index=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
					}

				}

				//No clients handle this message?
				if(numClients == 0)
				{
					_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Ignored msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
					
					pDataBuf->refCount = 1;
					RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
				}
			}
			else
			{
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg IGNORED msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
			}
		}//RPC_TYPE_RESPONSE
	}
}