Browse Source

make presence handlers like message ones, add jid helpers, add XEP-0045 func

master
eta 2 years ago
parent
commit
74e491e467
  1. 12
      component.lisp
  2. 1
      sxcl.asd
  3. 17
      xep-0045.lisp
  4. 12
      xmpp.lisp

12
component.lisp

@ -279,14 +279,22 @@ @@ -279,14 +279,22 @@
"Handles a presence STANZA for component COMP."
(let* ((type (dom:get-attribute stanza "type"))
(from (dom:get-attribute stanza "from"))
(stripped (strip-resource from))
(to (dom:get-attribute stanza "to"))
(id (dom:get-attribute stanza "id"))
(event-name
(cond
((equal type "subscribe") :presence-subscribe)
((equal type "probe") :presence-probe)
((equal type "unavailable") :presence-unavailable)
(t :presence))))
(emit event-name comp :from from :to to :type type :stanza stanza)))
(handler-case
(emit event-name comp :from from :to to :type type :stanza stanza :stripped stripped)
(stanza-error (e)
(send-stanza-error comp
:id id :to from :from to
:stanza-type "presence"
:e e)))))
(defun handle-message (comp stanza)
"Handles a message STANZA for component COMP."
@ -317,7 +325,7 @@ @@ -317,7 +325,7 @@
(emit :message comp :from from :to to :id id :stanza stanza :stripped stripped)))
(stanza-error (e)
(send-stanza-error comp
:id id :to to :from from
:id id :to from :from to
:stanza-type "message"
:e e)))))

1
sxcl.asd

@ -8,5 +8,6 @@ @@ -8,5 +8,6 @@
(:file "component")
(:file "xmpp")
(:file "xep-0030")
(:file "xep-0045")
(:file "xep-0363")
(:file "xep-0115")))

17
xep-0045.lisp

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
;;;; XEP-0045: Multi-User Chat
(in-package :sxcl)
(defun send-muc-presence (comp to muc-jid user-nickname affiliation role &key stati user-jid)
(with-presence (comp to :from (concatenate 'string muc-jid "/" user-nickname))
(cxml:with-element "x"
(cxml:attribute "xmlns" +muc-user-ns+)
(cxml:with-element "item"
(when user-jid
(cxml:attribute "jid" user-jid))
(cxml:attribute "affiliation" affiliation)
(cxml:attribute "role" role))
(loop
for status in stati
do (cxml:with-element "status"
(cxml:attribute "code" status))))))

12
xmpp.lisp

@ -163,6 +163,18 @@ @@ -163,6 +163,18 @@
(split-at rest at-pos)
(values hostname localpart resource)))))))
(defun hostname (jid)
"Returns the hostname part of JID."
(nth-value 0 (parse-jid jid)))
(defun localpart (jid)
"Returns the localpart of JID."
(nth-value 1 (parse-jid jid)))
(defun resource (jid)
"Returns the resource of JID."
(nth-value 2 (parse-jid jid)))
(defun strip-resource (jid)
"Strips a resource from JID, if there is one, returning the bare JID."
(let ((slash-pos (position #\/ jid)))

Loading…
Cancel
Save