Initial revision
[crypto.git] / apps / silc / clientconfig.h
1 /*
2
3   clientconfig.h
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 #ifndef CLIENTCONFIG_H
22 #define CLIENTCONFIG_H
23
24 /* Holds information of configured algorithms */
25 typedef struct SilcClientConfigSectionAlgStruct {
26   char *alg_name;
27   char *sim_name;
28   unsigned int block_len;
29   unsigned int key_len;
30   struct SilcClientConfigSectionAlgStruct *next;
31   struct SilcClientConfigSectionAlgStruct *prev;
32 #define SILC_CLIENT_CONFIG_MODNAME "builtin"
33 } SilcClientConfigSectionAlg;
34
35 /* Holds all server connections from config file */
36 typedef struct SilcClientConfigSectionConnectionStruct {
37   char *host;
38   int auth_meth;
39   char *auth_data;
40   unsigned short port;
41   struct SilcClientConfigSectionConnectionStruct *next;
42   struct SilcClientConfigSectionConnectionStruct *prev;
43 #define SILC_CLIENT_CONFIG_AUTH_METH_PASSWD "passwd"
44 #define SILC_CLIENT_CONFIG_AUTH_METH_PUBKEY "pubkey"
45 } SilcClientConfigSectionConnection;
46
47 /* Holds all given commands from config file */
48 typedef struct SilcClientConfigSectionCommandStruct {
49   char *command;
50   struct SilcClientConfigSectionCommandStruct *next;
51   struct SilcClientConfigSectionCommandStruct *prev;
52 } SilcClientConfigSectionCommand;
53
54 /* 
55    SILC Client Config object.
56
57    This object holds all the data parsed from the SILC client configuration
58    file. This is mainly used at the initialization of the client.
59
60 */
61 typedef struct {
62   /* Pointer back to the client */
63   void *client;
64
65   /* Filename of the configuration file */
66   char *filename;
67
68   /* Configuration sections */
69   SilcClientConfigSectionAlg *cipher;
70   SilcClientConfigSectionAlg *pkcs;
71   SilcClientConfigSectionAlg *hash_func;
72   SilcClientConfigSectionConnection *conns;
73   SilcClientConfigSectionCommand *commands;
74 } SilcClientConfigObject;
75
76 typedef SilcClientConfigObject *SilcClientConfig;
77
78 /* Configuration section type enumerations. */
79 typedef enum {
80   SILC_CLIENT_CONFIG_SECTION_TYPE_NONE = 0,
81   SILC_CLIENT_CONFIG_SECTION_TYPE_CIPHER,
82   SILC_CLIENT_CONFIG_SECTION_TYPE_PKCS,
83   SILC_CLIENT_CONFIG_SECTION_TYPE_HASH_FUNCTION,
84   SILC_CLIENT_CONFIG_SECTION_TYPE_CONNECTION,
85   SILC_CLIENT_CONFIG_SECTION_TYPE_COMMAND = 253, /* Special section */
86 } SilcClientConfigSectionType;
87
88 /* SILC Configuration Section structure. */
89 typedef struct {
90   const char *section;
91   SilcClientConfigSectionType type;
92   unsigned int maxfields;
93 } SilcClientConfigSection;
94
95 /* List of all possible config sections in SILC client */
96 extern SilcClientConfigSection silc_client_config_sections[];
97
98 /* Structure used in parsing the configuration lines. The line is read
99    from a file to this structure before parsing it further. */
100 typedef struct SilcClientConfigParseStruct {
101   SilcBuffer line;
102   unsigned int linenum;
103   SilcClientConfigSection *section;
104   struct SilcClientConfigParseStruct *next;
105   struct SilcClientConfigParseStruct *prev;
106 } *SilcClientConfigParse;
107
108 /* Prototypes */
109 SilcClientConfig silc_client_config_alloc(char *filename);
110 void silc_client_config_free(SilcClientConfig config);
111 int silc_client_config_parse(SilcClientConfig config, SilcBuffer buffer,
112                              SilcClientConfigParse *return_config);
113 int silc_client_config_parse_lines(SilcClientConfig config, 
114                                    SilcClientConfigParse parse_config);
115 int silc_client_config_check_sections(unsigned int checkmask);
116 void silc_client_config_setlogfiles(SilcClientConfig config);
117 void silc_client_config_register_ciphers(SilcClientConfig config);
118 void silc_client_config_register_pkcs(SilcClientConfig config);
119 void silc_client_config_register_hashfuncs(SilcClientConfig config);
120 SilcClientConfigSectionConnection *
121 silc_client_config_find_connection(SilcClientConfig config, 
122                                    char *host, int port);
123
124 #endif