Mercurial > emacs
annotate lisp/url/url-methods.el @ 66003:eefcdbee90bc
(glyph_rect): Return 0 if position is outside text area.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 10 Oct 2005 22:54:19 +0000 |
parents | 875dcc490074 |
children | e8a3fb527b77 532e0a9335a9 |
rev | line source |
---|---|
54695 | 1 ;;; url-methods.el --- Load URL schemes as needed |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
2 |
64748
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, |
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
5 |
54695 | 6 ;; Keywords: comm, data, processes, hypermedia |
7 | |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
9 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
13 ;; any later version. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
14 ;; |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
18 ;; GNU General Public License for more details. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
19 ;; |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64084 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
24 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
25 ;;; Commentary: |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
26 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
27 ;;; Code: |
54695 | 28 |
29 (eval-when-compile | |
30 (require 'cl)) | |
31 | |
32 ;; This loads up some of the small, silly URLs that I really don't | |
33 ;; want to bother putting in their own separate files. | |
34 (require 'url-parse) | |
35 | |
36 (defvar url-scheme-registry (make-hash-table :size 7 :test 'equal)) | |
37 | |
38 (defconst url-scheme-methods | |
39 '((default-port . variable) | |
40 (asynchronous-p . variable) | |
41 (expand-file-name . function) | |
42 (file-exists-p . function) | |
43 (file-attributes . function) | |
44 (parse-url . function) | |
45 (file-symlink-p . function) | |
46 (file-writable-p . function) | |
47 (file-directory-p . function) | |
48 (file-executable-p . function) | |
49 (directory-files . function) | |
50 (file-truename . function)) | |
51 "Assoc-list of methods that each URL loader can provide.") | |
52 | |
53 (defconst url-scheme-default-properties | |
54 (list 'name "unknown" | |
55 'loader 'url-scheme-default-loader | |
56 'default-port 0 | |
57 'expand-file-name 'url-identity-expander | |
58 'parse-url 'url-generic-parse-url | |
59 'asynchronous-p nil | |
60 'file-directory-p 'ignore | |
61 'file-truename (lambda (&rest args) | |
62 (url-recreate-url (car args))) | |
63 'file-exists-p 'ignore | |
64 'file-attributes 'ignore)) | |
65 | |
66 (defun url-scheme-default-loader (url &optional callback cbargs) | |
67 "Signal an error for an unknown URL scheme." | |
68 (error "Unkown URL scheme: %s" (url-type url))) | |
69 | |
70 (defun url-scheme-register-proxy (scheme) | |
71 "Automatically find a proxy for SCHEME and put it in `url-proxy-services'." | |
72 (let* ((env-var (concat scheme "_proxy")) | |
73 (env-proxy (or (getenv (upcase env-var)) | |
74 (getenv (downcase env-var)))) | |
75 (cur-proxy (assoc scheme url-proxy-services)) | |
76 (urlobj nil)) | |
77 | |
78 ;; Store any proxying information - this will not overwrite an old | |
79 ;; entry, so that people can still set this information in their | |
80 ;; .emacs file | |
81 (cond | |
82 (cur-proxy nil) ; Keep their old settings | |
83 ((null env-proxy) nil) ; No proxy setup | |
84 ;; First check if its something like hostname:port | |
85 ((string-match "^\\([^:]+\\):\\([0-9]+\\)$" env-proxy) | |
86 (setq urlobj (url-generic-parse-url nil)) ; Get a blank object | |
87 (url-set-type urlobj "http") | |
88 (url-set-host urlobj (match-string 1 env-proxy)) | |
89 (url-set-port urlobj (string-to-number (match-string 2 env-proxy)))) | |
90 ;; Then check if its a fully specified URL | |
91 ((string-match url-nonrelative-link env-proxy) | |
92 (setq urlobj (url-generic-parse-url env-proxy)) | |
93 (url-set-type urlobj "http") | |
94 (url-set-target urlobj nil)) | |
95 ;; Finally, fall back on the assumption that its just a hostname | |
96 (t | |
97 (setq urlobj (url-generic-parse-url nil)) ; Get a blank object | |
98 (url-set-type urlobj "http") | |
99 (url-set-host urlobj env-proxy))) | |
100 | |
101 (if (and (not cur-proxy) urlobj) | |
102 (progn | |
103 (setq url-proxy-services | |
104 (cons (cons scheme (format "%s:%d" (url-host urlobj) | |
105 (url-port urlobj))) | |
106 url-proxy-services)) | |
107 (message "Using a proxy for %s..." scheme))))) | |
108 | |
109 (defun url-scheme-get-property (scheme property) | |
110 "Get property of a URL SCHEME. | |
111 Will automatically try to load a backend from url-SCHEME.el if | |
112 it has not already been loaded." | |
113 (setq scheme (downcase scheme)) | |
114 (let ((desc (gethash scheme url-scheme-registry))) | |
115 (if (not desc) | |
116 (let* ((stub (concat "url-" scheme)) | |
117 (loader (intern stub))) | |
118 (condition-case () | |
119 (require loader) | |
120 (error nil)) | |
121 (if (fboundp loader) | |
122 (progn | |
123 ;; Found the module to handle <scheme> URLs | |
124 (url-scheme-register-proxy scheme) | |
125 (setq desc (list 'name scheme | |
126 'loader loader)) | |
127 (dolist (cell url-scheme-methods) | |
128 (let ((symbol (intern-soft (format "%s-%s" stub (car cell)))) | |
129 (type (cdr cell))) | |
130 (if symbol | |
131 (case type | |
132 (function | |
133 ;; Store the symbol name of a function | |
134 (if (fboundp symbol) | |
135 (setq desc (plist-put desc (car cell) symbol)))) | |
136 (variable | |
137 ;; Store the VALUE of a variable | |
138 (if (boundp symbol) | |
139 (setq desc (plist-put desc (car cell) | |
140 (symbol-value symbol))))) | |
141 (otherwise | |
142 (error "Malformed url-scheme-methods entry: %S" | |
143 cell)))))) | |
144 (puthash scheme desc url-scheme-registry))))) | |
145 (or (plist-get desc property) | |
146 (plist-get url-scheme-default-properties property)))) | |
147 | |
148 (provide 'url-methods) | |
54699 | 149 |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
150 ;; arch-tag: 336863f8-5a07-4906-9be5-b3c6bcebbe67 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
151 ;;; url-methods.el ends here |