unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them
       [not found]         ` <CAN4ruPiKhLBq1e85kESLON4X_pdmcvffx89DTUw76yq8rZUJEg@mail.gmail.com>
@ 2011-10-31  3:56           ` Mike Kazantsev
  2011-10-31  4:47             ` Michael Olson
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Kazantsev @ 2011-10-31  3:56 UTC (permalink / raw)
  To: emacs-devel; +Cc: Michael Olson

[-- Attachment #1: Type: text/plain, Size: 3504 bytes --]

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.


From b18c2639d53c2b87270ad21198cfe09a9b6a6684 Mon Sep 17 00:00:00 2001
From: Mike Kazantsev <mk.fraggod@gmail.com>
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
        '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 != the host the dcc sender is on.
         (erc-display-message
-- 
1.7.7



-- 
Mike Kazantsev // fraggod.net

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them
  2011-10-31  3:56           ` [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them Mike Kazantsev
@ 2011-10-31  4:47             ` Michael Olson
  2011-11-03 11:32               ` Mario Lang
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Olson @ 2011-10-31  4:47 UTC (permalink / raw)
  To: Mike Kazantsev; +Cc: emacs-devel

+1 from me

On Sun, Oct 30, 2011 at 8:56 PM, Mike Kazantsev <mk.fraggod@gmail.com> wrote:
> 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.
>
>
> From b18c2639d53c2b87270ad21198cfe09a9b6a6684 Mon Sep 17 00:00:00 2001
> From: Mike Kazantsev <mk.fraggod@gmail.com>
> 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
>        '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 != the host the dcc sender is on.
>         (erc-display-message
> --
> 1.7.7
>
>
>
> --
> Mike Kazantsev // fraggod.net
>



-- 
Michael Olson  |  http://mwolson.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them
  2011-10-31  4:47             ` Michael Olson
@ 2011-11-03 11:32               ` Mario Lang
  0 siblings, 0 replies; 3+ messages in thread
From: Mario Lang @ 2011-11-03 11:32 UTC (permalink / raw)
  To: emacs-devel

Michael Olson <mwolson@gnu.org> writes:

Looks fine.

> +1 from me
>
> On Sun, Oct 30, 2011 at 8:56 PM, Mike Kazantsev <mk.fraggod@gmail.com> wrote:
>> 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.
>>
>>
>> From b18c2639d53c2b87270ad21198cfe09a9b6a6684 Mon Sep 17 00:00:00 2001
>> From: Mike Kazantsev <mk.fraggod@gmail.com>
>> 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
>>        '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 != the host the dcc sender is on.
>>         (erc-display-message
>> --
>> 1.7.7
>>
>>
>>
>> --
>> Mike Kazantsev // fraggod.net
>>

-- 
CYa,
  ⡍⠁⠗⠊⠕ | Debian Developer <URL:http://debian.org/>
  .''`. | Get my public key via finger mlang/key@db.debian.org
 : :' : | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44
 `. `'
   `-      <URL:http://delysid.org/>  <URL:http://www.staff.tugraz.at/mlang/>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-03 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20111029120402.257da486@sacrilege>
     [not found] ` <CAN4ruPgO8QMmvhDRMJmiK6ROimp+K68-0ffbnY=hMT4yFf_n6A@mail.gmail.com>
     [not found]   ` <20111030105020.19ad8b47@sacrilege>
     [not found]     ` <20111030113143.66c44ae9@sacrilege>
     [not found]       ` <CAN4ruPhfn1vs4DWW34B-gYGk6gN2_znrX9VgiMyhrp51UrXG4A@mail.gmail.com>
     [not found]         ` <CAN4ruPiKhLBq1e85kESLON4X_pdmcvffx89DTUw76yq8rZUJEg@mail.gmail.com>
2011-10-31  3:56           ` [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them Mike Kazantsev
2011-10-31  4:47             ` Michael Olson
2011-11-03 11:32               ` Mario Lang

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).