Skip to content

Commit

Permalink
The configuration of a proxy is referred via `twittering-proxy-info'.
Browse files Browse the repository at this point in the history
* twittering-mode.el: The configuration of a proxy is referred via
the function `twittering-proxy-info'.
(twittering-proxy-info): return all configuration of the proxy for
the scheme.
  • Loading branch information
cvmat committed May 19, 2010
1 parent 4aea9ec commit d59b1a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
2010-05-20 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el: The configuration of a proxy is referred via
the function `twittering-proxy-info'.
(twittering-proxy-info): return all configuration of the proxy for
the scheme.

2010-05-17 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-start-http-session-curl): fix
Expand Down
80 changes: 40 additions & 40 deletions twittering-mode.el
Expand Up @@ -520,9 +520,8 @@ and `twittering-http-proxy-port' is used.")
'(twittering-http-proxy-port
twittering-https-proxy-port)))

(defun twittering-proxy-info (scheme)
"Return a cons pair of the registered proxy server and its port number
for SCHEME.
(defun twittering-proxy-info (scheme &optional item)
"Return an alist for proxy configuration registered for SCHEME.
SCHEME must be a string \"http\", \"https\" or a symbol 'http or 'https.
The server name is a string and the port number is an integer."
(twittering-normalize-proxy-vars)
Expand All @@ -531,28 +530,40 @@ The server name is a string and the port number is an integer."
scheme))
(info-list
`((("http")
. (,twittering-http-proxy-server
. ,twittering-http-proxy-port))
. ((server . ,twittering-http-proxy-server)
(port . ,twittering-http-proxy-port)
(keep-alive . ,twittering-http-proxy-keep-alive)
(user . ,twittering-http-proxy-user)
(password . ,twittering-http-proxy-password)))
(("https")
. (,twittering-https-proxy-server
. ,twittering-https-proxy-port)))))
(car (remove nil
(mapcar
(lambda (entry)
(when (member scheme (car entry))
(let ((info (cdr entry)))
(when (and (car info) (cdr info))
info))))
info-list)))))
. ((server . ,twittering-https-proxy-server)
(port . ,twittering-https-proxy-port)
(keep-alive . ,twittering-https-proxy-keep-alive)
(user . ,twittering-https-proxy-user)
(password . ,twittering-https-proxy-password))))))
(let ((info
(car (remove nil
(mapcar
(lambda (entry)
(when (member scheme (car entry))
(let ((info (cdr entry)))
(when (and (cdr (assq 'server info))
(cdr (assq 'port info)))
info))))
info-list)))))
(if item
(cdr (assq item info))
info))))

(defun twittering-url-proxy-services ()
"Return the current proxy configuration for `twittering-mode' in the format
of `url-proxy-services'."
(remove nil (mapcar
(lambda (scheme)
(let ((info (twittering-proxy-info scheme)))
(when info
`(,scheme . ,(format "%s:%s" (car info) (cdr info))))))
(let ((server (twittering-proxy-info scheme 'server))
(port (twittering-proxy-info scheme 'port)))
(when (and server port)
`(,scheme . ,(format "%s:%s" server port)))))
'("http" "https"))))

(defun twittering-find-proxy (scheme)
Expand Down Expand Up @@ -2878,11 +2889,10 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
,@(when twittering-use-ssl
`("--cacert" ,cacert-filename))
,@(when twittering-proxy-use
(let* ((proxy-info
(twittering-proxy-info (funcall request :schema)))
(host (car-safe proxy-info))
(port (cdr-safe proxy-info)))
(when proxy-info
(let* ((scheme (funcall request :schema))
(host (twittering-proxy-info scheme 'server))
(port (twittering-proxy-info scheme 'port)))
(when (and host port)
`("-x" ,(format "%s:%s" host port)))))
,@(when twittering-proxy-use
(let ((pair
Expand Down Expand Up @@ -2956,10 +2966,10 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
(when twittering-proxy-use
(twittering-proxy-info (request :schema))))
(server (if proxy-info
(car proxy-info)
(cdr (assq 'server proxy-info))
(request :host)))
(port (if proxy-info
(cdr proxy-info)
(cdr (assq 'port proxy-info))
(request :port)))
(proc
(cond
Expand Down Expand Up @@ -3078,21 +3088,11 @@ Available keywords:
(push (cons "Content-Length" "0") headers)
(push (cons "Content-Type" "text/plain") headers))
(when twittering-proxy-use
(let* ((proxy-conf-alist
`(("http" .
(,twittering-http-proxy-keep-alive
,twittering-http-proxy-user
,twittering-http-proxy-password))
("https" .
(,twittering-https-proxy-keep-alive
,twittering-https-proxy-user
,twittering-https-proxy-password))))
(schema (if twittering-use-ssl "https" "http"))
(conf (cdr (assoc schema proxy-conf-alist)))
(keep-alive (elt conf 0))
(user (elt conf 1))
(password (elt conf 2)))
(when keep-alive
(let* ((scheme (if twittering-use-ssl "https" "http"))
(keep-alive (twittering-proxy-info scheme 'keep-alive))
(user (twittering-proxy-info scheme 'user))
(password (twittering-proxy-info scheme 'password)))
(when (twittering-proxy-info scheme 'keep-alive)
(push (cons "Proxy-Connection" "Keep-Alive")
headers))
(when (and user password)
Expand Down

0 comments on commit d59b1a2

Please sign in to comment.