1 #include <HttpdSocket.h>
2 #include <SocketHandler.h>
3 #include <ListenSocket.h>
7 class sSocket
: public HttpdSocket
10 sSocket(ISocketHandler
& h
) : HttpdSocket(h
) {
15 if (GetParent() -> GetPort() == 443 || GetParent() -> GetPort() == 8443)
20 fprintf(stderr
, "SSL not available\n");
35 fprintf(stderr
, "Uri: '%s'\n", GetUri().c_str());
38 for (size_t i
= 0; i
< GetUri().size(); i
++)
39 if (GetUri()[i
] == '.')
41 std::string ext
= GetUri().substr(x
+ 1);
42 if (ext
== "gif" || ext
== "jpg" || ext
== "png")
43 AddResponseHeader("Content-type", "image/" + ext
);
45 AddResponseHeader("Content-type", "text/" + ext
);
47 AddResponseHeader("Connection", "close");
51 void GenerateDocument()
53 std::string fn
= GetUri().substr(1);
54 FILE *fil
= fopen(fn
.c_str(), "rb");
58 int n
= fread(slask
,1,1000,fil
);
62 n
= fread(slask
,1,1000,fil
);
69 SetStatusText("Not Found");
77 InitializeContext("httpd", "comb.pem", "", SSLv23_method());
84 int main(int argc
, char *argv
[])
86 std::string host
= argc
> 1 ? argv
[1] : "www.alhem.net";
88 SocketHandler
h(&log
);
89 ListenSocket
<sSocket
> l(h
);
92 printf("Bind port 1028 failed\n");
96 ListenSocket
<sSocket
> l2(h
);
99 printf("Bind port 8443 failed\n");