1 /* This file is part of Metaproxy.
2 Copyright (C) Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <metaproxy/origin.hpp>
24 namespace mp = metaproxy_1;
26 mp::Origin::Origin() : m_address(""), m_origin_id(0), m_max_sockets(0)
30 void mp::Origin::set_max_sockets(int max_sockets)
32 m_max_sockets = max_sockets;
35 int mp::Origin::get_max_sockets()
40 void mp::Origin::set_tcpip_address(std::string addr, unsigned long s)
42 // assume first call is immediate reverse IP: cs_addrstr(COMSTACK)
43 // 2nd call might be X-Forwarded .. we use that for logging
44 std::string tmp = m_address;
48 m_address.append(" ");
49 m_address.append(tmp);
54 void mp::Origin::set_custom_session(const std::string &s)
59 std::string mp::Origin::get_forward_address() const
61 // return first component of address
62 // That's either first part of X-Forwarded component
63 size_t pos = m_address.find(' ');
64 if (pos != std::string::npos)
65 return m_address.substr(0, pos);
70 std::string mp::Origin::get_address()
72 // return last component of address
73 size_t pos = m_address.rfind(' ');
74 if (pos != std::string::npos)
75 return m_address.substr(pos + 1);
80 std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o)
82 // print first component of address
83 std::string a = o.get_forward_address();
88 os << ":" << o.m_origin_id;
89 if (o.m_custom_session.length())
90 os << ":" << o.m_custom_session;
97 * c-file-style: "Stroustrup"
98 * indent-tabs-mode: nil
100 * vim: shiftwidth=4 tabstop=8 expandtab