summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/papod.clj33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/papod.clj b/src/papod.clj
index 4055e8a..8b7d4d5 100644
--- a/src/papod.clj
+++ b/src/papod.clj
@@ -3862,11 +3862,38 @@
[(str "BATCH -" batch-id)]))
w)))))
+(defn- byte-length
+ [^String s]
+ (alength (.getBytes s "UTF-8")))
+
+(defn- input-too-long?
+ [^String raw]
+ (let [tagged? (.startsWith raw "@")
+ sp (when tagged? (.indexOf raw " "))
+ tags (when (and tagged? (pos? sp))
+ (subs raw 1 sp))
+ body (cond
+ (not tagged?) raw
+ (pos? sp) (subs raw (inc sp))
+ :else "")
+ tag-len (if tags (byte-length tags) 0)
+ body-len (byte-length body)]
+ (or (and tagged? (> tag-len 4094))
+ (> body-len 510))))
+
(defn- process-message!
[raw-message w client components]
- (let [[message err] (parse-message raw-message)]
- (when-not err
- (handle-message! message w client components))))
+ (cond
+ (input-too-long? raw-message)
+ (let [nick (or (:nick @client) "*")
+ line (str ":" +server-name+ " 417 " nick
+ " :Input line was too long")]
+ (deliver-to-client! w line))
+
+ :else
+ (let [[message err] (parse-message raw-message)]
+ (when-not err
+ (handle-message! message w client components)))))
(defn- process-input!
[input w client components]