From 73c8d8b380a06fbac4ef7533cf1ed8c485694928 Mon Sep 17 00:00:00 2001 From: bg66 Date: Mon, 23 Oct 2006 05:41:34 +0000 Subject: [PATCH] * mixi.el (mixi-retrieve-function): New user option. (mixi-retrieve): Abolish. (mixi-w3-retrieve): New function. (mixi-w3m-retrieve): Ditto. (mixi-retrieve-1): Ditto. (mixi-login): Follow the change above. (with-mixi-retrieve): Ditto. --- ChangeLog | 10 +++++++ mixi.el | 93 +++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 73 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e4ad01..913a654 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2006-10-23 OHASHI Akira + * mixi.el (mixi-retrieve-function): New user option. + (mixi-retrieve): Abolish. + (mixi-w3-retrieve): New function. + (mixi-w3m-retrieve): Ditto. + (mixi-retrieve-1): Ditto. + (mixi-login): Follow the change above. + (with-mixi-retrieve): Ditto. + +2006-10-23 OHASHI Akira + * mixi.el: Require `url' instead of `w3m'. (mixi-retrieve): Follow the change above. (mixi-login): Ditto. diff --git a/mixi.el b/mixi.el index 2a08cb6..3849ad5 100644 --- a/mixi.el +++ b/mixi.el @@ -98,8 +98,8 @@ ;;; Code: -(require 'url) (eval-when-compile (require 'cl)) +(autoload 'w3m-expand-url "w3m" nil t) (defgroup mixi nil "API library for accessing to mixi." @@ -115,6 +115,16 @@ :type 'coding-system :group 'mixi) +(defcustom mixi-retrieve-function + (if (and (require 'url "url" t) + (fboundp 'url-retrieve-synchronously)) + 'mixi-w3-retrieve 'mixi-w3m-retrieve) + "*The function for retrieving." + :type '(choice (const :tag "Using w3" mixi-w3-retrieve) + (const :tag "Using w3m" mixi-w3m-retrieve) + (function :format "Other function: %v\n" :size 0)) + :group 'mixi) + (defcustom mixi-default-email nil "*Default E-mail address that is used to login automatically." :type '(choice (string :tag "E-mail address") @@ -173,8 +183,20 @@ Increase this value when unexpected error frequently occurs." ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤­¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ
¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£") -;; FIXME: Don't use `url-retrieve-synchronously'? -(defun mixi-retrieve (url &optional post-data) +(defun mixi-retrieve-1 (buffer url &optional post-data) + (when (string-match mixi-message-adult-contents buffer) + (if mixi-accept-adult-contents + (setq buffer (funcall mixi-retrieve-function url "submit=agree")) + (setq buffer (funcall mixi-retrieve-function (concat url "?"))))) + (when (string-match mixi-warning-continuously-accessing buffer) + (error (mixi-message "Continuously accessing"))) + (if (not (string-match mixi-message-continuously-accessing buffer)) + buffer + (message (mixi-message "Waiting for continuously accessing...")) + (sit-for mixi-continuously-access-interval) + (funcall mixi-retrieve-function url post-data))) + +(defun mixi-w3-retrieve (url &optional post-data) "Retrieve the URL and return getted strings." (if post-data (progn @@ -189,57 +211,68 @@ Increase this value when unexpected error frequently occurs." (error (mixi-message "Cannot retrieve"))) (with-current-buffer buffer (goto-char (point-min)) - (unless (re-search-forward "HTTP/[0-9.]+ 200 OK" nil t) - (error (mixi-message "Cannot retrieve"))) - (search-forward "\n\n") - (setq ret (mm-decode-coding-string - (buffer-substring-no-properties (point) (point-max)) - mixi-coding-system)) - (kill-buffer buffer)) - (when (string-match mixi-message-adult-contents ret) - (if mixi-accept-adult-contents - (setq ret (mixi-retrieve url "submit=agree")) - (setq ret (mixi-retrieve (concat url "?"))))) - (when (string-match mixi-warning-continuously-accessing ret) - (error (mixi-message "Continuously accessing"))) - (if (not (string-match mixi-message-continuously-accessing ret)) - ret - (message (mixi-message "Waiting for continuously accessing...")) - (sit-for mixi-continuously-access-interval) - (mixi-retrieve url post-data)))) + (if (re-search-forward "HTTP/[0-9.]+ 302 Moved" nil t) + (if (re-search-forward + (concat "Location: " mixi-url "\\(.+\\)") nil t) + (setq ret (mixi-w3-retrieve (match-string 1) post-data)) + (setq ret (mixi-w3-retrieve "/home.pl" post-data))) + (unless (re-search-forward "HTTP/[0-9.]+ 200 OK" nil t) + (error (mixi-message "Cannot retrieve"))) + (search-forward "\n\n") + (setq ret (mm-decode-coding-string + (buffer-substring-no-properties (point) (point-max)) + mixi-coding-system)) + (kill-buffer buffer) + (setq ret (mixi-retrieve-1 ret url post-data)))) + ret)) + +(defun mixi-w3m-retrieve (url &optional post-data) + "Retrieve the URL and return getted strings." + (let ((url (w3m-expand-url url mixi-url))) + (with-temp-buffer + (if (not (string= (w3m-retrieve url nil nil post-data) "text/html")) + (error (mixi-message "Cannot retrieve")) + (w3m-decode-buffer url) + (let ((ret (buffer-substring-no-properties (point-min) (point-max)))) + (mixi-retrieve-1 ret url post-data)))))) (defconst mixi-my-id-regexp "