1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef FILTER_HTTP_REWRITE_HPP
20 #define FILTER_HTTP_REWRITE_HPP
22 #include <metaproxy/filter.hpp>
25 #include <metaproxy/util.hpp>
27 namespace mp = metaproxy_1;
29 namespace metaproxy_1 {
31 class HttpRewrite : public Base {
33 typedef std::pair<std::string, std::string> string_pair;
34 typedef std::vector<string_pair> spair_vec;
35 typedef spair_vec::iterator spv_iter;
38 void process(metaproxy_1::Package & package) const;
39 void configure(const xmlNode * ptr, bool test_only,
41 void configure(const spair_vec req_uri_pats,
42 const spair_vec res_uri_pats);
44 spair_vec req_uri_pats;
45 spair_vec res_uri_pats;
46 std::vector<std::map<int, std::string> > req_groups_bynum;
47 std::vector<std::map<int, std::string> > res_groups_bynum;
48 void rewrite_reqline (mp::odr & o, Z_HTTP_Request *hreq,
49 std::map<std::string, std::string> & vars) const;
50 void rewrite_headers (mp::odr & o, Z_HTTP_Header *headers,
51 std::map<std::string, std::string> & vars,
52 const spair_vec & uri_pats,
53 const std::vector<std::map<int, std::string> > & groups_bynum_vec) const;
54 void rewrite_body (mp::odr & o, char **content_buf, int *content_len,
55 std::map<std::string, std::string> & vars,
56 const spair_vec & uri_pats,
57 const std::vector<std::map<int, std::string> >
58 & groups_bynum) const;
59 const std::string test_patterns(
60 std::map<std::string, std::string> & vars,
61 const std::string & txt,
62 const spair_vec & uri_pats,
63 const std::vector<std::map<int, std::string> >
64 & groups_bynum) const;
65 const std::string search_replace(
66 std::map<std::string, std::string> & vars,
67 const std::string & txt,
68 const std::string & uri_re,
69 const std::string & uri_pat,
70 const std::map<int, std::string> & groups_bynum) const;
71 static void parse_groups(
72 const spair_vec & uri_pats,
73 std::vector<std::map<int, std::string> > & groups_bynum_vec);
74 static std::string sub_vars (const std::string & in,
75 const std::map<std::string, std::string> & vars);
81 extern struct metaproxy_1_filter_struct metaproxy_1_filter_http_rewrite;
88 * c-file-style: "Stroustrup"
89 * indent-tabs-mode: nil
91 * vim: shiftwidth=4 tabstop=8 expandtab