summaryrefslogtreecommitdiffabout
path: root/lib/util.cc
Unidiff
Diffstat (limited to 'lib/util.cc') (more/less context) (show whitespace changes)
-rw-r--r--lib/util.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/util.cc b/lib/util.cc
index b7bc437..b85a377 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -2,12 +2,13 @@
2#include <cassert> 2#include <cassert>
3#include <cctype> 3#include <cctype>
4#include <cstring> 4#include <cstring>
5#include <vector> 5#include <vector>
6#include <string> 6#include <string>
7#include <stack> 7#include <stack>
8#include <algorithm>
8#include <openssl/bio.h> 9#include <openssl/bio.h>
9#include <openssl/evp.h> 10#include <openssl/evp.h>
10#include <openssl/hmac.h> 11#include <openssl/hmac.h>
11#include <curl/curl.h> 12#include <curl/curl.h>
12#include "opkele/util.h" 13#include "opkele/util.h"
13#include "opkele/exception.h" 14#include "opkele/exception.h"
@@ -348,12 +349,41 @@ namespace opkele {
348 u.erase(f); 349 u.erase(f);
349 } 350 }
350 } 351 }
351 return u; 352 return u;
352 } 353 }
353 354
355 bool uri_matches_realm(const string& uri,const string& realm) {
356 string nrealm = opkele::util::rfc_3986_normalize_uri(realm);
357 string nu = opkele::util::rfc_3986_normalize_uri(uri);
358 string::size_type pr = nrealm.find("://");
359 string::size_type pu = nu.find("://");
360 assert(!(pr==string::npos || pu==string::npos));
361 pr += sizeof("://")-1;
362 pu += sizeof("://")-1;
363 if(!strncmp(nrealm.c_str()+pr,"*.",2)) {
364 pr = nrealm.find('.',pr);
365 pu = nu.find('.',pu);
366 assert(pr!=string::npos);
367 if(pu==string::npos)
368 return false;
369 // TODO: check for overgeneralized realm
370 }
371 string::size_type lr = nrealm.length();
372 string::size_type lu = nu.length();
373 if( (lu-pu) < (lr-pr) )
374 return false;
375 pair<const char*,const char*> mp = mismatch(
376 nrealm.c_str()+pr,nrealm.c_str()+lr,
377 nu.c_str()+pu);
378 if( (*(mp.first-1))!='/'
379 && !strchr("/?#",*mp.second) )
380 return false;
381 return true;
382 }
383
354 string abi_demangle(const char *mn) { 384 string abi_demangle(const char *mn) {
355#ifndef HAVE_DEMANGLE 385#ifndef HAVE_DEMANGLE
356 return mn; 386 return mn;
357#else /* !HAVE_DEMANGLE */ 387#else /* !HAVE_DEMANGLE */
358 int dstat; 388 int dstat;
359 char *demangled = abi::__cxa_demangle(mn,0,0,&dstat); 389 char *demangled = abi::__cxa_demangle(mn,0,0,&dstat);