annotate src/settings.sml @ 1617:8611da277df4

Return to working version mode
author Adam Chlipala <adam@chlipala.net>
date Sun, 27 Nov 2011 15:32:06 -0500
parents c6cc104a47ac
children f96e708b4b93
rev   line source
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
adamc@764 30 val urlPrefix = ref "/"
adam@1370 31 val urlPrePrefix = ref ""
adamc@764 32 val timeout = ref 0
adamc@764 33 val headers = ref ([] : string list)
adamc@766 34 val scripts = ref ([] : string list)
adamc@764 35
adamc@764 36 fun getUrlPrefix () = !urlPrefix
adam@1370 37 fun getUrlPrePrefix () = !urlPrePrefix
adamc@764 38 fun setUrlPrefix p =
adam@1370 39 let
adam@1370 40 val prefix = if p = "" then
adam@1370 41 "/"
adam@1370 42 else if String.sub (p, size p - 1) <> #"/" then
adam@1370 43 p ^ "/"
adam@1370 44 else
adam@1370 45 p
adam@1370 46
adam@1470 47 fun findPrefix n =
adam@1470 48 let
adam@1470 49 val (befor, after) = Substring.splitl (fn ch => ch <> #"/") (Substring.extract (prefix, n, NONE))
adam@1470 50 in
adam@1470 51 if Substring.isEmpty after then
adam@1470 52 ("", prefix)
adam@1470 53 else
adam@1470 54 (String.substring (prefix, 0, n) ^ Substring.string befor, Substring.string after)
rmbruijn@1597 55 end
adam@1470 56
adam@1370 57 val (prepre, prefix) =
adam@1370 58 if String.isPrefix "http://" prefix then
adam@1470 59 findPrefix 7
adam@1470 60 else if String.isPrefix "https://" prefix then
adam@1470 61 findPrefix 8
adam@1370 62 else
adam@1370 63 ("", prefix)
adam@1370 64 in
adam@1370 65 urlPrePrefix := prepre;
adam@1370 66 urlPrefix := prefix
adam@1370 67 end
adamc@764 68
adamc@764 69 fun getTimeout () = !timeout
adamc@764 70 fun setTimeout n = timeout := n
adamc@764 71
adamc@764 72 fun getHeaders () = !headers
adamc@764 73 fun setHeaders ls = headers := ls
adamc@764 74
adamc@766 75 fun getScripts () = !scripts
adamc@766 76 fun setScripts ls = scripts := ls
adamc@766 77
adamc@765 78 type ffi = string * string
adamc@765 79
adamc@765 80 structure K = struct
adamc@765 81 type ord_key = ffi
adamc@765 82 fun compare ((m1, x1), (m2, x2)) =
adamc@765 83 Order.join (String.compare (m1, m2),
adamc@765 84 fn () => String.compare (x1, x2))
adamc@764 85 end
adamc@765 86
adamc@765 87 structure S = BinarySetFn(K)
adamc@765 88 structure M = BinaryMapFn(K)
adamc@765 89
adamc@765 90 fun basis x = S.addList (S.empty, map (fn x : string => ("Basis", x)) x)
adamc@765 91
adamc@765 92 val clientToServerBase = basis ["int",
adamc@765 93 "float",
adamc@765 94 "string",
adamc@765 95 "time",
adamc@765 96 "file",
adamc@765 97 "unit",
adamc@765 98 "option",
adamc@765 99 "list",
adam@1288 100 "bool",
adam@1288 101 "variant"]
adamc@765 102 val clientToServer = ref clientToServerBase
adamc@765 103 fun setClientToServer ls = clientToServer := S.addList (clientToServerBase, ls)
adamc@765 104 fun mayClientToServer x = S.member (!clientToServer, x)
adamc@765 105
adamc@779 106 val effectfulBase = basis ["dml",
adamc@779 107 "nextval",
adamc@1073 108 "setval",
adamc@779 109 "set_cookie",
adamc@1050 110 "clear_cookie",
adamc@765 111 "new_channel",
adamc@1200 112 "send",
adamc@1200 113 "htmlifyInt_w",
adamc@1200 114 "htmlifyFloat_w",
adamc@1200 115 "htmlifyString_w",
adamc@1200 116 "htmlifyBool_w",
adamc@1200 117 "htmlifyTime_w",
adamc@1200 118 "attrifyInt_w",
adamc@1200 119 "attrifyFloat_w",
adamc@1200 120 "attrifyString_w",
adamc@1200 121 "attrifyChar_w",
adamc@1200 122 "urlifyInt_w",
adamc@1200 123 "urlifyFloat_w",
adamc@1200 124 "urlifyString_w",
adamc@1200 125 "urlifyBool_w",
adamc@1200 126 "urlifyChannel_w"]
adamc@765 127
adamc@765 128 val effectful = ref effectfulBase
adamc@765 129 fun setEffectful ls = effectful := S.addList (effectfulBase, ls)
adamc@765 130 fun isEffectful x = S.member (!effectful, x)
adamc@765 131
adamc@1171 132 val benignBase = basis ["get_cookie",
adamc@1171 133 "new_client_source",
adamc@1171 134 "get_client_source",
adamc@1171 135 "set_client_source",
adamc@1171 136 "current",
adamc@1171 137 "alert",
adam@1290 138 "confirm",
adamc@1171 139 "onError",
adamc@1171 140 "onFail",
adamc@1171 141 "onConnectFail",
adamc@1171 142 "onDisconnect",
adamc@1171 143 "onServerError",
adamc@1171 144 "kc",
adamc@1250 145 "debug",
adam@1389 146 "naughtyDebug",
adam@1422 147 "rand",
adam@1465 148 "now",
adam@1465 149 "getHeader",
adam@1555 150 "setHeader",
adam@1555 151 "spawn",
adam@1555 152 "onClick",
adam@1555 153 "onDblclick",
adam@1555 154 "onKeydown",
adam@1555 155 "onKeypress",
adam@1555 156 "onKeyup",
adam@1555 157 "onMousedown",
adam@1556 158 "onMouseup",
adam@1559 159 "preventDefault",
adam@1559 160 "stopPropagation",
adam@1556 161 "fresh"]
adamc@1171 162
adamc@1171 163 val benign = ref benignBase
adamc@1171 164 fun setBenignEffectful ls = benign := S.addList (benignBase, ls)
adamc@1171 165 fun isBenignEffectful x = S.member (!benign, x)
adamc@1171 166
adam@1595 167 val clientBase = basis ["get_client_source",
adamc@841 168 "current",
adamc@765 169 "alert",
adam@1290 170 "confirm",
adamc@765 171 "recv",
adamc@765 172 "sleep",
adamc@765 173 "spawn",
adamc@765 174 "onError",
adamc@765 175 "onFail",
adamc@765 176 "onConnectFail",
adamc@765 177 "onDisconnect",
adamc@895 178 "onServerError",
adam@1555 179 "kc",
adam@1555 180 "onClick",
adam@1555 181 "onDblclick",
adam@1555 182 "onKeydown",
adam@1555 183 "onKeypress",
adam@1555 184 "onKeyup",
adam@1555 185 "onMousedown",
adam@1559 186 "onMouseup",
adam@1559 187 "preventDefault",
adam@1559 188 "stopPropagation"]
adamc@765 189 val client = ref clientBase
adamc@765 190 fun setClientOnly ls = client := S.addList (clientBase, ls)
adamc@765 191 fun isClientOnly x = S.member (!client, x)
adamc@765 192
adamc@765 193 val serverBase = basis ["requestHeader",
adamc@765 194 "query",
adamc@765 195 "dml",
adamc@765 196 "nextval",
adamc@1073 197 "setval",
adamc@765 198 "channel",
adamc@765 199 "send"]
adamc@765 200 val server = ref serverBase
adamc@765 201 fun setServerOnly ls = server := S.addList (serverBase, ls)
adamc@765 202 fun isServerOnly x = S.member (!server, x)
adamc@765 203
adamc@765 204 val basisM = foldl (fn ((k, v : string), m) => M.insert (m, ("Basis", k), v)) M.empty
adamc@765 205
adamc@765 206 val jsFuncsBase = basisM [("alert", "alert"),
adam@1599 207 ("stringToTime", "stringToTime"),
adam@1599 208 ("stringToTime_error", "stringToTime_error"),
adam@1609 209 ("timef", "strftime"),
adam@1290 210 ("confirm", "confrm"),
adamc@765 211 ("get_client_source", "sg"),
adamc@841 212 ("current", "scur"),
adamc@765 213 ("htmlifyBool", "bs"),
adamc@765 214 ("htmlifyFloat", "ts"),
adamc@765 215 ("htmlifyInt", "ts"),
adamc@765 216 ("htmlifyString", "eh"),
adamc@765 217 ("new_client_source", "sc"),
adamc@765 218 ("set_client_source", "sv"),
adamc@838 219 ("stringToFloat", "pflo"),
adamc@838 220 ("stringToInt", "pio"),
adamc@765 221 ("stringToFloat_error", "pfl"),
adamc@765 222 ("stringToInt_error", "pi"),
adamc@765 223 ("urlifyInt", "ts"),
adamc@765 224 ("urlifyFloat", "ts"),
adam@1360 225 ("urlifyTime", "ts"),
adamc@765 226 ("urlifyString", "uf"),
adamc@912 227 ("urlifyBool", "ub"),
adamc@765 228 ("recv", "rv"),
adamc@765 229 ("strcat", "cat"),
adamc@765 230 ("intToString", "ts"),
adamc@765 231 ("floatToString", "ts"),
adamc@821 232 ("charToString", "ts"),
adamc@765 233 ("onError", "onError"),
adamc@765 234 ("onFail", "onFail"),
adamc@765 235 ("onConnectFail", "onConnectFail"),
adamc@765 236 ("onDisconnect", "onDisconnect"),
adamc@798 237 ("onServerError", "onServerError"),
adamc@1108 238 ("attrifyString", "atr"),
adamc@798 239 ("attrifyInt", "ts"),
adamc@798 240 ("attrifyFloat", "ts"),
adamc@820 241 ("attrifyBool", "bs"),
adamc@821 242 ("boolToString", "ts"),
adamc@1057 243 ("str1", "id"),
adamc@821 244 ("strsub", "sub"),
adamc@828 245 ("strsuffix", "suf"),
adamc@829 246 ("strlen", "slen"),
adamc@829 247 ("strindex", "sidx"),
adamc@829 248 ("strchr", "schr"),
adamc@831 249 ("substring", "ssub"),
adamc@895 250 ("strcspn", "sspn"),
adamc@1061 251 ("kc", "kc"),
adam@1404 252 ("minTime", "0"),
adamc@1061 253
adamc@1061 254 ("islower", "isLower"),
adamc@1061 255 ("isupper", "isUpper"),
adamc@1061 256 ("isalpha", "isAlpha"),
adamc@1061 257 ("isdigit", "isDigit"),
adamc@1061 258 ("isalnum", "isAlnum"),
adamc@1061 259 ("isblank", "isBlank"),
adamc@1061 260 ("isspace", "isSpace"),
adamc@1061 261 ("isxdigit", "isXdigit"),
adamc@1061 262 ("tolower", "toLower"),
adamc@1323 263 ("toupper", "toUpper"),
adamc@1323 264
adamc@1323 265 ("checkUrl", "checkUrl"),
adam@1366 266 ("bless", "bless"),
adam@1366 267
adam@1366 268 ("eq_time", "eq"),
adam@1366 269 ("lt_time", "lt"),
adam@1430 270 ("le_time", "le"),
adam@1430 271
adam@1430 272 ("debug", "alert"),
adam@1487 273 ("naughtyDebug", "alert"),
adam@1487 274
adam@1571 275 ("floatFromInt", "float"),
adam@1571 276 ("ceil", "ceil"),
adam@1571 277 ("trunc", "trunc"),
adam@1571 278 ("round", "round"),
adam@1571 279
adam@1487 280 ("now", "now"),
adam@1487 281 ("timeToString", "showTime"),
adam@1514 282 ("htmlifyTime", "showTime"),
adam@1514 283 ("toSeconds", "toSeconds"),
adam@1518 284 ("addSeconds", "addSeconds"),
adam@1555 285 ("diffInSeconds", "diffInSeconds"),
adam@1555 286
adam@1555 287 ("onClick", "uw_onClick"),
adam@1555 288 ("onDblclick", "uw_onDblclick"),
adam@1555 289 ("onKeydown", "uw_onKeydown"),
adam@1555 290 ("onKeypress", "uw_onKeypress"),
adam@1555 291 ("onKeyup", "uw_onKeyup"),
adam@1555 292 ("onMousedown", "uw_onMousedown"),
adam@1556 293 ("onMouseup", "uw_onMouseup"),
adam@1559 294 ("preventDefault", "uw_preventDefault"),
adam@1559 295 ("stopPropagation", "uw_stopPropagation"),
adam@1556 296
adam@1556 297 ("fresh", "fresh")]
adamc@765 298 val jsFuncs = ref jsFuncsBase
adamc@765 299 fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls
adamc@765 300 fun jsFunc x = M.find (!jsFuncs, x)
adam@1433 301 fun allJsFuncs () = M.listItemsi (!jsFuncs)
adamc@765 302
adamc@768 303 datatype pattern_kind = Exact | Prefix
adamc@768 304 datatype action = Allow | Deny
adamc@768 305 type rule = { action : action, kind : pattern_kind, pattern : string }
adamc@768 306
adamc@768 307 datatype path_kind = Any | Url | Table | Sequence | View | Relation | Cookie | Style
adamc@768 308 type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string }
adamc@768 309
adamc@768 310 val rewrites = ref ([] : rewrite list)
adamc@768 311
adamc@768 312 fun subsume (pk1, pk2) =
adamc@768 313 pk1 = pk2
adamc@768 314 orelse pk2 = Any
adamc@768 315 orelse pk2 = Relation andalso (pk1 = Table orelse pk1 = Sequence orelse pk1 = View)
adamc@768 316
adamc@768 317 fun setRewriteRules ls = rewrites := ls
adamc@768 318 fun rewrite pk s =
adamc@768 319 let
adamc@768 320 fun rew (ls : rewrite list) =
adamc@768 321 case ls of
adamc@768 322 [] => s
adamc@768 323 | rewr :: ls =>
adamc@768 324 let
adamc@768 325 fun match () =
adamc@768 326 case #kind rewr of
adamc@768 327 Exact => if #from rewr = s then
adamc@768 328 SOME (size s)
adamc@768 329 else
adamc@768 330 NONE
adamc@768 331 | Prefix => if String.isPrefix (#from rewr) s then
adamc@768 332 SOME (size (#from rewr))
adamc@768 333 else
adamc@768 334 NONE
adamc@768 335 in
adamc@768 336 if subsume (pk, #pkind rewr) then
adamc@768 337 case match () of
adamc@768 338 NONE => rew ls
adamc@768 339 | SOME suffixStart => #to rewr ^ String.extract (s, suffixStart, NONE)
adamc@768 340 else
adamc@768 341 rew ls
adamc@768 342 end
adamc@768 343 in
adamc@768 344 rew (!rewrites)
adamc@768 345 end
adamc@768 346
adamc@769 347 val url = ref ([] : rule list)
adamc@769 348 val mime = ref ([] : rule list)
adam@1465 349 val request = ref ([] : rule list)
adam@1465 350 val response = ref ([] : rule list)
adamc@769 351
adamc@769 352 fun setUrlRules ls = url := ls
adamc@769 353 fun setMimeRules ls = mime := ls
adam@1465 354 fun setRequestHeaderRules ls = request := ls
adam@1465 355 fun setResponseHeaderRules ls = response := ls
adamc@769 356
adamc@770 357 fun getUrlRules () = !url
adamc@770 358 fun getMimeRules () = !mime
adam@1465 359 fun getRequestHeaderRules () = !request
adam@1465 360 fun getResponseHeaderRules () = !response
adamc@770 361
adamc@769 362 fun check f rules s =
adamc@769 363 let
adamc@769 364 fun chk (ls : rule list) =
adamc@769 365 case ls of
adamc@769 366 [] => false
adamc@769 367 | rule :: ls =>
adamc@769 368 let
adamc@769 369 val matches =
adamc@769 370 case #kind rule of
adamc@769 371 Exact => #pattern rule = s
adamc@769 372 | Prefix => String.isPrefix (#pattern rule) s
adamc@769 373 in
adamc@769 374 if matches then
adamc@769 375 case #action rule of
adamc@769 376 Allow => true
adamc@769 377 | Deny => false
adamc@769 378 else
adamc@769 379 chk ls
adamc@769 380 end
adamc@769 381 in
adamc@769 382 f s andalso chk (!rules)
adamc@769 383 end
adamc@769 384
adamc@769 385 val checkUrl = check (fn _ => true) url
adam@1465 386
adam@1465 387 val validMime = CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"/" orelse ch = #"-" orelse ch = #".")
adam@1465 388
adam@1465 389 val checkMime = check validMime mime
adam@1465 390 val checkRequestHeader = check validMime request
adam@1465 391 val checkResponseHeader = check validMime response
adamc@769 392
adamc@855 393
adamc@855 394 type protocol = {
adamc@855 395 name : string,
adamc@1096 396 compile : string,
adamc@1095 397 linkStatic : string,
adamc@1095 398 linkDynamic : string,
adamc@1164 399 persistent : bool,
adamc@1164 400 code : unit -> Print.PD.pp_desc
adamc@855 401 }
adamc@855 402 val protocols = ref ([] : protocol list)
adamc@855 403 fun addProtocol p = protocols := p :: !protocols
adamc@855 404 fun getProtocol s = List.find (fn p => #name p = s) (!protocols)
adamc@855 405
adamc@855 406 fun clibFile s = OS.Path.joinDirFile {dir = Config.libC,
adamc@855 407 file = s}
adamc@855 408
adamc@865 409 val curProto = ref {name = "",
adamc@1096 410 compile = "",
adamc@1095 411 linkStatic = "",
adamc@1095 412 linkDynamic = "",
adamc@1164 413 persistent = false,
adamc@1164 414 code = fn () => Print.box []}
adamc@856 415 fun setProtocol name =
adamc@856 416 case getProtocol name of
adamc@856 417 NONE => raise Fail ("Unknown protocol " ^ name)
adamc@856 418 | SOME p => curProto := p
adamc@855 419 fun currentProtocol () = !curProto
adamc@855 420
adamc@857 421 val debug = ref false
adamc@857 422 fun setDebug b = debug := b
adamc@857 423 fun getDebug () = !debug
adamc@857 424
adamc@867 425 datatype sql_type =
adamc@867 426 Int
adamc@867 427 | Float
adamc@867 428 | String
adamc@1011 429 | Char
adamc@867 430 | Bool
adamc@867 431 | Time
adamc@867 432 | Blob
adamc@867 433 | Channel
adamc@867 434 | Client
adamc@867 435 | Nullable of sql_type
adamc@867 436
adamc@873 437 fun p_sql_ctype t =
adamc@867 438 let
adamc@867 439 open Print.PD
adamc@867 440 open Print
adamc@867 441 in
adamc@867 442 case t of
adamc@870 443 Int => "uw_Basis_int"
adamc@870 444 | Float => "uw_Basis_float"
adamc@870 445 | String => "uw_Basis_string"
adamc@1011 446 | Char => "uw_Basis_char"
adamc@870 447 | Bool => "uw_Basis_bool"
adamc@870 448 | Time => "uw_Basis_time"
adamc@870 449 | Blob => "uw_Basis_blob"
adamc@870 450 | Channel => "uw_Basis_channel"
adamc@870 451 | Client => "uw_Basis_client"
adamc@870 452 | Nullable String => "uw_Basis_string"
adamc@873 453 | Nullable t => p_sql_ctype t ^ "*"
adamc@867 454 end
adamc@867 455
adamc@867 456 fun isBlob Blob = true
adamc@867 457 | isBlob (Nullable t) = isBlob t
adamc@867 458 | isBlob _ = false
adamc@867 459
adamc@870 460 fun isNotNull (Nullable _) = false
adamc@870 461 | isNotNull _ = true
adamc@870 462
adam@1293 463 datatype failure_mode = Error | None
adam@1293 464
adamc@866 465 type dbms = {
adamc@866 466 name : string,
adamc@866 467 header : string,
adamc@866 468 link : string,
adamc@873 469 p_sql_type : sql_type -> string,
adamc@870 470 init : {dbstring : string,
adamc@870 471 prepared : (string * int) list,
adamc@870 472 tables : (string * (string * sql_type) list) list,
adamc@872 473 views : (string * (string * sql_type) list) list,
adamc@870 474 sequences : string list} -> Print.PD.pp_desc,
adamc@873 475 query : {loc : ErrorMsg.span, cols : sql_type list,
adamc@880 476 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int, typ : sql_type} -> Print.PD.pp_desc)
adamc@867 477 -> Print.PD.pp_desc}
adamc@867 478 -> Print.PD.pp_desc,
adamc@867 479 queryPrepared : {loc : ErrorMsg.span, id : int, query : string,
adamc@873 480 inputs : sql_type list, cols : sql_type list,
adamc@880 481 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int,
adamc@880 482 typ : sql_type} -> Print.PD.pp_desc)
adamc@879 483 -> Print.PD.pp_desc,
adamc@879 484 nested : bool}
adamc@868 485 -> Print.PD.pp_desc,
adam@1293 486 dml : ErrorMsg.span * failure_mode -> Print.PD.pp_desc,
adamc@868 487 dmlPrepared : {loc : ErrorMsg.span, id : int, dml : string,
adam@1293 488 inputs : sql_type list, mode : failure_mode} -> Print.PD.pp_desc,
adamc@878 489 nextval : {loc : ErrorMsg.span, seqName : string option, seqE : Print.PD.pp_desc} -> Print.PD.pp_desc,
adamc@874 490 nextvalPrepared : {loc : ErrorMsg.span, id : int, query : string} -> Print.PD.pp_desc,
adamc@1073 491 setval : {loc : ErrorMsg.span, seqE : Print.PD.pp_desc, count : Print.PD.pp_desc} -> Print.PD.pp_desc,
adamc@874 492 sqlifyString : string -> string,
adamc@874 493 p_cast : string * sql_type -> string,
adamc@874 494 p_blank : int * sql_type -> string,
adamc@877 495 supportsDeleteAs : bool,
adamc@886 496 supportsUpdateAs : bool,
adamc@877 497 createSequence : string -> string,
adamc@878 498 textKeysNeedLengths : bool,
adamc@879 499 supportsNextval : bool,
adamc@882 500 supportsNestedPrepared : bool,
adamc@890 501 sqlPrefix : string,
adamc@1014 502 supportsOctetLength : bool,
adamc@1014 503 trueString : string,
adamc@1196 504 falseString : string,
adamc@1196 505 onlyUnion : bool,
adamc@1196 506 nestedRelops : bool
adamc@866 507 }
adamc@866 508
adamc@866 509 val dbmses = ref ([] : dbms list)
adamc@866 510 val curDb = ref ({name = "",
adamc@866 511 header = "",
adamc@866 512 link = "",
adamc@873 513 p_sql_type = fn _ => "",
adamc@867 514 init = fn _ => Print.box [],
adamc@867 515 query = fn _ => Print.box [],
adamc@868 516 queryPrepared = fn _ => Print.box [],
adamc@868 517 dml = fn _ => Print.box [],
adamc@869 518 dmlPrepared = fn _ => Print.box [],
adamc@869 519 nextval = fn _ => Print.box [],
adamc@874 520 nextvalPrepared = fn _ => Print.box [],
adamc@1073 521 setval = fn _ => Print.box [],
adamc@874 522 sqlifyString = fn s => s,
adamc@874 523 p_cast = fn _ => "",
adamc@874 524 p_blank = fn _ => "",
adamc@877 525 supportsDeleteAs = false,
adamc@886 526 supportsUpdateAs = false,
adamc@877 527 createSequence = fn _ => "",
adamc@878 528 textKeysNeedLengths = false,
adamc@879 529 supportsNextval = false,
adamc@882 530 supportsNestedPrepared = false,
adamc@890 531 sqlPrefix = "",
adamc@1014 532 supportsOctetLength = false,
adamc@1014 533 trueString = "",
adamc@1196 534 falseString = "",
adamc@1196 535 onlyUnion = false,
adamc@1196 536 nestedRelops = false} : dbms)
adamc@866 537
adamc@866 538 fun addDbms v = dbmses := v :: !dbmses
adamc@866 539 fun setDbms s =
adamc@866 540 case List.find (fn db => #name db = s) (!dbmses) of
adamc@866 541 NONE => raise Fail ("Unknown DBMS " ^ s)
adamc@866 542 | SOME db => curDb := db
adamc@866 543 fun currentDbms () = !curDb
adamc@866 544
adamc@891 545 val dbstring = ref (NONE : string option)
adamc@891 546 fun setDbstring so = dbstring := so
adamc@891 547 fun getDbstring () = !dbstring
adamc@891 548
adamc@891 549 val exe = ref (NONE : string option)
adamc@891 550 fun setExe so = exe := so
adamc@891 551 fun getExe () = !exe
adamc@891 552
adamc@891 553 val sql = ref (NONE : string option)
adamc@891 554 fun setSql so = sql := so
adamc@891 555 fun getSql () = !sql
adamc@891 556
adamc@1016 557 val coreInline = ref 20
adamc@1016 558 fun setCoreInline n = coreInline := n
adamc@1016 559 fun getCoreInline () = !coreInline
adamc@1016 560
adam@1351 561 val monoInline = ref 100
adamc@1016 562 fun setMonoInline n = monoInline := n
adamc@1016 563 fun getMonoInline () = !monoInline
adamc@1016 564
adamc@1095 565 val staticLinking = ref false
adamc@1095 566 fun setStaticLinking b = staticLinking := b
adamc@1095 567 fun getStaticLinking () = !staticLinking
adamc@1095 568
adamc@1114 569 val deadlines = ref false
adamc@1114 570 fun setDeadlines b = deadlines := b
adamc@1114 571 fun getDeadlines () = !deadlines
adamc@1114 572
adamc@1164 573 val sigFile = ref (NONE : string option)
adamc@1164 574 fun setSigFile v = sigFile := v
adamc@1164 575 fun getSigFile () = !sigFile
adamc@1164 576
adamc@1183 577 structure SS = BinarySetFn(struct
adamc@1183 578 type ord_key = string
adamc@1183 579 val compare = String.compare
adamc@1183 580 end)
adamc@1183 581
adamc@1183 582 val safeGet = ref SS.empty
adamc@1183 583 fun setSafeGets ls = safeGet := SS.addList (SS.empty, ls)
adamc@1183 584 fun isSafeGet x = SS.member (!safeGet, x)
adamc@1183 585
adam@1294 586 val onError = ref (NONE : (string * string list * string) option)
adam@1294 587 fun setOnError x = onError := x
adam@1294 588 fun getOnError () = !onError
adam@1294 589
adam@1307 590 val limits = ["messages", "clients", "headers", "page", "heap", "script",
adam@1307 591 "inputs", "subinputs", "cleanup", "deltas", "transactionals",
adam@1308 592 "globals", "database", "time"]
adam@1307 593
adam@1307 594 val limitsList = ref ([] : (string * int) list)
adam@1307 595 fun addLimit (v as (name, _)) =
adam@1307 596 if List.exists (fn name' => name' = name) limits then
adam@1308 597 (limitsList := v :: !limitsList;
adam@1308 598 if name = "time" then
adam@1308 599 setDeadlines true
adam@1308 600 else
adam@1308 601 ())
adam@1307 602 else
adam@1307 603 raise Fail ("Unknown limit category '" ^ name ^ "'")
adam@1307 604 fun limits () = !limitsList
adam@1307 605
adam@1332 606 val minHeap = ref 0
adam@1332 607 fun setMinHeap n = if n >= 0 then minHeap := n else raise Fail "Trying to set negative minHeap"
adam@1332 608 fun getMinHeap () = !minHeap
adam@1332 609
adam@1393 610 structure SS = BinarySetFn(struct
adam@1393 611 type ord_key = string
adam@1393 612 val compare = String.compare
adam@1393 613 end)
adam@1393 614
adam@1393 615 val alwaysInline = ref SS.empty
adam@1393 616 fun addAlwaysInline s = alwaysInline := SS.add (!alwaysInline, s)
adam@1393 617 fun checkAlwaysInline s = SS.member (!alwaysInline, s)
adam@1393 618
adam@1478 619 val noXsrfProtection = ref SS.empty
adam@1478 620 fun addNoXsrfProtection s = noXsrfProtection := SS.add (!noXsrfProtection, s)
adam@1478 621 fun checkNoXsrfProtection s = SS.member (!noXsrfProtection, s)
adam@1478 622
adamc@765 623 end