Main Page   Modules   Data Structures   File List   Data Fields  

svn_config.h

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

Generated on Sat Apr 2 11:52:35 2005 for Subversion by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002