Mercurial > emacs
annotate lisp/net/socks.el @ 91589:12b2f1526656
* net/dbus.el (dbus-interface-peer): New defconst.
(dbus-ping): New defun.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Wed, 06 Feb 2008 20:54:19 +0000 |
parents | 107ccd98fa12 |
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" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 :prefix "socks-" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 :group 'processes) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 '(defcustom socks-server-aliases nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 "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
|
108 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 :value ("" "" 1080 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 (string :tag "Alias") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 (string :tag "Hostname/IP Address") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 (integer :tag "Port #") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 (choice :tag "SOCKS Version" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (integer :tag "SOCKS v4" :value 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 (integer :tag "SOCKS v5" :value 5))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 '(defcustom socks-network-aliases |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 '(("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
|
120 "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
|
121 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 :value (netmask "" "255.255.255.0") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 (string :tag "Alias") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (radio-button-choice |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 (list :tag "IP address range" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (const :format "" :value range) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (string :tag "From") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (string :tag "To")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (list :tag "IP address/netmask" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 (const :format "" :value netmask) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 (string :tag "IP Address") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 (string :tag "Netmask")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 (list :tag "Domain Name" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (const :format "" :value domain) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (string :tag "Domain name")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (list :tag "Unique hostname/IP address" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 (const :format "" :value exact) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 (string :tag "Hostname/IP Address")))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 '(defun s5-servers-filter () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 (if socks-server-aliases |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (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
|
145 '((const :tag "No aliases defined" :value nil)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 '(defun s5-network-aliases-filter () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 (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
|
149 socks-network-aliases)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 '(defcustom socks-redirection-rules |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 "A list of redirection rules." |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 :type '(repeat (list :format "%v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 :value ("Anywhere" nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 (dynamic-choice :choice-function s5-network-aliases-filter |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 :tag "Destination network") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 (radio-button-choice |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 :tag "Connection type" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 (const :tag "Direct connection" :value nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 (dynamic-choice :format "%t: %[%v%]" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 :choice-function s5-servers-filter |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 :tag "Proxy chain via"))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 (defcustom socks-server |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 (list "Default server" "socks" 1080 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 "" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 :group 'socks |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 :type '(list |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 (string :format "" :value "Default server") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 (string :tag "Server") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 (integer :tag "Port") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 (radio-button-choice :tag "SOCKS Version" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 :format "%t: %v" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 (const :tag "SOCKS v4 " :format "%t" :value 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 (const :tag "SOCKS v5" :format "%t" :value 5)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 ;;; Get down to the nitty gritty |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 (defconst socks-version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (defvar socks-debug nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 ;; Common socks v5 commands |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 (defconst socks-connect-command 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 (defconst socks-bind-command 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 (defconst socks-udp-associate-command 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 ;; Miscellaneous other socks constants |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 (defconst socks-authentication-null 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (defconst socks-authentication-failure 255) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 ;; Response codes |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 (defconst socks-response-success 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 (defconst socks-response-general-failure 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 (defconst socks-response-access-denied 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 (defconst socks-response-network-unreachable 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 (defconst socks-response-host-unreachable 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 (defconst socks-response-connection-refused 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 (defconst socks-response-ttl-expired 6) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 (defconst socks-response-cmd-not-supported 7) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 (defconst socks-response-address-not-supported 8) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 (defvar socks-errors |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 '("Succeeded" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 "General SOCKS server failure" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 "Connection not allowed by ruleset" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 "Network unreachable" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 "Host unreachable" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 "Connection refused" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 "Time-to-live expired" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 "Command not supported" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 "Address type not supported")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 ;; The socks v5 address types |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 (defconst socks-address-type-v4 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 (defconst socks-address-type-name 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 (defconst socks-address-type-v6 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 ;; Base variables |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 (defvar socks-timeout 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 (defvar socks-connections (make-hash-table :size 13)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 ;; Miscellaneous stuff for authentication |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 (defvar socks-authentication-methods nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 (defvar socks-username (user-login-name)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 (defvar socks-password nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 (defun socks-register-authentication-method (id desc callback) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (let ((old (assq id socks-authentication-methods))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (if old |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 (setcdr old (cons desc callback)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (setq socks-authentication-methods |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (cons (cons id (cons desc callback)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 socks-authentication-methods))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 (defun socks-unregister-authentication-method (id) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 (let ((old (assq id socks-authentication-methods))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 (if old |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 (setq socks-authentication-methods |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 (delq old socks-authentication-methods))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 (socks-register-authentication-method 0 "No authentication" 'identity) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 (defun socks-build-auth-list () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 (let ((num 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (retval "")) |
85226
716b4c75ab5f
(socks-build-auth-list): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents:
84644
diff
changeset
|
250 (mapc |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 (function |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 (lambda (x) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 (if (fboundp (cdr (cdr x))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 (setq retval (format "%s%c" retval (car x)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 num (1+ num))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 (reverse socks-authentication-methods)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 (format "%c%s" num retval))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 (defconst socks-state-waiting-for-auth 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 (defconst socks-state-submethod-negotiation 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 (defconst socks-state-authenticated 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 (defconst socks-state-waiting 3) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 (defconst socks-state-connected 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 (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
|
266 `(while (and (= (gethash 'state ,htable) ,cur-state) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
267 (memq (process-status ,proc) '(run open))) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
268 (accept-process-output ,proc socks-timeout))) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 (defun socks-filter (proc string) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 (let ((info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 state version desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 (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
|
274 (setq state (gethash 'state info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 ((= state socks-state-waiting-for-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 (puthash 'scratch (concat string (gethash 'scratch info)) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (setq string (gethash 'scratch info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 (if (< (length string) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 nil ; We need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 (puthash 'authtype (aref string 1) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 (puthash 'scratch (substring string 2 nil) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 (puthash 'state socks-state-submethod-negotiation info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 ((= state socks-state-submethod-negotiation) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 ((= state socks-state-authenticated) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 ((= state socks-state-waiting) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 (puthash 'scratch (concat string (gethash 'scratch info)) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 (setq string (gethash 'scratch info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 (setq version (gethash 'server-protocol info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 (if (not (string-match "\r\n\r\n" string)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 nil ; Need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 (puthash 'reply 0 info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 (puthash 'response string info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 (if (< (length string) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 nil ; Can't know how much to read yet |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 (setq desired-len |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 (+ 4 ; address length |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 2 ; port |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 2 ; initial data |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 )) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 (if (< (length string) desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 nil ; need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 (let ((response (aref string 1))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 (if (= response 90) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 (setq response 0)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 (puthash 'reply response info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 (puthash 'response string info))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 ((equal version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 (if (< (length string) 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 (setq desired-len |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 (+ 6 ; Standard socks header |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 ((= (aref string 3) socks-address-type-v4) 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 ((= (aref string 3) socks-address-type-v6) 16) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 ((= (aref string 3) socks-address-type-name) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 (if (< (length string) 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 255 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 (+ 1 (aref string 4))))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 (if (< (length string) desired-len) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 nil ; Need to spin some more |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 (puthash 'state socks-state-connected info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 (puthash 'reply (aref string 1) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 (puthash 'response string info)))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 ((= state socks-state-connected) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 |
86534
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
338 (declare-function socks-original-open-network-stream "socks") ; fset |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
339 |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
340 (defvar socks-override-functions nil |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
341 "*Whether to overwrite the open-network-stream function with the SOCKSified |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
342 version.") |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
343 |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
344 (if (fboundp 'socks-original-open-network-stream) |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
345 nil ; Do nothing, we've been here already |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
346 (defalias 'socks-original-open-network-stream |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
347 (symbol-function 'open-network-stream)) |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
348 (if socks-override-functions |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
349 (defalias 'open-network-stream 'socks-open-network-stream))) |
1863c4982b31
(socks-original-open-network-stream): Declare as function. Move
Glenn Morris <rgm@gnu.org>
parents:
85226
diff
changeset
|
350 |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 (defun socks-open-connection (server-info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 (interactive) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (save-excursion |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 (let ((proc (socks-original-open-network-stream "socks" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 (nth 1 server-info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 (nth 2 server-info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 (info (make-hash-table :size 13)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
359 (authtype nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 version) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
362 ;; Initialize process and info about the process |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 (set-process-filter proc 'socks-filter) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 (set-process-query-on-exit-flag proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
365 (puthash proc info socks-connections) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 (puthash 'state socks-state-waiting-for-auth info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
367 (puthash 'authtype socks-authentication-failure info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
368 (puthash 'server-protocol (nth 3 server-info) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
369 (puthash 'server-name (nth 1 server-info) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
370 (setq version (nth 3 server-info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 ;; 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
|
374 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
375 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 ;; 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
|
377 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 ((equal version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 ;; Need to handle all the authentication crap under v5 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 ;; 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
|
381 (process-send-string proc (format "%c%s" socks-version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
382 (socks-build-auth-list))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
384 ;; Basically just do a select() until we change states. |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 (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
|
386 (setq authtype (gethash 'authtype info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
387 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
388 ((= authtype socks-authentication-null) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
389 (and socks-debug (message "No authentication necessary"))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 ((= authtype socks-authentication-failure) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
391 (error "No acceptable authentication methods found.")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 (let* ((auth-type (gethash 'authtype info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 (auth-handler (assoc auth-type socks-authentication-methods)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 (auth-func (and auth-handler (cdr (cdr auth-handler)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
396 (auth-desc (and auth-handler (car (cdr auth-handler))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
397 (set-process-filter proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
398 (if (and auth-func (fboundp auth-func) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 (funcall auth-func proc)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
400 nil ; We succeeded! |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
401 (delete-process proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
402 (error "Failed to use auth method: %s (%d)" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
403 (or auth-desc "Unknown") auth-type)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
404 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
406 ) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
407 (puthash 'state socks-state-authenticated info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 (set-process-filter proc 'socks-filter))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 proc))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
411 (defun socks-send-command (proc command atype address port) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 (let ((addr (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
413 ((or (= atype socks-address-type-v4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
414 (= atype socks-address-type-v6)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 address) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 ((= atype socks-address-type-name) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 (format "%c%s" (length address) address)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
419 (error "Unkown address type: %d" atype)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 (info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 request version) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 (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
|
423 proc)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 (puthash 'state socks-state-waiting info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
425 (setq version (gethash 'server-protocol info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
426 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
427 ((equal version 'http) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
428 (setq request (format (eval-when-compile |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
429 (concat |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
430 "CONNECT %s:%d HTTP/1.0\r\n" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 "User-Agent: Emacs/SOCKS v1.0\r\n" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 "\r\n")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
434 ((equal atype socks-address-type-name) address) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
435 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 (error "Unsupported address type for HTTP: %d" atype))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 port))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
438 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
439 (setq request (format |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
440 "%c%c%c%c%s%s%c" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
441 version ; version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
442 command ; command |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 (lsh port -8) ; port, high byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
444 (- port (lsh (lsh port -8) 8)) ; port, low byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
445 addr ; address |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 (user-full-name) ; username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
447 0 ; terminate username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
448 ))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
449 ((equal version 5) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 (setq request (format |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 "%c%c%c%c%s%c%c" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
452 version ; version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 command ; command |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
454 0 ; reserved |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
455 atype ; address type |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
456 addr ; address |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
457 (lsh port -8) ; port, high byte |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
458 (- port (lsh (lsh port -8) 8)) ; port, low byte |
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 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
461 (error "Unknown protocol version: %d" version))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
462 (process-send-string proc request) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
463 (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
|
464 (process-status proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 (if (= (or (gethash 'reply info) 1) socks-response-success) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 nil ; Sweet sweet success! |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 (delete-process proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 (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
|
469 proc)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 ;; Replacement functions for open-network-stream, etc. |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 (defvar socks-noproxy nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 "*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
|
475 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 (defun socks-find-route (host service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (let ((route socks-server) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 (noproxy socks-noproxy)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
479 (while noproxy |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 (if (eq ?! (aref (car noproxy) 0)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
481 (if (string-match (substring (car noproxy) 1) host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
482 (setq noproxy nil)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
483 (if (string-match (car noproxy) host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
484 (setq route nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
485 noproxy nil))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
486 (setq noproxy (cdr noproxy))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
487 route)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
488 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
489 (defvar socks-services-file "/etc/services") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
490 (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
|
491 (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
|
492 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
493 (defun socks-parse-services () |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
494 (if (not (and (file-exists-p socks-services-file) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
495 (file-readable-p socks-services-file))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
496 (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
|
497 (clrhash socks-tcp-services) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
498 (clrhash socks-udp-services) |
65b448298f0c
(socks-username/password-auth-filter):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
499 (with-current-buffer (get-buffer-create " *socks-tmp*") |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
500 (erase-buffer) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
501 (insert-file-contents socks-services-file) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
502 ;; Nuke comments |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
503 (goto-char (point-min)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
504 (while (re-search-forward "#.*" nil t) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
505 (replace-match "")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
506 ;; Nuke empty lines |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
507 (goto-char (point-min)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
508 (while (re-search-forward "^[ \t\n]+" nil t) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
509 (replace-match "")) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
510 ;; Now find all the lines |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
511 (goto-char (point-min)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
512 (let (name port type) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
513 (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
|
514 nil t) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
515 (setq name (downcase (match-string 1)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
516 port (string-to-number (match-string 2)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
517 type (downcase (match-string 3))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
518 (puthash name port (if (equal type "udp") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
519 socks-udp-services |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
520 socks-tcp-services)))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
521 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
522 (defun socks-find-services-entry (service &optional udp) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
523 "Return the port # associated with SERVICE" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
524 (if (= (hash-table-count socks-tcp-services) 0) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
525 (socks-parse-services)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
526 (gethash (downcase service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
527 (if udp socks-udp-services socks-tcp-services))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
528 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
529 (defun socks-open-network-stream (name buffer host service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
530 (let* ((route (socks-find-route host service)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
531 proc info version atype) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
532 (if (not route) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
533 (socks-original-open-network-stream name buffer host service) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
534 (setq proc (socks-open-connection route) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
535 info (gethash proc socks-connections) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
536 version (gethash 'server-protocol info)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
537 (cond |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
538 ((equal version 4) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
539 (setq host (socks-nslookup-host host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
540 (if (not (listp host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
541 (error "Could not get IP address for: %s" host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
542 (setq host (apply 'format "%c%c%c%c" host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
543 (setq atype socks-address-type-v4)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
544 (t |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
545 (setq atype socks-address-type-name))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
546 (socks-send-command proc |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
547 socks-connect-command |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
548 atype |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
549 host |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
550 (if (stringp service) |
84643
9cf2bf22d7ee
(socks-open-network-stream): Signal an explicit error if the port
Glenn Morris <rgm@gnu.org>
parents:
82907
diff
changeset
|
551 (or |
9cf2bf22d7ee
(socks-open-network-stream): Signal an explicit error if the port
Glenn Morris <rgm@gnu.org>
parents:
82907
diff
changeset
|
552 (socks-find-services-entry service) |
84644
630c599116d6
(socks-open-network-stream): Standardize error message from previous
Glenn Morris <rgm@gnu.org>
parents:
84643
diff
changeset
|
553 (error "Unknown service: %s" service)) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
554 service)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
555 (puthash 'buffer buffer info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
556 (puthash 'host host info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
557 (puthash 'service host info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
558 (set-process-filter proc nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
559 (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
|
560 proc))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
561 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
562 ;; Authentication modules go here |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
563 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
564 ;; Basic username/password authentication, ala RFC 1929 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
565 (socks-register-authentication-method 2 "Username/Password" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
566 'socks-username/password-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
567 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
568 (defconst socks-username/password-auth-version 1) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
569 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
570 (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
|
571 (let ((info (gethash proc socks-connections))) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
572 (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
|
573 (puthash 'scratch (concat (gethash 'scratch info) str) info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
574 (if (< (length (gethash 'scratch info)) 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
575 nil |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
576 (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
|
577 (puthash 'state socks-state-authenticated info)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
578 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
579 (defun socks-username/password-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
580 (let* ((info (gethash proc socks-connections)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
581 (state (gethash 'state info))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
582 (if (not socks-password) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
583 (setq socks-password (read-passwd |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
584 (format "Password for %s@%s: " |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
585 socks-username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
586 (gethash 'server-name info))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
587 (puthash 'scratch "" info) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
588 (set-process-filter proc 'socks-username/password-auth-filter) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
589 (process-send-string proc |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
590 (format "%c%c%s%c%s" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
591 socks-username/password-auth-version |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
592 (length socks-username) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
593 socks-username |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
594 (length socks-password) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
595 socks-password)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
596 (socks-wait-for-state-change proc info state) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
597 (= (gethash 'password-auth-status info) 0))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
598 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
599 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
600 ;; More advanced GSS/API stuff, not yet implemented - volunteers? |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
601 ;; (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
|
602 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
603 (defun socks-gssapi-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
604 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
605 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
606 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
607 ;; CHAP stuff |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
608 ;; (socks-register-authentication-method 3 "CHAP" 'socks-chap-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
609 (defun socks-chap-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
610 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
611 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
612 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
613 ;; CRAM stuff |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
614 ;; (socks-register-authentication-method 5 "CRAM" 'socks-cram-auth) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
615 (defun socks-cram-auth (proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
616 nil) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
617 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
618 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
619 (defcustom socks-nslookup-program "nslookup" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
620 "*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
|
621 :type '(choice (const :tag "None" :value nil) string) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
622 :group 'socks) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
623 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
624 (defun socks-nslookup-host (host) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
625 "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
|
626 (interactive "sHost: ") |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
627 (if socks-nslookup-program |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
628 (let ((proc (start-process " *nslookup*" " *nslookup*" |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
629 socks-nslookup-program host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
630 (res host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
631 (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
|
632 (with-current-buffer (process-buffer proc) |
77921
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
633 (while (progn |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
634 (accept-process-output proc) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
635 (memq (process-status proc) '(run open)))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
636 (goto-char (point-min)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
637 (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
|
638 (progn |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
639 (setq res (buffer-substring (match-beginning 2) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
640 (match-end 2)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
641 res (mapcar 'string-to-int (split-string res "\\."))))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
642 (kill-buffer (current-buffer))) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
643 res) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
644 host)) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
645 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
646 (provide 'socks) |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
647 |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
648 ;; arch-tag: 67aef0d9-f4f7-4056-89c3-b4c9bf93ce7f |
9a33ca5607a2
New file, taken from w3 repository.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
649 ;;; socks.el ends here |