Esempio n. 1
0
//
//  Process the data in the Rx buffer.
//
void ProcessUARTData()
{
    switch (_rxBuffer[1])
    {
        case COMMAND_GET_ID:
            break;
        case COMMAND_SET_ID:
            break;
        case COMMAND_GET_CARRIER_FREQUENCY:
            break;
        case COMMAND_SET_CARRIER_FREQUENCY:
            break;
        case COMMAND_GET_PULSE_DATA:
            SendResponse(EEPROM_PULSE_DATA,  ((*EEPROM_PULSE_DATA) * 3) + 1);
            break;
        case COMMAND_SET_PULSE_DATA:
            break;
        case COMMAND_TRANSMIT_PULSE_DATA:
            TransmitPulseData();
            SendACK();
            break;
        default:
            SendNAK(EC_UNKNOWN_COMMAND);
            break;
    }
    _uartMode = UART_MODE_WAITING_FOR_DATA;
}
Esempio n. 2
0
void Server::HandleSTOR(Client *pClient, char *szFileName) // store file on server
{
	FILE *pFile ;
	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(pClient->GetCurrentDir()) ;

	if (pClient->GetType() == I_TYPE) pFile = fopen(szFileName, "wb") ;
	else pFile = fopen(szFileName, "wb") ;

	::ReleaseMutex(m_hDiskMutex);

	if (pFile == NULL) 
	{
		SendResponse(pClient, 550, "No such file or directory.") ;
		return ;
	}

	if (!pClient->ConnectDTL())
	{
		SendResponse(pClient, 500, "Error opening connection.") ;
		return ;
	}
	SendResponse(pClient, 150, "Opening data connection.") ;
	SOCKET *phSocket = pClient->GetDTL() ;
	char cTemp ;
	if (pClient->GetType() == I_TYPE)
		while (cTemp != '\n' && cTemp != 255)
		{
			if (recv((*phSocket), &cTemp, 1, 0) == SOCKET_ERROR) break ;
			if (cTemp != 255) putc(cTemp, pFile) ;
		}
	else
		while (cTemp != 255)
		{
			if (recv((*phSocket), &cTemp, 1, 0) == SOCKET_ERROR) break ;
			if (cTemp != 255) putc(cTemp, pFile) ;
		}
	closesocket((*phSocket));
	(*phSocket) = -1 ;
	fclose(pFile) ;

	SendResponse(pClient, 226, "Transfer complete.") ;

	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(m_szMainDir) ;
	::ReleaseMutex(m_hDiskMutex);
}
Esempio n. 3
0
NS_IMETHODIMP
TelephonyRequestParent::NotifyDialCallSuccess(uint32_t aClientId,
        uint32_t aCallIndex,
        const nsAString& aNumber)
{
    return SendResponse(DialResponseCallSuccess(aClientId, aCallIndex,
                        nsAutoString(aNumber)));
}
/**************************************
* SendError
*	Devuelve el html con el error
**************************************/
int XmlRpcServer::SendError(TSession * r, short code,const char *msg)
{
	//POnemos el content type
	ResponseContentType(r, (char*)"text/html; charset=\"utf-8\"");

	//Escribimos el codigo de error
	return SendResponse(r,code,(char*)msg,strlen(msg));
}
Esempio n. 5
0
void Server::HandleCWD(Client *pClient, char *szDirectory) // change directory
{
	char szBuffer[256] ;
	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(pClient->GetCurrentDir()) ;
	if (SetCurrentDirectory(szDirectory))
	{
		GetCurrentDirectory(256, szBuffer) ;
		pClient->ChangeCurrentDir(szBuffer) ;
		SendResponse(pClient, 250, "CWD command successful.") ;
	} else
	{
		SendResponse(pClient, 550, "No such file or directory.") ;
	}
	SetCurrentDirectory(m_szMainDir) ;
	::ReleaseMutex(m_hDiskMutex);
}
Esempio n. 6
0
void DummyStMgr::HandleStMgrHelloRequest(REQID _id, Connection* _conn,
                                         heron::proto::stmgr::StrMgrHelloRequest* _request) {
  other_stmgrs_ids_.push_back(_request->stmgr());
  heron::proto::stmgr::StrMgrHelloResponse response;
  response.mutable_status()->set_status(heron::proto::system::OK);
  SendResponse(_id, _conn, response);
  delete _request;
}
Esempio n. 7
0
void Server::HandleCDUP(Client *pClient) // go up a directory
{
	char szBuffer[256] ;
	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(pClient->GetCurrentDir()) ;
	if (SetCurrentDirectory(".."))
	{
		GetCurrentDirectory(256, szBuffer) ;
		pClient->ChangeCurrentDir(szBuffer) ;
		SendResponse(pClient, 250, "CDUP command successful.") ;
	} else
	{
		SendResponse(pClient, 550, "CDUP command failed.") ;
	}
	SetCurrentDirectory(m_szMainDir) ;
	::ReleaseMutex(m_hDiskMutex);
}
Esempio n. 8
0
//----------------------------------------------------------------------------
//
void TelnetTCPClient::DispatchCommand(QString command)
{
    QString cmd = command.trimmed();

    if (isExit(cmd))
    {
        SendResponse( "bye..." );
        Socket->close();
        return;
    }

    QString ret = telnetLogic->ProcessCommand( cmd );
    if ( ! ret.isEmpty() )
    {
        SendResponse( ret + strCR );
    }
}
Esempio n. 9
0
void Server::HandleRMD(Client *pClient, char *szDirectory) // remove directory
{
	char szBuffer[256] ;
	::WaitForSingleObject(m_hDiskMutex, INFINITE) ;
	SetCurrentDirectory(pClient->GetCurrentDir()) ;

	if (RemoveDirectory(szDirectory))
	{
		sprintf(szBuffer, "\"%s\\%s\" directory removed.", pClient->GetCurrentDir(), szDirectory) ;
		SendResponse(pClient, 257, szBuffer) ;
	} else
	{
		SendResponse(pClient, 557, "Cannot remove directory.") ;
	}
	SetCurrentDirectory(m_szMainDir) ;
	::ReleaseMutex(m_hDiskMutex);
}
void Connection::SendCameraControl(long Message, long GameID)
{
	CameraControl data;
	data.Message = Message;
	data.GameID = GameID;

	SendResponse(ENB_OPCODE_0092_CAMERA_CONTROL, (unsigned char *) &data, sizeof(data));
}
//* For RTConnHttp
void CRTConnection::OnLogin(const char* pUserid, const char* pPass, const char* pNname)
{
    bool ok = false;
    {
        //check & auth
#if 0
        std::string pass;
        RTHiredisRemote::Instance().CmdGet(pUserid, pass);
        if (pass.compare(pPass)!=0) {
            LE("OnLogin pass not same redis error\n");
            return;
        }
#endif
        m_userId = pUserid;
        m_token = pPass;
        m_nname = pNname;
    }
    //if (ok) {
    if (false) {
        std::string sid;
        //store userid & pass
        CRTConnManager::ConnectionInfo* pci = new CRTConnManager::ConnectionInfo();
        if (pci) {
            GenericSessionId(sid);
            m_connectorId = CRTConnManager::Instance().ConnectorId();
            pci->_connId = sid;
            pci->_connAddr = CRTConnManager::Instance().ConnectorIp();
            pci->_connPort = CRTConnManager::Instance().ConnectorPort();
            pci->_userId = pUserid;
            pci->_token = pPass;
            pci->_pConn = NULL;
            pci->_connType = CONNECTIONTYPE::_chttp;
            pci->_flag = 1;
            std::string uid(pUserid);
            CRTConnManager::Instance().AddUser(CONNECTIONTYPE::_chttp, uid, pci);
        } else {
            LE("new ConnectionInfo error!!!\n");
        }
    } else {
        std::string uid(pUserid);
        CRTConnManager::ConnectionInfo* pci = NULL;
        CRTConnManager::Instance().AddUser(CONNECTIONTYPE::_chttp, uid, pci);
    }
    {
        // send response
        rapidjson::Document     jsonDoc;
        rapidjson::StringBuffer jsonStr;
        rapidjson::Writer<rapidjson::StringBuffer>   jsonWriter(jsonStr);
        jsonDoc.SetObject();
        if (ok) {
            jsonDoc.AddMember("login", "success", jsonDoc.GetAllocator());
        } else {
            jsonDoc.AddMember("login", "failed", jsonDoc.GetAllocator());
        }
        jsonDoc.Accept(jsonWriter);
        SendResponse(HPS_OK, jsonStr.GetString());
    }
}
Esempio n. 12
0
int ServerProcessor::InitiateHolePunch(int sockfd,string fruid,bool udp,bool sameNet){
  int len=0;
  string msg,command("friendaddress");
  GetAddress(fruid,msg,udp,sameNet);
  msg+=colon;
  msg+=fruid;
  SendResponse(sockfd,command,msg);
  return 0;
}
Esempio n. 13
0
void Server::HandleHELP(Client *pClient, char *szHelp) // respond with help
{
//	if (szHelp[0] == '\0') 
		SendResponse(pClient, 214, "The following commands are implimented: CDUP CWD DELE HELP MKD NLST NOOP LIST PASS PORT PWD QUIT RETR RMD RNFR RNTO STOR SYST TYPE USER") ;
//	else if (stricmp(szHelp, "HELP") == 0)
//	{
//		SendResponse(pClient, 214, "Syntax: HELP <command>") ;
//	}
}
nsresult
PresentationRequestParent::DoRequest(const BuildTransportRequest& aRequest)
{
  MOZ_ASSERT(mService);

  // Validate the accessibility (primarily for receiver side) so that a
  // compromised child process can't fake the ID.
  if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())->
                  IsSessionAccessible(aRequest.sessionId(), aRequest.role(), OtherPid()))) {
    return SendResponse(NS_ERROR_DOM_SECURITY_ERR);
  }

  nsresult rv = mService->BuildTransport(aRequest.sessionId(), aRequest.role());
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return SendResponse(rv);
  }
  return SendResponse(NS_OK);
}
Esempio n. 15
0
int CWebServer::SendErrorResponse(const HTTPRequest& request, int errorType, HTTPMethod method) const
{
  struct MHD_Response *response = nullptr;
  int ret = CreateErrorResponse(request.connection, errorType, method, response);
  if (ret == MHD_NO)
    return MHD_NO;

  return SendResponse(request, errorType, response);
}
Esempio n. 16
0
bool_t HttpMsgNotFound::Dispatch(serial_t uidx, HttpMsgReq *req)
{
	bool_t ret = FALSE;

	ret = SendResponse(uidx, HTTP::STATUS_NOT_FOUND, "404 Not Found", 13);
	if(!ret) { ECILA_TRACE(); return FALSE; }

	return TRUE;
}
Esempio n. 17
0
static VOID ProcessRequest(PHttpContext ctx) {
	char body[1024];
    char label = 'A';
    int totalSize;

    totalSize=sprintf(body, mapFormat);
 	KeyValueNode *curr = ctx->queryList.next;	
    while (curr != &ctx->queryList) {
        int size;
	    if ((size=ProcessEntry(body+totalSize, curr, label++)) == -1) {
            SendResponse(ctx, "Invalid Request", FALSE);
            return;
        }
        totalSize += size;
        curr = curr->next;
	}
 		 
	SendResponse(ctx, body, TRUE);
}
void RTConnectionTcp::OnLogout(const char* pUserid)
{
    std::string uid(pUserid);
    RTConnectionManager::Instance()->DelUser(CONNECTIONTYPE::_ctcp, uid);
    m_userId = "";
    std::string resp;
    GenericResponse(SIGNALTYPE::reqlogout, MSGTYPE::meeting, 1, RTCommCode::_ok, GetRTCommStatus(RTCommCode::_ok), resp);
    SendResponse(0, resp.c_str());
    return;
}
Esempio n. 19
0
void CI2CEchoServer::Run (void)
{
	while (1)
	{
		if (ReceiveRequest ())
		{
			SendResponse ();
		}
	}
}
Esempio n. 20
0
//********************************************************************************************************
// 函数名称:TransfersReplyHandle
// 输入参数:无
// 输出参数:无
// 功能描述:传输应答帧处理
//********************************************************************************************************
void TransfersReplyHandle(void)
{
	uint16_t	CRC_OR_LRC;
	*ADUData.ADUBuffPtr = ADUData.Address;	  								// 设备地址
	CRC_OR_LRC = Modbus_CRC16(ADUData.ADUBuffPtr,ADUData.ADULength-2);		// 计算CRC (ADU中CRC前的数据)
	*(ADUData.ADUBuffPtr+ADUData.ADULength-1) = (uint8_t)(CRC_OR_LRC/0x100);	// CRC Hi or LRC Hi 
	*(ADUData.ADUBuffPtr+ADUData.ADULength-2) = (uint8_t)CRC_OR_LRC;			// CRC Hi or LRC Hi 

	SendResponse(ADUData.ADUBuffPtr,ADUData.ADULength);
}
void Connection::SendStarbaseSet(long sector, char action, char exit_mode)
{
	StarbaseSet starbase_set;
	memset(&starbase_set, 0, sizeof(starbase_set));
	starbase_set.StarbaseID = sector;
	starbase_set.Action = action;
	starbase_set.ExitMode = exit_mode;

	SendResponse(ENB_OPCODE_004F_STARBASE_SET, (unsigned char *) &starbase_set, sizeof(starbase_set));
}
Esempio n. 22
0
void Server::HandleRETR(Client *pClient, char *szFileName) // retrieve file from server
{
	FILE *pFile ;
	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(pClient->GetCurrentDir()) ;

	if (pClient->GetType() == I_TYPE) pFile = fopen(szFileName, "rb") ;
	else pFile = fopen(szFileName, "rb") ;

	::ReleaseMutex(m_hDiskMutex);

	if (pFile == NULL) 
	{
		SendResponse(pClient, 550, "No such file or directory.") ;
		return ;
	}

	if (!pClient->ConnectDTL())
	{
		SendResponse(pClient, 500, "Error opening connection.") ;
		return ;
	}
	SendResponse(pClient, 150, "Opening data connection.") ;
	SOCKET *phSocket = pClient->GetDTL() ;

	char szBuffer[256] ;
	int iRead ;
	while (!feof(pFile) || iRead == 256)
	{
		iRead = fread(szBuffer, sizeof(char), 256, pFile) ; 
		send((*phSocket), szBuffer, iRead, 0) ;
	}
	closesocket((*phSocket));
	(*phSocket) = -1 ;
	fclose(pFile) ;

	SendResponse(pClient, 226, "Transfer complete.") ;

	::WaitForSingleObject(m_hDiskMutex, INFINITE);
	SetCurrentDirectory(m_szMainDir) ;
	::ReleaseMutex(m_hDiskMutex);
}
void LRTGroupSession::OnLogin(pms::EServerCmd cmd, pms::EModuleType module, const std::string& msg)
{
    LI("%s was called\n", __FUNCTION__);
    pms::Login login;
    if (!login.ParseFromString(msg)) {
        LE("login.ParseFromString error\n");
    }

    m_userid = login.usr_from();
    m_token = login.usr_token();
    LI("Onlogin user:%s login\n", m_userid.c_str());
    std::string sid;
    {
        //store userid & pass
        LRTConnManager::ConnectionInfo* pci = new LRTConnManager::ConnectionInfo();
        if (pci) {
            GenericSessionId(sid);
            pci->_connId = sid;
            pci->_userId = m_userid;
            pci->_token = m_token;
            pci->_pConn = this;
            pci->_connType = pms::EConnType::TTCP;
            pci->_flag = 1;
            LRTConnManager::Instance().AddUser(pms::EConnType::TTCP, m_userid, pci);
            //LRTConnManager::Instance().ConnectionConnNotify(m_userId, m_token);

            // send response
            std::string resp;
            GenericResponse(pms::EServerCmd::CLOGIN, module, 0, resp);
            SendResponse(0, resp.c_str());
            m_login = true;
            return;
        } else {
            LE("new ConnectionInfo error userid:%s\n", m_userid.c_str());
            std::string resp;
            GenericResponse(pms::EServerCmd::CLOGIN, module, 101, resp);
            SendResponse(0, resp.c_str());
            m_login = false;
            return;
        }
    }
}
void CRTConnHttp::OnHttpMessage(http_message* httpMsg)
{

	const char* pPath = httpMsg->request_path;
	//const char* pQuery = httpMsg->query_string;
	const char* pContent = httpMsg->body;
	int nContentLen = (int)httpMsg->body_size;
    if (!pPath || !pContent) {
        LE("OnHttpMessage pPath or pContent error\n");
		//SendResponse(HPS_NOT_ACCEPTABLE, "");
        return;
    }

    MEETMSG m_mmsg;
    std::string str(pContent, nContentLen), err("");
    m_mmsg.GetMsg(str, err);
    if (err.length() > 0) {
        LE("OnHttpMessage pContent error:%s\n", err.c_str());
		//SendResponse(HPS_NOT_ACCEPTABLE, "");
        return;
    }

    if (strcmp(pPath, "/login") == 0) {
        if (m_mmsg._from.length()>0 && m_mmsg._pass.length()>0 && m_mmsg._nname.length()>0) {
            OnLogin(m_mmsg._from.c_str(), m_mmsg._pass.c_str(), m_mmsg._nname.c_str());
        } else {
            LE("login params errors\n");
        }
    } else if(strcmp(pPath, "/sndmsg") == 0) {
        if (m_mmsg._from.length()>0) {
            const char* pContentDump = strdup(pContent);
            OnSndMsg(m_mmsg._from.c_str(), m_mmsg._mtype, pContentDump, (int)strlen(pContentDump));
            free((void*)pContentDump);
            pContentDump = NULL;
        } else {
            LE("sndmsg params errors\n");
        }
    } else if(strcmp(pPath, "/getmsg") == 0) {
        if (m_mmsg._from.length()>0) {
            OnGetMsg(m_mmsg._from.c_str(), m_mmsg._mtype);
        } else {
            LE("getmsg params errors\n");
        }
    } else if (strcmp(pPath, "/logout") == 0) {
        if (m_mmsg._from.length()>0) {
            OnLogout(m_mmsg._from.c_str());
        } else {
            LE("logout params errors\n");
        }
    } else {
        SendResponse(HPS_NOT_ACCEPTABLE, "");
        return;
    }
}
void RTConnectionTcp::OnKeepAlive(const char *pUserid)
{
    LI("RTConnectionTcp::OnKeepAlive pUserid:%s\n", pUserid);
    RTTcp::UpdateTimer();
    {
        std::string resp;
        GenericResponse(SIGNALTYPE::reqkeepalive, MSGTYPE::meeting, 2, RTCommCode::_ok, GetRTCommStatus(RTCommCode::_ok), resp);
        SendResponse(0, resp.c_str());
        return;
    }
}
Esempio n. 26
0
bool DeviceProxy::SendUpgradeDebugState(unsigned long cnt, const void* recvData, int recvDataLength)
{
	unsigned short status = 0;// 默认成功

	if (recvDataLength != 64)
		return SendResponse(cnt, 1, NULL, 0);
	
	//存到DeviceInfo的debugState中
	int iTemp[16];
	memcpy(iTemp, recvData, recvDataLength);
	CString strTemp;
	strTemp.Format(L"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
		iTemp[0], iTemp[1], iTemp[2], iTemp[3], iTemp[4], iTemp[5], iTemp[6], iTemp[7], iTemp[8], iTemp[9], iTemp[10], iTemp[11], iTemp[12], iTemp[13], iTemp[14], iTemp[15]);
	ConfigBlock::GetInstance()->SetStringParameter(L"DeviceInfo", L"debugState", strTemp);

	//
	ConfigBlock::GetInstance()->SetIntParameter(L"UpgradePara", L"flag", 1);
	ConfigBlock::GetInstance()->SetIntParameter(L"IRCalibrationPara", L"flag", 1);
	
	return SendResponse(cnt, status, NULL, 0);
}
Esempio n. 27
0
void EQWHTTPHandler::Exec() {
	m_sentHeaders = false;
	m_responseCode = "200";
//	printf("Request: %s, %s, %s, %s.\n", GetMethod().c_str(), GetUrl().c_str(), GetUri().c_str(), GetQueryString().c_str());

	SetHttpVersion("HTTP/1.0");
	AddResponseHeader("Connection", "close");

	if(GetUri().find("..") != std::string::npos) {
		SendResponse("403", "Forbidden");
		printf("%s is forbidden.\n", GetUri().c_str());
		return;
	}

	if(!CheckAuth()) {
		AddResponseHeader("Content-type", "text/plain");
		AddResponseHeader("WWW-Authenticate", "Basic realm=\"EQEmulator\"");
		SendResponse("401", "Authorization Required");
		SendString("Gotta Authenticate.");
	} else {
		std::string::size_type start = GetUri().find_first_not_of('/');
		std::string page;
		if(start != std::string::npos)
			page = GetUri().substr(start);
		else
			page = "index.html";
		SendPage(page);
	}
/*	if (!Detach()) {
		printf("Unable to detach...\n");
	}
	if(GetOutputLength() > 0) {
		//we cannot close yet
		m_closeOnFinish = true;
	} else {
		Close();
	}*/
	Free();	//the "app" side (us) is done with this connection too...
	Disconnect();
}
Esempio n. 28
0
int32 LoginRESTService::HandleGet(soap* soapClient)
{
    boost::asio::ip::address_v4 address(soapClient->ip);
    std::string ip_address = address.to_string();

    TC_LOG_DEBUG("server.rest", "[%s:%d] Handling GET request path=\"%s\"", ip_address.c_str(), soapClient->port, soapClient->path);

    static std::string const expectedPath = "/bnetserver/login/";
    if (strstr(soapClient->path, expectedPath.c_str()) != &soapClient->path[0])
        return 404;

    return SendResponse(soapClient, _formInputs);
}
Esempio n. 29
0
NS_IMETHODIMP
TelephonyRequestParent::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
        uint32_t aCount,
        const char16_t** aAdditionalInformation)
{
    nsTArray<nsString> additionalInformation;
    for (uint32_t i = 0; i < aCount; i++) {
        additionalInformation.AppendElement(nsDependentString(aAdditionalInformation[i]));
    }

    return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                        AdditionalInformation(additionalInformation)));
}
Esempio n. 30
0
NS_IMETHODIMP
TelephonyRequestParent::NotifyDialMMISuccessWithCallForwardingOptions(const nsAString& aStatusMessage,
        uint32_t aCount,
        nsIMobileCallForwardingOptions** aAdditionalInformation)
{
    nsTArray<nsIMobileCallForwardingOptions*> additionalInformation;
    for (uint32_t i = 0; i < aCount; i++) {
        additionalInformation.AppendElement(aAdditionalInformation[i]);
    }

    return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
                        AdditionalInformation(additionalInformation)));
}