summaryrefslogtreecommitdiff
path: root/src/net/server.cc
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/net/server.cc
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/net/server.cc')
-rw-r--r--src/net/server.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/net/server.cc b/src/net/server.cc
new file mode 100644
index 0000000..6996b20
--- /dev/null
+++ b/src/net/server.cc
@@ -0,0 +1,75 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <net/server.h>
21
22const mstring SERVURI="/htc/server.htc";
23
24htcServ::htcServ(const sref& path) : htcd(path),user(htcd.toks)
25{
26 Setup(user,htcd);
27 LoadBuffer(server,path+SERVURI);
28}
29
30///////////////////////////////////////////////////////
31
32static void Log(fp_stream& tlog,htcd_req& R,const sref& status)
33{
34 MLOCK(R.htcd()->mutex);
35 tlog<<"["<<time(0)<<"]["<<R.tcp->node.ip<<"]["
36 <<R.tcp->node.name<<":"<<R.tcp->port<<"]["
37 <<R.group<<":"<<R.user.uid()<<"]["
38 <<First(status)<<"]["<<R.req->method<<"]["
39 <<R.req->uri<<"]["<<R.req->arg<<"]\n";
40 tlog.flush();
41}
42
43///////////////////////////////////////////////////////
44
45int SendStatus(isocket& out,htcd_req& R,int keep,const sref& status,const sref& msg)
46{
47 R.resp.status=status;
48 if(atof(R.req->version.past_first(http_ver))<http_major) R.resp.version=HTTP_V10;
49 if(keep) R.resp.connect=keep_tag;
50 if(R.resp.cont_enc.nempty()||
51 R.resp.trans_enc.nempty()||
52 R.resp.status==HTTP_100||
53 R.resp.status==HTTP_204||
54 R.resp.status==HTTP_304||
55 eqn(R.req->method,HTTP_HEAD)) {
56 R.resp.cont_type.clear();
57 R.resp.cont_length.clear();
58 }
59 else {
60 if(R.resp.cont_type.empty()) R.resp.cont_type=http_mime_default;
61 R.resp.cont_length=itoa(msg.size());
62 }
63 Log(R.htcd()->logger,R,status);
64 R.resp.putHead(out);
65 putend(out);
66 out<<msg;
67#if 0
68 static fp_stream merr(stderr);
69 merr<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n";
70 R.resp.putHead(merr);
71 putend(merr);
72 merr<<"=================================\n";
73#endif
74 return out.hup?0:keep;
75}