Ejemplo n.º 1
0
nsresult
nsImapMoveCopyMsgTxn::Init(nsIMsgFolder* srcFolder, nsTArray<nsMsgKey>* srcKeyArray,
                           const char* srcMsgIdString, nsIMsgFolder* dstFolder,
                           bool idsAreUids, bool isMove)
{
  m_srcMsgIdString = srcMsgIdString;
  m_idsAreUids = idsAreUids;
  m_isMove = isMove;
  m_srcFolder = do_GetWeakReference(srcFolder);
  m_dstFolder = do_GetWeakReference(dstFolder);
  m_srcKeyArray = *srcKeyArray;
  m_dupKeyArray = *srcKeyArray;
  nsCString uri;
  nsresult rv = srcFolder->GetURI(uri);
  nsCString protocolType(uri);
  protocolType.SetLength(protocolType.FindChar(':'));
  nsCOMPtr<nsIMsgDatabase> srcDB;
  rv = srcFolder->GetMsgDatabase(getter_AddRefs(srcDB));
  NS_ENSURE_SUCCESS(rv, rv);
  uint32_t i, count = m_srcKeyArray.Length();
  nsCOMPtr<nsIMsgDBHdr> srcHdr;
  nsCOMPtr<nsIMsgDBHdr> copySrcHdr;
  nsCString messageId;

  for (i = 0; i < count; i++)
  {
    nsMsgKey pseudoKey;
    rv = srcDB->GetMsgHdrForKey(m_srcKeyArray[i],
      getter_AddRefs(srcHdr));
    if (NS_SUCCEEDED(rv))
    {
      // ** jt -- only do this for mailbox protocol
      if (MsgLowerCaseEqualsLiteral(protocolType, "mailbox"))
      {
        m_srcIsPop3 = true;
        uint32_t msgSize;
        rv = srcHdr->GetMessageSize(&msgSize);
        if (NS_SUCCEEDED(rv))
          m_srcSizeArray.AppendElement(msgSize);
        if (isMove)
        {
          srcDB->GetNextPseudoMsgKey(&pseudoKey);
          pseudoKey--;
          m_dupKeyArray[i] = pseudoKey;
          rv = srcDB->CopyHdrFromExistingHdr(pseudoKey, srcHdr, false,
                                             getter_AddRefs(copySrcHdr));
          if (NS_SUCCEEDED(rv)) 
            m_srcHdrs.AppendObject(copySrcHdr);
        }
      }
      srcHdr->GetMessageId(getter_Copies(messageId));
      m_srcMessageIds.AppendElement(messageId);
    }
  }
  return nsMsgTxn::Init();
}
Ejemplo n.º 2
0
bool J2534DiagInterface::write(std::vector<char> buffer)
{
	if (_j2534 && _connected)
	{
		long ret = 0;
		// Setup message:
		PASSTHRU_MSG tx_msg;
		memset(&tx_msg, 0, sizeof(tx_msg));
		if (protocolType() == AbstractDiagInterface::protocol_SSM2_ISO14230)
		{ 
			tx_msg.ProtocolID = ISO9141;
		}
		else if (protocolType() == AbstractDiagInterface::protocol_SSM2_ISO15765)
		{
			tx_msg.ProtocolID = ISO15765;
			tx_msg.TxFlags = ISO15765_FRAME_PAD;
		}
		else
			return false;
		for (unsigned int k=0; k<buffer.size(); k++)
			tx_msg.Data[k] = buffer[k];
		tx_msg.DataSize = buffer.size();
		unsigned long txNumMsgs = 1;
		unsigned long timeout = 1000;	// wait until message has been transmitted
		// Send message:
		ret = _j2534->PassThruWriteMsgs(_ChannelID, &tx_msg, &txNumMsgs, timeout);
		if (STATUS_NOERROR == ret)
			return true;
		else
		{
#ifdef __FSSM_DEBUG__
			printErrorDescription("PassThruWriteMsgs() failed: ", ret);
#endif
			return false;
		}
	}
	else
		return false;
}
Ejemplo n.º 3
0
bool J2534DiagInterface::write(std::vector<char> buffer)
{
	if (_j2534 && _connected)
	{
		long ret = 0;
		// Setup message:
		PASSTHRU_MSG tx_msg;
		memset(&tx_msg, 0, sizeof(tx_msg));
		switch(protocolType()) {
		case AbstractDiagInterface::protocol_SSM2_ISO14230:
			tx_msg.ProtocolID = ISO9141;
			break;
		case AbstractDiagInterface::protocol_SSM2_ISO15765:
			tx_msg.ProtocolID = ISO15765;
			tx_msg.TxFlags = ISO15765_FRAME_PAD;
			break;
		default:
			return false;
		}
		std::copy(buffer.begin(), buffer.end(), tx_msg.Data);
		tx_msg.DataSize = buffer.size();
		unsigned long txNumMsgs = 1;
		unsigned long timeout = 1000;	// wait until message has been transmitted
		// Send message:
		ret = _j2534->PassThruWriteMsgs(_ChannelID, &tx_msg, &txNumMsgs, timeout);
		if (STATUS_NOERROR == ret)
			return true;
		else
		{
#ifdef __FSSM_DEBUG__
			printErrorDescription("PassThruWriteMsgs() failed: ", ret);
#endif
			return false;
		}
	}
	else
		return false;
}
Ejemplo n.º 4
0
nsresult
nsImapMoveCopyMsgTxn::Init(nsIMsgFolder* srcFolder, nsTArray<nsMsgKey>* srcKeyArray, 
                           const char* srcMsgIdString, nsIMsgFolder* dstFolder,
                           PRBool idsAreUids, PRBool isMove,
                           nsIEventTarget* eventTarget)
{
  nsresult rv;
  m_srcHdrs = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
  m_srcMsgIdString = srcMsgIdString;
  m_idsAreUids = idsAreUids;
  m_isMove = isMove;
  m_srcFolder = do_GetWeakReference(srcFolder);
  m_dstFolder = do_GetWeakReference(dstFolder);
  m_eventTarget = eventTarget;
  m_srcKeyArray = *srcKeyArray;
  m_dupKeyArray = *srcKeyArray;
  nsCString uri;
  rv = srcFolder->GetURI(uri);
  nsCString protocolType(uri);
  protocolType.SetLength(protocolType.FindChar(':'));
  nsCOMPtr<nsIMsgDatabase> srcDB;
  rv = srcFolder->GetMsgDatabase(getter_AddRefs(srcDB));
  NS_ENSURE_SUCCESS(rv, rv);
  PRUint32 i, count = m_srcKeyArray.Length();
  nsCOMPtr<nsIMsgDBHdr> srcHdr;
  nsCOMPtr<nsIMsgDBHdr> copySrcHdr;
  nsCString messageId;

  for (i = 0; i < count; i++)
  {
    nsMsgKey pseudoKey;
    rv = srcDB->GetMsgHdrForKey(m_srcKeyArray[i],
      getter_AddRefs(srcHdr));
    if (NS_SUCCEEDED(rv))
    {
      // ** jt -- only do this for mailbox protocol
      if (protocolType.LowerCaseEqualsLiteral("mailbox"))
      {
        m_srcIsPop3 = PR_TRUE;
        PRUint32 msgSize;
        rv = srcHdr->GetMessageSize(&msgSize);
        if (NS_SUCCEEDED(rv))
          m_srcSizeArray.AppendElement(msgSize);
        if (isMove)
        {
          srcDB->GetNextPseudoMsgKey(&pseudoKey);
          pseudoKey--;
          m_dupKeyArray[i] = pseudoKey;
          rv = srcDB->CopyHdrFromExistingHdr(pseudoKey, srcHdr, PR_FALSE,
                                             getter_AddRefs(copySrcHdr));
          if (NS_SUCCEEDED(rv)) 
          {
            nsCOMPtr<nsISupports> supports = do_QueryInterface(copySrcHdr);
            m_srcHdrs->AppendElement(supports);
          }
        }
      }
      srcHdr->GetMessageId(getter_Copies(messageId));
      m_srcMessageIds.AppendElement(messageId);
    }
  }
  return nsMsgTxn::Init();
}
Ejemplo n.º 5
0
bool J2534DiagInterface::read(std::vector<char> *buffer)
{
	if (_j2534 && _connected)
	{
		long ret = 0;
		// Setup message-container:
		PASSTHRU_MSG rx_msg;
		memset(&rx_msg, 0, sizeof(rx_msg));
		if (protocolType() == AbstractDiagInterface::protocol_SSM2_ISO14230)
		{
			rx_msg.ProtocolID = ISO9141;
		}
		else if (protocolType() == AbstractDiagInterface::protocol_SSM2_ISO15765)
		{
			rx_msg.ProtocolID = ISO15765;
		}
		else
			return false;
		unsigned long rxNumMsgs = 1;
		unsigned long timeout = 0;	// return immediately
		// Read all available messages:
		do
		{
			ret = _j2534->PassThruReadMsgs(_ChannelID, &rx_msg, &rxNumMsgs, timeout);
			if ((STATUS_NOERROR == ret) && rxNumMsgs)
			{
#ifdef __FSSM_DEBUG__
				std::cout << "PassThruReadMsgs(): received J2534-message with protocol id 0x" << std::hex << rx_msg.ProtocolID
					<< ", rx status 0x" << rx_msg.RxStatus << ", extra data index " << std::dec << rx_msg.ExtraDataIndex << ":\n"
					<< libFSSM::StrToMultiLineHexstr(rx_msg.Data, rx_msg.DataSize);
#endif
				if (rx_msg.RxStatus & TX_MSG_TYPE)
				{
#ifdef __FSSM_DEBUG__
					if (rx_msg.RxStatus & TX_DONE)	// SAE J2534-1 (dec 2004): ISO-15765 only
					{
						std::cout << "=> message is transmit confirmation message\n";
						continue;
					}
					else
						std::cout << "=> message is loopback message\n";
#endif
				}
				else
				{
					if (rx_msg.RxStatus & START_OF_MESSAGE)
					{
						/* NOTE:
						 * - incoming (multi-frame) msg transfer has commenced (ISO-15765) /
						 *   first byte of an incoming message has been received (ISO-9141 / ISO-14230)
						 * - ISO-15765: message contains CAN-ID only                                   */
#ifdef __FSSM_DEBUG__
						std::cout << "=> message indicates that an incoming message transfer has commenced.\n";
#endif
						continue;
					}
					if ((protocolType() == protocol_SSM2_ISO15765) && (rx_msg.RxStatus & ISO15765_PADDING_ERROR))
					{
						// NOTE: ISO-15765 CAN frame was received with less than 8 data bytes
#ifdef __FSSM_DEBUG__
						std::cout << "=> message indicates ISO15765 padding error.\n";
#endif
						continue;
					}
					// NOTE: all other flags do not affect the transferred data or are not defined for the ISO-protocols
				}
				// Extract data:
				if (rx_msg.DataSize > 0)
				{
#ifdef __FSSM_DEBUG__
					if ((rx_msg.ExtraDataIndex == 0) && (_j2534->libraryAPIversion() == J2534_API_version::v0404))
					{
						std::cout << "WARNING: ExtraDataIndex is 0, which should be the case only for pure status messages !\n";
					}
					else if (rx_msg.ExtraDataIndex < rx_msg.DataSize)
					{
						if ((_j2534->libraryAPIversion() == J2534_API_version::v0404) || (protocolType() != protocol_SSM2_ISO14230) ||
							((protocolType() == protocol_SSM2_ISO14230) && (rx_msg.ExtraDataIndex < (rx_msg.DataSize - 1))))
							std::cout << "WARNING: ExtraDataIndex is smaller than expected !\n";
						/* NOTE:
						 * - 04.04-API: (SAE-J2534-1, dec 2004): ExtraDataIndex only used with J1850 PWM
						 * - 02.02-API: (SAE-J2534, feb 2002):   ExtraDataIndex also used with J1850 VPW, ISO-9141, ISO-14230 */
					}
#endif
					buffer->reserve(rx_msg.DataSize);
					buffer->assign(rx_msg.Data, rx_msg.Data + rx_msg.DataSize);
				}
			}
		} while ((STATUS_NOERROR == ret) && rxNumMsgs);
		if ((STATUS_NOERROR == ret) || (ERR_BUFFER_EMPTY == ret))
			return true;
#ifdef __FSSM_DEBUG__
		else
			printErrorDescription("PassThruReadMsgs() failed: ", ret);
#endif
	}
	return false;
}