2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001 by Alexander Barton (alex@barton.de)
5 * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 * der GNU General Public License (GPL), wie von der Free Software Foundation
7 * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
12 * $Id: conf.c,v 1.5 2001/12/30 19:26:11 alex Exp $
14 * conf.h: Konfiguration des ngircd
17 * Revision 1.5 2001/12/30 19:26:11 alex
18 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
20 * Revision 1.4 2001/12/26 22:48:53 alex
21 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
23 * Revision 1.3 2001/12/26 14:45:37 alex
26 * Revision 1.2 2001/12/26 03:19:57 alex
27 * - erste Konfigurations-Variablen definiert: PING/PONG-Timeout.
29 * Revision 1.1 2001/12/12 17:18:20 alex
30 * - Modul fuer Server-Konfiguration begonnen.
51 #define MAX_LINE_LEN 246 /* max. Laenge einer Konfigurationszeile */
54 LOCAL VOID Read_Config( VOID );
55 LOCAL VOID Validate_Config( VOID );
58 GLOBAL VOID Conf_Init( VOID )
60 /* Konfigurationsvariablen initialisieren: zunaechst Default-
61 * Werte setzen, dann Konfigurationsdtaei einlesen. */
63 strcpy( Conf_File, "/usr/local/etc/ngircd.conf" );
65 strcpy( Conf_ServerName, "" );
67 strcpy( Conf_MotdFile, "/usr/local/etc/ngircd.motd" );
69 Conf_ListenPorts_Count = 0;
71 Conf_PingTimeout = 120;
72 Conf_PongTimeout = 10;
74 /* Konfigurationsdatei einlesen und validieren */
80 GLOBAL VOID Conf_Exit( VOID )
86 LOCAL VOID Read_Config( VOID )
88 /* Konfigurationsdatei einlesen. */
90 CHAR str[MAX_LINE_LEN], *var, *arg, *ptr;
96 fd = fopen( Conf_File, "r" );
99 /* Keine Konfigurationsdatei gefunden */
100 Log( LOG_ALERT, "Can't read configuration \"%s\": %s", Conf_File, strerror( errno ));
101 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
108 if( ! fgets( str, MAX_LINE_LEN, fd )) break;
112 /* Kommentarzeilen und leere Zeilen ueberspringen */
113 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
117 ptr = strchr( str, '=' );
120 Log( LOG_ERR, "%s, line %d: Syntax error!", Conf_File, line );
125 var = str; ngt_TrimStr( var );
126 arg = ptr + 1; ngt_TrimStr( arg );
128 if( strcasecmp( str, "ServerName" ) == 0 )
130 /* Der Server-Name */
131 strncpy( Conf_ServerName, arg, CLIENT_ID_LEN );
132 Conf_ServerName[CLIENT_ID_LEN] = '\0';
135 else if( strcasecmp( str, "ListenPorts" ) == 0 )
137 /* Ports, durch "," getrennt, auf denen der Server
138 * Verbindungen annehmen soll */
139 ptr = strtok( arg, "," );
144 if( Conf_ListenPorts_Count + 1 > LISTEN_PORTS ) Log( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
145 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = port;
146 else Log( LOG_ERR, "Illegal port number: %ld. Ignored.", port );
147 ptr = strtok( NULL, "," );
151 else if( strcasecmp( str, "MotdFile" ) == 0 )
153 /* Datei mit der "message of the day" (MOTD) */
154 strncpy( Conf_MotdFile, arg, FNAME_LEN );
155 Conf_MotdFile[FNAME_LEN] = '\0';
158 else if( strcasecmp( str, "PingTimeout" ) == 0 )
161 Conf_PingTimeout = atoi( arg );
162 if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5;
165 else if( strcasecmp( str, "PongTimeout" ) == 0 )
168 Conf_PongTimeout = atoi( arg );
169 if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5;
173 if( ! ok ) Log( LOG_ERR, "%s, line %d: Unknown variable \"%s\"!", Conf_File, line, var );
180 LOCAL VOID Validate_Config( VOID )
182 /* Konfiguration ueberpruefen */
184 if( ! Conf_ServerName[0] )
186 /* Kein Servername konfiguriert */
187 Log( LOG_ALERT, "No server name configured (use \"ServerName\")!", Conf_File, strerror( errno ));
188 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
191 } /* Validate_Config */