From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/sh/main.cc | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/sh/main.cc (limited to 'src/sh/main.cc') 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 @@ +/************************************************************************* + * + * 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 +#include +#include +#include + +const mstring PREFSMAP=htchome()+sref("/htc/prefs.hdb"); +const mstring SYSLOG=htchome()+sref("/log/htc.log"); + +static fp_stream mout(stdout),merr(stderr); + +/////////////////////////////////////////////////// + +mstring Cwd() { + static char buf[1024]; + mstring cwd=getcwd(buf,1024); + cwd+='/'; + return cwd; +} + +/////////////////////////////////////////////////// + +static void OpenUSERS(dbmap& db) +{ + db.Open(USERMAP,1); + if(db.Tables()==0) for(int i=0;idb); + OpenPREFS(DBRef(toks,PREFS_tag,ms_empty,tok_t::SYSONLY)->db); +} + +/////////////////////////////////////////////////// + +htc_req::htc_req(HTC& g,tokmap& p) : req_env(g,p) +{ + user.reset(); +} + +/////////////////////////////////////////////////// + +void envAddFile(tokmap& map); +void envAddConvert(tokmap& map); +void envAddDates(tokmap& map); +void envAddUser(tokmap& map) throw(merror_t); +void envAddTree(tokmap& map); +void envAddSys(tokmap& map); +void envAddNet(tokmap& map); + +/////////////////////////////////////////////////// + +HTC::HTC(const sref& root): + syslog(fopen(SYSLOG.c_str(),"a+")) +{ + docroot=root; if(docroot.back()=='/') docroot=docroot.popb(); + username=getpwuid(getuid())->pw_name; + + envAddFile(toks); + envAddConvert(toks); + envAddDates(toks); + envAddUser(toks); + envAddTree(toks); + envAddSys(toks); + envAddNet(toks); +} + +/////////////////////////////////////////////////// + +HTC::~HTC() +{ + fclose(syslog.fp); +} + +/////////////////////////////////////////////////// + +void HTC::setHost(const sref& s) +{ + host=s; + if(!Lookup(node,host)) THROW("sys: host "<