summaryrefslogtreecommitdiff
path: root/src/serv/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/serv/main.cc')
-rw-r--r--src/serv/main.cc122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/serv/main.cc b/src/serv/main.cc
new file mode 100644
index 0000000..f02f10c
--- /dev/null
+++ b/src/serv/main.cc
@@ -0,0 +1,122 @@
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 <serv/htcd.h>
21#include <hdb/buffer.h>
22
23const mstring RCURI="/sys/htcd.rc";
24const mstring TREEURI="/sys/sitemap.hdb";
25const mstring TEMPURI="/sys/temp.hdb";
26
27const mstring LOGURI="/sys/htcd.log";
28const mstring ERRURI="/sys/htcd.err";
29
30///////////////////////////////////////////////////
31
32static void OpenTREE(dbmap& db,const sref& path)
33{
34 mstring TREEMAP=path+TREEURI;
35 db.Open(TREEMAP,1);
36 if(db.Tables()==0) for(int i=0;i<tree_tabs;i++) db.InsertTable(i,tree_tab[i]);
37}
38
39static void OpenTEMP(dbmap& db,const sref& path)
40{
41 mstring TEMPMAP=path+TEMPURI;
42 db.Open(TEMPMAP,1);
43 if(db.Tables()==0) for(int i=0;i<temp_tabs;i++) db.InsertTable(i,temp_tab[i]);
44}
45
46htcd_user::htcd_user(tokmap& p,const mstring& path) : htc_user(p)
47{
48 OpenTREE(DBRef(toks,TREE_tag,ms_empty,tok_t::SYSONLY)->db,path);
49 OpenTEMP(DBRef(toks,TEMP_tag,ms_empty,tok_t::SYSONLY)->db,path);
50}
51
52///////////////////////////////////////////////////
53
54void SetCookies(tokmap& map,const httpReq& req);
55void envAddForm(tokmap& map,const httpReq& req);
56
57int htcd_req::RootAllowed()
58{
59 if(htcd()->bindroot.empty()) return 1;
60 sref first,rest=htcd()->bindroot;
61 while(Split(first,rest)) if(first==tcp->node.name) return 1;
62 return 0;
63}
64
65htcd_req::htcd_req(HTCd& g,tokmap& p,mstream& out,
66 tcpReq& trec,httpReq& hrec) : htc_req(g,p)
67{
68 output=&out;
69 tcp=&trec;
70 req=&hrec;
71 SetCookies(toks,hrec);
72}
73
74void htcd_req::AddBody(const sref& body)
75{
76 req->body=body;
77 envAddForm(toks,*req);
78}
79
80///////////////////////////////////////////////////
81
82void envAddDirect(tokmap& map);
83void envAddReq(tokmap& map);
84void envAddConst(tokmap& map);
85void envAddAuth(tokmap& map);
86void envAddTemp(tokmap& map);
87
88HTCd::HTCd(const mstring& path):
89 logger(fopen((path+LOGURI).c_str(),"a+")),
90 errlog(fopen((path+ERRURI).c_str(),"a+")),
91 HTC(path)
92{
93 envAddDirect(toks);
94 envAddReq(toks);
95 envAddConst(toks);
96 envAddAuth(toks);
97 envAddTemp(toks);
98
99 memset(&mutex,0,sizeof(mutex));
100 errlog<<"["<<time(0)<<"][MAIN][HTCd started]\n";
101 errlog.flush();
102}
103
104HTCd::~HTCd()
105{
106 fclose(errlog.fp);
107 fclose(logger.fp);
108}
109
110void Setup(tokmap& user,HTCd& htcd)
111{
112 tcpReq tcp; tcp.port=0;
113 httpReq hreq; hreq.method="GET";
114 mstream m1;
115 htcd_req req(htcd,htcd.toks,m1,tcp,hreq);
116 Env env(htcd.ops,req,XSYSTEM);
117 mstring buffer;
118 LoadBuffer(buffer,htcd.docroot+RCURI);
119 Env e(env,user,htcd.docroot+RCURI);
120 mstream m2;
121 e.parse(m2,buffer);
122}