whohas
[hcoop/domtool2.git] / src / main.sml
index 03d5877..9f06c5b 100644 (file)
@@ -223,6 +223,24 @@ fun requestListPerms user =
        before OpenSSL.close bio
     end
 
        before OpenSSL.close bio
     end
 
+fun requestWhoHas perm =
+    let
+       val (_, bio) = requestBio (fn () => ())
+    in
+       Msg.send (bio, MsgWhoHas perm);
+       (case Msg.recv bio of
+            NONE => (print "Server closed connection unexpectedly.\n";
+                     NONE)
+          | SOME m =>
+            case m of
+                MsgWhoHasResponse users => SOME users
+              | MsgError s => (print ("whohas failed: " ^ s ^ "\n");
+                               NONE)
+              | _ => (print "Unexpected server reply.\n";
+                      NONE))
+       before OpenSSL.close bio
+    end
+
 fun service () =
     let
        val () = Acl.read Config.aclFile
 fun service () =
     let
        val () = Acl.read Config.aclFile
@@ -342,6 +360,20 @@ fun service () =
                                handle OpenSSL.OpenSSL _ => ();
                                loop ())
 
                                handle OpenSSL.OpenSSL _ => ();
                                loop ())
 
+                             | MsgWhoHas perm =>
+                               ((Msg.send (bio, MsgWhoHasResponse (Acl.whoHas perm));
+                                 print ("Sent whohas response for " ^ #class perm ^ " / " ^ #value perm ^ ".\n"))
+                                handle OpenSSL.OpenSSL s =>
+                                       (print "OpenSSL error\n";
+                                        Msg.send (bio,
+                                                  MsgError
+                                                      ("Error during whohas: "
+                                                       ^ s)));
+                               (ignore (OpenSSL.readChar bio);
+                                OpenSSL.close bio)
+                               handle OpenSSL.OpenSSL _ => ();
+                               loop ())
+
                              | _ =>
                                (Msg.send (bio, MsgError "Unexpected command")
                                 handle OpenSSL.OpenSSL _ => ();
                              | _ =>
                                (Msg.send (bio, MsgError "Unexpected command")
                                 handle OpenSSL.OpenSSL _ => ();