QByteArray MessageManager::dispatchHandler(QString incomingMessage, QTcpSocket *socket)
{
    QStringList message = incomingMessage.split('|');

    if(message.size() > 0){

        QString messageType = QString::fromLocal8Bit(message.at(0).toLocal8Bit()); //Extract the type

        //Call Handler for each type of message
        if(messageType == LOGIN_REQUEST){
            QString username = QString::fromLocal8Bit(message.at(1).toLocal8Bit());

            //Search for the username in the database of users
            QByteArray result = handleLogin(username).toLocal8Bit();
            return result;
        }
        else if(messageType == PATIENT_DATA_REQUEST){
            QByteArray result = handleDataRequest(socket).toLocal8Bit();
            return result;
        }
        else if(messageType == ADD_PATIENT_REQUEST){

        }
        else if(messageType == EDIT_PATIENT_REQUEST){

        }
        else if(messageType == DELETE_PATIENT_REQUEST){

        }
        else if(messageType == ADD_CONSULTATION_REQUEST){
            QByteArray result = handleAddConsultation(incomingMessage, socket).toLocal8Bit();
            return result;
        }
        else if(messageType == EDIT_CONSULTATION_REQUEST){
            QByteArray result = handleEditConsultation(incomingMessage).toLocal8Bit();
            return result;
        }
        else if(messageType == ADD_FOLLOWUP_REQUEST){
            QByteArray result = handleAddFollowUp(incomingMessage, socket).toLocal8Bit();
            return result;
        }
        else if(messageType == EDIT_FOLLOWUP_REQUEST){
            QByteArray result = handleEditFollowUp(incomingMessage, socket).toLocal8Bit();
            return result;
        }
    }
    return INVALID_MESSAGE_TYPE.toLocal8Bit();
}
Exemplo n.º 2
0
void MailServer::messageReceived(int sd, boost::shared_ptr<Message> msg)
{
	DEBUG("A message has been dispatched!");

	// Don't accept messages from users that aren't authenticated yet.
	if( msg->getType() != Message::MessageTypeLogin &&
		msg->getType() != Message::MessageTypeQuit  &&
		loginManager_.isLoggedIn() == false)
	{
		sendErr(sd);
		return;
	}

	switch( msg->getType() )
	{
		case Message::MessageTypeSend:
			handleSend(static_cast<SendMessage&>(*msg));
			break;
		case Message::MessageTypeList:
			handleList(static_cast<ListMessage&>(*msg));
			break;
		case Message::MessageTypeRead:
			handleRead(static_cast<ReadMessage&>(*msg));
			break;
		case Message::MessageTypeDel:
			handleDel(static_cast<DelMessage&>(*msg));
			break;
		case Message::MessageTypeQuit:
			handleQuit(static_cast<QuitMessage&>(*msg));
			break;
		case Message::MessageTypeLogin:
			handleLogin(static_cast<LoginMessage&>(*msg));
			break;
		case Message::MessageTypeInvalid:
		default:
			DEBUG("Ignoring: An invalid/unknown message type was received. Code: [" << (*msg).getType() << "].");
			break;
	}
}
Exemplo n.º 3
0
void UserProcessingCenter::consume(CEpollKey* epKey) {
	if(epKey == NULL)
		return ;
	
	MBlockSocket* stream = epKey->getTCPSocket();
	CPacket* pack = epKey->getPacket();
    char* pbuf = pack->getBuffer();
	int msgLen = pack->getLength();
	CMazeMsg *context = new CMazeMsg(pbuf,msgLen,stream);

    if(msgLen < 4)
    {
           delete context;
           //delete epKey;
           return;
    }

	if(pbuf[0] == 'A' && pbuf[1] == 'C' && pbuf[2] == 'A' && pbuf[3] == 'C' )
	{
		handleAC(context);
		delete context;
		//delete epKey;
		return;
	}

    string input(pbuf);
	string cmd=MXMLHandler::GetNode(input,"Cmd");
	CUserCard onecard;

	if(cmd == "Register")
	{
	}
	else if(cmd == "RefreshPersonalInfo")
	{
	    handleRefreshPersonalInfo(context);
	}
	else if(cmd == "IsEmailExist")
	{
	    handleIsEmailExist(context);
	}
	else if(cmd == "WebRegister")
	{
	    handleWebRegister(context);
	}
	else if(cmd == "WebLogin")
	{
	    handleWebLogin(context);
	}
	else if(cmd == "GetFaceImage")
	{
	    handleGetFaceImage(context);
	}
	else if(cmd == "UpdateEmail")
	{
	    handleUpdateEmail(context);
	}
	else if(cmd == "WebChgPwd")
	{
	    handleWebChgPwd(context);
	}
	else if(cmd == "WebUpdateInfo")
	{
	    handleWebUpdateInfo(context);
	}
	else if(cmd == "WebFindUser")
	{
	    handleWebFindUser(context);
	}
	else if(cmd == "LogServer")
	{
	    handleLogServer(context);
	}
	else if(cmd == "GetQuestion")
	{
	    handleGetQuestion(context);
	}
	else if(cmd == "GetPassword")
	{
	    ;//handleGetPassword(context);
	}
	else if(cmd == "FindUser")
	{
	    handleFindUser(context);
	}
	else if(cmd == "UpdateQA")
	{
	    handleUpdateQA(context);
	}
	else if(cmd == "Account")
	{
	    handleAccount(context);
	}
	else if(cmd == "Level")
	{
	    handleLevel(context);
	}
	else if(cmd == "Login")
	{
	    handleLogin(context);
	}
	else if(cmd == "ChgName")
	{
	    handleChgName(context);
	}
	else if(cmd == "Friend")
	{
	    ;
	}
	else if(cmd == "ChgAccount")
	{
	    ;
	}
	else if(cmd == "SignEmail")
	{
	    handleSignEmail(context);
	}
	else if(cmd == "AskforAuth")
	{
	    handleAskforAuth(context);
	}
	else if(cmd == "ChgPwd")
	{
	    handleChgPwd(context);
	}
	else if(cmd == "GetTCPPubIPandPort")
	{
		handleGetPubIP(context);
	}
	else
	    handleKerberosLogin(context);
	
	delete context;
	if(!isSNS)
	    stream->Close();
	else
		isSNS = false;

	//delete epKey;
}
Exemplo n.º 4
0
void DispatchTCPData( int nSocket, u8 *pData,int datalength)
{
    int varlen;
    int datalen;
    u8 cmd;
    u8 TcpCmd[2];
	int i;				
    int sendLen;
    unsigned char *pP0Data;

    if( !(pData[0]==0x00&&pData[1]==0x00&&pData[2]==0x00&&pData[3]==0x03)) return ;
    /*根据报文中的报文长度确定报文是否是一个有效的报文*/
    varlen = mqtt_num_rem_len_bytes(pData+4);
    /*这个地方+3是因为MQTT库里面实现把 UDP flag算到messagelen里面,这里为了跟mqtt库保持一致所以加3*/
    datalen = mqtt_parse_rem_len(pData+3); 

    cmd = pData[7+varlen-1];  
    GAgent_Printf(GAGENT_INFO,"LAN_TCP Receive Data  cmd:%2X\n", cmd);

	switch(cmd)//get cmd 
	{
		case 0x0006:  //user bind passcode
    		if( g_passcodeEnable==1 )
            {
                handlePasscode( nSocket,pData, datalength);
            }
		    break;
            
		case 0x0008: //user login 
			handleLogin( nSocket,pData, datalength);			
		    break;
            
		case 0x0090: // send p0 to uart
            for( i=0;i<8;i++ )
            {
            	if( nSocket==g_SocketLogin[i] )
            	{
                	pP0Data = pData+(7+varlen);                      
                	//datalen-3 才是P0的长度因为:datalen后面有falg(1B)+cmd(2B);
                	LAN_handleMCUData( nSocket,pP0Data, datalen-3);
                	break;
            	}
            }
			break;
    	case 0x000A:
            GetWifiVersion( nSocket,pData,datalength );
        	break;
    	case 0x000C:
            GetWifiHotspots( nSocket,pData,datalength );  
            break;
        //串口配置
        case 0x000E:
            break;
        //日志设置
        case 0x0010:
            break;
        //请求wifi模组信息
        case 0X0013:
            GetWifiInfo( nSocket );
            break;
        //心跳包
        case 0X0015:
            LanAppTick_Ack( nSocket );
            break;
		default: 
            GAgent_Printf(GAGENT_WARNING,"DispatchTCPData invalid cmd:%2x\n", cmd);
		break;
	}
    return;
}