Skip to content

Commit

Permalink
Integrate generic function into `twittering-start-http-session'.
Browse files Browse the repository at this point in the history
* twittering-mode.el: Integrate generic function into
`twittering-start-http-session'.
(twittering-connection-type-table): remove the entry `start' and
rename `start-process' `send-http-request'.
(twittering-lookup-http-start-function): use `send-http-request'
instead of `start-process'.
(twittering-start-http-session): unified with
`twittering-start-http-session-generic'.
(twittering-start-http-session-generic): removed.
  • Loading branch information
cvmat committed Sep 19, 2010
1 parent ddbaa4b commit c105900
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Expand Up @@ -58,6 +58,16 @@
`twittering-start-http-session-generic' and
`twittering-send-http-request-native'.

* twittering-mode.el: Integrate generic function into
`twittering-start-http-session'.
(twittering-connection-type-table): remove the entry `start' and
rename `start-process' `send-http-request'.
(twittering-lookup-http-start-function): use `send-http-request'
instead of `start-process'.
(twittering-start-http-session): unified with
`twittering-start-http-session-generic'.
(twittering-start-http-session-generic): removed.

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

* twittering-mode.el: Add an edited tweet into the history without
Expand Down
69 changes: 27 additions & 42 deletions twittering-mode.el
Expand Up @@ -321,14 +321,12 @@ If nil, this is initialized with a list of valied entries extracted from
(defvar twittering-connection-type-table
'((native (check . t)
(https . twittering-start-http-session-native-tls-p)
(start . twittering-start-http-session-generic)
(start-process . twittering-send-http-request-native)
(send-http-request . twittering-send-http-request-native)
(oauth-get-token . native)
(pre-process-buffer . twittering-pre-process-buffer-native))
(curl (check . twittering-start-http-session-curl-p)
(https . twittering-start-http-session-curl-https-p)
(start . twittering-start-http-session-generic)
(start-process . twittering-send-http-request-curl)
(send-http-request . twittering-send-http-request-curl)
(oauth-get-token . curl)
(pre-process-buffer . twittering-pre-process-buffer-curl)))
"A list of alist of connection methods.")
Expand Down Expand Up @@ -4039,7 +4037,7 @@ the function returns
(entry (twittering-lookup-connection-type
twittering-use-ssl order table)))
(if entry
(cdr (assq 'start entry))
(cdr (assq 'send-http-request entry))
(cond
((and twittering-use-ssl
(yes-or-no-p "HTTPS(SSL) is unavailable. Use HTTP instead? "))
Expand All @@ -4065,13 +4063,6 @@ CLEAN-UP-SENTINEL: sentinel always executed."
(error "Unknown HTTP method: %s" method))
(unless (string-match "^/" path)
(error "Invalid HTTP path: %s" path))

(unless (assoc "Host" headers)
(setq headers (cons `("Host" . ,host) headers)))
(unless (assoc "User-Agent" headers)
(setq headers (cons `("User-Agent" . ,(twittering-user-agent))
headers)))

(let* ((func (twittering-lookup-http-start-function
twittering-connection-type-order
twittering-connection-type-table))
Expand All @@ -4096,11 +4087,30 @@ CLEAN-UP-SENTINEL: sentinel always executed."
twittering-http-proxy-password
twittering-https-proxy-password))))
(noninteractive . ,noninteractive)
,@entry)))
(if (and func (fboundp func))
(funcall func method headers host port path parameters
connection-info sentinel clean-up-sentinel)
nil)))
,@entry))
(temp-buffer (generate-new-buffer "*twmode-http-buffer*"))
(url (concat (funcall request :uri)
(when parameters
(concat "?" (funcall request :query-string)))))
(headers
`(,@(unless (assoc "Host" headers)
`(("Host" . ,host)))
,@(unless (assoc "User-Agent" headers)
`(("User-Agent" . ,(twittering-user-agent))))
,@(unless (assoc "Expect" headers)
'(("Expect" . "")))
,@headers))
(post-body ""))
(when (and func (functionp func))
(lexical-let ((connection-info connection-info)
(clean-up-sentinel clean-up-sentinel)
(sentinel sentinel))
(funcall func "*twmode-generic*" temp-buffer
(lambda (&rest args)
(apply #'twittering-http-default-sentinel
sentinel connection-info clean-up-sentinel args))
method scheme url headers
connection-info post-body)))))

(defvar twittering-cert-file nil)

Expand Down Expand Up @@ -4143,31 +4153,6 @@ A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y
(add-hook 'kill-emacs-hook 'twittering-delete-ca-cert-file)
(setq twittering-cert-file file-name))))

(defun twittering-start-http-session-generic (method headers host port path parameters &optional connection-info sentinel clean-up-sentinel)
;; TODO: use curl
(let* ((request (twittering-make-http-request
method headers host port path parameters))
(temp-buffer (generate-new-buffer "*twmode-http-buffer*"))
(scheme (funcall request :schema))
(url
(concat (funcall request :uri)
(when parameters
(concat "?" (funcall request :query-string)))))
(headers (if (assoc "Expect" headers)
headers
(cons '("Expect" . "") headers)))
(post-body "")
(start-func (cdr (assq 'start-process connection-info))))
(lexical-let ((connection-info connection-info)
(clean-up-sentinel clean-up-sentinel)
(sentinel sentinel))
(funcall start-func "*twmode-generic*" temp-buffer
(lambda (&rest args)
(apply #'twittering-http-default-sentinel
sentinel connection-info clean-up-sentinel args))
method scheme url headers
connection-info post-body))))

(defun twittering-start-http-session-native-tls-p ()
(when (require 'tls nil t)
(unless twittering-tls-program
Expand Down

0 comments on commit c105900

Please sign in to comment.