Esempio n. 1
0
BOOL CNNTPConnection::Group(LPCTSTR pszGroup, int &nArticles)
{
	if(!m_bConnected)
		return FALSE;
	
	CString strCmd = _T("GROUP ");
	strCmd += pszGroup;
	strCmd += _T("\r\n");

	if(!m_nntp.Send(strCmd, strCmd.GetLength()))
	{
		m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_3%>");//<%IDS_News_3%>_T("дÊý¾Ý´íÎó")
		return FALSE;
	}

	CString strInfo = _T("");
	int nRes = CommandResponse(strInfo);
	if(nRes != 2)
	{
		m_strErrorMsg = strInfo;
		return FALSE;
	}

	strInfo.Delete(0, 3);
	nArticles = atoi(strInfo);
	return TRUE;
}
Esempio n. 2
0
BOOL CNNTPConnection::LoginPass(LPCTSTR pszPwd)
{
	if(!m_bConnected)
		return FALSE;

	CString	strCmd = _T("AUTHINFO PASS ");
	strCmd += pszPwd;
	strCmd += _T("\r\n");

	if(!m_nntp.Send(strCmd, strCmd.GetLength()))
	{
		m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_2%>");//<%IDS_News_2%>_T("дÊý¾Ý´íÎó")
		return FALSE;
	}

	CString strInfo = _T("");
	int nRes = CommandResponse(strInfo);
	if(nRes != 2 && nRes != 3)
	{
		m_strErrorMsg = strInfo;
		return FALSE;
	}

	return TRUE;
}
Esempio n. 3
0
QString Client::ProcessCommand(QScriptValue req)
{
    QScriptValue cmd = req.property("command");
    QString response;

    // Basic sanity check
    if (!cmd.isValid())
    {
        response = CommandErrorResponse("invalid", "No command specified");
    }

    // Process greeting
    else if (cmd.toString() == "greeting")
    {
        QScriptValue message = req.property("message");

        if (!message.isValid())
        {
            response = CommandErrorResponse("greeting", "No message specified");
        }
        else
        {
            response = CommandResponse("greeting", "Hello server. Hope things are well!");
        }
    }

    // Process shutdown request
    else if (cmd.toString() == "shutdown")
    {
        response = CommandResponse("shutdown", "Goodbye!");
        shutdownRequested = true;
    }

    // Handle unrecognized requests
    else
    {
        response = CommandErrorResponse("invalid", "Unsupported command specified");
    }

    return response;
}
Esempio n. 4
0
BOOL CNNTPConnection::Connect(LPCTSTR pszHostName, LPCTSTR pszUser, LPCTSTR pszPassword, int nPort)
{
	USES_CONVERSION;

	if (!m_nntp.Create())
	{
		m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_4%>");//<%IDS_News_4%>_T("ͨÐųõʼ»¯Ê§°Ü")
		return FALSE;
	}

	if (!m_nntp.Connect(pszHostName, nPort))
	{
		m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_5%>");//<%IDS_News_5%>_T("Ö÷»úÁ¬½Óʧ°Ü")
		return FALSE;
	}
	else
	{
		m_bConnected = TRUE;
		
		CString	strInfo = _T("");
		int nRes = CommandResponse(strInfo);
		if(nRes != 2)
		{
			m_strErrorMsg = strInfo;
			Disconnect();
			return FALSE;
		}

		if(*pszUser)
		{
			if(!LoginUser(pszUser))
			{
				m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_6%>");//<%IDS_News_6%>_T("µÇ¼ʧ°Ü")
				Disconnect();
				return FALSE;
			}

			if(!LoginUser(pszPassword))
			{
				m_strErrorMsg = FuncGetStringFromIDS("<%IDS_News_7%>");//<%IDS_News_7%>_T("µÇ¼ʧ°Ü")
				Disconnect();
				return FALSE;
			}
		}

		return TRUE;
	}
}
Esempio n. 5
0
    CommandResponse CommandInterface::SendCommand(std::string cmd) {
        CURLcode rc;
        CURL *handle = connection->getHandle();

        last_response.clear();
        read_buffer.clear();
        std::ostringstream cmd_url;

        cmd_url << "http://" << connection->host() << ":" << connection->port() << "/" << cmd;
        last_cmd_url = cmd_url.str();


        curl_easy_setopt(handle, CURLOPT_USERAGENT, "curl/7.58.0");
        /* send all data to this function  */
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &read_buffer);
        curl_easy_setopt(handle, CURLOPT_URL, cmd_url.str().c_str());

        rc = curl_easy_perform(handle);

        if (rc != CURLE_OK) {
            throw std::runtime_error(curl_easy_strerror(rc));
        }

        // all responses are hidden in HTML comments ...
        std::regex response_comment_re("<!--(.*)-->", std::regex_constants::ECMAScript);
        std::smatch comment_match;
        if (!regex_search(read_buffer, comment_match, response_comment_re)) {
            throw std::runtime_error("parsing error, response not found ");
        }

        last_response = comment_match[1].str();
        if (last_response.empty()) {
            throw std::runtime_error("parsing error, response empty");
        }

        return CommandResponse(comment_match[1].str());
    }
Esempio n. 6
0
BOOL CNNTPConnection::Disconnect()
{
	int nRes = 0;
	BOOL bSuccess = FALSE;      
	
	if (m_bConnected)
	{
		CString	strCmd = _T("QUIT\r\n");
		if (!m_nntp.Send(strCmd, strCmd.GetLength()))
			TRACE(_T("Failed to send the QUIT command to the POP3 server\n"));
		
		CString strInfo = _T("");
		nRes = CommandResponse(strInfo);
		
		m_bConnected = FALSE;
	}
	else
		TRACE(_T("CNNTPConnection, Already disconnected\n"));
	
	m_nntp.Close();
	
	return nRes == 2;
}
Esempio n. 7
0
void ControlTaskBase::Respond(CommandStatus aStatus)
{
	mData.mpRspAcceptor->AcceptResponse(CommandResponse(aStatus), mData.mSequence);
}