Location and Directory
[hcoop/domtool2.git] / src / plugins / apache.sml
index faa2c65..878204b 100644 (file)
@@ -24,12 +24,41 @@ open Ast
 
 val _ = Env.type_one "proxy_port"
        Env.int
-       (fn n => n >= 1024)
+       (fn n => n > 1024)
+
+val _ = Env.type_one "proxy_target"
+       Env.string
+       (fn s =>
+           let
+               fun default () = List.exists (fn s' => s = s') Config.Apache.proxyTargets
+           in
+               case String.fields (fn ch => ch = #":") s of
+                   ["http", "//localhost", rest] =>
+                   (case String.fields (fn ch => ch = #"/") rest of
+                        port :: _ =>
+                        (case Int.fromString port of
+                             NONE => default ()
+                           | SOME n => n > 1024 orelse default ())
+                      | _ => default ())
+                 | _ => default ()
+           end)
 
 val _ = Env.type_one "rewrite_arg"
        Env.string
        (CharVector.all Char.isAlphaNum)
 
+fun validLocation s =
+    size s > 0 andalso size s < 1000 andalso CharVector.all
+                                                (fn ch => Char.isAlphaNum ch
+                                                          orelse ch = #"-"
+                                                          orelse ch = #"_"
+                                                          orelse ch = #"."
+                                                          orelse ch = #"/") s
+
+val _ = Env.type_one "location"
+       Env.string
+       validLocation
+
 val dl = ErrorMsg.dummyLoc
 
 val _ = Main.registerDefault ("WebNodes",
@@ -93,6 +122,10 @@ val flag = fn (EVar "redirect", _) => SOME "R"
 
            | _ => NONE
 
+val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC"
+           | (EVar "ornext", _) => SOME "OR"
+           | _ => NONE
+
 
 val vhostsChanged = ref false
 
@@ -183,6 +216,22 @@ val () = Env.containerV_one "vhost"
          fn () => (write "</VirtualHost>\n";
                    app TextIO.closeOut (!vhostFiles)))
 
+val () = Env.container_one "location"
+        ("prefix", Env.string)
+        (fn prefix =>
+            (write "\t<Location ";
+             write prefix;
+             write ">\n"),
+         fn () => write "\t</Location>\n")
+
+val () = Env.container_one "directory"
+        ("directory", Env.string)
+        (fn directory =>
+            (write "\t<Directory ";
+             write directory;
+             write ">\n"),
+         fn () => write "\t</Directory>\n")
+
 fun checkRewrite () =
     if !rewriteEnabled then
        ()
@@ -202,45 +251,23 @@ val () = Env.action_three "localProxyRewrite"
              write to;
              write " [P]\n"))
 
-val () = Env.action_three "localProxyPass"
-        ("from", Env.string, "to", Env.string, "port", Env.int)
-        (fn (from, to, port) =>
-            let
-                val to =
-                    case to of
-                        "" => "/"
-                      | _ => if String.sub (to, 0) = #"/" then
-                                 to
-                             else
-                                 "/" ^ to
-            in
-                write "\tProxyPass\t";
-                write from;
-                write "\thttp://localhost:";
-                write (Int.toString port);
-                write to;
-                write "\n"
-            end)
-
-val () = Env.action_three "localProxyPassReverse"
-        ("from", Env.string, "to", Env.string, "port", Env.int)
-        (fn (from, to, port) =>
-            let
-                val to =
-                    case to of
-                        "" => "/"
-                      | _ => if String.sub (to, 0) = #"/" then
-                                 to
-                             else
-                                 "/" ^ to
-            in
-                write "\tProxyPassReverse\t";
-                write from;
-                write "\thttp://localhost:";
-                write (Int.toString port);
-                write to;
-                write "\n"
-            end)
+val () = Env.action_two "proxyPass"
+        ("from", Env.string, "to", Env.string)
+        (fn (from, to) =>
+                (write "\tProxyPass\t";
+                 write from;
+                 write "\t";
+                 write to;
+                 write "\n"))
+
+val () = Env.action_two "proxyPassReverse"
+        ("from", Env.string, "to", Env.string)
+        (fn (from, to) =>
+                (write "\tProxyPassReverse\t";
+                 write from;
+                 write "\t";
+                 write to;
+                 write "\n"))
 
 val () = Env.action_three "rewriteRule"
         ("from", Env.string, "to", Env.string, "flags", Env.list flag)
@@ -259,4 +286,21 @@ val () = Env.action_three "rewriteRule"
                                 write "]");
              write "\n"))
 
+val () = Env.action_three "rewriteCond"
+        ("test", Env.string, "pattern", Env.string, "flags", Env.list cond_flag)
+        (fn (from, to, flags) =>
+            (checkRewrite ();
+             write "\tRewriteCond\t";
+             write from;
+             write "\t";
+             write to;
+             case flags of
+                 [] => ()
+               | flag::rest => (write " [";
+                                write flag;
+                                app (fn flag => (write ",";
+                                                 write flag)) rest;
+                                write "]");
+             write "\n"))
+
 end