[cpp-sp COMMIT] /branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp
noreply at shibboleth.net
noreply at shibboleth.net
Mon Oct 15 15:07:24 EDT 2012
Author: scantor
Date: Mon Oct 15 15:07:24 2012
New Revision: 3788
URL: http://svn.shibboleth.net/view/cpp-sp?rev=3788&view=rev
Log:
https://issues.shibboleth.net/jira/browse/SSPCPP-447
Modified:
branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp
Modified: branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp?rev=3788&r1=3787&r2=3788&view=diff
==============================================================================
--- branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp (original)
+++ branches/REL_2/shibsp/impl/StorageServiceSessionCache.cpp Mon Oct 15 15:07:24 2012
@@ -75,7 +75,16 @@
using namespace boost;
using namespace std;
-namespace shibsp {
+namespace {
+
+ // Allows the cache to bind sessions to multiple client address
+ // families based on whatever this function returns.
+ static const char* getAddressFamily(const char* addr) {
+ if (strchr(addr, ':'))
+ return "6";
+ else
+ return "4";
+ }
class StoredSession;
class SSCache : public SessionCacheEx
@@ -247,10 +256,7 @@
const char* saddr = m_obj["client_addr"].string();
DDF addrobj = m_obj["client_addr"].structure();
if (saddr && *saddr) {
- if (strchr(saddr, ':'))
- addrobj.addmember("6").string(saddr);
- else
- addrobj.addmember("4").string(saddr);
+ addrobj.addmember(getAddressFamily(saddr)).string(saddr);
}
}
@@ -304,20 +310,16 @@
return m_obj["client_addr"].first().string();
}
- const char* getClientAddressV4() const {
- return m_obj["client_addr"]["4"].string();
- }
- const char* getClientAddressV6() const {
- return m_obj["client_addr"]["6"].string();
+ const char* getClientAddress(const char* family) const {
+ if (family)
+ return m_obj["client_addr"][family].string();
+ return nullptr;
}
void setClientAddress(const char* client_addr) {
DDF obj = m_obj["client_addr"];
if (!obj.isstruct())
obj = m_obj.addmember("client_addr").structure();
- if (strchr(client_addr, ':'))
- obj.addmember("6").string(client_addr);
- else
- obj.addmember("4").string(client_addr);
+ obj.addmember(getAddressFamily(client_addr)).string(client_addr);
}
const char* getEntityID() const {
@@ -459,11 +461,7 @@
// Address check?
if (client_addr) {
- const char* saddr = nullptr;
- if (strchr(client_addr, ':'))
- saddr = getClientAddressV6();
- else
- saddr = getClientAddressV4();
+ const char* saddr = getClientAddress(getAddressFamily(client_addr));
if (saddr && *saddr) {
if (!XMLString::equals(saddr, client_addr)) {
m_cache->m_log.warn("client address mismatch, client (%s), session (%s)", client_addr, saddr);
@@ -573,13 +571,9 @@
if (client_addr) {
short attempts = 0;
do {
- const char* saddr = nullptr;
- if (strchr(client_addr, ':'))
- saddr = getClientAddressV6();
- else
- saddr = getClientAddressV4();
- // Something snuck in and bound the session to this address type, so it better match what we have.
+ const char* saddr = getClientAddress(getAddressFamily(client_addr));
if (saddr) {
+ // Something snuck in and bound the session to this address type, so it better match what we have.
if (!XMLString::equals(saddr, client_addr)) {
m_cache->m_log.warn("client address mismatch, client (%s), session (%s)", client_addr, saddr);
throw RetryableProfileException(
@@ -1182,10 +1176,7 @@
string caddr(httpRequest.getRemoteAddr());
if (!caddr.empty()) {
DDF addrobj = obj.addmember("client_addr").structure();
- if (caddr.find(':') != string::npos)
- addrobj.addmember("6").string(caddr.c_str());
- else
- addrobj.addmember("4").string(caddr.c_str());
+ addrobj.addmember(getAddressFamily(caddr.c_str())).string(caddr.c_str());
}
if (issuer)
@@ -2037,11 +2028,7 @@
istringstream src(record);
src >> sessionobj;
ver = sessionobj["version"].integer();
- const char* saddr = nullptr;
- if (strchr(client_addr, ':'))
- saddr = sessionobj["client_addr"]["6"].string();
- else
- saddr = sessionobj["client_addr"]["4"].string();
+ const char* saddr = sessionobj["client_addr"][getAddressFamily(client_addr)].string();
[... 16 lines stripped ...]
More information about the commits
mailing list