00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <syslog.h>
00004 #include <string>
00005 #include <map>
00006 #include <fstream>
00007
00008 using namespace std;
00009
00010 void load(string fn, map<string, string> &c) {
00011 int i;
00012 char *z;
00013 string s;
00014 ifstream ifile(fn.c_str());
00015 while(!ifile.eof()) {
00016 ifile >> s;
00017 z = const_cast<char *>(s.c_str());
00018 for(i = 0; z[i]; i++)
00019 if(z[i] == '=') {
00020 z[i] = '\0';
00021 c[&z[0]] = &z[i + 1];
00022 break;
00023 }
00024 }
00025 ifile.close();
00026
00027
00028
00029
00030
00031 }
00032
00033 void save(string fn, map<string, string> &c) {
00034 string s;
00035 ofstream of(fn.c_str());
00036
00037
00038
00039
00040 for(map<string, string>::iterator it = c.begin(); it != c.end(); it++) {
00041 s = (*it).first;
00042 s += "=";
00043 s += (*it).second;
00044 of << s;
00045 of << endl;
00046 }
00047 of.close();
00048 }
00049
00050 int main() {
00051 const char *uri;
00052 const char *method;
00053 const char *query;
00054
00055
00056
00057 map<string, string> params;
00058 map<string, string> in;
00059 map<string, string> out;
00060
00061 method = getenv("REQUEST_METHOD");
00062 query = getenv("QUERY_STRING");
00063 uri = getenv("REQUEST_URI");
00064
00065
00066
00067
00068
00069
00070
00071
00072 string p_s = query;
00073 char *p = const_cast<char *>(p_s.c_str());
00074
00075 int i, j, k;
00076 k = 0;
00077 bool f = false, to_break = false;
00078 for(i = 0; ; i++) {
00079 if(p[i] == '\'')
00080 f = !f;
00081 if((p[i] == '&' || p[i] == '\0') && !f) {
00082 if(p[i] == '\0')
00083 to_break = true;
00084 else
00085 p[i] = '\0';
00086 for(j = k; p[j]; j++) {
00087 if(p[j] == '=') {
00088 p[j] = '\0';
00089 params[&p[k]] = &p[j + 1];
00090 break;
00091 }
00092 }
00093 k = i + 1;
00094 f = false;
00095 }
00096 if(to_break)
00097 break;
00098 }
00099
00100 load(params["in"], in);
00101 load(params["out"], out);
00103 in["init_1"] = out["init_1"];
00104 in["init_2"] = out["init_2"];
00106 if(params["init_1"] != "''")
00107 in["init_1"] = params["init_1"];
00108 if(params["init_2"] != "''")
00109 in["init_2"] = params["init_2"];
00110
00111 save(params["out"], in);
00112
00113
00114
00115
00116
00117 return 0;
00118 }