ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Smersh.cpp
(Generate patch)

Comparing Smersh/Smersh.cpp (file contents):
Revision 172 by Douglas Thrift, 2004-06-20T22:47:13-07:00 vs.
Revision 253 by Douglas Thrift, 2004-09-13T23:31:24-07:00

# Line 10 | Line 10
10   #include "Daemon.hpp"
11   #include "Redirector.hpp"
12  
13 + #include <menes-api/exename.hpp>
14 + #include <menes-app/application.hpp>
15 +
16   string program;
17   bool debug(false);
18  
19   int main(int argc, char* argv[])
20   {
21 <        program = argv[0];
21 >        program = api::GetExecutableName();
22  
23 <        int port(8080);
24 <        bool fork(false), daemon(false), redirector(false);
25 <        string redirect;
23 >        int port(54321);
24 >        bool daemon(false), redirector(false);
25 >        string redirect, log("smersh.log");
26  
27          for (int index(1); index < argc; ++index)
28          {
# Line 40 | Line 43 | int main(int argc, char* argv[])
43                  {
44                          port = lexical_cast<int>(matcher[1]);
45                  }
46 <                else if (arg == "-fork")
46 >                else if (arg == matcher("^-log=(.+)$"))
47                  {
48 <                        if (!fork) fork = true;
48 >                        log = matcher[1];
49                  }
50                  else if (arg == "-D")
51                  {
# Line 50 | Line 53 | int main(int argc, char* argv[])
53                  }
54                  else
55                  {
56 <                        cout << "Usage: " << program << " [-daemon|-redirector=redirect] ["
57 <                                << "-port=port] [-fork] [-D]\n";
56 >                        cout << "Usage: " << program << " [-daemon|-redirector=redirect] "
57 >                                "[-port=port] [-log=log] [-D]\n";
58  
59                          return 1;
60                  }
# Line 59 | Line 62 | int main(int argc, char* argv[])
62  
63          if (daemon)
64          {
65 <                Daemon daemon(port, fork);
65 >                Daemon daemon(port, log);
66          }
67          else if (redirector)
68          {
69 <                Redirector redirector(port, fork, redirect);
69 >                Redirector redirector(port, log, redirect);
70          }
71          else
72          {
# Line 73 | Line 76 | int main(int argc, char* argv[])
76          return 0;
77   }
78  
79 < Smersh::Smersh(istream& sin, ostream& sout)
79 > Smersh::Smersh(istream& sin, ostream& sout, const Environment& env)
80   {
81 <        parse(sin);
82 <        smersh(sout);
81 >        parse(sin, env);
82 >        smersh(sout, env);
83   }
84  
85 < void Smersh::parse(istream& sin)
85 > Environment Smersh::env;
86 >
87 > void Smersh::parse(istream& sin, const Environment& env)
88   {
89 <        stringstream query(sgetenv("QUERY_STRING"));
89 >        stringstream query(env.get("QUERY_STRING"));
90  
91 <        if (sgetenv("REQUEST_METHOD") == "POST")
91 >        if (env.get("REQUEST_METHOD") == "POST")
92          {
93 <                streamsize length(lexical_cast<streamsize>(sgetenv("CONTENT_LENGTH")));
94 <                char* content = new char[length];
93 >                streamsize length(lexical_cast<streamsize>(env.get("CONTENT_LENGTH")));
94 >                char* content(new char[length]);
95  
96                  sin.read(content, length);
97                  query.write(content, length);
# Line 107 | Line 112 | void Smersh::parse(istream& sin)
112          while (query.good());
113   }
114  
115 < void Smersh::smersh(ostream& sout)
115 > void Smersh::smersh(ostream& sout, const Environment& env)
116   {
117 <        sout << "Content-Type: text/html\n\n";
117 >        if (&env == &Smersh::env) sout << "Content-Type: text/html; charset=UTF-8\r"
118 >                << "\n\r\n";
119  
120          vector<Person> people(1);
121  
# Line 172 | Line 178 | void Smersh::smersh(ostream& sout)
178  
179          output(sout, people);
180  
181 <        sout << "!</font></strong></p></body></html>\n";
181 >        sout << "!</font></strong></p></body></html>\r\n";
182   }
183  
184   void Smersh::output(ostream& sout, const vector<Person>& people)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines