+LOCAL BOOLEAN Use_Log = TRUE;
+LOCAL CONF_SERVER New_Server;
+LOCAL INT New_Server_Idx;
+
+
+LOCAL VOID Set_Defaults PARAMS(( BOOLEAN InitServers ));
+LOCAL VOID Read_Config PARAMS(( VOID ));
+LOCAL VOID Validate_Config PARAMS(( BOOLEAN TestOnly ));
+
+LOCAL VOID Handle_GLOBAL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
+LOCAL VOID Handle_OPERATOR PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
+LOCAL VOID Handle_SERVER PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
+LOCAL VOID Handle_CHANNEL PARAMS(( INT Line, CHAR *Var, CHAR *Arg ));
+
+LOCAL VOID Config_Error PARAMS(( CONST INT Level, CONST CHAR *Format, ... ));
+
+LOCAL VOID Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
+
+
+GLOBAL VOID
+Conf_Init( VOID )
+{
+ Set_Defaults( TRUE );
+ Read_Config( );
+ Validate_Config( FALSE );
+} /* Config_Init */
+
+
+GLOBAL VOID
+Conf_Rehash( VOID )
+{
+ Set_Defaults( FALSE );
+ Read_Config( );
+ Validate_Config( FALSE );
+} /* Config_Rehash */
+
+
+GLOBAL INT
+Conf_Test( VOID )
+{
+ /* Read configuration, validate and output it. */
+
+ struct passwd *pwd;
+ struct group *grp;
+ INT i;
+
+ Use_Log = FALSE;
+ Set_Defaults( TRUE );
+
+ Read_Config( );
+ Validate_Config( TRUE );
+
+ /* If stdin is a valid tty wait for a key: */
+ if( isatty( fileno( stdout )))
+ {
+ puts( "OK, press enter to see a dump of your service configuration ..." );
+ getchar( );
+ }
+ else puts( "Ok, dump of your server configuration follows:\n" );
+
+ puts( "[GLOBAL]" );
+ printf( " ServerName = %s\n", Conf_ServerName );
+ printf( " ServerInfo = %s\n", Conf_ServerInfo );
+ printf( " ServerPwd = %s\n", Conf_ServerPwd );
+ printf( " AdminInfo1 = %s\n", Conf_ServerAdmin1 );
+ printf( " AdminInfo2 = %s\n", Conf_ServerAdmin2 );
+ printf( " AdminEMail = %s\n", Conf_ServerAdminMail );
+ printf( " MotdFile = %s\n", Conf_MotdFile );
+ printf( " Ports = " );
+ for( i = 0; i < Conf_ListenPorts_Count; i++ )
+ {
+ if( i != 0 ) printf( ", " );
+ printf( "%u", Conf_ListenPorts[i] );
+ }
+ puts( "" );
+ pwd = getpwuid( Conf_UID );
+ if( pwd ) printf( " ServerUID = %s\n", pwd->pw_name );
+ else printf( " ServerUID = %ld\n", (LONG)Conf_UID );
+ grp = getgrgid( Conf_GID );
+ if( grp ) printf( " ServerGID = %s\n", grp->gr_name );
+ else printf( " ServerGID = %ld\n", (LONG)Conf_GID );
+ printf( " PingTimeout = %d\n", Conf_PingTimeout );
+ printf( " PongTimeout = %d\n", Conf_PongTimeout );
+ printf( " ConnectRetry = %d\n", Conf_ConnectRetry );
+ printf( " OperCanUseMode = %s\n", Conf_OperCanMode == TRUE ? "yes" : "no" );
+ if( Conf_MaxConnections > 0 ) printf( " MaxConnections = %ld\n", Conf_MaxConnections );
+ else printf( " MaxConnections = -1\n" );
+ if( Conf_MaxJoins > 0 ) printf( " MaxJoins = %d\n", Conf_MaxJoins );
+ else printf( " MaxJoins = -1\n" );
+ puts( "" );
+
+ for( i = 0; i < Conf_Oper_Count; i++ )
+ {
+ if( ! Conf_Oper[i].name[0] ) continue;
+
+ /* Valid "Operator" section */
+ puts( "[OPERATOR]" );
+ printf( " Name = %s\n", Conf_Oper[i].name );
+ printf( " Password = %s\n", Conf_Oper[i].pwd );
+ puts( "" );
+ }
+
+ for( i = 0; i < MAX_SERVERS; i++ )
+ {
+ if( ! Conf_Server[i].name[0] ) continue;
+
+ /* Valid "Server" section */
+ puts( "[SERVER]" );
+ printf( " Name = %s\n", Conf_Server[i].name );
+ printf( " Host = %s\n", Conf_Server[i].host );
+ printf( " Port = %d\n", Conf_Server[i].port );
+ printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
+ printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
+ printf( " Group = %d\n", Conf_Server[i].group );
+ puts( "" );
+ }
+
+ for( i = 0; i < Conf_Channel_Count; i++ )
+ {
+ if( ! Conf_Channel[i].name[0] ) continue;
+
+ /* Valid "Channel" section */
+ puts( "[CHANNEL]" );
+ printf( " Name = %s\n", Conf_Channel[i].name );
+ printf( " Modes = %s\n", Conf_Channel[i].modes );
+ printf( " Topic = %s\n", Conf_Channel[i].topic );
+ puts( "" );
+ }
+
+ return 0;
+} /* Conf_Test */
+
+
+GLOBAL VOID
+Conf_UnsetServer( CONN_ID Idx )
+{
+ /* Set next time for next connection attempt, if this is a server
+ * link that is (still) configured here. If the server is set as
+ * "once", delete it from our configuration.
+ * Non-Server-Connections will be silently ignored. */
+
+ INT i;
+
+ /* Check all our configured servers */
+ for( i = 0; i < MAX_SERVERS; i++ )
+ {
+ if( Conf_Server[i].conn_id != Idx ) continue;
+
+ /* Gotcha! Mark server configuration as "unused": */
+ Conf_Server[i].conn_id = NONE;
+
+ if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
+ {
+ /* Delete configuration here */
+ Init_Server_Struct( &Conf_Server[i] );
+ }
+ else
+ {
+ /* Set time for next connect attempt */
+ if( Conf_Server[i].lasttry < time( NULL ) - Conf_ConnectRetry )
+ {
+ /* Okay, the connection was established "long enough": */
+ Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
+ }
+ }
+ }
+} /* Conf_UnsetServer */
+
+
+GLOBAL VOID
+Conf_SetServer( INT ConfServer, CONN_ID Idx )
+{
+ /* Set connection for specified configured server */