comparison src/cjr_print.sml @ 770:c125df6fabfc

Runtime URL and MIME type filtering
author Adam Chlipala <adamc@hcoop.net>
date Sat, 02 May 2009 18:20:15 -0400
parents df09c95085f8
children 7394368a5cad
comparison
equal deleted inserted replaced
769:efceae06df17 770:c125df6fabfc
3174 | SOME acc => box [string ("uw_Basis_strcat(ctx, uw_unnull(uw_Basis_get_cookie(ctx, \"" 3174 | SOME acc => box [string ("uw_Basis_strcat(ctx, uw_unnull(uw_Basis_get_cookie(ctx, \""
3175 ^ cookie ^ "\")), uw_Basis_strcat(ctx, \"/\", "), 3175 ^ cookie ^ "\")), uw_Basis_strcat(ctx, \"/\", "),
3176 acc, 3176 acc,
3177 string "))"])) 3177 string "))"]))
3178 NONE cookies 3178 NONE cookies
3179
3180 fun makeChecker (name, rules : Settings.rule list) =
3181 box [string "int ",
3182 string name,
3183 string "(const char *s) {",
3184 newline,
3185 box [p_list_sep (box [])
3186 (fn rule =>
3187 box [string "if (!str",
3188 case #kind rule of
3189 Settings.Exact => box [string "cmp(s, \"",
3190 string (String.toString (#pattern rule)),
3191 string "\"))"]
3192 | Settings.Prefix => box [string "ncmp(s, \"",
3193 string (String.toString (#pattern rule)),
3194 string "\", ",
3195 string (Int.toString (size (#pattern rule))),
3196 string "))"],
3197 string " return ",
3198 string (case #action rule of
3199 Settings.Allow => "1"
3200 | Settings.Deny => "0"),
3201 string ";",
3202 newline]) rules,
3203 string "return 0;",
3204 newline],
3205 string "}",
3206 newline]
3179 in 3207 in
3180 box [string "#include <stdio.h>", 3208 box [string "#include <stdio.h>",
3181 newline, 3209 newline,
3182 string "#include <stdlib.h>", 3210 string "#include <stdlib.h>",
3183 newline, 3211 newline,
3215 string "int uw_input_num(char *name) {", 3243 string "int uw_input_num(char *name) {",
3216 newline, 3244 newline,
3217 makeSwitch (fnums, 0), 3245 makeSwitch (fnums, 0),
3218 string "}", 3246 string "}",
3219 newline, 3247 newline,
3248 newline,
3249
3250 makeChecker ("uw_check_url", Settings.getUrlRules ()),
3251 newline,
3252
3253 makeChecker ("uw_check_mime", Settings.getMimeRules ()),
3220 newline, 3254 newline,
3221 3255
3222 string "extern void uw_sign(const char *in, char *out);", 3256 string "extern void uw_sign(const char *in, char *out);",
3223 newline, 3257 newline,
3224 string "extern int uw_hash_blocksize;", 3258 string "extern int uw_hash_blocksize;",