annotate lisp/w3/url-gopher.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents 0293115a14e9
children 859a2309aef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; url-gopher.el --- Gopher Uniform Resource Locator retrieval code
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3 ;; Created: 1997/01/10 00:13:05
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
4 ;; Version: 1.4
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1993-1996 by William M. Perry (wmperry@cs.indiana.edu)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 (require 'url-vars)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 (require 'url-parse)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 (defun url-grok-gopher-href (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 "Return a list of attributes from a gopher url. List is of the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 type: host port selector-string MIME-type extra-info"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 (let (host ; host name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 port ; Port #
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 selector ; String to send to gopher host
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 type ; MIME type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 extra ; Extra information
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 x ; Temporary storage for host/port
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 y ; Temporary storage for selector
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 ylen
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 (or (string-match "gopher:/*\\([^/]+\\)\\(/*\\)" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 (error "Can't understand url %s" url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (setq x (url-match url 1) ; The host (and possible port #)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 ylen (- (length url) (match-end 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 y (if (= ylen 0) ; The selector (and possible type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 ""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 (url-unhex-string (substring url (- ylen)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52 ;First take care of the host/port/gopher+ information from the url
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 ;A + after the port # (host:70+) specifies a gopher+ link
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 ;A ? after the port # (host:70?) specifies a gopher+ ask block
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 (if (string-match "^\\([^:]+\\):\\([0-9]+\\)\\([?+]*\\)" x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (setq host (url-match x 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 port (url-match x 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 extra (url-match x 3))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (setq host x
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 port "70"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 extra nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 ((equal extra "") (setq extra nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 ((equal extra "?") (setq extra 'ask-block))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 ((equal extra "+") (setq extra 'gopher+)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 ; Next, get the type/get rid of the Mosaic double-typing. Argh.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (setq x (string-to-char y) ; Get gopher type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 selector (if (or url-use-hypertext-gopher
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 (< 3 (length y)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 y ; Get the selector string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (substring y 1 nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 type (cdr (assoc x url-gopher-to-mime)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 (list host port (or selector "") type extra)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 (defun url-convert-ask-to-form (ask)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 ;; Convert a Gopher+ ASK block into a form. Returns a string to be
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79 ;; inserted into a buffer to create the form."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 (let ((form (concat "<form enctype=application/gopher-ask-block\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 " method=\"GOPHER-ASK\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 " <ul plain>\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 (type "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 (x 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 (parms ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 (while (string-match "^\\([^:]+\\): +\\(.*\\)" ask)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 (setq parms (url-match ask 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 type (url-strip-leading-spaces (downcase (url-match ask 1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 ask (substring ask (if (= (length ask) (match-end 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 (match-end 0) (1+ (match-end 0))) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 ((string= "note" type) (setq form (concat form parms)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94 ((or (string= "ask" type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 (string= "askf" type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (string= "choosef" type))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 (setq parms (url-string-to-tokens parms ?\t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98 form (format "%s\n<li>%s<input name=\"%d\" value=\"%s\">"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 form (or (nth 0 parms) "Text:")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 x (or (nth 1 parms) ""))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 ((string= "askp" type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 (setq parms (mapcar 'car (nreverse (url-split parms "\t")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 form (format
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104 "%s\n<li>%s<input name=\"%d\" type=\"password\" value=\"%s\">"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 form ; Earlier string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (or (nth 0 parms) "Password:") ; Prompt
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 x ; Name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 (or (nth 1 parms) "") ; Default value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 )))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 ((string= "askl" type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (setq parms (url-string-to-tokens parms ?\t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 form (format "%s\n<li>%s<textarea name=\"%d\">%s</textarea>"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113 form ; Earlier string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114 (or (nth 0 parms) "") ; Prompt string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 x ; Name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 (or (nth 1 parms) "") ; Default value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 )))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 ((or (string= "select" type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 (string= "choose" type))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 (setq parms (url-string-to-tokens parms ?\t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 form (format "%s\n<li>%s<select name=\"%d\">" form (car parms) x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 parms (cdr parms))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 (if (null parms) (setq parms (list "Yes" "No")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 (while parms
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 (setq form (concat form "<option>" (car parms) "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 parms (cdr parms)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 (setq form (concat form "</select>")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128 (concat form "\n<li><input type=\"SUBMIT\""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129 " value=\"Submit Gopher+ Ask Block\"></ul></form>")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (defun url-grok-gopher-line ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 "Return a list of link attributes from a gopher string. Order is:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 title, type, selector string, server, port, gopher-plus?"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 (let (type selector server port gopher+ st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 (beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 (setq st (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 (setq nd (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 (mapcar (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 (lambda (var)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (goto-char st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (skip-chars-forward "^\t\n" nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 (set-variable var (buffer-substring st (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (setq st (min (point-max) (1+ (point))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 '(type selector server port))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 (setq gopher+ (and (/= (1- st) nd) (buffer-substring st nd)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (list type (concat (substring type 0 1) selector) server port gopher+))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 (defun url-format-gopher-link (gophobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 ;; Insert a gopher link as an <A> tag
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 (let ((title (nth 0 gophobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (ref (nth 1 gophobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 (type (if (> (length (nth 0 gophobj)) 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 (substring (nth 0 gophobj) 0 1) ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (serv (nth 2 gophobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (port (nth 3 gophobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 (plus (nth 4 gophobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 (desc nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 (if (and (equal type "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 (> (length title) 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 (setq type (substring title 0 1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 (setq title (and title (substring title 1 nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 title (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 ((= x ?&) "&amp;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 ((= x ?<) "&lt;");
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 ((= x ?>) "&gt;");
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (t (char-to-string x))))) title "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 desc (or (cdr (assoc type url-gopher-labels)) "(UNK)"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 ((null ref) "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 ((equal type "8")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (format "<LI> %s <A HREF=\"telnet://%s:%s/\">%s</A>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 desc serv port title))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 ((equal type "T")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 (format "<LI> %s <A HREF=\"tn3270://%s:%s/\">%s</A>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 desc serv port title))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 (t (format "<LI> %s <A METHODS=%s HREF=\"gopher://%s:%s/%s\">%s</A>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 desc type serv (concat port plus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 (url-hexify-string ref) title)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (defun url-gopher-clean-text (&optional buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 "Decode text transmitted by gopher.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 0. Delete status line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 1. Delete `^M' at end of line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 2. Delete `.' at end of buffer (end of text mark).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 3. Delete `.' at beginning of line. (does gopher want this?)"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 (set-buffer (or buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 ;; Insert newline at end of buffer.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 (if (not (bolp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 (insert "\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 ;; Delete `^M' at end of line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 (while (re-search-forward "\r[^\n]*$" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 (replace-match ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 ; (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 ; (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 ; (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 ; (if (= (preceding-char) ?\r)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 ; (delete-char -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 ; (forward-line 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 ; )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 ;; Delete `.' at end of buffer (end of text mark).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209 (forward-line -1) ;(beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 (while (looking-at "^\\.$")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 (delete-region (point) (progn (forward-line 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 (forward-line -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 ;; Replace `..' at beginning of line with `.'.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 ;; (replace-regexp "^\\.\\." ".")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (while (search-forward "\n.." nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (delete-char -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 (defun url-parse-gopher (&optional buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 (set-buffer (or buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 (url-replace-regexp "^\r*$\n" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 (url-replace-regexp "^\\.\r*$\n" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 (url-gopher-clean-text (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 (skip-chars-backward "\n\r\t ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 (delete-region (point-max) (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 (insert "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 (delete-region (point-min) (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 (let* ((len (count-lines (point-min) (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 (objs nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 (i 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 (setq objs (cons (url-grok-gopher-line) objs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 i (1+ i))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 (url-lazy-message "Converting gopher listing... %d/%d (%d%%)"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 i len (url-percentage i len))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (forward-line 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 (setq objs (nreverse objs))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (insert "<title>"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 ((or (string= "" url-current-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 (string= "1/" url-current-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (string= "1" url-current-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 (concat "Gopher root at " url-current-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 ((string-match (format "^[%s]+/" url-gopher-types)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 url-current-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (substring url-current-file 2 nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 (t url-current-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 "</title><ol>"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 (mapconcat 'url-format-gopher-link objs "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 "</ol>"))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (defun url-gopher-retrieve (host port selector &optional wait-for)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 ;; Fetch a gopher object and don't mess with it at all
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 (let ((proc (url-open-stream "*gopher*" url-working-buffer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262 host (if (stringp port) (string-to-int port)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 port)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 (len nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (parsed nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 (url-clear-tmp-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 (setq url-current-file selector
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 url-current-port port
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 url-current-server host
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 url-current-type "gopher")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 (if (> (length selector) 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (setq selector (substring selector 1 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273 (if (stringp proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 (message "%s" proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 (process-send-string proc (concat selector "\r\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (while (and (or (not wait-for)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 (not (re-search-forward wait-for nil t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281 (memq (url-process-status proc) '(run open)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 (if (not parsed)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284 ((and (eq ?+ (char-after 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
285 (memq (char-after 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
286 (list ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
287 (setq parsed (copy-marker 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
288 len (read parsed))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
289 (delete-region (point-min) parsed))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
290 ((and (eq ?+ (char-after 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
291 (eq ?- (char-after 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
292 (setq len nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
293 parsed t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295 (delete-region (point-min) (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
298 ((and (eq ?- (char-after 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
299 (eq ?- (char-after 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 (setq parsed t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 len nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 (delete-region (point-min) (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
304 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305 (point))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
306 (if len (url-lazy-message "Reading... %d of %d bytes (%d%%)"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
307 (point-max)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
308 len
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
309 (url-percentage (point-max) len))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
310 (url-lazy-message "Read... %d bytes." (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
311 (url-accept-process-output proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
312 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
313 (url-kill-process proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
314 (error nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
315 (url-replace-regexp "\n*Connection closed.*\n*" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
316 (url-replace-regexp "\n*Process .*gopher.*\n*" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
317 (while (looking-at "\r") (delete-char 1))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
318
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
319 (defun url-do-gopher-cso-search (descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
320 ;; Do a gopher CSO search and return a plaintext document
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
321 (let ((host (nth 0 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
322 (port (nth 1 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
323 (file (nth 2 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
324 search-type search-term)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
325 (string-match "search-by=\\([^&]+\\)" file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
326 (setq search-type (url-match file 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
327 (string-match "search-term=\\([^&]+\\)" file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
328 (setq search-term (url-match file 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
329 (url-gopher-retrieve host port (format "2query %s=%s"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
330 search-type search-term) "^[2-9]")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
331 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
332 (url-replace-regexp "^-[0-9][0-9][0-9]:[0-9]*:" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
333 (url-replace-regexp "^[^15][0-9][0-9]:.*" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
334 (url-replace-regexp "^[15][0-9][0-9]:\\(.*\\)" "<H1>\\1</H1>&ensp;<PRE>")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
335 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
336 (insert "<title>Results of CSO search</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
337 "<h1>" search-type " = " search-term "</h1>\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
338 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
339 (insert "</pre>")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
340
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
341 (defun url-do-gopher (descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
342 ;; Fetch a gopher object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
343 (let ((host (nth 0 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
344 (port (nth 1 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
345 (file (nth 2 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
346 (type (nth 3 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
347 (extr (nth 4 descr))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
348 parse-gopher)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
349 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
350 ((and ; Gopher CSO search
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
351 (equal type "www/gopher-cso-search")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
352 (string-match "search-by=" file)) ; With a search term in it
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
353 (url-do-gopher-cso-search descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
354 (setq type "text/html"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
355 ((equal type "www/gopher-cso-search") ; Blank CSO search
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
356 (url-clear-tmp-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
357 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
358 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
359 " <title>CSO Search</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
360 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
361 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
362 " <div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
363 " <h1>This is a CSO search</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
364 " <hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
365 " <form>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
366 " <ul>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
367 " <li> Search by: <select name=\"search-by\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
368 " <option>Name\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
369 " <option>Phone\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
370 " <option>Email\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
371 " <option>Address\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
372 " </select>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
373 " <li> Search for: <input name=\"search-term\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
374 " <li> <input type=\"submit\" value=\"Submit query\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
375 " </ul>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
376 " </form>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
377 " </div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
378 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
379 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
380 "<!-- Automatically generated by URL v" url-version " -->\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
381 (setq type "text/html"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
382 parse-gopher t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
383 ((and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
384 (equal type "www/gopher-search") ; Ack! Mosaic-style search href
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
385 (string-match "\t" file)) ; and its got a search term in it!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
386 (url-gopher-retrieve host port file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
387 (setq type "www/gopher"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
388 parse-gopher t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
389 ((and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
390 (equal type "www/gopher-search") ; Ack! Mosaic-style search href
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
391 (string-match "\\?" file)) ; and its got a search term in it!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
392 (setq file (concat (substring file 0 (match-beginning 0)) "\t"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
393 (substring file (match-end 0) nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
394 (url-gopher-retrieve host port file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
395 (setq type "www/gopher"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
396 parse-gopher t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
397 ((equal type "www/gopher-search") ; Ack! Mosaic-style search href
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
398 (setq type "text/html"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
399 parse-gopher t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
400 (url-clear-tmp-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
401 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
402 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
403 " <title>Gopher Server</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
404 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
405 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
406 " <div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
407 " <h1>Searchable Gopher Index</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
408 " <hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
409 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
410 " Enter the search keywords below\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
411 " </p>"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
412 " <form enctype=\"application/x-gopher-query\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
413 " <input name=\"internal-gopher\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
414 " </form>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
415 " <hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
416 " </div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
417 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
418 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
419 "<!-- Automatically generated by URL v" url-version " -->\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
420 ((null extr) ; Normal Gopher link
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
421 (url-gopher-retrieve host port file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
422 (setq parse-gopher t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
423 ((eq extr 'gopher+) ; A gopher+ link
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
424 (url-gopher-retrieve host port (concat file "\t+"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
425 (setq parse-gopher t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
426 ((eq extr 'ask-block) ; A gopher+ interactive query
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
427 (url-gopher-retrieve host port (concat file "\t!")) ; Fetch the info
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
428 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
429 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
430 ((re-search-forward "^\\+ASK:[ \t\r]*" nil t) ; There is an ASK
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
431 (let ((x (buffer-substring (1+ (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
432 (or (re-search-forward "^\\+[^:]+:" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
433 (point-max)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
434 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
435 (insert (url-convert-ask-to-form x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
436 (setq type "text/html" parse-gopher t)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
437 (t (setq parse-gopher t)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
438 (if (or (equal type "www/gopher")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
439 (equal type "text/plain")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
440 (equal file "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
441 (equal type "text/html"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
442 (url-gopher-clean-text))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
443 (if (and parse-gopher (or (equal type "www/gopher")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
444 (equal file "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
445 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
446 (url-parse-gopher)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
447 (setq type "text/html"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
448 url-current-mime-viewer (mm-mime-info type nil 5))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
449 (setq url-current-mime-type (or type "text/plain")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
450 url-current-mime-viewer (mm-mime-info type nil 5)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
451 url-current-file file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
452 url-current-port port
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
453 url-current-server host
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
454 url-current-type "gopher")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
455
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
456 (defun url-gopher (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
457 ;; Handle gopher URLs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
458 (let ((descr (url-grok-gopher-href url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
459 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
460 ((or (not (member (nth 1 descr) url-bad-port-list))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
461 (funcall
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
462 url-confirmation-func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
463 (format "Warning! Trying to connect to port %s - continue? "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
464 (nth 1 descr))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
465 (if url-use-hypertext-gopher
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
466 (url-do-gopher descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
467 (gopher-dispatch-object (vector (if (= 0
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
468 (string-to-char (nth 2 descr)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
469 ?1
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
470 (string-to-char (nth 2 descr)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
471 (nth 2 descr) (nth 2 descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
472 (nth 0 descr)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
473 (string-to-int (nth 1 descr)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
474 (current-buffer))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
475 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
476 (ding)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
477 (url-warn 'security "Aborting connection to bad port...")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
478
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
479 (provide 'url-gopher)