updates
[silc.git] / apps / silcd / serverconfig.c
index ecc35e2fa799ca880a0c7ef696b60362246d1933..5a8f731d0b0414570a6701e05e2026a239dd21ba 100644 (file)
 #include "server_internal.h"
 
 SilcServerConfigSection silc_server_config_sections[] = {
-  { "[Cipher]", 
+  { "[Cipher]",
     SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
-  { "[PKCS]", 
+  { "[PKCS]",
     SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 1 },
-  { "[Hash]", 
+  { "[Hash]",
     SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
-  { "[hmac]", 
+  { "[hmac]",
     SILC_CONFIG_SERVER_SECTION_TYPE_HMAC, 3 },
-  { "[ServerKeys]", 
+  { "[ServerKeys]",
     SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_KEYS, 2 },
-  { "[ServerInfo]", 
+  { "[ServerInfo]",
     SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
-  { "[AdminInfo]", 
+  { "[AdminInfo]",
     SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
-  { "[ListenPort]", 
+  { "[ListenPort]",
     SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
-  { "[Identity]", 
+  { "[Identity]",
     SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY, 2 },
-  { "[Logging]", 
+  { "[Logging]",
     SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
   { "[ConnectionClass]", 
     SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
@@ -57,6 +57,8 @@ SilcServerConfigSection silc_server_config_sections[] = {
     SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 3 },
   { "[motd]", 
     SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
+  { "[pid]",
+    SILC_CONFIG_SERVER_SECTION_TYPE_PID, 1},
   
   { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
 };
@@ -94,11 +96,12 @@ SilcServerConfig silc_server_config_alloc(char *filename)
   if ((silc_server_config_parse_lines(new, config_parse)) == FALSE)
     goto fail;
 
-  silc_free(buffer);
+  silc_buffer_free(buffer);
 
   return new;
 
  fail:
+  silc_buffer_free(buffer);
   silc_free(new);
   return NULL;
 }
@@ -121,6 +124,7 @@ void silc_server_config_free(SilcServerConfig config)
     silc_free(config->routers);
     silc_free(config->denied);
     silc_free(config->motd);
+    silc_free(config->pidfile);
     silc_free(config);
   }
 }
@@ -143,7 +147,7 @@ int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
 
   begin = 0;
   linenum = 0;
-  while((begin = silc_gets(line, sizeof(line), 
+  while((begin = silc_gets(line, sizeof(line),
                           buffer->data, buffer->len, begin)) != EOF) {
     cp = line;
     linenum++;
@@ -649,14 +653,16 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       if (ret < 0)
        break;
       if (ret == 0) {
-       fprintf(stderr, "%s:%d: Log file section not defined\n", 
+       fprintf(stderr, "%s:%d: Log file section not defined\n",
                config->filename, pc->linenum);
        break;
       }
       if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
          && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
          && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
-         && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
+         && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)
+         && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LO_QUICK)
+         && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LO_FDELAY)) {
        fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
                config->filename, pc->linenum, config->logging->logtype);
        break;
@@ -951,22 +957,27 @@ int silc_server_config_parse_lines(SilcServerConfig config,
        silc_free(tmp);
       }
 
-      /* Check whether this connection is backup router connection */
-      ret = silc_config_get_token(line, &tmp);
-      if (ret != -1) {
-       config->routers->backup_router = atoi(tmp);
-       if (config->routers->backup_router != 0)
-         config->routers->backup_router = TRUE;
-       silc_free(tmp);
-      }
-
-      /* Check whether this backup is local (in cell) or remote (other cell) */
-      ret = silc_config_get_token(line, &tmp);
-      if (ret != -1) {
-       config->routers->backup_local = atoi(tmp);
-       if (config->routers->backup_local != 0)
-         config->routers->backup_local = TRUE;
-       silc_free(tmp);
+      /* Get backup replace IP */
+      ret = silc_config_get_token(line, &config->routers->backup_replace_ip);
+      if (ret != -1)
+       config->routers->backup_router = TRUE;
+
+      if (config->routers->backup_router) {
+       /* Get backup replace port */
+       ret = silc_config_get_token(line, &tmp);
+       if (ret != -1) {
+         config->routers->backup_replace_port = atoi(tmp);
+         silc_free(tmp);
+       }
+       
+       /* Check whether the backup connection is local */
+       ret = silc_config_get_token(line, &tmp);
+       if (ret != -1) {
+         config->routers->backup_local = atoi(tmp);
+         if (config->routers->backup_local != 0)
+           config->routers->backup_local = TRUE;
+         silc_free(tmp);
+       }
       }
 
       check = TRUE;
@@ -1102,6 +1113,19 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       checkmask |= (1L << pc->section->type);
       break;
 
+    case SILC_CONFIG_SERVER_SECTION_TYPE_PID:
+
+       if (!config->pidfile)
+          config->pidfile = silc_calloc(1, sizeof(*config->pidfile));
+          
+       ret = silc_config_get_token(line, &config->pidfile->pid_file);
+       if (ret < 0)
+          break;
+          
+       check = TRUE;
+       checkmask |= (1L << pc->section->type);
+       break;
+
     case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
     default:
       /* Error */
@@ -1119,7 +1143,7 @@ int silc_server_config_parse_lines(SilcServerConfig config,
   }
 
   if (check == FALSE)
-    return FALSE;;
+    return FALSE;
 
   /* Check that all mandatory sections really were found. If not, the server
      cannot function and we return error. */
@@ -1186,9 +1210,9 @@ int silc_server_config_check_sections(uint32 checkmask)
     
     return FALSE;
   }
-  if (!(checkmask 
+  if (!(checkmask
        & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
-    
+
     return FALSE;
   }
 
@@ -1197,48 +1221,42 @@ int silc_server_config_check_sections(uint32 checkmask)
 
 /* Sets log files where log messages is saved by the server. */
 
-void silc_server_config_setlogfiles(SilcServerConfig config)
+void silc_server_config_setlogfiles(SilcServerConfig config, SilcSchedule sked)
 {
+  long tmp;
   SilcServerConfigSectionLogging *log;
-  char *info, *warning, *error, *fatal;
-  uint32 info_size, warning_size, error_size, fatal_size;
 
   SILC_LOG_DEBUG(("Setting configured log file names"));
-
-  /* Set default files before checking configuration */
-  info = SILC_LOG_FILE_INFO;
-  warning = SILC_LOG_FILE_WARNING;
-  error = SILC_LOG_FILE_ERROR;
-  fatal = SILC_LOG_FILE_FATAL;
-  info_size = 0;
-  warning_size = 0;
-  error_size = 0;
-  fatal_size = 0;
-
   log = config->logging;
-  while(log) {
-    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
-      info = log->filename;
-      info_size = log->maxsize;
-    }
-    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
-      warning = log->filename;
-      warning_size = log->maxsize;
-    }
-    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
-      error = log->filename;
-      error_size = log->maxsize;
+  while (log) {
+    /* Logging Files */
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO))
+      silc_log_set_file(SILC_LOG_INFO, log->filename, log->maxsize, sked);
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING))
+      silc_log_set_file(SILC_LOG_WARNING, log->filename, log->maxsize, sked);
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR))
+      silc_log_set_file(SILC_LOG_ERROR, log->filename, log->maxsize, sked);
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL))
+      silc_log_set_file(SILC_LOG_FATAL, log->filename, log->maxsize, sked);
+    /* Logging Options */
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LO_QUICK)) {
+      if (!strcasecmp(log->filename, "yes") ||
+         !strcasecmp(log->filename, "on"))
+          silc_log_quick = TRUE;
     }
-    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
-      fatal = log->filename;
-      fatal_size = log->maxsize;
+    if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LO_FDELAY)) {
+      tmp = atol(log->filename);
+      if (tmp > 0)
+        silc_log_flushdelay = tmp;
+      else {
+        fprintf(stderr, "config: invalid flushdelay value, use quicklogs if "
+               "you want real-time logging.\n");
+       exit(1);
+      }
     }
 
     log = log->next;
   }
-
-  silc_log_set_files(info, info_size, warning, warning_size,
-                    error, error_size, fatal, fatal_size);
 }
 
 /* Registers configured ciphers. These can then be allocated by the