Exemple #1
0
static GLOBAL_FUNC(cmd_list)
{
    struct globalMessage *message;
    struct helpfile_table table;
    unsigned int length, nn;

    if(!messageList)
    {
	global_notice(user, "GMSG_NO_MESSAGES");
        return 1;
    }

    for(nn=0, message = messageList; message; nn++, message=message->next) ;
    table.length = nn+1;
    table.width = 5;
    table.flags = TABLE_NO_FREE;
    table.contents = calloc(table.length, sizeof(char**));
    table.contents[0] = calloc(table.width, sizeof(char*));
    table.contents[0][0] = "ID";
    table.contents[0][1] = "Target";
    table.contents[0][2] = "Expires";
    table.contents[0][3] = "From";
    table.contents[0][4] = "Message";

    for(nn=1, message = messageList; message; nn++, message = message->next)
    {
        char buffer[64];

        table.contents[nn] = calloc(table.width, sizeof(char*));
        snprintf(buffer, sizeof(buffer), "%lu", message->id);
        table.contents[nn][0] = strdup(buffer);
        table.contents[nn][1] = messageType(message);
        if(message->duration)
            intervalString(buffer, message->posted + message->duration - now, user->handle_info);
        else
            strcpy(buffer, "Never.");
        table.contents[nn][2] = strdup(buffer);
        table.contents[nn][3] = message->from;
	length = strlen(message->message);
	safestrncpy(buffer, message->message, sizeof(buffer));
	if(length > (sizeof(buffer) - 4))
	{
	    buffer[sizeof(buffer) - 1] = 0;
	    buffer[sizeof(buffer) - 2] = buffer[sizeof(buffer) - 3] = buffer[sizeof(buffer) - 4] = '.';
	}
        table.contents[nn][4] = strdup(buffer);
    }
    table_send(global, user->nick, 0, NULL, table);
    for (nn=1; nn<table.length; nn++)
    {
        free((char*)table.contents[nn][0]);
        free((char*)table.contents[nn][2]);
        free((char*)table.contents[nn][4]);
        free(table.contents[nn]);
    }
    free(table.contents[0]);
    free(table.contents);

    return 1;
}
Exemple #2
0
static void
notice_target(const char *target, struct globalMessage *message)
{
    if(!(message->flags & MESSAGE_OPTION_SOURCELESS))
    {
	if(message->flags & MESSAGE_OPTION_IMMEDIATE)
	{
	    send_target_message(0, target, global, "GMSG_NOTICE_SOURCE", messageType(message), message->from);
	}
	else
	{
	    send_target_message(0, target, global, "GMSG_MESSAGE_SOURCE", messageType(message), message->from, message->posted_s);
	}
    }

    send_target_message(4, target, global, "%s", message->message);
}
void Message::messageToNetwork(QByteArray &qbaOut) const {
	char buffer[8192];
	PacketDataStream qdsOut(buffer, 8192);
	qdsOut << messageType();
	qdsOut << uiSession;
	saveStream(qdsOut);

	if (qdsOut.undersize() == 0) {
		qbaOut = QByteArray(buffer, qdsOut.size());
		return;
	}

	unsigned int size = 8192 + qdsOut.undersize();
	STACKVAR(char, b, size);
	PacketDataStream pdsResized(b, size);
	pdsResized << messageType();
	pdsResized << uiSession;
	saveStream(pdsResized);
	qbaOut = QByteArray(b, pdsResized.size());
}
QVariantMap DebugMessagesModel::details(int index) const
{
    const QmlEventType &type = modelManager()->qmlModel()->eventTypes()[m_data[index].typeId];

    QVariantMap result;
    result.insert(QLatin1String("displayName"), messageType(type.detailType()));
    result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index)));
    result.insert(tr("Message"), m_data[index].text);
    result.insert(tr("Location"), type.displayName());
    return result;
}
Exemple #5
0
static GLOBAL_FUNC(cmd_notice)
{
    struct globalMessage *message = NULL;
    const char *recipient = NULL, *text;
    char *sender;
    long target = 0;

    assert(argc >= 3);
    sender = user->handle_info->handle;
    if(!irccasecmp(argv[1], "all")) {
	target = MESSAGE_RECIPIENT_ALL;
    } else if(!irccasecmp(argv[1], "users")) {
	target = MESSAGE_RECIPIENT_LUSERS;
    } else if(!irccasecmp(argv[1], "authed")) {
        target = MESSAGE_RECIPIENT_AUTHED;
    } else if(!irccasecmp(argv[1], "helpers")) {
	target = MESSAGE_RECIPIENT_HELPERS;
    } else if(!irccasecmp(argv[1], "opers")) {
	target = MESSAGE_RECIPIENT_OPERS;
    } else if(!irccasecmp(argv[1], "staff") || !irccasecmp(argv[1], "privileged")) {
	target |= MESSAGE_RECIPIENT_HELPERS | MESSAGE_RECIPIENT_OPERS;
    } else if(!irccasecmp(argv[1], "announcement") || !irccasecmp(argv[1], "announce")) {
        target |= MESSAGE_RECIPIENT_ANNOUNCE;
    } else if(!irccasecmp(argv[1], "channels")) {
	target = MESSAGE_RECIPIENT_CHANNELS;
    } else if(!irccasecmp(argv[1], "rchannels")) {
	target = MESSAGE_RECIPIENT_RCHANNELS;
    } else {
	global_notice(user, "GMSG_INVALID_TARGET", argv[1]);
	return 0;
    }
    if(!irccasecmp(argv[2], "from")) {
        if (argc < 5) {
            reply("MSG_MISSING_PARAMS", argv[0]);
            GLOBAL_SYNTAX();
            return 0;
        }
        sender = argv[3];
        text = unsplit_string(argv + 4, argc - 4, NULL);
    } else {
        text = unsplit_string(argv + 2, argc - 2, NULL);
    }

    message = message_add(target | MESSAGE_OPTION_IMMEDIATE, now, 0, sender, text);
    if(!message)
	return 0;

    recipient = messageType(message);
    message_send(message);
    message_del(message);

    global_notice(user, "GMSG_MESSAGE_SENT", recipient);
    return 1;
}
QVariantList DebugMessagesModel::labels() const
{
    QVariantList result;

    for (int i = 0; i <= m_maximumMsgType; ++i) {
        QVariantMap element;
        element.insert(QLatin1String("description"), messageType(i));
        element.insert(QLatin1String("id"), i);
        result << element;
    }
    return result;
}
Exemple #7
0
void FunctionQueueQt::callFunctionoidNonblocking(Functionoid* f)
{
	//if the call comes from the QApplication thread, execute the functionoid immediately
	if(QThread::currentThread() == _qAppThread)
	{
		(*f)();
		delete f;
	}
	else //call is from another thread, add it to the queue and wait until it is executed
	{
		messageQueue.addMessage(messageType(f,0));
	}
}
Exemple #8
0
static GLOBAL_FUNC(cmd_message)
{
    struct globalMessage *message = NULL;
    const char *recipient = NULL;

    assert(argc >= 3);
    message = message_create(user, argc - 1, argv + 1);
    if(!message)
        return 0;
    recipient = messageType(message);
    global_notice(user, "GMSG_MESSAGE_ADDED", recipient, message->id);
    return 1;
}
Exemple #9
0
void FunctionQueueQt::callFunctionoidBlocking(Functionoid& f)
{
	//if the call comes from the QApplication thread, execute the functionoid immediately
	if(QThread::currentThread() == _qAppThread)
	{
		f();
	}
	else //call is from another thread, add it to the queue and wait until it is executed
	{
		Pause p;
		messageQueue.addMessage(messageType(&f,&p));
		p.pause();
	}
}
Exemple #10
0
static void MyDefaultErrorCallBack(std::string message, std::string file,
                                   int line, bool isWarning, int lineRange) {
    std::string messageType(isWarning ? "WARNING" : "ERROR");
    if (line < 1 || file.empty()) {
        std::cerr << messageType << ": ";
    } else {
        std::cerr << messageType;
        if (lineRange > 1) {
            std::cerr << " within " << lineRange << " lines of line ";
        } else {
            std::cerr << " on line ";
        }
        std::cerr << line << " in file " << file << ": ";
    }
    std::cerr << message << std::endl;
}
Exemple #11
0
		void CRotationComponent::init(Gnoll::Scene::GObject* _parent, CPage* _page)
		{
			parent = _parent;

			/**
			 * A parent must exist
			 */
			if (parent == NULL)
			{
				GNOLL_LOG() << this->getInstance() << " object initialized without any parent";
				return;
			}

			/**
			 * A parent page must exist
			 */
			if (_page == NULL)
			{
				GNOLL_LOG() << parent->getInstance() << ":" << this->getInstance() << " object initialized without any parent page" << "\n";
				return;
			}


			/**
			 * Register the listener
			 */
			MessageModule*  messageModule  = MessageModule::getInstancePtr();
			Messages::Messenger* messageManager = messageModule->getMessageManager();

			rotationListener = shared_ptr<Messages::Listener> (new RotationListener(this));
			messageManager->addListener ( rotationListener, "SET_ROTATION_" + parent->getInstance() );


			shared_ptr< Gnoll::DynamicObject::Vector3 > zero ( new Gnoll::DynamicObject::Vector3());
			rotation = *(this->getAttributeOrDefault < Gnoll::DynamicObject::Vector3 > (CRotationComponent::ATTRIBUTE_ROTATION(), zero));


			/**
			 * Queue the message of the init rotation
			 */
			Messages::MessageType messageType("SET_ROTATION_" + parent->getInstance());
			shared_ptr<boost::any> data(new boost::any(rotation)) ;
			shared_ptr<Message> message = shared_ptr<Message>(new Message(messageType, data));
			messageManager->queueMessage(message);
		}
