From 0adb3f8db21f8c45e90efa979f229dd095c36eae Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 23 Jun 2003 06:19:57 +0000 Subject: [PATCH] * riece-300.el: Rewrite using riece-decode-identity. * riece-identity.el (riece-completing-read-identity): Signal an error when the encoded channel name is not matched with riece-channel-regexp. * riece-globals.el (riece-channel-regexp): Moved from riece-channel.el. (riece-user-regexp): Moved form riece-user.el. --- lisp/ChangeLog | 12 +++ lisp/riece-300.el | 198 ++++++++++++++++++++++++++---------------------- lisp/riece-channel.el | 5 +- lisp/riece-globals.el | 6 ++ lisp/riece-identity.el | 4 + lisp/riece-user.el | 3 - 6 files changed, 132 insertions(+), 96 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 680f097..c528ffa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,17 @@ 2003-06-23 Daiki Ueno + * riece-300.el: Rewrite using riece-decode-identity. + + * riece-identity.el (riece-completing-read-identity): Signal an + error when the encoded channel name is not matched with + riece-channel-regexp. + + * riece-globals.el (riece-channel-regexp): Moved from + riece-channel.el. + (riece-user-regexp): Moved form riece-user.el. + +2003-06-23 Daiki Ueno + * riece-handle.el (riece-handle-join-message): Don't call riece-switch-to-channel. (riece-handle-part-message): Don't decode message if it is empty. diff --git a/lisp/riece-300.el b/lisp/riece-300.el index d7e60ad..3f52d56 100644 --- a/lisp/riece-300.el +++ b/lisp/riece-300.el @@ -54,7 +54,9 @@ (concat (riece-concat-server-name (format "%s is (%s) [%s, %s]" - user + (riece-decode-identity + (riece-make-identity user riece-server-name) + t) (riece-strip-user-at-host user-at-host) (if operator "operator" @@ -71,25 +73,35 @@ (riece-insert-info (list riece-dialogue-buffer riece-others-buffer) (concat - (riece-concat-server-name (concat "Online: " (substring string 1))) + (riece-concat-server-name + (concat "Online: " + (mapconcat + (lambda (user) + (riece-decode-identity + (riece-make-identity user riece-server-name) + t)) + (split-string (substring string 1) " ") + ""))) "\n"))) (defun riece-handle-301-message (prefix number name string) - (when (string-match - (concat "^\\(" riece-user-regexp "\\) :") - string) - (let ((user (match-string 1 string)) - (message (riece-decode-coding-string - (substring string (match-end 0))))) - (riece-user-toggle-away user t) - (riece-insert-info - (list riece-dialogue-buffer riece-others-buffer) - (concat - (riece-concat-server-name - (format "%s is away: %s" user message)) - "\n"))) + (if (string-match (concat "^\\(" riece-user-regexp "\\) :") string) + (let ((user (match-string 1 string)) + (message (riece-decode-coding-string + (substring string (match-end 0))))) + (riece-user-toggle-away user t) + (riece-insert-info + (list riece-dialogue-buffer riece-others-buffer) + (concat + (riece-concat-server-name + (format "%s is away: %s" + (riece-decode-identity + (riece-make-identity user riece-server-name) + t) + message)) + "\n")))) (riece-update-status-indicators) - (force-mode-line-update t))) + (force-mode-line-update t)) (defun riece-handle-305-message (prefix number name string) (riece-user-toggle-away riece-real-nickname nil) @@ -106,16 +118,21 @@ (concat "^\\(" riece-user-regexp "\\) \\([^ ]+\\) \\([^ ]+\\) \\* :") string) - (riece-insert-info - (list riece-dialogue-buffer riece-others-buffer) - (concat - (riece-concat-server-name - (format "%s is %s (%s@%s)" - (match-string 1 string) - (riece-decode-coding-string (substring string (match-end 0))) - (match-string 2 string) - (match-string 3 string))) - "\n")))) + (let ((user (match-string 1 string)) + (name (substring string (match-end 0))) + (user-at-host (concat (match-string 2 string) "@" + (match-string 3 string)))) + (riece-insert-info + (list riece-dialogue-buffer riece-others-buffer) + (concat + (riece-concat-server-name + (format "%s is %s (%s)" + (riece-decode-identity + (riece-make-identity user riece-server-name) + t) + (riece-decode-coding-string name) + user-at-host)) + "\n"))))) (defun riece-handle-312-message (prefix number name string) (if (string-match @@ -132,25 +149,33 @@ (defun riece-handle-313-message (prefix number name string) (if (string-match (concat "^" riece-user-regexp) string) - (riece-insert-info - (list riece-dialogue-buffer riece-others-buffer) - (concat - (riece-concat-server-name - (concat (match-string 0 string) " is an IRC operator")) - "\n")))) + (let ((user (match-string 0 string))) + (riece-insert-info + (list riece-dialogue-buffer riece-others-buffer) + (concat + (riece-concat-server-name + (concat (riece-decode-identity + (riece-make-identity user riece-server-name) + t) + " is an IRC operator")) + "\n"))))) (defun riece-handle-317-message (prefix number name string) (if (string-match (concat "^\\(" riece-user-regexp "\\) \\([0-9]+\\) :") string) - (riece-insert-info - (list riece-dialogue-buffer riece-others-buffer) - (concat - (riece-concat-server-name - (format "%s is %s seconds idle" - (match-string 1 string) - (match-string 2 string))) - "\n")))) + (let ((user (match-string 1 string)) + (idle (match-string 2 string))) + (riece-insert-info + (list riece-dialogue-buffer riece-others-buffer) + (concat + (riece-concat-server-name + (format "%s is %s seconds idle" + (riece-decode-identity + (riece-make-identity user riece-server-name) + t) + idle)) + "\n"))))) (defun riece-handle-351-message (prefix number name string) (if (string-match "\\([^ ]+\\.[^ ]+\\) \\([^ ]+\\) :" string) @@ -195,8 +220,9 @@ (topic (riece-decode-coding-string (substring string (match-end 0))))) (riece-channel-set-topic (riece-get-channel channel) topic) - (let ((buffer (riece-channel-buffer-name - (riece-make-identity channel riece-server-name)))) + (let* ((channel-identity (riece-make-identity channel + riece-server-name)) + (buffer (riece-channel-buffer-name channel-identity))) (riece-insert-info buffer (concat visible " users, topic: " topic "\n")) (riece-insert-info @@ -207,7 +233,7 @@ (concat (riece-concat-server-name (format "%s users on %s, topic: %s" visible - (riece-decode-coding-string channel) topic)) + (riece-decode-identity channel-identity t) topic)) "\n")))))) (defun riece-handle-324-message (prefix number name string) @@ -220,8 +246,9 @@ (while modes (riece-channel-toggle-mode channel (car modes) (eq toggle ?+)) (setq modes (cdr modes))) - (let ((buffer (riece-channel-buffer-name - (riece-make-identity channel riece-server-name)))) + (let* ((channel-identity (riece-make-identity channel + riece-server-name)) + (buffer (riece-channel-buffer-name channel-identity))) (riece-insert-info buffer (concat "Mode: " mode-string "\n")) (riece-insert-info (if (and riece-channel-buffer-mode @@ -230,7 +257,8 @@ riece-dialogue-buffer) (concat (riece-concat-server-name - (format "Mode for %s: %s" (riece-decode-coding-string channel) + (format "Mode for %s: %s" + (riece-decode-identity channel-identity t) mode-string)) "\n"))) (riece-update-channel-indicator) @@ -241,8 +269,8 @@ (let* ((channel (match-string 1 string)) (message (riece-decode-coding-string (substring string (match-end 0)))) - (buffer (riece-channel-buffer-name - (riece-make-identity channel riece-server-name)))) + (channel-identity (riece-make-identity channel riece-server-name)) + (buffer (riece-channel-buffer-name channel-identity))) (if remove (riece-channel-set-topic (riece-get-channel channel) nil) (riece-channel-set-topic (riece-get-channel channel) message) @@ -254,7 +282,8 @@ riece-dialogue-buffer) (concat (riece-concat-server-name - (format "Topic for %s: %s" (riece-decode-coding-string channel) + (format "Topic for %s: %s" + (riece-decode-identity channel-identity t) message)) "\n")) (riece-update-channel-indicator))))) @@ -269,8 +298,8 @@ (if (string-match "^\\([^ ]+\\) " string) (let* ((channel (match-string 1 string)) (user (substring string (match-end 0))) - (buffer (riece-channel-buffer-name - (riece-make-identity channel riece-server-name)))) + (channel-identity (riece-make-identity channel riece-server-name)) + (buffer (riece-channel-buffer-name channel-identity))) (riece-insert-info buffer (concat "Inviting " user "\n")) (riece-insert-info (if (and riece-channel-buffer-mode @@ -280,7 +309,7 @@ (concat (riece-concat-server-name (format "Inviting %s to %s" user - (riece-decode-coding-string channel))) + (riece-decode-identity channel-identity t))) "\n"))))) (defun riece-handle-352-message (prefix number name string) @@ -297,29 +326,30 @@ (name (riece-decode-coding-string (substring string (match-end 0)))) (buffer (riece-channel-buffer-name - (riece-make-identity channel riece-server-name)))) + (riece-make-identity channel riece-server-name))) + (info (format "%10s = %s (%s) [%s, %s, %s hops, on %s]" + (concat + (if (memq flag '(?@ ?+)) + (char-to-string flag) + " ") + (riece-decode-identity + (riece-make-identity nick riece-server-name) + t)) + (riece-decode-coding-string name) + (riece-strip-user-at-host + (concat user "@" host)) + (if operator + "operator" + "not operator") + (if away + "away" + "not away") + hops + server))) (riece-naming-assert-join nick channel) (riece-user-toggle-away user away) (riece-user-toggle-operator user operator) - (riece-insert-info - buffer - (format "%10s = %s (%s) [%s, %s, %s hops, on %s]\n" - (concat - (if (memq flag '(?@ ?+)) - (char-to-string flag) - " ") - nick) - name - (riece-strip-user-at-host - (concat user "@" host)) - (if operator - "operator" - "not operator") - (if away - "away" - "not away") - hops - server)) + (riece-insert-info buffer (concat info "\n")) (riece-insert-info (if (and riece-channel-buffer-mode (not (eq buffer riece-channel-buffer))) @@ -327,24 +357,12 @@ riece-dialogue-buffer) (concat (riece-concat-server-name - (format "%s %10s = %s (%s) [%s, %s, %s hops, on %s]\n" - (riece-decode-coding-string channel) - (concat - (if (memq flag '(?@ ?+)) - (char-to-string flag) - " ") - nick) - name - (riece-strip-user-at-host - (concat user "@" host)) - (if operator - "operator" - "not operator") - (if away - "away" - "not away") - hops - server)) + (concat + (riece-decode-identity + (riece-make-identity channel riece-server-name) + t) + " " + info)) "\n")) (riece-redisplay-buffers)))) diff --git a/lisp/riece-channel.el b/lisp/riece-channel.el index a6f3d6e..cf61f37 100644 --- a/lisp/riece-channel.el +++ b/lisp/riece-channel.el @@ -25,15 +25,14 @@ ;;; Code: (require 'riece-options) +(require 'riece-globals) (require 'riece-identity) ;;; String representation of a channel: -(defconst riece-channel-regexp "^[+&#!]") - (defun riece-channel-p (string) "Return t if STRING is a channel. \(i.e. it matches `riece-channel-regexp')" - (string-match riece-channel-regexp string)) + (string-match (concat "^" riece-channel-regexp) string)) ;;; Channel object: (defun riece-find-channel (name) diff --git a/lisp/riece-globals.el b/lisp/riece-globals.el index 99f2bb6..a260377 100644 --- a/lisp/riece-globals.el +++ b/lisp/riece-globals.el @@ -24,6 +24,12 @@ ;;; Code: +;;; Constants: +(defconst riece-channel-regexp + "\\([+&#]\\|![A-Z0-9]\\{5\\}\\)[^\0\7\r\n ,:]*\\(:[^\0\7\r\n ,:]*\\)?") +(defconst riece-user-regexp + "[][\\\\`_^{|}A-Za-z][][\\\\`_^{|}A-Za-z0-9-]\\{0,8\\}") + ;;; Miscellaneous global variables: (defvar riece-process-list nil "List of processes opened in the current session.") diff --git a/lisp/riece-identity.el b/lisp/riece-identity.el index 081d3c3..b054edc 100644 --- a/lisp/riece-identity.el +++ b/lisp/riece-identity.el @@ -159,6 +159,10 @@ RFC2812, 2.2 \"Character codes\" says: predicate must-match initial)) (encoded (riece-encode-identity decoded))) + (unless (string-match (concat "^\\(" riece-channel-regexp "\\|" + riece-user-regexp "\\)") + (riece-identity-prefix encoded)) + (error "Invalid channel name!")) (if (and (not (string-match "[ ,]" decoded)) (string-match "[ ,]" (riece-identity-prefix encoded)) (not (y-or-n-p (format "The encoded channel name contains illegal character \"%s\". continue? " diff --git a/lisp/riece-user.el b/lisp/riece-user.el index 811867d..e42c825 100644 --- a/lisp/riece-user.el +++ b/lisp/riece-user.el @@ -25,9 +25,6 @@ (require 'riece-identity) -(defconst riece-user-regexp - "[][\\\\`_^{|}A-Za-z][][\\\\`_^{|}A-Za-z0-9-]\\{0,8\\}") - ;;; User object: (defun riece-find-user (name) "Get a user object named NAME from the server buffer." -- 1.7.10.4