Skip to content

Commit

Permalink
(twittering-http-default-sentinel): get a buffer associate with the p…
Browse files Browse the repository at this point in the history
…rocess from calling 'process-buffer' instead of taking from an argument.

(twittering-http-default-sentinel): delete an unnecessary argument.
  • Loading branch information
yata committed Feb 14, 2010
1 parent 528f092 commit 457eb74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Expand Up @@ -150,6 +150,14 @@
by width instead of length.
(twittering-favorite): Likewise.

* twittering-mode.el (twittering-http-default-sentinel): Get a
buffer associate with the process from calling `process-buffer'
instead of taking from an argument.
(twittering-http-default-sentinel): Delete an unnecessary
argument.
(twittering-start-http-ssl-session): Adjust callers.
(twittering-start-http-non-ssl-session): Likewise.

2010-02-09 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-goto-previous-status): simplified.
Expand Down
48 changes: 24 additions & 24 deletions twittering-mode.el
Expand Up @@ -1443,6 +1443,7 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
;; TODO: use curl
(let* ((request (twittering-make-http-request
method headers host port path parameters))
(temp-buffer (generate-new-buffer "*twmode-http-buffer*"))
(headers (if (assoc "Expect" headers)
headers
(cons '("Expect" . "") headers)))
Expand Down Expand Up @@ -1480,9 +1481,7 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
(cdr pair)))))
parameters)))))
(debug-print curl-args)
(lexical-let ((temp-buffer
(generate-new-buffer "*twmode-http-buffer*"))
(noninteractive noninteractive)
(lexical-let ((noninteractive noninteractive)
(sentinel sentinel))
(let ((curl-process
(apply 'start-process
Expand All @@ -1494,14 +1493,15 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
curl-process
(lambda (&rest args)
(apply #'twittering-http-default-sentinel
sentinel temp-buffer noninteractive args)))
sentinel noninteractive args)))
curl-process)))
)

;; TODO: proxy
(defun twittering-start-http-non-ssl-session (method headers host port path parameters &optional noninteractive sentinel)
(let ((request (twittering-make-http-request
method headers host port path parameters)))
method headers host port path parameters))
(temp-buffer (generate-new-buffer "*twmode-http-buffer*")))
(flet ((request (key) (funcall request key)))
(let* ((request-str
(format "%s %s%s HTTP/1.1\r\n%s\r\n\r\n"
Expand All @@ -1517,18 +1517,16 @@ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv
(port (if twittering-proxy-use
twittering-proxy-port
(request :port)))
(temp-buffer (generate-new-buffer "*twmode-http-buffer*"))
(proc (open-network-stream
"network-connection-process" temp-buffer server port))
)
(lexical-let ((temp-buffer temp-buffer)
(sentinel sentinel)
(lexical-let ((sentinel sentinel)
(noninteractive noninteractive))
(set-process-sentinel
proc
(lambda (&rest args)
(apply #'twittering-http-default-sentinel
sentinel temp-buffer noninteractive args))))
sentinel noninteractive args))))
(debug-print request-str)
(process-send-string proc request-str)
proc)))
Expand Down Expand Up @@ -1657,22 +1655,24 @@ Available keywords:
(+ (* (car encoded-time) 65536)
(cadr encoded-time))))

(defun twittering-http-default-sentinel (func temp-buffer noninteractive proc stat &optional suc-msg)
(defun twittering-http-default-sentinel (func noninteractive proc stat &optional suc-msg)
(debug-printf "http-default-sentinel: proc=%s stat=%s" proc stat)
(unwind-protect
(let ((header (twittering-get-response-header temp-buffer))
(mes nil))
(if (string-match twittering-http-status-line-regexp header)
(when (and func (fboundp func))
(with-current-buffer temp-buffer
(setq mes (funcall func header proc noninteractive suc-msg))))
(setq mes "Failure: Bad http response."))
(when (and mes (twittering-buffer-active-p))
(message mes)))
;; unwindforms
(twittering-release-process proc)
(when (and (not twittering-debug-mode) (buffer-live-p temp-buffer))
(kill-buffer temp-buffer))))
(let ((temp-buffer (buffer-name (process-buffer proc))))
(unwind-protect
(let ((header (twittering-get-response-header temp-buffer))
(mes nil))
(if (string-match twittering-http-status-line-regexp header)
(when (and func (fboundp func))
(with-current-buffer temp-buffer
(setq mes (funcall func header proc noninteractive suc-msg))))
(setq mes "Failure: Bad http response."))
(when (and mes (twittering-buffer-active-p))
(message mes)))
;; unwindforms
(twittering-release-process proc)
(when (and (not twittering-debug-mode) (buffer-live-p temp-buffer))
(kill-buffer temp-buffer))))
)

(defun twittering-http-get-default-sentinel (header proc noninteractive &optional suc-msg)
(let ((status-line (match-string-no-properties 1 header))
Expand Down

0 comments on commit 457eb74

Please sign in to comment.