OSDN Git Service

trunk整理
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / module / protocol / http_protocol_module_base.h
1 /*
2  *    @file    http_protocol_module_base.h
3  *    @brief    shared object http protocol module abstract class
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24 #ifndef    HTTP_PROTOCOL_MODULE_BASE_H
25 #define    HTTP_PROTOCOL_MODULE_BASE_H
26
27 #include "protocol_module_base.h"
28
29 namespace l7vs
30 {
31
32 class http_protocol_module_base : public protocol_module_base
33 {
34 protected:
35         //! @enum    CHECK_RESULT_TAG
36         //! @brief    check tag is return to http protocol module.
37         enum    CHECK_RESULT_TAG {
38                 CHECK_OK = 0,            //!< check ok
39                 CHECK_NG,                //!< check NG
40                 CHECK_IMPOSSIBLE        //!< check impossible
41         };
42
43         //! check http method function
44         //! @param const char*            buffer
45         //! @param const size_t            buffer_len
46         //! @return CHECK_RESULT_TAG    http method is valid
47         CHECK_RESULT_TAG    check_http_method(const char *, const size_t);
48
49         //! check http version function
50         //! @param const char*            buffer
51         //! @param const size_t            buffer_len
52         //! @return    CHECK_RESULT_TAG     http version 1.0 or 1.1
53         CHECK_RESULT_TAG    check_http_version(const char *, const size_t);
54
55         //! check http status code function
56         //! @param const char*            buffer
57         //! @param const size_t            buffer_len
58         //! @return    CHECK_RESULT_TAG    status code is normal or error
59         CHECK_RESULT_TAG    check_status_code(const char *, const size_t);
60
61         //! check http method and version function
62         //! @param const char*            buffer
63         //! @param const size_t            buffer_len
64         //! @return CHECK_RESULT_TAG    http method and version is valid
65         CHECK_RESULT_TAG    check_http_method_and_version(const char *, const size_t);
66
67         //! check http version and status code function
68         //! @param const char*            buffer
69         //! @param const size_t            buffer_len
70         //! @return CHECK_RESULT_TAG    http version and status code is valid
71         CHECK_RESULT_TAG    check_http_version_and_status_code(const char *, const size_t);
72
73         //! search uri function
74         //! @param const char*            buffer
75         //! @param const size_t            buffer_len
76         //! @param size_t&                uri offset
77         //! @param size_t&                uri length
78         //! @return bool                find is true. not find is false
79         bool    find_uri(const char *, const size_t, size_t &, size_t &);
80
81         //! search status function
82         //! @param const char*            buffer
83         //! @param const size_t            buffer_len
84         //! @param size_t&                status offset
85         //! @param size_t&                status length
86         //! @return bool                find is true. not find is false
87         bool    find_status_code(const char *, const size_t, size_t &, size_t &);
88
89         //! search http header function
90         //! @param const char*            buffer
91         //! @param const size_t            buffer_len
92         //! @param const string&        header name
93         //! @param size_t&                header offset
94         //! @param size_t&                header length
95         //! @return bool                find is true. not find is false
96         bool    find_http_header(const char *, const size_t, const std::string &, size_t &, size_t &);
97
98         //! search http header Cookie function
99         //! @param const char*            buffer
100         //! @param const size_t            buffer_len
101         //! @param size_t&                header offset
102         //! @param size_t&                header length
103         //! @return bool                find is true. not find is false
104         bool    find_http_header_cookie(const char *, const size_t, size_t &, size_t &);
105
106         //! search http header Content_Length function
107         //! @param const char*            buffer
108         //! @param const size_t            buffer_len
109         //! @param size_t&                header offset
110         //! @param size_t&                header length
111         //! @return bool                find is true. not find is false
112         bool    find_http_header_content_length(const char *, const size_t, size_t &, size_t &);
113
114         //! search http header X_Forwarded_For function
115         //! @param const char*            buffer
116         //! @param const size_t            buffer_len
117         //! @param size_t&                header offset
118         //! @param size_t&                header length
119         //! @return bool                find is true. not find is false
120         bool    find_http_header_x_forwarded_for(const char *, const size_t, size_t &, size_t &);
121
122         //! search http header all function
123         //! @param const char*            buffer
124         //! @param const size_t            buffer_len
125         //! @param size_t&                header offset
126         //! @param size_t&                header length
127         //! @return bool                find is true. not find is false
128         bool    find_http_header_all(const char *, const size_t, size_t &, size_t &);
129
130         //! check http get method
131         //! @param  const char*            buffer
132         //! @return bool                   get method is true. other is false
133         bool    is_get_request(const char *buffer);
134
135         //! check http post method
136         //! @param  const char*            buffer
137         //! @return bool                   post method is true. other is false
138         bool    is_post_request(const char *buffer);
139
140         //! increment http statistics
141         //! @param  const char*            buffer
142         void    increment_stats(const char *buffer);
143
144         //! http statistic information
145         http_stats http_stats_info;
146
147 public:
148
149         //! constructor
150         http_protocol_module_base(std::string in_modulename) : protocol_module_base(in_modulename) {};
151
152         //! destructor
153         virtual    ~http_protocol_module_base() {};
154
155         //! get base statistic object.
156         //! @return                        base statistic object.
157         stats_base& get_stats()
158         {
159                 return http_stats_info;
160         }
161 };
162
163 } // namespace l7vsd
164
165 #endif    //HTTP_PROTOCOL_MODULE_BASE_H