mapping.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 
30 #ifndef TNT_MAPPING_H
31 #define TNT_MAPPING_H
32 
33 #include <tnt/maptarget.h>
34 #include <cxxtools/regex.h>
35 
36 namespace tnt
37 {
38  class HttpRequest;
39 
40  class Mapping
41  {
42  std::string _vhost;
43  std::string _url;
44  std::string _method;
45  int _ssl;
46 
47  cxxtools::Regex _regexVhost;
48  cxxtools::Regex _regexUrl;
49  cxxtools::Regex _regexMethod;
50 
51  Maptarget _target;
52 
53  public:
54  typedef Maptarget::args_type args_type;
55 
56  Mapping() { }
57 
58  Mapping(const std::string& vhost, const std::string& url, const std::string& method, int ssl, const Maptarget& target);
59 
60  const std::string& getVHost() const { return _vhost; }
61  const std::string& getUrl() const { return _url; }
62  const std::string& getMethod() const { return _method; }
63  int getSsl() const { return _ssl; }
64 
65  const Maptarget& getTarget() const { return _target; }
66 
67  Mapping& setPathInfo(const std::string& p)
68  {
69  _target.setPathInfo(p);
70  return *this;
71  }
72 
73  Mapping& setHttpReturn(unsigned httpreturn)
74  {
75  _target.setHttpReturn(httpreturn);
76  return *this;
77  }
78 
80  {
81  _target.setArgs(a);
82  return *this;
83  }
84 
85  Mapping& setArg(const std::string& name, const std::string& value)
86  {
87  _target.setArg(name, value);
88  return *this;
89  }
90 
93  Mapping& pushArg(const std::string& value);
94 
95  Mapping& setVHost(const std::string& vhost)
96  {
97  _vhost = vhost;
98  _regexVhost = cxxtools::Regex(vhost);
99  return *this;
100  }
101 
102  Mapping& setUrl(const std::string& url)
103  {
104  _url = url;
105  _regexUrl = cxxtools::Regex(url);
106  return *this;
107  }
108 
109  Mapping& setMethod(const std::string& method)
110  {
111  _method = method;
112  _regexMethod = cxxtools::Regex(method);
113  return *this;
114  }
115 
116  Mapping& setSsl(bool sw)
117  {
118  _ssl = (sw ? SSL_YES : SSL_NO);
119  return *this;
120  }
121 
123  {
124  _ssl = SSL_ALL;
125  return *this;
126  }
127 
128  bool match(const HttpRequest& request, cxxtools::RegexSMatch& smatch) const;
129  };
130 
131 }
132 
133 #endif // TNT_MAPPING_H