A WhatsApp (Web) transport for XMPP.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.4KB

  1. ;;;; XEP-0115: Entity Capabilities
  2. (in-package :whatsxmpp)
  3. (defun format-disco-identity (name type category &optional (lang ""))
  4. "Formats a disco#info identity into a verification string part."
  5. (format nil "~A/~A/~A/~A" category type lang name))
  6. (defun generate-entity-caps (disco-info-list)
  7. "Using DISCO-INFO-LIST, a quoted list of calls to DISCO-IDENTITY and DISCO-FEATURE, generate and return an XEP-0115 verification string.
  8. WARNING: You must pre-sort DISCO-INFO-LIST according to the rules in XEP-0115 § 5.1."
  9. (let (identities features)
  10. (loop
  11. for call in disco-info-list
  12. do (ecase (car call)
  13. (disco-identity (push (cdr call) identities))
  14. (disco-feature (push (cdr call) features))))
  15. (qbase64:encode-bytes
  16. (ironclad:digest-sequence :sha1
  17. (babel:string-to-octets
  18. (format nil "~{~A<~}~{~A<~}"
  19. (mapcar (lambda (call)
  20. ;; Because DISCO-IDENTITY and FORMAT-DISCO-IDENTITY
  21. ;; intentionally take the same lambda lists,
  22. ;; we can just do this.
  23. (apply #'format-disco-identity call))
  24. ;; NREVERSE because pushing things does it the wrong
  25. ;; way round (FIXME, inefficient)
  26. (nreverse identities))
  27. ;; DISCO-FEATURE takes one argument (the feature name)
  28. (mapcar #'car (nreverse features))))))))