annotate lisp/net/socks.el @ 92986:589bafdc6c3e

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