From a7d638168947b36cec0c17cc89bad20f113d23ae Mon Sep 17 00:00:00 2001 From: rekado Date: Mon, 1 Dec 2014 21:33:21 +0100 Subject: implement predicates for iq/message/presence --- xmpp.scm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/xmpp.scm b/xmpp.scm index 274524b..91d8662 100644 --- a/xmpp.scm +++ b/xmpp.scm @@ -1,9 +1,10 @@ (define-module (gnubba xmpp) #:use-module (sxml simple) + #:use-module ((sxml xpath) #:select (sxpath)) #:use-module ((srfi srfi-1) #:select (find)) - #:export (iq - presence - message + #:export (iq iq? + presence presence? + message message? stanza-id stanza-to stanza-from @@ -89,14 +90,14 @@ is unregistered." (to "") (type "get") (id (next-stanza-id! 'iq))) - `(iq ,(drop-empty-attr `(@ (from ,from) - (to ,to) - (type ,type) - (id ,id))) - ,body)) + `(*TOP* (iq ,(drop-empty-attr `(@ (from ,from) + (to ,to) + (type ,type) + (id ,id))) + ,body))) (define (message to body) - `(message (@ (to ,to)) (body ,body))) + `(*TOP* (message (@ (to ,to)) (body ,body)))) (define* (presence #:optional body #:key (from "") @@ -108,9 +109,9 @@ is unregistered." (from ,from) (to ,to) (id ,id))))) - (if body - `(presence ,attr ,body) - `(presence ,attr)))) + `(*TOP* ,(if body + `(presence ,attr ,body) + `(presence ,attr))))) (define (stanza-find-property property-name stanza) @@ -148,7 +149,6 @@ is unregistered." ;; (define-attributes (from to type id)) -;; TODO: define some useful predicates -(define (iq? stanza) #f) -(define (message? stanza) #f) -(define (presence? stanza) #f) +(define (iq? stanza) (not (null? ((sxpath '(iq)) stanza)))) +(define (message? stanza) (not (null? ((sxpath '(message)) stanza)))) +(define (presence? stanza) (not (null? ((sxpath '(presence)) stanza)))) -- cgit v1.2.3