Example #1
0
ResolvSocket::ResolvSocket(SocketHandler& h,Socket *parent)
:TcpSocket(h)
,m_bServer(false)
,m_parent(parent)
{
	SetLineProtocol();
}
Example #2
0
ChatSocket::ChatSocket(ISocketHandler& h)
:TcpSocket(h)
,m_state(STATE_LOGIN)
,m_name("")
{
	SetLineProtocol();
}
Example #3
0
  MySocket(ISocketHandler& h,bool one) : TcpSocket(h), m_b_client(false), m_b_one(one), m_b_created(false), m_b_active(false) {
    gettime(&m_create, NULL);
    SetLineProtocol();
#ifdef HAVE_OPENSSL
    if (g_b_ssl)
      EnableSSL();
#endif
    if (g_max_connections && !m_b_one && Handler().GetCount() >= g_max_connections)
    {
      fprintf(stderr, "\nConnection limit reached: %d, continuing in single connection stress mode\n", (int)g_max_connections);
      if (g_b_off)
        printreport_reset();
      g_b_limit = true;
      m_b_one = true;
      //
      g_b_flood = g_b_repeat;
    }
#ifndef USE_EPOLL
    if (!m_b_one && Handler().GetCount() >= Handler().MaxCount() - 17)
    {
      fprintf(stderr, "\nFD_SETSIZE connection limit reached: %d, continuing in single connection stress mode\n", (int)Handler().GetCount());
      if (g_b_off)
        printreport_reset();
      g_b_limit = true;
      m_b_one = true;
      //
      g_b_flood = g_b_repeat;
    }
#endif
  }
Example #4
0
ProtocolSocket::ProtocolSocket(ISocketHandler& h)
    :TcpSocket(h)
{
    SetLineProtocol(false);

    m_pIOBuffer = new IOBuffer();
    m_pIOBuffer->AllocIOBuf(PACKETIO_SIZE);
}
Example #5
0
    MySocket(ISocketHandler& h) : TcpSocket(h) {
        SetLineProtocol();
#ifdef HAVE_OPENSSL
        if (g_b_ssl)
            EnableSSL();
#endif
        if (g_b_nobuf)
            DisableInputBuffer();
    }
