int WaypointMessageHelper::readWaypointMessageForTarget (const void *pWaypointMsgPayload, uint32 ui32Offset, uint32 ui32TotalLen, PreviousMessageIds &previouMessagesSentToTargets, uint32 &ui32WaypointMsgPayloadLen) { ui32WaypointMsgPayloadLen = ui32TotalLen; BufferReader br (pWaypointMsgPayload, ui32TotalLen); br.setPosition (ui32Offset); uint32 ui32LatestMessageSentLen = 0; if (br.read32 (&ui32LatestMessageSentLen) < 0) { return -1; } ui32WaypointMsgPayloadLen -= 4; if (ui32LatestMessageSentLen > 0) { static const uint16 BUF_LEN = 1024; char buf[BUF_LEN]; if ((ui32LatestMessageSentLen + 1) > BUF_LEN) { return -2; } if (br.readBytes (buf, ui32LatestMessageSentLen) < 0) { return -3; } buf[ui32LatestMessageSentLen] = '\0'; previouMessagesSentToTargets = buf; ui32WaypointMsgPayloadLen -= ui32LatestMessageSentLen; } return 0; }
PtrLList<const char> * InformationPull::remoteSearchArrived (const void *pData, uint32 ui32DataLength, uint32 &ui32RcvdRemoteSeachQuery, const char *pszSenderNodeId) { // Read the message BufferReader br (pData, ui32DataLength); br.read32 (&ui32RcvdRemoteSeachQuery); uint16 ui16Len; br.read16 (&ui16Len); char *pszGroupName = new char[ui16Len+1]; br.readBytes (pszGroupName, ui16Len); pszGroupName[ui16Len] = '\0'; br.read16 (&ui16Len); char *pszQuery = new char[ui16Len+1]; br.readBytes (pszQuery, ui16Len); pszQuery[ui16Len] = '\0'; // Check the search seq id uint32 *pUI32PrevRcvdRemoteSeachQuery = _latestSearchIdRcvdByPeer.get (pszSenderNodeId); if (pUI32PrevRcvdRemoteSeachQuery == NULL) { pUI32PrevRcvdRemoteSeachQuery = new uint32; (*pUI32PrevRcvdRemoteSeachQuery) = ui32RcvdRemoteSeachQuery; _latestSearchIdRcvdByPeer.put (pszSenderNodeId, pUI32PrevRcvdRemoteSeachQuery); } else { if (SequentialArithmetic::lessThanOrEqual (ui32RcvdRemoteSeachQuery, (*pUI32PrevRcvdRemoteSeachQuery))) { // This is either a duplicate search or an old search. Either way // it must not be served! (Actually the "equal" case should never // happen). return NULL; } else { (*pUI32PrevRcvdRemoteSeachQuery) = ui32RcvdRemoteSeachQuery; } } // Get the IDs of the messages matching the query except the ones specified // in ppszFilters (because they have already been sent) char **ppszFilters = (char **) malloc (sizeof(char*) * 2); ppszFilters[0] = (char *) pszSenderNodeId; ppszFilters[1] = NULL; PtrLList<const char> *pRet = _pInformationStore->getMessageIDs (pszGroupName, pszQuery); ppszFilters[0] = NULL; delete ppszFilters; ppszFilters = NULL; return pRet; }