/*
*
* (C) 2003-2009 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for furhter details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
*
*/
#ifndef SERVICES_H
#define SERVICES_H
/*************************************************************************/
#include "sysconf.h"
#include "config.h"
#ifndef MAX_CMD_HASH
#define MAX_CMD_HASH 1024
#endif
/* Some SUN fixs */
#ifdef __sun
/* Solaris specific code, types that do not exist in Solaris'
* sys/types.h
**/
#undef u_int8_t
#undef u_int16_t
#undef u_int32_t
#undef u_int_64_t
#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
#define u_int64_t uint64_t
#ifndef INADDR_NONE
#define INADDR_NONE (-1)
#endif
#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Windows does not have: unistd.h, grp.h, netdb.h, netinet/in.h, sys/socket.h, sys/time.h
* Windows requires: winsock.h
* -- codemastr
*/
#ifndef _WIN32
#include <unistd.h>
#endif
#include <signal.h>
#include <time.h>
#include <errno.h>
#ifndef _WIN32
#include <grp.h>
#endif
#include <limits.h>
#ifndef _WIN32
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#else
#include <winsock.h>
#include <windows.h>
#endif
#include <sys/stat.h> /* for umask() on some systems */
#include <sys/types.h>
#ifdef HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
#ifdef _WIN32
#include <sys/timeb.h>
#include <direct.h>
#include <io.h>
#endif
#include <fcntl.h>
#ifndef _WIN32
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
#endif
#ifndef _WIN32
#include <dirent.h>
#endif
#ifdef _WIN32
/* VS2008 hates having this define before its own */
#define vsnprintf _vsnprintf
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif
#if HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#include "sockets.h"
#ifndef va_copy
# ifdef __va_copy
# define VA_COPY(DEST,SRC) __va_copy((DEST),(SRC))
# else
# define VA_COPY(DEST, SRC) memcpy ((&DEST), (&SRC), sizeof(va_list))
# endif
#else
# define VA_COPY(DEST, SRC) va_copy(DEST, SRC)
#endif
#ifdef _AIX
/* Some AIX boxes seem to have bogus includes that don't have these
* prototypes. */
extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, size_t);
# undef FD_ZERO
# define FD_ZERO(p) memset((p), 0, sizeof(*(p)))
#endif /* _AIX */
/* Alias stricmp/strnicmp to strcasecmp/strncasecmp if we have the latter
* but not the former. */
#if !HAVE_STRICMP && HAVE_STRCASECMP
# define stricmp strcasecmp
# define strnicmp strncasecmp
#endif
/* We have our own versions of toupper()/tolower(). */
#include <ctype.h>
#undef tolower
#undef toupper
#define tolower tolower_
#define toupper toupper_
/* We also have our own encrypt(). */
#define encrypt encrypt_
#ifdef __WINS__
#ifndef BKCHECK
#define BKCHECK
extern "C" void __pfnBkCheck() {}
#endif
#endif
#if INTTYPE_WORKAROUND
# undef int16
# undef int32
#endif
#ifndef _WIN32
#define MARK_DEPRECATED __attribute((deprecated))
#else
#define MARK_DEPRECATED
#endif
#ifdef _WIN32
# ifdef MODULE_COMPILE
# define CoreExport __declspec(dllimport)
# define DllExport __declspec(dllexport)
# else
# define CoreExport __declspec(dllexport)
# define DllExport __declspec(dllimport)
# endif
#else
# define DllExport
# define CoreExport
#endif
/** This definition is used as shorthand for the various classes
* and functions needed to make a module loadable by the OS.
* It defines the class factory and external init_module function.
*/
#ifdef _WIN32
#define MODULE_INIT(x, y) \
extern "C" DllExport Module *init_module(const std::string &, const std::string &); \
extern "C" Module *init_module(const std::string &, const std::string &creator) \
{ \
return new y(x, creator); \
} \
BOOLEAN WINAPI DllMain(HINSTANCE, DWORD nReason, LPVOID) \
{ \
switch ( nReason ) \
{ \
case DLL_PROCESS_ATTACH: \
case DLL_PROCESS_DETACH: \
break; \
} \
return TRUE; \
} \
extern "C" DllExport void destroy_module(y *); \
extern "C" void destroy_module(y *m) \
{ \
delete m; \
}
#else
#define MODULE_INIT(x, y) \
extern "C" DllExport Module *init_module(const std::string &, const std::string &creator) \
{ \
return new y(x, creator); \
} \
extern "C" DllExport void destroy_module(y *m) \
{ \
delete m; \
}
#endif
/* Miscellaneous definitions. */
#include "defs.h"
#include "slist.h"
#include "events.h"
/* pull in the various bits of STL to pull in */
#include <string>
#include <map>
#include <exception>
#include <list>
#include <vector>
/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
* When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
* a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
* be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
* attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
*/
class CoreExport CoreException : public std::exception
{
protected:
/** Holds the error message to be displayed
*/
std::string err;
/** Source of the exception
*/
std::string source;
public:
/** Default constructor, just uses the error mesage 'Core threw an exception'.
*/
CoreException() : err("Core threw an exception"), source("The core") {}
/** This constructor can be used to specify an error message before throwing.
*/
CoreException(const std::string &message) : err(message), source("The core") {}
/** This constructor can be used to specify an error message before throwing,
* and to specify the source of the exception.
*/
CoreException(const std::string &message, const std::string &src) : err(message), source(src) {}
/** This destructor solves world hunger, cancels the world debt, and causes the world to end.
* Actually no, it does nothing. Never mind.
* @throws Nothing!
*/
virtual ~CoreException() throw() {}
/** Returns the reason for the exception.
* The module should probably put something informative here as the user will see this upon failure.
*/
virtual const char* GetReason() const
{
return err.c_str();
}
virtual const char* GetSource() const
{
return source.c_str();
}
};
class CoreExport ModuleException : public CoreException
{
public:
/** Default constructor, just uses the error mesage 'Module threw an exception'.
*/
ModuleException() : CoreException("Module threw an exception", "A Module") {}
/** This constructor can be used to specify an error message before throwing.
*/
ModuleException(const std::string &message) : CoreException(message, "A Module") {}
/** This destructor solves world hunger, cancels the world debt, and causes the world to end.
* Actually no, it does nothing. Never mind.
* @throws Nothing!
*/
virtual ~ModuleException() throw() {}
};
/** Class with the ability to be extended with key:value pairs.
* Thanks to InspIRCd for this.
*/
class CoreExport Extensible
{
private:
std::map<std::string, void *> Extension_Items;
public:
/** Extend an Extensible class.
*
* @param key The key parameter is an arbitary string which identifies the extension data
* @param p This parameter is a pointer to any data you wish to associate with the object
*
* You must provide a key to store the
|