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/serv/main.cc | |
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/serv/main.cc')
| -rw-r--r-- | src/serv/main.cc | 122 |
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 | |||
| 23 | const mstring RCURI="/sys/htcd.rc"; | ||
| 24 | const mstring TREEURI="/sys/sitemap.hdb"; | ||
| 25 | const mstring TEMPURI="/sys/temp.hdb"; | ||
| 26 | |||
| 27 | const mstring LOGURI="/sys/htcd.log"; | ||
| 28 | const mstring ERRURI="/sys/htcd.err"; | ||
| 29 | |||
| 30 | /////////////////////////////////////////////////// | ||
| 31 | |||
| 32 | static 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 | |||
| 39 | static 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 | |||
| 46 | htcd_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 | |||
| 54 | void SetCookies(tokmap& map,const httpReq& req); | ||
| 55 | void envAddForm(tokmap& map,const httpReq& req); | ||
| 56 | |||
| 57 | int 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 | |||
| 65 | htcd_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 | |||
| 74 | void htcd_req::AddBody(const sref& body) | ||
| 75 | { | ||
| 76 | req->body=body; | ||
| 77 | envAddForm(toks,*req); | ||
| 78 | } | ||
| 79 | |||
| 80 | /////////////////////////////////////////////////// | ||
| 81 | |||
| 82 | void envAddDirect(tokmap& map); | ||
| 83 | void envAddReq(tokmap& map); | ||
| 84 | void envAddConst(tokmap& map); | ||
| 85 | void envAddAuth(tokmap& map); | ||
| 86 | void envAddTemp(tokmap& map); | ||
| 87 | |||
| 88 | HTCd::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 | |||
| 104 | HTCd::~HTCd() | ||
| 105 | { | ||
| 106 | fclose(errlog.fp); | ||
| 107 | fclose(logger.fp); | ||
| 108 | } | ||
| 109 | |||
| 110 | void 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 | } | ||
