#include "portab.h"
-static char UNUSED id[] = "$Id: conf.c,v 1.52 2002/12/30 00:01:45 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.56 2003/04/20 23:09:43 alex Exp $";
#include "imp.h"
#include <assert.h>
/* Gotcha! Mark server configuration as "unused": */
Conf_Server[i].conn_id = NONE;
- if( Conf_Server[i].once )
+ if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
{
/* Delete configuration here */
Init_Server_Struct( &Conf_Server[i] );
Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
}
}
- break;
}
} /* Conf_UnsetServer */
} /* Conf_GetServer */
+GLOBAL BOOLEAN
+Conf_EnableServer( CHAR *Name, INT Port )
+{
+ /* Enable specified server and adjust port */
+
+ INT i;
+
+ assert( Name != NULL );
+
+ for( i = 0; i < MAX_SERVERS; i++ )
+ {
+ if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
+ {
+ /* Gotcha! Set port and enable server: */
+ Conf_Server[i].port = Port;
+ Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
+ return TRUE;
+ }
+ }
+ return FALSE;
+} /* Conf_EnableServer */
+
+
+GLOBAL BOOLEAN
+Conf_DisableServer( CHAR *Name )
+{
+ /* Enable specified server and adjust port */
+
+ INT i;
+
+ assert( Name != NULL );
+
+ for( i = 0; i < MAX_SERVERS; i++ )
+ {
+ if( strcasecmp( Conf_Server[i].name, Name ) == 0 )
+ {
+ /* Gotcha! Disable and disconnect server: */
+ Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
+ if( Conf_Server[i].conn_id > NONE ) Conn_Close( Conf_Server[i].conn_id, NULL, "Server link terminated on operator request", TRUE );
+ return TRUE;
+ }
+ }
+ return FALSE;
+} /* Conf_DisableServer */
+
+
+GLOBAL BOOLEAN
+Conf_AddServer( CHAR *Name, INT Port, CHAR *Host, CHAR *MyPwd, CHAR *PeerPwd )
+{
+ /* Add new server to configuration */
+
+ INT i;
+
+ assert( Name != NULL );
+ assert( Host != NULL );
+ assert( MyPwd != NULL );
+ assert( PeerPwd != NULL );
+
+ /* Search unused item in server configuration structure */
+ for( i = 0; i < MAX_SERVERS; i++ )
+ {
+ /* Is this item used? */
+ if( ! Conf_Server[i].name[0] ) break;
+ }
+ if( i >= MAX_SERVERS ) return FALSE;
+
+ Init_Server_Struct( &Conf_Server[i] );
+ strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
+ strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
+ strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
+ strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
+ Conf_Server[i].port = Port;
+ Conf_Server[i].flags = CONF_SFLAG_ONCE;
+
+ return TRUE;
+} /* Conf_AddServer */
+
+
LOCAL VOID
Set_Defaults( BOOLEAN InitServers )
{
INT i;
strcpy( Conf_ServerName, "" );
- sprintf( Conf_ServerInfo, "%s %s", PACKAGE, VERSION );
+ sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
strcpy( Conf_ServerPwd, "" );
strcpy( Conf_ServerAdmin1, "" );
/* Read configuration file. */
CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
- INT line, i;
+ INT line, i, n;
FILE *fd;
/* Open configuration file */
{
/* No configuration file found! */
Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
- Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+ Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
exit( 1 );
}
/* Clean up server configuration structure: mark all already
* configured servers as "once" so that they are deleted
- * after the next disconnect and delete all unused servers. */
+ * after the next disconnect and delete all unused servers.
+ * And delete all servers which are "duplicates" of servers
+ * that are already marked as "once" (such servers have been
+ * created by the last rehash but are now useless). */
for( i = 0; i < MAX_SERVERS; i++ )
{
if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
- else Conf_Server[i].once = TRUE;
+ else
+ {
+ /* This structure is in use ... */
+ if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
+ {
+ /* Check for duplicates */
+ for( n = 0; n < MAX_SERVERS; n++ )
+ {
+ if( n == i ) continue;
+
+ if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
+ {
+ Init_Server_Struct( &Conf_Server[n] );
+ Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
+ }
+ }
+ }
+ else
+ {
+ /* Mark server as "once" */
+ Conf_Server[i].flags |= CONF_SFLAG_ONCE;
+ Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
+ }
+ }
}
/* Initialize variables */
Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
if( ! Configtest )
{
- Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+ Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
exit( 1 );
}
}
Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
if( ! Configtest )
{
- Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+ Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
exit( 1 );
}
}
if( Conf_Server[i].name[0] )
{
servers++;
- if( Conf_Server[i].once ) servers_once++;
+ if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) servers_once++;
}
}
Log( LOG_DEBUG, "Configuration: Operators=%d, Servers=%d[%d], Channels=%d", Conf_Oper_Count, servers, servers_once, Conf_Channel_Count );
Server->group = NONE;
Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
Server->res_stat = NULL;
- Server->once = FALSE;
+ if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
+ else Server->flags = 0;
Server->conn_id = NONE;
} /* Init_Server_Struct */