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