X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Forigin.cpp;h=e4f9415cf4494aa1b6edfb6a63d34957b6a5c685;hb=a395969830b02ecb29a24d455d60edb394af77e4;hp=6901a92b7c6257b75bfdaf3a6ab545a47c61ba93;hpb=cdb9d2053fa54a0a2d7da1514164de3bbe52edb3;p=metaproxy-moved-to-github.git diff --git a/src/origin.cpp b/src/origin.cpp index 6901a92..e4f9415 100644 --- a/src/origin.cpp +++ b/src/origin.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -18,38 +18,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "config.hpp" #include - +#include #include namespace mp = metaproxy_1; -mp::Origin::Origin(std::string listen_host, - unsigned int listen_port) - : m_type(API), m_address(""), m_origin_id(0), - m_listen_host(listen_host), m_listen_port(listen_port), m_max_sockets(0) +mp::Origin::Origin() : m_address(""), m_origin_id(0), m_max_sockets(0) { } -std::string mp::Origin::listen_host() const -{ - return m_listen_host; -}; - -std::string & mp::Origin::listen_host() -{ - return m_listen_host; -}; - -unsigned int mp::Origin::listen_port() const -{ - return m_listen_port; -}; - -unsigned int & mp::Origin::listen_port() -{ - return m_listen_port; -}; - void mp::Origin::set_max_sockets(int max_sockets) { m_max_sockets = max_sockets; @@ -62,8 +39,15 @@ int mp::Origin::get_max_sockets() void mp::Origin::set_tcpip_address(std::string addr, unsigned long s) { - m_type = TCPIP; + // assume first call is immediate reverse IP: cs_addrstr(COMSTACK) + // 2nd call might be X-Forwarded .. we use that for logging + std::string tmp = m_address; m_address = addr; + if (tmp.length()) + { + m_address.append(" "); + m_address.append(tmp); + } m_origin_id = s; } @@ -72,15 +56,33 @@ void mp::Origin::set_custom_session(const std::string &s) m_custom_session = s; } +std::string mp::Origin::get_forward_address() const +{ + // return first component of address + // That's either first part of X-Forwarded component + size_t pos = m_address.find(' '); + if (pos != std::string::npos) + return m_address.substr(0, pos); + else + return m_address; +} + std::string mp::Origin::get_address() { - return m_address; + // return last component of address + size_t pos = m_address.rfind(' '); + if (pos != std::string::npos) + return m_address.substr(pos + 1); + else + return m_address; } -std::ostream& std::operator<<(std::ostream& os, mp::Origin& o) +std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o) { - if (o.m_address.length()) - os << o.m_address; + // print first component of address + std::string a = o.get_forward_address(); + if (a.length()) + os << a; else os << "0"; os << ":" << o.m_origin_id; @@ -88,7 +90,7 @@ std::ostream& std::operator<<(std::ostream& os, mp::Origin& o) os << ":" << o.m_custom_session; return os; } - + /* * Local variables: * c-basic-offset: 4