Use xml-parse-region to parse stream header
authorMagnus Henoch <[email protected]>
Sun, 2 Oct 2011 18:28:21 +0000 (2 19:28 +0100)
committerMagnus Henoch <[email protected]>
Sun, 2 Oct 2011 18:28:21 +0000 (2 19:28 +0100)
This lets us get rid of some ugly hacks, and will make it easier to
extract other attributes from the header.

jabber-core.el

index b2a1fa5..21d0d96 100644 (file)
@@ -854,30 +854,18 @@ DATA is any sexp."
         (return (fsm-send fsm :stream-end)))
 
        ;; Stream header?
-       (when (looking-at "<stream:stream[^>]*>")
-        (let ((stream-header (match-string 0))
-              (ending-at (match-end 0))
-              session-id stream-version)
-          ;; These regexps extract attribute values from the stream
-          ;; header, taking into account that the quotes may be either
-          ;; single or double quotes.
-          (setq session-id
-                (and (or (string-match "id='\\([^']+\\)'" stream-header)
-                         (string-match "id=\"\\([^\"]+\\)\"" stream-header))
-                     (jabber-unescape-xml (match-string 1 stream-header))))
-          (setq stream-version
-                (and (or
-                      (string-match "version='\\([0-9.]+\\)'" stream-header)
-                      (string-match "version=\"\\([0-9.]+\\)\"" stream-header))
-                     (match-string 1 stream-header)))
-          (jabber-log-xml fsm "receive" stream-header)
+       (when (looking-at "<stream:stream[^>]*\\(>\\)")
+        ;; Let's pretend that the stream header is a closed tag,
+        ;; and parse it as such.
+        (replace-match "/>" t t nil 1)
+        (let* (;; Thus we need to add one to the index...
+               (ending-at (1+ (match-end 0)))
+               (stream-header (car (xml-parse-region (point-min) ending-at)))
+               (session-id (jabber-xml-get-attribute stream-header 'id))
+               (stream-version (jabber-xml-get-attribute stream-header 'version)))
           
-          ;; If the server is XMPP compliant, i.e. there is a version attribute
-          ;; and it's >= 1.0, there will be a stream:features tag shortly,
-          ;; so just wait for that.
-
+          (jabber-log-xml fsm "receive" stream-header)
           (fsm-send fsm (list :stream-start session-id stream-version))
-        
           (delete-region (point-min) ending-at)))
        
        ;; Normal tag