backtrace.h | backtrace.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <stdexcept> | #include <stdexcept> | |||
#include <typeinfo> | #include <typeinfo> | |||
#include <string> | #include <string> | |||
#include <vector> | #include <vector> | |||
#include <iosfwd> | #include <iosfwd> | |||
namespace booster { | namespace booster { | |||
/// | ||||
/// \brief Namespace that holds basic operations | ||||
/// for implementing stack trace | ||||
/// | ||||
namespace stack_trace { | namespace stack_trace { | |||
/// | ||||
/// \brief Record stack frame | ||||
/// | ||||
/// Records at most \a size stack frames returning the pointers to | ||||
the running | ||||
/// code into \a addresses vector that should have at least size pl | ||||
aces | ||||
/// | ||||
/// returns that number of actually recorded frames | ||||
/// | ||||
BOOSTER_API int trace(void **addresses,int size); | BOOSTER_API int trace(void **addresses,int size); | |||
/// | ||||
/// \brief Print stack trace | ||||
/// | ||||
/// Writes stack trace recorded \ref trace function of \a size size | ||||
to the output stream | ||||
/// | ||||
BOOSTER_API void write_symbols(void *const *addresses,int size,std: :ostream &); | BOOSTER_API void write_symbols(void *const *addresses,int size,std: :ostream &); | |||
/// | ||||
/// \brief Get stack trace information about a single address recor | ||||
ded | ||||
/// | ||||
BOOSTER_API std::string get_symbol(void *address); | BOOSTER_API std::string get_symbol(void *address); | |||
/// | ||||
/// \brief Get stack trace information about multiple address recor | ||||
ded | ||||
/// | ||||
BOOSTER_API std::string get_symbols(void * const *address,int size) ; | BOOSTER_API std::string get_symbols(void * const *address,int size) ; | |||
} // stack_trace | } // stack_trace | |||
/// | ||||
/// \brief the class that records the stack trace when it is created, | ||||
/// | ||||
/// It is a base class for all exceptions that record stack trace | ||||
/// | ||||
class backtrace { | class backtrace { | |||
public: | public: | |||
/// | ||||
/// The default number of recorded frames | ||||
/// | ||||
static size_t const default_stack_size = 32; | static size_t const default_stack_size = 32; | |||
/// | ||||
/// Create stack trace recording at most \a frames_no stack frames | ||||
/// | ||||
backtrace(size_t frames_no = default_stack_size) | backtrace(size_t frames_no = default_stack_size) | |||
{ | { | |||
if(frames_no == 0) | if(frames_no == 0) | |||
return; | return; | |||
frames_.resize(frames_no,0); | frames_.resize(frames_no,0); | |||
int size = stack_trace::trace(&frames_.front(),frames_no); | int size = stack_trace::trace(&frames_.front(),frames_no); | |||
frames_.resize(size); | frames_.resize(size); | |||
} | } | |||
virtual ~backtrace() throw() | virtual ~backtrace() throw() | |||
{ | { | |||
} | } | |||
/// | ||||
/// Get the actual number of recorded stack frames | ||||
/// | ||||
size_t stack_size() const | size_t stack_size() const | |||
{ | { | |||
return frames_.size(); | return frames_.size(); | |||
} | } | |||
/// | ||||
/// Get the returned address for the stack frame number \a frame_no | ||||
/// | ||||
void *return_address(unsigned frame_no) const | void *return_address(unsigned frame_no) const | |||
{ | { | |||
if(frame_no < stack_size()) | if(frame_no < stack_size()) | |||
return frames_[frame_no]; | return frames_[frame_no]; | |||
return 0; | return 0; | |||
} | } | |||
/// | ||||
/// Print the stack trace frame for the frame \a frame_no to the st | ||||
ream \a out | ||||
/// | ||||
void trace_line(unsigned frame_no,std::ostream &out) const | void trace_line(unsigned frame_no,std::ostream &out) const | |||
{ | { | |||
if(frame_no < frames_.size()) | if(frame_no < frames_.size()) | |||
stack_trace::write_symbols(&frames_[frame_no],1,out); | stack_trace::write_symbols(&frames_[frame_no],1,out); | |||
} | } | |||
/// | ||||
/// Get a readable stack trace frame for the frame \a frame_no | ||||
/// | ||||
std::string trace_line(unsigned frame_no) const | std::string trace_line(unsigned frame_no) const | |||
{ | { | |||
if(frame_no < frames_.size()) | if(frame_no < frames_.size()) | |||
return stack_trace::get_symbol(frames_[frame_no]); | return stack_trace::get_symbol(frames_[frame_no]); | |||
return std::string(); | return std::string(); | |||
} | } | |||
/// | ||||
/// Get full stack trace as a string | ||||
/// | ||||
std::string trace() const | std::string trace() const | |||
{ | { | |||
if(frames_.empty()) | if(frames_.empty()) | |||
return std::string(); | return std::string(); | |||
return stack_trace::get_symbols(&frames_.front(),frames_.size() ); | return stack_trace::get_symbols(&frames_.front(),frames_.size() ); | |||
} | } | |||
/// | ||||
/// Print full stack trace to a stream \a out | ||||
/// | ||||
void trace(std::ostream &out) const | void trace(std::ostream &out) const | |||
{ | { | |||
if(frames_.empty()) | if(frames_.empty()) | |||
return; | return; | |||
stack_trace::write_symbols(&frames_.front(),frames_.size(),out) ; | stack_trace::write_symbols(&frames_.front(),frames_.size(),out) ; | |||
} | } | |||
private: | private: | |||
std::vector<void *> frames_; | std::vector<void *> frames_; | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::exception but records stack trace | ||||
/// | ||||
class exception : public std::exception, public backtrace { | class exception : public std::exception, public backtrace { | |||
public: | public: | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::bad_cast but records stack trace | ||||
/// | ||||
class bad_cast : public std::bad_cast, public backtrace { | class bad_cast : public std::bad_cast, public backtrace { | |||
public: | public: | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::runtime_error but records stack trace | ||||
/// | ||||
class runtime_error: public std::runtime_error, public backtrace { | class runtime_error: public std::runtime_error, public backtrace { | |||
public: | public: | |||
explicit runtime_error(std::string const &s) : std::runtime_error(s ) | explicit runtime_error(std::string const &s) : std::runtime_error(s ) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::range_error but records stack trace | ||||
/// | ||||
class range_error: public std::range_error, public backtrace { | class range_error: public std::range_error, public backtrace { | |||
public: | public: | |||
explicit range_error(std::string const &s) : std::range_error(s) | explicit range_error(std::string const &s) : std::range_error(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::overflow_error but records stack trace | ||||
/// | ||||
class overflow_error: public std::overflow_error, public backtrace { | class overflow_error: public std::overflow_error, public backtrace { | |||
public: | public: | |||
explicit overflow_error(std::string const &s) : std::overflow_error (s) | explicit overflow_error(std::string const &s) : std::overflow_error (s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::underflow_error but records stack trace | ||||
/// | ||||
class underflow_error: public std::underflow_error, public backtrace { | class underflow_error: public std::underflow_error, public backtrace { | |||
public: | public: | |||
explicit underflow_error(std::string const &s) : std::underflow_err or(s) | explicit underflow_error(std::string const &s) : std::underflow_err or(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::logic_error but records stack trace | ||||
/// | ||||
class logic_error: public std::logic_error, public backtrace { | class logic_error: public std::logic_error, public backtrace { | |||
public: | public: | |||
explicit logic_error(std::string const &s) : std::logic_error(s) | explicit logic_error(std::string const &s) : std::logic_error(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::domain_error but records stack trace | ||||
/// | ||||
class domain_error: public std::domain_error, public backtrace { | class domain_error: public std::domain_error, public backtrace { | |||
public: | public: | |||
explicit domain_error(std::string const &s) : std::domain_error(s) | explicit domain_error(std::string const &s) : std::domain_error(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::length_error but records stack trace | ||||
/// | ||||
class length_error: public std::length_error, public backtrace { | class length_error: public std::length_error, public backtrace { | |||
public: | public: | |||
explicit length_error(std::string const &s) : std::length_error(s) | explicit length_error(std::string const &s) : std::length_error(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::invalid_argument but records stack trace | ||||
/// | ||||
class invalid_argument : public std::invalid_argument, public backtrace { | class invalid_argument : public std::invalid_argument, public backtrace { | |||
public: | public: | |||
explicit invalid_argument(std::string const &s) : std::invalid_argu ment(s) | explicit invalid_argument(std::string const &s) : std::invalid_argu ment(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief Same as std::out_of_range but records stack trace | ||||
/// | ||||
class out_of_range : public std::out_of_range, public backtrace { | class out_of_range : public std::out_of_range, public backtrace { | |||
public: | public: | |||
explicit out_of_range(std::string const &s) : std::out_of_range(s) | explicit out_of_range(std::string const &s) : std::out_of_range(s) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// \cond INTERNAL | ||||
namespace details { | namespace details { | |||
class trace_manip { | class trace_manip { | |||
public: | public: | |||
trace_manip(backtrace const *tr) : | trace_manip(backtrace const *tr) : | |||
tr_(tr) | tr_(tr) | |||
{ | { | |||
} | } | |||
std::ostream &write(std::ostream &out) const | std::ostream &write(std::ostream &out) const | |||
{ | { | |||
if(tr_) | if(tr_) | |||
skipping to change at line 182 | skipping to change at line 270 | |||
private: | private: | |||
backtrace const *tr_; | backtrace const *tr_; | |||
}; | }; | |||
inline std::ostream &operator<<(std::ostream &out,details::trace_ma nip const &t) | inline std::ostream &operator<<(std::ostream &out,details::trace_ma nip const &t) | |||
{ | { | |||
return t.write(out); | return t.write(out); | |||
} | } | |||
} | } | |||
/// \endcond | ||||
/// | ||||
/// \brief manipulator that print stack trace for the exception \a e if | ||||
it is derived from backtrace. | ||||
/// | ||||
/// For example: | ||||
/// \code | ||||
/// catch(std::exception const &e) { | ||||
/// std::cerr << e.what() << std::endl; | ||||
/// std::cerr << booster::trace(e); | ||||
/// } | ||||
/// | ||||
template<typename E> | template<typename E> | |||
details::trace_manip trace(E const &e) | details::trace_manip trace(E const &e) | |||
{ | { | |||
backtrace const *tr = dynamic_cast<backtrace const *>(&e); | backtrace const *tr = dynamic_cast<backtrace const *>(&e); | |||
return details::trace_manip(tr); | return details::trace_manip(tr); | |||
} | } | |||
} // booster | } // booster | |||
#endif | #endif | |||
End of changes. 27 change blocks. | ||||
0 lines changed or deleted | 107 lines changed or added | |||
date_time.h | date_time.h | |||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
/// | /// | |||
/// \defgroup date_time Date, Time, Timezone and Calendar manipulat ions | /// \defgroup date_time Date, Time, Timezone and Calendar manipulat ions | |||
/// | /// | |||
/// This module provides various calendar, timezone and date time s ervices | /// This module provides various calendar, timezone and date time s ervices | |||
/// | /// | |||
/// @{ | /// @{ | |||
/// | /// | |||
/// \brief This error is thrown in case of invalid state that occur red | /// \brief This error is thrown in case of invalid state that occur red | |||
/// | /// | |||
class BOOSTER_SYMBOL_VISIBLE date_time_error : public booster::runt ime_error { | class date_time_error : public booster::runtime_error { | |||
public: | public: | |||
/// | /// | |||
/// Constructor of date_time_error class | /// Constructor of date_time_error class | |||
/// | /// | |||
date_time_error(std::string const &e) : booster::runtime_error( e) {} | date_time_error(std::string const &e) : booster::runtime_error( e) {} | |||
}; | }; | |||
/// | /// | |||
/// \brief This class represents a pair of period_type and the inte ger | /// \brief This class represents a pair of period_type and the inte ger | |||
/// values that describes its amount. For example 3 days or 4 years . | /// values that describes its amount. For example 3 days or 4 years . | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
defs.h | defs.h | |||
---|---|---|---|---|
skipping to change at line 51 | skipping to change at line 51 | |||
#endif | #endif | |||
#if defined(CPPCMS_WIN_NATIVE) || defined(CPPCMS_CYGWIN) | #if defined(CPPCMS_WIN_NATIVE) || defined(CPPCMS_CYGWIN) | |||
#define CPPCMS_WIN32 | #define CPPCMS_WIN32 | |||
#endif | #endif | |||
#if !defined(CPPCMS_WIN_NATIVE) | #if !defined(CPPCMS_WIN_NATIVE) | |||
#define CPPCMS_POSIX | #define CPPCMS_POSIX | |||
#endif | #endif | |||
#if defined __GNUC__ || defined __clang__ | ||||
#define CPPCMS_DEPRECATED __attribute__((deprecated)) | ||||
#elif defined _MSC_VER | ||||
#define CPPCMS_DEPRECATED __declspec(deprecated) | ||||
#else | ||||
#define CPPCMS_DEPRECATED | ||||
#endif | ||||
#endif /// CPPCMS_DEFS_H | #endif /// CPPCMS_DEFS_H | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 8 lines changed or added | |||
encoding.h | encoding.h | |||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
// | // | |||
#ifndef BOOSTER_LOCALE_ENCODING_H_INCLUDED | #ifndef BOOSTER_LOCALE_ENCODING_H_INCLUDED | |||
#define BOOSTER_LOCALE_ENCODING_H_INCLUDED | #define BOOSTER_LOCALE_ENCODING_H_INCLUDED | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <booster/locale/info.h> | #include <booster/locale/info.h> | |||
#include <booster/cstdint.h> | #include <booster/locale/encoding_errors.h> | |||
#include <booster/backtrace.h> | #include <booster/locale/encoding_utf.h> | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \brief Namespace that contains all functions related to charact er set conversion | /// \brief Namespace that contains all functions related to charact er set conversion | |||
/// | /// | |||
namespace conv { | namespace conv { | |||
/// | /// | |||
/// \defgroup codepage Character conversion functions | /// \defgroup codepage Character conversion functions | |||
/// | /// | |||
/// @{ | /// @{ | |||
/// | /// | |||
/// \brief The excepton that is thrown in case of conversion er | ||||
ror | ||||
/// | ||||
class BOOSTER_SYMBOL_VISIBLE conversion_error : public booster: | ||||
:runtime_error { | ||||
public: | ||||
conversion_error() : booster::runtime_error("Conversion fai | ||||
led") {} | ||||
}; | ||||
/// | ||||
/// \brief This exception is thrown in case of use of unsupport | ||||
ed | ||||
/// or invalid character set | ||||
/// | ||||
class BOOSTER_SYMBOL_VISIBLE invalid_charset_error : public boo | ||||
ster::runtime_error { | ||||
public: | ||||
/// Create an error for charset \a charset | ||||
invalid_charset_error(std::string charset) : | ||||
booster::runtime_error("Invalid or unsupported charset: | ||||
" + charset) | ||||
{ | ||||
} | ||||
}; | ||||
/// | ||||
/// enum that defines conversion policy | ||||
/// | ||||
typedef enum { | ||||
skip = 0, ///< Skip illegal/unconvertable cha | ||||
racters | ||||
stop = 1, ///< Stop conversion and throw conv | ||||
ersion_error | ||||
default_method = skip ///< Default method - skip | ||||
} method_type; | ||||
/// | ||||
/// convert string to UTF string from text in range [begin,end) encoded with \a charset according to policy \a how | /// convert string to UTF string from text in range [begin,end) encoded with \a charset according to policy \a how | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method); | std::basic_string<CharType> to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method); | |||
/// | /// | |||
/// convert UTF text in range [begin,end) to a text encoded wit h \a charset according to policy \a how | /// convert UTF text in range [begin,end) to a text encoded wit h \a charset according to policy \a how | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::string from_utf(CharType const *begin,CharType const *end, std::string const &charset,method_type how=default_method); | std::string from_utf(CharType const *begin,CharType const *end, std::string const &charset,method_type how=default_method); | |||
skipping to change at line 259 | skipping to change at line 228 | |||
#endif | #endif | |||
#ifdef BOOSTER_HAS_CHAR32_T | #ifdef BOOSTER_HAS_CHAR32_T | |||
template<> | template<> | |||
BOOSTER_API std::basic_string<char32_t> to_utf(char const *begi n,char const *end,std::string const &charset,method_type how); | BOOSTER_API std::basic_string<char32_t> to_utf(char const *begi n,char const *end,std::string const &charset,method_type how); | |||
template<> | template<> | |||
BOOSTER_API std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how); | BOOSTER_API std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how); | |||
#endif | #endif | |||
namespace details { | ||||
template<typename CharOut,typename CharIn> | ||||
struct utf_to_utf_traits { | ||||
static std::basic_string<CharOut> | ||||
convert(CharIn const *begin,CharIn const *end,method_ty | ||||
pe how) | ||||
{ | ||||
// Make more efficient in fututre - UTF-16/UTF-32 s | ||||
hould be quite | ||||
// simple and fast | ||||
return to_utf<CharOut>(from_utf(begin,end,"UTF-8",h | ||||
ow),"UTF-8",how); | ||||
} | ||||
}; | ||||
template<typename CharOut> | ||||
struct utf_to_utf_traits<CharOut,char> { | ||||
static std::basic_string<CharOut> | ||||
convert(char const *begin,char const *end,method_type h | ||||
ow) | ||||
{ | ||||
return to_utf<CharOut>(begin,end,"UTF-8",how); | ||||
} | ||||
}; | ||||
template<typename CharIn> | ||||
struct utf_to_utf_traits<char,CharIn> { | ||||
static std::string | ||||
convert(CharIn const *begin,CharIn const *end,method_ty | ||||
pe how) | ||||
{ | ||||
return from_utf(begin,end,"UTF-8",how); | ||||
} | ||||
}; | ||||
template<> | ||||
struct utf_to_utf_traits<char,char> { // just test valid | ||||
static std::string | ||||
convert(char const *begin,char const *end,method_type h | ||||
ow) | ||||
{ | ||||
return from_utf(begin,end,"UTF-8",how); | ||||
} | ||||
}; | ||||
} | ||||
/// \endcond | ||||
/// | ||||
/// Convert a Unicode text in range [begin,end) to other Unicod | ||||
e encoding | ||||
/// | ||||
template<typename CharOut,typename CharIn> | ||||
std::basic_string<CharOut> | ||||
utf_to_utf(CharIn const *begin,CharIn const *end,method_type ho | ||||
w = default_method) | ||||
{ | ||||
return details::utf_to_utf_traits<CharOut,CharIn>::convert( | ||||
begin,end,how); | ||||
} | ||||
/// | ||||
/// Convert a Unicode NUL terminated string \a str other Unicod | ||||
e encoding | ||||
/// | ||||
template<typename CharOut,typename CharIn> | ||||
std::basic_string<CharOut> | ||||
utf_to_utf(CharIn const *str,method_type how = default_method) | ||||
{ | ||||
CharIn const *end = str; | ||||
while(*end) | ||||
end++; | ||||
return utf_to_utf<CharOut,CharIn>(str,end,how); | ||||
} | ||||
/// | ||||
/// Convert a Unicode string \a str other Unicode encoding | ||||
/// | ||||
template<typename CharOut,typename CharIn> | ||||
std::basic_string<CharOut> | ||||
utf_to_utf(std::basic_string<CharIn> const &str,method_type how | ||||
= default_method) | ||||
{ | ||||
return utf_to_utf<CharOut,CharIn>(str.c_str(),str.c_str()+s | ||||
tr.size(),how); | ||||
} | ||||
/// @} | /// @} | |||
} // conv | } // conv | |||
} // locale | } // locale | |||
} // boost | } // boost | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
#pragma warning(pop) | #pragma warning(pop) | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
126 lines changed or deleted | 2 lines changed or added | |||
form.h | form.h | |||
---|---|---|---|---|
skipping to change at line 281 | skipping to change at line 281 | |||
void add(widgets::base_widget &widget); | void add(widgets::base_widget &widget); | |||
/// | /// | |||
/// Add \a widget to form. The ownership is transferred to | /// Add \a widget to form. The ownership is transferred to | |||
/// the parent and the widget will be destroyed together wit h | /// the parent and the widget will be destroyed together wit h | |||
/// the parent. | /// the parent. | |||
/// | /// | |||
void attach(widgets::base_widget *widget); | void attach(widgets::base_widget *widget); | |||
/// | /// | |||
/// \deprecated Use add(form &) instead | ||||
/// | ||||
/// Shortcut to \a add. | /// Shortcut to \a add. | |||
/// | /// | |||
inline form &operator + (form &f) | CPPCMS_DEPRECATED inline form &operator + (form &f) | |||
{ | { | |||
add(f); | add(f); | |||
return *this; | return *this; | |||
} | } | |||
/// | /// | |||
/// \deprecated Use add(widgets::base_widget &) instead | ||||
/// | ||||
/// Shortcut to \a add. | /// Shortcut to \a add. | |||
/// | /// | |||
inline form &operator + (widgets::base_widget &f) | CPPCMS_DEPRECATED inline form &operator + (widgets::base_wid get &f) | |||
{ | { | |||
add(f); | add(f); | |||
return *this; | return *this; | |||
} | } | |||
/// | /// | |||
/// Set the parent of this form. It is used internally; you should not use it. It is called | /// Set the parent of this form. It is used internally; you should not use it. It is called | |||
/// when the form is added or attached to another form. | /// when the form is added or attached to another form. | |||
/// | /// | |||
virtual void parent(base_form *subform); | virtual void parent(base_form *subform); | |||
skipping to change at line 672 | skipping to change at line 676 | |||
/// | /// | |||
virtual void parent(base_form *subform); | virtual void parent(base_form *subform); | |||
/// | /// | |||
/// Get parent of this form. If this is topmost form , NULL is returned | /// Get parent of this form. If this is topmost form , NULL is returned | |||
/// Note widget is assumed to be assigned to forms o nly | /// Note widget is assumed to be assigned to forms o nly | |||
/// | /// | |||
virtual form *parent(); | virtual form *parent(); | |||
/// | ||||
/// This function should be called before actual loa | ||||
ding | ||||
/// of widgets, it performs cross widgets validation | ||||
/// and causes automatic generation of undefined nam | ||||
es | ||||
/// | ||||
void pre_load(http::context &); | ||||
protected: | protected: | |||
/// | /// | |||
/// This function should be called by overloaded loa d/render methods | /// This function should be called by overloaded loa d/render methods | |||
/// before rendering/loading starts | /// before rendering/loading starts | |||
/// | /// | |||
void auto_generate(form_context *context = 0); | void auto_generate(form_context *context = 0); | |||
private: | private: | |||
void generate(int position,form_context *context = 0 ); | void generate(int position,form_context *context = 0 ); | |||
skipping to change at line 1035 | skipping to change at line 1046 | |||
base_html_input::clear(); | base_html_input::clear(); | |||
loaded_string_.clear(); | loaded_string_.clear(); | |||
} | } | |||
/// | /// | |||
/// Load widget data | /// Load widget data | |||
/// | /// | |||
virtual void load(http::context &context) | virtual void load(http::context &context) | |||
{ | { | |||
auto_generate(); | pre_load(context); | |||
loaded_string_.clear(); | loaded_string_.clear(); | |||
set(false); | set(false); | |||
valid(true); | valid(true); | |||
http::request::form_type::const_iterator p; | http::request::form_type::const_iterator p; | |||
http::request::form_type const &request=cont ext.request().post_or_get(); | http::request::form_type const &request=cont ext.request().post_or_get(); | |||
p=request.find(name()); | p=request.find(name()); | |||
if(p==request.end()) { | if(p==request.end()) { | |||
End of changes. 6 change blocks. | ||||
3 lines changed or deleted | 16 lines changed or added | |||
function.h | function.h | |||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
#ifndef BOOSTER_FUNCTION_H | #ifndef BOOSTER_FUNCTION_H | |||
#define BOOSTER_FUNCTION_H | #define BOOSTER_FUNCTION_H | |||
#include <booster/backtrace.h> | #include <booster/backtrace.h> | |||
#include <booster/clone_ptr.h> | #include <booster/clone_ptr.h> | |||
namespace booster { | namespace booster { | |||
template<typename Type> | template<typename Type> | |||
class function; | class function; | |||
/// | ||||
/// \brief This exception is thrown in case of an attempt to call to | ||||
/// unassigned \ref booster::function | ||||
/// | ||||
class bad_function_call : public booster::runtime_error { | class bad_function_call : public booster::runtime_error { | |||
public: | public: | |||
bad_function_call() : | bad_function_call() : | |||
booster::runtime_error("bad_function_call") | booster::runtime_error("bad_function_call") | |||
{ | { | |||
} | } | |||
}; | }; | |||
#ifdef BOOSTER_DOXYGEN_DOCS | #ifdef BOOSTER_DOXYGEN_DOCS | |||
/// | /// | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 4 lines changed or added | |||
http_request.h | http_request.h | |||
---|---|---|---|---|
skipping to change at line 265 | skipping to change at line 265 | |||
/// | /// | |||
/// Get all cookies sent with this request | /// Get all cookies sent with this request | |||
/// | /// | |||
cookies_type const &cookies(); | cookies_type const &cookies(); | |||
/// | /// | |||
/// Get cookie by its name, if not assigned returns empty co okie | /// Get cookie by its name, if not assigned returns empty co okie | |||
/// | /// | |||
cookie const &cookie_by_name(std::string const &name); | cookie const &cookie_by_name(std::string const &name); | |||
/// | /// | |||
/// Fetch GET value by name, if name not exists or more then | ||||
one | ||||
/// entry with same name exists, empty string is returned | ||||
/// | ||||
std::string get(std::string const &name); | ||||
/// | ||||
/// Fetch POST value by name, if name not exists or more the | ||||
n one | ||||
/// entry with same name exists, empty string is returned | ||||
/// | ||||
std::string post(std::string const &name); | ||||
/// | ||||
/// form-data GET part of request | /// form-data GET part of request | |||
/// | /// | |||
form_type const &get(); | form_type const &get(); | |||
/// | /// | |||
/// form-data POST part of request | /// form-data POST part of request | |||
/// | /// | |||
form_type const &post(); | form_type const &post(); | |||
/// | /// | |||
/// form-data POST or GET according to reuqest_method() | /// form-data POST or GET according to reuqest_method() | |||
/// | /// | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 12 lines changed or added | |||
io_service.h | io_service.h | |||
---|---|---|---|---|
skipping to change at line 36 | skipping to change at line 36 | |||
class event_loop_impl; | class event_loop_impl; | |||
/// | /// | |||
/// \brief this is the central event loop that dispatches all reques ts. | /// \brief this is the central event loop that dispatches all reques ts. | |||
/// | /// | |||
/// This all this class member functions are thread safe unless spec ified otherwise. | /// This all this class member functions are thread safe unless spec ified otherwise. | |||
/// | /// | |||
/// Sinlge or multiple threads may execute run() member function and dispatch its handlers, this class | /// Sinlge or multiple threads may execute run() member function and dispatch its handlers, this class | |||
/// also can be safely created before fork and used after it | /// also can be safely created before fork and used after it | |||
/// | /// | |||
class BOOSTER_API io_service : public noncopyable { | class BOOSTER_API io_service : public noncopyable, public io_events { | |||
public: | public: | |||
static const int in = 1 << 0; | ||||
static const int out = 1 << 1; | ||||
/// | /// | |||
/// Create io service using specific reactor type and not de fault one (see reactor's class use_* constants) | /// Create io service using specific reactor type and not de fault one (see reactor's class use_* constants) | |||
/// | /// | |||
io_service(int reactor_type); | io_service(int reactor_type); | |||
/// | /// | |||
/// Create io service using default reactor | /// Create io service using default reactor | |||
/// | /// | |||
io_service(); | io_service(); | |||
/// | /// | |||
/// Destroy io_service. It should be stopped before!. | /// Destroy io_service. It should be stopped before!. | |||
/// | /// | |||
~io_service(); | ~io_service(); | |||
/// | /// | |||
/// Set event handler \a h for file descriptor \fd. \a event | /// Set event handler \a h for file descriptor \a fd. \a eve | |||
can be in, out or in. | nt can be \ref io_events::in, \ref io_events::out | |||
/// or \ref io_events::in | \ref io_events::out. | ||||
/// | /// | |||
/// Error handling: | /// Error handling: | |||
/// | /// | |||
/// - If invalid \a event type is given, std::invalid_argume nt is throw. | /// - If invalid \a event type is given, std::invalid_argume nt is throw. | |||
/// - All other applicative errors are always reported using event handler \a h and never thrown directly. | /// - All other applicative errors are always reported using event handler \a h and never thrown directly. | |||
/// | /// | |||
void set_io_event(native_type fd,int event,event_handler con st &h); | void set_io_event(native_type fd,int event,event_handler con st &h); | |||
/// | /// | |||
/// Cancel all io-events for file descriptor \a fd. Event ha ndlers associated with this descriptor are | /// Cancel all io-events for file descriptor \a fd. Event ha ndlers associated with this descriptor are | |||
/// dispatched asynchronously with aio_error::canceled error code. | /// dispatched asynchronously with aio_error::canceled error code. | |||
End of changes. 3 change blocks. | ||||
6 lines changed or deleted | 4 lines changed or added | |||
reactor.h | reactor.h | |||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
#define BOOSTER_AIO_REACTOR_H | #define BOOSTER_AIO_REACTOR_H | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <booster/aio/types.h> | #include <booster/aio/types.h> | |||
#include <memory> | #include <memory> | |||
#include <string> | #include <string> | |||
namespace booster { | namespace booster { | |||
namespace aio { | namespace aio { | |||
class reactor_impl; | class reactor_impl; | |||
class BOOSTER_API reactor { | /// | |||
/// \brief This class is an abstraction of platform dependent pollin | ||||
g API. | ||||
/// | ||||
/// It abstracts platform specific APIs like epoll, /dev/poll, kqueu | ||||
e, poll | ||||
/// and select. | ||||
/// | ||||
/// It provides platform indepenent functionality for polling file d | ||||
escriptions | ||||
/// in efficient way | ||||
/// | ||||
class BOOSTER_API reactor : public io_events { | ||||
reactor(reactor const &); | reactor(reactor const &); | |||
void operator=(reactor const &); | void operator=(reactor const &); | |||
public: | public: | |||
static const int in = 1 << 0; | ||||
static const int out = 1 << 1; | ||||
static const int err = 1 << 2; | ||||
static const int use_default = 0; | static const int use_default = 0; //< Best polling device | |||
static const int use_select = 1; | available on the OS | |||
static const int use_poll = 2; | static const int use_select = 1; //< select() API, defau | |||
static const int use_epoll = 3; | lt on Windows | |||
static const int use_dev_poll = 4; | static const int use_poll = 2; //< poll() API default | |||
static const int use_kqueue = 5; | on POSIX platforms without better polling support | |||
static const int use_max = use_kqueue; | static const int use_epoll = 3; //< epoll() available a | |||
nd default on Linux | ||||
static const int use_dev_poll = 4; //< /dev/poll available | ||||
and default on Solaris and HP-UX | ||||
static const int use_kqueue = 5; //< kqueue available an | ||||
d default on BSD and Mac OS X. | ||||
static const int use_max = use_kqueue; //< Maximal n | ||||
umber | ||||
/// \brief structure that defines output events | ||||
struct event { | struct event { | |||
native_type fd; | native_type fd; //< A descriptor that event occurred | |||
int events; | on | |||
int events; //< a bit mask of events \see io_eve | ||||
nts | ||||
}; | }; | |||
/// | ||||
/// Create a new polling device using \a hint recommendation | ||||
. If provided | ||||
/// device is not supported the default is used | ||||
/// | ||||
reactor(int hint = use_default); | reactor(int hint = use_default); | |||
~reactor(); | ~reactor(); | |||
/// | ||||
/// Add \a fd to watch list, flags can be a or mask of \ref | ||||
io_events::in, \ref io_events::out | ||||
/// and \ref io_events::err | ||||
/// | ||||
/// If flags=0 removes the \a fd from the watch list | ||||
/// | ||||
/// If error occurs throws \ref system::system_error | ||||
/// | ||||
void select(native_type fd,int flags); | void select(native_type fd,int flags); | |||
/// | ||||
/// Add \a fd to watch list, flags can be a or mask of \ref | ||||
io_events::in, | ||||
/// \ref io_events::out and \ref io_events::err | ||||
/// | ||||
/// If flags=0 removes the \a fd from the watch list | ||||
/// | ||||
/// If error occurs, the error code is assigned to \a e | ||||
/// | ||||
void select(native_type fd,int flags,system::error_code &e); | void select(native_type fd,int flags,system::error_code &e); | |||
/// | ||||
/// Removes the \a fd from the watch list | ||||
/// | ||||
/// If error occurs throws \ref system::system_error | ||||
/// | ||||
void remove(native_type fd) | void remove(native_type fd) | |||
{ | { | |||
select(fd,0); | select(fd,0); | |||
} | } | |||
/// | ||||
/// Removes the \a fd from the watch list | ||||
/// | ||||
/// If error occurs, the error code is assigned to \a e | ||||
/// | ||||
void remove(native_type fd,system::error_code &e) | void remove(native_type fd,system::error_code &e) | |||
{ | { | |||
select(fd,0,e); | select(fd,0,e); | |||
} | } | |||
/// | ||||
/// Poll for the events, wait at most \a timeout microsecond | ||||
s. | ||||
/// Save up to \a n values to the \a events vector. | ||||
/// | ||||
/// Returns number of events recorded. Returns 0 if timeout | ||||
occurred. | ||||
/// | ||||
/// If error occurs throws \ref system::system_error | ||||
/// | ||||
int poll(event *events,int n,int timeout); | int poll(event *events,int n,int timeout); | |||
/// | ||||
/// Poll for the events, wait at most \a timeout microsecond | ||||
s. | ||||
/// Save up to \a n values to the \a events vector. | ||||
/// | ||||
/// Returns number of events recorded. Returns 0 if timeout | ||||
occurred. | ||||
/// | ||||
/// If error occurs, the error code is assigned to \a e | ||||
/// | ||||
int poll(event *events,int n,int timeout,system::error_code &e); | int poll(event *events,int n,int timeout,system::error_code &e); | |||
/// | ||||
/// Get the actual name of the polling device used. | ||||
/// | ||||
std::string name() const; | std::string name() const; | |||
private: | private: | |||
std::auto_ptr<reactor_impl> impl_; | std::auto_ptr<reactor_impl> impl_; | |||
}; | }; | |||
} // aio | } // aio | |||
} // booster | } // booster | |||
#endif | #endif | |||
End of changes. 13 change blocks. | ||||
13 lines changed or deleted | 88 lines changed or added | |||
service.h | service.h | |||
---|---|---|---|---|
skipping to change at line 29 | skipping to change at line 29 | |||
#ifndef CPPCMS_SERVICE_H | #ifndef CPPCMS_SERVICE_H | |||
#define CPPCMS_SERVICE_H | #define CPPCMS_SERVICE_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
#include <booster/hold_ptr.h> | #include <booster/hold_ptr.h> | |||
#include <booster/function.h> | #include <booster/function.h> | |||
#include <locale> | #include <locale> | |||
#include <memory> | #include <memory> | |||
#include <cppcms/locale_fwd.h> | #include <cppcms/locale_fwd.h> | |||
#include <cppcms/json.h> | ||||
namespace booster { | namespace booster { | |||
namespace aio { | namespace aio { | |||
class io_service; | class io_service; | |||
} | } | |||
} | } | |||
/// | /// | |||
/// \brief This is the namespace where all CppCMS functionality is placed | /// \brief This is the namespace where all CppCMS functionality is placed | |||
/// | /// | |||
skipping to change at line 71 | skipping to change at line 72 | |||
/// | /// | |||
/// This is the central class that is responsible for management of CppCMS services: management of HTTP requests and | /// This is the central class that is responsible for management of CppCMS services: management of HTTP requests and | |||
/// responses, sessions, cache and much more services. It is the cen tral class that runs during execution of any CppCMS | /// responses, sessions, cache and much more services. It is the cen tral class that runs during execution of any CppCMS | |||
/// service. | /// service. | |||
/// | /// | |||
class CPPCMS_API service : public booster::noncopyable | class CPPCMS_API service : public booster::noncopyable | |||
{ | { | |||
public: | public: | |||
/// | /// | |||
/// Load configuration settings from the command line parame | ||||
ters. This object can be passed | ||||
/// to service(json::value const &v) constructor allowing to | ||||
alter these settings before | ||||
/// creating the actual service object. | ||||
/// | ||||
static json::value load_settings(int argc,char *argv[]); | ||||
/// | ||||
/// Create a new service, passing all configuration settings via json::value instead of parsing command line parameters. | /// Create a new service, passing all configuration settings via json::value instead of parsing command line parameters. | |||
/// | /// | |||
service(json::value const &v); | service(json::value const &v); | |||
/// | /// | |||
/// Parse command line parameters, get the configuration fil e and additional options and create the service. | /// Parse command line parameters, get the configuration fil e and additional options and create the service. | |||
/// | /// | |||
/// Note for Windows users: argv is assumed to be UTF-8 enco ded strings, if you want pass non-ascii or "wide" parameters | /// Note for Windows users: argv is assumed to be UTF-8 enco ded strings, if you want pass non-ascii or "wide" parameters | |||
/// you need convert them from UTF-16 to UTF-8. For example you can use booster::nowide::convert functions. | /// you need convert them from UTF-16 to UTF-8. For example you can use booster::nowide::convert functions. | |||
/// | /// | |||
service(int argc,char *argv[]); | service(int argc,char *argv[]); | |||
skipping to change at line 190 | skipping to change at line 197 | |||
/// with same id. | /// with same id. | |||
/// | /// | |||
/// So if an application want to run certain activity that c an't be executed in multiple processes it can setup an after_fork | /// So if an application want to run certain activity that c an't be executed in multiple processes it can setup an after_fork | |||
/// handle that would check the process id and start this ac tivity. | /// handle that would check the process id and start this ac tivity. | |||
/// | /// | |||
/// Under Windows and Cygwin it is always 0. | /// Under Windows and Cygwin it is always 0. | |||
/// | /// | |||
int process_id(); | int process_id(); | |||
/// \cond INTERNAL | /// \cond INTERNAL | |||
// internal functions never call it directly | ||||
cppcms::impl::service &impl(); | cppcms::impl::service &impl(); | |||
impl::cached_settings const &cached_settings(); | impl::cached_settings const &cached_settings(); | |||
#ifdef CPPCMS_WIN_NATIVE | ||||
void impl_run_as_windows_service(); | ||||
#endif | ||||
void impl_run_prepare(); | ||||
void impl_run_event_loop(); | ||||
/// \endcond | /// \endcond | |||
private: | private: | |||
void setup(); | void setup(); | |||
void setup_logging(); | void setup_logging(); | |||
std::auto_ptr<cppcms::impl::cgi::acceptor> setup_acceptor(js on::value const &,int,int shift=0); | std::auto_ptr<cppcms::impl::cgi::acceptor> setup_acceptor(js on::value const &,int,int shift=0); | |||
void load_settings(int argc,char *argv[]); | ||||
void stop(); | void stop(); | |||
void start_acceptor(bool after_fork=false); | void start_acceptor(bool after_fork=false); | |||
void setup_exit_handling(); | void setup_exit_handling(); | |||
bool prefork(); | bool prefork(); | |||
void impl_run(); | ||||
#ifdef CPPCMS_WIN_NATIVE | ||||
void install_service(); | ||||
void uninstall_service(); | ||||
#endif | ||||
booster::hold_ptr<impl::service> impl_; | booster::hold_ptr<impl::service> impl_; | |||
}; | }; | |||
} // | } // | |||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
1 lines changed or deleted | 24 lines changed or added | |||
session_interface.h | session_interface.h | |||
---|---|---|---|---|
skipping to change at line 27 | skipping to change at line 27 | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#ifndef CPPCMS_SESSION_INTERFACE_H | #ifndef CPPCMS_SESSION_INTERFACE_H | |||
#define CPPCMS_SESSION_INTERFACE_H | #define CPPCMS_SESSION_INTERFACE_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
#include <booster/hold_ptr.h> | #include <booster/hold_ptr.h> | |||
#include <booster/shared_ptr.h> | #include <booster/shared_ptr.h> | |||
#include <cppcms/cstdint.h> | #include <cppcms/cstdint.h> | |||
#include <cppcms/cppcms_error.h> | ||||
#include <cppcms/serialization_classes.h> | #include <cppcms/serialization_classes.h> | |||
#include <string> | #include <string> | |||
#include <map> | #include <map> | |||
#include <memory> | #include <memory> | |||
#include <sstream> | #include <sstream> | |||
#include <typeinfo> | #include <typeinfo> | |||
namespace cppcms { | namespace cppcms { | |||
namespace http { | namespace http { | |||
class context; | class context; | |||
class request; | class request; | |||
class response; | class response; | |||
} | } | |||
class session_api; | class session_api; | |||
/// | /// | |||
/// \brief This exception is thrown when CSRF attempt is suspected: | ||||
/// | ||||
class CPPCMS_API request_forgery_error : public cppcms_error { | ||||
public: | ||||
/// Create an exception object | ||||
request_forgery_error() : | ||||
cppcms_error("Cross site request forgery detected") | ||||
{ | ||||
} | ||||
}; | ||||
/// | ||||
/// \brief This class provides an access to an application for session mana gement | /// \brief This class provides an access to an application for session mana gement | |||
/// | /// | |||
/// Usually it is accessed via application::session member function. | /// Usually it is accessed via application::session member function. | |||
/// | /// | |||
/// Note, when the application is asynchronous, the sessions should be load ed manually as | /// Note, when the application is asynchronous, the sessions should be load ed manually as | |||
/// fetching information from session may be not so cheap | /// fetching information from session may be not so cheap | |||
/// | /// | |||
/// Generally, session data is represented as a map of key-value strings th at can be read | /// Generally, session data is represented as a map of key-value strings th at can be read | |||
/// and written. All changes in session should be done before headers are w ritten to the output | /// and written. All changes in session should be done before headers are w ritten to the output | |||
/// (before requesting an output stream from http::response object) | /// (before requesting an output stream from http::response object) | |||
skipping to change at line 289 | skipping to change at line 302 | |||
/// from event loop when using asynchronous applications. | /// from event loop when using asynchronous applications. | |||
/// | /// | |||
bool is_blocking(); | bool is_blocking(); | |||
/// | /// | |||
/// When using session id based session - force generation of new se ssion id to prevent session | /// When using session id based session - force generation of new se ssion id to prevent session | |||
/// fixation attacks | /// fixation attacks | |||
/// | /// | |||
void reset_session(); | void reset_session(); | |||
/// | ||||
/// Check that the CSRF token is the same as in the session object, | ||||
it does not do any checks, whether | ||||
/// CSRF enabled or the request method is correct. It should be used | ||||
for custom request handling (like | ||||
/// custom content types for RESTful services. | ||||
/// | ||||
/// Returns true if the token is valid, otherwise returns false | ||||
/// | ||||
bool validate_csrf_token(std::string const &str); | ||||
/// | ||||
/// Check that there is no Cross Site Request Forgery Attempt. | ||||
/// | ||||
/// If CSRF checks enabled it validates that there is a valid CSRF t | ||||
oken is submitted via POST request | ||||
/// or via X-CSRF-Token header for AJAX requests. | ||||
/// | ||||
/// \note it is checked for POST requests only. | ||||
/// | ||||
void validate_request_origin(); | ||||
/// | ||||
/// Set CSRF validation mode. | ||||
/// | ||||
/// If \a required \c is true then validate_request_origin() would t | ||||
hrow \ref request_forgery_error | ||||
/// if the CSRF token is not valid. | ||||
/// | ||||
/// Setting it to false would prevent from validate_request_origin() | ||||
to do any checks. | ||||
/// | ||||
/// \note The default is defined in the configuration property \c se | ||||
curity.csrf.automatic. If | ||||
/// its value is not set the default is \c true | ||||
/// | ||||
/// It is useful when some parts of the application do not require C | ||||
SRF validation regardless | ||||
/// the status of sepecifc session owner | ||||
/// | ||||
void request_origin_validation_is_required(bool required); | ||||
/// | ||||
/// Get CSRF token that is stored in the session that can be used fo | ||||
r validation | ||||
/// of the request origin | ||||
/// | ||||
std::string get_csrf_token(); | ||||
/// | ||||
/// Get the cooke name that holds CSRF token. Note it can be used on | ||||
ly if security.csrf.exposed | ||||
/// is set to true (which is not by default) | ||||
/// | ||||
std::string get_csrf_token_cookie_name(); | ||||
private: | private: | |||
friend class http::response; | friend class http::response; | |||
friend class http::request; | friend class http::request; | |||
struct entry; | struct entry; | |||
typedef std::map<std::string,entry> data_type; | typedef std::map<std::string,entry> data_type; | |||
data_type data_,data_copy_; | data_type data_,data_copy_; | |||
http::context *context_; | http::context *context_; | |||
skipping to change at line 315 | skipping to change at line 373 | |||
int how_; | int how_; | |||
// Information from session data | // Information from session data | |||
time_t timeout_in_; | time_t timeout_in_; | |||
uint32_t new_session_ : 1; | uint32_t new_session_ : 1; | |||
uint32_t saved_ : 1; | uint32_t saved_ : 1; | |||
uint32_t on_server_ : 1; | uint32_t on_server_ : 1; | |||
uint32_t loaded_ : 1; | uint32_t loaded_ : 1; | |||
uint32_t reset_ : 1; | uint32_t reset_ : 1; | |||
uint32_t reserved_ : 27; | uint32_t csrf_checked_ : 1; | |||
uint32_t csrf_do_validation_ : 1; | ||||
uint32_t csrf_validation_ : 1; | ||||
uint32_t reserved_ : 24; | ||||
std::string temp_cookie_; | std::string temp_cookie_; | |||
// storage itself | // storage itself | |||
booster::shared_ptr<session_api> storage_; | booster::shared_ptr<session_api> storage_; | |||
struct _data; | struct _data; | |||
booster::hold_ptr<_data> d; // for future use | booster::hold_ptr<_data> d; // for future use | |||
int cookie_age(); | int cookie_age(); | |||
time_t session_age(); | time_t session_age(); | |||
void check(); | void check(); | |||
void update_exposed(bool); | void update_exposed(bool); | |||
void set_session_cookie(int64_t age,std::string const &data,std::str ing const &key=std::string()); | void set_session_cookie(int64_t age,std::string const &data,std::str ing const &key=std::string()); | |||
void save_data(std::map<std::string,entry> const &data,std::string & s); | void save_data(std::map<std::string,entry> const &data,std::string & s); | |||
void load_data(std::map<std::string,entry> &data,std::string const & s); | void load_data(std::map<std::string,entry> &data,std::string const & s); | |||
std::string generate_csrf_token(); | ||||
}; | }; | |||
} // cppcms | } // cppcms | |||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
1 lines changed or deleted | 72 lines changed or added | |||
steal_buf.h | steal_buf.h | |||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
#include <streambuf> | #include <streambuf> | |||
#include <ostream> | #include <ostream> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <string> | #include <string> | |||
#include <string.h> | #include <string.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
namespace cppcms { | namespace cppcms { | |||
namespace util { | namespace util { | |||
template<size_t on_stack_size = 128> | /// | |||
class steal_buffer : public std::streambuf { | /// \brief Very simple output stream buffer that uses stack for smal | |||
steal_buffer(steal_buffer const &); | l chunks of | |||
void operator=(steal_buffer const &); | /// text and then allocates memory of the default buffer is too smal | |||
l. | ||||
/// | ||||
/// It is something like std::stringbuf with small string optimizati | ||||
on, it also | ||||
/// allows to access the memory without actually creating the string | ||||
itself. | ||||
/// | ||||
/// The template parameter defines how many characters should be all | ||||
ocated | ||||
/// on stack by default before heap is used. | ||||
/// | ||||
template<size_t OnStackSize = 128> | ||||
class stackbuf : public std::streambuf { | ||||
stackbuf(stackbuf const &); | ||||
void operator=(stackbuf const &); | ||||
public: | public: | |||
/// | ||||
/// get the pointer to the beginning of the output buffer | ||||
/// | ||||
char *begin() | char *begin() | |||
{ | { | |||
return pbase(); | return pbase(); | |||
} | } | |||
/// | ||||
/// get the pointer to the end of the output buffer | ||||
/// | ||||
char *end() | char *end() | |||
{ | { | |||
return pptr(); | return pptr(); | |||
} | } | |||
steal_buffer(std::ostream &out) | /// | |||
{ | /// get the 0 terminated string from the buffer. | |||
init(); | /// | |||
steal(out); | char *c_str() | |||
} | ||||
steal_buffer() | ||||
{ | { | |||
init(); | *pptr() = 0; | |||
return begin(); | ||||
} | } | |||
void steal(std::ostream &out) | /// | |||
/// get the std::string from the buffer. | ||||
/// | ||||
std::string str() | ||||
{ | { | |||
release(); | return std::string(begin(),size_t(end()-begin())); | |||
stolen_ = out.rdbuf(this); | ||||
stream_ = &out; | ||||
} | } | |||
void release() | stackbuf() | |||
{ | { | |||
if(stream_ && stolen_) { | init(); | |||
stream_->rdbuf(stolen_); | ||||
} | ||||
stream_ = 0; | ||||
stolen_ = 0; | ||||
} | } | |||
~steal_buffer() | ~stackbuf() | |||
{ | { | |||
release(); | ||||
free(on_heap_); | free(on_heap_); | |||
} | } | |||
protected: | ||||
int overflow(int c) | int overflow(int c) | |||
{ | { | |||
size_t current_size; | size_t current_size; | |||
size_t new_size; | size_t new_size; | |||
if(pbase() == on_stack_) { | if(pbase() == on_stack_) { | |||
current_size = on_stack_size; | current_size = OnStackSize; | |||
new_size = on_stack_size * 2; | new_size = OnStackSize * 2; | |||
on_heap_ = (char *)malloc(new_size); | on_heap_ = (char *)malloc(new_size + 1); | |||
if(!on_heap_) | if(!on_heap_) | |||
throw std::bad_alloc(); | throw std::bad_alloc(); | |||
memcpy(on_heap_,on_stack_,current_size); | memcpy(on_heap_,on_stack_,current_size); | |||
} | } | |||
else { | else { | |||
current_size = pptr() - pbase(); | current_size = pptr() - pbase(); | |||
new_size = current_size * 2; | new_size = current_size * 2; | |||
char *new_ptr = (char *)realloc(on_heap_,new _size); | char *new_ptr = (char *)realloc(on_heap_,new _size + 1); | |||
if(!new_ptr) | if(!new_ptr) | |||
throw std::bad_alloc(); | throw std::bad_alloc(); | |||
on_heap_ = new_ptr; | on_heap_ = new_ptr; | |||
} | } | |||
setp(on_heap_,on_heap_ + new_size); | setp(on_heap_,on_heap_ + new_size); | |||
pbump(current_size); | pbump(current_size); | |||
if(c!=EOF) | if(c!=EOF) | |||
sputc(c); | sputc(c); | |||
return 0; | return 0; | |||
} | } | |||
private: | private: | |||
void init() | void init() | |||
{ | { | |||
on_heap_ = 0; | on_heap_ = 0; | |||
setp(on_stack_,on_stack_+OnStackSize); | ||||
} | ||||
char *on_heap_; | ||||
char on_stack_[OnStackSize + 1]; | ||||
}; | ||||
template<size_t Size = 128> | ||||
class steal_buffer : public stackbuf<Size> { | ||||
public: | ||||
steal_buffer(std::ostream &out) | ||||
{ | ||||
stolen_ = 0; | stolen_ = 0; | |||
stream_ = 0; | stream_ = 0; | |||
setp(on_stack_,on_stack_+on_stack_size); | steal(out); | |||
} | } | |||
char *on_heap_; | steal_buffer() | |||
{ | ||||
stolen_ = 0; | ||||
stream_ = 0; | ||||
} | ||||
void steal(std::ostream &out) | ||||
{ | ||||
release(); | ||||
stolen_ = out.rdbuf(this); | ||||
stream_ = &out; | ||||
} | ||||
void release() | ||||
{ | ||||
if(stream_ && stolen_) { | ||||
stream_->rdbuf(stolen_); | ||||
} | ||||
stream_ = 0; | ||||
stolen_ = 0; | ||||
} | ||||
~steal_buffer() | ||||
{ | ||||
release(); | ||||
} | ||||
private: | ||||
std::streambuf *stolen_; | std::streambuf *stolen_; | |||
std::ostream *stream_; | std::ostream *stream_; | |||
char on_stack_[on_stack_size]; | }; | |||
template<size_t Size = 128> | ||||
class stackstream : public std::ostream { | ||||
public: | ||||
stackstream() : std::ostream(0) | ||||
{ | ||||
rbbuf(&buf_); | ||||
} | ||||
char *begin() | ||||
{ | ||||
return buf_->begin(); | ||||
} | ||||
char *end() | ||||
{ | ||||
return buf_->end(); | ||||
} | ||||
char *c_str() | ||||
{ | ||||
return buf_.c_str(); | ||||
} | ||||
std::string str() | ||||
{ | ||||
return buf_.str(); | ||||
} | ||||
private: | ||||
stackbuf<Size> buf_; | ||||
}; | }; | |||
} // util | } // util | |||
} // cppcms | } // cppcms | |||
#endif | #endif | |||
End of changes. 18 change blocks. | ||||
30 lines changed or deleted | 108 lines changed or added | |||
types.h | types.h | |||
---|---|---|---|---|
skipping to change at line 51 | skipping to change at line 51 | |||
typedef enum { | typedef enum { | |||
pf_unix, | pf_unix, | |||
pf_inet, | pf_inet, | |||
pf_inet6 | pf_inet6 | |||
} family_type; | } family_type; | |||
typedef enum { | typedef enum { | |||
sock_stream, | sock_stream, | |||
sock_datagram | sock_datagram | |||
} socket_type; | } socket_type; | |||
/// | ||||
/// \brief the struct that collects multiple event | ||||
/// types for polling. | ||||
/// | ||||
struct io_events { | ||||
static const int in = 1 << 0; //< Event socket rea | ||||
dability | ||||
static const int out = 1 << 1; //< Event socket wri | ||||
tability | ||||
static const int err = 1 << 2; //< Error on socket | ||||
or OOB data | ||||
}; | ||||
} | } | |||
} | } | |||
#endif | #endif | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 13 lines changed or added | |||
util.h | util.h | |||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_LOCALE_UTIL_HPP | #ifndef BOOSTER_LOCALE_UTIL_HPP | |||
#define BOOSTER_LOCALE_UTIL_HPP | #define BOOSTER_LOCALE_UTIL_HPP | |||
#include <locale> | #include <locale> | |||
#include <typeinfo> | #include <typeinfo> | |||
#include <booster/cstdint.h> | #include <booster/cstdint.h> | |||
#include <booster/locale/utf.h> | ||||
#include <booster/locale/generator.h> | #include <booster/locale/generator.h> | |||
#include <booster/assert.h> | #include <booster/assert.h> | |||
#include <vector> | #include <vector> | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \brief This namespace provides various utility function useful for Boos t.Locale backends | /// \brief This namespace provides various utility function useful for Boos t.Locale backends | |||
/// implementations | /// implementations | |||
/// | /// | |||
skipping to change at line 83 | skipping to change at line 84 | |||
/// these converters for certain character set. | /// these converters for certain character set. | |||
/// | /// | |||
class base_converter { | class base_converter { | |||
public: | public: | |||
/// | /// | |||
/// This value should be returned when an illegal input sequence or code-point is observed: | /// This value should be returned when an illegal input sequence or code-point is observed: | |||
/// For example if a UCS-32 code-point is in the range reserved for UTF-16 surrogates | /// For example if a UCS-32 code-point is in the range reserved for UTF-16 surrogates | |||
/// or an invalid UTF-8 sequence is found | /// or an invalid UTF-8 sequence is found | |||
/// | /// | |||
static const uint32_t illegal=0xFFFFFFFF; | static const uint32_t illegal=utf::illegal; | |||
/// | /// | |||
/// This value is returned in following cases: The of incomplete in put sequence was found or | /// This value is returned in following cases: The of incomplete in put sequence was found or | |||
/// insufficient output buffer was provided so complete output coul d not be written. | /// insufficient output buffer was provided so complete output coul d not be written. | |||
/// | /// | |||
static const uint32_t incomplete=0xFFFFFFFE; | static const uint32_t incomplete=utf::incomplete; | |||
virtual ~base_converter() | virtual ~base_converter() | |||
{ | { | |||
} | } | |||
/// | /// | |||
/// Return the maximal length that one Unicode code-point can be co nverted to, for example | /// Return the maximal length that one Unicode code-point can be co nverted to, for example | |||
/// for UTF-8 it is 4, for Shift-JIS it is 2 and ISO-8859-1 is 1 | /// for UTF-8 it is 4, for Shift-JIS it is 2 and ISO-8859-1 is 1 | |||
/// | /// | |||
virtual int max_len() const | virtual int max_len() const | |||
{ | { | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 3 lines changed or added | |||
view.h | view.h | |||
---|---|---|---|---|
skipping to change at line 29 | skipping to change at line 29 | |||
#ifndef CPPCMS_VIEW_H | #ifndef CPPCMS_VIEW_H | |||
#define CPPCMS_VIEW_H | #define CPPCMS_VIEW_H | |||
#include <cppcms/form.h> | #include <cppcms/form.h> | |||
#include <cppcms/filters.h> | #include <cppcms/filters.h> | |||
#include <cppcms/base_view.h> | #include <cppcms/base_view.h> | |||
#include <cppcms/views_pool.h> | #include <cppcms/views_pool.h> | |||
#include <cppcms/application.h> | #include <cppcms/application.h> | |||
#include <cppcms/url_mapper.h> | #include <cppcms/url_mapper.h> | |||
#include <cppcms/copy_filter.h> | #include <cppcms/copy_filter.h> | |||
#include <cppcms/cache_interface.h> | #include <cppcms/cache_interface.h> | |||
#include <cppcms/session_interface.h> | ||||
#endif | #endif | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 1 lines changed or added | |||
xss.h | xss.h | |||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
#include <booster/copy_ptr.h> | #include <booster/copy_ptr.h> | |||
#include <booster/regex.h> | #include <booster/regex.h> | |||
#include <booster/function.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 { | |||
namespace json { | ||||
class value; | ||||
} | ||||
/// | /// | |||
/// \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 { | |||
skipping to change at line 105 | skipping to change at line 108 | |||
/// it and use it for filtering and validation - and make yo ur attackers cry :-). | /// it and use it for filtering and validation - and make yo ur attackers cry :-). | |||
/// | /// | |||
/// | /// | |||
class CPPCMS_API rules { | class CPPCMS_API rules { | |||
public: | public: | |||
rules(); | rules(); | |||
rules(rules const &); | rules(rules const &); | |||
rules const &operator=(rules const &); | rules const &operator=(rules const &); | |||
~rules(); | ~rules(); | |||
/// Create rules from JSON object \a r | ||||
/// | ||||
/// The json object the defines the XSS prevention r | ||||
ules. | ||||
/// This object has following properties: | ||||
/// | ||||
/// - "xhtml" - boolean; default true - use XHTML (t | ||||
rue) or HTML input | ||||
/// - "comments" - boolean; setting it to true allow | ||||
s comments, default false | ||||
/// - "numeric_entities" - boolean; setting it to tr | ||||
ue allows numeric_entities, default false | ||||
/// - "entities" - array of strings: list of allowed | ||||
HTML entities besides lt, gt and amp | ||||
/// - "encoding" - string; the encoding of the text | ||||
to validate, by default not checked and the | ||||
/// input is assumed to be ASCII compatible. Alw | ||||
ays specifiy it for multibyte encodings | ||||
/// like Shift-JIS or GBK as they are not ASCII | ||||
compatible. | ||||
/// - "tags" - object with 3 properties of type arra | ||||
y of string: | ||||
/// - "opening_and_closing" - the tags that shou | ||||
ld come in pair like "<b></b>" | ||||
/// - "stand_alone" - the tags that should appea | ||||
r stand alone like "<br/>" | ||||
/// - "any_tag" - the tags that can be both like | ||||
"<input>" | ||||
/// - "attributes" - array of objects that define HT | ||||
ML attributes. Each object consists | ||||
/// of following properties: | ||||
/// - "type" - string - the type of the attribut | ||||
e one of: "boolean", "uri", "relative_uri", | ||||
/// "absolute_uri", "integer", "regex". | ||||
/// - "scheme" - string the allowed URI scheme - | ||||
regular expression like "(http|ftp)". Used with | ||||
/// "uri" and "absolute_uri" type | ||||
/// - "expression" - string the regular express | ||||
ion that defines the value that the attribute | ||||
/// should match. | ||||
/// - "tags" - array of strings - list of tags t | ||||
hat this attribute is allowed for. | ||||
/// - "attributes" - array of strings - lisf of | ||||
names of the attribute | ||||
/// - "pairs" - array of objects that consists o | ||||
f two properities "tag" and "attr" of | ||||
/// type string that define tag and attr | ||||
ibuted that such type of property | ||||
/// should be allowed for. | ||||
/// | ||||
/// The extra properties that are not defined by thi | ||||
s scheme are ingored | ||||
/// | ||||
/// For example: | ||||
/// \code | ||||
/// { | ||||
/// "xhtml" : true, | ||||
/// "encoding" : "UTF-8", | ||||
/// "entities" : [ "nbsp" , "copy" ], | ||||
/// "comments" : false, | ||||
/// "numeric_entities" : false, | ||||
/// "tags" : { | ||||
/// "opening_and_closing" : [ | ||||
/// "p", "b", "i", "tt", | ||||
/// "a", | ||||
/// "strong", "em", | ||||
/// "sub", "sup", | ||||
/// "ol", "ul", "li", | ||||
/// "dd", "dt", "dl", | ||||
/// "blockquote","code", "pre", | ||||
/// "span", "div" | ||||
/// ], | ||||
/// "stand_alone" : [ "br", "hr", "img" | ||||
] | ||||
/// ], | ||||
/// "attributes": [ | ||||
/// { | ||||
/// "tags" : [ "p", "li", "ul" ] | ||||
/// "attr" : [ "style" ], | ||||
/// "type" : "regex", | ||||
/// "expression" : "\\s*text-alg | ||||
in:\\s*(center|left|right|justify);?\\s*" | ||||
/// }, | ||||
/// { | ||||
/// "tags" : [ "span", "div" ] | ||||
/// "attr" : [ "class", "id" ], | ||||
/// "type" : "regex", | ||||
/// "expression" : "[a-zA-Z_0-9] | ||||
+" | ||||
/// }, | ||||
/// { | ||||
/// "pairs" : [ | ||||
/// { "tag" : "a", "at | ||||
tr" : "href" }, | ||||
/// { "tag" : "img", "at | ||||
tr" : "src" } | ||||
/// ], | ||||
/// "type" : "absolute_uri", | ||||
/// "scheme" : "(http|https|ftp) | ||||
" | ||||
/// }, | ||||
/// { | ||||
/// "tags" : [ "img" ], | ||||
/// "attr" : [ "alt" ], | ||||
/// "type" : "regex", | ||||
/// "expression" : ".*" | ||||
/// } | ||||
/// ] | ||||
/// } | ||||
/// \endcode | ||||
/// | ||||
rules(json::value const &r); | ||||
/// | ||||
/// Create rules from the JSON object stored in the | ||||
file \a file_name | ||||
/// | ||||
/// \see rules(json::value const&) | ||||
/// | ||||
rules(std::string const &file_name); | ||||
/// | /// | |||
/// How to treat in input | /// How to treat in input | |||
/// | /// | |||
typedef enum { | typedef enum { | |||
xhtml_input, ///< Assume that the input is X HTML | xhtml_input, ///< Assume that the input is X HTML | |||
html_input ///< Assume that the input is H TML | html_input ///< Assume that the input is H TML | |||
} html_type; | } html_type; | |||
/// | /// | |||
/// The type of tag | /// The type of tag | |||
skipping to change at line 208 | skipping to change at line 304 | |||
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 | /// \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(); | CPPCMS_DEPRECATED static booster::regex uri_matcher( ); | |||
/// | /// | |||
/// \deprecated use uri_validator | /// \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); | CPPCMS_DEPRECATED static booster::regex uri_matcher( std::string const &schema); | |||
//// | //// | |||
/// Create a validator that checks URI for safe incl usion in the property. | /// 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. | /// 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&). | /// If you need finer control over allowed schemas, use uri_validator(std::string const&). | |||
/// | /// | |||
static validator_type uri_validator(); | static validator_type uri_validator(); | |||
//// | //// | |||
/// Create a validator that checks URI for safe incl usion in the property. | /// Create a validator that checks URI for safe incl usion in the property. | |||
End of changes. 4 change blocks. | ||||
2 lines changed or deleted | 126 lines changed or added | |||