annotate src/settings.sml @ 765:a28982de5645

Successfully influenced effectful-ness status of FFI func
author Adam Chlipala <adamc@hcoop.net>
date Sat, 02 May 2009 11:27:26 -0400
parents 7f653298dd66
children df09c95085f8
rev   line source
adamc@764 1 (* Copyright (c) 2008-2009, 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
adamc@764 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 "/"
adamc@764 31 val timeout = ref 0
adamc@764 32 val headers = ref ([] : string list)
adamc@764 33
adamc@764 34 fun getUrlPrefix () = !urlPrefix
adamc@764 35 fun setUrlPrefix p =
adamc@764 36 urlPrefix := (if p = "" then
adamc@764 37 "/"
adamc@764 38 else if String.sub (p, size p - 1) <> #"/" then
adamc@764 39 p ^ "/"
adamc@764 40 else
adamc@764 41 p)
adamc@764 42
adamc@764 43 fun getTimeout () = !timeout
adamc@764 44 fun setTimeout n = timeout := n
adamc@764 45
adamc@764 46 fun getHeaders () = !headers
adamc@764 47 fun setHeaders ls = headers := ls
adamc@764 48
adamc@765 49 type ffi = string * string
adamc@765 50
adamc@765 51 structure K = struct
adamc@765 52 type ord_key = ffi
adamc@765 53 fun compare ((m1, x1), (m2, x2)) =
adamc@765 54 Order.join (String.compare (m1, m2),
adamc@765 55 fn () => String.compare (x1, x2))
adamc@764 56 end
adamc@765 57
adamc@765 58 structure S = BinarySetFn(K)
adamc@765 59 structure M = BinaryMapFn(K)
adamc@765 60
adamc@765 61 fun basis x = S.addList (S.empty, map (fn x : string => ("Basis", x)) x)
adamc@765 62
adamc@765 63 val clientToServerBase = basis ["int",
adamc@765 64 "float",
adamc@765 65 "string",
adamc@765 66 "time",
adamc@765 67 "file",
adamc@765 68 "unit",
adamc@765 69 "option",
adamc@765 70 "list",
adamc@765 71 "bool"]
adamc@765 72 val clientToServer = ref clientToServerBase
adamc@765 73 fun setClientToServer ls = clientToServer := S.addList (clientToServerBase, ls)
adamc@765 74 fun mayClientToServer x = S.member (!clientToServer, x)
adamc@765 75
adamc@765 76 val effectfulBase = basis ["set_cookie",
adamc@765 77 "new_client_source",
adamc@765 78 "get_client_source",
adamc@765 79 "set_client_source",
adamc@765 80 "alert",
adamc@765 81 "new_channel",
adamc@765 82 "send",
adamc@765 83 "onError",
adamc@765 84 "onFail",
adamc@765 85 "onConnectFail",
adamc@765 86 "onDisconnect",
adamc@765 87 "onServerError"]
adamc@765 88
adamc@765 89 val effectful = ref effectfulBase
adamc@765 90 fun setEffectful ls = effectful := S.addList (effectfulBase, ls)
adamc@765 91 fun isEffectful x = S.member (!effectful, x)
adamc@765 92
adamc@765 93 val clientBase = basis ["get",
adamc@765 94 "set",
adamc@765 95 "alert",
adamc@765 96 "recv",
adamc@765 97 "sleep",
adamc@765 98 "spawn",
adamc@765 99 "onError",
adamc@765 100 "onFail",
adamc@765 101 "onConnectFail",
adamc@765 102 "onDisconnect",
adamc@765 103 "onServerError"]
adamc@765 104 val client = ref clientBase
adamc@765 105 fun setClientOnly ls = client := S.addList (clientBase, ls)
adamc@765 106 fun isClientOnly x = S.member (!client, x)
adamc@765 107
adamc@765 108 val serverBase = basis ["requestHeader",
adamc@765 109 "query",
adamc@765 110 "dml",
adamc@765 111 "nextval",
adamc@765 112 "channel",
adamc@765 113 "send"]
adamc@765 114 val server = ref serverBase
adamc@765 115 fun setServerOnly ls = server := S.addList (serverBase, ls)
adamc@765 116 fun isServerOnly x = S.member (!server, x)
adamc@765 117
adamc@765 118 val basisM = foldl (fn ((k, v : string), m) => M.insert (m, ("Basis", k), v)) M.empty
adamc@765 119
adamc@765 120 val jsFuncsBase = basisM [("alert", "alert"),
adamc@765 121 ("get_client_source", "sg"),
adamc@765 122 ("htmlifyBool", "bs"),
adamc@765 123 ("htmlifyFloat", "ts"),
adamc@765 124 ("htmlifyInt", "ts"),
adamc@765 125 ("htmlifyString", "eh"),
adamc@765 126 ("new_client_source", "sc"),
adamc@765 127 ("set_client_source", "sv"),
adamc@765 128 ("stringToFloat_error", "pfl"),
adamc@765 129 ("stringToInt_error", "pi"),
adamc@765 130 ("urlifyInt", "ts"),
adamc@765 131 ("urlifyFloat", "ts"),
adamc@765 132 ("urlifyString", "uf"),
adamc@765 133 ("recv", "rv"),
adamc@765 134 ("strcat", "cat"),
adamc@765 135 ("intToString", "ts"),
adamc@765 136 ("floatToString", "ts"),
adamc@765 137 ("onError", "onError"),
adamc@765 138 ("onFail", "onFail"),
adamc@765 139 ("onConnectFail", "onConnectFail"),
adamc@765 140 ("onDisconnect", "onDisconnect"),
adamc@765 141 ("onServerError", "onServerError")]
adamc@765 142 val jsFuncs = ref jsFuncsBase
adamc@765 143 fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls
adamc@765 144 fun jsFunc x = M.find (!jsFuncs, x)
adamc@765 145
adamc@765 146 end