comparison src/luan/host/WebHandler.java @ 1333:25746915a241

merge Luan and LuanState
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Feb 2019 22:33:40 -0700
parents 11b7e11f9ed5
children e0cf0d108a77
comparison
equal deleted inserted replaced
1332:11b7e11f9ed5 1333:25746915a241
6 import luan.webserver.Handler; 6 import luan.webserver.Handler;
7 import luan.webserver.Request; 7 import luan.webserver.Request;
8 import luan.webserver.Response; 8 import luan.webserver.Response;
9 import luan.webserver.handlers.DomainHandler; 9 import luan.webserver.handlers.DomainHandler;
10 import luan.Luan; 10 import luan.Luan;
11 import luan.LuanState;
12 import luan.LuanException; 11 import luan.LuanException;
13 import luan.LuanTable; 12 import luan.LuanTable;
14 import luan.LuanFunction; 13 import luan.LuanFunction;
15 import luan.LuanClosure; 14 import luan.LuanClosure;
16 import luan.modules.BasicLuan; 15 import luan.modules.BasicLuan;
37 String dirStr = dir.toString(); 36 String dirStr = dir.toString();
38 37
39 String logDir = dirStr + "/site/private/local/logs/web"; 38 String logDir = dirStr + "/site/private/local/logs/web";
40 new File(logDir).mkdirs(); 39 new File(logDir).mkdirs();
41 40
42 LuanState luan = new LuanState(); 41 Luan luan = new Luan();
43 try { 42 try {
44 Log4j.newLoggerRepository(luan); 43 Log4j.newLoggerRepository(luan);
45 } catch(LuanException e) { 44 } catch(LuanException e) {
46 throw new RuntimeException(e); 45 throw new RuntimeException(e);
47 } 46 }
98 throw new RuntimeException("couldn't rename "+from+" to "+dir); 97 throw new RuntimeException("couldn't rename "+from+" to "+dir);
99 logger.info("recovered "+name+" from "+from); 98 logger.info("recovered "+name+" from "+from);
100 return true; 99 return true;
101 } 100 }
102 */ 101 */
103 static void initLuan(LuanState luan,String dir,String domain,boolean logging) { 102 static void initLuan(Luan luan,String dir,String domain,boolean logging) {
104 security(luan,dir); 103 security(luan,dir);
105 try { 104 try {
106 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan"); 105 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan");
107 fn.call(luan,new Object[]{dir,domain,logging}); 106 fn.call(luan,new Object[]{dir,domain,logging});
108 } catch(LuanException e) { 107 } catch(LuanException e) {
120 } catch(LuanRuntimeException e) { 119 } catch(LuanRuntimeException e) {
121 throw e.e; 120 throw e.e;
122 } 121 }
123 } 122 }
124 123
125 private static final void security(LuanState luan,String dir) { 124 private static final void security(Luan luan,String dir) {
126 final String siteUri = "file:" + dir + "/site"; 125 final String siteUri = "file:" + dir + "/site";
127 Luan.Security security = new Luan.Security() { 126 Luan.Security security = new Luan.Security() {
128 public void check(LuanState luan,LuanClosure closure,String op,Object... args) 127 public void check(Luan luan,LuanClosure closure,String op,Object... args)
129 throws LuanException 128 throws LuanException
130 { 129 {
131 if( op.equals("uri") ) { 130 if( op.equals("uri") ) {
132 String name = (String)args[0]; 131 String name = (String)args[0];
133 if( name.startsWith("file:") ) { 132 if( name.startsWith("file:") ) {