| 204 if (gc->inpa > 0) |
204 if (gc->inpa > 0) |
| 205 gaim_input_remove(gc->inpa); |
205 gaim_input_remove(gc->inpa); |
| 206 gc->inpa = 0; |
206 gc->inpa = 0; |
| 207 close(((struct toc_data *)gc->proto_data)->toc_fd); |
207 close(((struct toc_data *)gc->proto_data)->toc_fd); |
| 208 g_free(gc->proto_data); |
208 g_free(gc->proto_data); |
| |
209 } |
| |
210 |
| |
211 static int escape_message(char *msg) |
| |
212 { |
| |
213 char *c, *cpy; |
| |
214 int cnt = 0; |
| |
215 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ |
| |
216 if (strlen(msg) > BUF_LEN) { |
| |
217 debug_printf("Warning: truncating message to 2048 bytes\n"); |
| |
218 msg[2047] = '\0'; |
| |
219 } |
| |
220 |
| |
221 cpy = g_strdup(msg); |
| |
222 c = cpy; |
| |
223 while (*c) { |
| |
224 switch (*c) { |
| |
225 case '$': |
| |
226 case '[': |
| |
227 case ']': |
| |
228 case '(': |
| |
229 case ')': |
| |
230 case '#': |
| |
231 msg[cnt++] = '\\'; |
| |
232 /* Fall through */ |
| |
233 default: |
| |
234 msg[cnt++] = *c; |
| |
235 } |
| |
236 c++; |
| |
237 } |
| |
238 msg[cnt] = '\0'; |
| |
239 g_free(cpy); |
| |
240 return cnt; |
| |
241 } |
| |
242 |
| |
243 static int escape_text(char *msg) |
| |
244 { |
| |
245 char *c, *cpy; |
| |
246 int cnt = 0; |
| |
247 /* Assumes you have a buffer able to cary at least BUF_LEN * 4 bytes */ |
| |
248 if (strlen(msg) > BUF_LEN) { |
| |
249 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); |
| |
250 msg[2047] = '\0'; |
| |
251 } |
| |
252 |
| |
253 cpy = g_strdup(msg); |
| |
254 c = cpy; |
| |
255 while (*c) { |
| |
256 switch (*c) { |
| |
257 case '\n': |
| |
258 msg[cnt++] = '<'; |
| |
259 msg[cnt++] = 'B'; |
| |
260 msg[cnt++] = 'R'; |
| |
261 msg[cnt++] = '>'; |
| |
262 break; |
| |
263 case '{': |
| |
264 case '}': |
| |
265 case '\\': |
| |
266 case '"': |
| |
267 msg[cnt++] = '\\'; |
| |
268 /* Fall through */ |
| |
269 default: |
| |
270 msg[cnt++] = *c; |
| |
271 } |
| |
272 c++; |
| |
273 } |
| |
274 msg[cnt] = '\0'; |
| |
275 g_free(cpy); |
| |
276 return cnt; |
| 209 } |
277 } |
| 210 |
278 |
| 211 static int sflap_send(struct gaim_connection *gc, char *buf, int olen, int type) |
279 static int sflap_send(struct gaim_connection *gc, char *buf, int olen, int type) |
| 212 { |
280 { |
| 213 int len; |
281 int len; |
| 1078 } |
1146 } |
| 1079 |
1147 |
| 1080 static void toc_chat_whisper(struct gaim_connection *g, int id, char *who, char *message) |
1148 static void toc_chat_whisper(struct gaim_connection *g, int id, char *who, char *message) |
| 1081 { |
1149 { |
| 1082 char buf2[BUF_LEN * 2]; |
1150 char buf2[BUF_LEN * 2]; |
| 1083 g_snprintf(buf2, sizeof(buf2), "toc_chat_whisper %d %s \"%s\"", id, who, message); |
1151 escape_text(message); |
| |
1152 g_snprintf(buf2, sizeof(buf2), "toc_chat_whisper %d %s \"%s\"", id, normalize(who), message); |
| 1084 sflap_send(g, buf2, -1, TYPE_DATA); |
1153 sflap_send(g, buf2, -1, TYPE_DATA); |
| 1085 } |
1154 } |
| 1086 |
1155 |
| 1087 static int toc_chat_send(struct gaim_connection *g, int id, char *message) |
1156 static int toc_chat_send(struct gaim_connection *g, int id, char *message) |
| 1088 { |
1157 { |