diff options
Diffstat (limited to 'src/serv/htcs.cc')
| -rw-r--r-- | src/serv/htcs.cc | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/serv/htcs.cc b/src/serv/htcs.cc new file mode 100644 index 0000000..42ac8e3 --- /dev/null +++ b/src/serv/htcs.cc | |||
| @@ -0,0 +1,92 @@ | |||
| 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 | #include <mt/lock.h> | ||
| 23 | |||
| 24 | static fp_stream mout(stdout),merr(stderr); | ||
| 25 | const mstring left="{",right="}"; | ||
| 26 | |||
| 27 | static int unbalanced(const sref& in) | ||
| 28 | { | ||
| 29 | static const charset tag("{[("); | ||
| 30 | if(in.empty()) return 1; | ||
| 31 | sref s=in.right_first_of(tag); | ||
| 32 | while(s.nempty()) { | ||
| 33 | int p=-1; | ||
| 34 | switch(*s) { | ||
| 35 | case '{': p=s.skip(cset_braces); break; | ||
| 36 | case '[': p=s.skip(cset_indices); break; | ||
| 37 | case '(': p=s.skip(cset_para); break; | ||
| 38 | } | ||
| 39 | if(p<0) return 1; | ||
| 40 | s=s.adv(p).right_first_of(tag); | ||
| 41 | } | ||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | main(int argc,char* argv[]) try | ||
| 46 | { | ||
| 47 | NODELOCK(USERMAP); | ||
| 48 | if(argc<2) THROW("Usage: "<<argv[0]<<" <docroot>"); | ||
| 49 | mstring path=argv[1]; | ||
| 50 | if(path.back()=='/') path=path.popb(); | ||
| 51 | HTCd htcd(path); | ||
| 52 | tokmap user(htcd.toks); | ||
| 53 | Setup(user,htcd); | ||
| 54 | htcd_user thr(user,path); | ||
| 55 | tcpReq tcp; tcp.port=0; | ||
| 56 | httpReq hreq; hreq.method="GET"; | ||
| 57 | htcd_req req(htcd,thr.toks,mout,tcp,hreq); | ||
| 58 | Env env(htcd.ops,req,XSYSTEM); | ||
| 59 | if(argc>2) { | ||
| 60 | for(int i=3;i<argc;i++) env.xpush(left+sref(argv[i])+right); | ||
| 61 | mstring buffer; LoadBuffer(buffer,argv[2]); | ||
| 62 | if(*buffer=='#') buffer.erase(0,buffer.find('\n')+1); | ||
| 63 | mstream m; | ||
| 64 | env.eval(m,buffer,1); | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | mstring buffer,line; | ||
| 68 | while(!feof(stdin)) { | ||
| 69 | merr<<"htcd>"; | ||
| 70 | buffer.clear(); | ||
| 71 | while(!feof(stdin)&&unbalanced(buffer)) { | ||
| 72 | getline(line,stdin); | ||
| 73 | buffer.append(sref(line)); | ||
| 74 | buffer+='\n'; | ||
| 75 | } | ||
| 76 | try { | ||
| 77 | env.parse(mout,buffer); | ||
| 78 | mout<<"\n"; | ||
| 79 | } | ||
| 80 | catch(const merror_t& e) { | ||
| 81 | merr<<e.desc<<"\n"; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | catch(const merror_t& e) { | ||
| 88 | merr<<"ERROR: ["<<e.desc<<"]\n"; | ||
| 89 | return -1; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
