X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Forigin.cpp;h=e4f9415cf4494aa1b6edfb6a63d34957b6a5c685;hb=f3e215cc00b02e3d92016f095295af2ba4649e2f;hp=88d362bd8410dc98f5e4034e80fe74b0457779fa;hpb=73f37c91c144b070020df2f27472c09b62367acf;p=metaproxy-moved-to-github.git diff --git a/src/origin.cpp b/src/origin.cpp index 88d362b..e4f9415 100644 --- a/src/origin.cpp +++ b/src/origin.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2012 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,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "config.hpp" #include - +#include #include namespace mp = metaproxy_1; @@ -39,7 +39,15 @@ int mp::Origin::get_max_sockets() void mp::Origin::set_tcpip_address(std::string addr, unsigned long s) { + // 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; } @@ -48,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, 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;