no title added by mercora on Sun May 13 17:45:00 2012

#!/usr/bin/csi -s

(use tcp6 input-parse)

(define nntp:status:info 49)
(define nntp:status:cmd-ok 50)
(define nntp:status:cmd-needs-more 51)
(define nntp:status:cmd-failed 52)
(define nntp:status:cmd-unknown 53)

(define nntp:category:connection 48)
(define nntp:category:group 49)
(define nntp:category:article 50)
(define nntp:category:distribution 51)
(define nntp:category:posting 52)
(define nntp:category:auth 56)
(define nntp:category:ext 57)


(define (nntp:send-command cmd . args)
  (display (string-append cmd "\r\n")))

(define (nntp:receive-response . proc)
  (let* ((status (read-byte))
	 (category (read-byte))
	 (vendor (read-byte)))
    
    (case category
      ((nntp:category:connection)
       (case status
	 ((nntp:status:cmd-ok)
	  (print "Connected")
	  (if (= vendor 48)
	      (print "Posting allowed!"))
	  (if (= vendor 49) 
	      (print "Posting forbidden!"))))))

    (display status)
    (display category)
    (display vendor)
    (print (read-line))))


(let-values (((nntp-in nntp-out) (tcp-connect "localhost" 119)))
  (with-output-to-port (current-output-port)
    (lambda ()
      (with-input-from-port nntp-in
	(lambda ()
	  (nntp:receive-response))))))