From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Michal Nazarewicz" Newsgroups: gmane.emacs.devel Subject: Add support for MPC password Date: Fri, 03 Aug 2012 06:08:43 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1343966933 28914 80.91.229.3 (3 Aug 2012 04:08:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Aug 2012 04:08:53 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 03 06:08:54 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sx9C1-0001je-7d for ged-emacs-devel@m.gmane.org; Fri, 03 Aug 2012 06:08:53 +0200 Original-Received: from localhost ([::1]:41147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx9C0-0002f2-Aq for ged-emacs-devel@m.gmane.org; Fri, 03 Aug 2012 00:08:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx9Bx-0002eP-FV for emacs-devel@gnu.org; Fri, 03 Aug 2012 00:08:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sx9Bv-0005C7-KE for emacs-devel@gnu.org; Fri, 03 Aug 2012 00:08:49 -0400 Original-Received: from mail-ee0-f41.google.com ([74.125.83.41]:51194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx9Bv-0005By-9g for emacs-devel@gnu.org; Fri, 03 Aug 2012 00:08:47 -0400 Original-Received: by eeke49 with SMTP id e49so41832eek.0 for ; Thu, 02 Aug 2012 21:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:content-type:to:date:subject:mime-version :content-transfer-encoding:from:message-id:user-agent; bh=2dDQk07KglrUPBZMr6U71I/0KJ2/PXfRw7xvwnqiNRo=; b=Gs3I8rnt2vFHqtHeACRnyI/hp1dcOlyY2Q9Y4nrpmBWWyLdx+CXNkoFPWByZdvwvSN Yxd/B1WFBwZX6Jt5DFarsUmoY85ufPFj75Q4vVyV6UGNYNz7TwnDN4LIHYVe2j3mq+CW 2X3NSHbOvi0ta+fJBie94RewYyegyvrBM+mb5EL4zgZqa0omHoCgw+ouJGoezcHPR0Qw K/t/JmkTLefsyYY0ChBn/wacaJfo4xczrgjxC6kYikljmogkoUvJ+hIRhAkZYnuLuo0p iOC3kGvPYIygGCti371BnVIqqkZaKMryJMg0dovVS7KiFysKb1ddV2h3NvJ2nqGjb9AA CzQw== Original-Received: by 10.14.179.71 with SMTP id g47mr435384eem.21.1343966926297; Thu, 02 Aug 2012 21:08:46 -0700 (PDT) Original-Received: from mpn-glaptop ([2620:0:105f:5:f2de:f1ff:fe35:1a72]) by mx.google.com with ESMTPS id g42sm22272026eem.14.2012.08.02.21.08.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Aug 2012 21:08:45 -0700 (PDT) User-Agent: Opera Mail/12.00 (Linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.83.41 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152133 Archived-At: 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//BgBp0Zbnd9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