;;; extracted from w3-4.0pre.46/lisp/url.el (last part) 2001-08-17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; How to register a protocol ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun url-register-protocol (protocol &optional retrieve expander defport) "Register a protocol with the URL retrieval package. PROTOCOL is the type of protocol being registers (http, nntp, etc), and is the first chunk of the URL. ie: http:// URLs will be handled by the protocol registered as 'http'. PROTOCOL can be either a symbol or a string - it is converted to a string, and lowercased before being registered. RETRIEVE (optional) is the function to be called with a url as its only argument. If this argument is omitted, then this looks for a function called 'url-PROTOCOL'. A warning is shown if the function is undefined, but the protocol is still registered. EXPANDER (optional) is the function to call to expand a relative link of type PROTOCOL. If omitted, this defaults to `url-default-expander' Any proxy information is read in from environment variables at this time, so this function should only be called after dumping emacs." (let* ((protocol (cond ((stringp protocol) (downcase protocol)) ((symbolp protocol) (downcase (symbol-name protocol))) (t nil))) (retrieve (or retrieve (intern (concat "url-" protocol)))) (expander (or expander 'url-default-expander)) (cur-protocol (assoc protocol url-registered-protocols)) (urlobj nil) (cur-proxy (assoc protocol url-proxy-services)) (env-proxy (or (getenv (concat protocol "_proxy")) (getenv (concat protocol "_PROXY")) (getenv (upcase (concat protocol "_PROXY")))))) (if (not protocol) (error "Invalid data to url-register-protocol.")) (if (not (fboundp retrieve)) (message "Warning: %s registered, but no function found." protocol)) ;; Store the default port, if none previously specified and ;; defport given (if (and defport (not (assoc protocol url-default-ports))) (setq url-default-ports (cons (cons protocol defport) url-default-ports))) ;; Store the appropriate information for later (if cur-protocol (setcdr cur-protocol (cons retrieve expander)) (setq url-registered-protocols (cons (cons protocol (cons retrieve expander)) url-registered-protocols))) ;; Store any proxying information - this will not overwrite an old ;; entry, so that people can still set this information in their ;; .emacs file (cond (cur-proxy nil) ; Keep their old settings ((null env-proxy) nil) ; No proxy setup ;; First check if its something like hostname:port ((string-match "^\\([^:]+\\):\\([0-9]+\\)$" env-proxy) (setq urlobj (url-generic-parse-url nil)) ; Get a blank object (url-set-type urlobj "http") (url-set-host urlobj (url-match env-proxy 1)) (url-set-port urlobj (url-match env-proxy 2))) ;; Then check if its a fully specified URL ((string-match url-nonrelative-link env-proxy) (setq urlobj (url-generic-parse-url env-proxy)) (url-set-type urlobj "http") (url-set-target urlobj nil)) ;; Finally, fall back on the assumption that its just a hostname (t (setq urlobj (url-generic-parse-url nil)) ; Get a blank object (url-set-type urlobj "http") (url-set-host urlobj env-proxy))) (if (and (not cur-proxy) urlobj) (progn (setq url-proxy-services (cons (cons protocol (concat (url-host urlobj) ":" (url-port urlobj))) url-proxy-services)) (message "Using a proxy for %s..." protocol)))))