Beginnings of url recipe handling
[metaproxy-moved-to-github.git] / src / url_recipe.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2011 Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17 */
18
19 #include <metaproxy/xmlutil.hpp>
20
21 #include <string.h>
22
23 namespace mp = metaproxy_1;
24 // Doxygen doesn't like mp::xml, so we use this instead
25 namespace mp_xml = metaproxy_1::xml;
26
27 void mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe)
28 {
29     if (recipe.length() == 0)
30         return;
31     std::string result;
32
33     size_t p0 = 0, p1 = 0;
34     for (;;)
35     {
36         p1 = recipe.find_first_of("${", p0);
37         if (p1 == std::string::npos)
38         {
39             result += recipe.substr(p0);
40             break;
41         }
42         result += recipe.substr(p0, p1 - p0);
43
44         int step = 0;  // 0=variable, 1=pattern, 2=replacement, 3=mode
45         std::string variable;
46         std::string pattern;
47         std::string replacement;
48         std::string mode;
49         p0 = p1+2;
50         while (p0 < recipe.length() && step < 5)
51         {
52             char c = recipe[p0];
53             if (c == '}')
54                 step = 5;
55             else if (step == 0)
56             {
57                 if (c == '[')
58                     step = 1;
59                 else
60                     variable += c;
61             }
62             else if (step == 1)
63             {
64                 if (c == '/')
65                     step = 2;
66                 else
67                     pattern += c;
68             }
69             else if (step == 2)
70             {
71                 if (c == '/')
72                     step = 3;
73                 else
74                     replacement += c;
75             }
76             else if (step == 3)
77             {
78                 if (c == ']')
79                     step = 4;
80                 else
81                     mode += c;
82             }
83             p0++;
84         }
85         if (variable.length())
86         {
87             ;
88         }
89     }
90 }
91
92
93 /*
94  * Local variables:
95  * c-basic-offset: 4
96  * c-file-style: "Stroustrup"
97  * indent-tabs-mode: nil
98  * End:
99  * vim: shiftwidth=4 tabstop=8 expandtab
100  */
101