diff options
| author | Simon Josefsson | 2006-04-04 10:34:03 +0000 |
|---|---|---|
| committer | Simon Josefsson | 2006-04-04 10:34:03 +0000 |
| commit | bd707233ea563f8186ccf86c127b27498bfe31f7 (patch) | |
| tree | b34d284f51042aa04fb467b9eea1c4ed52a706ac | |
| parent | d65b42351fbebde2539d447ecf5443e1725bdce3 (diff) | |
| download | emacs-bd707233ea563f8186ccf86c127b27498bfe31f7.tar.gz emacs-bd707233ea563f8186ccf86c127b27498bfe31f7.zip | |
2006-04-04 Daiki Ueno <ueno@unixuser.org>
* pgg-gpg.el: Clean up process buffers every time gpg processes
complete.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/pgg-gpg.el | 130 |
2 files changed, 79 insertions, 56 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1140cd7fbd4..532dc341c14 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2006-04-04 Daiki Ueno <ueno@unixuser.org> | ||
| 2 | |||
| 3 | * pgg-gpg.el: Clean up process buffers every time gpg processes | ||
| 4 | complete. | ||
| 5 | |||
| 1 | 2006-04-04 Kenichi Handa <handa@m17n.org> | 6 | 2006-04-04 Kenichi Handa <handa@m17n.org> |
| 2 | 7 | ||
| 3 | * sort.el (sort-build-lists): Don't bind inhibit-field-text-motion | 8 | * sort.el (sort-build-lists): Don't bind inhibit-field-text-motion |
diff --git a/lisp/pgg-gpg.el b/lisp/pgg-gpg.el index 986d3f8d343..b59e68a27a8 100644 --- a/lisp/pgg-gpg.el +++ b/lisp/pgg-gpg.el | |||
| @@ -107,13 +107,13 @@ | |||
| 107 | process)) | 107 | process)) |
| 108 | 108 | ||
| 109 | (defun pgg-gpg-process-filter (process input) | 109 | (defun pgg-gpg-process-filter (process input) |
| 110 | (if pgg-gpg-debug | ||
| 111 | (save-excursion | ||
| 112 | (set-buffer (get-buffer-create " *pgg-gpg-debug*")) | ||
| 113 | (goto-char (point-max)) | ||
| 114 | (insert input))) | ||
| 110 | (if (buffer-live-p (process-buffer process)) | 115 | (if (buffer-live-p (process-buffer process)) |
| 111 | (save-excursion | 116 | (save-excursion |
| 112 | (if pgg-gpg-debug | ||
| 113 | (save-excursion | ||
| 114 | (set-buffer (get-buffer-create " *pgg-gpg-debug*")) | ||
| 115 | (goto-char (point-max)) | ||
| 116 | (insert input))) | ||
| 117 | (set-buffer (process-buffer process)) | 117 | (set-buffer (process-buffer process)) |
| 118 | (goto-char (point-max)) | 118 | (goto-char (point-max)) |
| 119 | (insert input) | 119 | (insert input) |
| @@ -131,39 +131,39 @@ | |||
| 131 | pgg-gpg-pending-status-list))) | 131 | pgg-gpg-pending-status-list))) |
| 132 | (if (and symbol | 132 | (if (and symbol |
| 133 | (fboundp symbol)) | 133 | (fboundp symbol)) |
| 134 | (funcall symbol process (buffer-substring (match-beginning 1) | 134 | (funcall symbol process (buffer-substring |
| 135 | (match-end 0))))))) | 135 | (match-beginning 1) |
| 136 | (match-end 0))))))) | ||
| 136 | (forward-line)) | 137 | (forward-line)) |
| 137 | (setq pgg-gpg-read-point (point))))) | 138 | (setq pgg-gpg-read-point (point))))) |
| 138 | 139 | ||
| 139 | (defun pgg-gpg-process-sentinel (process status) | 140 | (defun pgg-gpg-process-sentinel (process status) |
| 140 | (set-process-filter process nil) | 141 | (if (buffer-live-p (process-buffer process)) |
| 141 | (save-excursion | 142 | (save-excursion |
| 142 | ;; Copy the contents of process-buffer to pgg-errors-buffer. | 143 | (set-buffer (process-buffer process)) |
| 143 | (set-buffer (get-buffer-create pgg-errors-buffer)) | 144 | (when pgg-gpg-passphrase |
| 144 | (buffer-disable-undo) | 145 | (fillarray pgg-gpg-passphrase 0) |
| 145 | (erase-buffer) | 146 | (setq pgg-gpg-passphrase nil)) |
| 146 | (when (buffer-live-p (process-buffer process)) | 147 | ;; Copy the contents of process-buffer to pgg-errors-buffer. |
| 147 | (insert-buffer-substring (process-buffer process)) | 148 | (set-buffer (get-buffer-create pgg-errors-buffer)) |
| 148 | (goto-char (point-min)) | 149 | (buffer-disable-undo) |
| 149 | ;(delete-matching-lines "^\\[GNUPG:] ") | 150 | (erase-buffer) |
| 150 | (goto-char (point-min)) | 151 | (insert-buffer-substring (process-buffer process)) |
| 151 | (while (re-search-forward "^gpg: " nil t) | 152 | ;; Read the contents of the output file to pgg-output-buffer. |
| 152 | (replace-match ""))) | 153 | (set-buffer (get-buffer-create pgg-output-buffer)) |
| 153 | ;; Read the contents of the output file to pgg-output-buffer. | 154 | (buffer-disable-undo) |
| 154 | (set-buffer (get-buffer-create pgg-output-buffer)) | 155 | (erase-buffer) |
| 155 | (buffer-disable-undo) | 156 | (if (equal status "finished\n") |
| 156 | (erase-buffer) | 157 | (let ((output-file-name |
| 157 | (if (and (equal status "finished\n") | 158 | (with-current-buffer (process-buffer process) |
| 158 | (buffer-live-p (process-buffer process))) | 159 | pgg-gpg-output-file-name))) |
| 159 | (let ((output-file-name (with-current-buffer (process-buffer process) | 160 | (when (file-exists-p output-file-name) |
| 160 | pgg-gpg-output-file-name))) | 161 | (let ((coding-system-for-read (if pgg-text-mode |
| 161 | (when (file-exists-p output-file-name) | 162 | 'raw-text |
| 162 | (let ((coding-system-for-read (if pgg-text-mode | 163 | 'binary))) |
| 163 | 'raw-text | 164 | (insert-file-contents output-file-name)) |
| 164 | 'binary))) | 165 | (delete-file output-file-name)))) |
| 165 | (insert-file-contents output-file-name)) | 166 | (kill-buffer (process-buffer process))))) |
| 166 | (delete-file output-file-name)))))) | ||
| 167 | 167 | ||
| 168 | (defun pgg-gpg-wait-for-status (process status-list) | 168 | (defun pgg-gpg-wait-for-status (process status-list) |
| 169 | (with-current-buffer (process-buffer process) | 169 | (with-current-buffer (process-buffer process) |
| @@ -172,24 +172,12 @@ | |||
| 172 | pgg-gpg-pending-status-list) | 172 | pgg-gpg-pending-status-list) |
| 173 | (accept-process-output process 1)))) | 173 | (accept-process-output process 1)))) |
| 174 | 174 | ||
| 175 | (defun pgg-gpg-wait-for-completion (process &optional status-list) | 175 | (defun pgg-gpg-wait-for-completion (process) |
| 176 | (process-send-eof process) | 176 | (process-send-eof process) |
| 177 | (while (eq (process-status process) 'run) | 177 | (while (eq (process-status process) 'run) |
| 178 | (sit-for 0.1)) | 178 | ;; We can't use accept-process-output instead of sit-for here |
| 179 | (if (buffer-live-p (process-buffer process)) | 179 | ;; because it may cause an interrupt during the sentinel execution. |
| 180 | (save-excursion | 180 | (sit-for 0.1))) |
| 181 | (set-buffer (process-buffer process)) | ||
| 182 | (setq status-list (copy-sequence status-list)) | ||
| 183 | (let ((pointer status-list)) | ||
| 184 | (while pointer | ||
| 185 | (goto-char (point-min)) | ||
| 186 | (unless (re-search-forward | ||
| 187 | (concat "^\\[GNUPG:] " (car pointer) "\\>") | ||
| 188 | nil t) | ||
| 189 | (setq status-list (delq (car pointer) status-list))) | ||
| 190 | (setq pointer (cdr pointer)))) | ||
| 191 | (kill-buffer (process-buffer process)) | ||
| 192 | status-list))) | ||
| 193 | 181 | ||
| 194 | (defun pgg-gpg-status-USERID_HINT (process line) | 182 | (defun pgg-gpg-status-USERID_HINT (process line) |
| 195 | (if (string-match "\\`USERID_HINT \\([^ ]+\\) \\(.*\\)" line) | 183 | (if (string-match "\\`USERID_HINT \\([^ ]+\\) \\(.*\\)" line) |
| @@ -271,7 +259,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 271 | (if (and sign (not pgg-gpg-use-agent)) | 259 | (if (and sign (not pgg-gpg-use-agent)) |
| 272 | (pgg-gpg-wait-for-status process '("GOOD_PASSPHRASE"))) | 260 | (pgg-gpg-wait-for-status process '("GOOD_PASSPHRASE"))) |
| 273 | (process-send-region process start end) | 261 | (process-send-region process start end) |
| 274 | (pgg-gpg-wait-for-completion process '("SIG_CREATED" "END_ENCRYPTION")))) | 262 | (pgg-gpg-wait-for-completion process) |
| 263 | (save-excursion | ||
| 264 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 265 | (goto-char (point-max)) | ||
| 266 | (not (null (re-search-backward "^\\[GNUPG:] END_ENCRYPTION\\>" | ||
| 267 | nil t)))))) | ||
| 275 | 268 | ||
| 276 | (defun pgg-gpg-encrypt-symmetric-region (start end &optional passphrase) | 269 | (defun pgg-gpg-encrypt-symmetric-region (start end &optional passphrase) |
| 277 | "Encrypt the current region between START and END with symmetric cipher." | 270 | "Encrypt the current region between START and END with symmetric cipher." |
| @@ -281,7 +274,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 281 | (process (pgg-gpg-start-process args))) | 274 | (process (pgg-gpg-start-process args))) |
| 282 | (pgg-gpg-wait-for-status process '("BEGIN_ENCRYPTION")) | 275 | (pgg-gpg-wait-for-status process '("BEGIN_ENCRYPTION")) |
| 283 | (process-send-region process start end) | 276 | (process-send-region process start end) |
| 284 | (pgg-gpg-wait-for-completion process '("END_ENCRYPTION")))) | 277 | (pgg-gpg-wait-for-completion process) |
| 278 | (save-excursion | ||
| 279 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 280 | (goto-char (point-max)) | ||
| 281 | (not (null (re-search-backward "^\\[GNUPG:] END_ENCRYPTION\\>" | ||
| 282 | nil t)))))) | ||
| 285 | 283 | ||
| 286 | (defun pgg-gpg-decrypt-region (start end &optional passphrase) | 284 | (defun pgg-gpg-decrypt-region (start end &optional passphrase) |
| 287 | "Decrypt the current region between START and END." | 285 | "Decrypt the current region between START and END." |
| @@ -289,7 +287,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 289 | (process (pgg-gpg-start-process args))) | 287 | (process (pgg-gpg-start-process args))) |
| 290 | (process-send-region process start end) | 288 | (process-send-region process start end) |
| 291 | (pgg-gpg-wait-for-status process '("BEGIN_DECRYPTION")) | 289 | (pgg-gpg-wait-for-status process '("BEGIN_DECRYPTION")) |
| 292 | (pgg-gpg-wait-for-completion process '("GOODSIG" "DECRYPTION_OKAY")))) | 290 | (pgg-gpg-wait-for-completion process) |
| 291 | (save-excursion | ||
| 292 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 293 | (goto-char (point-max)) | ||
| 294 | (not (null (re-search-backward "^\\[GNUPG:] DECRYPTION_OKAY\\>" | ||
| 295 | nil t)))))) | ||
| 293 | 296 | ||
| 294 | (defun pgg-gpg-sign-region (start end &optional cleartext passphrase) | 297 | (defun pgg-gpg-sign-region (start end &optional cleartext passphrase) |
| 295 | "Make detached signature from text between START and END." | 298 | "Make detached signature from text between START and END." |
| @@ -303,7 +306,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 303 | (unless pgg-gpg-use-agent | 306 | (unless pgg-gpg-use-agent |
| 304 | (pgg-gpg-wait-for-status process '("GOOD_PASSPHRASE"))) | 307 | (pgg-gpg-wait-for-status process '("GOOD_PASSPHRASE"))) |
| 305 | (process-send-region process start end) | 308 | (process-send-region process start end) |
| 306 | (pgg-gpg-wait-for-completion process '("SIG_CREATED")))) | 309 | (pgg-gpg-wait-for-completion process) |
| 310 | (save-excursion | ||
| 311 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 312 | (goto-char (point-max)) | ||
| 313 | (not (null (re-search-backward "^\\[GNUPG:] SIG_CREATED\\>" | ||
| 314 | nil t)))))) | ||
| 307 | 315 | ||
| 308 | (defun pgg-gpg-verify-region (start end &optional signature) | 316 | (defun pgg-gpg-verify-region (start end &optional signature) |
| 309 | "Verify region between START and END as the detached signature SIGNATURE." | 317 | "Verify region between START and END as the detached signature SIGNATURE." |
| @@ -313,7 +321,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 313 | (setq args (append args (list signature)))) | 321 | (setq args (append args (list signature)))) |
| 314 | (setq process (pgg-gpg-start-process (append args '("-")))) | 322 | (setq process (pgg-gpg-start-process (append args '("-")))) |
| 315 | (process-send-region process start end) | 323 | (process-send-region process start end) |
| 316 | (pgg-gpg-wait-for-completion process '("GOODSIG")))) | 324 | (pgg-gpg-wait-for-completion process) |
| 325 | (save-excursion | ||
| 326 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 327 | (goto-char (point-max)) | ||
| 328 | (not (null (re-search-backward "^\\[GNUPG:] GOODSIG\\>" | ||
| 329 | nil t)))))) | ||
| 317 | 330 | ||
| 318 | (defun pgg-gpg-insert-key () | 331 | (defun pgg-gpg-insert-key () |
| 319 | "Insert public key at point." | 332 | "Insert public key at point." |
| @@ -330,7 +343,12 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt." | |||
| 330 | (process (pgg-gpg-start-process args)) | 343 | (process (pgg-gpg-start-process args)) |
| 331 | status) | 344 | status) |
| 332 | (process-send-region process start end) | 345 | (process-send-region process start end) |
| 333 | (pgg-gpg-wait-for-completion process '("IMPORT_RES")))) | 346 | (pgg-gpg-wait-for-completion process) |
| 347 | (save-excursion | ||
| 348 | (set-buffer (get-buffer-create pgg-errors-buffer)) | ||
| 349 | (goto-char (point-max)) | ||
| 350 | (not (null (re-search-backward "^\\[GNUPG:] IMPORT_RES\\>" | ||
| 351 | nil t)))))) | ||
| 334 | 352 | ||
| 335 | (provide 'pgg-gpg) | 353 | (provide 'pgg-gpg) |
| 336 | 354 | ||