From a74c677c09774c02d3bc347525fb071f25d25697 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Mon, 25 Apr 2005 16:27:12 +0000 Subject: 1. bumped version to 0.0.1 2. added utility functions extracted from sitecing --- (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index a904569..7d44856 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -12,5 +12,6 @@ endif libkonforka_la_SOURCES = \ exception.cc \ + util.cc \ pointer_map.cc \ ${EXTRA_SOURCES} diff --git a/lib/util.cc b/lib/util.cc new file mode 100644 index 0000000..74039c6 --- a/dev/null +++ b/lib/util.cc @@ -0,0 +1,127 @@ +#include +#include +#include + +namespace konforka { + + /* + * XXX: this code is borrowed from sitecing as is, although it should be optimized. + */ + + string normalize_path(const string& p,int o) { + const char *s = p.c_str(); + if( s[0]=='.' && s[1]=='/' ) + s += 2; // skip leading './' + if(o&strip_leading_slash) + for(;(*s)=='/';s++); + string rv; + string::size_type notslash = 0; + for(;*s;s++) { + if(s[0]=='/') { + if(s[1]=='/') + continue; // skip duplicate slash + if(s[1]=='.' && s[2]=='/') { + // '/./' sequence encountered + s += 2; + continue; + } + } + if( + (o&restrict_dotdot) && ( + ( rv.empty() && s[0]=='.' && s[1]=='.' && s[2]=='/' ) // '^../' + || + ( s[0]=='/' && s[1]=='.' && s[2]=='.' && (s[3]=='/' || s[3]==0) ) // '/../' or '/..$' + ) + ) + throw restricted_sequence_error(CODEPOINT,"restricted updir (..) sequence encountered"); + rv += *s; + if( (*s) !='/' ) + notslash = rv.length(); + } + if(!(o&strip_trailing_slash)) + notslash++; + if(notslash