* mixi.el (mixi-curl-retrieve): New function.
authorueno <ueno>
Mon, 23 Oct 2006 08:18:03 +0000 (08:18 +0000)
committerueno <ueno>
Mon, 23 Oct 2006 08:18:03 +0000 (08:18 +0000)
ChangeLog
mixi.el

index cd7c92a..71c3a97 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-10-23  Daiki Ueno  <ueno@unixuser.org>
+
+       * mixi.el (mixi-curl-retrieve): New function.
+
 2006-10-23  OHASHI Akira  <bg66@koka-in.org>
 
        * mixi.el (mixi-get-matched-items): Don't convert string to number.
diff --git a/mixi.el b/mixi.el
index 4a35c67..4027a73 100644 (file)
--- a/mixi.el
+++ b/mixi.el
                 (function :format "Other function: %v\n" :size 0))
   :group 'mixi)
 
+(defcustom mixi-curl-program "curl"
+  "*The program name of `curl'."
+  :type 'file
+  :group 'mixi)
+
+(defcustom mixi-curl-cookie-file (expand-file-name "~/.mixi-cookies.txt")
+  "*The location of cookie file created by `curl'."
+  :type 'file
+  :group 'mixi)
+
 (defcustom mixi-default-email nil
   "*Default E-mail address that is used to login automatically."
   :type '(choice (string :tag "E-mail address")
@@ -237,6 +247,39 @@ Increase this value when unexpected error frequently occurs."
        (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
          (mixi-retrieve-1 ret url post-data))))))
 
+(defun mixi-curl-retrieve (url &optional post-data)
+  "Retrieve the URL and return getted strings."
+  (with-temp-buffer
+    (let ((orig-mode (default-file-modes))
+         process ret)
+      (unwind-protect
+         (progn
+           (set-default-file-modes 448)
+           (setq process
+                 (apply #'start-process "curl" (current-buffer)
+                        mixi-curl-program
+                        (append (if post-data '("-d" "@-"))
+                                (list "-i" "-L" "-s"
+                                      "-b" mixi-curl-cookie-file
+                                      "-c" mixi-curl-cookie-file
+                                      (concat mixi-url url)))))
+           (set-process-sentinel process #'ignore))
+       (set-default-file-modes orig-mode))
+      (when post-data
+       (process-send-string process (concat post-data "\n"))
+       (process-send-eof process))
+      (while (eq (process-status process) 'run)
+       (accept-process-output process 1))
+      (goto-char (point-min))
+      (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
+       (delete-region (point) (re-search-forward "\r?\n\r?\n")))
+      (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
+       (error (mixi-message "Cannot retrieve")))
+      (delete-region (point) (re-search-forward "\r?\n\r?\n"))
+      (setq ret (decode-coding-string (buffer-substring (point) (point-max))
+                                     mixi-coding-system))
+      (mixi-retrieve-1 ret url post-data))))
+
 (defconst mixi-my-id-regexp
   "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")