Author: iratqq
Date: Thu Feb  5 10:17:51 2009
New Revision: 5822

Added:
   trunk/scm/posix.scm
Modified:
   trunk/scm/Makefile.am
   trunk/scm/http-client.scm
   trunk/scm/socket.scm

Log:
* scm/http-client.scm (http:get):
  - Rename *-socket-* to *-file-*.
* scm/Makefile.am (SCM_FILES):
  - Add posix.scm.
* scm/socket.scm:
  - Move file handling functions to posix.scm
* scm/posix.scm:
  - New file.


Modified: trunk/scm/Makefile.am
==============================================================================
--- trunk/scm/Makefile.am       (original)
+++ trunk/scm/Makefile.am       Thu Feb  5 10:17:51 2009
@@ -43,7 +43,7 @@
  ajax-ime.scm ajax-ime-custom.scm ajax-ime-key-custom.scm \
  yahoo-jp.scm yahoo-jp-custom.scm yahoo-jp-key-custom.scm \
  uim-module-manager.scm \
- socket.scm http-client.scm \
+ posix.scm socket.scm http-client.scm \
  input-parse.scm

 ETAGS_ARGS=$(SCM_FILES) $(GENERATED_SCM_FILES)

Modified: trunk/scm/http-client.scm
==============================================================================
--- trunk/scm/http-client.scm   (original)
+++ trunk/scm/http-client.scm   Thu Feb  5 10:17:51 2009
@@ -30,6 +30,7 @@
 ;;;;

 (require-extension (srfi 1 2))
+(require "posix.scm")
 (require "socket.scm")

 (define (http:open hostname servname)
@@ -61,12 +62,12 @@
         (string->list str))))

 (define (http:read-header port)
-  (let loop ((str (socket-read-line port))
+  (let loop ((str (file-read-line port))
              (rest '()))
     (if (or (null? str)
             (string=? "\r" str))
         (reverse rest)
-        (loop (socket-read-line port) (cons str rest)))))
+        (loop (file-read-line port) (cons str rest)))))

 (define (http:find-body-length l)
   (and-let* ((req (map (lambda (q)
@@ -100,14 +101,14 @@

 (define (http:get hostname path servname request-alist)
     (and-let* ((socket (http:open hostname servname))
-               (port (open-socket-port socket))
+               (port (open-file-port socket))
(request (http:make-get-request-string hostname path request-alist))
-               (nr (socket-display request port))
+               (nr (file-display request port))
                (header (http:read-header port)))
       (let* ((body-length (http:find-body-length header))
              (body (if body-length
-                       (socket-read-buffer port body-length)
-                       (socket-get-buffer port))))
+                       (file-read-buffer port body-length)
+                       (file-get-buffer port))))
         (file-close socket)
         body)))


Added: trunk/scm/posix.scm
==============================================================================
--- (empty file)
+++ trunk/scm/posix.scm Thu Feb  5 10:17:51 2009
@@ -0,0 +1,84 @@
+;;; posix.scm: posix functions for uim.
+;;;
+;;; Copyright (c) 2009-2009 uim Project http://code.google.com/p/uim/
+;;;
+;;; 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. Neither the name of authors nor the names of its contributors
+;;; may be used to endorse or promote products derived from this software
+;;;    without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``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 COPYRIGHT HOLDERS OR CONTRIBUTORS 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.
+;;;;
+
+(require-extension (srfi 9))
+
+(define file-bufsiz 16384)
+
+(define (string->file-buf str)
+  (map char->integer (string->list str)))
+(define (file-buf->string buf)
+  (list->string (map integer->char buf)))
+(define (file-read-string s len)
+    (file-buf->string (file-read s len)))
+(define (file-write-string s str)
+  (file-write s (string->file-buf str)))
+
+(define-record-type file-port
+  (make-file-port fd inbufsiz inbuf) file-port?
+  (fd       fd?       fd!)
+  (inbufsiz inbufsiz? inbufsiz!)
+  (inbuf    inbuf?    inbuf!))
+
+(define (open-file-port fd)
+  (make-file-port fd file-bufsiz '()))
+
+(define (file-read-char port)
+  (if (null? (inbuf? port))
+      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
+  (let ((c (car (inbuf? port))))
+    (inbuf! port (cdr (inbuf? port)))
+    (integer->char c)))
+
+(define (file-peek-char port)
+  (if (null? (inbuf? port))
+      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
+  (let ((c (car (inbuf? port))))
+    (integer->char c)))
+
+(define (file-display str port)
+  (file-write (fd? port) (string->file-buf str)))
+
+(define (file-newline str port)
+  (file-write (fd? port) '(#\newline)))
+
+(define (file-read-line port)
+  (let loop ((c (file-read-char port))
+             (rest '()))
+    (if (eq? #\newline c)
+        (list->string (reverse rest))
+        (loop (file-read-char port) (cons c rest)))))
+
+(define (file-read-buffer port len)
+  (list->string (map (lambda (i) (file-read-char port)) (iota len))))
+
+(define (file-get-buffer port)
+  (file-buf->string (inbuf? port)))

Modified: trunk/scm/socket.scm
==============================================================================
--- trunk/scm/socket.scm        (original)
+++ trunk/scm/socket.scm        Thu Feb  5 10:17:51 2009
@@ -49,15 +49,6 @@
 (define (addrinfo-ai-protocol-number s)
   (assq-cdr s addrinfo-ai-protocol-alist))

-(define (string->socket-buf str)
-  (map char->integer (string->list str)))
-(define (socket-buf->string buf)
-  (list->string (map integer->char buf)))
-(define (file-read-string s len)
-    (socket-buf->string (file-read s len)))
-(define (file-write-string s str)
-  (file-write s (string->socket-buf str)))
-
 (define (call-with-getaddrinfo-hints flags family socktype protocol thunk)
   (let* ((hints (make-addrinfo)))
     (and flags    (addrinfo-set-ai-flags!    hints
@@ -82,42 +73,3 @@
     (let ((ret (thunk sun)))
       (delete-sockaddr-un sun))))

-(define socket-bufsiz 16384)
-
-(define-record-type socket-port
-  (make-socket-port fd inbufsiz inbuf) socket-port?
-  (fd       fd?       fd!)
-  (inbufsiz inbufsiz? inbufsiz!)
-  (inbuf    inbuf?    inbuf!))
-
-(define (open-socket-port fd)
-  (make-socket-port fd socket-bufsiz '()))
-
-(define (socket-read-char port)
-  (if (null? (inbuf? port))
-      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
-  (let ((c (car (inbuf? port))))
-    (inbuf! port (cdr (inbuf? port)))
-    (integer->char c)))
-
-(define (socket-peek-char port)
-  (if (null? (inbuf? port))
-      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
-  (let ((c (car (inbuf? port))))
-    (integer->char c)))
-
-(define (socket-display str port)
-  (file-write (fd? port) (string->socket-buf str)))
-
-(define (socket-read-line port)
-  (let loop ((c (socket-read-char port))
-             (rest '()))
-    (if (eq? #\newline c)
-        (list->string (reverse rest))
-        (loop (socket-read-char port) (cons c rest)))))
-
-(define (socket-read-buffer port len)
-  (list->string (map (lambda (i) (socket-read-char port)) (iota len))))
-
-(define (socket-get-buffer port)
-  (socket-buf->string (inbuf? port)))

Reply via email to