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) const;
52 void rewrite_body (mp::odr & o, char **content_buf, int *content_len,
53 std::map<std::string, std::string> & vars) const;
54 const std::string test_patterns(
55 std::map<std::string, std::string> & vars,
56 const std::string & txt,
57 const spair_vec & uri_pats,
58 const std::vector<std::map<int, std::string> > & groups_bynum_vec) const;
59 const std::string search_replace(
60 std::map<std::string, std::string> & vars,
61 const std::string & txt,
62 const std::string & uri_re,
63 const std::string & uri_pat,
64 const std::map<int, std::string> & groups_bynum) const;
65 static void parse_groups(
66 const spair_vec & uri_pats,
67 std::vector<std::map<int, std::string> > & groups_bynum_vec);
68 static std::string sub_vars (const std::string & in,
69 const std::map<std::string, std::string> & vars);
75 extern struct metaproxy_1_filter_struct metaproxy_1_filter_http_rewrite;
82 * c-file-style: "Stroustrup"
83 * indent-tabs-mode: nil
85 * vim: shiftwidth=4 tabstop=8 expandtab