The icb protocol limits each message to 255 chars, so automagically

split at a reasonable length, so the messages actually get delivered to
the server.

Patch taken from pkgsrc
OK sthen@, landry@
This commit is contained in:
phessler 2010-06-04 14:16:22 +00:00
parent 63507764a2
commit 5231142c8a
4 changed files with 141 additions and 2 deletions

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.19 2010/05/19 09:17:51 sthen Exp $
# $OpenBSD: Makefile,v 1.20 2010/06/04 14:16:22 phessler Exp $
SHARED_ONLY= Yes
COMMENT= ICB plugin for irssi
DISTNAME= irssi-icb-0.14
PKGNAME= ${DISTNAME}p4
PKGNAME= ${DISTNAME}p5
MASTER_SITES= http://www.phil.uu.nl/~lievisse/distfiles/
CATEGORIES= net

View File

@ -0,0 +1,99 @@
$OpenBSD: patch-src_core_icb-protocol_c,v 1.1 2010/06/04 14:16:22 phessler Exp $
Break lines longer than 255 chars
--- src/core/icb-protocol.c.orig Sat May 4 19:21:44 2002
+++ src/core/icb-protocol.c Fri Jun 4 10:12:25 2010
@@ -121,7 +121,91 @@ static void icb_login(ICB_SERVER_REC *server)
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,

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-src_core_icb-protocol_h,v 1.1 2010/06/04 14:16:22 phessler Exp $
Break lines longer than 255 chars
--- src/core/icb-protocol.h.orig Sat May 4 19:21:44 2002
+++ src/core/icb-protocol.h Fri Jun 4 10:12:25 2010
@@ -4,6 +4,8 @@
#define ICB_PROTOCOL_LEVEL 1
void icb_send_open_msg(ICB_SERVER_REC *server, const char *text);
+void icb_send_private_msg(ICB_SERVER_REC *server, const char *target,
+ const char *text);
void icb_command(ICB_SERVER_REC *server, const char *cmd,
const char *args, const char *id);
void icb_protocol(ICB_SERVER_REC *server, const char *level,

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-src_core_icb-servers_c,v 1.1 2010/06/04 14:16:22 phessler Exp $
Break lines longer than 255 chars
--- src/core/icb-servers.c.orig Tue May 28 18:56:34 2002
+++ src/core/icb-servers.c Fri Jun 4 10:12:25 2010
@@ -113,7 +113,6 @@ static void send_message(SERVER_REC *server, const cha
const char *msg, int target_type)
{
ICB_SERVER_REC *icbserver;
- char *str;
icbserver = ICB_SERVER(server);
g_return_if_fail(server != NULL);
@@ -125,9 +124,7 @@ static void send_message(SERVER_REC *server, const cha
icb_send_open_msg(icbserver, msg);
} else {
/* private message */
- str = g_strconcat(target, " ", msg, NULL);
- icb_command(icbserver, "m", str, NULL);
- g_free(str);
+ icb_send_private_msg(icbserver, target, msg);
}
}