[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] erc-dcc: allow SEND commands containing quoted filenames with sp

From: Mike Kazantsev
Subject: [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them
Date: Mon, 31 Oct 2011 09:56:58 +0600

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.


From b18c2639d53c2b87270ad21198cfe09a9b6a6684 Mon Sep 17 00:00:00 2001
From: Mike Kazantsev <address@hidden>
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))))
 (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))
 (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
        ?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 != the host the dcc sender is on.

Mike Kazantsev // fraggod.net

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]