Synch to No Gnus 200405270734.
[elisp/gnus.git-] / lisp / dns.el
index 19ab3ba..bddfe02 100644 (file)
@@ -1,5 +1,5 @@
 ;;; dns.el --- Domain Name Service lookups
-;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: network
@@ -56,6 +56,7 @@ If nil, /etc/resolv.conf will be consulted.")
     (MX 15)
     (TXT 16)
     (AAAA 28) ; RFC3596
+    (SRV 33) ; RFC2782
     (AXFR 252)
     (MAILB 253)
     (MAILA 254)
@@ -284,6 +285,11 @@ If TCP-P, the first two bytes of the package with be the length field."
                  (list 'retry (dns-read-int32))
                  (list 'expire (dns-read-int32))
                  (list 'minimum (dns-read-int32))))
+          ((eq type 'SRV)
+           (list (list 'priority (dns-read-bytes 2))
+                 (list 'weight (dns-read-bytes 2))
+                 (list 'port (dns-read-bytes 2))
+                 (list 'target (dns-read-name buffer))))
           ((eq type 'MX)
            (cons (dns-read-bytes 2) (dns-read-name buffer)))
           ((or (eq type 'CNAME) (eq type 'NS) (eq type 'PTR))
@@ -300,6 +306,25 @@ If TCP-P, the first two bytes of the package with be the length field."
        (push (match-string 1) dns-servers))
       (setq dns-servers (nreverse dns-servers)))))
 
+(defun dns-read-txt (string)
+  (if (> (length string) 1)
+      (substring string 1)
+    string))
+
+(defun dns-get-txt-answer (answers)
+  (let ((result "")
+       (do-next nil))
+    (dolist (answer answers)
+      (dolist (elem answer)
+       (when (consp elem)
+         (cond
+          ((eq (car elem) 'type)
+           (setq do-next (eq (cadr elem) 'TXT)))
+          ((eq (car elem) 'data)
+           (when do-next
+             (setq result (concat result (dns-read-txt (cadr elem))))))))))
+    result))
+
 ;;; Interface functions.
 (defmacro dns-make-network-process (server)
   (if (featurep 'xemacs)
@@ -369,7 +394,9 @@ If FULLP, return the entire record returned."
                  result
                (let ((answer (car (dns-get 'answers result))))
                  (when (eq type (dns-get 'type answer))
-                   (dns-get 'data answer)))))))))))
+                   (if (eq type 'TXT)
+                       (dns-get-txt-answer (dns-get 'answers result))
+                     (dns-get 'data answer))))))))))))
 
 (provide 'dns)