From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mike Kazantsev Newsgroups: gmane.emacs.devel Subject: [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them Date: Mon, 31 Oct 2011 09:56:58 +0600 Message-ID: <20111031095658.47f826d8@sacrilege> References: <20111029120402.257da486@sacrilege> <20111030105020.19ad8b47@sacrilege> <20111030113143.66c44ae9@sacrilege> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/ueMuzgsEbc.S3JyU6K8jah5"; protocol="application/pgp-signature" X-Trace: dough.gmane.org 1320033436 5014 80.91.229.12 (31 Oct 2011 03:57:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Oct 2011 03:57:16 +0000 (UTC) Cc: Michael Olson To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 31 04:57:12 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 1RKizm-00041w-LM for ged-emacs-devel@m.gmane.org; Mon, 31 Oct 2011 04:57:10 +0100 Original-Received: from localhost ([::1]:60110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKizm-0007rn-3r for ged-emacs-devel@m.gmane.org; Sun, 30 Oct 2011 23:57:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKizj-0007rW-Bc for emacs-devel@gnu.org; Sun, 30 Oct 2011 23:57:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKizh-0004KD-Ut for emacs-devel@gnu.org; Sun, 30 Oct 2011 23:57:07 -0400 Original-Received: from mail-bw0-f41.google.com ([209.85.214.41]:49960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKizh-0004K3-AD; Sun, 30 Oct 2011 23:57:05 -0400 Original-Received: by bkbzv15 with SMTP id zv15so929797bkb.0 for ; Sun, 30 Oct 2011 20:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type; bh=VDsL3ThosUulgboknUpK2D63rqJkbZy+GBt2P5uts3A=; b=qmjxQkIVbd94XXzSBfLY3qbAVZ4AjNgQTduUS1er3qAP2j18wbr5v8IeZOkQV+nXvp iyGx6XIKzr2f1ZgETiVOimyzl9SCSpZJakFmoPMYPM8myjD6op+b4MpnwLBVcAXIdgjf 1iM7z6s9DmgS9tVsvNhFUN7AEvAi9o0ztQt4g= Original-Received: by 10.205.112.6 with SMTP id eq6mr9245785bkc.16.1320033423404; Sun, 30 Oct 2011 20:57:03 -0700 (PDT) Original-Received: from sacrilege ([188.226.51.71]) by mx.google.com with ESMTPS id zv16sm157027bkb.6.2011.10.30.20.57.01 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 30 Oct 2011 20:57:02 -0700 (PDT) In-Reply-To: X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.7; i686-pc-linux-gnu) 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:145809 Archived-At: --Sig_/ueMuzgsEbc.S3JyU6K8jah5 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Good day, This patch allows receiving DCC SEND requests like these: DCC 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. =46rom 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 with spaces in them * erc-dcc.el (erc-dcc-ctcp-query-send-regexp): Updated regexp to match quoted filenames with spaces inside. (erc-dcc-handle-ctcp-send): Updated regexp match group numbers, added processing of escaped quotes and backslashes if filename itself was in quotes. --- erc-dcc.el | 21 ++++++++++++++++----- 1 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." ?q query ?n nick ?u login ?h host)))) =20 (defconst erc-dcc-ctcp-query-send-regexp - "^DCC SEND \\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)") + (concat "^DCC SEND \\(" + ;; Following part matches either filename without spaces + ;; or filename enclosed in double quotes with any number + ;; of escaped double quotes inside. + "\"\\(\\(.*?\\(\\\\\"\\)?\\)+?\\)\"\\|\\([^ ]+\\)" + "\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)")) + +(defsubst erc-dcc-unquote-filename (filename) + (erc-replace-regexp-in-string "\\\\\\\\" "\\" + (erc-replace-regexp-in-string "\\\\\"" "\"" filename t t) t t)) =20 (defun erc-dcc-handle-ctcp-send (proc query nick login host to) "This is called if a CTCP DCC SEND subcommand is sent to the client. @@ -661,10 +670,12 @@ It extracts the information about the dcc request and= adds it to 'dcc-request-bogus ?r "SEND" ?n nick ?u login ?h host)) ((string-match erc-dcc-ctcp-query-send-regexp query) - (let ((filename (match-string 1 query)) - (ip (erc-decimal-to-ip (match-string 2 query))) - (port (match-string 3 query)) - (size (match-string 4 query))) + (let ((filename + (or (match-string 3 query) + (erc-dcc-unquote-filename (match-string 2 query)))) + (ip (erc-decimal-to-ip (match-string 6 query))) + (port (match-string 7 query)) + (size (match-string 8 query))) ;; FIXME: a warning really should also be sent ;; if the ip address !=3D the host the dcc sender is on. (erc-display-message --=20 1.7.7 --=20 Mike Kazantsev // fraggod.net --Sig_/ueMuzgsEbc.S3JyU6K8jah5 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (GNU/Linux) iEYEARECAAYFAk6uHIoACgkQASbOZpzyXnEaaACg8JDbbyjzPy6DYc4eUmVO/wso szkAn15m0zJutrJeSXXArKvPOOj+gb31 =gQVG -----END PGP SIGNATURE----- --Sig_/ueMuzgsEbc.S3JyU6K8jah5--