CTeleSerialConsoleOverTcp::CTeleSerialConsoleOverTcp(ISocketHandler& h, std::string strSocketName)
        :TcpSocket(h)
{
    SetLineProtocol();

    m_enLoginStatus = LoginStatusNotLogin;

    //SetSockName(strSocketName);

    m_strLastCmd = "";

    m_ttLastUpdate = 0;
    m_bAutoDumpPJ = false;
    m_bAutoDumpUser = false;
}
Example #7
0
HTTPSocket::HTTPSocket(ISocketHandler& h)
:TcpSocket(h)
,m_first(true)
,m_header(true)
,m_http_version("HTTP/1.0")
,m_request(false)
,m_response(false)
,m_body_size_left(0)
,m_b_http_1_1(false)
,m_b_keepalive(false)
,m_b_chunked(false)
,m_chunk_size(0)
,m_chunk_state(0)
{
	SetLineProtocol();
	DisableInputBuffer();
}
Example #8
0
UBSocket::UBSocket(ISocketHandler& h) :
    TcpSocket(h),
    m_prompt(),
    m_account(),
    m_popeditor(false),
    m_popLast(false),
    m_editors(),
    m_nexteditor(NULL),
    m_forcer(NULL),
    m_lowforced(false),
    m_forced(false),
    m_highforced(false),
    m_hascolor(true),
    m_colorcode('`')
{
    SetLineProtocol();
}
Example #9
0
void HTTPSocket::Reset()
{
	m_first = true;
	m_header = true;
	m_request = false;
	m_response = false;
	SetLineProtocol(true);
        while (m_response_header.size())
        {
                string_m::iterator it = m_response_header.begin();
                m_response_header.erase(it);
        }
        while (m_response_header_append.size())
        {
                std::list<std::pair<std::string, std::string> >::iterator it = m_response_header_append.begin();
                m_response_header_append.erase(it);
        }

}
Example #10
0
void HTTPSocket::OnRawData(const char *buf,size_t len)
{
	if (!m_header)
	{
		if (m_b_chunked)
		{
			size_t ptr = 0;
			while (ptr < len)
			{
				switch (m_chunk_state)
				{
				case 4:
					while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n"))
						m_chunk_line += buf[ptr++];
					if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n")
					{
						OnDataComplete();
						// prepare for next request(or response)
						m_b_chunked = false;
						SetLineProtocol( true );
						m_first = true;
						m_header = true;
						m_body_size_left = 0;
						if (len - ptr > 0)
						{
							char tmp[TCP_BUFSIZE_READ];
							memcpy(tmp, buf + ptr, len - ptr);
							tmp[len - ptr] = 0;
							OnRead( tmp, len - ptr );
							ptr = len;
						}
					}
					break;
				case 0:
					while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n"))
						m_chunk_line += buf[ptr++];
					if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n")
					{
						m_chunk_line.resize(m_chunk_line.size() - 2);
						Parse pa(m_chunk_line, ";");
						std::string size_str = pa.getword();
						m_chunk_size = Utility::hex2unsigned(size_str);
						if (!m_chunk_size)
						{
							m_chunk_state = 4;
							m_chunk_line = "";
						}
						else
						{
							m_chunk_state = 1;
							m_chunk_line = "";
						}
					}
					break;
				case 1:
					{
						size_t left = len - ptr;
						size_t sz = m_chunk_size < left ? m_chunk_size : left;
						OnData(buf + ptr, sz);
						m_chunk_size -= sz;
						ptr += sz;
						if (!m_chunk_size)
						{
							m_chunk_state = 2;
						}
					}
					break;
				case 2: // skip CR
					ptr++;
					m_chunk_state = 3;
					break;
				case 3: // skip LF
					ptr++;
					m_chunk_state = 0;
					break;
				}
			}
		}
		else
		if (!m_b_http_1_1 || !m_b_keepalive)
		{
			OnData(buf, len);
			/*
				request is HTTP/1.0 _or_ HTTP/1.1 and not keep-alive

				This means we destroy the connection after the response has been delivered,
				hence no need to reset all internal state variables for a new incoming
				request.
			*/
			m_body_size_left -= len;
			if (!m_body_size_left)
			{
				OnDataComplete();
			}
		}
		else
		{
			size_t sz = m_body_size_left < len ? m_body_size_left : len;
			OnData(buf, sz);
			m_body_size_left -= sz;
			if (!m_body_size_left)
			{
				OnDataComplete();
				// prepare for next request(or response)
				SetLineProtocol( true );
				m_first = true;
				m_header = true;
				m_body_size_left = 0;
				if (len - sz > 0)
				{
					char tmp[TCP_BUFSIZE_READ];
					memcpy(tmp, buf + sz, len - sz);
					tmp[len - sz] = 0;
					OnRead( tmp, len - sz );
				}
			}
		}
	}
}
Example #11
0
void HTTPSocket::OnLine(const std::string& line)
{
	if (m_first)
	{
		Parse pa(line);
		std::string str = pa.getword();
		if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response
		{
			m_http_version = str;
			m_status = pa.getword();
			m_status_text = pa.getrest();
			m_response = true;
		}
		else // request
		{
			m_method = str;
			m_url = pa.getword();
			size_t spl = m_url.find("?");
			if (spl != std::string::npos)
			{
				m_uri = m_url.substr(0,spl);
				m_query_string = m_url.substr(spl + 1);
			}
			else
			{
				m_uri = m_url;
				m_query_string = "";
			}
			m_http_version = pa.getword();
			m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1";
			m_b_keepalive = m_b_http_1_1;
			m_request = true;
		}
		m_first = false;
		OnFirst();
		return;
	}
	if (!line.size())
	{
		if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive || m_b_chunked)
		{
			SetLineProtocol(false);
			m_header = false;
		}
		OnHeaderComplete();
		if (!m_body_size_left && !m_b_chunked)
		{
			OnDataComplete();
		}
		return;
	}
	Parse pa(line,":");
	std::string key = pa.getword();
	std::string value = pa.getrest();
	OnHeader(key,value);
	if (Utility::ToLower(key) == "content-length")
	{
		m_body_size_left = atol(value.c_str());
	}
	if (m_b_http_1_1 && Utility::ToLower(key) == "connection")
	{
		m_b_keepalive = Utility::ToLower(value) != "close";
	}
	if (Utility::ToLower(key) == "transfer-encoding" && Utility::ToLower(value) == "chunked")
	{
		m_b_chunked = true;
	}
	/* If remote end tells us to keep connection alive, and we're operating
	in http/1.1 mode (not http/1.0 mode), then we mark the socket to be
	retained. */
#ifdef ENABLE_POOL
	if (m_b_http_1_1 && m_b_keepalive)
	{
		SetRetain();
	}
#endif
}
Example #12
0
	lSocket(ISocketHandler& h, bool first = false) : TcpSocket(h), IEventOwner(static_cast<evHandler&>(h)), m_id(0), m_first(first) {
		SetLineProtocol();
		lc++;
	}
Example #13
0
	MyClient(SocketHandler& h) : TcpSocket(h) {
		SetLineProtocol();
	}
Example #14
0
	IOSocket(ISocketHandler& h) : TcpSocket(h) {
		SetLineProtocol();
	}
Example #15
0
	tSocket(ISocketHandler& h, const std::string& host, int port) : TcpSocket(h), m_host(host)
	{
		SetLineProtocol();
		Open(host, port);
	}
Example #16
0
	void OnAccept() {
		SetLineProtocol();
	}
ServerSocket::ServerSocket(ISocketHandler& h)
:TcpSocket(h)
{
	SetLineProtocol();
}