]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/parse.c
Rework check for number of parameters
[ngircd-alex.git] / src / ngircd / parse.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  */
11
12 #include "portab.h"
13
14 /**
15  * @file
16  * IRC command parser and validator.
17  */
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <strings.h>
25
26 #include "ngircd.h"
27 #include "defines.h"
28 #include "conn-func.h"
29 #include "channel.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "tool.h"
33
34 #include "exp.h"
35 #include "parse.h"
36
37 #include "imp.h"
38 #include "irc.h"
39 #include "irc-cap.h"
40 #include "irc-channel.h"
41 #include "irc-encoding.h"
42 #include "irc-info.h"
43 #include "irc-login.h"
44 #include "irc-metadata.h"
45 #include "irc-mode.h"
46 #include "irc-op.h"
47 #include "irc-oper.h"
48 #include "irc-server.h"
49 #include "irc-write.h"
50 #include "numeric.h"
51
52 #include "exp.h"
53 #include "conf.h"
54
55 struct _NUMERIC {
56         int numeric;
57         bool (*function) PARAMS(( CLIENT *Client, REQUEST *Request ));
58 };
59
60
61 static COMMAND My_Commands[] =
62 {
63         { "ADMIN", IRC_ADMIN, CLIENT_USER|CLIENT_SERVER, 0, 1, 0, 0, 0 },
64         { "AWAY", IRC_AWAY, CLIENT_USER, 0, 1, 0, 0, 0 },
65         { "CAP", IRC_CAP, CLIENT_ANY, 1, 2, 0, 0, 0 },
66         { "CONNECT", IRC_CONNECT, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
67 #ifdef STRICT_RFC
68         { "DIE", IRC_DIE, CLIENT_USER, 0, 0, 0, 0, 0 },
69 #else
70         { "DIE", IRC_DIE, CLIENT_USER, 0, 1, 0, 0, 0 },
71 #endif
72         { "DISCONNECT", IRC_DISCONNECT, CLIENT_USER, 1, 1, 0, 0, 0 },
73         { "ERROR", IRC_ERROR, CLIENT_ANY, 0, -1, 0, 0, 0 },
74         { "GLINE", IRC_xLINE, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
75         { "HELP", IRC_HELP, CLIENT_USER, 0, 1, 0, 0, 0 },
76         { "INFO", IRC_INFO, CLIENT_USER|CLIENT_SERVER, 0, 1, 0, 0, 0 },
77         { "INVITE", IRC_INVITE, CLIENT_USER|CLIENT_SERVER, 2, 2, 0, 0, 0 },
78         { "ISON", IRC_ISON, CLIENT_USER, 1, -1, 0, 0, 0 },
79         { "JOIN", IRC_JOIN, CLIENT_USER|CLIENT_SERVER, 1, 2, 0, 0, 0 },
80         { "KICK", IRC_KICK, CLIENT_USER|CLIENT_SERVER, 2, 3, 0, 0, 0 },
81         { "KILL", IRC_KILL, CLIENT_USER|CLIENT_SERVER, 2, 2, 0, 0, 0 },
82         { "KLINE", IRC_xLINE, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
83         { "LINKS", IRC_LINKS, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
84         { "LIST", IRC_LIST, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
85         { "LUSERS", IRC_LUSERS, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
86         { "METADATA", IRC_METADATA, CLIENT_SERVER, 3, 3, 0, 0, 0 },
87         { "MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 1, -1, 0, 0, 0 },
88         { "MOTD", IRC_MOTD, CLIENT_USER|CLIENT_SERVER, 0, 1, 0, 0, 0 },
89         { "NAMES", IRC_NAMES, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
90         { "NICK", IRC_NICK, CLIENT_ANY, 0, -1, 0, 0, 0 },
91         { "NJOIN", IRC_NJOIN, CLIENT_SERVER, 2, 2, 0, 0, 0 },
92         { "NOTICE", IRC_NOTICE, CLIENT_ANY, 0, -1, 0, 0, 0 },
93         { "OPER", IRC_OPER, CLIENT_USER, 2, 2, 0, 0, 0 },
94         { "PART", IRC_PART, CLIENT_USER|CLIENT_SERVER, 1, 2, 0, 0, 0 },
95         { "PASS", IRC_PASS, CLIENT_ANY, 0, -1, 0, 0, 0 },
96         { "PING", IRC_PING, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
97         { "PONG", IRC_PONG, CLIENT_ANY, 0, -1, 0, 0, 0 },
98         { "PRIVMSG", IRC_PRIVMSG, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
99         { "QUIT", IRC_QUIT, CLIENT_ANY, 0, 1, 0, 0, 0 },
100         { "REHASH", IRC_REHASH, CLIENT_USER, 0, 0, 0, 0, 0 },
101         { "RESTART", IRC_RESTART, CLIENT_USER, 0, 0, 0, 0, 0 },
102         { "SERVER", IRC_SERVER, CLIENT_ANY, 0, -1, 0, 0, 0 },
103         { "SERVICE", IRC_SERVICE, CLIENT_ANY, 6, 6, 0, 0, 0 },
104         { "SERVLIST", IRC_SERVLIST, CLIENT_USER, 0, 2, 0, 0, 0 },
105         { "SQUERY", IRC_SQUERY, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
106         { "SQUIT", IRC_SQUIT, CLIENT_USER|CLIENT_SERVER, 2, 2, 0, 0, 0 },
107         { "STATS", IRC_STATS, CLIENT_USER|CLIENT_SERVER, 0, 2, 0, 0, 0 },
108         { "SVSNICK", IRC_SVSNICK, CLIENT_SERVER, 2, 2, 0, 0, 0 },
109         { "SUMMON", IRC_SUMMON, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
110         { "TIME", IRC_TIME, CLIENT_USER|CLIENT_SERVER, 0, 1, 0, 0, 0 },
111         { "TOPIC", IRC_TOPIC, CLIENT_USER|CLIENT_SERVER, 1, 2, 0, 0, 0 },
112         { "TRACE", IRC_TRACE, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
113         { "USER", IRC_USER, CLIENT_ANY, 0, -1, 0, 0, 0 },
114         { "USERHOST", IRC_USERHOST, CLIENT_USER, 1, -1, 0, 0, 0 },
115         { "USERS", IRC_USERS, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
116         { "VERSION", IRC_VERSION, CLIENT_USER|CLIENT_SERVER, 0, 1, 0, 0, 0 },
117         { "WALLOPS", IRC_WALLOPS, CLIENT_USER|CLIENT_SERVER, 1, 1, 0, 0, 0 },
118         { "WEBIRC", IRC_WEBIRC, CLIENT_UNKNOWN, 4, 4, 0, 0, 0 },
119         { "WHO", IRC_WHO, CLIENT_USER, 0, 2, 0, 0, 0 },
120         { "WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
121         { "WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, -1, 0, 0, 0 },
122
123 #ifdef IRCPLUS
124         { "CHANINFO", IRC_CHANINFO, CLIENT_SERVER, 0, -1, 0, 0, 0 },
125 # ifdef ICONV
126         { "CHARCONV", IRC_CHARCONV, CLIENT_USER, 1, 1, 0, 0, 0 },
127 # endif
128 #endif
129
130 #ifndef STRICT_RFC
131         { "GET",  IRC_QUIT_HTTP, CLIENT_UNKNOWN, 0, -1, 0, 0, 0 },
132         { "POST", IRC_QUIT_HTTP, CLIENT_UNKNOWN, 0, -1, 0, 0, 0 },
133 #endif
134         { NULL, NULL, 0x0, 0, 0, 0, 0, 0 } /* End-Mark */
135 };
136
137 static void Init_Request PARAMS(( REQUEST *Req ));
138
139 static bool Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
140 static bool Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
141 static bool Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
142
143 static bool Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req ));
144
145 static bool ScrubCTCP PARAMS((char *Request));
146
147 /**
148  * Return the pointer to the global "IRC command structure".
149  * This structure, an array of type "COMMAND" describes all the IRC commands
150  * implemented by ngIRCd and how to handle them.
151  * @return Pointer to the global command structure.
152  */
153 GLOBAL COMMAND *
154 Parse_GetCommandStruct( void )
155 {
156         return My_Commands;
157 } /* Parse_GetCommandStruct */
158
159
160 /**
161  * Parse a command ("request") received from a client.
162  * 
163  * This function is called after the connection layer received a valid CR+LF
164  * terminated line of text: we assume that this is a valid IRC command and
165  * try to do something useful with it :-)
166  *
167  * All errors are reported to the client from which the command has been
168  * received, and if the error is fatal this connection is closed down.
169  *
170  * This function is able to parse the syntax as described in RFC 2812,
171  * section 2.3.
172  *
173  * @param Idx Index of the connection from which the command has been received.
174  * @param Request NULL terminated line of text (the "command").
175  * @return true on success (valid command or "regular" error), false if a
176  *      fatal error occurred and the connection has been shut down.
177  */
178 GLOBAL bool
179 Parse_Request( CONN_ID Idx, char *Request )
180 {
181         REQUEST req;
182         char *start, *ptr;
183         bool closed;
184
185         assert( Idx >= 0 );
186         assert( Request != NULL );
187
188 #ifdef SNIFFER
189         if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
190 #endif
191
192         Init_Request( &req );
193
194         /* remove leading & trailing whitespace */
195         ngt_TrimStr( Request );
196
197         if (Conf_ScrubCTCP && ScrubCTCP(Request))
198                 return true;
199
200         if (Request[0] == ':') {
201                 /* Prefix */
202                 req.prefix = Request + 1;
203                 ptr = strchr( Request, ' ' );
204                 if( ! ptr )
205                 {
206                         LogDebug("Connection %d: Parse error: prefix without command!?", Idx);
207                         return Conn_WriteStr(Idx, "ERROR :Prefix without command");
208                 }
209                 *ptr = '\0';
210 #ifndef STRICT_RFC
211                 /* ignore multiple spaces between prefix and command */
212                 while( *(ptr + 1) == ' ' ) ptr++;
213 #endif
214                 start = ptr + 1;
215         }
216         else start = Request;
217
218         ptr = strchr( start, ' ' );
219         if( ptr )
220         {
221                 *ptr = '\0';
222 #ifndef STRICT_RFC
223                 /* ignore multiple spaces between parameters */
224                 while( *(ptr + 1) == ' ' ) ptr++;
225 #endif
226         }
227         req.command = start;
228
229         /* Arguments, Parameters */
230         if( ptr )
231         {
232                 start = ptr + 1;
233                 while( start )
234                 {
235                         if( start[0] == ':' )
236                         {
237                                 req.argv[req.argc] = start + 1;
238                                 ptr = NULL;
239                         }
240                         else
241                         {
242                                 req.argv[req.argc] = start;
243                                 ptr = strchr( start, ' ' );
244                                 if( ptr )
245                                 {
246                                         *ptr = '\0';
247 #ifndef STRICT_RFC
248                                         while( *(ptr + 1) == ' ' ) ptr++;
249 #endif
250                                 }
251                         }
252
253                         req.argc++;
254
255                         if( start[0] == ':' ) break;
256                         if( req.argc > 14 ) break;
257
258                         if( ptr ) start = ptr + 1;
259                         else start = NULL;
260                 }
261         }
262
263         if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed;
264         if( ! Validate_Command( Idx, &req, &closed )) return ! closed;
265         if( ! Validate_Args( Idx, &req, &closed )) return ! closed;
266
267         return Handle_Request( Idx, &req );
268 } /* Parse_Request */
269
270
271 /**
272  * Initialize request structure.
273  * @param Req Request structure to be initialized.
274  */
275 static void
276 Init_Request( REQUEST *Req )
277 {
278         int i;
279
280         assert( Req != NULL );
281
282         Req->prefix = NULL;
283         Req->command = NULL;
284         for( i = 0; i < 15; Req->argv[i++] = NULL );
285         Req->argc = 0;
286 } /* Init_Request */
287
288
289 static bool
290 Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
291 {
292         CLIENT *client, *c;
293
294         assert( Idx >= 0 );
295         assert( Req != NULL );
296
297         *Closed = false;
298
299         client = Conn_GetClient( Idx );
300         assert( client != NULL );
301
302         if (!Req->prefix && Client_Type(client) == CLIENT_SERVER
303             && !(Conn_Options(Idx) & CONN_RFC1459)
304             && strcasecmp(Req->command, "ERROR") != 0
305             && strcasecmp(Req->command, "PING") != 0)
306         {
307                 Log(LOG_ERR,
308                     "Received command without prefix (connection %d, command \"%s\")!?",
309                     Idx, Req->command);
310                 if (!Conn_WriteStr(Idx, "ERROR :Prefix missing"))
311                         *Closed = true;
312                 return false;
313         }
314
315         if (!Req->prefix)
316                 return true;
317
318         /* only validate if this connection is already registered */
319         if (Client_Type(client) != CLIENT_USER
320             && Client_Type(client) != CLIENT_SERVER
321             && Client_Type(client) != CLIENT_SERVICE) {
322                 /* not registered, ignore prefix */
323                 Req->prefix = NULL;
324                 return true;
325         }
326
327         /* check if client in prefix is known */
328         c = Client_Search( Req->prefix );
329         if (!c) {
330                 Log(LOG_ERR,
331                     "Invalid prefix \"%s\", client not known (connection %d, command \"%s\")!?",
332                     Req->prefix, Idx, Req->command);
333                 if (!Conn_WriteStr(Idx,
334                                    "ERROR :Invalid prefix \"%s\", client not known",
335                                    Req->prefix))
336                         *Closed = true;
337                 return false;
338         }
339
340         /* check if the client named in the prefix is expected
341          * to come from that direction */
342         if (Client_NextHop(c) != client) {
343                 if (Client_Type(c) != CLIENT_SERVER) {
344                         Log(LOG_ERR,
345                             "Spoofed prefix \"%s\" from \"%s\" (connection %d, command \"%s\")!",
346                             Req->prefix, Client_Mask(Conn_GetClient(Idx)), Idx,
347                             Req->command);
348                         Conn_Close(Idx, NULL, "Spoofed prefix", true);
349                         *Closed = true;
350                 } else {
351                         Log(LOG_INFO,
352                             "Ignoring spoofed prefix \"%s\" from \"%s\" (connection %d, command \"%s\").",
353                             Req->prefix, Client_Mask(Conn_GetClient(Idx)), Idx,
354                             Req->command);
355                 }
356                 return false;
357
358         }
359
360         return true;
361 } /* Validate_Prefix */
362
363
364 static bool
365 Validate_Command( UNUSED CONN_ID Idx, UNUSED REQUEST *Req, bool *Closed )
366 {
367         assert( Idx >= 0 );
368         assert( Req != NULL );
369         *Closed = false;
370
371         return true;
372 } /* Validate_Command */
373
374
375 static bool
376 #ifdef STRICT_RFC
377 Validate_Args(CONN_ID Idx, REQUEST *Req, bool *Closed)
378 #else
379 Validate_Args(UNUSED CONN_ID Idx, UNUSED REQUEST *Req, bool *Closed)
380 #endif
381 {
382 #ifdef STRICT_RFC
383         int i;
384 #endif
385
386         *Closed = false;
387
388 #ifdef STRICT_RFC
389         assert( Idx >= 0 );
390         assert( Req != NULL );
391
392         /* CR and LF are never allowed in command parameters.
393          * But since we do accept lines terminated only with CR or LF in
394          * "non-RFC-compliant mode" (besides the correct CR+LF combination),
395          * this check can only trigger in "strict RFC" mode; therefore we
396          * optimize it away otherwise ... */
397         for (i = 0; i < Req->argc; i++) {
398                 if (strchr(Req->argv[i], '\r') || strchr(Req->argv[i], '\n')) {
399                         Log(LOG_ERR,
400                             "Invalid character(s) in parameter (connection %d, command %s)!?",
401                             Idx, Req->command);
402                         if (!Conn_WriteStr(Idx,
403                                            "ERROR :Invalid character(s) in parameter!"))
404                                 *Closed = true;
405                         return false;
406                 }
407         }
408 #endif
409
410         return true;
411 } /* Validate_Args */
412
413
414 /* Command is a status code ("numeric") from another server */
415 static bool
416 Handle_Numeric(CLIENT *client, REQUEST *Req)
417 {
418         static const struct _NUMERIC Numerics[] = {
419                 {   5, IRC_Num_ISUPPORT },
420                 {  20, NULL },
421                 { 376, IRC_Num_ENDOFMOTD }
422         };
423         int i, num;
424         char str[LINE_LEN];
425         CLIENT *prefix, *target = NULL;
426
427         /* Determine target */
428         if (Req->argc > 0) {
429                 if (strcmp(Req->argv[0], "*") != 0)
430                         target = Client_Search(Req->argv[0]);
431                 else
432                         target = Client_ThisServer();
433         }
434
435         if (!target) {
436                 /* Status code without target!? */
437                 if (Req->argc > 0)
438                         Log(LOG_WARNING,
439                             "Unknown target for status code %s: \"%s\"",
440                             Req->command, Req->argv[0]);
441                 else
442                         Log(LOG_WARNING,
443                             "Unknown target for status code %s!",
444                             Req->command);
445                 return true;
446         }
447         if (target == Client_ThisServer()) {
448                 /* This server is the target of the numeric */
449                 num = atoi(Req->command);
450
451                 for (i = 0; i < (int) C_ARRAY_SIZE(Numerics); i++) {
452                         if (num == Numerics[i].numeric) {
453                                 if (!Numerics[i].function)
454                                         return CONNECTED;
455                                 return Numerics[i].function(client, Req);
456                         }
457                 }
458
459                 LogDebug("Ignored status code %s from \"%s\".",
460                          Req->command, Client_ID(client));
461                 return true;
462         }
463
464         /* Determine source */
465         if (! Req->prefix[0]) {
466                 /* Oops, no prefix!? */
467                 Log(LOG_WARNING, "Got status code %s from \"%s\" without prefix!?",
468                                                 Req->command, Client_ID(client));
469                 return true;
470         }
471
472         prefix = Client_Search(Req->prefix);
473         if (! prefix) { /* Oops, unknown prefix!? */
474                 Log(LOG_WARNING, "Got status code %s from unknown source: \"%s\"", Req->command, Req->prefix);
475                 return true;
476         }
477
478         /* Forward status code */
479         strlcpy(str, Req->command, sizeof(str));
480         for (i = 0; i < Req->argc; i++) {
481                 if (i < Req->argc - 1)
482                         strlcat(str, " ", sizeof(str));
483                 else
484                         strlcat(str, " :", sizeof(str));
485                 strlcat(str, Req->argv[i], sizeof(str));
486         }
487         return IRC_WriteStrClientPrefix(target, prefix, "%s", str);
488 }
489
490 static bool
491 Handle_Request( CONN_ID Idx, REQUEST *Req )
492 {
493         CLIENT *client;
494         bool result = true;
495         int client_type;
496         COMMAND *cmd;
497
498         assert( Idx >= 0 );
499         assert( Req != NULL );
500         assert( Req->command != NULL );
501
502         client = Conn_GetClient( Idx );
503         assert( client != NULL );
504
505         /* Numeric? */
506         client_type = Client_Type(client);
507         if ((client_type == CLIENT_SERVER ||
508              client_type == CLIENT_UNKNOWNSERVER)
509             && strlen(Req->command) == 3 && atoi(Req->command) > 1)
510                 return Handle_Numeric(client, Req);
511
512         cmd = My_Commands;
513         while (cmd->name) {
514                 if (strcasecmp(Req->command, cmd->name) != 0) {
515                         cmd++;
516                         continue;
517                 }
518
519                 if (!(client_type & cmd->type)) {
520                         if (client_type == CLIENT_USER
521                             && cmd->type & CLIENT_SERVER)
522                                 return IRC_WriteErrClient(client,
523                                                  ERR_NOTREGISTEREDSERVER_MSG,
524                                                  Client_ID(client));
525                         else
526                                 return IRC_WriteErrClient(client,
527                                                 ERR_NOTREGISTERED_MSG,
528                                                 Client_ID(client));
529                 }
530
531                 if (Req->argc < cmd->min_argc ||
532                     (cmd->max_argc != -1 && Req->argc > cmd->max_argc)) {
533                         IRC_SetPenalty(client, 2);
534                         return IRC_WriteStrClient(client, ERR_NEEDMOREPARAMS_MSG,
535                                                   Client_ID(client), Req->command);
536                 }
537
538                 /* Command is allowed for this client: call it and count
539                  * generated bytes in output */
540                 Conn_ResetWCounter();
541                 result = (cmd->function)(client, Req);
542                 cmd->bytes += Conn_WCounter();
543
544                 /* Adjust counters */
545                 if (client_type != CLIENT_SERVER)
546                         cmd->lcount++;
547                 else
548                         cmd->rcount++;
549                 return result;
550         }
551
552         if (client_type != CLIENT_USER &&
553             client_type != CLIENT_SERVER &&
554             client_type != CLIENT_SERVICE )
555                 return true;
556
557         /* Unknown command and registered connection: generate error: */
558         LogDebug("Connection %d: Unknown command \"%s\", %d %s,%s prefix.",
559                         Client_Conn( client ), Req->command, Req->argc,
560                         Req->argc == 1 ? "parameter" : "parameters",
561                         Req->prefix ? "" : " no" );
562
563         if (Client_Type(client) != CLIENT_SERVER)
564                 result = IRC_WriteErrClient(client, ERR_UNKNOWNCOMMAND_MSG,
565                                 Client_ID(client), Req->command);
566
567         return result;
568 } /* Handle_Request */
569
570
571 /**
572  * Check if incoming messages contains CTCP commands and should be dropped.
573  *
574  * @param Request NULL terminated incoming command.
575  * @returns true, when the message should be dropped.
576  */
577 static bool
578 ScrubCTCP(char *Request)
579 {
580         static const char me_cmd[] = "ACTION ";
581         static const char ctcp_char = 0x1;
582         bool dropCommand = false;
583         char *ptr = Request;
584         char *ptrEnd = strchr(Request, '\0');
585
586         if (Request[0] == ':' && ptrEnd > ptr)
587                 ptr++;
588
589         while (ptr != ptrEnd && *ptr != ':')
590                 ptr++;
591
592         if ((ptrEnd - ptr) > 1) {
593                 ptr++;
594                 if (*ptr == ctcp_char) {
595                         dropCommand = true;
596                         ptr++;
597                         /* allow /me commands */
598                         if ((size_t)(ptrEnd - ptr) >= strlen(me_cmd)
599                             && !strncmp(ptr, me_cmd, strlen(me_cmd)))
600                                 dropCommand = false;
601                 }
602         }
603         return dropCommand;
604 }
605
606 /* -eof- */