Replace tabs with spaces in more files.
--HG-- branch : trunk
This commit is contained in:
1 parent
b0694d7e5e
commit
d230302b16
602 files changed
+41367
-41366
No files matched your search
+263
-263
@@ -1,6 +1,6 @@
|
||||
/** \file ResolvSocket.cpp
|
||||
** \date 2005-03-24
|
||||
** \author grymse@alhem.net
|
||||
** \date 2005-03-24
|
||||
** \author grymse@alhem.net
|
||||
**/
|
||||
/*
|
||||
Copyright (C) 2004-2007 Anders Hedstrom
|
||||
@@ -69,7 +69,7 @@ ResolvSocket::ResolvSocket(ISocketHandler& h)
|
||||
#endif
|
||||
,m_cached(false)
|
||||
{
|
||||
SetLineProtocol();
|
||||
SetLineProtocol();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, const std::string&
|
||||
#endif
|
||||
,m_cached(false)
|
||||
{
|
||||
SetLineProtocol();
|
||||
SetLineProtocol();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, ipaddr_t a)
|
||||
#endif
|
||||
,m_cached(false)
|
||||
{
|
||||
SetLineProtocol();
|
||||
SetLineProtocol();
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, in6_addr& a)
|
||||
,m_resolv_address6(a)
|
||||
,m_cached(false)
|
||||
{
|
||||
SetLineProtocol();
|
||||
SetLineProtocol();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -125,145 +125,145 @@ ResolvSocket::~ResolvSocket()
|
||||
|
||||
void ResolvSocket::OnLine(const std::string& line)
|
||||
{
|
||||
Parse pa(line, ":");
|
||||
if (m_bServer)
|
||||
{
|
||||
m_query = pa.getword();
|
||||
m_data = pa.getrest();
|
||||
DEB( fprintf(stderr, " *** ResolvSocket server; query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
|
||||
// %! check cache
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
if (m_cache[m_query].find(m_data) != m_cache[m_query].end())
|
||||
{
|
||||
if (time(NULL) - m_cache_to[m_query][m_data] < 3600) // ttl
|
||||
{
|
||||
std::string result = m_cache[m_query][m_data];
|
||||
Parse pa(line, ":");
|
||||
if (m_bServer)
|
||||
{
|
||||
m_query = pa.getword();
|
||||
m_data = pa.getrest();
|
||||
DEB( fprintf(stderr, " *** ResolvSocket server; query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
|
||||
// %! check cache
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
if (m_cache[m_query].find(m_data) != m_cache[m_query].end())
|
||||
{
|
||||
if (time(NULL) - m_cache_to[m_query][m_data] < 3600) // ttl
|
||||
{
|
||||
std::string result = m_cache[m_query][m_data];
|
||||
DEB(fprintf(stderr, " *** Returning cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), result.c_str());)
|
||||
Send("Cached\n");
|
||||
if (!result.size()) /* failed */
|
||||
{
|
||||
Send("Failed\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
if (m_query == "gethostbyname")
|
||||
{
|
||||
Send("A: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
Send("Cached\n");
|
||||
if (!result.size()) /* failed */
|
||||
{
|
||||
Send("Failed\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
if (m_query == "gethostbyname")
|
||||
{
|
||||
Send("A: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
if (m_query == "gethostbyname2")
|
||||
{
|
||||
Send("AAAA: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
if (m_query == "gethostbyname2")
|
||||
{
|
||||
Send("AAAA: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
if (m_query == "gethostbyaddr")
|
||||
{
|
||||
Send("Name: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Detach()) // detach failed?
|
||||
{
|
||||
SetCloseAndDelete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::string key = pa.getword();
|
||||
std::string value = pa.getrest();
|
||||
DEB( fprintf(stderr, " *** ResolvSocket response; %s: %s\n", key.c_str(), value.c_str());)
|
||||
if (m_query == "gethostbyaddr")
|
||||
{
|
||||
Send("Name: " + result + "\n\n");
|
||||
SetCloseAndDelete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Detach()) // detach failed?
|
||||
{
|
||||
SetCloseAndDelete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::string key = pa.getword();
|
||||
std::string value = pa.getrest();
|
||||
DEB( fprintf(stderr, " *** ResolvSocket response; %s: %s\n", key.c_str(), value.c_str());)
|
||||
|
||||
if (key == "Cached")
|
||||
{
|
||||
m_cached = true;
|
||||
}
|
||||
else
|
||||
if (key == "Failed" && m_parent)
|
||||
{
|
||||
DEB( fprintf(stderr, " ************ Resolve failed\n");)
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnResolveFailed(m_resolv_id);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
if (key == "Cached")
|
||||
{
|
||||
m_cached = true;
|
||||
}
|
||||
else
|
||||
if (key == "Failed" && m_parent)
|
||||
{
|
||||
DEB( fprintf(stderr, " ************ Resolve failed\n");)
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnResolveFailed(m_resolv_id);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
else
|
||||
if (key == "Name" && !m_resolv_host.size() && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnReverseResolved(m_resolv_id, value);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
else
|
||||
if (key == "Name" && !m_resolv_host.size() && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnReverseResolved(m_resolv_id, value);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
else
|
||||
if (key == "A" && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
ipaddr_t l;
|
||||
Utility::u2ip(value, l); // ip2ipaddr_t
|
||||
m_parent -> OnResolved(m_resolv_id, l, m_resolv_port);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
else
|
||||
if (key == "A" && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
ipaddr_t l;
|
||||
Utility::u2ip(value, l); // ip2ipaddr_t
|
||||
m_parent -> OnResolved(m_resolv_id, l, m_resolv_port);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL; // always use first ip in case there are several
|
||||
}
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL; // always use first ip in case there are several
|
||||
}
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
else
|
||||
if (key == "AAAA" && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
in6_addr a;
|
||||
Utility::u2ip(value, a);
|
||||
m_parent -> OnResolved(m_resolv_id, a, m_resolv_port);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
else
|
||||
if (key == "AAAA" && m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
in6_addr a;
|
||||
Utility::u2ip(value, a);
|
||||
m_parent -> OnResolved(m_resolv_id, a, m_resolv_port);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -271,160 +271,160 @@ DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(),
|
||||
|
||||
void ResolvSocket::OnDetached()
|
||||
{
|
||||
DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
|
||||
if (m_query == "gethostbyname")
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
if (Utility::u2ip(m_data, sa))
|
||||
{
|
||||
std::string ip;
|
||||
Utility::l2ip(sa.sin_addr, ip);
|
||||
Send("A: " + ip + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Failed\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
|
||||
if (m_query == "gethostbyname")
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
if (Utility::u2ip(m_data, sa))
|
||||
{
|
||||
std::string ip;
|
||||
Utility::l2ip(sa.sin_addr, ip);
|
||||
Send("A: " + ip + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Failed\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
if (m_query == "gethostbyname2")
|
||||
{
|
||||
struct sockaddr_in6 sa;
|
||||
if (Utility::u2ip(m_data, sa))
|
||||
{
|
||||
std::string ip;
|
||||
Utility::l2ip(sa.sin6_addr, ip);
|
||||
Send("AAAA: " + ip + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Failed\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
if (m_query == "gethostbyname2")
|
||||
{
|
||||
struct sockaddr_in6 sa;
|
||||
if (Utility::u2ip(m_data, sa))
|
||||
{
|
||||
std::string ip;
|
||||
Utility::l2ip(sa.sin6_addr, ip);
|
||||
Send("AAAA: " + ip + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Failed\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
if (m_query == "gethostbyaddr")
|
||||
{
|
||||
if (Utility::isipv4( m_data ))
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
|
||||
{
|
||||
Send("Failed: convert to sockaddr_in failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name;
|
||||
if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
|
||||
{
|
||||
Send("Failed: ipv4 reverse lookup of " + m_data + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Name: " + name + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (m_query == "gethostbyaddr")
|
||||
{
|
||||
if (Utility::isipv4( m_data ))
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
|
||||
{
|
||||
Send("Failed: convert to sockaddr_in failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name;
|
||||
if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
|
||||
{
|
||||
Send("Failed: ipv4 reverse lookup of " + m_data + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Name: " + name + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
if (Utility::isipv6( m_data ))
|
||||
{
|
||||
struct sockaddr_in6 sa;
|
||||
if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
|
||||
{
|
||||
Send("Failed: convert to sockaddr_in6 failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name;
|
||||
if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
|
||||
{
|
||||
Send("Failed: ipv6 reverse lookup of " + m_data + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Name: " + name + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (Utility::isipv6( m_data ))
|
||||
{
|
||||
struct sockaddr_in6 sa;
|
||||
if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
|
||||
{
|
||||
Send("Failed: convert to sockaddr_in6 failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name;
|
||||
if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
|
||||
{
|
||||
Send("Failed: ipv6 reverse lookup of " + m_data + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Send("Name: " + name + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
Send("Failed: malformed address\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string msg = "Unknown query type: " + m_query;
|
||||
Handler().LogError(this, "OnDetached", 0, msg);
|
||||
Send("Unknown\n\n");
|
||||
}
|
||||
SetCloseAndDelete();
|
||||
{
|
||||
Send("Failed: malformed address\n");
|
||||
}
|
||||
Send("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string msg = "Unknown query type: " + m_query;
|
||||
Handler().LogError(this, "OnDetached", 0, msg);
|
||||
Send("Unknown\n\n");
|
||||
}
|
||||
SetCloseAndDelete();
|
||||
}
|
||||
|
||||
|
||||
void ResolvSocket::OnConnect()
|
||||
{
|
||||
if (!m_resolv_host.empty())
|
||||
{
|
||||
if (!m_resolv_host.empty())
|
||||
{
|
||||
#ifdef ENABLE_IPV6
|
||||
std::string msg = (m_resolve_ipv6 ? "gethostbyname2 " : "gethostbyname ") + m_resolv_host + "\n";
|
||||
m_query = m_resolve_ipv6 ? "gethostbyname2" : "gethostbyname";
|
||||
std::string msg = (m_resolve_ipv6 ? "gethostbyname2 " : "gethostbyname ") + m_resolv_host + "\n";
|
||||
m_query = m_resolve_ipv6 ? "gethostbyname2" : "gethostbyname";
|
||||
#else
|
||||
std::string msg = "gethostbyname " + m_resolv_host + "\n";
|
||||
m_query = "gethostbyname";
|
||||
std::string msg = "gethostbyname " + m_resolv_host + "\n";
|
||||
m_query = "gethostbyname";
|
||||
#endif
|
||||
m_data = m_resolv_host;
|
||||
Send( msg );
|
||||
return;
|
||||
}
|
||||
m_data = m_resolv_host;
|
||||
Send( msg );
|
||||
return;
|
||||
}
|
||||
#ifdef ENABLE_IPV6
|
||||
if (m_resolve_ipv6)
|
||||
{
|
||||
std::string tmp;
|
||||
Utility::l2ip(m_resolv_address6, tmp);
|
||||
m_query = "gethostbyaddr";
|
||||
m_data = tmp;
|
||||
std::string msg = "gethostbyaddr " + tmp + "\n";
|
||||
Send( msg );
|
||||
}
|
||||
if (m_resolve_ipv6)
|
||||
{
|
||||
std::string tmp;
|
||||
Utility::l2ip(m_resolv_address6, tmp);
|
||||
m_query = "gethostbyaddr";
|
||||
m_data = tmp;
|
||||
std::string msg = "gethostbyaddr " + tmp + "\n";
|
||||
Send( msg );
|
||||
}
|
||||
#endif
|
||||
std::string tmp;
|
||||
Utility::l2ip(m_resolv_address, tmp);
|
||||
m_query = "gethostbyaddr";
|
||||
m_data = tmp;
|
||||
std::string msg = "gethostbyaddr " + tmp + "\n";
|
||||
Send( msg );
|
||||
std::string tmp;
|
||||
Utility::l2ip(m_resolv_address, tmp);
|
||||
m_query = "gethostbyaddr";
|
||||
m_data = tmp;
|
||||
std::string msg = "gethostbyaddr " + tmp + "\n";
|
||||
Send( msg );
|
||||
}
|
||||
|
||||
|
||||
void ResolvSocket::OnDelete()
|
||||
{
|
||||
if (m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnResolveFailed(m_resolv_id);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
std::string value;
|
||||
if (m_parent)
|
||||
{
|
||||
if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
|
||||
{
|
||||
m_parent -> OnResolveFailed(m_resolv_id);
|
||||
}
|
||||
// update cache
|
||||
if (!m_cached)
|
||||
{
|
||||
Lock lock(m_cache_mutex);
|
||||
std::string value;
|
||||
DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
m_cache[m_query][m_data] = value;
|
||||
m_cache_to[m_query][m_data] = time(NULL);
|
||||
}
|
||||
m_parent = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user