summaryrefslogtreecommitdiff
path: root/src/sh/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/sh/main.cc')
-rw-r--r--src/sh/main.cc129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/sh/main.cc b/src/sh/main.cc
new file mode 100644
index 0000000..4926b77
--- /dev/null
+++ b/src/sh/main.cc
@@ -0,0 +1,129 @@
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 <sh/htc.h>
21#include <pwd.h>
22#include <sys/stat.h>
23#include <sys/utsname.h>
24
25const mstring PREFSMAP=htchome()+sref("/htc/prefs.hdb");
26const mstring SYSLOG=htchome()+sref("/log/htc.log");
27
28static fp_stream mout(stdout),merr(stderr);
29
30///////////////////////////////////////////////////
31
32mstring Cwd() {
33 static char buf[1024];
34 mstring cwd=getcwd(buf,1024);
35 cwd+='/';
36 return cwd;
37}
38
39///////////////////////////////////////////////////
40
41static void OpenUSERS(dbmap& db)
42{
43 db.Open(USERMAP,1);
44 if(db.Tables()==0) for(int i=0;i<user_tabs;i++) db.InsertTable(i,user_tab[i]);
45}
46
47static void OpenPREFS(dbmap& db)
48{
49 db.Open(PREFSMAP,1);
50 if(db.Tables()==0) for(int i=0;i<prefs_tabs;i++) db.InsertTable(i,prefs_tab[i]);
51}
52
53htc_user::htc_user(tokmap& p) : toks(p)
54{
55 OpenUSERS(DBRef(toks,USERS_tag,ms_empty,tok_t::SYSONLY)->db);
56 OpenPREFS(DBRef(toks,PREFS_tag,ms_empty,tok_t::SYSONLY)->db);
57}
58
59///////////////////////////////////////////////////
60
61htc_req::htc_req(HTC& g,tokmap& p) : req_env(g,p)
62{
63 user.reset();
64}
65
66///////////////////////////////////////////////////
67
68void envAddFile(tokmap& map);
69void envAddConvert(tokmap& map);
70void envAddDates(tokmap& map);
71void envAddUser(tokmap& map) throw(merror_t);
72void envAddTree(tokmap& map);
73void envAddSys(tokmap& map);
74void envAddNet(tokmap& map);
75
76///////////////////////////////////////////////////
77
78HTC::HTC(const sref& root):
79 syslog(fopen(SYSLOG.c_str(),"a+"))
80{
81 docroot=root; if(docroot.back()=='/') docroot=docroot.popb();
82 username=getpwuid(getuid())->pw_name;
83
84 envAddFile(toks);
85 envAddConvert(toks);
86 envAddDates(toks);
87 envAddUser(toks);
88 envAddTree(toks);
89 envAddSys(toks);
90 envAddNet(toks);
91}
92
93///////////////////////////////////////////////////
94
95HTC::~HTC()
96{
97 fclose(syslog.fp);
98}
99
100///////////////////////////////////////////////////
101
102void HTC::setHost(const sref& s)
103{
104 host=s;
105 if(!Lookup(node,host)) THROW("sys: host "<<host<<" not listed in nameserver");
106}
107
108///////////////////////////////////////////////////
109
110void HTC::setDomain(const sref& s)
111{
112 domain=s;
113}
114
115///////////////////////////////////////////////////
116
117void HTC::setPort(int p)
118{
119 port=p;
120}
121
122///////////////////////////////////////////////////
123
124void HTC::setMailer(const sref& s)
125{
126 mailer=s;
127}
128
129///////////////////////////////////////////////////