コード例 #1
0
// Handles an incoming message (from the message queue).
UtlBoolean SipClientWriteBuffer::handleMessage(OsMsg& eventMessage)
{
   UtlBoolean messageProcessed = FALSE;

   int msgType = eventMessage.getMsgType();
   int msgSubType = eventMessage.getMsgSubType();

   if (msgType == OsMsg::OS_SHUTDOWN)
   {
      // When shutting down, have to return all queued outgoing messages
      // with transport errors.
      emptyBuffer(TRUE);

      // Continue with shutdown processing.
      messageProcessed = FALSE;
   }
   else if (msgType == OsMsg::OS_EVENT
           &&  (msgSubType == SipClientSendMsg::SIP_CLIENT_SEND
             || msgSubType == SipClientSendMsg::SIP_CLIENT_SEND_KEEP_ALIVE))
   {
      // Queued SIP message to send - normal path.
      if (msgSubType == SipClientSendMsg::SIP_CLIENT_SEND)
      {
          // Insert the SIP message into the queue, detaching it from
          // the incoming eventMessage.
          SipClientSendMsg* sendMsg =
             dynamic_cast <SipClientSendMsg*> (&eventMessage);
          if (sendMsg)
          {
             insertMessage(sendMsg->detachMessage());
             messageProcessed = TRUE;
          }
          else
          {
             Os::Logger::instance().log(FAC_SIP, PRI_CRIT,
                           "SipClientWriteBuffer[%s]::handleMessage "
                           "message is not a SipClientSendMsg",
                           mName.data());
          }
      }
      else // send Keep Alive
      {
          Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                        "SipClientWriteBuffer[%s]::handleMessage send TCP keep-alive CR-LF response",
                        mName.data());
          UtlString* pKeepAlive;
          pKeepAlive = new UtlString("\r\n");
          insertMessage(pKeepAlive);
          messageProcessed = TRUE;
      }

      // Write what we can.
      writeMore();

      // sendMsg will be deleted by ::run(), as usual.
      // Its destructor will free any storage owned by it.
   }

   return (messageProcessed);
}
コード例 #2
0
bool MyXmppClient::sendMyMessage(QString bareJid, QString resource, QString msgBody) //Q_INVOKABLE
{
    if (msgBody == "" || m_stateConnect != Connected) return false; // if message is empty or user not connected - BREAK

    QXmppMessage xmppMsg;

    QString jid_from = bareJid;
    if( resource == "" ) jid_from += "/resource"; else jid_from += "/" + resource;

    xmppMsg.setTo( jid_from );
    QString jid_to = m_myjid + "/" + xmppClient->configuration().resource();
    xmppMsg.setFrom( jid_to );

    xmppMsg.setBody( msgBody );

    xmppMsg.setState( QXmppMessage::Active );

    xmppClient->sendPacket( xmppMsg );

    this->messageReceivedSlot( xmppMsg );

    emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.to()),msgBody,QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),1);

    return true;
}
コード例 #3
0
ファイル: chatareawidget.cpp プロジェクト: rokups/qTox
void ChatAreaWidget::insertMessagesTop(QList<ChatActionPtr> &list)
{
    std::reverse(list.begin(), list.end());

    for (ChatActionPtr it : list)
    {
        insertMessage(it, QTextCursor::Start);
    }

    empty = false;
}
コード例 #4
0
void MyXmppClient::messageReceivedSlot( const QXmppMessage &xmppMsg )
{
    QString bareJid_from = MyXmppClient::getBareJidByJid( xmppMsg.from() );
    QString bareJid_to = MyXmppClient::getBareJidByJid( xmppMsg.to() );

    if( xmppMsg.state() == QXmppMessage::Active ) qDebug() << "Msg state is QXmppMessage::Active";
    else if( xmppMsg.state() == QXmppMessage::Inactive ) qDebug() << "Msg state is QXmppMessage::Inactive";
    else if( xmppMsg.state() == QXmppMessage::Gone ) qDebug() << "Msg state is QXmppMessage::Gone";
    else if( xmppMsg.state() == QXmppMessage::Composing ) {
        if (bareJid_from != "") {
            m_flTyping = true;
            emit typingChanged(m_accountId,bareJid_from, true);
            qDebug() << bareJid_from << " is composing.";
        }
    }
    else if( xmppMsg.state() == QXmppMessage::Paused ) {
        if (bareJid_from != "") {
            m_flTyping = false;
            emit typingChanged(m_accountId,bareJid_from, false);
            qDebug() << bareJid_from << " paused.";
        }
    } else {
        if( xmppMsg.isAttentionRequested() )
        {
            //qDebug() << "ZZZ: attentionRequest !!! from:" <<xmppMsg.from();
            //msgWrapper->attention( bareJid_from, false );
        }
        qDebug() << "MessageWrapper::messageReceived(): xmppMsg.state():" << xmppMsg.state();
    }
    if ( !( xmppMsg.body().isEmpty() || xmppMsg.body().isNull() || bareJid_from == m_myjid ) ) {
        m_bareJidLastMessage = getBareJidByJid(xmppMsg.from());
        m_resourceLastMessage = getResourceByJid(xmppMsg.from());

        this->openChat( bareJid_from );

        RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid_from );
        if( item != 0 ) { int cnt = item->unreadMsg(); item->setUnreadMsg( ++cnt ); } else {
          RosterItemModel *itemModel = new RosterItemModel( );
          itemModel->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) );
          itemModel->setContactName( bareJid_from );
          itemModel->setJid( bareJid_from );
          itemModel->setUnreadMsg( 1 );
          itemModel->setStatusText( "");
          cachedRoster->append(itemModel);
          itemModel = 0;
          delete itemModel;
        }
        item = 0; delete item;

        emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.from()),xmppMsg.body(),QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),0);
    }
}
コード例 #5
0
void QtChatHistoryWidget::insertTranslatedMessage(const QString & contactId, const QString & senderName,const QString & protocolName, const QString & message, const QString & translatedMessage, const QTime & time, const QDate & date) {
	
	// Prepare message
	QString htmlOriginalMessage = QtChatUtils::decodeMessage(message);

	QString htmlTranslatedMessage = QtChatUtils::decodeMessage(translatedMessage);


	

	QString translatedHTML  =  QString("<div style=\"display:inline-block\"><div onclick=\"document.getElementById('%1').style.display = (document.getElementById('%1').style.display == 'none') ? 'block' : 'none'\">%2</div><div id=\"%1\" style=\"display:none\" onclick=\"document.getElementById('%1').style.display = (document.getElementById('%1').style.display == 'none') ? 'block' : 'none'\">%3</div></div>").arg(QUuid::createUuid().toString()).arg(htmlOriginalMessage).arg(htmlTranslatedMessage);
	insertMessage(contactId,senderName,protocolName,translatedHTML,time,date);
	
}
コード例 #6
0
ファイル: Chat.cpp プロジェクト: 8102/QNetSoul
void    Chat::sendMessage(void)
{
  Q_ASSERT(this->_network);

  QString message = this->inputTextEdit->toPlainText();
  if (message.length() == 0) return;

#ifndef QT_NO_DEBUG
  qDebug() << "[Chat::sendMessage] Message:" << message;
#endif

  message.replace("\n", "<br />");
  insertMessage(this->_options->loginLineEdit->text(),
                message, QColor(32, 74, 135));
  this->_network->transmitMsg(this->_login, this->_location, message);
  this->inputTextEdit->clear();
}
コード例 #7
0
ファイル: chatareawidget.cpp プロジェクト: rokups/qTox
void ChatAreaWidget::clearChatArea()
{
    QList<ChatActionPtr> newMsgs;
    for (ChatActionPtr message : messages)
    {
        if (message->isInteractive())
        {
            newMsgs.append(message);
        }
    }
    messages.clear();
    this->clear();
    empty = true;

    for (ChatActionPtr message : newMsgs)
    {
        insertMessage(message);
    }
}
コード例 #8
0
void serverMessage(std::string command, std::string option, std::string data, IClientSocket *socket)
{
	//	Server command: client attempts a connection
	if(command == "newClient"){
		std::string idcode = idstring(socket);
		
		if(findUser(data) == true){
			remoteMessage("/error,userFound",socket);
		}else{
			//	Inform the client connection is accepted on server
			remoteMessage("/accepted,"+idcode,socket);
			//	Inform all clients to show user as connected
			broadcastMessage("/userConnect,"+data+":"+idcode, socket);
			
			//	Now send a list of current users to the client you just accepted
			std::string token,userlist = getUserlist();

			for(size_t pos = userlist.find(";");pos != std::string::npos;pos = userlist.find(";")){
				token = userlist.substr(0,pos);
				userlist = userlist.substr(pos+1);
				
				size_t sep = token.find(",");
				std::string user = token.substr(0,sep);
				std::string id = token.substr(sep+1);
				
				remoteMessage("/userConnect,"+user+":"+id,socket);
			}
		}
	}
	
	if(command == "info")
	{
		if(data == "listening")		data = "Listening for clients";
		if(data == "serverStart")	data = "Server started";
		if(data == "serverStop")	data = "Server stopped, all clients disconnected";
		if(data == "newClient")		data = "incoming connection from client";
		
		
		insertMessage("info",data);
	}
}
コード例 #9
0
ファイル: Chat.cpp プロジェクト: 8102/QNetSoul
void    Chat::autoReply(const int currentStatus)
{
  Q_ASSERT(this->_network);

  // No autoReply if you are online...
  if (currentStatus == 0) return;
  // No autoReply for yourself :)
  if (this->_options->loginLineEdit->text() == this->_login) return;

  const QString autoReplyMsg =
    this->_options->chatWidget->getReply(currentStatus);
  if (autoReplyMsg.isEmpty() == false)
    {
      // Fetch self login
      insertMessage(this->_options->loginLineEdit->text(),
                    autoReplyMsg, QColor(32, 74, 135));
      this->_network->transmitMsg(this->_login,
                                  this->_location,
                                  autoReplyMsg);
    }
}
コード例 #10
0
ファイル: exceptions.c プロジェクト: alainrk/AmiKaya11
/**********************************************************************
														SEND

	Invia un messaggio come richiesto dal sender al destinatario
	specificato nel registro a1 (receiver), col payload specificato
	al registro	a2 (payload).
	Operazione NON BLOCCANTE.

**********************************************************************/
int send (tcb_t *sender, tcb_t *target, U32 payload){

	msg_t *msg;
	tcb_t *_sender_;

	/* Protezione SSI */
	if (sender == SSI_tcb)
		_sender_ = (tcb_t *)MAGIC_SSI;
	else 
		_sender_ = sender;

	/* Destinatario in ready_queue o thread corrente */
	if ( ((thereIsThread(&ready_queue, target)) != NULL ) || (current_thread == target) ) {
		if ((msg = allocMsg()) == NULL) PANIC();
		/* Creazione e compilazione messaggio */

		msg->m_sender = _sender_;
		msg->m_message = payload;

		/* Priorità allo Pseudo Clock Tick -> Messaggio in testa */
		if (_sender_ == (tcb_t*)BUS_INTERVALTIMER)
			pushMessage(&(target->t_inbox), msg);
		/* Trattamento normale -> Messaggio in coda */
		else insertMessage(&(target->t_inbox), msg);

		return (MSGGOOD);
	}
	
	/* Destinatario in wait_queue */
	else if ((thereIsThread(&wait_queue, target)) != NULL ) {

		/* 
				Se sta aspettando un messaggio da questo thread 
				o da chiunque sveglio il thread dest togliendolo 
				dalla wait_queue e lo inserisco nella ready_queue
				passandogli il payload dove mi aveva richiesto e 
				che avevo salvato nel TCB nel	campo "reply".
		*/
		if ((target->waiting_for == _sender_) || (target->waiting_for == ANYMESSAGE)) {
			*(target->reply) = payload;

			/* Risveglio il thread */
			insertThread(&ready_queue, outThread(&wait_queue, target));

			/* Risettaggio campi per message passing */
			target->waiting_for = (tcb_t *)-1;
			target->reply = (U32 *)-1;

			/* Decremento soft block count se caso SSI e restituisco sender al destinatario */
			if (_sender_ == SSI_tcb)
				soft_block_count--;

			target->t_state.reg_v0 = (U32)_sender_;
			
			return (MSGGOOD);
		}

		/* Destinatario momentaneamente in attesa di un altro mittente */
		else {
			/* Tutto come sopra */
			if ((msg = allocMsg()) == NULL) PANIC();

			msg->m_sender = _sender_;
			msg->m_message = payload;

			if (sender == (tcb_t *)BUS_INTERVALTIMER)
				pushMessage(&(target->t_inbox), msg);

			else insertMessage(&(target->t_inbox), msg);

			return (MSGGOOD);
		}

	}

	/* Nessuno dei casi precedenti --> potrebbe essere stato terminato il thread */
	return (MSGNOGOOD);
	
}
コード例 #11
0
ファイル: EdoChatWindow.cpp プロジェクト: orisha85/edoapp
void EdoChatWindowGroup::insertMessage (MessageType messageType, const String &messageText, const String &messageAuthor, const bool showTimestamp)
{
	EdoChatWindowMessage *m = new EdoChatWindowMessage(messageType, owner, messageText, messageAuthor, showTimestamp);
	insertMessage(m);
}
コード例 #12
0
/// Message handling routines
long MessageHandler::updateMessage(const Message &msg)
{
    long messageid = -1;
    long translationid = -1;
    long params = -1;
    //msg.print();

    if(msg.getString() == "" || msg.getClass() == "") {
        LOG4CXX_ERROR(narratorMsgHlrLog, "Not enough info to add message to database '" << msg.getString() << "'");
        //msg.print();
        return -1;
    }


    // Start a new transaction
    if(!db->prepare("BEGIN")) {
        LOG4CXX_ERROR(narratorMsgHlrLog, "Query failed '" << db->getLasterror() << "'");
    }

    narrator::DBResult result;
    if(!db->perform(&result)) {
        LOG4CXX_ERROR(narratorMsgHlrLog, "%s: Query failed '" << db->getLasterror() << "'");
        return false;
    }


    // Check if we already have this message in the database
    messageid = checkMessage(msg);
    if(messageid < 0)
        messageid = insertMessage(msg);

    // Check message translationx
    if(messageid > 0) {
        if(msg.hasTranslation())
            translationid = checkMessageTranslation(messageid, msg.getTranslation());
        else translationid = 0;
    }

    // Check message parameters
    if(messageid > 0) {
        params = checkMessageParameters(messageid, msg);
    }

    // If all went well commit changes
    if(messageid > 0 && translationid >= 0 && params >= 0) {
        if(!db->prepare("COMMIT")) {
            LOG4CXX_ERROR(narratorMsgHlrLog, "Query failed '" << db->getLasterror() << "'");
        }

        narrator::DBResult result2;
        if(!db->perform(&result2)) {
            LOG4CXX_ERROR(narratorMsgHlrLog, "Query failed '" << db->getLasterror() << "'");
            return -1;
        }
    } else {
        // If we had an error discard changes
        cout << "An error ocurred, rolling back changes" << endl;
        if(!db->prepare("COMMIT")) {
            LOG4CXX_ERROR(narratorMsgHlrLog, "Query failed '" << db->getLasterror() << "'");
        }

        narrator::DBResult result3;
        if(!db->perform(&result3)) {
            LOG4CXX_ERROR(narratorMsgHlrLog, "Query failed '" << db->getLasterror() << "'");
            return -1;
        }
    }
    return messageid;
}
コード例 #13
0
void clientMessage(std::string command, std::string option, std::string data, IClientSocket *socket)
{
	if(command == "message") insertMessage(option,data);
	
	//	Client command: connect to a server
	if(command == "connect"){
		clientMessage("/info,connect:"+data);
		
		if(state.enableClient == false){
			state.client = fusion->Network->CreateSocket();
			if(state.client->Connect(data.c_str(),state.port) == true){
				state.enableClient = true;
							
				//	You are connected to the server with a socket
				
				//	Set your nick, to what it is now 
				//	(results not in an update of username, but an 
				//	update of the clients username on the server)
				remoteMessage("/newClient,"+state.username);
			}else{
				clientMessage("/error,connect");
			}
		}else{
			clientMessage("/error,connectionPresent");
		}
	}
	
	//	Client command: disconnect from a server
	if(command == "disconnect"){
		state.client->Disconnect();
		state.enableClient = false;
		setDisconnected();
	}	
	
	//	Client command: server accepted your connection
	if(command == "accepted"){
		if(getConnected() == "Connect"){
			//	Inform the client it has connected successfully
			clientMessage("/info,accepted");
			//	Set the identifying code for this client
			state.id = data;
			//	Set the gui to show connected to a server
			setConnected();
		}
	}
	
	//	Client command: informs the client a new user has entered the server
	if(command == "userConnect")
	{
		clientMessage("/info,userConnect:"+option+";"+data);
		//	If the user being added, is you, then set the state.id
		if(addUser(option,data) == false){
			//	Error adding the user to the client
			clientMessage("/error,invalidUsername",socket);
		}else{
			//	Should the client do something if addUser succeeded?
			clientMessage("/info,userConnect");
		}
	}
	
	//	Client command: informs the client a user has disconnected from the server
	if(command == "userDisconnect"){}
	
	//	Client command: show information to the interface
	if(command == "info")
	{
		if(option == "connect")		data = "Lets connect to: " + data;
		if(data == "accepted")		data = "connection accepted!";
		if(data == "userConnect")	data = option + " has entered the room";
		if(data == "userDisconnect")data = option + " has left the room";

		insertMessage("info",data);
	}	
	
	if(command == "error")
	{
		//	The client failed to connect to the server
		if(data == "connect") data = "Failed to connect, sorry";

		//	The connect address was invalid (the network couldnt resolve or understand the address given
		if(data == "invalidAddress") data = "Try to use a correct hostname/address please";

		//	The app is running as a server, or the client is already connected
		//	therefore you cannot make another connection until the server is deactivated
		//	or the client, disconnected.
		if(data == "connectionPresent") data = "Cannot connect, Server running, or client already connected";
		
		//	The username is invalid (you entered a semi colon?)
		if(data == "invalidUsername"){
			data = "the username requested is invalid, please attempt to choose another";
			updateUsername();
		}

		//	This is sent from the server in response to an attempt to use an username which already exists there
		//	it says userFound, so you can choose another username and attempt again
		if(data == "userFound"){
			data = "Server reported this username is not available";
			updateUsername();
		}
		insertMessage("error",data);
	}
}
コード例 #14
0
void DebugMessage::insertMessage(const GLenum source, const GLenum type, const GLuint id, const GLenum severity, const std::string & message)
{
    insertMessage(DebugMessage(source, type, id, severity, message));
}
コード例 #15
0
void DebugMessage::insertMessage(const GLenum source, const GLenum type, const GLuint id, const GLenum severity, const GLsizei length, const char * message)
{
    assert(message != nullptr);

    insertMessage(DebugMessage(source, type, id, severity, std::string(message, length)));
}