From: "Michal Nazarewicz" <mina86@mina86.com>
To: emacs-devel@gnu.org
Subject: Add support for MPC password
Date: Fri, 03 Aug 2012 06:08:43 +0200 [thread overview]
Message-ID: <op.wif5stuz3l0zgt@mpn-glaptop> (raw)
Hi guys,
Below is a patch for mpc.el that adds support for login password.
I'm not entirely sure how to send patches, but I hope that you can make
use from the attached patch.
As for copyright, it goes to Google, which has already signed the agreement,
so there should be no problem on that front.
------------------ >8 -----------------------------------------------------
Add support for MPC password
The MPD_HOST environment variable may contain a password used to connect
to MPD. With this change, mpc.el accepts this format and sends password
when connecting.
* lisp/mpc.el (mpc--proc-connect): Support password in host argument, and
set mpc-proc variable instead of returning process. This is required so
that the function can call mpc-proc-cmd. Without that, mpc-proc-cmd
would call mpc-proc, which would call mpc--proc-connect ad infinitum.
(mpc-proc): Refactor since mpc-proc variable is set by mpc--proc-connect.
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: mina86@mina86.com-20120803035348-luup7bqmfmo1xedt
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: da3759cf2d6fb972905b652eee11b8975d360e3d
# timestamp: 2012-08-03 05:55:28 +0200
# base_revision_id: tsdh@gnu.org-20120802190453-usyiu7n45qi456be
#
# Begin patch
=== modified file 'lisp/mpc.el'
--- lisp/mpc.el 2012-07-10 11:51:54 +0000
+++ lisp/mpc.el 2012-08-03 03:53:48 +0000
@@ -199,9 +199,10 @@
(defcustom mpc-host
(concat (or (getenv "MPD_HOST") "localhost")
(if (getenv "MPD_PORT") (concat ":" (getenv "MPD_PORT"))))
- "Host (and port) where the Music Player Daemon is running.
-The format is \"HOST\" or \"HOST:PORT\" where PORT defaults to 6600
-and HOST defaults to localhost."
+ "Host (and port) where the Music Player Daemon is running. The
+format is \"HOST\", \"HOST:PORT\", \"PASSWORD@HOST\" or
+\"PASSWORD@HOST:PORT\" where PASSWORD defaults to no password, PORT
+defaults to 6600 and HOST defaults to localhost."
:type 'string)
(defvar mpc-proc nil)
@@ -252,20 +253,30 @@
(funcall callback)))))))))
(defun mpc--proc-connect (host)
- (mpc--debug "Connecting to %s..." host)
- (with-current-buffer (get-buffer-create (format " *mpc-%s*" host))
- ;; (pop-to-buffer (current-buffer))
- (let (proc)
- (while (and (setq proc (get-buffer-process (current-buffer)))
- (progn ;; (debug)
- (delete-process proc)))))
- (erase-buffer)
- (let ((port 6600))
- (when (string-match ":[^.]+\\'" host)
- (setq port (substring host (1+ (match-beginning 0))))
- (setq host (substring host 0 (match-beginning 0)))
- (unless (string-match "[^[:digit:]]" port)
- (setq port (string-to-number port))))
+ (let ((port 6600)
+ pass)
+
+ (when (string-match "\\`\\(?:\\(.*\\)@\\)?\\(.*?\\)\\(?::\\(.*\\)\\)?\\'"
+ host)
+ (let ((v (match-string 1 host)))
+ (when (and (stringp v) (not (string= "" v)))
+ (setq pass v)))
+ (let ((v (match-string 3 host)))
+ (setq host (match-string 2 host))
+ (when (and (stringp v) (not (string= "" v)))
+ (setq port
+ (if (string-match "[^[:digit:]]" v)
+ (string-to-number v)
+ v)))))
+
+ (mpc--debug "Connecting to %s:%s..." host port)
+ (with-current-buffer (get-buffer-create (format " *mpc-%s:%s*" host port))
+ ;; (pop-to-buffer (current-buffer))
+ (let (proc)
+ (while (and (setq proc (get-buffer-process (current-buffer)))
+ (progn ;; (debug)
+ (delete-process proc)))))
+ (erase-buffer)
(let* ((coding-system-for-read 'utf-8-unix)
(coding-system-for-write 'utf-8-unix)
(proc (open-network-stream "MPC" (current-buffer) host port)))
@@ -282,7 +293,9 @@
(set-process-query-on-exit-flag proc nil)
;; This may be called within a process filter ;-(
(with-local-quit (mpc-proc-sync proc))
- proc))))
+ (setq mpc-proc proc)
+ (when pass
+ (mpc-proc-cmd (list "password" pass) nil))))))
(defun mpc--proc-quote-string (s)
(if (numberp s) (number-to-string s)
@@ -306,11 +319,11 @@
(nreverse alists)))
(defun mpc-proc ()
- (or (and mpc-proc
- (buffer-live-p (process-buffer mpc-proc))
- (not (memq (process-status mpc-proc) '(closed)))
- mpc-proc)
- (setq mpc-proc (mpc--proc-connect mpc-host))))
+ (unless (and mpc-proc
+ (buffer-live-p (process-buffer mpc-proc))
+ (not (memq (process-status mpc-proc) '(closed))))
+ (mpc--proc-connect mpc-host))
+ mpc-proc)
(defun mpc-proc-check (proc)
(let ((error-text (process-get proc 'mpc-proc-error)))
# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWSPB4w0AAsv/gHUdVABS9///
/kPcj//v//BgBp0Zbnd9gG9a7252h1dnu5XnwyQTQRp6Jg1MpkTBqM01DEwQAGh6IyaDIUYmCNI0
0KntTSflJ6hoaBjKaZNAAD1GmgkiZTTUp+VHqP1R6GpsptI0NAAMgAAAADElTZT1DyT0Qwm1DCZA
NGI00aA0aGmnojIcaMmRhGIBhNBgE0GgZMmjJkMIDCRSNTTCMJNT9DVPGqA0ANABkMmgAARwgIok
ubb8pLM5TIF9SipYrxzU/EiKqIlQ9VrICKwHrpl3Q1k7O9CR1t+s7KdMrFaW47rKFCBAJDQSaAEZ
qH3b+AyOpRfsFy61a2rhVM/+yImzEJV9/8dsyNCxLnGO9EQiLuDmZK4aFMGfmzuc2RGotbl6Fhma
bF5QpRuYQTly+wbgG5JJ82yUzF4dJfb4vsSsP8g67lDqHZrxqXyjBu3Fc6PhRb9kd0NqJlznJnJW
a+uNO/BzYIvB3JOcQr0moYQsnZFGkSBHO3gxQlEan0S+fpr3F3aP3CjBk+Gx4jxBBxGJawiCDiFX
GFtRAIhEdcbHBdY30GKIuhXL+q44Ue7xklFRkQQVYbUHQ2b3NIE5tuvEzdF+9MF9ZRe7jMSzsEuM
RqedbTtIytvLl23SpwWS8Gw6eJ1sl+wfZ8cspqBMnb8PRvJffwBmHx7Y4AGIEG+acDaPjGwrZIua
2iG4Uboqu6CXVEXG3CFdlcdfI4gTrCKxDlIYgBeziLVFi6JsFMQTL2giULcqFkkhOSFdRFhDMKDr
9Hk3jHuk6MaTL4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8N8iXIUVTQxYtny4gzQU0BgoBHFAapxAEnMO7LKj9uLcnec2alFouJSCyASqrn4RHZL
VpoJbtJwRdl4rMG0z5tG1xEKbZI7iCeVUyMHLAg0QwZQU50E8iPpMgL0KKUjMSEA5mBQepybpfIi
MeBylkwW6mYRAuZmyQKGeXhSlc17LQqhOmjHABT7UKYoGbBTOGD41SuhDDdlB1QGkMUuuE6FCgCA
rQkNhtkApmTBsQXihmM8qOmUD1QNfe8zFIpSCs4XkywwViWVRoi7G6eIa4oKsUu5WI1wGbELhWmI
qYvEENhdMDE4kIoITbUykbjUPnwYWGYT2EjhoGiQ5ZNrbbc+4Gr7JJYUt10nJaDMGk+SHPZScyQA
cb0cUWlzwWNhz9QMZzWyIFSEVqDBOIqBdyRThQkCPB4w0A==
next reply other threads:[~2012-08-03 4:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-03 4:08 Michal Nazarewicz [this message]
2012-08-04 7:38 ` Add support for MPC password Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=op.wif5stuz3l0zgt@mpn-glaptop \
--to=mina86@mina86.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).