1
0
mirror of https://github.com/anope/anope.git synced 2026-06-24 09:56:37 +02:00

Added support for multiple uplink blocks in the new config.

Moved the type and id directives from the uplink block to the serverinfo block.
Small config fixes.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1746 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
cyberbotx
2008-11-16 19:31:31 +00:00
parent 72a4c7e6c7
commit ffbcff1604
11 changed files with 133 additions and 129 deletions
+19 -19
View File
@@ -80,19 +80,6 @@
*/
uplink
{
/*
* This directive instructs Anope which IRCd Protocol to speak when connecting.
* You MUST modify this to match the IRCd you run.
*
* Supported:
* - inspircd11
* - ratbox
* - bahamut
* - charybdis
* - unreal32
*/
type = "inspircd11"
/*
* The IP or hostname of the IRC server you wish to connect Services to.
* Usually, you will want to connect Services over 127.0.0.1 (aka localhost).
@@ -117,12 +104,6 @@ uplink
* Refer to your IRCd documentation for more information on link blocks.
*/
password = "mypassword"
/*
* What Server ID to use for this connection?
* Note: This should *ONLY* be used for TS6/P10 IRCds.
*/
#id = "64"
}
/*
@@ -146,6 +127,25 @@ serverinfo {
*/
description = "Services for IRC Networks"
/*
* This directive instructs Anope which IRCd Protocol to speak when connecting.
* You MUST modify this to match the IRCd you run.
*
* Supported:
* - inspircd11
* - ratbox
* - bahamut
* - charybdis
* - unreal32
*/
type = "inspircd11"
/*
* What Server ID to use for this connection?
* Note: This should *ONLY* be used for TS6/P10 IRCds.
*/
#id = "64"
/*
* These identify the ident@hostname which will be used by the Serivces pesudoclients.
* They can be overridden by the -user and -host command-line options when starting
+2 -10
View File
@@ -227,15 +227,7 @@ char *sockstrerror(int error);
/**** config.c ****/
E char *RemoteServer;
E int RemotePort;
E char *RemotePassword;
E char *RemoteServer2;
E int RemotePort2;
E char *RemotePassword2;
E char *RemoteServer3;
E int RemotePort3;
E char *RemotePassword3;
E std::list<Uplink *> Uplinks;
E char *LocalHost;
E int LocalPort;
@@ -514,7 +506,7 @@ E void set_lastmask(User * u);
E void introduce_user(const char *user);
E int init_primary(int ac, char **av);
E int init_secondary(int ac, char **av);
E int servernum;
E Uplink *uplink_server;
/**** ircd.c ****/
E void pmodule_ircd_proto(IRCDProto *);
+24 -4
View File
@@ -229,6 +229,7 @@ extern int strncasecmp(const char *, const char *, size_t);
#include <string>
#include <map>
#include <exception>
#include <list>
/** 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
@@ -351,7 +352,7 @@ class Extensible
* @return Returns true on success.
*/
bool Shrink(const std::string &key);
/** Get an extension item.
*
* @param key The key parameter is an arbitary string which identifies the extension data
@@ -372,12 +373,12 @@ class Extensible
return false;
}
}
/** Get an extension item.
*
* @param key The key parameter is an arbitary string which identifies the extension data
* @return Returns true if the item was found and false if it was not.
*
*
* This single-parameter version only checks if the key exists, it does nothing with
* the 'data' field and is probably only useful in conjunction with the single-parameter
* version of Extend().
@@ -1249,11 +1250,11 @@ struct capabinfo_ {
/*************************************************************************/
/*
* Forward declaration reqired, because the base IRCDProto class uses some crap from in here.
*/
class IRCDProto;
struct Uplink;
#include "extern.h"
class IRCDProto {
@@ -1517,4 +1518,23 @@ class IRCDTS6Proto : public IRCDProto
/*************************************************************************/
struct Uplink {
char *host;
int port;
char *password;
Uplink(const char *_host, int _port, const char *_password)
{
host = sstrdup(_host);
port = _port;
password = sstrdup(_password);
}
~Uplink()
{
free(host);
free(password);
}
};
/*************************************************************************/
#endif /* SERVICES_H */
+65 -35
View File
@@ -27,17 +27,8 @@ static const char *SERVICES_CONF_NEW = "services_new.conf";
char *IRCDModule;
char *EncModule;
char *RemoteServer;
int RemotePort;
char *RemotePassword;
char *RemoteServer2;
int RemotePort2;
char *RemotePassword2;
char *RemoteServer3;
int RemotePort3;
char *RemotePassword3;
std::list<Uplink *> Uplinks;
char *LocalHost;
int LocalPort;
@@ -566,15 +557,57 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail)
}
}
bool InitUplinks(ServerConfig *, const char *)
{
if (!Uplinks.empty()) {
std::list<Uplink *>::iterator curr_uplink = Uplinks.begin(), end_uplink = Uplinks.end();
for (; curr_uplink != end_uplink; ++curr_uplink) delete *curr_uplink;
}
Uplinks.clear();
return true;
}
bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values, int *)
{
// Validation variables
const char *host = values[0].GetString(), *password = values[2].GetString();
int port = values[1].GetInteger();
ValueItem vi_host(host), vi_port(port), vi_password(password);
// Validate the host to make sure it is not empty
if (!ValidateNotEmpty(conf, "uplink", "host", vi_host))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
// Validate the port to make sure it is a valid port
if (!ValidatePort(conf, "uplink", "port", vi_port))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
// Validate the password to make sure it is not empty
if (!ValidateNotEmpty(conf, "uplink", "password", vi_password))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
// If we get here, all the values are valid, we'll add it to the Uplinks list
Uplinks.push_back(new Uplink(host, port, password));
return true;
}
bool DoneUplinks(ServerConfig *, const char *)
{
return true;
}
bool InitModules(ServerConfig *, const char *)
{
Modules.clear();
return true;
}
bool DoModule(ServerConfig *, const char *, const char **, ValueList &values, int *)
bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values, int *)
{
// First we validate that there was a name in the module block
const char *module = values[0].GetString();
ValueItem vi(module);
if (!ValidateNotEmpty(conf, "module", "name", vi))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
// If the string isn't empty, add a space before we add the module name
if (!Modules.empty()) Modules += " ";
// Add the module name to the string
Modules += values[0].GetString();
return true;
}
@@ -619,34 +652,31 @@ int ServerConfig::Read(bool bail)
*
* If you want to create a directive using a character pointer specifically to hold a hostname (this will call ValidateHostname automatically):
* char *blarg;
* {"tag", "value", "", new ValueContainerChar(blarg), DT_HOSTNAME, <validation>},
* {"tag", "value", "", new ValueContainerChar(&blarg), DT_HOSTNAME, <validation>},
*
* If you want to create a directive using a character pointer that specifically can not have spaces in it (this will call ValidateNoSpaces automatically):
* char *blarg;
* {"tag", "value", "", new ValueContainerChar(blarg), DT_NOSPACES, <validation>},
* {"tag", "value", "", new ValueContainerChar(&blarg), DT_NOSPACES, <validation>},
*
* If you want to create a directive using a character pointer specifically to hold an IP address (this will call ValidateIP automatically):
* char *blarg;
* {"tag", "value", "", new ValueContainerChar(blarg), DT_IPADDRESS, <validation>},
* {"tag", "value", "", new ValueContainerChar(&blarg), DT_IPADDRESS, <validation>},
*
* If you want to create a directive using a time (a time_t variable converted from a string):
* time_t blarg;
* {"tag", "value", "", new ValueContainterTime(&blarg), DT_TIME, <validation>},
*
* For the second-to-last argument, you can or (|) in the following values:
* DT_NORELOAD - The variable can't be changed on a reload of the configuration (CURRENTLY NOT SET UP TO WORK YET)
* DT_NORELOAD - The variable can't be changed on a reload of the configuration
* DT_ALLOW_WILD - Allows wildcards/CIDR in DT_IPADDRESS
* DT_ALLOW_NEWLINE - Allows new line characters in DT_CHARPTR and DT_STRING
*
* We may need to add some other validation functions to handle certain things, we can handle that later.
* Any questions about these, w00t, feel free to ask. */
{"uplink", "type", "", new ValueContainerChar(&IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"uplink", "host", "", new ValueContainerChar(&RemoteServer), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
{"uplink", "port", "0", new ValueContainerInt(&RemotePort), DT_INTEGER | DT_NORELOAD, ValidatePort},
{"uplink", "password", "", new ValueContainerChar(&RemotePassword), DT_NOSPACES | DT_NORELOAD, ValidateNotEmpty},
{"uplink", "id", "", new ValueContainerChar(&Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
{"serverinfo", "name", "", new ValueContainerChar(&ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "description", "", new ValueContainerChar(&ServerDesc), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "type", "", new ValueContainerChar(&IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "id", "", new ValueContainerChar(&Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
{"serverinfo", "ident", "", new ValueContainerChar(&ServiceUser), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "hostname", "", new ValueContainerChar(&ServiceHost), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "pid", "services.pid", new ValueContainerChar(&PIDFilename), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
@@ -813,6 +843,11 @@ int ServerConfig::Read(bool bail)
/* These tags can occur multiple times, and therefore they have special code to read them
* which is different to the code for reading the singular tags listed above. */
MultiConfig MultiValues[] = {
{"uplink",
{"host", "port", "password", NULL},
{"", "0", "", NULL},
{DT_HOSTNAME | DT_NORELOAD, DT_INTEGER | DT_NORELOAD, DT_NOSPACES | DT_NORELOAD},
InitUplinks, DoUplink, DoneUplinks},
{"module",
{"name", NULL},
{"", NULL},
@@ -845,8 +880,8 @@ int ServerConfig::Read(bool bail)
dt &= ~DT_ALLOW_NEWLINE;
dt &= ~DT_ALLOW_WILD;
dt &= ~DT_NORELOAD;
// If the value is set to not allow reloading and we are reloading (bail will be true), skip the item
if (noreload && bail)
// If the value is set to not allow reloading and we are reloading (bail will be false), skip the item
if (noreload && !bail)
continue;
ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, BUFSIZE, allow_newlines);
ValueItem vi(item);
@@ -932,8 +967,8 @@ int ServerConfig::Read(bool bail)
dt &= ~DT_ALLOW_NEWLINE;
dt &= ~DT_ALLOW_WILD;
dt &= ~DT_NORELOAD;
// If the value is set to not allow reloading and we are reloading (bail will be true), skip the item
if (noreload && bail)
// If the value is set to not allow reloading and we are reloading (bail will be false), skip the item
if (noreload && !bail)
continue;
switch (dt) {
case DT_NOSPACES: {
@@ -986,7 +1021,8 @@ int ServerConfig::Read(bool bail)
}
break;
case DT_INTEGER:
case DT_UINTEGER: {
case DT_UINTEGER:
case DT_LUINTEGER: {
int item = 0;
if (ConfValueInteger(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum],
MultiValues[Index].items_default[valuenum], tagnum, item)) vl.push_back(ValueItem(item));
@@ -1403,13 +1439,6 @@ bool ValueItem::GetBool()
Directive directives[] = {
{"LocalAddress", {{PARAM_STRING, 0, &LocalHost},
{PARAM_PORT, PARAM_OPTIONAL, &LocalPort}}},
{"ModuleAutoload", {{PARAM_STRING, PARAM_RELOAD, &Modules}}},
{"RemoteServer2", {{PARAM_STRING, 0, &RemoteServer2},
{PARAM_PORT, 0, &RemotePort2},
{PARAM_STRING, 0, &RemotePassword2}}},
{"RemoteServer3", {{PARAM_STRING, 0, &RemoteServer3},
{PARAM_PORT, 0, &RemotePort3},
{PARAM_STRING, 0, &RemotePassword3}}},
};
/*************************************************************************/
@@ -1676,7 +1705,7 @@ int read_config(int reload)
}
}
retval = serverConfig.Read(reload);
retval = serverConfig.Read(reload ? false : true);
if (!retval) return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX
config = fopen(SERVICES_CONF, "r");
if (!config) {
@@ -1698,7 +1727,8 @@ int read_config(int reload)
}
fclose(config);
if (!reload) {
// This section will need better checking after we get LocalAddress moved to the new config
/*if (!reload) {
if (RemoteServer3)
CHECK(RemoteServer2);
@@ -1713,7 +1743,7 @@ int read_config(int reload)
retval = 0;
}
}
}
}*/
if (temp_nsuserhost) {
if (!(s = strchr(temp_nsuserhost, '@'))) {
+12 -30
View File
@@ -14,7 +14,7 @@
#include "services.h"
#include "pseudo.h"
int servernum = 0;
Uplink *uplink_server;
extern void moduleAddMsgs(void);
extern void moduleAddIRCDMsgs(void);
@@ -142,14 +142,14 @@ static int parse_options(int ac, char **av)
*t++ = 0;
portnum = atoi(t);
if ((portnum > 0) && (portnum < 65535))
RemotePort = portnum;
/*RemotePort = portnum*/; // Needs fixing to handle the Uplinks list
else {
fprintf(stderr,
"-remote: Port numbers must be in the range 1..65535. Using default.\n");
return -1;
}
}
RemoteServer = s;
/*RemoteServer = s*/; // Needs fixing to handle the Uplinks list
} else if (strcmp(s, "local") == 0) {
if (++i >= ac) {
fprintf(stderr,
@@ -608,35 +608,17 @@ int init_secondary(int ac, char **av)
send_event(EVENT_CONNECT, 1, EVENT_START);
/* Connect to the remote server */
servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort);
if (servsock < 0 && RemoteServer2) {
servsock = conn(RemoteServer2, RemotePort2, LocalHost, LocalPort);
if (servsock < 0 && RemoteServer3) {
servsock =
conn(RemoteServer3, RemotePort3, LocalHost, LocalPort);
if (servsock < 0) {
fatal_perror("Can't connect to server");
} else {
servernum = 3;
alog("Connected to Server %d (%s:%d)", servernum,
RemoteServer3, RemotePort3);
}
} else {
if (servsock < 0) {
fatal_perror("Can't connect to server");
}
servernum = 2;
alog("Connected to Server %d (%s:%d)", servernum,
RemoteServer2, RemotePort2);
std::list<Uplink *>::iterator curr_uplink = Uplinks.begin(), end_uplink = Uplinks.end();
int servernum = 1;
for (; curr_uplink != end_uplink; ++curr_uplink, ++servernum) {
uplink_server = *curr_uplink;
servsock = conn(uplink_server->host, uplink_server->port, LocalHost, LocalPort);
if (servsock >= 0) {
alog("Connected to Server %d (%s:%d)", servernum, uplink_server->host, uplink_server->port);
break;
}
} else {
if (servsock < 0) {
fatal_perror("Can't connect to server");
}
servernum = 1;
alog("Connected to Server %d (%s:%d)", servernum, RemoteServer,
RemotePort);
}
if (curr_uplink == end_uplink) fatal_perror("Can't connect to any servers");
ircdproto->SendConnect();
send_event(EVENT_CONNECT, 1, EVENT_STOP);
+3 -13
View File
@@ -221,19 +221,9 @@ int m_stats(const char *source, int ac, const char **av)
if (u && is_oper(u)) {
if (servernum == 1) {
ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer, write_buffer_len(), total_written, -1, read_buffer_len(),
total_read, -1, time(NULL) - start_time);
} else if (servernum == 2) {
ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer2, write_buffer_len(), total_written, -1, read_buffer_len(),
total_read, -1, time(NULL) - start_time);
} else if (servernum == 3) {
ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer3, write_buffer_len(), total_written, -1, read_buffer_len(),
total_read, -1, time(NULL) - start_time);
}
ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host, write_buffer_len(), total_written, -1, read_buffer_len(),
total_read, -1, time(NULL) - start_time);
}
ircdproto->SendNumeric(ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*');
+1 -3
View File
@@ -721,9 +721,7 @@ class BahamutIRCdProto : public IRCDProto
void SendConnect()
{
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
if (servernum == 1) bahamut_cmd_pass(RemotePassword);
else if (servernum == 2) bahamut_cmd_pass(RemotePassword2);
else if (servernum == 3) bahamut_cmd_pass(RemotePassword3);
bahamut_cmd_pass(uplink_server->password);
bahamut_cmd_capab();
SendServer(ServerName, 1, ServerDesc);
bahamut_cmd_svinfo();
+1 -3
View File
@@ -606,9 +606,7 @@ class InspIRCdProto : public IRCDProto
void SendConnect()
{
if (servernum == 1) inspircd_cmd_pass(RemotePassword);
else if (servernum == 2) inspircd_cmd_pass(RemotePassword2);
else if (servernum == 3) inspircd_cmd_pass(RemotePassword3);
inspircd_cmd_pass(uplink_server->password);
SendServer(ServerName, 0, ServerDesc);
send_cmd(NULL, "BURST");
send_cmd(ServerName, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build);
+4 -6
View File
@@ -609,9 +609,7 @@ class InspIRCdProto : public IRCDProto
void SendConnect()
{
if (servernum == 1) inspircd_cmd_pass(RemotePassword);
else if (servernum == 2) inspircd_cmd_pass(RemotePassword2);
else if (servernum == 3) inspircd_cmd_pass(RemotePassword3);
inspircd_cmd_pass(uplink_server->password);
SendServer(ServerName, 0, ServerDesc);
send_cmd(NULL, "BURST");
send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build);
@@ -728,16 +726,16 @@ int anope_event_mode(const char *source, int ac, const char **av)
*/
User *u = find_byuid(source);
User *u2 = find_byuid(av[0]);
// This can happen with server-origin modes.
if (u == NULL)
u = u2;
// drop it like fire.
// most likely situation was
if (u == NULL || u2 == NULL)
return MOD_CONT;
av[0] = u2->nick;
do_umode(u->nick, ac, av);
}
+1 -3
View File
@@ -595,9 +595,7 @@ class RatboxProto : public IRCDTS6Proto
{
/* Make myself known to myself in the serverlist */
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID);
if (servernum == 1) ratbox_cmd_pass(RemotePassword);
else if (servernum == 2) ratbox_cmd_pass(RemotePassword2);
else if (servernum == 3) ratbox_cmd_pass(RemotePassword3);
ratbox_cmd_pass(uplink_server->password);
ratbox_cmd_capab();
SendServer(ServerName, 1, ServerDesc);
ratbox_cmd_svinfo();
+1 -3
View File
@@ -739,9 +739,7 @@ class UnrealIRCdProto : public IRCDProto
if (Numeric) me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, Numeric);
else me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
unreal_cmd_capab();
if (servernum == 1) unreal_cmd_pass(RemotePassword);
else if (servernum == 2) unreal_cmd_pass(RemotePassword2);
else if (servernum == 3) unreal_cmd_pass(RemotePassword3);
unreal_cmd_pass(uplink_server->password);
SendServer(ServerName, 1, ServerDesc);
}