void Message::messageToNetwork(PacketDataStream &pds) const {
	pds << messageType();
	pds << uiSession;
	saveStream(pds);
	pds.truncate();
}
/* Parse the XML configuration file */
void FROLogger::ParseConfig( const std::string &configFile ) {
    // Test to see if the file is ok.
    struct stat fileStatus;
    int iretStat = stat( configFile.c_str(), &fileStatus );
    if( iretStat == ENOENT )
        std::cout << "Path file_name does not exist, or path is an empty string.";
    else if( iretStat == ENOTDIR )
        std::cout << "A component of the path is not a directory.";
    else if( iretStat == ELOOP )
        std::cout << "Too many symbolic links encountered while traversing the path.";
    else if( iretStat == EACCES )
        std::cout << "Permission denied.";
    else if( iretStat == ENAMETOOLONG )
        std::cout << "File can not be read\n";

    // Configure DOM parser
    xercesc::XMLPlatformUtils::Initialize();
    xercesc::XercesDOMParser *parser = new xercesc::XercesDOMParser;
    parser->setValidationScheme( xercesc::XercesDOMParser::Val_Never );
    parser->setDoNamespaces( false );
    parser->setDoSchema( false );
    parser->setLoadExternalDTD( false );
    // Ready the standard tags
    //	XMLCh* tagFROLog = xercesc::XMLString::transcode("FROLog");
    XMLCh* tagUDPChannel = xercesc::XMLString::transcode("UDPChannel");
    XMLCh* tagMessageType = xercesc::XMLString::transcode("MessageType");
    XMLCh* tagElement = xercesc::XMLString::transcode("Element");
    XMLCh* attrAddress = xercesc::XMLString::transcode("address");
    XMLCh* attrPort = xercesc::XMLString::transcode("port");
    XMLCh* attrType = xercesc::XMLString::transcode("type");
    XMLCh* attrID = xercesc::XMLString::transcode("id");
    XMLCh* attrName = xercesc::XMLString::transcode("name");
    XMLCh* attrOffset = xercesc::XMLString::transcode("offset");
    char *charAddress=NULL, *charPort=NULL, *charType=NULL, *charID=NULL, *charName=NULL, *charOffset=NULL;

    // Try to parse the file
    try {
        // Here we go...
        parser->parse( configFile.c_str() );
        // No need to free this pointer - owned by the parent parser object
        xercesc::DOMDocument* xmlDoc = parser->getDocument();
        // Get the top-level element: Name is "FROLog". No attributes for "FROLog"
        xercesc::DOMElement* elementRoot = xmlDoc->getDocumentElement();
        if( !elementRoot ) throw( std::runtime_error( "Empty XML document" ) );

        // Parse XML file for tags of interest: "Channel, MessageTyp, etc."
        // Look one level nested within "FROLog". (children of root)
        xercesc::DOMNodeList* children = elementRoot->getChildNodes();
        const XMLSize_t nodeCount = children->getLength();
        // For all nodes, children of "FROLog" in the XML tree.
        for( XMLSize_t i = 0; i < nodeCount; i++ ) {
            // Get the child
            xercesc::DOMNode* currentNode = children->item( i );
            // We only care about valid element children
            if( currentNode->getNodeType() && currentNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
                // Found node which is an Element. Re-cast node as element
                xercesc::DOMElement* currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode );
                // Is this a UDP Channel declaration
                if( xercesc::XMLString::equals( currentElement->getTagName(), tagUDPChannel ) ) {
                    // Read attributes of element "UDPChannel".
                    const XMLCh* xmlchAddress = currentElement->getAttribute( attrAddress );
                    charAddress = xercesc::XMLString::transcode( xmlchAddress );
                    const XMLCh* xmlchPort = currentElement->getAttribute( attrPort );
                    charPort = xercesc::XMLString::transcode( xmlchPort );
                    // Call to create a UDP channel object
                    FLUDPChannel *udpChannel = new FLUDPChannel( this, charAddress, atoi( charPort ) );
                    // Add this channel into the global vector
                    this->_channels.push_back( udpChannel );
                }
                // Is this a MessageType declaration
                else if ( xercesc::XMLString::equals( currentElement->getTagName(), tagMessageType ) ) {
                    // Read attributes of element "MessageType".
                    const XMLCh* xmlchID = currentElement->getAttribute( attrID );
                    charID = xercesc::XMLString::transcode( xmlchID );
                    uint16_t msgID = atoi( charID );
                    const XMLCh* xmlchName = currentElement->getAttribute( attrName );
                    charName = xercesc::XMLString::transcode( xmlchName );
                    // Call to create a MessageType object
                    std::cout << "Creating MessageType (" << charName << ") with ID: " << msgID << ".\n";
                    FLMessageType messageType( charName, msgID );
                    // Now we need to get all of the element children
                    xercesc::DOMNodeList* elementChildren = currentNode->getChildNodes();
                    const XMLSize_t elementCount = elementChildren->getLength();
                    // Loop through all elements
                    for ( XMLSize_t j = 0; j < elementCount; j++ ) {
                        // Get the element child
                        xercesc::DOMNode* elementNode = elementChildren->item( j );
                        // We only care about valid element children
                        if( elementNode->getNodeType() && elementNode->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
                            // Found node which is an Element. Re-cast node as element
                            xercesc::DOMElement* element = dynamic_cast< xercesc::DOMElement* >( elementNode );
                            // Make sure this is an "Element" type child
                            if ( xercesc::XMLString::equals( element->getTagName(), tagElement ) ) {
                                // Get the attributes of the element
                                const XMLCh* xmlchName = element->getAttribute( attrName );
                                charName = xercesc::XMLString::transcode( xmlchName );
                                const XMLCh* xmlchType = element->getAttribute( attrType );
                                charType = xercesc::XMLString::transcode( xmlchType );
                                const XMLCh* xmlchOffset = element->getAttribute( attrOffset );
                                charOffset = xercesc::XMLString::transcode( xmlchOffset );
                                uint16_t offset = atoi( charOffset );
                                // Now add this element to the parent message type object
                                std::cout << "\tElement " << charName << " of type: " << charType << " @ " << offset << ".\n";
                                messageType.AddElement( charName, charType, offset );
                            }
                        }
                    }
                    // Now add this messageType into the global list
                    this->_messageTypes.insert( std::make_pair( msgID, messageType ) );
                }
            }
        }
    }
    // Catch any parsing errors
    catch( xercesc::XMLException& e ) {
        char* message = xercesc::XMLString::transcode( e.getMessage() );
        //		ostringstream errBuf;
        //		errBuf << "Error parsing file: " << message << flush;
        xercesc::XMLString::release( &message );
    }
    // Now clean up
    delete parser;
    if( charAddress ) xercesc::XMLString::release( &charAddress );
    if( charPort ) xercesc::XMLString::release( &charPort );
    if( charType ) xercesc::XMLString::release( &charType );
    if( charID ) xercesc::XMLString::release( &charID );
    if( charName ) xercesc::XMLString::release( &charName );
    if( charOffset ) xercesc::XMLString::release( &charOffset );
    try {
        //		xercesc::XMLString::release( &tagFROLog );
        xercesc::XMLString::release( &tagUDPChannel );
        xercesc::XMLString::release( &tagMessageType );
        xercesc::XMLString::release( &tagElement );
        xercesc::XMLString::release( &attrAddress );
        xercesc::XMLString::release( &attrPort );
        xercesc::XMLString::release( &attrType );
        xercesc::XMLString::release( &attrID );
        xercesc::XMLString::release( &attrName );
        xercesc::XMLString::release( &attrOffset );
    }
    catch( ... ) {
        std::cout << "Unknown exception encountered in TagNamesdtor\n";
    }
}
/*
 * This function works pretty much like routTcpMessage only that this one interpretes message from RFIDMonitor and don't verify packages size.
 * it only tries to interpret data just arrived.
 */
