summaryrefslogtreecommitdiff
path: root/chat/irssi-icb/patches/patch-af
blob: 4f0b13f2c8354e2ed6ea9a7d320effbb01bc621b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- src/core/icb-protocol.c.orig	2010-05-18 21:09:43.000000000 +0100
+++ src/core/icb-protocol.c	2010-05-18 22:32:50.000000000 +0100
@@ -121,7 +121,91 @@
 
 void icb_send_open_msg(ICB_SERVER_REC *server, const char *text)
 {
-        icb_send_cmd(server, 'b', text, NULL);
+	size_t remain;
+
+	/*
+	 * ICB has 255 byte line length limit, and public messages are sent
+	 * out with our nickname, so split text accordingly.
+	 *
+	 * 250 = 255 - 'b' - 1 space after nick - ^A - nul - extra
+	 *
+	 * Taken from ircII's icb.c, thanks phone :-)
+	 */
+	remain = 250 - strlen(server->connrec->nick);
+
+	while(*text) {
+		char buf[256], *sendbuf;
+		size_t len, copylen;
+
+		len = strlen(text);
+		copylen = remain;
+		if (len > remain) {
+			int i;
+
+			/* try to split on a word boundary */
+			for (i = 1; i < 128 && i < len; i++) {
+				if (isspace(text[remain - i])) {
+					copylen -= i - 1;
+					break;
+				}
+			}
+			strncpy(buf, text, copylen);
+			buf[copylen] = 0;
+			sendbuf = buf;
+		} else {
+			sendbuf = (char *)text;
+		}
+		icb_send_cmd(server, 'b', sendbuf, NULL);
+		text += len > copylen ? copylen : len;
+	}
+}
+
+void icb_send_private_msg(ICB_SERVER_REC *server, const char *target,
+		const char *text)
+{
+	size_t mylen, targlen, remain;
+
+	/*
+	 * ICB has 255 byte line length limit.  Private messages are sent
+	 * out with our nickname, but received with the target nickname,
+	 * so deduct the larger of the two in addition to other parts.
+	 *
+	 * 248 = 255 - 'hm' - 1 space after nick - ^A's - nul - extra
+	 *
+	 * Taken from ircII's icb.c, thanks phone :-)
+	 */
+	mylen = strlen(server->connrec->nick);
+	targlen = strlen(target);
+	if (mylen > targlen) {
+		remain = 248 - mylen;
+	} else {
+		remain = 248 - targlen;
+	}
+	while(*text) {
+		char buf[256], *sendbuf;
+		size_t len, copylen;
+
+		len = strlen(text);
+		copylen = remain;
+		if (len > remain) {
+			int i;
+
+			/* try to split on a word boundary */
+			for (i = 1; i < 128 && i < len; i++) {
+				if (isspace(text[remain - i])) {
+					copylen -= i - 1;
+					break;
+				}
+			}
+			strncpy(buf, text, copylen);
+			buf[copylen] = 0;
+			sendbuf = g_strconcat(target, " ", buf, NULL);
+		} else {
+			sendbuf = g_strconcat(target, " ", text, NULL);
+		}
+		icb_send_cmd(server, 'h', "m", sendbuf, NULL);
+		text += len > copylen ? copylen : len;
+	}
 }
 
 void icb_command(ICB_SERVER_REC *server, const char *cmd,