/*
 * ----------------------------------------------------------------
 * Night Light IRC Proxy - Connection Parser Header
 * ----------------------------------------------------------------
 * Copyright (C) 1997-2006 Jonas Kvinge <jonas@night-light.net>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Last modified by:
 * Jonas Kvinge (11.09.2006)
 *
 */

#ifdef CONN_PARSER_H
#warning "conn_parser.h already included."
#else
#define CONN_PARSER_H

/* MACROS - JONAS (24.06.2000) */

#define CONN_PARSE_STRREALLOC(P, S) \
  strrealloc((P), (S)); \
  if (aerrno != AESUCCESS) { \
    assert(Conn_IsSocket(ConnS)); \
    if (Conn_IsWelcome(ConnS)) { conn_quit(ConnS, "String reallocation failure in function %s() (%s:%d): [%d] %s", __FUNCTION__, __FILE__, __LINE__, aerrno, straerror(aerrno)); } \
    else { conn_disconnect(ConnS, "Connection %s server %s: String reallocation failure in function %s() (%s:%d): [%d] %s", ConnS->Name, ConnS->ServerHostName, __FUNCTION__, __FILE__, __LINE__, aerrno, straerror(aerrno)); } \
    return(FALSE); \
  } \
  assert(strcmp((P), (S)) == FALSE)

#define CONN_PARSE_NUMERIC_ERROR(X) \
	conn_quit(ConnS, \
	"Internal failure calling function %s() from function %s() (%s:%d) connection: %s after receiving numeric %d from server %s(%s):%ld: [%d] %s" \
	, (X), __FUNCTION__, __FILE__, __LINE__, ConnS->Name, Numeric, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, aerrno, straerror(aerrno)); \
	return(FALSE)

#define CONN_PARSE_NUMERIC_CHECKPARAMS(X) \
	if (Params < X) { \
		if (Conn_IsWelcome(ConnS)) { conn_quit(ConnS, "Too few parameters for numeric %d received from server %s(%s):%ld (function %s (%s:%d))", Numeric, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, __FUNCTION__, __FILE__, __LINE__); } \
		else { conn_disconnect(ConnS, "Connection %s: Too few parameters for numeric %d received from server %s(%s):%ld (function %s (%s:%d))", ConnS->Name, Numeric, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, __FUNCTION__, __FILE__, __LINE__); } \
		return(FALSE); \
	}


#define CONN_PARSE_EVENT_ERROR(X) \
	conn_quit(ConnS, \
	"Internal failure calling function %s() from function %s() (%s:%d) connection: %s after receiving event %s from server %s(%s):%ld: [%d] %s", \
	(X), __FUNCTION__, __FILE__, __LINE__, ConnS->Name, CommandPT, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, aerrno, straerror(aerrno)); \
	return(FALSE)

#define CONN_PARSE_EVENT_CHECKPARAMS(X) \
	if (Params < X) { \
		if (Conn_IsWelcome(ConnS)) { conn_quit(ConnS, "Too few parameters for event %s received from server %s(%s):%ld (function %s (%s:%d))", CommandPT, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, __FUNCTION__, __FILE__, __LINE__); } \
		else { conn_disconnect(ConnS, "Connection %s: Too few parameters for event %s received from server %s(%s):%ld (function %s (%s:%d))", ConnS->Name, CommandPT, ConnS->ServerHostName, ConnS->ServerHostIPS, ConnS->ServerPortH, __FUNCTION__, __FILE__, __LINE__); } \
		return(FALSE); \
	}


/* TYPEDEFS - JONAS (24.06.2000) */

#define CONN_PARSE_NUMERIC(X)			unsigned short int X(struct Conn_Struct *ConnS, const char *const PrefixPT, const char *const LinePT, const unsigned short int Numeric, char **ParamsPT, const unsigned short int Params)
#define CONN_PARSE_EVENT(X)			unsigned short int X(struct Conn_Struct *ConnS, const char *const NickPT, const char *const UserPT, const char *const HostPT, const char *const NUHPT, const char *const CommandPT, char **ParamsPT, const unsigned short int Params)

/* FUNCTION PROTOTYPES - JONAS (18.07.2001) */

void conn_parser(struct Conn_Struct *ConnS);
void conn_parse_message(struct Conn_Struct *ConnS, char *MessagePT);
unsigned short int conn_parse_numeric(struct Conn_Struct *ConnS, const char *const PrefixPT, const char *const LinePT, const unsigned short int Numeric, char **ParamsPT, const unsigned short int Params);
CONN_PARSE_NUMERIC(conn_parse_numeric_welcome);
CONN_PARSE_NUMERIC(conn_parse_numeric_isupport);
CONN_PARSE_NUMERIC(conn_parse_numeric_nowaway);
CONN_PARSE_NUMERIC(conn_parse_numeric_unaway);
CONN_PARSE_NUMERIC(conn_parse_numeric_nextnick);
CONN_PARSE_NUMERIC(conn_parse_numeric_ison);
CONN_PARSE_NUMERIC(conn_parse_numeric_namereply);
CONN_PARSE_NUMERIC(conn_parse_numeric_endofnames);
CONN_PARSE_NUMERIC(conn_parse_numeric_whoreply);
CONN_PARSE_NUMERIC(conn_parse_numeric_endofwho);
unsigned short int conn_parse_event(struct Conn_Struct *ConnS, const char *PrefixPT, const char *const CommandPT, char **ParamsPT, const unsigned short int Params);
CONN_PARSE_EVENT(conn_parse_event_ping);
CONN_PARSE_EVENT(conn_parse_event_pong);
CONN_PARSE_EVENT(conn_parse_event_error);
CONN_PARSE_EVENT(conn_parse_event_nick);
CONN_PARSE_EVENT(conn_parse_event_join);
CONN_PARSE_EVENT(conn_parse_event_part);
CONN_PARSE_EVENT(conn_parse_event_quit);
CONN_PARSE_EVENT(conn_parse_event_kick);
CONN_PARSE_EVENT(conn_parse_event_mode);
CONN_PARSE_EVENT(conn_parse_event_privmsg_notice_topic);

#endif


syntax highlighted by Code2HTML, v. 0.9.1