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