/////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) // // See accompanying file COPYING.TXT file for licensing details. // /////////////////////////////////////////////////////////////////////////////// #ifndef CPPCMS_HTTP_PROTOCOL_H #define CPPCMS_HTTP_PROTOCOL_H #include namespace cppcms { namespace http { namespace protocol { inline bool separator(char c) { switch(c) { case '(': case ')': case '<': case '>': case '@': case ',': case ';': case ':': case '\\': case '"': case '/': case '[': case ']': case '?': case '=': case '{': case '}': case ' ': case '\t': return true; default: return false; } } inline char ascii_to_lower(char c) { if(c<'A' || c>'Z') return c; return c-'A'+'a'; } template It skip_ws(It p,It end) { while(p It tocken(It begin,It end) { char c; while(begin < end && 0x20<=(c=*begin) && c<=0x7E && !separator(c)) begin++; return begin; } template std::string unquote(It &begin,It end) { It p=begin; std::string result; if(p>=end || *p!='\"') return result; result.reserve(end-p); p++; while(p < end) { char c=*p++; if(c=='\"') { begin=p; return result; } else if(c=='\\' && pcr) return 1; // if(cl==cr) continue } if(lsizersize) return 1; return 0; } inline std::string quote(std::string const &input) { std::string result; result.reserve(input.size()); result+='"'; for(std::string::const_iterator p=input.begin();p!=input.end();++p) { char c=*p; if(0<=c && c<' ') { result+='\\'; } result+=c; } result+='"'; return result; } bool inline is_prefix_of(char const *prefix,std::string const &s) { std::string::const_iterator p=s.begin(),e=s.end(); p=skip_ws(p,e); char c; while((c=(*prefix++))!=0) { if(p==e) return false; if(ascii_to_lower(c)!=ascii_to_lower(*p++)) return false; } return true; } bool inline xdigit(int c) { return ('0'<=c && c<='9') || ('a'<=c && c<='f') || ('A'<=c && c<='F'); } } // protocol } // http } // cppcms #endif