void RFIDMonitorDaemon::routeIpcMessage()
{
    QByteArray message = ipcConnection->readAll();
    json::NodeJSMessage nodeMessage;

    nodeMessage.read(QJsonDocument::fromJson(message).object());
    QString messageType(nodeMessage.type());

    if(messageType == "SYN"){

        m_restoreTimer.stop();
        ipcSendMessage(buildMessage(QJsonObject(), "ACK-SYN").toJson());
        qApp->processEvents();

        /* When the deskApp change some configuration the RFIDMonitor is restarted.
         * But, the RFIDMonitor starts with flag connection=false. And if the server is connected the RFIDMonitor don't know that yet.
         * To solve this, after 1 seconds a SYNC message is sent to RFIDMonitor to set true to connection flag.
         */
        if(isConnected)
        {
            QTimer *timer = new QTimer();
            timer->setSingleShot(true);
            timer->setInterval(1000);
            connect(timer, &QTimer::timeout, [=](){
                ipcSendMessage(buildMessage(QJsonObject(), "SYNC").toJson());
                timer->deleteLater();
            });
            timer->start();
        }

        m_configManager->restartNetwork();

    }else if (messageType == "READER-RESPONSE") {
        QJsonObject command(nodeMessage.jsonData());
        /*
         * When a 'reader response' message is received is because someone sent a 'reader command' message. So it needs to know who did it.
         * To perform this it uses a field called 'sender' that carry the name of who sent the 'command message'.
         * And based on that, it will respond to the server connection or to the deskApp connection.
         *
         * see reoutTcpMessage (messageType == "READER-COMMAND")
         */
        if(command.value("sender").toString() == "server")
            tcpSendMessage(m_tcpSocket, message);
        else
            tcpSendMessage(m_tcpAppSocket, message);

    }else if (messageType == "DATA"){
        /*
         * A Data message means that the RFIDMonitor is trying to sync some data into the server. So, it just send this message to the server.
         */
//        qDebug() <<  "DATA Message Received from Monitor\n";
//        qDebug() <<  QString(QJsonDocument(nodeMessage.jsonData()).toJson());
        // Only a node.js server receives DATA messages.
        tcpSendMessage(m_tcpSocket, message);

    }else if (messageType == "STOPPED"){
        qDebug() << "STOPPED";
        m_process.kill();
//        qDebug() << "Process Killed, PID: " << m_process.pid();
    }
    else if (messageType == "ACK-UNKNOWN") {
        QJsonDocument unknown(nodeMessage.jsonData());
        QJsonObject dataObj(unknown.object().value("unknownmessage").toObject());
        qDebug() <<  "The Monitor don't understand the message type: "
                        << dataObj.value("type").toString();
    }
    else{
        /* When receives a message that can't be interpreted like any type is an unknown message.
         * In this case an ACK-UNKNOWN message is built and sent to the connection that received this message
         */
        qDebug() <<  "UNKNOWN MESSAGE";

        QJsonObject unknownObj;
        unknownObj.insert("unknownmessage", QJsonDocument::fromJson(message).object());
        unknownObj.insert("errorinfo", QString("Unknown message received"));

        ipcSendMessage(buildMessage(unknownObj, "ACK-UNKNOWN").toJson());
    }
}
/*
 * The routeTcpMessage() receives messages from any TCP connection. The Daemon can be connected with server and deskApp at the same time, but it will know which connection received data.
 * Any message arrive by TCP must to have two parts. The first part defines the data size of the coming package (second part) and must to be an 8 bytes String (always 8 bytes).
 *
 * The algoritm works like this:
 * When some data arrive it verifies (using the hasPackage variable) if is the first part or the second one of the complete message;
 * If hasPackage is true then is especting the second part of the message, otherwise the dada just arrived is the size information.
 *
 * The information of size correspond to the size of the message package. So, when more data arrive it verifies if the size is greater than or equals to the expected size.
 * If true the message is all here and can go on, otherwise the message is coming and it will wait for more data.
 *
 * When all the message arrives it will interpret and route it (by message type) to the right way.
 *
 */
