Skip to content

Commit 7fde255

Browse files
committed
Now applications use more flexible mount-points
1 parent 32922e9 commit 7fde255

9 files changed

Lines changed: 288 additions & 176 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ set(CPPCMS_SOURCES
315315
src/session_interface.cpp
316316
src/session_memory_storage.cpp
317317
src/rpc_json.cpp
318+
src/mount_point.cpp
318319
cppcms_boost/src/zlib.cpp
319320
cppcms_boost/src/gzip.cpp
320321
)

cppcms/applications_pool.h

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace cppcms {
3131

3232
class application;
3333
class service;
34+
class mount_point;
3435

3536
///
3637
/// \brief Application pool is the central class that holds user created applications
@@ -71,29 +72,13 @@ namespace cppcms {
7172
void mount(std::auto_ptr<factory> aps);
7273

7374
///
74-
/// Mount an application factory \a aps for processing of requests for which CGI PATH_INFO
75-
/// matches the regular expression \a path_info. The marched part of an regular expression \a select would
76-
/// be passed for URL matching.
75+
/// Mount an application factory \a app by mount_point \a point application matching and
76+
/// URL selection rules
7777
///
7878
/// This member function is thread safe.
7979
///
80-
void mount(std::auto_ptr<factory> aps,std::string path_info,int select);
8180

82-
///
83-
/// Mount an application factory \a aps for processing of requests for which CGI SCRIPT_NAME exactly
84-
/// matches \a script_name parameter. CGI PATH_INFO is passed to application for URL matching.
85-
///
86-
/// This member function is thread safe.
87-
///
88-
void mount(std::auto_ptr<factory> aps,std::string script_name);
89-
///
90-
/// Mount an application factory \a aps for processing of requests for which CGI SCRIPT_NAME exactly
91-
/// matches \a script_name parameter. And PATH_INFO patches regular expression \a path_info.
92-
/// The matched part \a select is passed to application for URL matching.
93-
///
94-
/// This member function is thread safe.
95-
///
96-
void mount(std::auto_ptr<factory> aps,std::string script_name,std::string path_info, int select);
81+
void mount(std::auto_ptr<factory> aps,mount_point const &point);
9782

9883
///
9984
/// Mount an asynchronous application \a app for processing of any incoming requests. Application
@@ -103,34 +88,17 @@ namespace cppcms {
10388
///
10489
void mount(booster::intrusive_ptr<application> app);
10590
///
106-
/// Mount an asynchronous application \a app for processing of requests for which CGI PATH_INFO
107-
/// matches the regular expression \a path_info. The marched part of an regular expression \a select would
108-
/// be passed for URL matching.
109-
///
110-
/// This member function is thread safe.
111-
///
112-
void mount(booster::intrusive_ptr<application> app,std::string path_info,int select);
113-
///
114-
/// Mount an asynchronous application \a app for processing of requests for which CGI SCRIPT_NAME exactly
115-
/// matches \a script_name parameter. And PATH_INFO patches regular expression \a path_info.
116-
/// The matched part \a select is passed to application for URL matching.
117-
///
118-
/// This member function is thread safe.
119-
///
120-
void mount(booster::intrusive_ptr<application> app,std::string script_name);
121-
///
122-
/// Mount an asynchronous application \a app for processing of requests for which CGI SCRIPT_NAME exactly
123-
/// matches \a script_name parameter. And PATH_INFO patches regular expression \a path_info.
124-
/// The matched part \a select is passed to application for URL matching.
91+
/// Mount an asynchronous application \a app by mount_point \a point application matching and
92+
/// URL selection rules
12593
///
12694
/// This member function is thread safe.
12795
///
128-
void mount(booster::intrusive_ptr<application> app,std::string script_name,std::string path_info, int select);
96+
void mount(booster::intrusive_ptr<application> app,mount_point const &point);
12997

13098
///
13199
/// Internal API - do not use it directly
132100
///
133-
booster::intrusive_ptr<application> get(std::string script_name,std::string path_info,std::string &match);
101+
booster::intrusive_ptr<application> get(std::string const &h,std::string const &s,std::string const &path_info,std::string &match);
134102
///
135103
/// Internal API - do not use it directly
136104
///
@@ -147,8 +115,6 @@ namespace cppcms {
147115
struct app_data;
148116
struct long_running_app_data;
149117
struct _data;
150-
std::string script_name();
151-
bool matched(basic_app_data &data,std::string script_name,std::string path_info,std::string &matched);
152118
service *srv_;
153119
booster::hold_ptr<_data> d;
154120
};

cppcms/mount_point.h

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,167 @@
2525
#include <booster/copy_ptr.h>
2626

2727
namespace cppcms {
28+
///
29+
/// This class represents application's mount point or the rule on which specific application
30+
/// is selected to process the query. It is used by applications_pool class for mounting applications,
31+
/// and by forwarding managers to match forwarding requests
32+
///
2833
class CPPCMS_API mount_point {
2934
public:
35+
///
36+
/// Type that describes what parameter should be passed to application::main(std::string) function
37+
///
38+
/// When the application selected specific string is passed for matching with application's member function
39+
/// or application's children. This can be CGI variable PATH_INFO or SCRIPT_NAME or their substring taken
40+
/// with regular expression.
41+
///
42+
/// If selection is \a match_path_info then PATH_INFO passed for matching, otherwide SCRIPT_NAME is used
43+
/// for matching.
44+
///
45+
/// For example if your service works with SCRIPT_NAME /app and the URL is pointing to /app/page/20
46+
/// such as SCRIPT_NAME is "/app" and PATH_INFO is "/page/20" then the last one will be used for dispatching
47+
/// by cppcms::application::main function.
48+
///
49+
/// But you may also work with "*.cgi" style URL if your application process all queries comping from
50+
/// "*.cgi" and you have "dummy scripts" at "/cgi-bin/users.cgi" and "/cgi-bin/app.cgi" and you want to match
51+
/// against SCRIPT_NAME rather then PATH_INFO you can use \a match_script_name option and the script name
52+
/// will be used for matching.
53+
///
3054
typedef enum {
31-
match_path_info,
32-
match_script_name
55+
match_path_info, ///< Pass PATH_INFO to applications
56+
match_script_name ///< Pass SCRIPT_NAME to applications
3357
} selection_type;
3458

59+
///
60+
/// Get regular expression for HTTP_HOST CGI variable matching, if empty, no restrictions given
61+
///
3562
booster::regex host() const;
63+
///
64+
/// Get regular expression for SCRIPT_NAME CGI variable matching, if empty, no restrictions given
65+
///
3666
booster::regex script_name() const;
67+
///
68+
/// Get regular expression for PATH_INFO CGI variable matching, if empty, no restrictions given
69+
///
3770
booster::regex path_info() const;
71+
///
72+
/// Get regular expression subgroup that is passes to application for URL dispatching
73+
///
3874
int group() const;
75+
76+
///
77+
/// Get SCRIPT_NAME/PATH_INFO selection
78+
///
3979
selection_type selection() const;
4080

81+
///
82+
/// Set regular expression for HTTP_HOST CGI variable matching, if empty, no restrictions given
83+
///
4184
void host(booster::regex const &);
85+
///
86+
/// Set regular expression for SCRIPT_NAME CGI variable matching, if empty, no restrictions given
87+
///
4288
void script_name(booster::regex const &);
89+
///
90+
/// Set regular expression for PATH_INFO CGI variable matching, if empty, no restrictions given
91+
///
4392
void path_info(booster::regex const &);
93+
///
94+
/// Set regular expression subgroup that is passes to application for URL dispatching
95+
///
4496
void group(int);
97+
///
98+
/// Get SCRIPT_NAME/PATH_INFO selection
99+
///
45100
void selection(selection_type);
46101

102+
///
103+
/// Match \a h - HTTP_HOST, \a s - SCRIPT_NAME, \a p - PATH_INFO against mount point and return
104+
/// true and selected URL path for application
105+
/// Otherwise return false and empty string
106+
///
47107
std::pair<bool,std::string> match(std::string const &h,std::string const &s,std::string const &p) const;
48108

109+
///
110+
/// Create default mount point, it uses PATH_INFO for url-dispatching and gives no restriction on URL
111+
///
49112
mount_point();
113+
///
114+
/// Destructor
50115
~mount_point();
116+
///
117+
/// Copy constructor
118+
///
51119
mount_point(mount_point const &);
120+
///
121+
/// Assignment variable
122+
///
52123
mount_point const &operator=(mount_point const &);
124+
125+
///
126+
/// Create a mount point that checks PATH_INFO only and passes matched \a group for dispatching
127+
///
128+
mount_point(std::string const &path,int group);
129+
///
130+
/// Create a mount point that checks SCRIPT_NAME, and passes PATH_INFO for dispatching
131+
///
132+
mount_point(std::string const &script);
133+
///
134+
/// Create a mount point that checks SCRIPT_NAME, PATH_INFO only and passes matched
135+
/// PATH_INFO's \a group for dispatching
136+
///
137+
mount_point(std::string const &script,std::string const &path,int group);
138+
139+
///
140+
/// Create a mount point with selection rule \a sel.
141+
///
142+
/// \param sel -- selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
143+
/// \param selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according \a sel
144+
/// \param regular expression subgroup of \a selected_part for URL dispatching
145+
///
146+
mount_point( selection_type sel,
147+
std::string const &selected_part,
148+
int group);
149+
150+
///
151+
/// Create a mount point with selection rule \a sel.
152+
///
153+
/// \param sel -- selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
154+
/// \param non_selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according to
155+
/// opposite of \a sel, if sel is match_path_info then non_selected_part checked against SCRIPT_NAME
156+
/// otherwise it is checked against PATH_INFO
157+
///
158+
mount_point( selection_type sel,
159+
std::string const &non_selected_part);
160+
161+
///
162+
/// Create a mount point with selection rule \a sel.
163+
///
164+
/// \param sel -- selection rule use SCRIPT_INFO or PATH_NAME for URL based dispatching
165+
/// \param non_selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according to
166+
/// opposite of \a sel, if sel is match_path_info then non_selected_part checked against SCRIPT_NAME
167+
/// otherwise it is checked against PATH_INFO
168+
/// \param selected_part is a regular expression for matching against PATH_INFO or SCRIPT_NAME according \a sel
169+
/// \param regular expression subgroup of \a selected_part for URL dispatching
170+
///
171+
mount_point( selection_type sel,
172+
std::string const &non_selected_part,
173+
std::string const &selected_part,
174+
int group);
175+
176+
///
177+
/// Create fully defined mount rule for matching against, \a http_host - HTTP_HOST, \a script - SCRIPT_NAME,
178+
/// \a path - PATH_INFO, and use subgroup \a group of regular expression selected with \a sel definition.
179+
///
180+
/// Note: if regular expression is empty, no checks are performed.
181+
///
182+
183+
mount_point( selection_type sel,
184+
booster::regex const &http_host,
185+
booster::regex const &script,
186+
booster::regex const &path,
187+
int group);
188+
53189
private:
54190
booster::regex host_;
55191
booster::regex script_name_;

0 commit comments

Comments
 (0)