Mercurial > emacs
annotate lisp/net/socks.el @ 80662:11132aa5cccf
(abbreviate-file-name): When replacing $HOME with ~, turn off
case-fold-search.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Thu, 31 Jul 2008 21:12:21 +0000 |
parents | 4af0bb174714 |
children | d999f30304bc |
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, |
79714 | 4 ;; 2007, 2008 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 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
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 |
78230
84cf1e2214c5
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77921
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; any later version. |
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 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 ;; Boston, MA 02110-1301, USA. |
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 ;;; Commentary: |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 ;; 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
|
30 ;; RFC 1928. |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 ;; TODO |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 ;; - Finish the redirection rules stuff |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 ;; - Implement composition of servers. Recursively evaluate the |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 ;; 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
|
36 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 (eval-when-compile |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 (require 'wid-edit)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 (require 'custom) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 (if (not (fboundp 'split-string)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 (defun split-string (string &optional pattern) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 "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
|
44 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
|
45 (or pattern |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 (setq pattern "[ \f\t\n\r\v]+")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 (let (parts (start 0)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 (while (string-match pattern string start) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 (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
|
50 start (match-end 0))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 (nreverse (cons (substring string start) parts))))) |
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 ;;; Custom widgets |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 (define-widget 'dynamic-choice 'menu-choice |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 "A pretty simple dynamic dropdown list" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 :format "%[%t%]: %v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 :tag "Network" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 :case-fold t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 :void '(item :format "invalid (%t)\n") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 :value-create 's5-widget-value-create |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 :value-delete 'widget-children-value-delete |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 :value-get 'widget-choice-value-get |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 :value-inline 'widget-choice-value-inline |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 :mouse-down-action 'widget-choice-mouse-down-action |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 :action 'widget-choice-action |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 :error "Make a choice" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 :validate 'widget-choice-validate |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 :match 's5-dynamic-choice-match |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 :match-inline 's5-dynamic-choice-match-inline) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 (defun s5-dynamic-choice-match (widget value) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 (let ((choices (funcall (widget-get widget :choice-function))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 current found) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 (while (and choices (not found)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (setq current (car choices) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 choices (cdr choices) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 found (widget-apply current :match value))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 found)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 (defun s5-dynamic-choice-match-inline (widget value) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 (let ((choices (funcall (widget-get widget :choice-function))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 current found) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 (while (and choices (not found)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 (setq current (car choices) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 choices (cdr choices) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 found (widget-match-inline current value))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 found)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 (defun s5-widget-value-create (widget) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 (let ((choices (funcall (widget-get widget :choice-function))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 (value (widget-get widget :value))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 (if (not value) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (widget-put widget :value (widget-value (car choices)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 (widget-put widget :args choices) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 (widget-choice-value-create widget))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 |
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 ;;; Customization support |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 (defgroup socks nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 "SOCKS Support" |
80261
4af0bb174714
* textmodes/css-mode.el (css-indent-offset, css-electric-keys):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79714
diff
changeset
|
103 :version "22.2" |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 :prefix "socks-" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 :group 'processes) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 '(defcustom socks-server-aliases nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 "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
|
109 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 :value ("" "" 1080 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 (string :tag "Alias") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 (string :tag "Hostname/IP Address") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 (integer :tag "Port #") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (choice :tag "SOCKS Version" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 (integer :tag "SOCKS v4" :value 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 (integer :tag "SOCKS v5" :value 5))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 '(defcustom socks-network-aliases |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 '(("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
|
121 "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
|
122 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 :value (netmask "" "255.255.255.0") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (string :tag "Alias") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (radio-button-choice |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (list :tag "IP address range" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (const :format "" :value range) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (string :tag "From") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (string :tag "To")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 (list :tag "IP address/netmask" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 (const :format "" :value netmask) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 (string :tag "IP Address") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 (string :tag "Netmask")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (list :tag "Domain Name" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (const :format "" :value domain) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (string :tag "Domain name")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 (list :tag "Unique hostname/IP address" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 (const :format "" :value exact) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 (string :tag "Hostname/IP Address")))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 '(defun s5-servers-filter () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (if socks-server-aliases |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (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
|
146 '((const :tag "No aliases defined" :value nil)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 '(defun s5-network-aliases-filter () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 (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
|
150 socks-network-aliases)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 '(defcustom socks-redirection-rules |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 "A list of redirection rules." |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 :value ("Anywhere" nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 (dynamic-choice :choice-function s5-network-aliases-filter |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 :tag "Destination network") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 (radio-button-choice |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 :tag "Connection type" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 (const :tag "Direct connection" :value nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 (dynamic-choice :format "%t: %[%v%]" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 :choice-function s5-servers-filter |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 :tag "Proxy chain via"))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 (defcustom socks-server |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 (list "Default server" "socks" 1080 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 "" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 :type '(list |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 (string :format "" :value "Default server") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 (string :tag "Server") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 (integer :tag "Port") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 (radio-button-choice :tag "SOCKS Version" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 :format "%t: %v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 (const :tag "SOCKS v4 " :format "%t" :value 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 (const :tag "SOCKS v5" :format "%t" :value 5)))) |
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 |
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 ;;; Get down to the nitty gritty |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (defconst socks-version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 (defvar socks-debug nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 ;; Common socks v5 commands |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 (defconst socks-connect-command 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 (defconst socks-bind-command 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 (defconst socks-udp-associate-command 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 ;; Miscellaneous other socks constants |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (defconst socks-authentication-null 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 (defconst socks-authentication-failure 255) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 ;; Response codes |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 (defconst socks-response-success 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 (defconst socks-response-general-failure 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 (defconst socks-response-access-denied 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 (defconst socks-response-network-unreachable 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 (defconst socks-response-host-unreachable 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 (defconst socks-response-connection-refused 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 (defconst socks-response-ttl-expired 6) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 (defconst socks-response-cmd-not-supported 7) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 (defconst socks-response-address-not-supported 8) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 (defvar socks-errors |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 '("Succeeded" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 "General SOCKS server failure" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 "Connection not allowed by ruleset" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 "Network unreachable" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 "Host unreachable" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 "Connection refused" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 "Time-to-live expired" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 "Command not supported" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 "Address type not supported")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 ;; The socks v5 address types |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 (defconst socks-address-type-v4 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 (defconst socks-address-type-name 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (defconst socks-address-type-v6 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 ;; Base variables |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 (defvar socks-timeout 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 (defvar socks-connections (make-hash-table :size 13)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 ;; Miscellaneous stuff for authentication |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 (defvar socks-authentication-methods nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 (defvar socks-username (user-login-name)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 (defvar socks-password nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (defun socks-register-authentication-method (id desc callback) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (let ((old (assq id socks-authentication-methods))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 (if old |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (setcdr old (cons desc callback)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (setq socks-authentication-methods |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 (cons (cons id (cons desc callback)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 socks-authentication-methods))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 (defun socks-unregister-authentication-method (id) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 (let ((old (assq id socks-authentication-methods))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 (if old |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 (setq socks-authentication-methods |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 (delq old socks-authentication-methods))))) |
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 (socks-register-authentication-method 0 "No authentication" 'identity) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 (defun socks-build-auth-list () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (let ((num 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 (retval "")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 (mapcar |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 (function |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 (lambda (x) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 (if (fboundp (cdr (cdr x))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 (setq retval (format "%s%c" retval (car x)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 num (1+ num))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 (reverse socks-authentication-methods)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 (format "%c%s" num retval))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 (defconst socks-state-waiting-for-auth 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 (defconst socks-state-submethod-negotiation 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 (defconst socks-state-authenticated 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 (defconst socks-state-waiting 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 (defconst socks-state-connected 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 (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
|
267 `(while (and (= (gethash 'state ,htable) ,cur-state) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
268 (memq (process-status ,proc) '(run open))) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
269 (accept-process-output ,proc socks-timeout))) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 (defun socks-filter (proc string) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 (let ((info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 state version desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 (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
|
275 (setq state (gethash 'state info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 ((= state socks-state-waiting-for-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (puthash 'scratch (concat string (gethash 'scratch info)) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 (setq string (gethash 'scratch info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 (if (< (length string) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 nil ; We need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 (puthash 'authtype (aref string 1) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 (puthash 'scratch (substring string 2 nil) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 (puthash 'state socks-state-submethod-negotiation info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 ((= state socks-state-submethod-negotiation) |
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-authenticated) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 ((= state socks-state-waiting) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 (puthash 'scratch (concat string (gethash 'scratch info)) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 (setq string (gethash 'scratch info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 (setq version (gethash 'server-protocol info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 (if (not (string-match "\r\n\r\n" string)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 nil ; Need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 (puthash 'reply 0 info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 (puthash 'response string info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 (if (< (length string) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 nil ; Can't know how much to read yet |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 (setq desired-len |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 (+ 4 ; address length |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 2 ; port |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 2 ; initial data |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 )) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 (if (< (length string) desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 nil ; need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 (let ((response (aref string 1))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 (if (= response 90) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 (setq response 0)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 (puthash 'reply response info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 (puthash 'response string info))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 ((equal version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 (if (< (length string) 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 (setq desired-len |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 (+ 6 ; Standard socks header |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 ((= (aref string 3) socks-address-type-v4) 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 ((= (aref string 3) socks-address-type-v6) 16) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 ((= (aref string 3) socks-address-type-name) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 (if (< (length string) 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 255 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 (+ 1 (aref string 4))))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 (if (< (length string) desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 nil ; Need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 (puthash 'reply (aref string 1) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 (puthash 'response string info)))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 ((= state socks-state-connected) |
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 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 (defun socks-open-connection (server-info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 (interactive) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 (save-excursion |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 (let ((proc (socks-original-open-network-stream "socks" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 (nth 1 server-info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 (nth 2 server-info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 (info (make-hash-table :size 13)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
347 (authtype nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
348 version) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
349 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
350 ;; Initialize process and info about the process |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 (set-process-filter proc 'socks-filter) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 (set-process-query-on-exit-flag proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (puthash proc info socks-connections) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 (puthash 'state socks-state-waiting-for-auth info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 (puthash 'authtype socks-authentication-failure info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 (puthash 'server-protocol (nth 3 server-info) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 (puthash 'server-name (nth 1 server-info) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 (setq version (nth 3 server-info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
359 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 ;; 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
|
362 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 ;; 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
|
365 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 ((equal version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
367 ;; Need to handle all the authentication crap under v5 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
368 ;; 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
|
369 (process-send-string proc (format "%c%s" socks-version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
370 (socks-build-auth-list))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 ;; Basically just do a select() until we change states. |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 (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
|
374 (setq authtype (gethash 'authtype info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
375 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 ((= authtype socks-authentication-null) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
377 (and socks-debug (message "No authentication necessary"))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 ((= authtype socks-authentication-failure) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 (error "No acceptable authentication methods found.")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
381 (let* ((auth-type (gethash 'authtype info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
382 (auth-handler (assoc auth-type socks-authentication-methods)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 (auth-func (and auth-handler (cdr (cdr auth-handler)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
384 (auth-desc (and auth-handler (car (cdr auth-handler))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 (set-process-filter proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
386 (if (and auth-func (fboundp auth-func) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
387 (funcall auth-func proc)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
388 nil ; We succeeded! |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
389 (delete-process proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 (error "Failed to use auth method: %s (%d)" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
391 (or auth-desc "Unknown") auth-type)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 (puthash 'state socks-state-authenticated info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
396 (set-process-filter proc 'socks-filter))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
397 proc))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
398 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 (defun socks-send-command (proc command atype address port) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
400 (let ((addr (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
401 ((or (= atype socks-address-type-v4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
402 (= atype socks-address-type-v6)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
403 address) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
404 ((= atype socks-address-type-name) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 (format "%c%s" (length address) address)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
406 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
407 (error "Unkown address type: %d" atype)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 (info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 request version) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 (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
|
411 proc)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 (puthash 'state socks-state-waiting info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
413 (setq version (gethash 'server-protocol info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
414 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 (setq request (format (eval-when-compile |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 (concat |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 "CONNECT %s:%d HTTP/1.0\r\n" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
419 "User-Agent: Emacs/SOCKS v1.0\r\n" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 "\r\n")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 ((equal atype socks-address-type-name) address) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
423 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 (error "Unsupported address type for HTTP: %d" atype))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
425 port))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
426 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
427 (setq request (format |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
428 "%c%c%c%c%s%s%c" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
429 version ; version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
430 command ; command |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 (lsh port -8) ; port, high byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 (- port (lsh (lsh port -8) 8)) ; port, low byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 addr ; address |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
434 (user-full-name) ; username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
435 0 ; terminate username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 ))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 ((equal version 5) |
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%c%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 0 ; reserved |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 atype ; address type |
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 (lsh port -8) ; port, high byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 (- port (lsh (lsh port -8) 8)) ; port, low byte |
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 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
449 (error "Unknown protocol version: %d" version))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 (process-send-string proc request) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 (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
|
452 (process-status proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 (if (= (or (gethash 'reply info) 1) socks-response-success) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
454 nil ; Sweet sweet success! |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
455 (delete-process proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
456 (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
|
457 proc)) |
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 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
460 ;; Replacement functions for open-network-stream, etc. |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
461 (defvar socks-noproxy nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
462 "*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
|
463 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
464 (defun socks-find-route (host service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 (let ((route socks-server) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 (noproxy socks-noproxy)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 (while noproxy |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 (if (eq ?! (aref (car noproxy) 0)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
469 (if (string-match (substring (car noproxy) 1) host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 (setq noproxy nil)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 (if (string-match (car noproxy) host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 (setq route nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 noproxy nil))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 (setq noproxy (cdr noproxy))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
475 route)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (defvar socks-override-functions nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 "*Whether to overwrite the open-network-stream function with the SOCKSified |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
479 version.") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
481 (if (fboundp 'socks-original-open-network-stream) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
482 nil ; Do nothing, we've been here already |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
483 (defalias 'socks-original-open-network-stream |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
484 (symbol-function 'open-network-stream)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
485 (if socks-override-functions |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
486 (defalias 'open-network-stream 'socks-open-network-stream))) |
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) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
550 (socks-find-services-entry service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
551 service)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
552 (puthash 'buffer buffer info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
553 (puthash 'host host info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
554 (puthash 'service host info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
555 (set-process-filter proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
556 (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
|
557 proc))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
558 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
559 ;; Authentication modules go here |
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 ;; Basic username/password authentication, ala RFC 1929 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
562 (socks-register-authentication-method 2 "Username/Password" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
563 'socks-username/password-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
564 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
565 (defconst socks-username/password-auth-version 1) |
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 (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
|
568 (let ((info (gethash proc socks-connections))) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
569 (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
|
570 (puthash 'scratch (concat (gethash 'scratch info) str) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
571 (if (< (length (gethash 'scratch info)) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
572 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
573 (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
|
574 (puthash 'state socks-state-authenticated info)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
575 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
576 (defun socks-username/password-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
577 (let* ((info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
578 (state (gethash 'state info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
579 (if (not socks-password) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
580 (setq socks-password (read-passwd |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
581 (format "Password for %s@%s: " |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
582 socks-username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
583 (gethash 'server-name info))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
584 (puthash 'scratch "" info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
585 (set-process-filter proc 'socks-username/password-auth-filter) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
586 (process-send-string proc |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
587 (format "%c%c%s%c%s" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
588 socks-username/password-auth-version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
589 (length socks-username) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
590 socks-username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
591 (length socks-password) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
592 socks-password)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
593 (socks-wait-for-state-change proc info state) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
594 (= (gethash 'password-auth-status info) 0))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
595 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
596 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
597 ;; More advanced GSS/API stuff, not yet implemented - volunteers? |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
598 ;; (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
|
599 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
600 (defun socks-gssapi-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
601 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
602 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
603 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
604 ;; CHAP stuff |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
605 ;; (socks-register-authentication-method 3 "CHAP" 'socks-chap-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
606 (defun socks-chap-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
607 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
608 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
609 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
610 ;; CRAM stuff |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
611 ;; (socks-register-authentication-method 5 "CRAM" 'socks-cram-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
612 (defun socks-cram-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
613 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
614 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
615 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
616 (defcustom socks-nslookup-program "nslookup" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
617 "*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
|
618 :type '(choice (const :tag "None" :value nil) string) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
619 :group 'socks) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
620 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
621 (defun socks-nslookup-host (host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
622 "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
|
623 (interactive "sHost: ") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
624 (if socks-nslookup-program |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
625 (let ((proc (start-process " *nslookup*" " *nslookup*" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
626 socks-nslookup-program host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
627 (res host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
628 (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
|
629 (with-current-buffer (process-buffer proc) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
630 (while (progn |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
631 (accept-process-output proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
632 (memq (process-status proc) '(run open)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
633 (goto-char (point-min)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
634 (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
|
635 (progn |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
636 (setq res (buffer-substring (match-beginning 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
637 (match-end 2)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
638 res (mapcar 'string-to-int (split-string res "\\."))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
639 (kill-buffer (current-buffer))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
640 res) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
641 host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
642 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
643 (provide 'socks) |
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 ;; arch-tag: 67aef0d9-f4f7-4056-89c3-b4c9bf93ce7f |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
646 ;;; socks.el ends here |