imported irssi.
[silc.git] / apps / silcd / silcd.c
1 /*
2
3   silcd.c
4   
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20 /* 
21  * Created: Wed Mar 19 00:17:12 1997
22  *
23  * This is the main program for the SILC daemon. This parses command
24  * line arguments and creates the server object.
25  */
26 /*
27  * $Id$
28  * $Log$
29  * Revision 1.1.1.1  2000/06/27 11:36:56  priikone
30  *      Importet from internal CVS/Added Log headers.
31  *
32  *
33  */
34
35 #include "serverincludes.h"
36 #include "server_internal.h"
37 #include "version.h"
38
39 /* Long command line options */
40 static struct option long_opts[] = 
41 {
42   { "config-file", 1, NULL, 'f' },
43   { "generate-config-file", 0, NULL, 'c' },
44   { "help", 0, NULL, 'h' },
45   { "version", 0, NULL,'V' },
46   { NULL, 0, NULL, 0 }
47 };
48
49 /* Prints out the usage of silc client */
50
51 void silc_usage()
52 {
53   printf("Usage: silcd [options]\n");
54   printf("Options:\n");
55   printf("  -f  --config-file=FILE        Alternate configuration file\n");
56   printf("  -c  --generate-config-file    Generate example configuration "
57          "file\n");
58   printf("  -h  --help                    Display this message\n");
59   printf("  -V  --version                 Display version\n");
60   exit(0);
61 }
62
63 int main(int argc, char **argv)
64 {
65   int ret;
66   int opt, option_index;
67   char *config_file = NULL;
68   SilcServer silcd;
69
70   /* Parse command line arguments */
71   if (argc > 1) {
72     while ((opt = getopt_long(argc, argv, "cf:hV",
73                               long_opts, &option_index)) != EOF) {
74       switch(opt) 
75         {
76         case 'h':
77           silc_usage();
78           break;
79         case 'V':
80           printf("SILCd Secure Internet Live Conferencing daemon, "
81                  "version %s\n", silc_version);
82           printf("(c) 1997 - 2000 Pekka Riikonen "
83                  "<priikone@poseidon.pspt.fi>\n");
84           exit(0);
85           break;
86         case 'c':
87           /* Print out example configuration file */
88           silc_config_server_print();
89           exit(0);
90           break;
91         case 'f':
92           config_file = strdup(optarg);
93           break;
94         default:
95           silc_usage();
96           break;
97         }
98     }
99   }
100
101   /* Default configuration file */
102   if (!config_file)
103     config_file = strdup(SILC_SERVER_CONFIG_FILE);
104
105   /* Create SILC Server object */
106   ret = silc_server_alloc(&silcd);
107   if (ret == FALSE)
108     goto fail;
109
110   /* Read configuration files */
111   silcd->config = silc_config_server_alloc(config_file);
112   if (silcd->config == NULL)
113     goto fail;
114
115   /* Initialize the server */
116   ret = silc_server_init(silcd);
117   if (ret == FALSE)
118     goto fail;
119   
120   /* Run the server. When this returns the server has been stopped
121      and we will exit. */
122   silc_server_run(silcd);
123   
124   /* Stop the server. This probably has been done already but it
125      doesn't hurt to do it here again. */
126   silc_server_stop(silcd);
127   silc_server_free(silcd);
128   
129   exit(0);
130  fail:
131   exit(1);
132 }