6 |
|
|
7 |
|
#include "Environment.hpp" |
8 |
|
#include "Matcher.hpp" |
9 |
+ |
#include "Jargon.hpp" |
10 |
|
|
11 |
|
extern "C" |
12 |
|
{ |
17 |
|
|
18 |
|
int main(int argc, char* argv[]) |
19 |
|
{ |
20 |
+ |
FeepingCreaturism::program = argv[0]; |
21 |
+ |
|
22 |
|
FeepingCreaturism creaturism; |
23 |
|
|
24 |
|
return 0; |
31 |
|
std::string path(env.get("PATH_INFO")); |
32 |
|
Matcher matcher; |
33 |
|
|
34 |
< |
if (path.empty()) daily(); else if (path == "/random") |
34 |
> |
if (path == "/daily/") daily(); else if (path == "/random/") |
35 |
|
{ |
36 |
|
random(); |
37 |
|
} |
39 |
|
{ |
40 |
|
select(matcher[1], true); |
41 |
|
} |
42 |
< |
else daily(); |
42 |
> |
else |
43 |
> |
{ |
44 |
> |
cout << "Status: 301\r\n"; |
45 |
> |
} |
46 |
|
} |
47 |
|
|
48 |
+ |
std::string FeepingCreaturism::program; |
49 |
+ |
|
50 |
|
void FeepingCreaturism::initialize() |
51 |
|
{ |
52 |
< |
ext::Handle<xml::Document> document(xml::Parse("FeepingCreaturism.xml")); |
53 |
< |
ext::Handle<xml::Node> node(*document/"FeepingCreaturism"); |
52 |
> |
ext::Handle<xml::Document> document(xml::Parse("jargon.xml")); |
53 |
> |
ext::Handle<xml::Node> node(*document/"feepingcreaturism"); |
54 |
|
|
55 |
< |
this->path = *node/"Jargon"; |
56 |
< |
this->matcher = *node/"Matcher"; |
55 |
> |
this->path = *node/"jargon"; |
56 |
> |
this->matcher = *node/"matcher"; |
57 |
|
|
58 |
|
char* path[] = { new char[this->path.size()] }; |
59 |
|
|
62 |
|
::FTS* traversal(::fts_open(path, FTS_LOGICAL, NULL)); |
63 |
|
Matcher matcher('^' + this->path + "/(" + this->matcher + ")$"); |
64 |
|
|
65 |
+ |
if (traversal == NULL) |
66 |
+ |
{ |
67 |
+ |
cerr << program << ": Horrible Failure!\n"; |
68 |
+ |
|
69 |
+ |
std::exit(1); |
70 |
+ |
} |
71 |
+ |
|
72 |
|
for (::FTSENT* entity(::fts_read(traversal)); entity != NULL; |
73 |
|
entity = ::fts_read(traversal)) |
74 |
|
{ |
113 |
|
{ |
114 |
|
if (!validate || jargon.find(selection) != jargon.end()) |
115 |
|
{ |
116 |
< |
cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << selection |
117 |
< |
<< "\r\n"; |
116 |
> |
cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n"; |
117 |
> |
|
118 |
> |
Jargon jargon(path + '/' + selection); |
119 |
> |
|
120 |
> |
cout << jargon; |
121 |
> |
} |
122 |
> |
else |
123 |
> |
{ |
124 |
> |
cout << "Status: 404\r\nContent-Type: text/html; charset=ISO-8859-1\r\n" |
125 |
> |
<< "\r\n<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" |
126 |
> |
<< "<html><head>\n<title>404 Not Found</title>\n</head><body>\n" |
127 |
> |
<< "<h1>Not Found</h1>\n<p>The requested URL " |
128 |
> |
<< env.get("PATH_INFO") << " was not found on this server.</p>\n" |
129 |
> |
<< "<hr />\n" << env.get("SERVER_SIGNATURE") << "</body></html>\n"; |
130 |
|
} |
104 |
– |
else cout << "Status: 404\r\n\r\n"; |
131 |
|
} |