[cl-irc-devel] Elimination of trailing-argument

Erik Huelsmann e.huelsmann at gmx.net
Tue Feb 14 23:02:31 UTC 2006


As brought up by Zach in Jan 2004, cl-irc distinguishes between arguments
and trailing-argument. The RFCs don't: the ':' preceding the trailing
argument is just 'syntactic sugar to allow SPACE characters in an argument'.

The patch below introduces a growth path to a situation without a trailing
argument field:

- eliminate the field (but introduce a method by the same name)
- remove the (temporary) method (in 6 months)

Why is applying this patch important?

Some networks send:

:<USER> JOIN <#channel>

Others

:<USER> JOIN :<#channel>

Which are equivalent in the RFC, but quite different from a library user
POV.

Applying this patch would resolve that issue.

Comments?

Bye,


Erik.



Index: parse-message.lisp
===================================================================
RCS file: /project/cl-irc/cvsroot/cl-irc/parse-message.lisp,v
retrieving revision 1.6
diff -u -r1.6 parse-message.lisp
--- parse-message.lisp  21 Mar 2005 18:15:52 -0000      1.6
+++ parse-message.lisp  14 Feb 2006 22:56:47 -0000
@@ -60,6 +60,19 @@
 trailing-argument part is not present."
   (cut-between string #\: '(#\Return) :start start))
  
+(defun combine-arguments-and-trailing (string &key (start 0))
+  (multiple-value-bind
+      (start return-string)
+      (return-arguments string :start start)
+    (print return-string)
+    (multiple-value-bind
+        (return-index trailing)
+        (return-trailing-argument string :start start)
+      (print trailing)
+      (values return-index
+              (append return-string (when (and trailing (string/= ""
trailing))+                                      (list trailing)))))))
+
 (defun parse-raw-message (string &key (start 0))
   "Assuming `string' is a valid IRC message, parse the message and
 return the values in the following order:
@@ -78,8 +91,7 @@
                         return-user
                         return-host
                         return-command
-                        return-arguments
-                        return-trailing-argument))
+                        combine-arguments-and-trailing))
       (multiple-value-bind (return-index return-string)
           (funcall function string :start index)
         (setf index return-index)
@@ -145,10 +157,11 @@
   "If `string' is a valid IRC message parse it and return an object of
 the correct type with its slots prefilled according to the information
 in the message."
-  (multiple-value-bind (source user host command arguments
trailing-argument)
+  (multiple-value-bind (source user host command arguments)
       (parse-raw-message string)
-    (let ((class 'irc-message)
-          (ctcp (ctcp-message-type trailing-argument)))
+    (let* ((class 'irc-message)
+           (trailing-argument (car (last arguments)))
+           (ctcp (ctcp-message-type trailing-argument)))
       (when command
         (cond
           (nil ;(irc-error-reply-p command)
@@ -177,7 +190,6 @@
                                                   "")
                                      :arguments arguments
                                      :connection nil
-                                     :trailing-argument (or
trailing-argument "")
                                      :received-time (get-universal-time)
                                      :raw-message-string (or string ""))))
         (when ctcp
Index: protocol.lisp
===================================================================
RCS file: /project/cl-irc/cvsroot/cl-irc/protocol.lisp,v
retrieving revision 1.33
diff -u -r1.33 protocol.lisp
--- protocol.lisp       12 Feb 2006 08:08:07 -0000      1.33
+++ protocol.lisp       14 Feb 2006 22:56:47 -0000
@@ -817,10 +817,6 @@
     :accessor arguments
     :initarg :arguments
     :type list)
-   (trailing-argument
-    :accessor trailing-argument
-    :initarg :trailing-argument
-    :type string)
    (connection
     :accessor connection
     :initarg :connection)
@@ -837,6 +833,12 @@
   (print-unreadable-object (object stream :type t :identity t)
     (format stream "~A ~A" (source object) (command object))))
  
+;;Compat code; remove after 2006-08-01
+
+(defgeneric trailing-argument (message))
+(defmethod trailing-argument ((message irc-message))
+  (car (last (arguments message))))
+
 (defgeneric self-message-p (message))
 (defgeneric find-irc-message-class (type))
 (defgeneric client-log (connection message &optional prefix))
Index: test/test-parse-message.lisp
===================================================================
RCS file: /project/cl-irc/cvsroot/cl-irc/test/test-parse-message.lisp,v
retrieving revision 1.2
diff -u -r1.2 test-parse-message.lisp
--- test/test-parse-message.lisp        5 Jan 2004 14:18:07 -0000       1.2
+++ test/test-parse-message.lisp        14 Feb 2006 22:56:47 -0000
@@ -10,6 +10,8 @@
 (defvar *msg3* (format nil "NOTICE AUTH :*** Your forward and reverse DNS
don't match~A" #\Return))
 (defvar *msg4* (format nil
":kire_!~~eenge at adsl-156-35-240.asm.bellsouth.net MODE #lisppaste +k key~A"
#\Return))
 (defvar *msg5* (format nil
":kire_!~~eenge at adsl-156-35-240.asm.bellsouth.net MODE #lisppaste +bbb
*!*@somewhere.com *!*@somewhereles.com *!*@youdontwannaknow.org~A"
#\Return))
+(defvar *msg6* (format nil ":kire!~~eenge at 216.248.178.227 PRIVMSG cl-irc
heyhey!~A" #\Return))
+
  
 (deftest find-reply-name.1 (irc:find-reply-name 1) :rpl_welcome)
 (deftest find-reply-name.2
@@ -59,4 +61,8 @@
  
 (deftest parse-raw-message.1
     (irc::parse-raw-message cl-irc-test::*msg1*)
-  "kire" "~eenge" "216.248.178.227" "PRIVMSG" ("cl-irc") "heyhey!")
+  "kire" "~eenge" "216.248.178.227" "PRIVMSG" ("cl-irc" "heyhey!"))
+
+(deftest no-trailing.1
+  (irc::parse-raw-message *msg6*)
+  "kire" "~eenge" "216.248.178.227" "PRIVMSG" ("cl-irc" "heyhey!"))

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner



More information about the cl-irc-devel mailing list