Global costemic changes.
[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.2  2000/07/05 06:14:01  priikone
30  *      Global costemic changes.
31  *
32  * Revision 1.1.1.1  2000/06/27 11:36:56  priikone
33  *      Imported from internal CVS/Added Log headers.
34  *
35  *
36  */
37
38 #include "serverincludes.h"
39 #include "server_internal.h"
40 #include "version.h"
41
42 /* Long command line options */
43 static struct option long_opts[] = 
44 {
45   { "config-file", 1, NULL, 'f' },
46   { "generate-config-file", 0, NULL, 'c' },
47   { "help", 0, NULL, 'h' },
48   { "version", 0, NULL,'V' },
49   { NULL, 0, NULL, 0 }
50 };
51
52 /* Prints out the usage of silc client */
53
54 void silc_usage()
55 {
56   printf("Usage: silcd [options]\n");
57   printf("Options:\n");
58   printf("  -f  --config-file=FILE        Alternate configuration file\n");
59   printf("  -c  --generate-config-file    Generate example configuration "
60          "file\n");
61   printf("  -h  --help                    Display this message\n");
62   printf("  -V  --version                 Display version\n");
63   exit(0);
64 }
65
66 int main(int argc, char **argv)
67 {
68   int ret;
69   int opt, option_index;
70   char *config_file = NULL;
71   SilcServer silcd;
72
73   /* Parse command line arguments */
74   if (argc > 1) {
75     while ((opt = getopt_long(argc, argv, "cf:hV",
76                               long_opts, &option_index)) != EOF) {
77       switch(opt) 
78         {
79         case 'h':
80           silc_usage();
81           break;
82         case 'V':
83           printf("SILCd Secure Internet Live Conferencing daemon, "
84                  "version %s\n", silc_version);
85           printf("(c) 1997 - 2000 Pekka Riikonen "
86                  "<priikone@poseidon.pspt.fi>\n");
87           exit(0);
88           break;
89         case 'c':
90           /* Print out example configuration file */
91           silc_config_server_print();
92           exit(0);
93           break;
94         case 'f':
95           config_file = strdup(optarg);
96           break;
97         default:
98           silc_usage();
99           break;
100         }
101     }
102   }
103
104   /* Default configuration file */
105   if (!config_file)
106     config_file = strdup(SILC_SERVER_CONFIG_FILE);
107
108   /* Create SILC Server object */
109   ret = silc_server_alloc(&silcd);
110   if (ret == FALSE)
111     goto fail;
112
113   /* Read configuration files */
114   silcd->config = silc_config_server_alloc(config_file);
115   if (silcd->config == NULL)
116     goto fail;
117
118   /* Initialize the server */
119   ret = silc_server_init(silcd);
120   if (ret == FALSE)
121     goto fail;
122   
123   /* Run the server. When this returns the server has been stopped
124      and we will exit. */
125   silc_server_run(silcd);
126   
127   /* Stop the server. This probably has been done already but it
128      doesn't hurt to do it here again. */
129   silc_server_stop(silcd);
130   silc_server_free(silcd);
131   
132   exit(0);
133  fail:
134   exit(1);
135 }