diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
| commit | 5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch) | |
| tree | 1a81af141708b826e9c61e8a04019994fcca8298 /src/sh/main.cc | |
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/sh/main.cc')
| -rw-r--r-- | src/sh/main.cc | 129 |
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 | |||
| 25 | const mstring PREFSMAP=htchome()+sref("/htc/prefs.hdb"); | ||
| 26 | const mstring SYSLOG=htchome()+sref("/log/htc.log"); | ||
| 27 | |||
| 28 | static fp_stream mout(stdout),merr(stderr); | ||
| 29 | |||
| 30 | /////////////////////////////////////////////////// | ||
| 31 | |||
| 32 | mstring Cwd() { | ||
| 33 | static char buf[1024]; | ||
| 34 | mstring cwd=getcwd(buf,1024); | ||
| 35 | cwd+='/'; | ||
| 36 | return cwd; | ||
| 37 | } | ||
| 38 | |||
| 39 | /////////////////////////////////////////////////// | ||
| 40 | |||
| 41 | static 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 | |||
| 47 | static 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 | |||
| 53 | htc_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 | |||
| 61 | htc_req::htc_req(HTC& g,tokmap& p) : req_env(g,p) | ||
| 62 | { | ||
| 63 | user.reset(); | ||
| 64 | } | ||
| 65 | |||
| 66 | /////////////////////////////////////////////////// | ||
| 67 | |||
| 68 | void envAddFile(tokmap& map); | ||
| 69 | void envAddConvert(tokmap& map); | ||
| 70 | void envAddDates(tokmap& map); | ||
| 71 | void envAddUser(tokmap& map) throw(merror_t); | ||
| 72 | void envAddTree(tokmap& map); | ||
| 73 | void envAddSys(tokmap& map); | ||
| 74 | void envAddNet(tokmap& map); | ||
| 75 | |||
| 76 | /////////////////////////////////////////////////// | ||
| 77 | |||
| 78 | HTC::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 | |||
| 95 | HTC::~HTC() | ||
| 96 | { | ||
| 97 | fclose(syslog.fp); | ||
| 98 | } | ||
| 99 | |||
| 100 | /////////////////////////////////////////////////// | ||
| 101 | |||
| 102 | void 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 | |||
| 110 | void HTC::setDomain(const sref& s) | ||
| 111 | { | ||
| 112 | domain=s; | ||
| 113 | } | ||
| 114 | |||
| 115 | /////////////////////////////////////////////////// | ||
| 116 | |||
| 117 | void HTC::setPort(int p) | ||
| 118 | { | ||
| 119 | port=p; | ||
| 120 | } | ||
| 121 | |||
| 122 | /////////////////////////////////////////////////// | ||
| 123 | |||
| 124 | void HTC::setMailer(const sref& s) | ||
| 125 | { | ||
| 126 | mailer=s; | ||
| 127 | } | ||
| 128 | |||
| 129 | /////////////////////////////////////////////////// | ||
