1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
21 structure Main
:> MAIN
= struct
25 structure SM
= StringMap
27 fun init () = Acl
.read Config
.aclFile
31 val prog
= Parse
.parse fname
33 if !ErrorMsg
.anyErrors
then
36 Tycheck
.checkFile
G (Defaults
.tInit ()) prog
41 val dir
= Posix
.FileSys
.opendir Config
.libRoot
44 case Posix
.FileSys
.readdir dir
of
45 NONE
=> (Posix
.FileSys
.closedir dir
;
48 if String.isSuffix
".dtl" fname
then
49 loop (OS
.Path
.joinDirFile
{dir
= Config
.libRoot
,
56 val files
= Order
.order files
58 if !ErrorMsg
.anyErrors
then
61 foldl (fn (fname
, G
) => check
' G fname
) Env
.empty files
66 val _
= ErrorMsg
.reset ()
67 val _
= Env
.preTycheck ()
71 if !ErrorMsg
.anyErrors
then
75 val _
= ErrorMsg
.reset ()
76 val prog
= Parse
.parse fname
78 if !ErrorMsg
.anyErrors
then
82 val G
' = Tycheck
.checkFile
b (Defaults
.tInit ()) prog
91 val (G
, body
) = check fname
93 if !ErrorMsg
.anyErrors
then
99 val body
' = Reduce
.reduceExp G body
101 (*printd (PD
.hovBox (PD
.PPS
.Rel
0,
102 [PD
.string "Result:",
113 if !ErrorMsg
.anyErrors
then
116 Eval
.exec (Defaults
.eInit ()) body
'
120 Config
.dispatcher ^
":" ^
Int.toString Config
.dispatcherPort
124 val uid
= Posix
.ProcEnv
.getuid ()
125 val user
= Posix
.SysDB
.Passwd
.name (Posix
.SysDB
.getpwuid uid
)
127 val () = Acl
.read Config
.aclFile
128 val () = Domain
.setUser user
131 val context
= OpenSSL
.context (Config
.certDir ^
"/" ^ user ^
".pem",
132 Config
.keyDir ^
"/" ^ user ^
".pem",
135 val bio
= OpenSSL
.connect (context
, dispatcher
)
137 val inf
= TextIO.openIn fname
140 case TextIO.inputLine inf
of
142 | SOME line
=> (OpenSSL
.writeAll (bio
, line
);
149 handle ErrorMsg
.Error
=> ()
153 val () = Acl
.read Config
.aclFile
155 val context
= OpenSSL
.context (Config
.serverCert
,
159 val sock
= OpenSSL
.listen (context
, Config
.dispatcherPort
)
162 case OpenSSL
.accept sock
of
166 val user
= OpenSSL
.peerCN bio
167 val () = print ("\nConnection from " ^ user ^
"\n")
168 val () = Domain
.setUser user
170 val outname
= OS
.FileSys
.tmpName ()
171 val outf
= TextIO.openOut outname
174 case OpenSSL
.readOne bio
of
176 | SOME line
=> (TextIO.output (outf
, line
);
180 TextIO.closeOut outf
;
182 handle ErrorMsg
.Error
=> ();
183 OS
.FileSys
.remove outname
;
185 handle OpenSSL
.OpenSSL _
=> ();
190 OpenSSL
.shutdown sock