Fixup fromcvs/togit conversion
[pkgsrcv2.git] / chat / irssi-icb / patches / patch-af
1 $NetBSD$
2
3 --- src/core/icb-protocol.c     (revision 5174)
4 +++ src/core/icb-protocol.c     (working copy)
5 @@ -27,19 +27,19 @@
6  #include "icb-servers.h"
7  
8  static char *signal_names[] = {
9 -       "login",
10 -       "open",
11 -       "personal",
12 -       "status",
13 -       "error",
14 -       "important",
15 -       "exit",
16 -       "command",
17 -       "cmdout",
18 -       "protocol",
19 -       "beep",
20 -       "ping",
21 -        "pong"
22 +       "login",        /* a */
23 +       "open",         /* b */
24 +       "personal",     /* c */
25 +       "status",       /* d */
26 +       "error",        /* e */
27 +       "important",    /* f */
28 +       "exit",         /* g */
29 +       "command",      /* h */
30 +       "cmdout",       /* i */
31 +       "protocol",     /* j */
32 +       "beep",         /* k */
33 +       "ping",         /* l */
34 +       "pong"          /* m */
35  };
36  
37  #define SIGNAL_FIRST 'a'
38 @@ -121,9 +121,93 @@
39  
40  void icb_send_open_msg(ICB_SERVER_REC *server, const char *text)
41  {
42 -        icb_send_cmd(server, 'b', text, NULL);
43 +       size_t remain;
44 +
45 +       /*
46 +        * ICB has 255 byte line length limit, and public messages are sent
47 +        * out with our nickname, so split text accordingly.
48 +        *
49 +        * 250 = 255 - 'b' - 1 space after nick - ^A - nul - extra
50 +        *
51 +        * Taken from ircII's icb.c, thanks phone :-)
52 +        */
53 +       remain = 250 - strlen(server->connrec->nick);
54 +
55 +       while(*text) {
56 +               char buf[256], *sendbuf;
57 +               size_t len, copylen;
58 +
59 +               len = strlen(text);
60 +               copylen = remain;
61 +               if (len > remain) {
62 +                       int i;
63 +
64 +                       /* try to split on a word boundary */
65 +                       for (i = 1; i < 128 && i < len; i++) {
66 +                               if (isspace(text[remain - i])) {
67 +                                       copylen -= i - 1;
68 +                                       break;
69 +                               }
70 +                       }
71 +                       strncpy(buf, text, copylen);
72 +                       buf[copylen] = 0;
73 +                       sendbuf = buf;
74 +               } else {
75 +                       sendbuf = (char *)text;
76 +               }
77 +               icb_send_cmd(server, 'b', sendbuf, NULL);
78 +               text += len > copylen ? copylen : len;
79 +       }
80  }
81  
82 +void icb_send_private_msg(ICB_SERVER_REC *server, const char *target,
83 +               const char *text)
84 +{
85 +       size_t mylen, targlen, remain;
86 +
87 +       /*
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.
91 +        *
92 +        * 248 = 255 - 'hm' - 1 space after nick - ^A's - nul - extra
93 +        *
94 +        * Taken from ircII's icb.c, thanks phone :-)
95 +        */
96 +       mylen = strlen(server->connrec->nick);
97 +       targlen = strlen(target);
98 +       if (mylen > targlen) {
99 +               remain = 248 - mylen;
100 +       } else {
101 +               remain = 248 - targlen;
102 +       }
103 +       while(*text) {
104 +               char buf[256], *sendbuf;
105 +               size_t len, copylen;
106 +
107 +               len = strlen(text);
108 +               copylen = remain;
109 +               if (len > remain) {
110 +                       int i;
111 +
112 +                       /* try to split on a word boundary */
113 +                       for (i = 1; i < 128 && i < len; i++) {
114 +                               if (isspace(text[remain - i])) {
115 +                                       copylen -= i - 1;
116 +                                       break;
117 +                               }
118 +                       }
119 +                       strncpy(buf, text, copylen);
120 +                       buf[copylen] = 0;
121 +                       sendbuf = g_strconcat(target, " ", buf, NULL);
122 +               } else {
123 +                       sendbuf = g_strconcat(target, " ", text, NULL);
124 +               }
125 +               icb_send_cmd(server, 'h', "m", sendbuf, NULL);
126 +               text += len > copylen ? copylen : len;
127 +       }
128 +}
129 +
130  void icb_command(ICB_SERVER_REC *server, const char *cmd,
131                  const char *args, const char *id)
132  {
133 @@ -293,6 +377,20 @@
134          g_strfreev(args);
135  }
136  
137 +static void event_status(ICB_SERVER_REC *server, const char *data)
138 +{
139 +       char **args, *event;
140 +
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);
146 +                g_free(event);
147 +       }
148 +        g_strfreev(args);
149 +}
150 +
151  void icb_protocol_init(void)
152  {
153          signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
154 @@ -300,6 +398,7 @@
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);
159  }
160  
161  void icb_protocol_deinit(void)
162 @@ -309,4 +408,5 @@
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);
167  }