Changeset 15832 in project


Ignore:
Timestamp:
09/12/09 15:09:02 (10 years ago)
Author:
sjamaan
Message:

Swap around the reader/writer procedures to EXEC again, so it is less confusing when comparing to http-client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/estraier-client/estraier-client.scm

    r15831 r15832  
    5252(use data-structures extras ports srfi-1 srfi-13 http-client uri-common intarweb)
    5353
    54 ;; TODO: Make reader optional. If it's optional, clear out input port and
    55 ;; return (void).  This will shorten the code a bit more.  Maybe then
    56 ;; we can reverse the reader and writer again..  Not likely though.
    57 ;; Use keywords (reader: foo writer: bar) instead?
    58 (define (exec uri reader #!optional writer)
     54;; Exhaust input port with web-server's output (yes, confusing) and return void
     55(define (discard-output in)
     56  (let loop ((line (read-line in)))
     57    (if (eof-object? line) (void) (loop (read-line in)))))
     58
     59(define (exec uri writer reader)
    5960  ;; Estraier doesn't understand the preferred ";" separator
    6061  (parameterize ((form-urlencoded-separator "&"))
    6162    (call-with-input-request uri writer reader)))
    62 
    63 (define (discard-output in)
    64   (let loop ((line (read-line in)))
    65     (if (eof-object? line) (void) (loop (read-line in)))))
    6663
    6764;; Read one block of data. The Hyper Estraier API sends data out in blocks
     
    9794  (exec
    9895   (node-uri node "inform")
     96   #f
    9997   (lambda (in)
    10098     (let* ((db-info (string-split (car (read-block in)) "\t" #t))
     
    113111
    114112(define (node-cache-usage node)
    115   (string->number (exec (node-uri node "cacheusage") read-line)))
     113  (string->number (exec (node-uri node "cacheusage") #f read-line)))
    116114
    117115(define (node-optimize node)
    118   (exec (node-uri node "optimize") discard-output))
     116  (exec (node-uri node "optimize") #f discard-output))
    119117
    120118(define (node-sync node)
    121   (exec (node-uri node "sync") discard-output))
     119  (exec (node-uri node "sync") #f discard-output))
    122120
    123121(define (list-documents node #!key max prev)
    124122  (exec (node-uri node "list"
    125123                  query: `((max . ,(and max (->string max))) (prev . ,prev)))
     124        #f
    126125        (lambda (in)
    127126          (map (lambda (line)
     
    137136                 method: 'POST major: 1 minor: 0
    138137                 headers: (headers '((content-type text/x-estraier-draft))))
    139    discard-output
    140138   (call-with-output-string ; use string because it wants content-length
    141139     (lambda (out)
     
    150148       (fprintf out "\r\n")
    151149       ;; What if there's a newline in the text?
    152        (for-each (lambda (line) (fprintf out "~A\r\n" line)) contents)))))
     150       (for-each (lambda (line) (fprintf out "~A\r\n" line)) contents)))
     151   discard-output))
    153152
    154153(define (delete-document node #!key id uri)
    155154  (exec (node-uri node "out_doc" query: (id/uri->alist id uri))
    156         discard-output))
    157 
    158 ;; XXX Perhaps URIs should be auto-converted to strings?
    159 ;; OTOH, too much magic will kill us; estraier allows free-form
    160 ;; strings, even in supposedly integral system fields like 'mdate'
     155        #f discard-output))
    161156
    162157(define (document-uri->id node uri)
    163   (exec (node-uri node "uri_to_id" query: `((uri . ,uri))) read-line))
     158  (exec (node-uri node "uri_to_id" query: `((uri . ,uri))) #f read-line))
    164159
    165160(define (get-document node #!key id uri)
     
    167162         (exec
    168163          (node-uri node "get_doc" query: (id/uri->alist id uri))
     164          #f
    169165          (lambda (in)
    170166            (let ((metadata (map split-attrib-line
     
    179175;; simply replaces the document's attributes.  This also means it
    180176;; requires both @uri and @id!  Anything not present is reset or
    181 ;; removed.
     177;; removed.  It's identical to put-document, except for the doc body.
    182178(define (update-attributes node attribs)
    183179  (exec
     
    185181                 method: 'POST major: 1 minor: 0
    186182                 headers: (headers '((content-type text/x-estraier-draft))))
    187    discard-output
    188183   (call-with-output-string ; use string because it wants content-length
    189184     (lambda (out)
     
    191186        (lambda (attrib)
    192187          (fprintf out "~A=~A\r\n" (car attrib) (cdr attrib)))
    193         attribs)))))
     188        attribs)))
     189   discard-output))
    194190
    195191(define (document-attribute node attrib #!key id uri)
    196192  (exec (node-uri node "get_doc_attr" query: (cons `(attr . ,(->string attrib))
    197193                                                   (id/uri->alist id uri)))
    198         read-line))
     194        #f read-line))
    199195
    200196(define (document-keywords node #!key id uri)
    201197  (exec (node-uri node "etch_doc" query: (id/uri->alist id uri))
     198        #f
    202199        (lambda (in)
    203200          (let loop ((line (read-line in))
     
    229226                            (skip . ,(and skip (->string skip)))
    230227                            (mask . ,(and mask (->string mask)))))
     228         #f
    231229         (lambda (in)
    232230           (let* ((delimiter (read-line in))
     
    279277  (exec (node-uri node "_set_user" query: `((name . ,name)
    280278                                            (mode . ,(->string mode))))
    281         read-lines))
     279        #f read-lines))
    282280
    283281(define (delete-user node name)
     
    303301
    304302(define (master-shutdown master)
    305   (exec (master-uri master "shutdown") discard-output))
     303  (exec (master-uri master "shutdown") #f discard-output))
    306304
    307305(define (master-sync master)
    308   (exec (master-uri master "sync") discard-output))
     306  (exec (master-uri master "sync") #f discard-output))
    309307
    310308(define (master-backup master)
    311   (exec (master-uri master "backup") discard-output))
     309  (exec (master-uri master "backup") #f discard-output))
    312310
    313311(define (master-rotate-log master)
    314   (exec (master-uri master "logrtt") discard-output))
     312  (exec (master-uri master "logrtt") #f discard-output))
    315313
    316314(define (master-nodes master)
    317315  (map (lambda (line)
    318316         (string-split line "\t" #t))
    319        (exec (master-uri master "nodelist") read-lines)))
     317       (exec (master-uri master "nodelist") #f read-lines)))
    320318
    321319(define (master-add-node master node-name #!optional node-label)
    322320  (exec (master-uri master "nodeadd"
    323321                    query: `((name . ,node-name) (label . ,node-label)))
    324         discard-output))
     322        #f discard-output))
    325323
    326324(define (master-delete-node master node-name)
    327325  (exec (master-uri master "nodedel" query: `((name . ,node-name)))
    328         discard-output))
     326        #f discard-output))
    329327
    330328(define (master-clear-node master node-name)
    331329  (exec (master-uri master "nodeclr" query: `((name . ,node-name)))
    332         discard-output))
     330        #f discard-output))
    333331
    334332(define (master-users master)
    335333  (exec (master-uri master "userlist")
     334        #f
    336335        (lambda (in)
    337336          (let loop ((line (read-line in))
     
    346345  (exec (make-request uri: (master-uri master "useradd")
    347346                      method: 'POST major: 1 minor: 0)
    348         discard-output
    349347        `((name . ,username) (passwd . ,password)
    350           (flags . ,flags) (fname . ,fullname) (misc . ,description))))
     348          (flags . ,flags) (fname . ,fullname) (misc . ,description))
     349        discard-output))
    351350
    352351(define (master-delete-user master username)
    353352  (exec (master-uri master "userdel" query: `((name . ,username)))
    354         discard-output))
     353        #f discard-output))
    355354
    356355)
Note: See TracChangeset for help on using the changeset viewer.