00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2000-2004 CollabNet. All rights reserved. 00005 * 00006 * This software is licensed as described in the file COPYING, which 00007 * you should have received as part of this distribution. The terms 00008 * are also available at http://subversion.tigris.org/license-1.html. 00009 * If newer versions of this license are posted there, you may use a 00010 * newer version instead, at your option. 00011 * 00012 * This software consists of voluntary contributions made by many 00013 * individuals. For exact contribution history, see the revision 00014 * history and logs, available at http://subversion.tigris.org/. 00015 * ==================================================================== 00016 * @endcopyright 00017 * 00018 * @file svn_config.h 00019 * @brief Accessing SVN configuration files. 00020 */ 00021 00022 00023 00024 #ifndef SVN_CONFIG_H 00025 #define SVN_CONFIG_H 00026 00027 #include <apr_pools.h> 00028 00029 #include "svn_types.h" 00030 #include "svn_error.h" 00031 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif /* __cplusplus */ 00036 00037 00038 /************************************************************************** 00039 *** *** 00040 *** For a description of the SVN configuration file syntax, see *** 00041 *** your ~/.subversion/README, which is written out automatically by *** 00042 *** svn_config_ensure(). *** 00043 *** *** 00044 **************************************************************************/ 00045 00046 00047 /** Opaque structure describing a set of configuration options. */ 00048 typedef struct svn_config_t svn_config_t; 00049 00050 00051 /*** Configuration Defines ***/ 00052 00053 /** @{ 00054 * Strings for the names of files, sections, and options in the 00055 * client configuration files. 00056 */ 00057 #define SVN_CONFIG_CATEGORY_SERVERS "servers" 00058 #define SVN_CONFIG_SECTION_GROUPS "groups" 00059 #define SVN_CONFIG_SECTION_GLOBAL "global" 00060 #define SVN_CONFIG_OPTION_HTTP_PROXY_HOST "http-proxy-host" 00061 #define SVN_CONFIG_OPTION_HTTP_PROXY_PORT "http-proxy-port" 00062 #define SVN_CONFIG_OPTION_HTTP_PROXY_USERNAME "http-proxy-username" 00063 #define SVN_CONFIG_OPTION_HTTP_PROXY_PASSWORD "http-proxy-password" 00064 #define SVN_CONFIG_OPTION_HTTP_PROXY_EXCEPTIONS "http-proxy-exceptions" 00065 #define SVN_CONFIG_OPTION_HTTP_TIMEOUT "http-timeout" 00066 #define SVN_CONFIG_OPTION_HTTP_COMPRESSION "http-compression" 00067 #define SVN_CONFIG_OPTION_NEON_DEBUG_MASK "neon-debug-mask" 00068 #define SVN_CONFIG_OPTION_SSL_AUTHORITY_FILES "ssl-authority-files" 00069 #define SVN_CONFIG_OPTION_SSL_TRUST_DEFAULT_CA "ssl-trust-default-ca" 00070 #define SVN_CONFIG_OPTION_SSL_CLIENT_CERT_FILE "ssl-client-cert-file" 00071 #define SVN_CONFIG_OPTION_SSL_CLIENT_CERT_PASSWORD "ssl-client-cert-password" 00072 00073 #define SVN_CONFIG_CATEGORY_CONFIG "config" 00074 #define SVN_CONFIG_SECTION_AUTH "auth" 00075 #define SVN_CONFIG_OPTION_STORE_PASSWORDS "store-passwords" 00076 #define SVN_CONFIG_OPTION_STORE_AUTH_CREDS "store-auth-creds" 00077 #define SVN_CONFIG_SECTION_HELPERS "helpers" 00078 #define SVN_CONFIG_OPTION_EDITOR_CMD "editor-cmd" 00079 #define SVN_CONFIG_OPTION_DIFF_CMD "diff-cmd" 00080 #define SVN_CONFIG_OPTION_DIFF3_CMD "diff3-cmd" 00081 #define SVN_CONFIG_OPTION_DIFF3_HAS_PROGRAM_ARG "diff3-has-program-arg" 00082 #define SVN_CONFIG_SECTION_MISCELLANY "miscellany" 00083 #define SVN_CONFIG_OPTION_GLOBAL_IGNORES "global-ignores" 00084 #define SVN_CONFIG_OPTION_LOG_ENCODING "log-encoding" 00085 #define SVN_CONFIG_OPTION_USE_COMMIT_TIMES "use-commit-times" 00086 #define SVN_CONFIG_OPTION_TEMPLATE_ROOT "template-root" 00087 #define SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS "enable-auto-props" 00088 #define SVN_CONFIG_OPTION_NO_UNLOCK "no-unlock" 00089 #define SVN_CONFIG_SECTION_TUNNELS "tunnels" 00090 #define SVN_CONFIG_SECTION_AUTO_PROPS "auto-props" 00091 /** @} */ 00092 00093 /** @{ 00094 * Strings for the names of sections and options in the 00095 * repository conf directory configuration files. 00096 */ 00097 /* For repository svnserve.conf files */ 00098 #define SVN_CONFIG_SECTION_GENERAL "general" 00099 #define SVN_CONFIG_OPTION_ANON_ACCESS "anon-access" 00100 #define SVN_CONFIG_OPTION_AUTH_ACCESS "auth-access" 00101 #define SVN_CONFIG_OPTION_PASSWORD_DB "password-db" 00102 #define SVN_CONFIG_OPTION_REALM "realm" 00103 00104 /* For repository password database */ 00105 #define SVN_CONFIG_SECTION_USERS "users" 00106 /** @} */ 00107 00108 /*** Configuration Default Values ***/ 00109 00110 #define SVN_CONFIG_DEFAULT_GLOBAL_IGNORES \ 00111 "*.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store" 00112 00113 #define SVN_CONFIG_TRUE "true" 00114 #define SVN_CONFIG_FALSE "false" 00115 00116 00117 /** Read configuration information from the standard sources and merge it 00118 * into the hash @a *cfg_hash. If @a config_dir is not NULL it specifies a 00119 * directory from which to read the configuration files, overriding all 00120 * other sources. Otherwise, first read any system-wide configurations 00121 * (from a file or from the registry), then merge in personal 00122 * configurations (again from file or registry). The hash and all its data 00123 * are allocated in @a pool. 00124 * 00125 * @a *cfg_hash is a hash whose keys are @c const char * configuration 00126 * categories (@c SVN_CONFIG_CATEGORY_SERVERS, 00127 * @c SVN_CONFIG_CATEGORY_CONFIG, etc.) and whose values are the @c 00128 * svn_config_t * items representing the configuration values for that 00129 * category. 00130 */ 00131 svn_error_t *svn_config_get_config (apr_hash_t **cfg_hash, 00132 const char *config_dir, 00133 apr_pool_t *pool); 00134 00135 00136 /** Read configuration data from @a file (a file or registry path) into 00137 * @a *cfgp, allocated in @a pool. 00138 * 00139 * If @a file does not exist, then if @a must_exist, return an error, 00140 * otherwise return an empty @c svn_config_t. 00141 */ 00142 svn_error_t *svn_config_read (svn_config_t **cfgp, 00143 const char *file, 00144 svn_boolean_t must_exist, 00145 apr_pool_t *pool); 00146 00147 /** Like @c svn_config_read, but merges the configuration data from @a file 00148 * (a file or registry path) into @a *cfg, which was previously returned 00149 * from @c svn_config_read. This function invalidates all value 00150 * expansions in @a cfg, so that the next @c svn_option_get takes the 00151 * modifications into account. 00152 */ 00153 svn_error_t *svn_config_merge (svn_config_t *cfg, 00154 const char *file, 00155 svn_boolean_t must_exist); 00156 00157 00158 /** Find the value of a (@a section, @a option) pair in @a cfg, set @a 00159 * *valuep to the value. 00160 * 00161 * If @a cfg is @c NULL, just sets @a *valuep to @a default_value. If 00162 * the value does not exist, expand and return @a default_value. 00163 * 00164 * The returned value will be valid at least until the next call to 00165 * @c svn_config_get, or for the lifetime of @a default_value. It is 00166 * safest to consume the returned value immediately. 00167 * 00168 * This function may change @a cfg by expanding option values. 00169 */ 00170 void svn_config_get (svn_config_t *cfg, const char **valuep, 00171 const char *section, const char *option, 00172 const char *default_value); 00173 00174 /** Add or replace the value of a (@a section, @a option) pair in @a cfg with 00175 * @a value. 00176 * 00177 * This function invalidates all value expansions in @a cfg. 00178 */ 00179 void svn_config_set (svn_config_t *cfg, 00180 const char *section, const char *option, 00181 const char *value); 00182 00183 /** Like @c svn_config_get, but for boolean values. 00184 * 00185 * Parses the option as a boolean value. The recognized representations 00186 * are 'true'/'false', 'yes'/'no', 'on'/'off', '1'/'0'; case does not 00187 * matter. Returns an error if the option doesn't contain a known string. 00188 */ 00189 svn_error_t *svn_config_get_bool (svn_config_t *cfg, svn_boolean_t *valuep, 00190 const char *section, const char *option, 00191 svn_boolean_t default_value); 00192 00193 /** Like @c svn_config_set, but for boolean values. 00194 * 00195 * Sets the option to 'true'/'false', depending on @a value. 00196 */ 00197 void svn_config_set_bool (svn_config_t *cfg, 00198 const char *section, const char *option, 00199 svn_boolean_t value); 00200 00201 /** A callback function used in enumerating config sections. 00202 * 00203 * See @c svn_config_enumerate_sections for the details of this type. 00204 */ 00205 typedef svn_boolean_t (*svn_config_section_enumerator_t) 00206 (const char *name, void *baton); 00207 00208 /** Enumerate the sections, passing @a baton and the current section's name to 00209 * @a callback. Continue the enumeration if @a callback returns @c TRUE. 00210 * Return the number of times @a callback was called. 00211 * 00212 * ### See kff's comment to @c svn_config_enumerate. It applies to this 00213 * function, too. ### 00214 * 00215 * @a callback's @a name and @a name parameters are only valid for the 00216 * duration of the call. 00217 */ 00218 int svn_config_enumerate_sections (svn_config_t *cfg, 00219 svn_config_section_enumerator_t callback, 00220 void *baton); 00221 00222 /** A callback function used in enumerating config options. 00223 * 00224 * See @c svn_config_enumerate for the details of this type. 00225 */ 00226 typedef svn_boolean_t (*svn_config_enumerator_t) 00227 (const char *name, const char *value, void *baton); 00228 00229 /** Enumerate the options in @a section, passing @a baton and the current 00230 * option's name and value to @a callback. Continue the enumeration if 00231 * @a callback returns @c TRUE. Return the number of times @a callback 00232 * was called. 00233 * 00234 * ### kff asks: A more usual interface is to continue enumerating 00235 * while @a callback does not return error, and if @a callback does 00236 * return error, to return the same error (or a wrapping of it) 00237 * from @c svn_config_enumerate. What's the use case for 00238 * @c svn_config_enumerate? Is it more likely to need to break out 00239 * of an enumeration early, with no error, than an invocation of 00240 * @a callback is likely to need to return an error? ### 00241 * 00242 * @a callback's @a name and @a value parameters are only valid for the 00243 * duration of the call. 00244 */ 00245 int svn_config_enumerate (svn_config_t *cfg, const char *section, 00246 svn_config_enumerator_t callback, void *baton); 00247 00248 00249 /** Enumerate the group @a master_section in @a cfg. Each variable 00250 * value is interpreted as a list of glob patterns (separated by comma 00251 * and optional whitespace). Return the name of the first variable 00252 * whose value matches @a key, or @c NULL if no variable matches. 00253 */ 00254 const char *svn_config_find_group (svn_config_t *cfg, const char *key, 00255 const char *master_section, 00256 apr_pool_t *pool); 00257 00258 /** Retrieve value corresponding to @a option_name for a given 00259 * @a server_group in @a cfg , or return @a default_value if none is found. 00260 * 00261 * The config will first be checked for a default, then will be checked for 00262 * an override in a server group. 00263 */ 00264 const char *svn_config_get_server_setting(svn_config_t *cfg, 00265 const char* server_group, 00266 const char* option_name, 00267 const char* default_value); 00268 00269 /** Retrieve value into @a result_value corresponding to @a option_name for a 00270 * given @a server_group in @a cfg, or return @a default_value if none is 00271 * found. 00272 * 00273 * The config will first be checked for a default, then will be checked for 00274 * an override in a server group. If the value found is not a valid integer, 00275 * a @c svn_error_t* will be returned. 00276 */ 00277 svn_error_t *svn_config_get_server_setting_int(svn_config_t *cfg, 00278 const char *server_group, 00279 const char *option_name, 00280 apr_int64_t default_value, 00281 apr_int64_t *result_value, 00282 apr_pool_t *pool); 00283 00284 00285 /** Try to ensure that the user's ~/.subversion/ area exists, and create 00286 * no-op template files for any absent config files. Use @a pool for any 00287 * temporary allocation. If @a config_dir is not NULL it specifies a 00288 * directory from which to read the config overriding all other sources. 00289 * 00290 * Don't error if something exists but is the wrong kind (for example, 00291 * ~/.subversion exists but is a file, or ~/.subversion/servers exists 00292 * but is a directory). 00293 * 00294 * Also don't error if try to create something and fail -- it's okay 00295 * for the config area or its contents not to be created. But if 00296 * succeed in creating a config template file, return error if unable 00297 * to initialize its contents. 00298 */ 00299 svn_error_t *svn_config_ensure (const char *config_dir, apr_pool_t *pool); 00300 00301 00302 00303 00304 /** Accessing cached authentication data in the user config area. 00305 * 00306 * @defgroup cached_authentication_data cached authentication data. 00307 * @{ 00308 */ 00309 00310 00311 /** A hash-key pointing to a realmstring. Every file containing 00312 * authentication data should have this key. 00313 */ 00314 #define SVN_CONFIG_REALMSTRING_KEY "svn:realmstring" 00315 00316 /** Use @a cred_kind and @a realmstring to locate a file within the 00317 * ~/.subversion/auth/ area. If the file exists, initialize @a *hash 00318 * and load the file contents into the hash, using @a pool. If the 00319 * file doesn't exist, set @a *hash to NULL. 00320 * 00321 * If @a config_dir is not NULL it specifies a directory from which to 00322 * read the config overriding all other sources. 00323 * 00324 * Besides containing the original credential fields, the hash will 00325 * also contain @c SVN_CONFIG_REALMSTRING_KEY. The caller can examine 00326 * this value as a sanity-check that the correct file was loaded. 00327 * 00328 * The hashtable will contain <tt>const char *</tt> keys and 00329 * <tt>svn_string_t *</tt> values. 00330 */ 00331 svn_error_t * svn_config_read_auth_data (apr_hash_t **hash, 00332 const char *cred_kind, 00333 const char *realmstring, 00334 const char *config_dir, 00335 apr_pool_t *pool); 00336 00337 /** Use @a cred_kind and @a realmstring to create or overwrite a file 00338 * within the ~/.subversion/auth/ area. Write the contents of @a hash into 00339 * the file. If @a config_dir is not NULL it specifies a directory to read 00340 * the config overriding all other sources. 00341 * 00342 * Also, add @a realmstring to the file, with key @c 00343 * SVN_CONFIG_REALMSTRING_KEY. This allows programs (or users) to 00344 * verify exactly which set credentials live within the file. 00345 * 00346 * The hashtable must contain <tt>const char *</tt> keys and 00347 * <tt>svn_string_t *</tt> values. 00348 */ 00349 svn_error_t * svn_config_write_auth_data (apr_hash_t *hash, 00350 const char *cred_kind, 00351 const char *realmstring, 00352 const char *config_dir, 00353 apr_pool_t *pool); 00354 00355 /** @} */ 00356 00357 #ifdef __cplusplus 00358 } 00359 #endif /* __cplusplus */ 00360 00361 #endif /* SVN_CONFIG_H */