void RFIDMonitorDaemon::routeTcpMessage()
{
    QTcpSocket *connection = (QTcpSocket *) QObject::sender();

    static bool hasPackage = false;
    static quint64 packageSize = 0;

    if( ! hasPackage){

        if((quint64)connection->bytesAvailable() < sizeof(quint64))
            return;

        //    	m_tcpSocket->read((char *)&packageSize, sizeof(quint64));
        QString packageSizeStr(connection->read(sizeof(quint64)));
        packageSize = packageSizeStr.toULongLong();

        qDebug() <<  QString("Message = %1 - Size of coming package: %2").arg(packageSizeStr).arg(QString::number(packageSize));
        hasPackage = true;
    }

    if((quint64)connection->bytesAvailable() >=  packageSize){
        QByteArray data(connection->read(packageSize));

        json::NodeJSMessage nodeMessage;

        nodeMessage.read(QJsonDocument::fromJson(data).object());
        QString messageType(nodeMessage.type());

        qDebug() << QString("New Message Received: %1").arg(QString(data));


        if(messageType == "SYN-ALIVE"){

            tcpSendMessage(connection, buildMessage(m_configManager->identification(), "ACK-ALIVE").toJson());
            qDebug() << QString("New Message Received: %1").arg(messageType);
        }
        else if (messageType == "ACK-SYN") {

            QJsonObject obj(nodeMessage.jsonData());
            if(!obj.isEmpty()){
                m_configManager->setIdentification(obj);
            }

            bool statusDateTime = m_configManager->setDateTime(nodeMessage.dateTime());
            QJsonObject response = m_configManager->identification();
            response["success"] = QJsonValue(statusDateTime);

            tcpSendMessage(connection, buildMessage(response, "ACK").toJson());

            // Informe RFIDMonitor that server is now connected. Wait 2 seconds;
            if(connection->objectName() == "server"){
                isConnected = true;
                QTimer *timer = new QTimer();
                timer->setSingleShot(true);
                timer->setInterval(2000);
                connect(timer, &QTimer::timeout, [=](){
                    ipcSendMessage(buildMessage(QJsonObject(), "SYNC").toJson());
                    timer->deleteLater();
                });
                timer->start();
            }
        }else if (messageType == "GET-CONFIG") {
            tcpSendMessage(connection, buildMessage(m_configManager->currentConfig(), "CONFIG").toJson());

        }else if (messageType == "READER-COMMAND") {

            QJsonObject command(nodeMessage.jsonData());
            /*
             * When a 'reader command' message is received is because someone is sending a command to the reader. So it needs to send also who is doing this.
             * To perform this it uses a field called 'sender' that carry the name of who is sending the 'command message'.
             * And based on that, it will respond to the server connection or to the deskApp connection
             *
             * see reoutIcpMessage (messageType == "READER-RESPONSE")
             */
            if(connection->objectName() == "server")
                command.insert("sender", QString("server"));
            else
                command.insert("sender", QString("app"));

            ipcSendMessage(buildMessage(command, "READER-COMMAND").toJson());

        }else if (messageType == "NEW-CONFIG") {

            QJsonObject newConfig(nodeMessage.jsonData());
            bool ackConf;
            if(m_configManager->newConfig(newConfig))
            {
                // Send a message to stop the RFIDMonitor
                emit restartMonitor();
                ackConf = true;
            }else{
                ackConf = false;
            }
            QJsonObject dataObj;
            dataObj.insert("success", QJsonValue(ackConf));
            tcpSendMessage(connection, buildMessage(dataObj, "ACK-NEW-CONFIG").toJson());

            if(m_tcpAppSocket->isOpen())
                m_tcpAppSocket->close();

        }else if (messageType == "DATETIME") {

            QJsonObject dataObj;
            dataObj["success"] =  QJsonValue(m_configManager->setDateTime(nodeMessage.dateTime()));
            tcpSendMessage(connection, buildMessage(dataObj, "ACK").toJson());

        }else if (messageType == "ACK-DATA") {
            // A ACK-DATA message means that the server is trying to inform the RFIDMonitor that some data is now synced. So, it just send this message to the RFIDMonitor.
            ipcSendMessage(data);

        }else if (messageType == "GET-NET-CONFIG") {
            // Only return the network configuration.
            tcpSendMessage(connection, buildMessage(m_configManager->netConfig(), "NET-CONFIG").toJson());

        }else if (messageType == "NEW-NET") {

            QJsonObject network = nodeMessage.jsonData();
            // Receive a new configuration for the network (ssid and password).
            QJsonObject dataObj;
            dataObj.insert("success", QJsonValue(m_configManager->setNetConfig(network)));

            // returns a message ACK-NET to inform the sender that the new configuration was set
            tcpSendMessage(connection, buildMessage(dataObj, "ACK-NET").toJson());

            // Try to restar the network service to already use the new configuration
            bool resetNet = m_configManager->restartNetwork();
            qDebug() <<  QString(resetNet? "Network restarted" : "Networkt Don't restarted");

        }else if (messageType == "ACK-UNKNOWN") {
            QJsonDocument unknown(nodeMessage.jsonData());
            QJsonObject oldMessage(unknown.object().value("unknownmessage").toObject());
            qDebug() <<  "The server don't understand the message type: " << oldMessage.value("type").toString();
            qDebug() <<  "ERROR message: " << unknown.object().value("errorinfo").toString();

        }else if (messageType == "FULL-READ"){
            ipcSendMessage(data);

        }else{
            /* When receives a message that can't be interpreted like any type is an unknown message.
             * In this case an ACK-UNKNOWN message is built and sent to the connection that received this message
             */
            qDebug() <<  "UNKNOWN MESSAGE";
            QJsonObject unknownObj;
            unknownObj.insert("unknownmessage", QJsonValue(QJsonDocument::fromJson(data).object()));
            unknownObj.insert("errorinfo", QString("Unknown message received"));
            tcpSendMessage(connection, buildMessage(unknownObj, "ACK-UNKNOWN").toJson());
        }

        /* when all the process is done, reset the expecting message size to zero and the haspackage to false.
         * Then when more data arrive it must to be the size information again.
         */
        packageSize = 0;
        hasPackage = false;
    }
}