[nio-cvs] r58 - in branches/home/psmith/restructure: . src/io

psmith at common-lisp.net psmith at common-lisp.net
Mon Jan 29 05:55:47 UTC 2007


Author: psmith
Date: Mon Jan 29 00:55:46 2007
New Revision: 58

Added:
   branches/home/psmith/restructure/ips.txt
   branches/home/psmith/restructure/src/io/ip-authorisation.lisp
Modified:
   branches/home/psmith/restructure/run-yarpc.lisp
   branches/home/psmith/restructure/src/io/async-fd.lisp
   branches/home/psmith/restructure/src/io/nio-package.lisp
   branches/home/psmith/restructure/src/io/nio-server.lisp
   branches/home/psmith/restructure/src/io/nio.asd
Log:
Added ip authorisation

Added: branches/home/psmith/restructure/ips.txt
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/ips.txt	Mon Jan 29 00:55:46 2007
@@ -0,0 +1 @@
+("192.168.1.1" "127.0.0.1")

Modified: branches/home/psmith/restructure/run-yarpc.lisp
==============================================================================
--- branches/home/psmith/restructure/run-yarpc.lisp	(original)
+++ branches/home/psmith/restructure/run-yarpc.lisp	Mon Jan 29 00:55:46 2007
@@ -5,7 +5,8 @@
 (require :nio-yarpc)
 
 (setf nio-yarpc:+process-jobs-inline+ nil)
-(sb-thread:make-thread #'(lambda()(nio:start-server 'identity 'identity 'nio-yarpc:yarpc-state-machine :host "127.0.0.1")) :name "nio-server")
+(nio:load-ips "ips.txt")
+(sb-thread:make-thread #'(lambda()(nio:start-server 'identity 'identity 'nio-yarpc:yarpc-state-machine :host "127.0.0.1" :accept-connection 'nio:check-ip)) :name "nio-server")
 (loop
     ;;block waiting for jobs
      (nio-yarpc:run-job))

Modified: branches/home/psmith/restructure/src/io/async-fd.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/async-fd.lisp	(original)
+++ branches/home/psmith/restructure/src/io/async-fd.lisp	Mon Jan 29 00:55:46 2007
@@ -101,9 +101,11 @@
 
 (defun close-async-fd (async-fd)
   "Close ASYNC-FD's fd after everything has been written from write-queue."
+#+nio-debug    (format t "close-async-fd called with :async-fd ~A~%" async-fd)
   (with-slots (read-fd write-fd foreign-read-buffer foreign-write-buffer) async-fd
+    (nio-buffer:flip foreign-write-buffer)
+#+nio-debug    (format t "close-async-fd foreign-write-buffer ~A~%" foreign-write-buffer)
     (assert (eql (remaining foreign-write-buffer) 0))
-#+nio-debug    (format t "close-async-fd called with :read-fd ~A :write-fd ~A~%" read-fd write-fd)
       ;; if write-queue is emtpy, close now
        (close-fd read-fd)
        (free-buffer foreign-read-buffer)

Added: branches/home/psmith/restructure/src/io/ip-authorisation.lisp
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/src/io/ip-authorisation.lisp	Mon Jan 29 00:55:46 2007
@@ -0,0 +1,41 @@
+#|
+Copyright (c) 2007
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+|#
+(in-package :nio)
+
+(declaim (optimize (debug 3) (speed 3) (space 0)))
+
+(defparameter +ip-list+ nil)
+
+(defun load-ips (filename)
+  (with-open-file (stream filename)
+    (setf +ip-list+ (read stream))))
+
+(defun check-ip (async-fd)
+  (with-slots (remote-host) (socket async-fd)
+    (let ((str-rep (format nil "~{~a~^.~}" (reverse remote-host))))
+      (format t "ip-authorisation:check-ip ~A ~A~%" str-rep +ip-list+)
+      (member str-rep +ip-list+ :test 'string-equal))))
\ No newline at end of file

Modified: branches/home/psmith/restructure/src/io/nio-package.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/nio-package.lisp	(original)
+++ branches/home/psmith/restructure/src/io/nio-package.lisp	Mon Jan 29 00:55:46 2007
@@ -39,4 +39,7 @@
 	     
 	     ;;packet
 	     packet write-bytes
+
+	     ;;ip-authorisation
+	     check-ip load-ips
 	     ))

Modified: branches/home/psmith/restructure/src/io/nio-server.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/nio-server.lisp	(original)
+++ branches/home/psmith/restructure/src/io/nio-server.lisp	Mon Jan 29 00:55:46 2007
@@ -106,8 +106,8 @@
 			  (format t "Accept failed.~%"))
 
 			 ;; accept connection ?
-			 ((set-fd-nonblocking (async-fd-read-fd async-fd))
-			  (funcall accept-connection async-fd)
+			 ((funcall accept-connection async-fd)
+			  (set-fd-nonblocking (async-fd-read-fd async-fd))
 			  (setf (gethash (async-fd-read-fd async-fd) client-hash) async-fd)
 			  (add-async-fd event-queue async-fd :read-write)
 ;			  (add-async-fd event-queue async-fd :write)

Modified: branches/home/psmith/restructure/src/io/nio.asd
==============================================================================
--- branches/home/psmith/restructure/src/io/nio.asd	(original)
+++ branches/home/psmith/restructure/src/io/nio.asd	Mon Jan 29 00:55:46 2007
@@ -10,6 +10,7 @@
 		 (:file "async-fd" :depends-on ("fd-helper"))
 		 (:file "async-socket" :depends-on ("async-fd"))
 		 (:file "nio-server" :depends-on ("async-socket"))
+		 (:file "ip-authorisation" :depends-on ("nio-package"))
 		 )
 
     :depends-on (:cffi :event-notification :nio-buffer :nio-compat :nio-utils))



More information about the Nio-cvs mailing list