From 3658759966cbadb7b50457d446f3436b6f7987da Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Sat, 02 Feb 2008 21:10:12 +0000 Subject: moved uri matching into separate procedure Signed-off-by: Michael Krelin --- (limited to 'lib/util.cc') diff --git a/lib/util.cc b/lib/util.cc index b7bc437..b85a377 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -351,6 +352,35 @@ namespace opkele { return u; } + bool uri_matches_realm(const string& uri,const string& realm) { + string nrealm = opkele::util::rfc_3986_normalize_uri(realm); + string nu = opkele::util::rfc_3986_normalize_uri(uri); + string::size_type pr = nrealm.find("://"); + string::size_type pu = nu.find("://"); + assert(!(pr==string::npos || pu==string::npos)); + pr += sizeof("://")-1; + pu += sizeof("://")-1; + if(!strncmp(nrealm.c_str()+pr,"*.",2)) { + pr = nrealm.find('.',pr); + pu = nu.find('.',pu); + assert(pr!=string::npos); + if(pu==string::npos) + return false; + // TODO: check for overgeneralized realm + } + string::size_type lr = nrealm.length(); + string::size_type lu = nu.length(); + if( (lu-pu) < (lr-pr) ) + return false; + pair mp = mismatch( + nrealm.c_str()+pr,nrealm.c_str()+lr, + nu.c_str()+pu); + if( (*(mp.first-1))!='/' + && !strchr("/?#",*mp.second) ) + return false; + return true; + } + string abi_demangle(const char *mn) { #ifndef HAVE_DEMANGLE return mn; -- cgit v0.9.0.2