1 /*************************************** 2 $Header: /home/amb/CVS/wwwoffle/src/configpriv.h,v 1.27 2006-01-07 16:10:38 amb Exp $ 3 4 WWWOFFLE - World Wide Web Offline Explorer - Version 2.9. 5 Configuration file management functions. 6 ******************/ /****************** 7 Written by Andrew M. Bishop 8 9 This file Copyright 1997,98,99,2000,01,02,03,04,05,06 Andrew M. Bishop 10 It may be distributed under the GNU Public License, version 2, or 11 any higher version. See section COPYING of the GNU Public license 12 for conditions under which this file may be redistributed. 13 ***************************************/ 14 15 16 #ifndef CONFIGPRIV_H 17 #define CONFIGPRIV_H /*+ To stop multiple inclusions. +*/ 18 19 20 /* How the Configuration data structures relate to each other 21 * ========================================================== 22 * 23 * Static Part 24 * ----------- -> char[] -> char[] 25 * / ? B; static / ? B; static 26 * ConfigSection / ConfigItemDef / 27 * +-----------+ / +-----------+ / 28 * | name | - ConfigItemDef[] --> | name | - ConfigItem 29 * +-----------+ +-----------+ / +-----------+ +-----------+ 30 * | nitemdefs | --> | item[0] | --| | item | -----> | | 31 * +-----------+ / +-----------+ | +-----------+ +-----------+ 32 * | itemdef | -- | item[1] | | | url_type | 4 B; static 33 * +-----------+ +-----------+ | +-----------+ 34 * 12 B; static : : | | same_key | 35 * +-----------+ | +-----------+ 36 * | item[n-1] | | | key_type | 37 * +-----------+ | +-----------+ 38 * 4N B; static | | val_type | 39 * | +-----------+ 40 * | | def_val | 41 * | +-----------+ 42 * | 28 B; static 43 * Dynamic Part | 44 * ------------ | 45 * | UrlSpec opt. 46 * | optional +-----------+ - - -> char[] 47 * | - - - - - - - - - - > +-----------+ - - -> char[] 48 * | / : : - - -> char[] 49 * | +-----------+ - - -> char[] 50 * struct | / +-----------+ ? B; realloc 51 * ConfigItem _ConfigItem | *UrlSpec[] 16 B; malloc UrlSpec 52 * +-----------+ opt. +-----------+ / +-----------+ / 53 * | | - - -> | itemdef | - t-> | url[0] | - KeyOrValue[] 54 * +-----------+ +-----------+ p/ +-----------+ +-----------+ opt. UrlSpec opt. 55 * 4 B; static | nentries | o : : -> | key[0] | - - -> +-----------+ - - -> char[] 56 * +-----------+ / +-----------+ / +-----------+ +-----------+ - - -> char[] 57 * | url | - | url[n-1] | / : : : : - - -> char[] 58 * +-----------+ +-----------+ / +-----------+ +-----------+ - - -> char[] 59 * | key | ----. 4N B; malloc / | key[2] | +-----------+ ? B; realloc 60 * +-----------+ `--------------- +-----------+ 16 B; malloc UrlSpec 61 * | val | - - - - - - - - - - - 4N B; malloc 62 * +-----------+ \o 63 * | def_val | -- KeyOrValue p KeyOrValue[] 64 * +-----------+ \ +-----------+ \t +-----------+ opt. UrlSpec opt. 65 * 24 B; malloc --> | | -> | val[0] | - - -> +-----------+ - - -> char[] 66 * +-----------+ +-----------+ +-----------+ - - -> char[] 67 * 4 B; malloc : : : : - - -> char[] 68 * +-----------+ +-----------+ - - -> char[] 69 * | val[n-1] | +-----------+ ? B; realloc 70 * +-----------+ 16 B; malloc UrlSpec 71 * 4N B; malloc 72 */ 73 74 75 /* Type definitions */ 76 77 /*+ The type of value to expect for a value. +*/ 78 typedef enum _ConfigType 79 { 80 Fixed, /*+ When the left hand side is fixed. +*/ 81 None, /*+ When there is no right hand side. +*/ 82 83 CfgMaxServers, /*+ Max number of servers to fork (>0, <MAX_SERVERS). +*/ 84 CfgMaxFetchServers, /*+ Max number of servers for fetching pages (>0, <MAX_FETCH_SERVERS). +*/ 85 86 CfgLogLevel, /*+ A log level (debug, info, important, warning or fatal). +*/ 87 88 Boolean, /*+ A boolean response (yes/no 1/0 true/false). +*/ 89 90 PortNumber, /*+ For port numbers (>0). +*/ 91 92 AgeDays, /*+ An age in days (can be -ve). +*/ 93 TimeSecs, /*+ A time in seconds (can be -ve). +*/ 94 95 CacheSize, /*+ The cache size (must be >=0). +*/ 96 FileSize, /*+ A file size (must be >=0) +*/ 97 98 Percentage, /*+ A percentage (must be >=0 and <=100) +*/ 99 100 UserId, /*+ For user IDs, (numeric or string). +*/ 101 GroupId, /*+ For group IDs, (numeric or string). +*/ 102 103 String, /*+ For an arbitrary string. +*/ 104 105 PathName, /*+ For pathname values (string starting with '/'). +*/ 106 FileExt, /*+ A file extension (.string). +*/ 107 FileMode, /*+ The mode for dir/file creation. +*/ 108 109 MIMEType, /*+ A MIME type (string/string). +*/ 110 111 Host, /*+ For host names (string). +*/ 112 HostOrNone, /*+ For host names (string) or nothing. +*/ 113 HostAndPort, /*+ For host name and port numbers (string[:port]). +*/ 114 HostAndPortOrNone, /*+ For host name and port numbers (string[:port]) or nothing. +*/ 115 HostWild, /*+ For host names that could be wildcards (string). +*/ 116 HostAndPortWild, /*+ For host names and port numbers that could be wildcards (string[:port]). +*/ 117 118 UserPass, /*+ A username and password (string:string) +*/ 119 120 Url, /*+ For a URL ([proto://host[:port]]/path). +*/ 121 UrlWild, /*+ For a URL that could contain wildcards ([proto://host[:port]]/path). +*/ 122 123 UrlSpecification /*+ A URL specification as described in README.CONF. +*/ 124 } 125 ConfigType; 126 127 128 /*+ The reference to one item in a section of the configuration file as used by the rest of the program. +*/ 129 typedef struct _ConfigItem* ConfigItem; 130 131 /*+ The definition of an item in a section of the configuration file. +*/ 132 typedef struct _ConfigItemDef 133 { 134 char *name; /*+ The name of the entry. +*/ 135 ConfigItem *item; /*+ A pointer to the item containing the values for the entry. +*/ 136 int url_type; /*+ Set to true if there is the option of having a URL present. +*/ 137 int same_key; /*+ Set to true if the entry can repeat with the same key. +*/ 138 ConfigType key_type; /*+ The type of the key on the left side of the equals sign. +*/ 139 ConfigType val_type; /*+ The type of the value on the right side of the equals sign. +*/ 140 /*@null@*/ char *def_val; /*+ The default value if no other is specified. +*/ 141 } 142 ConfigItemDef; 143 144 /*+ A section in the configuration file. +*/ 145 typedef struct _ConfigSection 146 { 147 char *name; /*+ The name of the section. +*/ 148 int nitemdefs; /*+ The number of item definitions in the section. +*/ 149 ConfigItemDef *itemdefs; /*+ The item definitions in the section. +*/ 150 } 151 ConfigSection; 152 153 /*+ A whole configuration file. +*/ 154 typedef struct _ConfigFile 155 { 156 char *name; /*+ The name of the file. +*/ 157 int nsections; /*+ The number of sections in the file. +*/ 158 ConfigSection **sections; /*+ The sections in the file. +*/ 159 } 160 ConfigFile; 161 162 /*+ A URL-SPECIFICATION as described in README.CONF. +*/ 163 typedef struct _UrlSpec 164 { 165 char null; /*+ A null character for parts that are not set. +*/ 166 char negated; /*+ Set to true if this is a negated URL-SPECIFICATION +*/ 167 char nocase; /*+ A flag that is set if case is ignored in the path. +*/ 168 unsigned short proto; /*+ The protocol or 0 (specified as an offset from start of UrlSpec). +*/ 169 unsigned short host; /*+ The hostname or 0 (specified as an offset from start of UrlSpec). +*/ 170 int port; /*+ The port number (or 0 or -1). +*/ 171 unsigned short path; /*+ The pathname or 0 (specified as an offset from start of UrlSpec). +*/ 172 unsigned short args; /*+ The arguments or 0 (specified as an offset from start of UrlSpec). +*/ 173 } 174 UrlSpec; 175 176 #define HasUrlSpecProto(xxx) ((xxx)->proto) 177 #define HasUrlSpecHost(xxx) ((xxx)->host) 178 #define HasUrlSpecPath(xxx) ((xxx)->path) 179 #define HasUrlSpecArgs(xxx) ((xxx)->args) 180 181 #define UrlSpecProto(xxx) (char*)((char*)(xxx)+(int)(xxx)->proto) 182 #define UrlSpecHost(xxx) (char*)((char*)(xxx)+(int)(xxx)->host) 183 #define UrlSpecPath(xxx) (char*)((char*)(xxx)+(int)(xxx)->path) 184 #define UrlSpecArgs(xxx) (char*)((char*)(xxx)+(int)(xxx)->args) 185 186 #define UrlSpecPort(xxx) ((xxx)->port) 187 188 /*+ A key or a value. +*/ 189 typedef union _KeyOrValue 190 { 191 char *string; /*+ A string value. +*/ 192 int integer; /*+ An integer value. +*/ 193 UrlSpec *urlspec; /*+ A URL-SPECIFICATION +*/ 194 } 195 KeyOrValue; 196 197 /*+ One item in a section of the configuration file. +*/ 198 struct _ConfigItem 199 { 200 const ConfigItemDef *itemdef; /*+ The corresponding item definition. +*/ 201 int nentries; /*+ The number of entries in the lists. +*/ 202 UrlSpec **url; /*+ The list of URL-SPECIFICATIONs if present. +*/ 203 KeyOrValue *key; /*+ The list of keys. +*/ 204 KeyOrValue *val; /*+ The list of values. +*/ 205 KeyOrValue *def_val; /*+ The default value. +*/ 206 }; 207 208 209 /* in configrdwr.c */ 210 211 char /*@only@*/ /*@null@*/ *ReadConfigFile(int read_startup); 212 213 char /*@only@*/ /*@null@*/ *ModifyConfigFile(int section,int item,/*@null@*/ char *newentry,/*@null@*/ char *preventry,/*@null@*/ char *sameentry,/*@null@*/ char *nextentry); 214 215 char /*@only@*/ /*@null@*/ *ParseKeyOrValue(const char *text,ConfigType type,/*@out@*/ KeyOrValue *pointer); 216 217 218 /* In configmisc.c */ 219 220 void DefaultConfigFile(void); 221 222 void CreateBackupConfigFile(void); 223 void RestoreBackupConfigFile(void); 224 225 void PurgeBackupConfigFile(int restore_startup); 226 void PurgeConfigFile(void); 227 228 void FreeConfigItem(/*@null@*/ /*@special@*/ ConfigItem item) /*@releases item@*/; 229 void FreeKeyOrValue(/*@only@*/ KeyOrValue *keyval,ConfigType type); 230 231 int MatchUrlSpecification(const UrlSpec *spec,const char *proto,const char *host,int port,const char *path,/*@null@*/ const char *args); 232 int WildcardMatch(const char *string,const char *pattern,int nocase); 233 234 char *ConfigEntryString(ConfigItem item,int which); 235 void ConfigEntryStrings(ConfigItem item,int which,/*@out@*/ char **url,/*@out@*/ char **key,/*@out@*/ char **val); 236 char *MakeConfigEntryString(const ConfigItemDef *itemdef,/*@null@*/ const char *url,/*@null@*/ const char *key,/*@null@*/ const char *val); 237 238 /*@observer@*/ char *ConfigTypeString(ConfigType type); 239 240 241 /* In configfunc.c */ 242 243 char *DefaultFTPPassWord(void); 244 245 246 /* Variable definitions */ 247 248 /*+ The contents of the whole configuration file. +*/ 249 extern ConfigFile CurrentConfig; 250 251 252 #endif /* CONFIGPRIV_H */ 253