Version 0.5.
authorrjones <rjones>
Fri, 29 Jun 2007 19:39:13 +0000 (19:39 +0000)
committerrjones <rjones>
Fri, 29 Jun 2007 19:39:13 +0000 (19:39 +0000)
Makefile.config
init
init.in
ocamlbotwrapper.c
xavierbot.pl
xavierbot.pl.in

index 084ac63..63671fe 100644 (file)
@@ -1,8 +1,8 @@
 # -*- Makefile -*-
-# $Id: Makefile.config,v 1.6 2007/06/29 13:15:00 rjones Exp $
+# $Id: Makefile.config,v 1.7 2007/06/29 19:39:13 rjones Exp $
 
 PACKAGE := xavierbot
-VERSION := 0.4
+VERSION := 0.5
 
 # Prefix for installation.
 # - Binaries are installed in $(PREFIX)/sbin
diff --git a/init b/init
index fc64bb1..52dc690 100644 (file)
--- a/init
+++ b/init
@@ -1,5 +1,5 @@
 (* Initialise the toplevel environment. -*- tuareg -*-
- * $Id: init,v 1.5 2007/06/29 13:15:02 rjones Exp $
+ * $Id: init,v 1.6 2007/06/29 19:39:13 rjones Exp $
  * - Removes the Pervasives module and any dangerous functions.
  * - Loads just the modules we want to give access to, and just
  *   the functions within those modules that we want to give.
@@ -11,6 +11,7 @@
 (* Load some libraries. *)
 #load "nums.cma";;
 #load "unix.cma";;
+#load "str.cma";;
 
 (* Remove the Pervasives module. *)
 module Pervasives = struct end;;
@@ -64,6 +65,7 @@ let _ = Nativeint.to_string
 let _ = Num.add_num
 let _ = Ratio.null_denominator
 let _ = Stack.create
+let _ = Str.regexp
 
 (* Allow only safe functions from String. *)
 module String : sig
@@ -149,6 +151,43 @@ module Array : sig
   val fast_sort : ('a -> 'a -> int) -> 'a array -> unit
 end = struct include Array end
 
+(* Allow only safe functions from Printf. *)
+module Printf : sig
+  val printf : ('a, out_channel, unit) format -> 'a
+  val sprintf : ('a, unit, string) format -> 'a
+end = struct include Printf end
+
+(* Allow only safe functions from Scanf. *)
+module Scanf : sig
+  module Scanning : sig
+    type scanbuf;;
+    val stdib : scanbuf;;
+    val from_string : string -> scanbuf;;
+    val from_function : (unit -> char) -> scanbuf;;
+    val end_of_input : scanbuf -> bool;;
+    val beginning_of_input : scanbuf -> bool;;
+    val name_of_input : scanbuf -> string;;
+  end;;
+  exception Scan_failure of string;;
+  type ('a, 'b, 'c, 'd) scanner =
+       ('a, Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c;;
+  val bscanf : Scanning.scanbuf -> ('a, 'b, 'c, 'd) scanner;;
+  val sscanf : string -> ('a, 'b, 'c, 'd) scanner;;
+  val scanf : ('a, 'b, 'c, 'd) scanner;;
+  val kscanf :
+    Scanning.scanbuf -> (Scanning.scanbuf -> exn -> 'd) ->
+      ('a, 'b, 'c, 'd) scanner;;
+  val bscanf_format :
+    Scanning.scanbuf -> ('a, 'b, 'c, 'd, 'e, 'f) format6 ->
+      (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;;
+  val sscanf_format :
+    string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 ->
+      (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;;
+  val format_from_string :
+    string ->
+      ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ('a, 'b, 'c, 'd, 'e, 'f) format6;;
+end = struct include Scanf end
+
 (* Set and Map. *)
 module StringSet = Set.Make(String)
 module StringMap = Map.Make(String)
diff --git a/init.in b/init.in
index b4168cb..bc41e72 100644 (file)
--- a/init.in
+++ b/init.in
@@ -1,5 +1,5 @@
 (* Initialise the toplevel environment. -*- tuareg -*-
- * $Id: init.in,v 1.3 2007/06/29 13:15:02 rjones Exp $
+ * $Id: init.in,v 1.4 2007/06/29 19:39:13 rjones Exp $
  * - Removes the Pervasives module and any dangerous functions.
  * - Loads just the modules we want to give access to, and just
  *   the functions within those modules that we want to give.
@@ -11,6 +11,7 @@
 (* Load some libraries. *)
 #load "nums.cma";;
 #load "unix.cma";;
+#load "str.cma";;
 
 (* Remove the Pervasives module. *)
 module Pervasives = struct end;;
@@ -64,6 +65,7 @@ let _ = Nativeint.to_string
 let _ = Num.add_num
 let _ = Ratio.null_denominator
 let _ = Stack.create
+let _ = Str.regexp
 
 (* Allow only safe functions from String. *)
 module String : sig
@@ -149,6 +151,43 @@ module Array : sig
   val fast_sort : ('a -> 'a -> int) -> 'a array -> unit
 end = struct include Array end
 
+(* Allow only safe functions from Printf. *)
+module Printf : sig
+  val printf : ('a, out_channel, unit) format -> 'a
+  val sprintf : ('a, unit, string) format -> 'a
+end = struct include Printf end
+
+(* Allow only safe functions from Scanf. *)
+module Scanf : sig
+  module Scanning : sig
+    type scanbuf;;
+    val stdib : scanbuf;;
+    val from_string : string -> scanbuf;;
+    val from_function : (unit -> char) -> scanbuf;;
+    val end_of_input : scanbuf -> bool;;
+    val beginning_of_input : scanbuf -> bool;;
+    val name_of_input : scanbuf -> string;;
+  end;;
+  exception Scan_failure of string;;
+  type ('a, 'b, 'c, 'd) scanner =
+       ('a, Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c;;
+  val bscanf : Scanning.scanbuf -> ('a, 'b, 'c, 'd) scanner;;
+  val sscanf : string -> ('a, 'b, 'c, 'd) scanner;;
+  val scanf : ('a, 'b, 'c, 'd) scanner;;
+  val kscanf :
+    Scanning.scanbuf -> (Scanning.scanbuf -> exn -> 'd) ->
+      ('a, 'b, 'c, 'd) scanner;;
+  val bscanf_format :
+    Scanning.scanbuf -> ('a, 'b, 'c, 'd, 'e, 'f) format6 ->
+      (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;;
+  val sscanf_format :
+    string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 ->
+      (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;;
+  val format_from_string :
+    string ->
+      ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ('a, 'b, 'c, 'd, 'e, 'f) format6;;
+end = struct include Scanf end
+
 (* Set and Map. *)
 module StringSet = Set.Make(String)
 module StringMap = Map.Make(String)
index c852850..460bbc2 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- C -*-
- * $Id: ocamlbotwrapper.c,v 1.4 2007/06/29 07:55:47 rjones Exp $
+ * $Id: ocamlbotwrapper.c,v 1.5 2007/06/29 19:39:13 rjones Exp $
  * SUID wrapper around ocaml program.
  */
 
index bfdd9bf..4650f0d 100755 (executable)
@@ -2,7 +2,7 @@
 # xavierbot : an OCaml interpreter IRC bot.
 # By Richard W.M. Jones <rich@annexia.org>.
 # This code is in the Public Domain.
-# $Id: xavierbot.pl,v 1.7 2007/06/29 07:55:47 rjones Exp $
+# $Id: xavierbot.pl,v 1.8 2007/06/29 19:39:13 rjones Exp $
 
 use strict;
 use POE qw(Component::IRC Wheel::Run);
@@ -22,6 +22,11 @@ my $channel = "#ocaml";
 
 $ENV{PATH} = "/usr/bin:/bin";
 
+# Simple flood protection.  This counts number of lines received from
+# the toplevel, and is reset when we send a line.  If this exceeds
+# some value, then we just eat lines.
+my $flood_lim = 0;
+
 POE::Session->create (
   package_states => [
     main => [ qw(_default _start irc_001 irc_public got_stdout got_sigchld) ],
@@ -78,11 +83,14 @@ sub irc_public
     print "got: $what\n";
     if (my ($stmt) = $what =~ /^\s*([^#].*;;)\s*$/) {
        $heap->{ocaml}->put ("$stmt\n");
+        $flood_lim = 0;
     }
     # XXX How to interpolate $nick into the patterns?
     elsif ($what =~ /^\s*xavierbot\b.*\bhelp\b/) {
        my $nick = (split /!/, $who)[0];
        $kernel->post ($sender => privmsg => $channel =>
+                      "hello $nick, I am xavierbot, an OCaml toplevel");
+       $kernel->post ($sender => privmsg => $channel =>
                       "$nick: expr ;;      evaluate expr in OCaml toplevel");
        $kernel->post ($sender => privmsg => $channel =>
                       "$nick: help         help message");
@@ -120,7 +128,10 @@ sub got_stdout
 {
     my ($kernel,$heap, $input, $wheel_id) = @_[KERNEL,HEAP,ARG0,ARG1];
     print "Child said: $input\n";
-    $kernel->post ($heap->{irc} => privmsg => $channel => "$input");
+    if ($flood_lim < 16) {
+       $kernel->post ($heap->{irc} => privmsg => $channel => "$input");
+    }
+    $flood_lim++;
 }
 
 # Got a SIGCHLD, so start the bot up again.
index caaf0f5..fa59d84 100755 (executable)
@@ -2,7 +2,7 @@
 # xavierbot : an OCaml interpreter IRC bot.
 # By Richard W.M. Jones <rich@annexia.org>.
 # This code is in the Public Domain.
-# $Id: xavierbot.pl.in,v 1.4 2007/06/29 07:40:15 rjones Exp $
+# $Id: xavierbot.pl.in,v 1.5 2007/06/29 19:39:13 rjones Exp $
 
 use strict;
 use POE qw(Component::IRC Wheel::Run);
@@ -22,6 +22,11 @@ my $channel = "#ocaml";
 
 $ENV{PATH} = "/usr/bin:/bin";
 
+# Simple flood protection.  This counts number of lines received from
+# the toplevel, and is reset when we send a line.  If this exceeds
+# some value, then we just eat lines.
+my $flood_lim = 0;
+
 POE::Session->create (
   package_states => [
     main => [ qw(_default _start irc_001 irc_public got_stdout got_sigchld) ],
@@ -78,11 +83,14 @@ sub irc_public
     print "got: $what\n";
     if (my ($stmt) = $what =~ /^\s*([^#].*;;)\s*$/) {
        $heap->{ocaml}->put ("$stmt\n");
+        $flood_lim = 0;
     }
     # XXX How to interpolate $nick into the patterns?
     elsif ($what =~ /^\s*xavierbot\b.*\bhelp\b/) {
        my $nick = (split /!/, $who)[0];
        $kernel->post ($sender => privmsg => $channel =>
+                      "hello $nick, I am xavierbot, an OCaml toplevel");
+       $kernel->post ($sender => privmsg => $channel =>
                       "$nick: expr ;;      evaluate expr in OCaml toplevel");
        $kernel->post ($sender => privmsg => $channel =>
                       "$nick: help         help message");
@@ -120,7 +128,10 @@ sub got_stdout
 {
     my ($kernel,$heap, $input, $wheel_id) = @_[KERNEL,HEAP,ARG0,ARG1];
     print "Child said: $input\n";
-    $kernel->post ($heap->{irc} => privmsg => $channel => "$input");
+    if ($flood_lim < 16) {
+       $kernel->post ($heap->{irc} => privmsg => $channel => "$input");
+    }
+    $flood_lim++;
 }
 
 # Got a SIGCHLD, so start the bot up again.