Gnus development mailing list
 help / color / mirror / Atom feed
* Help defadvising nnimap-open-connection
@ 2001-01-03 18:42 Jake Colman
  2001-01-03 23:00 ` Christoph Conrad
  0 siblings, 1 reply; 2+ messages in thread
From: Jake Colman @ 2001-01-03 18:42 UTC (permalink / raw)
  Cc: Simon Josefsson


In a previous post on this list, Christoph Conrad discusses a problem with
nntp-open-network-stream with respect to hangs when a connection problem
occurs.  He resolved the problem with with the following piece of advice:

        (defadvice open-network-stream
          ( before nntp-open-network-stream-resolve act )
            (when (not (string-match "[0-9.]+" (ad-get-arg 2)))
              (ad-set-arg 2 (cc-resolve-address nntp-address))))

The function cc-resolve-address converts a host name to a host IP address
using nslookup.

Since I see the same problem quite regularly when connecting to my imap
server, I attempted the following piece of advice:

        (defadvice nnimap-open-connection
          (before nnimap-open-connection-resolve act)
          (when (not (string-match "[0-9.]+" (ad-get-arg 0)))
            (ad-set-arg 0 (cc-resolve-address nnimap-address))))

When I do this, I end up crashing because nnimap-server-buffer is nil in
nnimap-open-server.  Can someone (Simon?) help me figure out how to do this?
Basically, I want to transparently replace the imap host name with the imap
IP address so that the actual connection is done via the address.

For completeness sake, here is the cc-resolve-address function:

(defun cc-resolve-address( domain )
  "Helper function for advised open-network-stream function"
  (save-excursion
    (let ((output-buf (generate-new-buffer " *resolve-address*")))
      (unwind-protect
          (progn
            (set-buffer output-buf)
            (and (eq (call-process
                      "/usr/sbin/nslookup" nil output-buf nil
                      "-retries=1" domain)
                     0)
                 (> (point-max) 2)
                 (goto-char (point-max))
                 (when (re-search-backward (concat "^Name: [ ]*"
                                                   domain
                                                   "\n"
                                                   "Address: [ ]*\\(.*\\)$")
                                           nil t)
                   (match-string 1))))
        ;; unwind-protect cleanup
        (kill-buffer output-buf)))))


TIA!

-- 
Jake Colman                     

Principia Partners LLC                  Phone: (201) 946-0300
Harborside Financial Center               Fax: (201) 946-0320
902 Plaza II                           Beeper: (800) 928-4640
Jersey City, NJ 07311                  E-mail: colman@ppllc.com
                                       E-mail: jcolman@jnc.com
                                          web: http://www.ppllc.com

microsoft: "where do you want to go today?"
linux:     "where do you want to go tomorrow?"
BSD:       "are you guys coming, or what?"




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help defadvising nnimap-open-connection
  2001-01-03 18:42 Help defadvising nnimap-open-connection Jake Colman
@ 2001-01-03 23:00 ` Christoph Conrad
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Conrad @ 2001-01-03 23:00 UTC (permalink / raw)
  Cc: ding, Simon Josefsson

Hi Jake,

you wrote:

    >    (defadvice nnimap-open-connection
    >      (before nnimap-open-connection-resolve act)
    >      (when (not (string-match "[0-9.]+" (ad-get-arg 0)))
    >        (ad-set-arg 0 (cc-resolve-address nnimap-address))))

I had a look in the relevant sources. Since `nnimap-open-connection' in
nnimap.el uses 

(defun imap-open (server &optional port stream auth buffer)

in imap.el you should advice this function. The server argument from
`nnimap-open-connection' seems to be something other.

So i would try (untested):

(defadvice imap-open
  ( before imap-open-resolve act )
  (let ( (host (ad-get-arg 0)) )
    (when (not (string-match "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" host))
      (ad-set-arg 0 (cc-resolve-address host)))))

Annotation: my original function had a bug which didn't had effects, i
changed it to (yet untested)

;; Args are NAME BUFFER HOST SERVICE.
(defadvice open-network-stream
  ( before open-network-stream-resolve act )
  (let ( (host (ad-get-arg 2)) )
    (when (not (string-match "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" host))
      (ad-set-arg 2 (cc-resolve-address host)))))

;; test
;; (not (string-match "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" "1.1.1.1"))
;; (not (string-match "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" "news.cis.dfn.de"))


Best regards,
cu, -cc-
-- 
=> GNU Emacs Webring @ <http://www.gnusoftware.com/WebRing/> <=
Look Ma, this man can twist his fingers as if they were made of rubber,
isn't that amazing? -- Not really, he's been using emacs for years...!



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-01-03 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-03 18:42 Help defadvising nnimap-open-connection Jake Colman
2001-01-03 23:00 ` Christoph Conrad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).