*/
#include "config.hpp"
+#include <assert.h>
#include <metaproxy/origin.hpp>
#include <yaz/log.h>
#include <iostream>
void mp::Origin::set_tcpip_address(std::string addr, unsigned long s)
{
- // assume first call is immediate reverse IP: cs_addrstr(COMSTACK)
+ // assume first call is immediate reverse IP: + bind IP
// 2nd call might be X-Forwarded .. we use that for logging
std::string tmp = m_address;
m_address = addr;
m_address.append(" ");
m_address.append(tmp);
}
+ else
+ {
+ size_t pos = addr.find(' ');
+ assert (pos != std::string::npos);
+ }
m_origin_id = s;
}
std::string mp::Origin::get_address()
{
+ // return 2nd last component of address (last is listening IP)
+ size_t pos2 = m_address.rfind(' ');
+ if (pos2 != std::string::npos && pos2 > 0)
+ {
+ size_t pos1 = m_address.rfind(' ', pos2 - 1);
+ if (pos1 != std::string::npos)
+ return m_address.substr(pos1 + 1, pos2 - pos1 - 1);
+ else
+ return m_address.substr(0, pos2);
+ }
+ else
+ return m_address;
+}
+
+std::string mp::Origin::get_bind_address()
+{
// return last component of address
- size_t pos = m_address.rfind(' ');
- if (pos != std::string::npos)
- return m_address.substr(pos + 1);
+ size_t pos2 = m_address.rfind(' ');
+ if (pos2 != std::string::npos && pos2 > 0)
+ {
+ return m_address.substr(pos2 + 1);
+ }
else
return m_address;
}
+
std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o)
{
// print first component of address