adam@1478
|
1 (* Copyright (c) 2008-2011, Adam Chlipala
|
adamc@764
|
2 * All rights reserved.
|
adamc@764
|
3 *
|
adamc@764
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@764
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@764
|
6 *
|
adamc@764
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@764
|
8 * this list of conditions and the following disclaimer.
|
adamc@764
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@764
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@764
|
11 * and/or other materials provided with the distribution.
|
adamc@764
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@764
|
13 * derived from this software without specific prior written permission.
|
adamc@764
|
14 *
|
adamc@764
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@764
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@764
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@764
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
rmbruijn@1597
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@764
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@764
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@764
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@764
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@764
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@764
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@764
|
26 *)
|
adamc@764
|
27
|
adamc@764
|
28 structure Settings :> SETTINGS = struct
|
adamc@764
|
29
|
ezyang@1739
|
30 val configBin = ref Config.bin
|
ezyang@1739
|
31 val configLib = ref Config.lib
|
ezyang@1739
|
32 val configSrcLib = ref Config.srclib
|
ezyang@1739
|
33 val configInclude = ref Config.includ
|
ezyang@1739
|
34 val configSitelisp = ref Config.sitelisp
|
ezyang@1739
|
35
|
grrwlf@1871
|
36 val configCCompiler = ref Config.ccompiler
|
grrwlf@1871
|
37
|
grrwlf@1871
|
38 fun getCCompiler () = !configCCompiler
|
grrwlf@1871
|
39 fun setCCompiler cc = configCCompiler := cc
|
grrwlf@1871
|
40
|
ezyang@1739
|
41 fun libUr () = OS.Path.joinDirFile {dir = !configSrcLib,
|
ezyang@1739
|
42 file = "ur"}
|
ezyang@1739
|
43 fun libC () = OS.Path.joinDirFile {dir = !configSrcLib,
|
ezyang@1739
|
44 file = "c"}
|
ezyang@1739
|
45 fun libJs () = OS.Path.joinDirFile {dir = !configSrcLib,
|
ezyang@1739
|
46 file = "js"}
|
ezyang@1739
|
47
|
ezyang@1739
|
48 fun libFile s = OS.Path.joinDirFile {dir = libUr (),
|
ezyang@1739
|
49 file = s}
|
ezyang@1739
|
50
|
adam@1637
|
51 val urlPrefixFull = ref "/"
|
adamc@764
|
52 val urlPrefix = ref "/"
|
adam@1370
|
53 val urlPrePrefix = ref ""
|
adamc@764
|
54 val timeout = ref 0
|
adamc@764
|
55 val headers = ref ([] : string list)
|
adamc@766
|
56 val scripts = ref ([] : string list)
|
adamc@764
|
57
|
adam@1637
|
58 fun getUrlPrefixFull () = !urlPrefixFull
|
adamc@764
|
59 fun getUrlPrefix () = !urlPrefix
|
adam@1370
|
60 fun getUrlPrePrefix () = !urlPrePrefix
|
adamc@764
|
61 fun setUrlPrefix p =
|
adam@1370
|
62 let
|
adam@1370
|
63 val prefix = if p = "" then
|
adam@1370
|
64 "/"
|
adam@1370
|
65 else if String.sub (p, size p - 1) <> #"/" then
|
adam@1370
|
66 p ^ "/"
|
adam@1370
|
67 else
|
adam@1370
|
68 p
|
adam@1370
|
69
|
adam@1470
|
70 fun findPrefix n =
|
adam@1470
|
71 let
|
adam@1470
|
72 val (befor, after) = Substring.splitl (fn ch => ch <> #"/") (Substring.extract (prefix, n, NONE))
|
adam@1470
|
73 in
|
adam@1470
|
74 if Substring.isEmpty after then
|
adam@1470
|
75 ("", prefix)
|
adam@1470
|
76 else
|
adam@1470
|
77 (String.substring (prefix, 0, n) ^ Substring.string befor, Substring.string after)
|
rmbruijn@1597
|
78 end
|
adam@1470
|
79
|
adam@1370
|
80 val (prepre, prefix) =
|
adam@1370
|
81 if String.isPrefix "http://" prefix then
|
adam@1470
|
82 findPrefix 7
|
adam@1470
|
83 else if String.isPrefix "https://" prefix then
|
adam@1470
|
84 findPrefix 8
|
adam@1370
|
85 else
|
adam@1370
|
86 ("", prefix)
|
adam@1370
|
87 in
|
adam@1637
|
88 urlPrefixFull := p;
|
adam@1370
|
89 urlPrePrefix := prepre;
|
adam@1370
|
90 urlPrefix := prefix
|
adam@1370
|
91 end
|
adamc@764
|
92
|
adamc@764
|
93 fun getTimeout () = !timeout
|
adamc@764
|
94 fun setTimeout n = timeout := n
|
adamc@764
|
95
|
adamc@764
|
96 fun getHeaders () = !headers
|
adamc@764
|
97 fun setHeaders ls = headers := ls
|
adamc@764
|
98
|
adamc@766
|
99 fun getScripts () = !scripts
|
adamc@766
|
100 fun setScripts ls = scripts := ls
|
adamc@766
|
101
|
adamc@765
|
102 type ffi = string * string
|
adamc@765
|
103
|
adamc@765
|
104 structure K = struct
|
adamc@765
|
105 type ord_key = ffi
|
adamc@765
|
106 fun compare ((m1, x1), (m2, x2)) =
|
adamc@765
|
107 Order.join (String.compare (m1, m2),
|
adamc@765
|
108 fn () => String.compare (x1, x2))
|
adamc@764
|
109 end
|
adamc@765
|
110
|
adamc@765
|
111 structure S = BinarySetFn(K)
|
adamc@765
|
112 structure M = BinaryMapFn(K)
|
adamc@765
|
113
|
adamc@765
|
114 fun basis x = S.addList (S.empty, map (fn x : string => ("Basis", x)) x)
|
adamc@765
|
115
|
adamc@765
|
116 val clientToServerBase = basis ["int",
|
adamc@765
|
117 "float",
|
adamc@765
|
118 "string",
|
adamc@765
|
119 "time",
|
adamc@765
|
120 "file",
|
adamc@765
|
121 "unit",
|
adamc@765
|
122 "option",
|
adamc@765
|
123 "list",
|
adam@1288
|
124 "bool",
|
adam@1288
|
125 "variant"]
|
adamc@765
|
126 val clientToServer = ref clientToServerBase
|
adamc@765
|
127 fun setClientToServer ls = clientToServer := S.addList (clientToServerBase, ls)
|
adamc@765
|
128 fun mayClientToServer x = S.member (!clientToServer, x)
|
adamc@765
|
129
|
adamc@779
|
130 val effectfulBase = basis ["dml",
|
adamc@779
|
131 "nextval",
|
adamc@1073
|
132 "setval",
|
adamc@779
|
133 "set_cookie",
|
adamc@1050
|
134 "clear_cookie",
|
adamc@765
|
135 "new_channel",
|
adamc@1200
|
136 "send",
|
adamc@1200
|
137 "htmlifyInt_w",
|
adamc@1200
|
138 "htmlifyFloat_w",
|
adamc@1200
|
139 "htmlifyString_w",
|
adamc@1200
|
140 "htmlifyBool_w",
|
adamc@1200
|
141 "htmlifyTime_w",
|
adamc@1200
|
142 "attrifyInt_w",
|
adamc@1200
|
143 "attrifyFloat_w",
|
adamc@1200
|
144 "attrifyString_w",
|
adamc@1200
|
145 "attrifyChar_w",
|
adamc@1200
|
146 "urlifyInt_w",
|
adamc@1200
|
147 "urlifyFloat_w",
|
adamc@1200
|
148 "urlifyString_w",
|
adamc@1200
|
149 "urlifyBool_w",
|
adamc@1200
|
150 "urlifyChannel_w"]
|
adamc@765
|
151
|
adamc@765
|
152 val effectful = ref effectfulBase
|
adamc@765
|
153 fun setEffectful ls = effectful := S.addList (effectfulBase, ls)
|
adamc@765
|
154 fun isEffectful x = S.member (!effectful, x)
|
adam@1878
|
155 fun addEffectful x = effectful := S.add (!effectful, x)
|
adamc@765
|
156
|
adamc@1171
|
157 val benignBase = basis ["get_cookie",
|
adamc@1171
|
158 "new_client_source",
|
adamc@1171
|
159 "get_client_source",
|
adamc@1171
|
160 "set_client_source",
|
adamc@1171
|
161 "current",
|
adamc@1171
|
162 "alert",
|
adam@1290
|
163 "confirm",
|
adamc@1171
|
164 "onError",
|
adamc@1171
|
165 "onFail",
|
adamc@1171
|
166 "onConnectFail",
|
adamc@1171
|
167 "onDisconnect",
|
adamc@1171
|
168 "onServerError",
|
adam@1783
|
169 "mouseEvent",
|
adam@1783
|
170 "keyEvent",
|
adamc@1250
|
171 "debug",
|
adam@1422
|
172 "rand",
|
adam@1465
|
173 "now",
|
adam@1465
|
174 "getHeader",
|
adam@1555
|
175 "setHeader",
|
adam@1555
|
176 "spawn",
|
adam@1555
|
177 "onClick",
|
adam@1555
|
178 "onDblclick",
|
adam@1555
|
179 "onKeydown",
|
adam@1555
|
180 "onKeypress",
|
adam@1555
|
181 "onKeyup",
|
adam@1555
|
182 "onMousedown",
|
adam@1791
|
183 "onMousemove",
|
adam@1791
|
184 "onMouseout",
|
adam@1791
|
185 "onMouseover",
|
adam@1556
|
186 "onMouseup",
|
adam@1559
|
187 "preventDefault",
|
adam@1559
|
188 "stopPropagation",
|
adam@1785
|
189 "fresh",
|
adam@1952
|
190 "giveFocus",
|
adam@1952
|
191 "currentUrlHasPost",
|
adam@1952
|
192 "currentUrlHasQueryString",
|
adam@1952
|
193 "currentUrl"]
|
adamc@1171
|
194
|
adamc@1171
|
195 val benign = ref benignBase
|
adamc@1171
|
196 fun setBenignEffectful ls = benign := S.addList (benignBase, ls)
|
adamc@1171
|
197 fun isBenignEffectful x = S.member (!benign, x)
|
adamc@1171
|
198
|
adam@1595
|
199 val clientBase = basis ["get_client_source",
|
adamc@841
|
200 "current",
|
adamc@765
|
201 "alert",
|
adam@1290
|
202 "confirm",
|
adamc@765
|
203 "recv",
|
adamc@765
|
204 "sleep",
|
adamc@765
|
205 "spawn",
|
adamc@765
|
206 "onError",
|
adamc@765
|
207 "onFail",
|
adamc@765
|
208 "onConnectFail",
|
adamc@765
|
209 "onDisconnect",
|
adamc@895
|
210 "onServerError",
|
adam@1783
|
211 "mouseEvent",
|
adam@1783
|
212 "keyEvent",
|
adam@1555
|
213 "onClick",
|
adam@1555
|
214 "onDblclick",
|
adam@1555
|
215 "onKeydown",
|
adam@1555
|
216 "onKeypress",
|
adam@1555
|
217 "onKeyup",
|
adam@1555
|
218 "onMousedown",
|
adam@1791
|
219 "onMousemove",
|
adam@1791
|
220 "onMouseout",
|
adam@1791
|
221 "onMouseover",
|
adam@1559
|
222 "onMouseup",
|
adam@1559
|
223 "preventDefault",
|
adam@1785
|
224 "stopPropagation",
|
adam@1785
|
225 "giveFocus"]
|
adamc@765
|
226 val client = ref clientBase
|
adamc@765
|
227 fun setClientOnly ls = client := S.addList (clientBase, ls)
|
adamc@765
|
228 fun isClientOnly x = S.member (!client, x)
|
adamc@765
|
229
|
adamc@765
|
230 val serverBase = basis ["requestHeader",
|
adamc@765
|
231 "query",
|
adamc@765
|
232 "dml",
|
adamc@765
|
233 "nextval",
|
adamc@1073
|
234 "setval",
|
adamc@765
|
235 "channel",
|
adam@1787
|
236 "send",
|
adam@1787
|
237 "fieldName",
|
adam@1787
|
238 "fieldValue",
|
adam@1787
|
239 "remainingFields",
|
adam@1787
|
240 "firstFormField"]
|
adamc@765
|
241 val server = ref serverBase
|
adamc@765
|
242 fun setServerOnly ls = server := S.addList (serverBase, ls)
|
adamc@765
|
243 fun isServerOnly x = S.member (!server, x)
|
adamc@765
|
244
|
adamc@765
|
245 val basisM = foldl (fn ((k, v : string), m) => M.insert (m, ("Basis", k), v)) M.empty
|
adamc@765
|
246
|
adamc@765
|
247 val jsFuncsBase = basisM [("alert", "alert"),
|
adam@1599
|
248 ("stringToTime", "stringToTime"),
|
adam@1599
|
249 ("stringToTime_error", "stringToTime_error"),
|
adam@1609
|
250 ("timef", "strftime"),
|
adam@1290
|
251 ("confirm", "confrm"),
|
adamc@765
|
252 ("get_client_source", "sg"),
|
adamc@841
|
253 ("current", "scur"),
|
adamc@765
|
254 ("htmlifyBool", "bs"),
|
adamc@765
|
255 ("htmlifyFloat", "ts"),
|
adamc@765
|
256 ("htmlifyInt", "ts"),
|
adamc@765
|
257 ("htmlifyString", "eh"),
|
adamc@765
|
258 ("new_client_source", "sc"),
|
adamc@765
|
259 ("set_client_source", "sv"),
|
adamc@838
|
260 ("stringToFloat", "pflo"),
|
adamc@838
|
261 ("stringToInt", "pio"),
|
adamc@765
|
262 ("stringToFloat_error", "pfl"),
|
adamc@765
|
263 ("stringToInt_error", "pi"),
|
adamc@765
|
264 ("urlifyInt", "ts"),
|
adamc@765
|
265 ("urlifyFloat", "ts"),
|
adam@1360
|
266 ("urlifyTime", "ts"),
|
adamc@765
|
267 ("urlifyString", "uf"),
|
adamc@912
|
268 ("urlifyBool", "ub"),
|
adamc@765
|
269 ("recv", "rv"),
|
adamc@765
|
270 ("strcat", "cat"),
|
adamc@765
|
271 ("intToString", "ts"),
|
adamc@765
|
272 ("floatToString", "ts"),
|
adamc@821
|
273 ("charToString", "ts"),
|
adamc@765
|
274 ("onError", "onError"),
|
adamc@765
|
275 ("onFail", "onFail"),
|
adamc@765
|
276 ("onConnectFail", "onConnectFail"),
|
adamc@765
|
277 ("onDisconnect", "onDisconnect"),
|
adamc@798
|
278 ("onServerError", "onServerError"),
|
adamc@1108
|
279 ("attrifyString", "atr"),
|
adamc@798
|
280 ("attrifyInt", "ts"),
|
adamc@798
|
281 ("attrifyFloat", "ts"),
|
adamc@820
|
282 ("attrifyBool", "bs"),
|
adamc@821
|
283 ("boolToString", "ts"),
|
adamc@1057
|
284 ("str1", "id"),
|
adamc@821
|
285 ("strsub", "sub"),
|
adamc@828
|
286 ("strsuffix", "suf"),
|
adamc@829
|
287 ("strlen", "slen"),
|
adamc@829
|
288 ("strindex", "sidx"),
|
adamc@829
|
289 ("strchr", "schr"),
|
adamc@831
|
290 ("substring", "ssub"),
|
adamc@895
|
291 ("strcspn", "sspn"),
|
adam@1624
|
292 ("strlenGe", "strlenGe"),
|
adam@1783
|
293 ("mouseEvent", "uw_mouseEvent"),
|
adam@1783
|
294 ("keyEvent", "uw_keyEvent"),
|
adam@1404
|
295 ("minTime", "0"),
|
adamc@1061
|
296
|
adamc@1061
|
297 ("islower", "isLower"),
|
adamc@1061
|
298 ("isupper", "isUpper"),
|
adamc@1061
|
299 ("isalpha", "isAlpha"),
|
adamc@1061
|
300 ("isdigit", "isDigit"),
|
adamc@1061
|
301 ("isalnum", "isAlnum"),
|
adamc@1061
|
302 ("isblank", "isBlank"),
|
adamc@1061
|
303 ("isspace", "isSpace"),
|
adamc@1061
|
304 ("isxdigit", "isXdigit"),
|
adam@1927
|
305 ("isprint", "isPrint"),
|
adamc@1061
|
306 ("tolower", "toLower"),
|
adamc@1323
|
307 ("toupper", "toUpper"),
|
adam@1927
|
308 ("ord", "ord"),
|
adamc@1323
|
309
|
adamc@1323
|
310 ("checkUrl", "checkUrl"),
|
adam@1366
|
311 ("bless", "bless"),
|
adam@2008
|
312 ("blessData", "blessData"),
|
adam@1366
|
313
|
adam@1366
|
314 ("eq_time", "eq"),
|
adam@1366
|
315 ("lt_time", "lt"),
|
adam@1430
|
316 ("le_time", "le"),
|
adam@1430
|
317
|
adam@1625
|
318 ("debug", "uw_debug"),
|
adam@1625
|
319 ("naughtyDebug", "uw_debug"),
|
adam@1487
|
320
|
adam@1571
|
321 ("floatFromInt", "float"),
|
adam@1571
|
322 ("ceil", "ceil"),
|
adam@1571
|
323 ("trunc", "trunc"),
|
adam@1571
|
324 ("round", "round"),
|
adam@1571
|
325
|
adam@1487
|
326 ("now", "now"),
|
adam@1487
|
327 ("timeToString", "showTime"),
|
adam@1629
|
328 ("htmlifyTime", "showTimeHtml"),
|
adam@1514
|
329 ("toSeconds", "toSeconds"),
|
adam@1518
|
330 ("addSeconds", "addSeconds"),
|
adam@1555
|
331 ("diffInSeconds", "diffInSeconds"),
|
adam@1685
|
332 ("toMilliseconds", "toMilliseconds"),
|
adam@1685
|
333 ("diffInMilliseconds", "diffInMilliseconds"),
|
adam@1555
|
334
|
phurst@1986
|
335 ("fromDatetime", "fromDatetime"),
|
phurst@1986
|
336 ("datetimeYear", "datetimeYear"),
|
phurst@1986
|
337 ("datetimeMonth", "datetimeMonth"),
|
phurst@1986
|
338 ("datetimeDay", "datetimeDay"),
|
phurst@1986
|
339 ("datetimeHour", "datetimeHour"),
|
phurst@1986
|
340 ("datetimeMinute", "datetimeMinute"),
|
phurst@1986
|
341 ("datetimeSecond", "datetimeSecond"),
|
phurst@1986
|
342 ("datetimeDayOfWeek", "datetimeDayOfWeek"),
|
phurst@1986
|
343
|
phurst@1986
|
344
|
adam@1555
|
345 ("onClick", "uw_onClick"),
|
adam@1555
|
346 ("onDblclick", "uw_onDblclick"),
|
adam@1555
|
347 ("onKeydown", "uw_onKeydown"),
|
adam@1555
|
348 ("onKeypress", "uw_onKeypress"),
|
adam@1555
|
349 ("onKeyup", "uw_onKeyup"),
|
adam@1555
|
350 ("onMousedown", "uw_onMousedown"),
|
adam@1791
|
351 ("onMousemove", "uw_onMousemove"),
|
adam@1791
|
352 ("onMouseout", "uw_onMouseout"),
|
adam@1791
|
353 ("onMouseover", "uw_onMouseover"),
|
adam@1556
|
354 ("onMouseup", "uw_onMouseup"),
|
adam@1559
|
355 ("preventDefault", "uw_preventDefault"),
|
adam@1559
|
356 ("stopPropagation", "uw_stopPropagation"),
|
adam@1556
|
357
|
adam@1755
|
358 ("fresh", "fresh"),
|
adam@1755
|
359
|
adam@1755
|
360 ("atom", "atom"),
|
adam@1755
|
361 ("css_url", "css_url"),
|
adam@1785
|
362 ("property", "property"),
|
adam@1785
|
363 ("giveFocus", "giveFocus")]
|
adamc@765
|
364 val jsFuncs = ref jsFuncsBase
|
adamc@765
|
365 fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls
|
adamc@765
|
366 fun jsFunc x = M.find (!jsFuncs, x)
|
adam@1433
|
367 fun allJsFuncs () = M.listItemsi (!jsFuncs)
|
adamc@765
|
368
|
adamc@768
|
369 datatype pattern_kind = Exact | Prefix
|
adamc@768
|
370 datatype action = Allow | Deny
|
adamc@768
|
371 type rule = { action : action, kind : pattern_kind, pattern : string }
|
adamc@768
|
372
|
adamc@768
|
373 datatype path_kind = Any | Url | Table | Sequence | View | Relation | Cookie | Style
|
adam@1752
|
374 type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string, hyphenate : bool }
|
adamc@768
|
375
|
adamc@768
|
376 val rewrites = ref ([] : rewrite list)
|
adamc@768
|
377
|
adamc@768
|
378 fun subsume (pk1, pk2) =
|
adamc@768
|
379 pk1 = pk2
|
adamc@768
|
380 orelse pk2 = Any
|
adamc@768
|
381 orelse pk2 = Relation andalso (pk1 = Table orelse pk1 = Sequence orelse pk1 = View)
|
adamc@768
|
382
|
adamc@768
|
383 fun setRewriteRules ls = rewrites := ls
|
adamc@768
|
384 fun rewrite pk s =
|
adamc@768
|
385 let
|
adamc@768
|
386 fun rew (ls : rewrite list) =
|
adamc@768
|
387 case ls of
|
adamc@768
|
388 [] => s
|
adamc@768
|
389 | rewr :: ls =>
|
adamc@768
|
390 let
|
adamc@768
|
391 fun match () =
|
adamc@768
|
392 case #kind rewr of
|
adamc@768
|
393 Exact => if #from rewr = s then
|
adamc@768
|
394 SOME (size s)
|
adamc@768
|
395 else
|
adamc@768
|
396 NONE
|
adamc@768
|
397 | Prefix => if String.isPrefix (#from rewr) s then
|
adamc@768
|
398 SOME (size (#from rewr))
|
adamc@768
|
399 else
|
adamc@768
|
400 NONE
|
adamc@768
|
401 in
|
adamc@768
|
402 if subsume (pk, #pkind rewr) then
|
adamc@768
|
403 case match () of
|
adamc@768
|
404 NONE => rew ls
|
adam@1752
|
405 | SOME suffixStart =>
|
adam@1752
|
406 let
|
adam@1752
|
407 val s = #to rewr ^ String.extract (s, suffixStart, NONE)
|
adam@1752
|
408 in
|
adam@1752
|
409 if #hyphenate rewr then
|
adam@1752
|
410 String.translate (fn #"_" => "-" | ch => str ch) s
|
adam@1752
|
411 else
|
adam@1752
|
412 s
|
adam@1752
|
413 end
|
adamc@768
|
414 else
|
adamc@768
|
415 rew ls
|
adamc@768
|
416 end
|
adamc@768
|
417 in
|
adamc@768
|
418 rew (!rewrites)
|
adamc@768
|
419 end
|
adamc@768
|
420
|
adamc@769
|
421 val url = ref ([] : rule list)
|
adamc@769
|
422 val mime = ref ([] : rule list)
|
adam@1465
|
423 val request = ref ([] : rule list)
|
adam@1465
|
424 val response = ref ([] : rule list)
|
adam@1799
|
425 val env = ref ([] : rule list)
|
adamc@769
|
426
|
adamc@769
|
427 fun setUrlRules ls = url := ls
|
adamc@769
|
428 fun setMimeRules ls = mime := ls
|
adam@1465
|
429 fun setRequestHeaderRules ls = request := ls
|
adam@1465
|
430 fun setResponseHeaderRules ls = response := ls
|
adam@1799
|
431 fun setEnvVarRules ls = env := ls
|
adamc@769
|
432
|
adamc@770
|
433 fun getUrlRules () = !url
|
adamc@770
|
434 fun getMimeRules () = !mime
|
adam@1465
|
435 fun getRequestHeaderRules () = !request
|
adam@1465
|
436 fun getResponseHeaderRules () = !response
|
adam@1799
|
437 fun getEnvVarRules () = !env
|
adamc@770
|
438
|
adamc@769
|
439 fun check f rules s =
|
adamc@769
|
440 let
|
adamc@769
|
441 fun chk (ls : rule list) =
|
adamc@769
|
442 case ls of
|
adamc@769
|
443 [] => false
|
adamc@769
|
444 | rule :: ls =>
|
adamc@769
|
445 let
|
adamc@769
|
446 val matches =
|
adamc@769
|
447 case #kind rule of
|
adamc@769
|
448 Exact => #pattern rule = s
|
adamc@769
|
449 | Prefix => String.isPrefix (#pattern rule) s
|
adamc@769
|
450 in
|
adamc@769
|
451 if matches then
|
adamc@769
|
452 case #action rule of
|
adamc@769
|
453 Allow => true
|
adamc@769
|
454 | Deny => false
|
adamc@769
|
455 else
|
adamc@769
|
456 chk ls
|
adamc@769
|
457 end
|
adamc@769
|
458 in
|
adamc@769
|
459 f s andalso chk (!rules)
|
adamc@769
|
460 end
|
adamc@769
|
461
|
adamc@769
|
462 val checkUrl = check (fn _ => true) url
|
adam@1465
|
463
|
adam@1465
|
464 val validMime = CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"/" orelse ch = #"-" orelse ch = #".")
|
adam@1799
|
465 val validEnv = CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"_" orelse ch = #".")
|
adam@1465
|
466
|
adam@1465
|
467 val checkMime = check validMime mime
|
adam@1465
|
468 val checkRequestHeader = check validMime request
|
adam@1465
|
469 val checkResponseHeader = check validMime response
|
adam@1799
|
470 val checkEnvVar = check validEnv env
|
adamc@769
|
471
|
adamc@855
|
472
|
adamc@855
|
473 type protocol = {
|
adamc@855
|
474 name : string,
|
adamc@1096
|
475 compile : string,
|
adamc@1095
|
476 linkStatic : string,
|
adamc@1095
|
477 linkDynamic : string,
|
adamc@1164
|
478 persistent : bool,
|
adamc@1164
|
479 code : unit -> Print.PD.pp_desc
|
adamc@855
|
480 }
|
adamc@855
|
481 val protocols = ref ([] : protocol list)
|
adamc@855
|
482 fun addProtocol p = protocols := p :: !protocols
|
adamc@855
|
483 fun getProtocol s = List.find (fn p => #name p = s) (!protocols)
|
adamc@855
|
484
|
ezyang@1739
|
485 fun clibFile s = OS.Path.joinDirFile {dir = libC (),
|
adamc@855
|
486 file = s}
|
adamc@855
|
487
|
adamc@865
|
488 val curProto = ref {name = "",
|
adamc@1096
|
489 compile = "",
|
adamc@1095
|
490 linkStatic = "",
|
adamc@1095
|
491 linkDynamic = "",
|
adamc@1164
|
492 persistent = false,
|
adamc@1164
|
493 code = fn () => Print.box []}
|
adamc@856
|
494 fun setProtocol name =
|
adamc@856
|
495 case getProtocol name of
|
adamc@856
|
496 NONE => raise Fail ("Unknown protocol " ^ name)
|
adamc@856
|
497 | SOME p => curProto := p
|
adamc@855
|
498 fun currentProtocol () = !curProto
|
adamc@855
|
499
|
adamc@857
|
500 val debug = ref false
|
adamc@857
|
501 fun setDebug b = debug := b
|
adamc@857
|
502 fun getDebug () = !debug
|
adamc@857
|
503
|
adamc@867
|
504 datatype sql_type =
|
adamc@867
|
505 Int
|
adamc@867
|
506 | Float
|
adamc@867
|
507 | String
|
adamc@1011
|
508 | Char
|
adamc@867
|
509 | Bool
|
adamc@867
|
510 | Time
|
adamc@867
|
511 | Blob
|
adamc@867
|
512 | Channel
|
adamc@867
|
513 | Client
|
adamc@867
|
514 | Nullable of sql_type
|
adamc@867
|
515
|
adamc@873
|
516 fun p_sql_ctype t =
|
adamc@867
|
517 let
|
adamc@867
|
518 open Print.PD
|
adamc@867
|
519 open Print
|
adamc@867
|
520 in
|
adamc@867
|
521 case t of
|
adamc@870
|
522 Int => "uw_Basis_int"
|
adamc@870
|
523 | Float => "uw_Basis_float"
|
adamc@870
|
524 | String => "uw_Basis_string"
|
adamc@1011
|
525 | Char => "uw_Basis_char"
|
adamc@870
|
526 | Bool => "uw_Basis_bool"
|
adamc@870
|
527 | Time => "uw_Basis_time"
|
adamc@870
|
528 | Blob => "uw_Basis_blob"
|
adamc@870
|
529 | Channel => "uw_Basis_channel"
|
adamc@870
|
530 | Client => "uw_Basis_client"
|
adamc@870
|
531 | Nullable String => "uw_Basis_string"
|
adamc@873
|
532 | Nullable t => p_sql_ctype t ^ "*"
|
adamc@867
|
533 end
|
adamc@867
|
534
|
adamc@867
|
535 fun isBlob Blob = true
|
adamc@867
|
536 | isBlob (Nullable t) = isBlob t
|
adamc@867
|
537 | isBlob _ = false
|
adamc@867
|
538
|
adamc@870
|
539 fun isNotNull (Nullable _) = false
|
adamc@870
|
540 | isNotNull _ = true
|
adamc@870
|
541
|
adam@1293
|
542 datatype failure_mode = Error | None
|
adam@1293
|
543
|
adamc@866
|
544 type dbms = {
|
adamc@866
|
545 name : string,
|
adam@1682
|
546 randomFunction : string,
|
adamc@866
|
547 header : string,
|
adamc@866
|
548 link : string,
|
adamc@873
|
549 p_sql_type : sql_type -> string,
|
adamc@870
|
550 init : {dbstring : string,
|
adamc@870
|
551 prepared : (string * int) list,
|
adamc@870
|
552 tables : (string * (string * sql_type) list) list,
|
adamc@872
|
553 views : (string * (string * sql_type) list) list,
|
adamc@870
|
554 sequences : string list} -> Print.PD.pp_desc,
|
adamc@873
|
555 query : {loc : ErrorMsg.span, cols : sql_type list,
|
adamc@880
|
556 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int, typ : sql_type} -> Print.PD.pp_desc)
|
adamc@867
|
557 -> Print.PD.pp_desc}
|
adamc@867
|
558 -> Print.PD.pp_desc,
|
adamc@867
|
559 queryPrepared : {loc : ErrorMsg.span, id : int, query : string,
|
adamc@873
|
560 inputs : sql_type list, cols : sql_type list,
|
adamc@880
|
561 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int,
|
adamc@880
|
562 typ : sql_type} -> Print.PD.pp_desc)
|
adamc@879
|
563 -> Print.PD.pp_desc,
|
adamc@879
|
564 nested : bool}
|
adamc@868
|
565 -> Print.PD.pp_desc,
|
adam@1293
|
566 dml : ErrorMsg.span * failure_mode -> Print.PD.pp_desc,
|
adamc@868
|
567 dmlPrepared : {loc : ErrorMsg.span, id : int, dml : string,
|
adam@1293
|
568 inputs : sql_type list, mode : failure_mode} -> Print.PD.pp_desc,
|
adamc@878
|
569 nextval : {loc : ErrorMsg.span, seqName : string option, seqE : Print.PD.pp_desc} -> Print.PD.pp_desc,
|
adamc@874
|
570 nextvalPrepared : {loc : ErrorMsg.span, id : int, query : string} -> Print.PD.pp_desc,
|
adamc@1073
|
571 setval : {loc : ErrorMsg.span, seqE : Print.PD.pp_desc, count : Print.PD.pp_desc} -> Print.PD.pp_desc,
|
adamc@874
|
572 sqlifyString : string -> string,
|
adamc@874
|
573 p_cast : string * sql_type -> string,
|
adamc@874
|
574 p_blank : int * sql_type -> string,
|
adamc@877
|
575 supportsDeleteAs : bool,
|
adamc@886
|
576 supportsUpdateAs : bool,
|
adamc@877
|
577 createSequence : string -> string,
|
adamc@878
|
578 textKeysNeedLengths : bool,
|
adamc@879
|
579 supportsNextval : bool,
|
adamc@882
|
580 supportsNestedPrepared : bool,
|
adamc@890
|
581 sqlPrefix : string,
|
adamc@1014
|
582 supportsOctetLength : bool,
|
adamc@1014
|
583 trueString : string,
|
adamc@1196
|
584 falseString : string,
|
adamc@1196
|
585 onlyUnion : bool,
|
adam@1777
|
586 nestedRelops : bool,
|
adam@1778
|
587 windowFunctions: bool
|
adamc@866
|
588 }
|
adamc@866
|
589
|
adamc@866
|
590 val dbmses = ref ([] : dbms list)
|
adamc@866
|
591 val curDb = ref ({name = "",
|
adam@1682
|
592 randomFunction = "",
|
adamc@866
|
593 header = "",
|
adamc@866
|
594 link = "",
|
adamc@873
|
595 p_sql_type = fn _ => "",
|
adamc@867
|
596 init = fn _ => Print.box [],
|
adamc@867
|
597 query = fn _ => Print.box [],
|
adamc@868
|
598 queryPrepared = fn _ => Print.box [],
|
adamc@868
|
599 dml = fn _ => Print.box [],
|
adamc@869
|
600 dmlPrepared = fn _ => Print.box [],
|
adamc@869
|
601 nextval = fn _ => Print.box [],
|
adamc@874
|
602 nextvalPrepared = fn _ => Print.box [],
|
adamc@1073
|
603 setval = fn _ => Print.box [],
|
adamc@874
|
604 sqlifyString = fn s => s,
|
adamc@874
|
605 p_cast = fn _ => "",
|
adamc@874
|
606 p_blank = fn _ => "",
|
adamc@877
|
607 supportsDeleteAs = false,
|
adamc@886
|
608 supportsUpdateAs = false,
|
adamc@877
|
609 createSequence = fn _ => "",
|
adamc@878
|
610 textKeysNeedLengths = false,
|
adamc@879
|
611 supportsNextval = false,
|
adamc@882
|
612 supportsNestedPrepared = false,
|
adamc@890
|
613 sqlPrefix = "",
|
adamc@1014
|
614 supportsOctetLength = false,
|
adamc@1014
|
615 trueString = "",
|
adamc@1196
|
616 falseString = "",
|
adamc@1196
|
617 onlyUnion = false,
|
adam@1777
|
618 nestedRelops = false,
|
adam@1777
|
619 windowFunctions = false} : dbms)
|
adamc@866
|
620
|
adamc@866
|
621 fun addDbms v = dbmses := v :: !dbmses
|
adamc@866
|
622 fun setDbms s =
|
adamc@866
|
623 case List.find (fn db => #name db = s) (!dbmses) of
|
adamc@866
|
624 NONE => raise Fail ("Unknown DBMS " ^ s)
|
adamc@866
|
625 | SOME db => curDb := db
|
adamc@866
|
626 fun currentDbms () = !curDb
|
adamc@866
|
627
|
adamc@891
|
628 val dbstring = ref (NONE : string option)
|
adamc@891
|
629 fun setDbstring so = dbstring := so
|
adamc@891
|
630 fun getDbstring () = !dbstring
|
adamc@891
|
631
|
adamc@891
|
632 val exe = ref (NONE : string option)
|
adamc@891
|
633 fun setExe so = exe := so
|
adamc@891
|
634 fun getExe () = !exe
|
adamc@891
|
635
|
adamc@891
|
636 val sql = ref (NONE : string option)
|
adamc@891
|
637 fun setSql so = sql := so
|
adamc@891
|
638 fun getSql () = !sql
|
adamc@891
|
639
|
adam@1820
|
640 val coreInline = ref 5
|
adamc@1016
|
641 fun setCoreInline n = coreInline := n
|
adamc@1016
|
642 fun getCoreInline () = !coreInline
|
adamc@1016
|
643
|
adam@1820
|
644 val monoInline = ref 5
|
adamc@1016
|
645 fun setMonoInline n = monoInline := n
|
adamc@1016
|
646 fun getMonoInline () = !monoInline
|
adamc@1016
|
647
|
adamc@1095
|
648 val staticLinking = ref false
|
adamc@1095
|
649 fun setStaticLinking b = staticLinking := b
|
adamc@1095
|
650 fun getStaticLinking () = !staticLinking
|
adamc@1095
|
651
|
adamc@1114
|
652 val deadlines = ref false
|
adamc@1114
|
653 fun setDeadlines b = deadlines := b
|
adamc@1114
|
654 fun getDeadlines () = !deadlines
|
adamc@1114
|
655
|
adamc@1164
|
656 val sigFile = ref (NONE : string option)
|
adamc@1164
|
657 fun setSigFile v = sigFile := v
|
adamc@1164
|
658 fun getSigFile () = !sigFile
|
adamc@1164
|
659
|
adamc@1183
|
660 structure SS = BinarySetFn(struct
|
adamc@1183
|
661 type ord_key = string
|
adamc@1183
|
662 val compare = String.compare
|
adamc@1183
|
663 end)
|
adamc@1183
|
664
|
adamc@1183
|
665 val safeGet = ref SS.empty
|
adamc@1183
|
666 fun setSafeGets ls = safeGet := SS.addList (SS.empty, ls)
|
adamc@1183
|
667 fun isSafeGet x = SS.member (!safeGet, x)
|
adamc@1183
|
668
|
adam@1294
|
669 val onError = ref (NONE : (string * string list * string) option)
|
adam@1294
|
670 fun setOnError x = onError := x
|
adam@1294
|
671 fun getOnError () = !onError
|
adam@1294
|
672
|
adam@1307
|
673 val limits = ["messages", "clients", "headers", "page", "heap", "script",
|
adam@1307
|
674 "inputs", "subinputs", "cleanup", "deltas", "transactionals",
|
adam@1308
|
675 "globals", "database", "time"]
|
adam@1307
|
676
|
adam@1307
|
677 val limitsList = ref ([] : (string * int) list)
|
adam@1307
|
678 fun addLimit (v as (name, _)) =
|
adam@1307
|
679 if List.exists (fn name' => name' = name) limits then
|
adam@1308
|
680 (limitsList := v :: !limitsList;
|
adam@1308
|
681 if name = "time" then
|
adam@1308
|
682 setDeadlines true
|
adam@1308
|
683 else
|
adam@1308
|
684 ())
|
adam@1307
|
685 else
|
adam@1307
|
686 raise Fail ("Unknown limit category '" ^ name ^ "'")
|
adam@1307
|
687 fun limits () = !limitsList
|
adam@1307
|
688
|
adam@1332
|
689 val minHeap = ref 0
|
adam@1332
|
690 fun setMinHeap n = if n >= 0 then minHeap := n else raise Fail "Trying to set negative minHeap"
|
adam@1332
|
691 fun getMinHeap () = !minHeap
|
adam@1332
|
692
|
adam@1393
|
693 structure SS = BinarySetFn(struct
|
adam@1393
|
694 type ord_key = string
|
adam@1393
|
695 val compare = String.compare
|
adam@1393
|
696 end)
|
adam@1393
|
697
|
adam@1393
|
698 val alwaysInline = ref SS.empty
|
adam@1393
|
699 fun addAlwaysInline s = alwaysInline := SS.add (!alwaysInline, s)
|
adam@1393
|
700 fun checkAlwaysInline s = SS.member (!alwaysInline, s)
|
adam@1393
|
701
|
adam@1966
|
702 val neverInline = ref SS.empty
|
adam@1966
|
703 fun addNeverInline s = neverInline := SS.add (!neverInline, s)
|
adam@1966
|
704 fun checkNeverInline s = SS.member (!neverInline, s)
|
adam@1966
|
705
|
adam@1478
|
706 val noXsrfProtection = ref SS.empty
|
adam@1478
|
707 fun addNoXsrfProtection s = noXsrfProtection := SS.add (!noXsrfProtection, s)
|
adam@1478
|
708 fun checkNoXsrfProtection s = SS.member (!noXsrfProtection, s)
|
adam@1478
|
709
|
adam@1629
|
710 val timeFormat = ref "%c"
|
adam@1629
|
711 fun setTimeFormat v = timeFormat := v
|
adam@1629
|
712 fun getTimeFormat () = !timeFormat
|
adam@1629
|
713
|
adam@1953
|
714 fun lowercase s =
|
adam@1953
|
715 case s of
|
adam@1953
|
716 "" => ""
|
adam@1953
|
717 | _ => str (Char.toLower (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adam@1953
|
718
|
adam@1953
|
719 fun capitalize s =
|
adam@1953
|
720 case s of
|
adam@1953
|
721 "" => ""
|
adam@1953
|
722 | _ => str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adam@1953
|
723
|
adam@1953
|
724 val mangle = ref true
|
adam@1953
|
725 fun setMangleSql x = mangle := x
|
adam@1953
|
726 fun mangleSqlTable s = if !mangle then "uw_" ^ capitalize s
|
adam@1953
|
727 else if #name (currentDbms ()) = "mysql" then capitalize s
|
adam@1959
|
728 else lowercase s
|
adam@1953
|
729 fun mangleSql s = if !mangle then "uw_" ^ s
|
adam@1953
|
730 else if #name (currentDbms ()) = "mysql" then lowercase s
|
adam@1959
|
731 else lowercase s
|
adam@1953
|
732 fun mangleSqlCatalog s = if !mangle then "uw_" ^ s else lowercase s
|
adam@1953
|
733
|
adam@1956
|
734 val html5 = ref false
|
adam@1956
|
735 fun setIsHtml5 b = html5 := b
|
adam@1956
|
736 fun getIsHtml5 () = !html5
|
adam@1956
|
737
|
adamc@765
|
738 end
|