parse.c 16 KB

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