3 --- src/core/icb-protocol.c (revision 5174)
4 +++ src/core/icb-protocol.c (working copy)
6 #include "icb-servers.h"
8 static char *signal_names[] = {
27 + "important", /* f */
37 #define SIGNAL_FIRST 'a'
40 void icb_send_open_msg(ICB_SERVER_REC *server, const char *text)
42 - icb_send_cmd(server, 'b', text, NULL);
46 + * ICB has 255 byte line length limit, and public messages are sent
47 + * out with our nickname, so split text accordingly.
49 + * 250 = 255 - 'b' - 1 space after nick - ^A - nul - extra
51 + * Taken from ircII's icb.c, thanks phone :-)
53 + remain = 250 - strlen(server->connrec->nick);
56 + char buf[256], *sendbuf;
57 + size_t len, copylen;
64 + /* try to split on a word boundary */
65 + for (i = 1; i < 128 && i < len; i++) {
66 + if (isspace(text[remain - i])) {
71 + strncpy(buf, text, copylen);
75 + sendbuf = (char *)text;
77 + icb_send_cmd(server, 'b', sendbuf, NULL);
78 + text += len > copylen ? copylen : len;
82 +void icb_send_private_msg(ICB_SERVER_REC *server, const char *target,
85 + size_t mylen, targlen, remain;
88 + * ICB has 255 byte line length limit. Private messages are sent
89 + * out with our nickname, but received with the target nickname,
90 + * so deduct the larger of the two in addition to other parts.
92 + * 248 = 255 - 'hm' - 1 space after nick - ^A's - nul - extra
94 + * Taken from ircII's icb.c, thanks phone :-)
96 + mylen = strlen(server->connrec->nick);
97 + targlen = strlen(target);
98 + if (mylen > targlen) {
99 + remain = 248 - mylen;
101 + remain = 248 - targlen;
104 + char buf[256], *sendbuf;
105 + size_t len, copylen;
107 + len = strlen(text);
109 + if (len > remain) {
112 + /* try to split on a word boundary */
113 + for (i = 1; i < 128 && i < len; i++) {
114 + if (isspace(text[remain - i])) {
119 + strncpy(buf, text, copylen);
121 + sendbuf = g_strconcat(target, " ", buf, NULL);
123 + sendbuf = g_strconcat(target, " ", text, NULL);
125 + icb_send_cmd(server, 'h', "m", sendbuf, NULL);
126 + text += len > copylen ? copylen : len;
130 void icb_command(ICB_SERVER_REC *server, const char *cmd,
131 const char *args, const char *id)
137 +static void event_status(ICB_SERVER_REC *server, const char *data)
139 + char **args, *event;
141 + args = g_strsplit(data, "\001", -1);
142 + if (args[0] != NULL) {
143 + event = g_strdup_printf("icb status %s", g_ascii_strdown(args[0], strlen(args[0])));
144 + if (!signal_emit(event, 2, server, args))
145 + signal_emit("default icb status", 2, server, args);
151 void icb_protocol_init(void)
153 signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
155 signal_add("icb event login", (SIGNAL_FUNC) event_login);
156 signal_add("icb event ping", (SIGNAL_FUNC) event_ping);
157 signal_add("icb event cmdout", (SIGNAL_FUNC) event_cmdout);
158 + signal_add("icb event status", (SIGNAL_FUNC) event_status);
161 void icb_protocol_deinit(void)
163 signal_remove("icb event login", (SIGNAL_FUNC) event_login);
164 signal_remove("icb event ping", (SIGNAL_FUNC) event_ping);
165 signal_remove("icb event cmdout", (SIGNAL_FUNC) event_cmdout);
166 + signal_remove("icb event status", (SIGNAL_FUNC) event_status);