Пример #1
0
void CSkypeProto::OnContactsSent(const ConversationRef &conversation, const MessageRef &message)
{
	SEString data;

	CMessage::TYPE messageType;
	message->GetPropType(messageType);

	uint timestamp;
	message->GetPropTimestamp(timestamp);

	CMessage::SENDING_STATUS status;
	message->GetPropSendingStatus(status);

	CParticipant::Refs participants;
	conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
	participants[0]->GetPropIdentity(data);
		
	CContact::Ref receiver;
	this->GetContact(data, receiver);

	MCONTACT hContact = this->AddContact(receiver);
	this->SendBroadcast(
		hContact,
		ACKTYPE_CONTACTS,
		status == CMessage::FAILED_TO_SEND ? ACKRESULT_FAILED : ACKRESULT_SUCCESS,
		(HANDLE)message->getOID(), 0);
}
Пример #2
0
void CSkypeProto::OnContactsReceived(const ConversationRef &conversation, const MessageRef &message)
{
	CContact::Refs contacts;
	message->GetContacts(contacts);

	uint timestamp;
	message->GetPropTimestamp(timestamp);

	CMessage::TYPE messageType;
	message->GetPropType(messageType);

	SEString data;
	message->GetPropAuthor(data);			
		
	CContact::Ref author;
	this->GetContact(data, author);

	MCONTACT hContact = this->AddContact(author);

	SEBinary guid;
	message->GetPropGuid(guid);
	ReadMessageParam param = { guid, messageType };

	PROTORECVEVENT pre = { 0 };
	pre.flags = PREF_UTF;
	pre.lParam = (LPARAM)&param;
	pre.timestamp = timestamp;

	int msgSize = 1;
	pre.szMessage = (char *)::mir_alloc(msgSize);
	pre.szMessage[0] = 0;

	int len = 0;
	char* pCur = &pre.szMessage[0];

	for (size_t i = 0; i < contacts.size(); i ++)
	{
		contacts[i]->GetIdentity(data);
		if ( ::lstrcmpi(mir_ptr<wchar_t>(::mir_utf8decodeW(data)), this->login) != 0)
			this->AddContact(contacts[i]);
	}

	char *text = ::mir_utf8encode(::Translate("Contacts received"));

	this->AddDBEvent(
		hContact,
		SKYPE_DB_EVENT_TYPE_CONTACTS,
		timestamp,
		PREF_UTF,
		(DWORD)::strlen(text) + 1,
		(PBYTE)text);
}
Пример #3
0
	virtual void send(MessageRef msg) {
		if (pipe == INVALID_HANDLE_VALUE) {
			return;
		}

		DWORD written = 0;
		int32_t size = msg->data_length();
		WriteFile(pipe, &size, 4, &written, NULL);
		// TODO check written == 4
		WriteFile(pipe, msg->data(), size, &written, NULL);
		// TODO check written == size
		msg->reset();
	}
