defmacro -> define-syntax

This commit is contained in:
nik gaffney 2009-04-17 17:30:25 +02:00
parent 9f1434a8da
commit db9fdaabe8

51
xmpp.ss
View file

@ -67,15 +67,15 @@
(module xmpp scheme (module xmpp scheme
(provide (all-defined-out) (provide (all-defined-out)
;open-connection ;; with-xmpp-session
;open-ssl-connection ;; xmpp-stream xmpp-session xmpp-auth
;with-xmpp-session ;; send message presence iq
;; jid-user jid-host jid-resource
) )
(require (planet lizorkin/sxml:2:1/sxml)) ;; encoding xml (require (planet lizorkin/sxml:2:1/sxml)) ;; encoding xml
(require (planet lizorkin/ssax:2:0/ssax)) ;; decoding xml (require (planet lizorkin/ssax:2:0/ssax)) ;; decoding xml
(require mzlib/os) ;; hostname (require mzlib/os) ;; hostname
(require mzlib/defmacro) ;; with-xmpp-session macro
(require scheme/tcp) ;; networking (require scheme/tcp) ;; networking
(require openssl) ;; ssl/tls (require openssl) ;; ssl/tls
(require srfi/13) ;; jid decoding (require srfi/13) ;; jid decoding
@ -301,27 +301,28 @@
(printf "sending iO: ~a ~%~%" str) (printf "sending iO: ~a ~%~%" str)
(fprintf (xmpp-out-port) "~A~%" str) (flush-output (xmpp-out-port))) (fprintf (xmpp-out-port) "~A~%" str) (flush-output (xmpp-out-port)))
(defmacro with-xmpp-session (jid pass . body) (define-syntax with-xmpp-session
`(let ((host (jid-host ,jid)) (syntax-rules ()
(user (jid-user ,jid)) ((_ jid pass . body)
(resource (jid-resource ,jid))) (let ((host (jid-host jid))
(let-values (((in out) (user (jid-user jid))
(ssl-connect host ssl-port 'tls))) (resource (jid-resource jid)))
;;(tcp-connect host port))) (let-values (((in out)
(parameterize ((xmpp-in-port in) (ssl-connect host ssl-port 'tls)))
(xmpp-out-port out)) ;;(tcp-connect host port)))
(file-stream-buffer-mode out 'line) (parameterize ((xmpp-in-port in)
(xmpp-response-handler in) (xmpp-out-port out))
(send (xmpp-stream host)) (file-stream-buffer-mode out 'line)
(send (xmpp-session host)) (xmpp-response-handler in)
;(starttls in out) (send (xmpp-stream host))
(send (xmpp-session host))
;(starttls in out)
(send (xmpp-auth user ,pass resource)) (send (xmpp-auth user pass resource))
(send (presence)) (send (presence))
(send (presence #:status "Available")) (send (presence #:status "Available"))
,@body body
(close-output-port out) (close-output-port out)
(close-input-port in))))) (close-input-port in)))))))
) ;; end module ) ;; end module