| base64.h | | base64.h | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 24 | |
| // | | // | |
| // You should have received a copy of the GNU Lesser General Public Licens
e | | // You should have received a copy of the GNU Lesser General Public Licens
e | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| // | | // | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| #ifndef CPPCMS_BASE64_H | | #ifndef CPPCMS_BASE64_H | |
| #define CPPCMS_BASE64_H | | #define CPPCMS_BASE64_H | |
| | | | |
| #include <cppcms/defs.h> | | #include <cppcms/defs.h> | |
| #include <string> | | #include <string> | |
|
| | | #include <iosfwd> | |
| | | | |
| namespace cppcms { | | namespace cppcms { | |
| /// | | /// | |
| /// \brief this namespace provides functions useful for modified Bas
e64 encoding for URL. | | /// \brief this namespace provides functions useful for modified Bas
e64 encoding for URL. | |
| /// This encoding does not insert newline characters, do not pad the
text with = character and | | /// This encoding does not insert newline characters, do not pad the
text with = character and | |
| /// use "_" and "-" instead of "+" and "/" characters reserved by UR
L format for special purposes. | | /// use "_" and "-" instead of "+" and "/" characters reserved by UR
L format for special purposes. | |
| /// | | /// | |
| namespace b64url { | | namespace b64url { | |
| | | | |
| /// | | /// | |
| | | | |
| skipping to change at line 51 | | skipping to change at line 52 | |
| /// | | /// | |
| int CPPCMS_API decoded_size(size_t s); | | int CPPCMS_API decoded_size(size_t s); | |
| | | | |
| /// | | /// | |
| /// Perform base64 URL encoding of the binary data in range [\a begi
n,\a end), and store it to output buffer | | /// Perform base64 URL encoding of the binary data in range [\a begi
n,\a end), and store it to output buffer | |
| /// \a target. The size of target storage should have a capacity cal
culated with encoded_size(end-begin). | | /// \a target. The size of target storage should have a capacity cal
culated with encoded_size(end-begin). | |
| /// | | /// | |
| /// Pointer to the first character directly after text string ends i
s returned. | | /// Pointer to the first character directly after text string ends i
s returned. | |
| /// | | /// | |
| unsigned char CPPCMS_API *encode(unsigned char const *begin,unsigned
char const *end,unsigned char *target); | | unsigned char CPPCMS_API *encode(unsigned char const *begin,unsigned
char const *end,unsigned char *target); | |
|
| | | /// | |
| | | /// Perform base64 URL encoding of the binary data in range [\a begi | |
| | | n,\a end), and write it to output stream | |
| | | /// | |
| | | void encode(unsigned char const *begin,unsigned char const *end,std: | |
| | | :ostream &output); | |
| | | | |
| /// | | /// | |
| /// Perform base64 URL decoding of the binary data in range [\a begi
n,\a end), and store it to output buffer | | /// Perform base64 URL decoding of the binary data in range [\a begi
n,\a end), and store it to output buffer | |
| /// \a target. The size of target storage should have a capacity cal
culated with encoded_size(end-begin). | | /// \a target. The size of target storage should have a capacity cal
culated with encoded_size(end-begin). | |
| /// | | /// | |
| /// Pointer to the first character directly after text string ends i
s returned. Invalid codes are substituted | | /// Pointer to the first character directly after text string ends i
s returned. Invalid codes are substituted | |
| /// by 0 values. | | /// by 0 values. | |
| /// | | /// | |
| /// | | /// | |
| unsigned char CPPCMS_API *decode(unsigned char const *begin,unsigned
char const *end,unsigned char *target); | | unsigned char CPPCMS_API *decode(unsigned char const *begin,unsigned
char const *end,unsigned char *target); | |
| | | | |
End of changes. 2 change blocks. |
| 0 lines changed or deleted | | 7 lines changed or added | |
|
| json.h | | json.h | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| // GNU Lesser General Public License for more details. | | // GNU Lesser General Public License for more details. | |
| // | | // | |
| // You should have received a copy of the GNU Lesser General Public Licens
e | | // You should have received a copy of the GNU Lesser General Public Licens
e | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| // | | // | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| #ifndef CPPCMS_JSON_H | | #ifndef CPPCMS_JSON_H | |
| #define CPPCMS_JSON_H | | #define CPPCMS_JSON_H | |
| | | | |
| #include <cppcms/defs.h> | | #include <cppcms/defs.h> | |
|
| | | #include <cppcms/string_key.h> | |
| #include <booster/copy_ptr.h> | | #include <booster/copy_ptr.h> | |
| #include <booster/backtrace.h> | | #include <booster/backtrace.h> | |
| #include <vector> | | #include <vector> | |
| #include <map> | | #include <map> | |
| #include <string> | | #include <string> | |
| #include <iostream> | | #include <iostream> | |
| #include <limits> | | #include <limits> | |
| | | | |
| namespace cppcms { | | namespace cppcms { | |
| /// | | /// | |
| | | | |
| skipping to change at line 60 | | skipping to change at line 61 | |
| inline bool operator==(null const &/*l*/,null const &/*r*/) {return
true;} | | inline bool operator==(null const &/*l*/,null const &/*r*/) {return
true;} | |
| inline bool operator!=(null const &/*l*/,null const &/*r*/) {return
false;} | | inline bool operator!=(null const &/*l*/,null const &/*r*/) {return
false;} | |
| | | | |
| /// | | /// | |
| /// The json::array - std::vector of json::value's | | /// The json::array - std::vector of json::value's | |
| /// | | /// | |
| typedef std::vector<value> array; | | typedef std::vector<value> array; | |
| /// | | /// | |
| /// The json::object - std::map of json::value's | | /// The json::object - std::map of json::value's | |
| /// | | /// | |
|
| typedef std::map<std::string,value> object; | | typedef std::map<string_key,value> object; | |
| | | | |
| #ifdef CPPCMS_DOXYGEN_DOCS | | #ifdef CPPCMS_DOXYGEN_DOCS | |
| | | | |
| /// | | /// | |
| /// The type traits schema for converting json values to/from orinar
y objects | | /// The type traits schema for converting json values to/from orinar
y objects | |
| /// i.e. serialization from JSON to C++ object | | /// i.e. serialization from JSON to C++ object | |
| /// | | /// | |
| template<typename T> | | template<typename T> | |
| struct traits { | | struct traits { | |
| /// | | /// | |
| | | | |
| skipping to change at line 260 | | skipping to change at line 261 | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Searches a value in the path \a path | | /// Searches a value in the path \a path | |
| /// | | /// | |
| /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | | /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | |
| /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | | /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | |
| /// that holds an object { "y" : 10 } and find("foo") would
return value of undefined type. | | /// that holds an object { "y" : 10 } and find("foo") would
return value of undefined type. | |
| /// | | /// | |
| value const &find(std::string const &path) const; | | value const &find(std::string const &path) const; | |
|
| | | /// | |
| | | /// Searches a value in the path \a path | |
| | | /// | |
| | | /// For example if the json::value represents { "x" : { "y" | |
| | | : 10 } }, then find("x.y") would return | |
| | | /// a reference to value that hold a number 10, find("x") re | |
| | | turns a reference to a value | |
| | | /// that holds an object { "y" : 10 } and find("foo") would | |
| | | return value of undefined type. | |
| | | /// | |
| | | value const &find(char const *path) const; | |
| | | | |
| /// | | /// | |
| /// Searches a value in the path \a path, if not found throw
bad_value_cast. | | /// Searches a value in the path \a path, if not found throw
bad_value_cast. | |
| /// | | /// | |
| /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | | /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | |
| /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | | /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | |
| /// that holds an object { "y" : 10 } and find("foo") throws | | /// that holds an object { "y" : 10 } and find("foo") throws | |
| /// | | /// | |
| value const &at(std::string const &path) const; | | value const &at(std::string const &path) const; | |
| /// | | /// | |
| /// Searches a value in the path \a path, if not found throw
bad_value_cast. | | /// Searches a value in the path \a path, if not found throw
bad_value_cast. | |
| /// | | /// | |
| /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | | /// For example if the json::value represents { "x" : { "y"
: 10 } }, then find("x.y") would return | |
| /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | | /// a reference to value that hold a number 10, find("x") re
turns a reference to a value | |
| /// that holds an object { "y" : 10 } and find("foo") throws | | /// that holds an object { "y" : 10 } and find("foo") throws | |
| /// | | /// | |
|
| | | value const &at(char const *path) const; | |
| | | /// | |
| | | /// Searches a value in the path \a path, if not found throw | |
| | | bad_value_cast. | |
| | | /// | |
| | | /// For example if the json::value represents { "x" : { "y" | |
| | | : 10 } }, then find("x.y") would return | |
| | | /// a reference to value that hold a number 10, find("x") re | |
| | | turns a reference to a value | |
| | | /// that holds an object { "y" : 10 } and find("foo") throws | |
| | | /// | |
| value &at(std::string const &path); | | value &at(std::string const &path); | |
|
| | | /// | |
| | | /// Searches a value in the path \a path, if not found throw | |
| | | bad_value_cast. | |
| | | /// | |
| | | /// For example if the json::value represents { "x" : { "y" | |
| | | : 10 } }, then find("x.y") would return | |
| | | /// a reference to value that hold a number 10, find("x") re | |
| | | turns a reference to a value | |
| | | /// that holds an object { "y" : 10 } and find("foo") throws | |
| | | /// | |
| | | value &at(char const *path); | |
| | | | |
| /// | | /// | |
| /// Sets the value \a v at the path \a path, if the path inv
alid, creates it. | | /// Sets the value \a v at the path \a path, if the path inv
alid, creates it. | |
| /// | | /// | |
| void at(std::string const &path,value const &v); | | void at(std::string const &path,value const &v); | |
|
| | | /// | |
| | | /// Sets the value \a v at the path \a path, if the path inv | |
| | | alid, creates it. | |
| | | /// | |
| | | void at(char const *path,value const &v); | |
| | | | |
| /// | | /// | |
| /// Creates a value from and object \a v of type T | | /// Creates a value from and object \a v of type T | |
| /// | | /// | |
| template<typename T> | | template<typename T> | |
| value(T const &v) | | value(T const &v) | |
| { | | { | |
| set_value(v); | | set_value(v); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Returns the type of variable in path, if not found retur
ns undefined | | /// Returns the type of variable in path, if not found retur
ns undefined | |
| /// | | /// | |
| /// Same as find(path).type() | | /// Same as find(path).type() | |
| /// | | /// | |
| json_type type(std::string const &path) const | | json_type type(std::string const &path) const | |
| { | | { | |
| return find(path).type(); | | return find(path).type(); | |
| } | | } | |
|
| | | /// | |
| | | /// Returns the type of variable in path, if not found retur | |
| | | ns undefined | |
| | | /// | |
| | | /// Same as find(path).type() | |
| | | /// | |
| | | json_type type(char const *path) const | |
| | | { | |
| | | return find(path).type(); | |
| | | } | |
| | | | |
| /// | | /// | |
| /// Convert an object \a v of type T to a value at specific
path, same as at(path,value(v)) | | /// Convert an object \a v of type T to a value at specific
path, same as at(path,value(v)) | |
| /// | | /// | |
| template<typename T> | | template<typename T> | |
| void set(std::string const &path,T const &v) | | void set(std::string const &path,T const &v) | |
| { | | { | |
| at(path,value(v)); | | at(path,value(v)); | |
| } | | } | |
|
| | | /// | |
| | | /// Convert an object \a v of type T to a value at specific | |
| | | path, same as at(path,value(v)) | |
| | | /// | |
| | | template<typename T> | |
| | | void set(char const *path,T const &v) | |
| | | { | |
| | | at(path,value(v)); | |
| | | } | |
| | | | |
| /// | | /// | |
| /// Get a string value from a path \a path. If the path is n
ot invalid or the object | | /// Get a string value from a path \a path. If the path is n
ot invalid or the object | |
| /// is not of type string at this path, returns \a def inste
ad | | /// is not of type string at this path, returns \a def inste
ad | |
| /// | | /// | |
| std::string get(std::string const &path,char const *def) con
st | | std::string get(std::string const &path,char const *def) con
st | |
| { | | { | |
| value const &v=find(path); | | value const &v=find(path); | |
| if(v.is_undefined()) | | if(v.is_undefined()) | |
| return def; | | return def; | |
| try { | | try { | |
| return v.get_value<std::string>(); | | return v.get_value<std::string>(); | |
| } | | } | |
| catch(std::bad_cast const &e) { | | catch(std::bad_cast const &e) { | |
| return def; | | return def; | |
| } | | } | |
| } | | } | |
|
| | | /// | |
| | | /// Get a string value from a path \a path. If the path is n | |
| | | ot invalid or the object | |
| | | /// is not of type string at this path, returns \a def inste | |
| | | ad | |
| | | /// | |
| | | std::string get(char const *path,char const *def) const | |
| | | { | |
| | | value const &v=find(path); | |
| | | if(v.is_undefined()) | |
| | | return def; | |
| | | try { | |
| | | return v.get_value<std::string>(); | |
| | | } | |
| | | catch(std::bad_cast const &e) { | |
| | | return def; | |
| | | } | |
| | | } | |
| | | | |
| /// | | /// | |
| /// Get an object of type T from the path \a path. Throws ba
d_value_cast if such path does not | | /// Get an object of type T from the path \a path. Throws ba
d_value_cast if such path does not | |
| /// exists of conversion can't be done | | /// exists of conversion can't be done | |
| /// | | /// | |
| template<typename T> | | template<typename T> | |
| T get(std::string const &path) const | | T get(std::string const &path) const | |
| { | | { | |
| return at(path).get_value<T>(); | | return at(path).get_value<T>(); | |
| } | | } | |
|
| | | /// | |
| | | /// Get an object of type T from the path \a path. Throws ba | |
| | | d_value_cast if such path does not | |
| | | /// exists of conversion can't be done | |
| | | /// | |
| | | template<typename T> | |
| | | T get(char const *path) const | |
| | | { | |
| | | return at(path).get_value<T>(); | |
| | | } | |
| | | | |
| /// | | /// | |
| /// Get an object of type T from the path \a path. Returns \
a def if such path does not | | /// Get an object of type T from the path \a path. Returns \
a def if such path does not | |
| /// exists of conversion can't be done | | /// exists of conversion can't be done | |
| /// | | /// | |
| template<typename T> | | template<typename T> | |
|
| | | T get(char const *path,T const &def) const | |
| | | { | |
| | | value const &v=find(path); | |
| | | if(v.is_undefined()) | |
| | | return def; | |
| | | try { | |
| | | return v.get_value<T>(); | |
| | | } | |
| | | catch(std::bad_cast const &e) { | |
| | | return def; | |
| | | } | |
| | | } | |
| | | /// | |
| | | /// Get an object of type T from the path \a path. Returns \ | |
| | | a def if such path does not | |
| | | /// exists of conversion can't be done | |
| | | /// | |
| | | template<typename T> | |
| T get(std::string const &path,T const &def) const | | T get(std::string const &path,T const &def) const | |
| { | | { | |
| value const &v=find(path); | | value const &v=find(path); | |
| if(v.is_undefined()) | | if(v.is_undefined()) | |
| return def; | | return def; | |
| try { | | try { | |
| return v.get_value<T>(); | | return v.get_value<T>(); | |
| } | | } | |
| catch(std::bad_cast const &e) { | | catch(std::bad_cast const &e) { | |
| return def; | | return def; | |
| | | | |
End of changes. 11 change blocks. |
| 1 lines changed or deleted | | 105 lines changed or added | |
|
| url_mapper.h | | url_mapper.h | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| // GNU Lesser General Public License for more details. | | // GNU Lesser General Public License for more details. | |
| // | | // | |
| // You should have received a copy of the GNU Lesser General Public Licens
e | | // You should have received a copy of the GNU Lesser General Public Licens
e | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| // | | // | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| #ifndef CPPCMS_URL_MAPPER_H | | #ifndef CPPCMS_URL_MAPPER_H | |
| #define CPPCMS_URL_MAPPER_H | | #define CPPCMS_URL_MAPPER_H | |
| | | | |
| #include <cppcms/defs.h> | | #include <cppcms/defs.h> | |
|
| | | #include <cppcms/string_key.h> | |
| #include <booster/noncopyable.h> | | #include <booster/noncopyable.h> | |
| #include <booster/hold_ptr.h> | | #include <booster/hold_ptr.h> | |
| #include <cppcms/filters.h> | | #include <cppcms/filters.h> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace cppcms { | | namespace cppcms { | |
| class application; | | class application; | |
| | | | |
| /// | | /// | |
| | | | |
| skipping to change at line 235 | | skipping to change at line 236 | |
| /// | | /// | |
| /// Note: this value is cleared globally for all application
s hierarchy and not only | | /// Note: this value is cleared globally for all application
s hierarchy and not only | |
| /// for this specific application | | /// for this specific application | |
| /// | | /// | |
| void clear_value(std::string const &key); | | void clear_value(std::string const &key); | |
| | | | |
| /// | | /// | |
| /// Write the URL to output stream \a out for the URL \a pat
h with 0 parameters | | /// Write the URL to output stream \a out for the URL \a pat
h with 0 parameters | |
| /// | | /// | |
| void map( std::ostream &out, | | void map( std::ostream &out, | |
|
| | | char const *path); | |
| | | | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 1 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1); | |
| | | | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 2 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1, | |
| | | filters::streamable const &p2); | |
| | | | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 3 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1, | |
| | | filters::streamable const &p2, | |
| | | filters::streamable const &p3); | |
| | | | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 4 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1, | |
| | | filters::streamable const &p2, | |
| | | filters::streamable const &p3, | |
| | | filters::streamable const &p4); | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 5 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1, | |
| | | filters::streamable const &p2, | |
| | | filters::streamable const &p3, | |
| | | filters::streamable const &p4, | |
| | | filters::streamable const &p5); | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 6 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| | | char const *path, | |
| | | filters::streamable const &p1, | |
| | | filters::streamable const &p2, | |
| | | filters::streamable const &p3, | |
| | | filters::streamable const &p4, | |
| | | filters::streamable const &p5, | |
| | | filters::streamable const &p6); | |
| | | /// | |
| | | /// Write the URL to output stream \a out for the URL \a pat | |
| | | h with 0 parameters | |
| | | /// | |
| | | void map( std::ostream &out, | |
| std::string const &path); | | std::string const &path); | |
| | | | |
| /// | | /// | |
| /// Write the URL to output stream \a out for the URL \a pat
h with 1 parameters | | /// Write the URL to output stream \a out for the URL \a pat
h with 1 parameters | |
| /// | | /// | |
| void map( std::ostream &out, | | void map( std::ostream &out, | |
| std::string const &path, | | std::string const &path, | |
| filters::streamable const &p1); | | filters::streamable const &p1); | |
| | | | |
| /// | | /// | |
| | | | |
| skipping to change at line 316 | | skipping to change at line 377 | |
| /// Get a parent mapper, if not exists throws cppcms_error | | /// Get a parent mapper, if not exists throws cppcms_error | |
| /// | | /// | |
| url_mapper &parent(); | | url_mapper &parent(); | |
| /// | | /// | |
| /// Get a topmost mapper, if have no parents returns referen
ce to \c this. | | /// Get a topmost mapper, if have no parents returns referen
ce to \c this. | |
| /// | | /// | |
| url_mapper &topmost(); | | url_mapper &topmost(); | |
| | | | |
| private: | | private: | |
| void real_assign(std::string const &key,std::string const &u
rl,application *child = 0); | | void real_assign(std::string const &key,std::string const &u
rl,application *child = 0); | |
|
| url_mapper &get_mapper_for_key(std::string const &key,std::s
tring &real_key,std::vector<std::string> &direct); | | url_mapper &get_mapper_for_key(string_key const &key,string_
key &real_key,std::vector<string_key> &direct); | |
| url_mapper *root_mapper(); | | url_mapper *root_mapper(); | |
|
| void real_map( std::string const &key, | | void real_map( char const *key, | |
| filters::streamable const *const *params, | | filters::streamable const *const *params, | |
| size_t params_no, | | size_t params_no, | |
| std::ostream &output); | | std::ostream &output); | |
| | | | |
| struct data; | | struct data; | |
| booster::hold_ptr<data> d; | | booster::hold_ptr<data> d; | |
| }; | | }; | |
| | | | |
| }; | | }; | |
| | | | |
| | | | |
End of changes. 4 change blocks. |
| 2 lines changed or deleted | | 70 lines changed or added | |
|
| xss.h | | xss.h | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 24 | |
| // | | // | |
| // You should have received a copy of the GNU Lesser General Public Licens
e | | // You should have received a copy of the GNU Lesser General Public Licens
e | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| // | | // | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| #ifndef CPPCMS_XSS_H | | #ifndef CPPCMS_XSS_H | |
| #define CPPCMS_XSS_H | | #define CPPCMS_XSS_H | |
| | | | |
| #include <booster/copy_ptr.h> | | #include <booster/copy_ptr.h> | |
| #include <booster/regex.h> | | #include <booster/regex.h> | |
|
| | | #include <booster/function.h> | |
| #include <cppcms/defs.h> | | #include <cppcms/defs.h> | |
| | | | |
| #include <string.h> | | #include <string.h> | |
| #include <string> | | #include <string> | |
| #include <algorithm> | | #include <algorithm> | |
| | | | |
| namespace cppcms { | | namespace cppcms { | |
| /// | | /// | |
| /// \brief Namespace that holds Anti-Cross Site Scripting Filter sup
port | | /// \brief Namespace that holds Anti-Cross Site Scripting Filter sup
port | |
| /// | | /// | |
| /// The classes in this namespace created to provide a filtering for
a save | | /// The classes in this namespace created to provide a filtering for
a save | |
| /// handing of HTML and preventing XSS attacks | | /// handing of HTML and preventing XSS attacks | |
| /// | | /// | |
| namespace xss { | | namespace xss { | |
| | | | |
| /// \cond INTERNAL | | /// \cond INTERNAL | |
| namespace details { | | namespace details { | |
|
| | | class c_string; | |
| class c_string { | | } | |
| public: | | | |
| | | | |
| typedef char const *const_iterator; | | | |
| | | | |
| char const *begin() const | | | |
| { | | | |
| return begin_; | | | |
| } | | | |
| | | | |
| char const *end() const | | | |
| { | | | |
| return end_; | | | |
| } | | | |
| | | | |
| c_string(char const *s) | | | |
| { | | | |
| begin_=s; | | | |
| end_=s+strlen(s); | | | |
| } | | | |
| | | | |
| c_string(char const *b,char const *e) : begi | | | |
| n_(b), end_(e) {} | | | |
| | | | |
| c_string() : begin_(0),end_(0) {} | | | |
| | | | |
| bool compare(c_string const &other) const | | | |
| { | | | |
| return std::lexicographical_compare( | | | |
| begin_,end_,other.begin_,other.end_,std::char_traits<char>::lt); | | | |
| } | | | |
| | | | |
| bool icompare(c_string const &other) const | | | |
| { | | | |
| return std::lexicographical_compare( | | | |
| begin_,end_,other.begin_,other.end_,ilt); | | | |
| } | | | |
| | | | |
| explicit c_string(std::string const &other) | | | |
| { | | | |
| container_ = other; | | | |
| begin_ = container_.c_str(); | | | |
| end_ = begin_ + container_.size(); | | | |
| } | | | |
| c_string(c_string const &other) | | | |
| { | | | |
| if(other.begin_ == other.end_) { | | | |
| begin_ = end_ = 0; | | | |
| } | | | |
| else if(other.container_.empty()) { | | | |
| begin_ = other.begin_; | | | |
| end_ = other.end_; | | | |
| } | | | |
| else { | | | |
| container_ = other.container | | | |
| _; | | | |
| begin_ = container_.c_str(); | | | |
| end_ = begin_ + container_.s | | | |
| ize(); | | | |
| } | | | |
| } | | | |
| c_string const &operator=(c_string const &ot | | | |
| her) | | | |
| { | | | |
| if(other.begin_ == other.end_) { | | | |
| begin_ = end_ = 0; | | | |
| } | | | |
| else if(other.container_.empty()) { | | | |
| begin_ = other.begin_; | | | |
| end_ = other.end_; | | | |
| } | | | |
| else { | | | |
| container_ = other.container | | | |
| _; | | | |
| begin_ = container_.c_str(); | | | |
| end_ = begin_ + container_.s | | | |
| ize(); | | | |
| } | | | |
| return *this; | | | |
| } | | | |
| | | | |
| private: | | | |
| static bool ilt(char left,char right) | | | |
| { | | | |
| unsigned char l = tolower(left); | | | |
| unsigned char r = tolower(right); | | | |
| return l < r; | | | |
| } | | | |
| static char tolower(char c) | | | |
| { | | | |
| if('A' <= c && c<='Z') | | | |
| return c-'A' + 'a'; | | | |
| return c; | | | |
| } | | | |
| char const *begin_; | | | |
| char const *end_; | | | |
| std::string container_; | | | |
| }; | | | |
| | | | |
| } // details | | | |
| | | | |
| struct basic_rules_holder; | | struct basic_rules_holder; | |
| | | | |
| /// \endcond | | /// \endcond | |
| | | | |
| /// | | /// | |
| /// \brief The class that holds XSS filter rules | | /// \brief The class that holds XSS filter rules | |
| /// | | /// | |
| /// This is the major class the defines the white list rules
to handle the | | /// This is the major class the defines the white list rules
to handle the | |
| /// Correct HTML input. | | /// Correct HTML input. | |
| /// | | /// | |
| | | | |
| skipping to change at line 248 | | skipping to change at line 157 | |
| /// Get if numeric entities are allowed, default is
false | | /// Get if numeric entities are allowed, default is
false | |
| /// | | /// | |
| bool numeric_entities_allowed() const; | | bool numeric_entities_allowed() const; | |
| | | | |
| /// | | /// | |
| /// Set if numeric entities are allowed | | /// Set if numeric entities are allowed | |
| /// | | /// | |
| void numeric_entities_allowed(bool v); | | void numeric_entities_allowed(bool v); | |
| | | | |
| /// | | /// | |
|
| | | /// Functor that allows to provide custom validation | |
| | | s for different properties | |
| | | /// | |
| | | typedef booster::function<bool(char const *begin,cha | |
| | | r const *end)> validator_type; | |
| | | | |
| | | /// | |
| /// Add the property that should be allowed to appea
r for specific tag as boolean property like | | /// Add the property that should be allowed to appea
r for specific tag as boolean property like | |
| /// checked="checked", when the type | | /// checked="checked", when the type | |
| /// is HTML it is case insensitive. | | /// is HTML it is case insensitive. | |
| /// | | /// | |
| /// The \a property should be ASCII only | | /// The \a property should be ASCII only | |
| /// | | /// | |
| void add_boolean_property(std::string const &tag_nam
e,std::string const &property); | | void add_boolean_property(std::string const &tag_nam
e,std::string const &property); | |
| /// | | /// | |
|
| | | /// Add the property that should be checked using cu | |
| | | stom functor | |
| | | /// | |
| | | void add_property(std::string const &tag_name,std::s | |
| | | tring const &property,validator_type const &val); | |
| | | /// | |
| /// Add the property that should be checked using re
gular expression. | | /// Add the property that should be checked using re
gular expression. | |
| /// | | /// | |
| void add_property(std::string const &tag_name,std::s
tring const &property,booster::regex const &r); | | void add_property(std::string const &tag_name,std::s
tring const &property,booster::regex const &r); | |
| /// | | /// | |
|
| /// Add numeric property, same as add_property(tag_n | | /// Add numeric property, same as add_property(tag_n | |
| ame,property,booster::regex("-?[0-9]+") | | ame,property,booster::regex("-?[0-9]+") but | |
| | | /// little bit more efficient | |
| /// | | /// | |
| void add_integer_property(std::string const &tag_nam
e,std::string const &property); | | void add_integer_property(std::string const &tag_nam
e,std::string const &property); | |
| | | | |
| /// | | /// | |
| /// Add URI property. | | /// Add URI property. | |
| /// It should be used for properties like like "href
" or "src". | | /// It should be used for properties like like "href
" or "src". | |
| /// It is very good idea to use it in order to preve
nt urls like javascript:alert('XSS') | | /// It is very good idea to use it in order to preve
nt urls like javascript:alert('XSS') | |
| /// | | /// | |
|
| /// It's behavior is same as add_property(tag_name,p
roperty,rules::uri_matcher()); | | /// It's behavior is same as add_property(tag_name,p
roperty,rules::uri_validator()); | |
| /// | | /// | |
| void add_uri_property(std::string const &tag_name,st
d::string const &property); | | void add_uri_property(std::string const &tag_name,st
d::string const &property); | |
| /// | | /// | |
| /// Add URI property, using regular expression that
matches allowed schemas. | | /// Add URI property, using regular expression that
matches allowed schemas. | |
| /// It should be used for properties like like "href
" or "src". | | /// It should be used for properties like like "href
" or "src". | |
| /// It is very good idea to use it in order to preve
nt urls like javascript:alert('XSS') | | /// It is very good idea to use it in order to preve
nt urls like javascript:alert('XSS') | |
| /// | | /// | |
|
| /// It's behavior is same as add_property(tag_name,p
roperty,rules::uri_matcher(schema)); | | /// It's behavior is same as add_property(tag_name,p
roperty,rules::uri_validator(schema)); | |
| /// | | /// | |
| void add_uri_property(std::string const &tag_name,st
d::string const &property,std::string const &schema); | | void add_uri_property(std::string const &tag_name,st
d::string const &property,std::string const &schema); | |
| | | | |
| /// | | /// | |
|
| | | /// \deprecated use uri_validator | |
| | | /// | |
| /// Create a regular expression that checks URI for
safe inclusion in the property. | | /// Create a regular expression that checks URI for
safe inclusion in the property. | |
| /// By default it allows only: http, https, ftp, mai
lto, news, nntp. | | /// By default it allows only: http, https, ftp, mai
lto, news, nntp. | |
| /// | | /// | |
| /// If you need finer control over allowed schemas,
use uri_matcher(std::string const&). | | /// If you need finer control over allowed schemas,
use uri_matcher(std::string const&). | |
| /// | | /// | |
| static booster::regex uri_matcher(); | | static booster::regex uri_matcher(); | |
| /// | | /// | |
|
| | | /// \deprecated use uri_validator | |
| | | /// | |
| /// Create a regular expression that checks URI for
safe inclusion in the text, where | | /// Create a regular expression that checks URI for
safe inclusion in the text, where | |
| /// schema is a regular expression that matches spec
ific protocols that can be used. | | /// schema is a regular expression that matches spec
ific protocols that can be used. | |
| /// | | /// | |
| /// \note Don't add "^" or "$" tags as this expressi
on would be used in construction of regular | | /// \note Don't add "^" or "$" tags as this expressi
on would be used in construction of regular | |
| /// other expression. | | /// other expression. | |
| /// | | /// | |
| /// For example: | | /// For example: | |
| /// \code | | /// \code | |
| /// booster::regex uri = uri_matcher("(http|https)")
; | | /// booster::regex uri = uri_matcher("(http|https)")
; | |
| /// \endcode | | /// \endcode | |
| /// | | /// | |
| static booster::regex uri_matcher(std::string const
&schema); | | static booster::regex uri_matcher(std::string const
&schema); | |
| | | | |
|
| | | //// | |
| | | /// Create a validator that checks URI for safe incl | |
| | | usion in the property. | |
| | | /// By default it allows only: http, https, ftp, mai | |
| | | lto, news, nntp. | |
| | | /// | |
| | | /// If you need finer control over allowed schemas, | |
| | | use uri_validator(std::string const&). | |
| | | /// | |
| | | static validator_type uri_validator(); | |
| | | //// | |
| | | /// Create a validator that checks URI for safe incl | |
| | | usion in the property. | |
| | | /// - schema is a regular expression that matches sp | |
| | | ecific protocols that can be used. | |
| | | /// - absolute_only - set to true to prevent accepti | |
| | | ng relative URIs like "/files/img.png" or "test.html" | |
| | | /// | |
| | | /// \note You don't need to add "^" or "$" tags to \ | |
| | | a scheme | |
| | | /// | |
| | | /// For example: | |
| | | /// \code | |
| | | /// uri_validator("(http|https)"); | |
| | | /// \endcode | |
| | | /// | |
| | | /// | |
| | | /// If you need finer control over allowed schemas, | |
| | | use uri_validator(std::string const&). | |
| | | /// | |
| | | static validator_type uri_validator(std::string cons | |
| | | t &scheme,bool absolute_only = false); | |
| | | | |
| | | /// | |
| | | /// Create a validator that checks that this URI is | |
| | | relative and it is safe for inclusion | |
| | | /// in URI property like href or src | |
| | | /// | |
| | | static validator_type relative_uri_validator(); | |
| | | | |
| /// | | /// | |
| /// Check if the comments are allowed in the text | | /// Check if the comments are allowed in the text | |
| /// | | /// | |
| bool comments_allowed() const; | | bool comments_allowed() const; | |
| /// | | /// | |
| /// Set to true if the comments are allowed in the t
ext | | /// Set to true if the comments are allowed in the t
ext | |
| /// | | /// | |
| void comments_allowed(bool comments); | | void comments_allowed(bool comments); | |
| | | | |
| /// | | /// | |
| | | | |
End of changes. 10 change blocks. |
| 106 lines changed or deleted | | 65 lines changed or added | |
|