annotate lisp/net/socks.el @ 102651:7040f7fa8fef

(sc-version): Doc fix.
author Glenn Morris <rgm@gnu.org>
date Thu, 19 Mar 2009 06:19:24 +0000
parents a9dc0e7c3f2b
children f8ba8d6fd250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; socks.el --- A Socks v5 Client for Emacs
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94677
diff changeset
4 ;; 2007, 2008, 2009 Free Software Foundation, Inc.
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6 ;; Author: William M. Perry <wmperry@gnu.org>
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; Dave Love <fx@gnu.org>
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 ;; Keywords: comm, firewalls
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92692
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92692
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92692
diff changeset
15 ;; (at your option) any later version.
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92692
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;;; Commentary:
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; This is an implementation of the SOCKS v5 protocol as defined in
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; RFC 1928.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; TODO
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; - Finish the redirection rules stuff
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; - Implement composition of servers. Recursively evaluate the
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; redirection rules and do SOCKS-over-HTTP and SOCKS-in-SOCKS
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 (eval-when-compile
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 (require 'wid-edit))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 (require 'custom)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 (if (not (fboundp 'split-string))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 (defun split-string (string &optional pattern)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 "Return a list of substrings of STRING which are separated by PATTERN.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 (or pattern
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 (setq pattern "[ \f\t\n\r\v]+"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 (let (parts (start 0))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 (while (string-match pattern string start)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 (setq parts (cons (substring string start (match-beginning 0)) parts)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 start (match-end 0)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 (nreverse (cons (substring string start) parts)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 ;;; Custom widgets
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 (define-widget 'dynamic-choice 'menu-choice
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 "A pretty simple dynamic dropdown list"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 :format "%[%t%]: %v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 :tag "Network"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 :case-fold t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 :void '(item :format "invalid (%t)\n")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 :value-create 's5-widget-value-create
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 :value-delete 'widget-children-value-delete
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 :value-get 'widget-choice-value-get
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 :value-inline 'widget-choice-value-inline
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 :mouse-down-action 'widget-choice-mouse-down-action
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 :action 'widget-choice-action
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 :error "Make a choice"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 :validate 'widget-choice-validate
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 :match 's5-dynamic-choice-match
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 :match-inline 's5-dynamic-choice-match-inline)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 (defun s5-dynamic-choice-match (widget value)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 (let ((choices (funcall (widget-get widget :choice-function)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 current found)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 (while (and choices (not found))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 (setq current (car choices)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 choices (cdr choices)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 found (widget-apply current :match value)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 found))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 (defun s5-dynamic-choice-match-inline (widget value)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 (let ((choices (funcall (widget-get widget :choice-function)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 current found)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 (while (and choices (not found))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 (setq current (car choices)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 choices (cdr choices)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 found (widget-match-inline current value)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 found))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 (defun s5-widget-value-create (widget)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 (let ((choices (funcall (widget-get widget :choice-function)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 (value (widget-get widget :value)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 (if (not value)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 (widget-put widget :value (widget-value (car choices))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 (widget-put widget :args choices)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 (widget-choice-value-create widget)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 ;;; Customization support
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 (defgroup socks nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 "SOCKS Support"
80261
4af0bb174714 * textmodes/css-mode.el (css-indent-offset, css-electric-keys):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 79714
diff changeset
101 :version "22.2"
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 :prefix "socks-"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 :group 'processes)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 '(defcustom socks-server-aliases nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 "A list of server aliases for use in access control and filtering rules."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 :group 'socks
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 :type '(repeat (list :format "%v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 :value ("" "" 1080 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 (string :tag "Alias")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 (string :tag "Hostname/IP Address")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 (integer :tag "Port #")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 (choice :tag "SOCKS Version"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 (integer :tag "SOCKS v4" :value 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 (integer :tag "SOCKS v5" :value 5)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 '(defcustom socks-network-aliases
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 '(("Anywhere" (netmask "0.0.0.0" "0.0.0.0")))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 "A list of network aliases for use in subsequent rules."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 :group 'socks
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 :type '(repeat (list :format "%v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 :value (netmask "" "255.255.255.0")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 (string :tag "Alias")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 (radio-button-choice
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 :format "%v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 (list :tag "IP address range"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 (const :format "" :value range)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 (string :tag "From")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 (string :tag "To"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 (list :tag "IP address/netmask"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 (const :format "" :value netmask)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 (string :tag "IP Address")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 (string :tag "Netmask"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 (list :tag "Domain Name"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 (const :format "" :value domain)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 (string :tag "Domain name"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 (list :tag "Unique hostname/IP address"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (const :format "" :value exact)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 (string :tag "Hostname/IP Address"))))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 '(defun s5-servers-filter ()
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 (if socks-server-aliases
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 (mapcar (lambda (x) (list 'const :tag (car x) :value (car x))) s5-server-aliases)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 '((const :tag "No aliases defined" :value nil))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 '(defun s5-network-aliases-filter ()
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (mapcar (lambda (x) (list 'const :tag (car x) :value (car x)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 socks-network-aliases))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 '(defcustom socks-redirection-rules
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 "A list of redirection rules."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 :group 'socks
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 :type '(repeat (list :format "%v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 :value ("Anywhere" nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 (dynamic-choice :choice-function s5-network-aliases-filter
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 :tag "Destination network")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (radio-button-choice
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 :tag "Connection type"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 (const :tag "Direct connection" :value nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 (dynamic-choice :format "%t: %[%v%]"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 :choice-function s5-servers-filter
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 :tag "Proxy chain via")))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 (defcustom socks-server
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 (list "Default server" "socks" 1080 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 ""
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 :group 'socks
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 :type '(list
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 (string :format "" :value "Default server")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (string :tag "Server")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 (integer :tag "Port")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 (radio-button-choice :tag "SOCKS Version"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 :format "%t: %v"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 (const :tag "SOCKS v4 " :format "%t" :value 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 (const :tag "SOCKS v5" :format "%t" :value 5))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 ;;; Get down to the nitty gritty
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 (defconst socks-version 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 (defvar socks-debug nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 ;; Common socks v5 commands
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 (defconst socks-connect-command 1)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 (defconst socks-bind-command 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 (defconst socks-udp-associate-command 3)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 ;; Miscellaneous other socks constants
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 (defconst socks-authentication-null 0)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 (defconst socks-authentication-failure 255)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 ;; Response codes
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 (defconst socks-response-success 0)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (defconst socks-response-general-failure 1)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 (defconst socks-response-access-denied 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 (defconst socks-response-network-unreachable 3)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 (defconst socks-response-host-unreachable 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (defconst socks-response-connection-refused 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 (defconst socks-response-ttl-expired 6)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (defconst socks-response-cmd-not-supported 7)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 (defconst socks-response-address-not-supported 8)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 (defvar socks-errors
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 '("Succeeded"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 "General SOCKS server failure"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 "Connection not allowed by ruleset"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 "Network unreachable"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 "Host unreachable"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 "Connection refused"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 "Time-to-live expired"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 "Command not supported"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 "Address type not supported"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 ;; The socks v5 address types
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 (defconst socks-address-type-v4 1)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 (defconst socks-address-type-name 3)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 (defconst socks-address-type-v6 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 ;; Base variables
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 (defvar socks-timeout 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 (defvar socks-connections (make-hash-table :size 13))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 ;; Miscellaneous stuff for authentication
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 (defvar socks-authentication-methods nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (defvar socks-username (user-login-name))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 (defvar socks-password nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (defun socks-register-authentication-method (id desc callback)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (let ((old (assq id socks-authentication-methods)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (if old
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (setcdr old (cons desc callback))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (setq socks-authentication-methods
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (cons (cons id (cons desc callback))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 socks-authentication-methods)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 (defun socks-unregister-authentication-method (id)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 (let ((old (assq id socks-authentication-methods)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (if old
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (setq socks-authentication-methods
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (delq old socks-authentication-methods)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 (socks-register-authentication-method 0 "No authentication" 'identity)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 (defun socks-build-auth-list ()
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 (let ((num 0)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 (retval ""))
85226
716b4c75ab5f (socks-build-auth-list): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84644
diff changeset
249 (mapc
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 (function
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 (lambda (x)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252 (if (fboundp (cdr (cdr x)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 (setq retval (format "%s%c" retval (car x))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254 num (1+ num)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 (reverse socks-authentication-methods))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 (format "%c%s" num retval)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 (defconst socks-state-waiting-for-auth 0)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 (defconst socks-state-submethod-negotiation 1)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
260 (defconst socks-state-authenticated 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
261 (defconst socks-state-waiting 3)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
262 (defconst socks-state-connected 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
263
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
264 (defmacro socks-wait-for-state-change (proc htable cur-state)
78635
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
265 `(while (and (= (gethash 'state ,htable) ,cur-state)
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
266 (memq (process-status ,proc) '(run open)))
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
267 (accept-process-output ,proc socks-timeout)))
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
268
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
269 (defun socks-filter (proc string)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 (let ((info (gethash proc socks-connections))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271 state version desired-len)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
272 (or info (error "socks-filter called on non-SOCKS connection %S" proc))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273 (setq state (gethash 'state info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275 ((= state socks-state-waiting-for-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
276 (puthash 'scratch (concat string (gethash 'scratch info)) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
277 (setq string (gethash 'scratch info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278 (if (< (length string) 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 nil ; We need to spin some more
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 (puthash 'authtype (aref string 1) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281 (puthash 'scratch (substring string 2 nil) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282 (puthash 'state socks-state-submethod-negotiation info)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 ((= state socks-state-submethod-negotiation)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 ((= state socks-state-authenticated)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287 ((= state socks-state-waiting)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 (puthash 'scratch (concat string (gethash 'scratch info)) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 (setq string (gethash 'scratch info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290 (setq version (gethash 'server-protocol info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 ((equal version 'http)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 (if (not (string-match "\r\n\r\n" string))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
294 nil ; Need to spin some more
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295 (puthash 'state socks-state-connected info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
296 (puthash 'reply 0 info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
297 (puthash 'response string info)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
298 ((equal version 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 (if (< (length string) 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 nil ; Can't know how much to read yet
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301 (setq desired-len
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 (+ 4 ; address length
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303 2 ; port
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304 2 ; initial data
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 ))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306 (if (< (length string) desired-len)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 nil ; need to spin some more
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 (let ((response (aref string 1)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309 (if (= response 90)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 (setq response 0))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
311 (puthash 'state socks-state-connected info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
312 (puthash 'reply response info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (puthash 'response string info)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314 ((equal version 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 (if (< (length string) 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316 nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 (setq desired-len
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318 (+ 6 ; Standard socks header
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320 ((= (aref string 3) socks-address-type-v4) 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 ((= (aref string 3) socks-address-type-v6) 16)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
322 ((= (aref string 3) socks-address-type-name)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 (if (< (length string) 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 255
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 (+ 1 (aref string 4)))))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 (if (< (length string) desired-len)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327 nil ; Need to spin some more
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 (puthash 'state socks-state-connected info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329 (puthash 'reply (aref string 1) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 (puthash 'response string info))))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331 ((= state socks-state-connected)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336
86534
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
337 (declare-function socks-original-open-network-stream "socks") ; fset
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
338
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
339 (defvar socks-override-functions nil
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
340 "*Whether to overwrite the open-network-stream function with the SOCKSified
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
341 version.")
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
342
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
343 (if (fboundp 'socks-original-open-network-stream)
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
344 nil ; Do nothing, we've been here already
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
345 (defalias 'socks-original-open-network-stream
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
346 (symbol-function 'open-network-stream))
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
347 (if socks-override-functions
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
348 (defalias 'open-network-stream 'socks-open-network-stream)))
1863c4982b31 (socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents: 85226
diff changeset
349
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 (defun socks-open-connection (server-info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351 (interactive)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 (save-excursion
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 (let ((proc (socks-original-open-network-stream "socks"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355 (nth 1 server-info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 (nth 2 server-info)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357 (info (make-hash-table :size 13))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358 (authtype nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 version)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361 ;; Initialize process and info about the process
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 (set-process-filter proc 'socks-filter)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 (set-process-query-on-exit-flag proc nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 (puthash proc info socks-connections)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365 (puthash 'state socks-state-waiting-for-auth info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 (puthash 'authtype socks-authentication-failure info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 (puthash 'server-protocol (nth 3 server-info) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368 (puthash 'server-name (nth 1 server-info) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 (setq version (nth 3 server-info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 ((equal version 'http)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372 ;; Don't really have to do any connection setup under http
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373 nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374 ((equal version 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 ;; Don't really have to do any connection setup under v4
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377 ((equal version 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 ;; Need to handle all the authentication crap under v5
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 ;; Send what we think we can handle for authentication types
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380 (process-send-string proc (format "%c%s" socks-version
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 (socks-build-auth-list)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383 ;; Basically just do a select() until we change states.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 (socks-wait-for-state-change proc info socks-state-waiting-for-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 (setq authtype (gethash 'authtype info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387 ((= authtype socks-authentication-null)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 (and socks-debug (message "No authentication necessary")))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389 ((= authtype socks-authentication-failure)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 (error "No acceptable authentication methods found."))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 (t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 (let* ((auth-type (gethash 'authtype info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 (auth-handler (assoc auth-type socks-authentication-methods))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 (auth-func (and auth-handler (cdr (cdr auth-handler))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395 (auth-desc (and auth-handler (car (cdr auth-handler)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 (set-process-filter proc nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397 (if (and auth-func (fboundp auth-func)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
398 (funcall auth-func proc))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 nil ; We succeeded!
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400 (delete-process proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 (error "Failed to use auth method: %s (%d)"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402 (or auth-desc "Unknown") auth-type))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 )
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 (puthash 'state socks-state-authenticated info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 (set-process-filter proc 'socks-filter)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 proc)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 (defun socks-send-command (proc command atype address port)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 (let ((addr (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 ((or (= atype socks-address-type-v4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413 (= atype socks-address-type-v6))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 address)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415 ((= atype socks-address-type-name)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 (format "%c%s" (length address) address))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417 (t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418 (error "Unkown address type: %d" atype))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 (info (gethash proc socks-connections))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 request version)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 (or info (error "socks-send-command called on non-SOCKS connection %S"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 proc))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423 (puthash 'state socks-state-waiting info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 (setq version (gethash 'server-protocol info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 ((equal version 'http)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427 (setq request (format (eval-when-compile
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 (concat
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 "CONNECT %s:%d HTTP/1.0\r\n"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 "User-Agent: Emacs/SOCKS v1.0\r\n"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 "\r\n"))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 ((equal atype socks-address-type-name) address)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 (t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 (error "Unsupported address type for HTTP: %d" atype)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436 port)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 ((equal version 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438 (setq request (format
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 "%c%c%c%c%s%s%c"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 version ; version
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 command ; command
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442 (lsh port -8) ; port, high byte
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 (- port (lsh (lsh port -8) 8)) ; port, low byte
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444 addr ; address
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 (user-full-name) ; username
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 0 ; terminate username
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 )))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448 ((equal version 5)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 (setq request (format
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450 "%c%c%c%c%s%c%c"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 version ; version
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452 command ; command
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 0 ; reserved
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454 atype ; address type
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455 addr ; address
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456 (lsh port -8) ; port, high byte
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457 (- port (lsh (lsh port -8) 8)) ; port, low byte
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 )))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 (t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460 (error "Unknown protocol version: %d" version)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 (process-send-string proc request)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 (socks-wait-for-state-change proc info socks-state-waiting)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
463 (process-status proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 (if (= (or (gethash 'reply info) 1) socks-response-success)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 nil ; Sweet sweet success!
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 (delete-process proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467 (error "SOCKS: %s" (nth (or (gethash 'reply info) 1) socks-errors)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 proc))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
469
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 ;; Replacement functions for open-network-stream, etc.
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472 (defvar socks-noproxy nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 "*List of regexps matching hosts that we should not socksify connections to")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 (defun socks-find-route (host service)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
476 (let ((route socks-server)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
477 (noproxy socks-noproxy))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
478 (while noproxy
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
479 (if (eq ?! (aref (car noproxy) 0))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
480 (if (string-match (substring (car noproxy) 1) host)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
481 (setq noproxy nil))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
482 (if (string-match (car noproxy) host)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
483 (setq route nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
484 noproxy nil)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
485 (setq noproxy (cdr noproxy)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
486 route))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
487
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
488 (defvar socks-services-file "/etc/services")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
489 (defvar socks-tcp-services (make-hash-table :size 13 :test 'equal))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
490 (defvar socks-udp-services (make-hash-table :size 13 :test 'equal))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
491
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
492 (defun socks-parse-services ()
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
493 (if (not (and (file-exists-p socks-services-file)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
494 (file-readable-p socks-services-file)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
495 (error "Could not find services file: %s" socks-services-file))
78635
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
496 (clrhash socks-tcp-services)
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
497 (clrhash socks-udp-services)
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
498 (with-current-buffer (get-buffer-create " *socks-tmp*")
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
499 (erase-buffer)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
500 (insert-file-contents socks-services-file)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
501 ;; Nuke comments
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
502 (goto-char (point-min))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
503 (while (re-search-forward "#.*" nil t)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
504 (replace-match ""))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
505 ;; Nuke empty lines
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
506 (goto-char (point-min))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
507 (while (re-search-forward "^[ \t\n]+" nil t)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
508 (replace-match ""))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
509 ;; Now find all the lines
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
510 (goto-char (point-min))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
511 (let (name port type)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
512 (while (re-search-forward "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)/\\([a-z]+\\)"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
513 nil t)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
514 (setq name (downcase (match-string 1))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
515 port (string-to-number (match-string 2))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
516 type (downcase (match-string 3)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
517 (puthash name port (if (equal type "udp")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
518 socks-udp-services
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
519 socks-tcp-services))))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
520
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
521 (defun socks-find-services-entry (service &optional udp)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
522 "Return the port # associated with SERVICE"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
523 (if (= (hash-table-count socks-tcp-services) 0)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
524 (socks-parse-services))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
525 (gethash (downcase service)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
526 (if udp socks-udp-services socks-tcp-services)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
527
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
528 (defun socks-open-network-stream (name buffer host service)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
529 (let* ((route (socks-find-route host service))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
530 proc info version atype)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
531 (if (not route)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
532 (socks-original-open-network-stream name buffer host service)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
533 (setq proc (socks-open-connection route)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
534 info (gethash proc socks-connections)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
535 version (gethash 'server-protocol info))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
536 (cond
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
537 ((equal version 4)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
538 (setq host (socks-nslookup-host host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
539 (if (not (listp host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
540 (error "Could not get IP address for: %s" host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
541 (setq host (apply 'format "%c%c%c%c" host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
542 (setq atype socks-address-type-v4))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
543 (t
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
544 (setq atype socks-address-type-name)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
545 (socks-send-command proc
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
546 socks-connect-command
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
547 atype
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
548 host
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
549 (if (stringp service)
84643
9cf2bf22d7ee (socks-open-network-stream): Signal an explicit error if the port
Glenn Morris <rgm@gnu.org>
parents: 82907
diff changeset
550 (or
9cf2bf22d7ee (socks-open-network-stream): Signal an explicit error if the port
Glenn Morris <rgm@gnu.org>
parents: 82907
diff changeset
551 (socks-find-services-entry service)
84644
630c599116d6 (socks-open-network-stream): Standardize error message from previous
Glenn Morris <rgm@gnu.org>
parents: 84643
diff changeset
552 (error "Unknown service: %s" service))
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
553 service))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
554 (puthash 'buffer buffer info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
555 (puthash 'host host info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
556 (puthash 'service host info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
557 (set-process-filter proc nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
558 (set-process-buffer proc (if buffer (get-buffer-create buffer)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
559 proc)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
560
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
561 ;; Authentication modules go here
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
562
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
563 ;; Basic username/password authentication, ala RFC 1929
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
564 (socks-register-authentication-method 2 "Username/Password"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
565 'socks-username/password-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
566
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
567 (defconst socks-username/password-auth-version 1)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
568
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
569 (defun socks-username/password-auth-filter (proc str)
78635
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
570 (let ((info (gethash proc socks-connections)))
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
571 (or info (error "socks-filter called on non-SOCKS connection %S" proc))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
572 (puthash 'scratch (concat (gethash 'scratch info) str) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
573 (if (< (length (gethash 'scratch info)) 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
574 nil
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
575 (puthash 'password-auth-status (aref (gethash 'scratch info) 1) info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
576 (puthash 'state socks-state-authenticated info))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
577
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
578 (defun socks-username/password-auth (proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
579 (let* ((info (gethash proc socks-connections))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
580 (state (gethash 'state info)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
581 (if (not socks-password)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
582 (setq socks-password (read-passwd
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
583 (format "Password for %s@%s: "
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
584 socks-username
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
585 (gethash 'server-name info)))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
586 (puthash 'scratch "" info)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
587 (set-process-filter proc 'socks-username/password-auth-filter)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
588 (process-send-string proc
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
589 (format "%c%c%s%c%s"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
590 socks-username/password-auth-version
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
591 (length socks-username)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
592 socks-username
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
593 (length socks-password)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
594 socks-password))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
595 (socks-wait-for-state-change proc info state)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
596 (= (gethash 'password-auth-status info) 0)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
597
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
598
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
599 ;; More advanced GSS/API stuff, not yet implemented - volunteers?
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
600 ;; (socks-register-authentication-method 1 "GSS/API" 'socks-gssapi-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
601
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
602 (defun socks-gssapi-auth (proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
603 nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
604
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
605
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
606 ;; CHAP stuff
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
607 ;; (socks-register-authentication-method 3 "CHAP" 'socks-chap-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
608 (defun socks-chap-auth (proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
609 nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
610
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
611
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
612 ;; CRAM stuff
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
613 ;; (socks-register-authentication-method 5 "CRAM" 'socks-cram-auth)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
614 (defun socks-cram-auth (proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
615 nil)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
616
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
617
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
618 (defcustom socks-nslookup-program "nslookup"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
619 "*If non-NIL then a string naming the nslookup program."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
620 :type '(choice (const :tag "None" :value nil) string)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
621 :group 'socks)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
622
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
623 (defun socks-nslookup-host (host)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
624 "Attempt to resolve the given HOSTNAME using nslookup if possible."
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
625 (interactive "sHost: ")
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
626 (if socks-nslookup-program
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
627 (let ((proc (start-process " *nslookup*" " *nslookup*"
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
628 socks-nslookup-program host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
629 (res host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
630 (set-process-query-on-exit-flag proc nil)
78635
65b448298f0c (socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78230
diff changeset
631 (with-current-buffer (process-buffer proc)
77921
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
632 (while (progn
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
633 (accept-process-output proc)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
634 (memq (process-status proc) '(run open))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
635 (goto-char (point-min))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
636 (if (re-search-forward "Name:.*\nAddress\\(es\\)?: *\\([0-9.]+\\)$" nil t)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
637 (progn
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
638 (setq res (buffer-substring (match-beginning 2)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
639 (match-end 2))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
640 res (mapcar 'string-to-int (split-string res "\\.")))))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
641 (kill-buffer (current-buffer)))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
642 res)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
643 host))
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
644
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
645 (provide 'socks)
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
646
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
647 ;; arch-tag: 67aef0d9-f4f7-4056-89c3-b4c9bf93ce7f
9a33ca5607a2 New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
648 ;;; socks.el ends here