Пример #4
0
WP::err MultiMailMessenger::postMessage(MessageRef message)
{
    lastParticipantIndex = -1;


    this->message = message;

//TODO set the uid at some point...
//info->setParticipantUid(targetContact->getAddress(), targetContact->getUid());

    // store message
    WP::err error = mailbox->storeMessage(message);
    if (error != WP::kOk)
        return error;
    error = mailbox->getDatabase()->commit();
    if (error != WP::kOk)
        return error;

    messageChannelInfo = message->getChannelInfo();

    // TODO: try to get all participant uids first (if missing)

    onSendResult(WP::kOk);

    return WP::kOk;
}
Пример #5
0
void CSkypeProto::OnContactsEvent(const ConversationRef &conversation, const MessageRef &message)
{
	SEString author;
	message->GetPropAuthor(author);
			
	if (::wcsicmp(mir_ptr<wchar_t>(::mir_utf8decodeW(author)), this->login) == 0)
		this->OnContactsSent(conversation, message);
	else
		this->OnContactsReceived(conversation, message);
}
Пример #6
0
void UserConversation::OnMessage(const MessageRef& message){

    Message::TYPE messageType;
    message->GetPropType(messageType);
    if(messageType==Message::POSTED_TEXT){
        SEIntList propIds;
        SEIntDict propValues;
        propIds.append(Message::P_AUTHOR);
        propIds.append(Message::P_BODY_XML);
        propValues = message->GetProps(propIds);   
    
        if(propValues[0]!="yourusername"){
        
            cout<<"Conversation with:"<<propValues[0]<<endl;
            cout<<"Text: "<<propValues[1]<<endl;
            //Message::Ref reply;
            //this->PostText("Have a reply",reply, false);
        }
    }
}
Пример #7
0
Poco::SharedPtr<MessageData> Util::dataFromMessage(const MessageRef &message)
{
    int messageType = message->GetProp(Message::P_TYPE).toInt();

    SEString author;
    SEString authorName;
    SEString bodyXmlString;
    unsigned int timeStamp;
    message->GetPropAuthor(author);
    message->GetPropAuthorDisplayname(authorName);
    message->GetPropBodyXml(bodyXmlString);
    message->GetPropTimestamp(timeStamp);

    Poco::SharedPtr<MessageData> data = new MessageData;
    data->author = author.data();
    data->authorDisplayname = authorName.data();
    data->body = bodyXmlString.data();
    data->timestamp = timeStamp;
    data->isEmote = (messageType == Message::POSTED_EMOTE);

    return data;
}
Пример #8
0
void MyConversation::OnMessage (const MessageRef &message)
{
  int messageType = message->GetProp(Message::P_TYPE).toInt();

  if (messageType == Message::POSTED_FILES)
  {  
    MyTransfer::Refs transferList;
    message->GetTransfers(transferList);
    fetch(transferList);

    // In case of incoming transfers, let's auto-accept them..
    Transfer::TYPE transferType;
    Transfer::STATUS transferStatus;

    for (uint i=0; i < transferList.size(); i++)
    {
      // To keep getting MyTransfer class events, we need to store the references
      globalTransferList->append(transferList[i]);

      // For incomings, we need to check for transfer status, just to be sure.
      // In some cases, a transfer can appear with STATUS == PLACEHOLDER
      // As such transfers cannot be accepted, we will need to just store
      // the reference to Transfer Object and then check for further
      // status changes in Transfer::OnChange
      transferList[i]->GetPropType(transferType);
      transferList[i]->GetPropStatus(transferStatus);
      if ( (transferType == Transfer::INCOMING) && (transferStatus == Transfer::NEW) )
      {
        transferList[i]->AutoAccept();
      };
    };

    SEString bodyXml;
    message->GetPropBodyXml(bodyXml);
    printf("File transfer msg BodyXML:\n%s\n", (const char*)bodyXml);
  };
};
Пример #9
0
MessageRef ReadZipFile(DataIO & readFrom, bool loadData)
{
   TCHECKPOINT;

   static const int NAME_BUF_LEN = 8*1024;  // names longer than 8KB are ridiculous anyway!
   char * nameBuf = newnothrow_array(char, NAME_BUF_LEN);
   if (nameBuf)
   {
      MessageRef ret = GetMessageFromPool();
      if (ret())
      {
         zlib_filefunc_def zdefs = {
            fopen_dataio_func,
            fread_dataio_func,
            fwrite_dataio_func,
            ftell_dataio_func,
            fseek_dataio_func,
            fclose_dataio_func,
            ferror_dataio_func,
            &readFrom
         };
         zipFile zf = unzOpen2(NULL, &zdefs);
         if (zf != NULL)
         {
            if (ReadZipFileAux(zf, *ret(), nameBuf, NAME_BUF_LEN, loadData) != B_NO_ERROR) ret.Reset();
            unzClose(zf);
         }
         else ret.Reset();  // failure!
      }
      delete [] nameBuf;
      return ret;
   }
   else WARN_OUT_OF_MEMORY;

   return MessageRef();
}
Пример #10
0
void EventStreamingSession::AddMessage(MessageRef message)
{
	if(m_messages.size() > 10000)
	{
		m_messages.pop_front();
	}

	IReportable *reportable = dynamic_cast<IReportable*>(message.get());
	if (!reportable) {
		return;
	}

	//For unknown reason, singlelineserialization the message can cause crash since the pointer somehow got modified somewhere else
	//This would lead to some pointed memory address become inaccessible
	//To avoid this, we create a cloned local pointer
	m_messages.push_back(reportable->Clone());
	m_semaphore.release();
}
Пример #11
0
void TapeMsg::HandleResponse(MessageRef responseRef) {
	CStdString logMsg;

	TapeResponse* tr = dynamic_cast<TapeResponse*>(responseRef.get());
	if (!tr) {
		LOG4CXX_WARN(LOG.messaging,"Ignoring wrong response type");
		return;
	}

	if(tr->m_deleteTape && this->m_stage.Equals("ready") )
	{
		CStdString tapeFilename = this->m_fileName;

		CStdString absoluteFilename = CONFIG.m_audioOutputPath + "/" + tapeFilename;
		if (ACE_OS::unlink((PCSTR)absoluteFilename) == 0)
		{
			FLOG_INFO(LOG.messaging,"deleted tape: %s", tapeFilename);
		}
		else
		{
			FLOG_DEBUG(LOG.messaging,"could not delete tape: %s ", tapeFilename);
		}

	}
	else if(tr->m_deleteTape && this->m_stage.Equals("start") && CONFIG.m_pauseRecordingOnRejectedStart == true)
	{
		CStdString orkUid = this->m_recId;
		CStdString empty;
		CapturePluginProxy::Singleton()->PauseCapture(empty, orkUid, empty);
	}
	else 
	{
		// Tape is wanted
		if(CONFIG.m_lookBackRecording == false && CONFIG.m_allowAutomaticRecording && this->m_stage.Equals("start"))
		{
			CStdString orkuid = "", nativecallid = "", side = "";
			CapturePluginProxy::Singleton()->StartCapture(this->m_localParty, orkuid, nativecallid, side);
			CapturePluginProxy::Singleton()->StartCapture(this->m_remoteParty, orkuid, nativecallid, side);
		}
	}

}
Пример #12
0
void
WUploadThread::TransferFileList(MessageRef msg)
{
	PRINT("WUploadThread::TransferFileList\n");

	if (msg())
	{

		if (fShutdownFlag && *fShutdownFlag)	// do we need to abort?
		{
			Reset();
			return;
		}

		if (gWin->IsScanning())
		{
			fSavedFileList = msg;
			if (!fBlocked)
			{
				SetLocallyQueued(true);
				SendQueuedNotification();
			}
			return;
		}

		QString user;

		if (GetInt32FromMessage(msg, "mm", fMungeMode) != B_OK)
			fMungeMode = WTransfer::MungeModeNone;

		GetStringFromMessage(msg, "beshare:FromSession", fRemoteSessionID);

		if (GetStringFromMessage(msg, "beshare:FromUserName", user) ==  B_OK)
		{
			if (!user.isEmpty() && (user != fRemoteSessionID))
				fRemoteUser = user;
		}
		if (fRemoteUser == QString::null)
		{
			fRemoteUser = GetUserName(fRemoteSessionID);
		}

		QString file;

		for (int i = 0; (GetStringFromMessage(msg, "files", i, file) == B_OK); i++)
		{
			MessageRef fileRef;

			if (fFileThread->FindFile(file, fileRef))
			{
				if (fileRef()) // <*****@*****.**> 20021023
				{
					// see if we need to add them
					int64 offset = 0L;
					ByteBufferRef hisDigest;
					uint32 numBytes = 0L;
					if (msg()->FindInt64("offsets", i, offset) == B_OK &&
						msg()->FindFlat("md5", i, hisDigest) == B_OK &&
						numBytes == MD5_DIGEST_SIZE)
					{
						uint8 myDigest[MD5_DIGEST_SIZE];
						uint64 readLen = 0;
						int64 onSuccessOffset = offset;

						for (uint32 j = 0; j < ARRAYITEMS(myDigest); j++)
							myDigest[j] = 'x';

						if ((msg()->FindInt64("numbytes", i, readLen) == B_OK) && (readLen > 0))
						{
							PRINT("\t\tULT: peer requested partial resume\n");
							int64 temp = readLen;
							readLen = offset - readLen; // readLen is now the seekTo value
							offset = temp;				// offset is now the numBytes value
						}

						// figure the path to our requested file
						QString file = MakeUploadPath(fileRef);

						// Notify window of our hashing
						WUploadEvent *hash = new WUploadEvent(WUploadEvent::FileHashing);
						if (hash)
						{
							hash->SetFile(SimplifyPath(file));
							SendReply(hash);
						}

						// Hash

						if (HashFileMD5(file, offset, readLen, NULL, myDigest, fShutdownFlag) == B_OK &&
							memcmp((const uint8*) hisDigest()->GetBuffer(), myDigest, sizeof(myDigest)) == 0)
						{
							// put this into our message ref
							fileRef.EnsureRefIsPrivate();
							fileRef()->AddInt64("secret:offset", (int64) onSuccessOffset);
						}
					}

					fUploads.AddTail(fileRef);
					fNames.AddTail(file);
				}
			}
		}

		msg()->GetInfo("files", NULL, &fNumFiles);

		fWaitingForUploadToFinish = false;
		SendQueuedNotification();

		// also send a message along to our GUI telling it what the first file is

		if (fUploads.IsEmpty())
		{
			PRINT("WUploadThread: No Files!!!\n");
			Reset();
			return;
		}

		if (IsLocallyQueued())
		{
			MessageRef fref;
			fUploads.GetItemAt(0, fref);
			if (fref())
			{
				QString filename = MakeUploadPath(fref);

				if (!filename.isEmpty())
				{
					// Check file size if is smaller than minimum size wanted for queue
					int64 filesize;
					if (fref()->FindInt64("beshare:File Size", filesize) == B_OK)
					{
						if (filesize < gWin->fSettings->GetMinQueuedSize())
						{
							SignalUpload();
							return;
						}
					}

					WUploadEvent *init = new WUploadEvent(WUploadEvent::Init);
					if (init)
					{
						init->SetFile(SimplifyPath(filename));
//						init->SetSession(fRemoteSessionID);
						SendReply(init);
					}
				}
			}
		}
		else
		{
			SignalUpload();
			return;
		}

	}
}
Пример #13
0
int EventStreamingServer::svc(void)
{
	ACE_Time_Value timeout;
	char buf[2048];
	CStdString logMsg;
	CStdString sessionId;
	int messagesSent = 0;

	ssize_t size = peer().recv(buf, 2040);

	if(size <= 5)
	{
		CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n");
		peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL);
		return 0;
	}

	try
	{
		int startUrlOffset = 5;
		char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP");

		if(!stopUrl)
		{
			throw (CStdString("Malformed http request"));
		}

		CStdString header;
		struct tm date = {0};
		time_t now = time(NULL);
		CStdString rfc822Date;

		ACE_OS::gmtime_r(&now, &date);
		rfc822Date.Format("Tue, %.2d Nov %.4d %.2d:%.2d:%.2d GMT", date.tm_mday, (date.tm_year+1900), date.tm_hour, date.tm_min, date.tm_sec);
		header.Format("HTTP/1.1 200 OK\r\nLast-Modified:%s\r\nContent-Type:text/plain\r\n\r\n", rfc822Date);
		peer().send(header, header.GetLength(), MSG_NOSIGNAL);

		time_t startTime = time(NULL);

		sessionId = EventStreamingSingleton::instance()->GetNewSessionId() + " -";
		logMsg.Format("%s Event streaming start", sessionId);
		LOG4CXX_INFO(s_log, logMsg);

		EventStreamingSessionRef session(new EventStreamingSession());
		EventStreamingSingleton::instance()->AddSession(session);

		int sendRes = 0;
		while(sendRes >= 0)
		{
			session->WaitForMessages();

			while(session->GetNumMessages() && sendRes >= 0)
			{
				MessageRef message;

				session->GetTapeMessage(message);
				if(message.get())
				{
					CStdString msgAsSingleLineString;
					msgAsSingleLineString = message->SerializeUrl() + "\r\n";

					sendRes = peer().send(msgAsSingleLineString, msgAsSingleLineString.GetLength(), MSG_NOSIGNAL);
					if(sendRes >= 0)
					{
						messagesSent += 1;
					}
				}
			}
		}

		EventStreamingSingleton::instance()->RemoveSession(session);
		logMsg.Format("%s Stream client stop - sent %d messages in %d sec", sessionId, messagesSent, (time(NULL) - startTime));
		LOG4CXX_INFO(s_log, logMsg);
	}
	catch (CStdString& e)
	{
		CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n");
		error = error + e + "\r\n";
		LOG4CXX_ERROR(s_log, e);
		peer().send(error, error.GetLength(), MSG_NOSIGNAL);
	}

	return 0;
}
int32
PlainTextMessageIOGateway ::
DoInputImplementation(AbstractGatewayMessageReceiver & receiver, uint32 maxBytes)
{
   TCHECKPOINT;

   int32 ret = 0;
   const int tempBufSize = 2048;
   char buf[tempBufSize];

   const uint32 mtuSize = GetMaximumPacketSize();
   if (mtuSize > 0)
   {
      // Packet-IO implementation
      char * pbuf  = buf;
      int pbufSize = tempBufSize;

      ByteBufferRef bigBuf;
      if (mtuSize > tempBufSize)
      {
         // Just in case our MTU size is too big for our on-stack buffer
         bigBuf = GetByteBufferFromPool(mtuSize);
         if (bigBuf())
         {
            pbuf     = (char *) bigBuf()->GetBuffer();
            pbufSize = bigBuf()->GetNumBytes();
         }
      }

      while(true)
      {
         IPAddressAndPort sourceIAP;
         const int32 bytesRead = GetPacketDataIO()->ReadFrom(pbuf, muscleMin(maxBytes, (uint32)(pbufSize-1)), sourceIAP);
              if (bytesRead < 0) return (ret > 0) ? ret : -1;
         else if (bytesRead > 0)
         {
            uint32 filteredBytesRead = bytesRead;
            FilterInputBuffer(pbuf, filteredBytesRead, pbufSize-1);
            ret += filteredBytesRead;
            pbuf[filteredBytesRead] = '\0';

            bool prevCharWasCarriageReturn = false;  // deliberately a local var, since UDP packets should be independent of each other
            MessageRef inMsg;  // demand-allocated
            int32 beginAt = 0;
            for (uint32 i=0; i<filteredBytesRead; i++)
            {
               char nextChar = pbuf[i];
               if ((nextChar == '\r')||(nextChar == '\n'))
               {
                  pbuf[i] = '\0';  // terminate the string here
                  if ((nextChar == '\r')||(prevCharWasCarriageReturn == false)) inMsg = AddIncomingText(inMsg, &pbuf[beginAt]);
                  beginAt = i+1;
               }
               prevCharWasCarriageReturn = (nextChar == '\r');
            }
            if (beginAt < (int32)filteredBytesRead) inMsg = AddIncomingText(inMsg, &pbuf[beginAt]);
            if (inMsg()) 
            {
               (void) inMsg()->AddFlat(PR_NAME_PACKET_REMOTE_LOCATION, sourceIAP);
               receiver.CallMessageReceivedFromGateway(inMsg);
               inMsg.Reset();
            }
            ret += bytesRead;
         }
         else return ret;
      }
   }
   else
   {
      // Stream-IO implementation
      const int32 bytesRead = GetDataIO()()->Read(buf, muscleMin(maxBytes, (uint32)(sizeof(buf)-1)));
      if (bytesRead < 0)
      {
         FlushInput(receiver);
         return -1;
      }
      if (bytesRead > 0)
      {
         uint32 filteredBytesRead = bytesRead;
         FilterInputBuffer(buf, filteredBytesRead, sizeof(buf)-1);
         ret += filteredBytesRead;
         buf[filteredBytesRead] = '\0';

         MessageRef inMsg;  // demand-allocated
         int32 beginAt = 0;
         for (uint32 i=0; i<filteredBytesRead; i++)
         {
            char nextChar = buf[i];
            if ((nextChar == '\r')||(nextChar == '\n'))
            {
               buf[i] = '\0';  // terminate the string here
               if ((nextChar == '\r')||(_prevCharWasCarriageReturn == false)) inMsg = AddIncomingText(inMsg, &buf[beginAt]);
               beginAt = i+1;
            }
            _prevCharWasCarriageReturn = (nextChar == '\r');
         }
         if (beginAt < (int32)filteredBytesRead)
         {
            if (_flushPartialIncomingLines) inMsg = AddIncomingText(inMsg, &buf[beginAt]);
                                       else _incomingText += &buf[beginAt];
         }
         if (inMsg()) receiver.CallMessageReceivedFromGateway(inMsg);
      }
   }
   return ret;
}
Пример #15
0
void WebSocketServer::onRead( Server* client, websocketpp::connection_hdl handle, MessageRef msg )
{
	mHandle = handle;
	mSignalRead( msg->get_payload() );
}