From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Olson Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them Date: Sun, 30 Oct 2011 21:47:48 -0700 Message-ID: References: <20111029120402.257da486@sacrilege> <20111030105020.19ad8b47@sacrilege> <20111030113143.66c44ae9@sacrilege> <20111031095658.47f826d8@sacrilege> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1320036504 19798 80.91.229.12 (31 Oct 2011 04:48:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Oct 2011 04:48:24 +0000 (UTC) Cc: emacs-devel@gnu.org To: Mike Kazantsev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 31 05:48:19 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RKjnG-0006Db-69 for ged-emacs-devel@m.gmane.org; Mon, 31 Oct 2011 05:48:18 +0100 Original-Received: from localhost ([::1]:55231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKjnF-0000Ir-C6 for ged-emacs-devel@m.gmane.org; Mon, 31 Oct 2011 00:48:17 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:44683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKjnC-0000Ih-F2 for emacs-devel@gnu.org; Mon, 31 Oct 2011 00:48:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKjnA-0004It-9L for emacs-devel@gnu.org; Mon, 31 Oct 2011 00:48:14 -0400 Original-Received: from mail-bw0-f41.google.com ([209.85.214.41]:35178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKjnA-0004In-2r for emacs-devel@gnu.org; Mon, 31 Oct 2011 00:48:12 -0400 Original-Received: by bkbzv15 with SMTP id zv15so952270bkb.0 for ; Sun, 30 Oct 2011 21:48:11 -0700 (PDT) Original-Received: by 10.205.113.17 with SMTP id eu17mr9131745bkc.76.1320036490154; Sun, 30 Oct 2011 21:48:10 -0700 (PDT) Original-Received: by 10.205.81.196 with HTTP; Sun, 30 Oct 2011 21:47:48 -0700 (PDT) X-Originating-IP: [99.116.250.80] In-Reply-To: <20111031095658.47f826d8@sacrilege> X-Google-Sender-Auth: 0LMIVScdoGRr3olLIboj7jvP0lE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.214.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:145812 Archived-At: +1 from me On Sun, Oct 30, 2011 at 8:56 PM, Mike Kazantsev wrot= e: > Good day, > > This patch allows receiving DCC SEND requests like these: > > =C2=A0DCC SEND "some name with spaces" 3473212121 3746 322641 > > Filename here is enclosed in double quotes, which seem to be a common > IRC client (and dcc bot) convention for names with whitespaces and is > widely used in file-sharing channels. > > Main change here is regexp, matching the filename, with additional > processing of matched result to unescape any double quotes and slashes > that might be inside. > > Any quoted filename will be processed through erc-dcc-unquote-filename > from now on, which contradicts pre-patch behavior somewhat in that now > "file\"x" will be stored as file"x, not as-is (with enclosing quotes), > even if filename doesn't have any spaces in it. > It seemed to be more consistent behavor for cases when clients might use > quoting w/o regard to the actual quoted contents. > > Patch was created on top of erc tree. > Many thanks to Michael Olson for giving the patch a thorough review. > > Thanks. > > > From b18c2639d53c2b87270ad21198cfe09a9b6a6684 Mon Sep 17 00:00:00 2001 > From: Mike Kazantsev > Date: Sat, 29 Oct 2011 11:36:49 +0600 > Subject: [PATCH] erc-dcc: allow SEND commands containing quoted filenames > =C2=A0with spaces in them > > * erc-dcc.el (erc-dcc-ctcp-query-send-regexp): Updated regexp to match > =C2=A0 =C2=A0quoted filenames with spaces inside. > =C2=A0(erc-dcc-handle-ctcp-send): Updated regexp match group numbers, add= ed > =C2=A0 =C2=A0processing of escaped quotes and backslashes if filename its= elf was > =C2=A0 =C2=A0in quotes. > --- > =C2=A0erc-dcc.el | =C2=A0 21 ++++++++++++++++----- > =C2=A01 files changed, 16 insertions(+), 5 deletions(-) > > diff --git a/erc-dcc.el b/erc-dcc.el > index 9e53edc..5aa346b 100644 > --- a/erc-dcc.el > +++ b/erc-dcc.el > @@ -646,7 +646,16 @@ that subcommand." > =C2=A0 =C2=A0 =C2=A0 =C2=A0?q query ?n nick ?u login ?h host)))) > > =C2=A0(defconst erc-dcc-ctcp-query-send-regexp > - =C2=A0"^DCC SEND \\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)") > + =C2=A0(concat "^DCC SEND \\(" > + =C2=A0 =C2=A0;; Following part matches either filename without spaces > + =C2=A0 =C2=A0;; or filename enclosed in double quotes with any number > + =C2=A0 =C2=A0;; of escaped double quotes inside. > + =C2=A0 =C2=A0"\"\\(\\(.*?\\(\\\\\"\\)?\\)+?\\)\"\\|\\([^ ]+\\)" > + =C2=A0 =C2=A0"\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)")) > + > +(defsubst erc-dcc-unquote-filename (filename) > + =C2=A0(erc-replace-regexp-in-string "\\\\\\\\" "\\" > + =C2=A0 =C2=A0(erc-replace-regexp-in-string "\\\\\"" "\"" filename t t) = t t)) > > =C2=A0(defun erc-dcc-handle-ctcp-send (proc query nick login host to) > =C2=A0 "This is called if a CTCP DCC SEND subcommand is sent to the clien= t. > @@ -661,10 +670,12 @@ It extracts the information about the dcc request a= nd adds it to > =C2=A0 =C2=A0 =C2=A0 =C2=A0'dcc-request-bogus > =C2=A0 =C2=A0 =C2=A0 =C2=A0?r "SEND" ?n nick ?u login ?h host)) > =C2=A0 =C2=A0 =C2=A0((string-match erc-dcc-ctcp-query-send-regexp query) > - =C2=A0 =C2=A0 =C2=A0(let ((filename (match-string 1 query)) > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(ip =C2=A0 =C2=A0 =C2=A0 (erc-= decimal-to-ip (match-string 2 query))) > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(port =C2=A0 =C2=A0 (match-str= ing 3 query)) > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(size =C2=A0 =C2=A0 (match-str= ing 4 query))) > + =C2=A0 =C2=A0 =C2=A0(let ((filename > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or (match-string 3 que= ry) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(erc-dcc-= unquote-filename (match-string 2 query)))) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(ip =C2=A0 =C2=A0 =C2=A0 (erc-= decimal-to-ip (match-string 6 query))) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(port =C2=A0 =C2=A0 (match-str= ing 7 query)) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(size =C2=A0 =C2=A0 (match-str= ing 8 query))) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; FIXME: a warning really should also be sen= t > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; if the ip address !=3D the host the dcc se= nder is on. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 (erc-display-message > -- > 1.7.7 > > > > -- > Mike Kazantsev // fraggod.net > --=20 Michael Olson=C2=A0 |=C2=A0 http://mwolson.org/