ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
7.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_MOUNT_POINT_H
  9. #define CPPCMS_MOUNT_POINT_H
  10. #include <cppcms/defs.h>
  11. #include <string>
  12. #include <booster/perl_regex.h>
  13. #include <booster/copy_ptr.h>
  14. namespace cppcms {
  15. ///
  16. /// \brief This class represents application's mount point or the rule on which specific application
  17. /// is selected to process the query.
  18. ///
  19. /// It is used by applications_pool class for mounting applications,
  20. /// and by forwarding managers to match forwarding requests
  21. ///
  22. class CPPCMS_API mount_point {
  23. public:
  24. ///
  25. /// Type that describes what parameter should be passed to application::main(std::string) function
  26. ///
  27. /// When the application selected specific string is passed for matching with application's member function
  28. /// or application's children. This can be CGI variable PATH_INFO or SCRIPT_NAME or their substring taken
  29. /// with regular expression.
  30. ///
  31. /// If selection is \a match_path_info then PATH_INFO passed for matching, otherwide SCRIPT_NAME is used
  32. /// for matching.
  33. ///
  34. /// For example if your service works with SCRIPT_NAME /app and the URL is pointing to /app/page/20
  35. /// such as SCRIPT_NAME is "/app" and PATH_INFO is "/page/20" then the last one will be used for dispatching
  36. /// by cppcms::application::main function.
  37. ///
  38. /// But you may also work with "*.cgi" style URL if your application process all queries comping from
  39. /// "*.cgi" and you have "dummy scripts" at "/cgi-bin/users.cgi" and "/cgi-bin/app.cgi" and you want to match
  40. /// against SCRIPT_NAME rather then PATH_INFO you can use \a match_script_name option and the script name
  41. /// will be used for matching.
  42. ///
  43. typedef enum {
  44. match_path_info, ///< Pass PATH_INFO to applications
  45. match_script_name ///< Pass SCRIPT_NAME to applications
  46. } selection_type;
  47. ///
  48. /// Get regular expression for HTTP_HOST CGI variable matching, if empty, no restrictions given
  49. ///
  50. booster::regex host() const;
  51. ///
  52. /// Get regular expression for SCRIPT_NAME CGI variable matching, if empty, no restrictions given
  53. ///
  54. booster::regex script_name() const;
  55. ///
  56. /// Get regular expression for PATH_INFO CGI variable matching, if empty, no restrictions given
  57. ///
  58. booster::regex path_info() const;
  59. ///
  60. /// Get regular expression subgroup that is passes to application for URL dispatching
  61. ///
  62. int group() const;
  63. ///
  64. /// Get SCRIPT_NAME/PATH_INFO selection
  65. ///
  66. selection_type selection() const;
  67. ///
  68. /// Set regular expression for HTTP_HOST CGI variable matching, if empty, no restrictions given
  69. ///
  70. void host(booster::regex const &);
  71. ///
  72. /// Set regular expression for SCRIPT_NAME CGI variable matching, if empty, no restrictions given
  73. ///
  74. void script_name(booster::regex const &);
  75. ///
  76. /// Set regular expression for PATH_INFO CGI variable matching, if empty, no restrictions given
  77. ///
  78. void path_info(booster::regex const &);
  79. ///
  80. /// Set regular expression subgroup that is passes to application for URL dispatching
  81. ///
  82. void group(int);
  83. ///
  84. /// Get SCRIPT_NAME/PATH_INFO selection
  85. ///
  86. void selection(selection_type);
  87. ///
  88. /// Match \a h - HTTP_HOST, \a s - SCRIPT_NAME, \a p - PATH_INFO against mount point and return
  89. /// true and selected URL path for application
  90. /// Otherwise return false and empty string
  91. ///
  92. std::pair<bool,std::string> match(std::string const &h,std::string const &s,std::string const &p) const;
  93. ///
  94. /// Match \a h - HTTP_HOST, \a s - SCRIPT_NAME, \a p - PATH_INFO against mount point and return
  95. /// true and selected URL path for application
  96. /// Otherwise return false and empty string
  97. ///
  98. std::pair<bool,std::string> match(char const *h,char const *s,char const *p) const;
  99. ///
  100. /// Create default mount point, it uses PATH_INFO for url-dispatching and gives no restriction on URL
  101. ///
  102. mount_point();
  103. ///
  104. /// Destructor
  105. ~mount_point();
  106. ///
  107. /// Copy constructor
  108. ///
  109. mount_point(mount_point const &);
  110. ///
  111. /// Assignment variable
  112. ///
  113. mount_point const &operator=(mount_point const &);
  114. ///
  115. /// Create a mount point that checks PATH_INFO only and passes matched \a group for dispatching
  116. ///
  117. mount_point(std::string const &path,int group);
  118. ///
  119. /// Create a mount point that checks SCRIPT_NAME, and passes PATH_INFO for dispatching
  120. ///
  121. mount_point(std::string const &script);
  122. ///
  123. /// Create a mount point that checks SCRIPT_NAME, PATH_INFO only and passes matched
  124. /// PATH_INFO's \a group for dispatching
  125. ///
  126. mount_point(std::string const &script,std::string const &path,int group);
  127. ///
  128. /// Create a mount point with selection rule \a sel.
  129. ///
  130. /// \param sel selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
  131. /// \param selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according \a sel
  132. /// \param group regular expression subgroup of \a selected_part for URL dispatching
  133. ///
  134. mount_point( selection_type sel,
  135. std::string const &selected_part,
  136. int group);
  137. ///
  138. /// Create a mount point with selection rule \a sel.
  139. ///
  140. /// \param sel -- selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
  141. /// \param non_selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according to
  142. /// opposite of \a sel, if sel is match_path_info then non_selected_part checked against SCRIPT_NAME
  143. /// otherwise it is checked against PATH_INFO
  144. ///
  145. mount_point( selection_type sel,
  146. std::string const &non_selected_part);
  147. ///
  148. /// Create a mount point with selection rule \a sel.
  149. ///
  150. /// \param sel -- selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
  151. /// \param non_selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according to
  152. /// opposite of \a sel, if sel is match_path_info then non_selected_part checked against SCRIPT_NAME
  153. /// otherwise it is checked against PATH_INFO
  154. /// \param selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according \a sel
  155. /// \param group regular expression subgroup of \a selected_part for URL dispatching
  156. ///
  157. mount_point( selection_type sel,
  158. std::string const &non_selected_part,
  159. std::string const &selected_part,
  160. int group);
  161. ///
  162. /// Create fully defined mount rule for matching against, \a http_host - HTTP_HOST, \a script - SCRIPT_NAME,
  163. /// \a path - PATH_INFO, and use subgroup \a group of regular expression selected with \a sel definition.
  164. ///
  165. /// Note: if regular expression is empty, no checks are performed.
  166. ///
  167. mount_point( selection_type sel,
  168. booster::regex const &http_host,
  169. booster::regex const &script,
  170. booster::regex const &path,
  171. int group);
  172. private:
  173. booster::regex host_;
  174. booster::regex script_name_;
  175. booster::regex path_info_;
  176. int group_;
  177. selection_type selection_;
  178. struct _data;
  179. booster::copy_ptr<_data> d;
  180. };
  181. } // cppcms
  182. #endif