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_cmdline.h 00019 * @brief Support functions for command line programs 00020 */ 00021 00022 00023 00024 00025 #ifndef SVN_CMDLINE_H 00026 #define SVN_CMDLINE_H 00027 00028 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00029 #define APR_WANT_STDIO 00030 #endif 00031 #include <apr_want.h> 00032 #include <apr_getopt.h> 00033 00034 #include "svn_utf.h" 00035 #include "svn_auth.h" 00036 #include "svn_config.h" 00037 #include "svn_types.h" 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif /* __cplusplus */ 00042 00043 00044 /** Set up the locale for character conversion, and initialize APR. 00045 * If @a error_stream is non-NULL, print error messages to the stream, 00046 * using @a progname as the program name. Attempt to set @c stdout to 00047 * line-buffered mode, and @a error_stream to unbuffered mode. Return 00048 * @c EXIT_SUCCESS if successful, otherwise @c EXIT_FAILURE. 00049 * 00050 * @note This function should be called exactly once at program startup, 00051 * before calling any other APR or Subversion functions. 00052 */ 00053 int svn_cmdline_init(const char *progname, FILE *error_stream); 00054 00055 00056 /** Set @a *dest to an output-encoded C string from UTF-8 C string @a 00057 * src; allocate @a *dest in @a pool. 00058 */ 00059 svn_error_t *svn_cmdline_cstring_from_utf8(const char **dest, 00060 const char *src, 00061 apr_pool_t *pool); 00062 00063 /** Like svn_utf_cstring_from_utf8_fuzzy(), but converts to an 00064 * output-encoded C string. */ 00065 const char *svn_cmdline_cstring_from_utf8_fuzzy(const char *src, 00066 apr_pool_t *pool); 00067 00068 /** Set @a *dest to a UTF-8-encoded C string from input-encoded C 00069 * string @a src; allocate @a *dest in @a pool. 00070 */ 00071 svn_error_t * svn_cmdline_cstring_to_utf8(const char **dest, 00072 const char *src, 00073 apr_pool_t *pool); 00074 00075 /** Set @a *dest to an output-encoded natively-formatted path string 00076 * from canonical path @a src; allocate @a *dest in @a pool. 00077 */ 00078 svn_error_t *svn_cmdline_path_local_style_from_utf8(const char **dest, 00079 const char *src, 00080 apr_pool_t *pool); 00081 00082 /** Write to stdout, using a printf-like format string @a fmt, passed 00083 * through apr_pvsprintf(). All string arguments are in UTF-8; the output 00084 * is converted to the output encoding. Use @a pool for temporary 00085 * allocation. 00086 * 00087 * @since New in 1.1. 00088 */ 00089 svn_error_t *svn_cmdline_printf(apr_pool_t *pool, 00090 const char *fmt, 00091 ...) 00092 __attribute__((format(printf, 2, 3))); 00093 00094 /** Write to the stdio @a stream, using a printf-like format string @a fmt, 00095 * passed through apr_pvsprintf(). All string arguments are in UTF-8; 00096 * the output is converted to the output encoding. Use @a pool for 00097 * temporary allocation. 00098 * 00099 * @since New in 1.1. 00100 */ 00101 svn_error_t *svn_cmdline_fprintf(FILE *stream, 00102 apr_pool_t *pool, 00103 const char *fmt, 00104 ...) 00105 __attribute__((format(printf, 3, 4))); 00106 00107 /** Output the @a string to the stdio @a stream, converting from UTF-8 00108 * to the output encoding. Use @a pool for temporary allocation. 00109 * 00110 * @since New in 1.1. 00111 */ 00112 svn_error_t *svn_cmdline_fputs(const char *string, 00113 FILE *stream, 00114 apr_pool_t *pool); 00115 00116 /** Flush output buffers of the stdio @a stream, returning an error if that 00117 * fails. This is just a wrapper for the standard fflush() function for 00118 * consistent error handling. 00119 * 00120 * @since New in 1.1. 00121 */ 00122 svn_error_t *svn_cmdline_fflush(FILE *stream); 00123 00124 /** Return the name of the output encoding allocated in @a pool, or @c 00125 * APR_LOCALE_CHARSET if the output encoding is the same as the locale 00126 * encoding. 00127 * 00128 * @since New in 1.3. 00129 */ 00130 const char *svn_cmdline_output_encoding(apr_pool_t *pool); 00131 00132 /** Handle @a error in preparation for immediate exit from a 00133 * command-line client. Specifically: 00134 * 00135 * Call svn_handle_error2(@a error, stderr, FALSE, @a prefix), clear 00136 * @a error, destroy @a pool iff it is non-NULL, and return EXIT_FAILURE. 00137 * 00138 * @since New in 1.3. 00139 */ 00140 int svn_cmdline_handle_exit_error(svn_error_t *error, 00141 apr_pool_t *pool, 00142 const char *prefix); 00143 00144 /** A cancellation function/baton pair, and the path to the configuration 00145 * directory. To be passed as the baton argument to the 00146 * @c svn_cmdline_*_prompt functions. 00147 * 00148 * @since New in 1.6. 00149 */ 00150 typedef struct svn_cmdline_prompt_baton2_t { 00151 svn_cancel_func_t cancel_func; 00152 void *cancel_baton; 00153 const char *config_dir; 00154 } svn_cmdline_prompt_baton2_t; 00155 00156 /** Like svn_cmdline_prompt_baton2_t, but without the path to the 00157 * configuration directory. 00158 * 00159 * @since New in 1.4. 00160 * @deprecated Provided for backward compatibility with the 1.5 API. 00161 */ 00162 typedef struct svn_cmdline_prompt_baton_t { 00163 svn_cancel_func_t cancel_func; 00164 void *cancel_baton; 00165 } svn_cmdline_prompt_baton_t; 00166 00167 /** Prompt the user for input, using @a prompt_str for the prompt and 00168 * @a baton (which may be @c NULL) for cancellation, and returning the 00169 * user's response in @a result, allocated in @a pool. 00170 * 00171 * @since New in 1.5. 00172 */ 00173 svn_error_t * 00174 svn_cmdline_prompt_user2(const char **result, 00175 const char *prompt_str, 00176 svn_cmdline_prompt_baton_t *baton, 00177 apr_pool_t *pool); 00178 00179 /** Similar to svn_cmdline_prompt_user2, but without cancellation 00180 * support. 00181 * 00182 * @deprecated Provided for backward compatibility with the 1.4 API. 00183 */ 00184 SVN_DEPRECATED 00185 svn_error_t * 00186 svn_cmdline_prompt_user(const char **result, 00187 const char *prompt_str, 00188 apr_pool_t *pool); 00189 00190 /** An implementation of @c svn_auth_simple_prompt_func_t that prompts 00191 * the user for keyboard input on the command line. 00192 * 00193 * @since New in 1.4. 00194 * 00195 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton. 00196 */ 00197 svn_error_t * 00198 svn_cmdline_auth_simple_prompt(svn_auth_cred_simple_t **cred_p, 00199 void *baton, 00200 const char *realm, 00201 const char *username, 00202 svn_boolean_t may_save, 00203 apr_pool_t *pool); 00204 00205 00206 /** An implementation of @c svn_auth_username_prompt_func_t that prompts 00207 * the user for their username via the command line. 00208 * 00209 * @since New in 1.4. 00210 * 00211 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton. 00212 */ 00213 svn_error_t * 00214 svn_cmdline_auth_username_prompt(svn_auth_cred_username_t **cred_p, 00215 void *baton, 00216 const char *realm, 00217 svn_boolean_t may_save, 00218 apr_pool_t *pool); 00219 00220 00221 /** An implementation of @c svn_auth_ssl_server_trust_prompt_func_t that 00222 * asks the user if they trust a specific ssl server via the command line. 00223 * 00224 * @since New in 1.4. 00225 * 00226 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton. 00227 */ 00228 svn_error_t * 00229 svn_cmdline_auth_ssl_server_trust_prompt 00230 (svn_auth_cred_ssl_server_trust_t **cred_p, 00231 void *baton, 00232 const char *realm, 00233 apr_uint32_t failures, 00234 const svn_auth_ssl_server_cert_info_t *cert_info, 00235 svn_boolean_t may_save, 00236 apr_pool_t *pool); 00237 00238 00239 /** An implementation of @c svn_auth_ssl_client_cert_prompt_func_t that 00240 * prompts the user for the filename of their SSL client certificate via 00241 * the command line. 00242 * 00243 * Records absolute path of the SSL client certificate file. 00244 * 00245 * @since New in 1.4. 00246 * 00247 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton. 00248 */ 00249 svn_error_t * 00250 svn_cmdline_auth_ssl_client_cert_prompt 00251 (svn_auth_cred_ssl_client_cert_t **cred_p, 00252 void *baton, 00253 const char *realm, 00254 svn_boolean_t may_save, 00255 apr_pool_t *pool); 00256 00257 00258 /** An implementation of @c svn_auth_ssl_client_cert_pw_prompt_func_t that 00259 * prompts the user for their SSL certificate password via the command line. 00260 * 00261 * @since New in 1.4. 00262 * 00263 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton. 00264 */ 00265 svn_error_t * 00266 svn_cmdline_auth_ssl_client_cert_pw_prompt 00267 (svn_auth_cred_ssl_client_cert_pw_t **cred_p, 00268 void *baton, 00269 const char *realm, 00270 svn_boolean_t may_save, 00271 apr_pool_t *pool); 00272 00273 /** An implementation of @c svn_auth_plaintext_prompt_func_t that 00274 * prompts the user whether storing unencypted passwords to disk is OK. 00275 * 00276 * @since New in 1.6. 00277 */ 00278 svn_error_t * 00279 svn_cmdline_auth_plaintext_prompt(svn_boolean_t *may_save_plaintext, 00280 const char *realmstring, 00281 void *baton, 00282 apr_pool_t *pool); 00283 00284 /** An implementation of @c svn_auth_plaintext_passphrase_prompt_func_t that 00285 * prompts the user whether storing unencypted passphrase to disk is OK. 00286 * 00287 * @since New in 1.6. 00288 */ 00289 svn_error_t * 00290 svn_cmdline_auth_plaintext_passphrase_prompt(svn_boolean_t *may_save_plaintext, 00291 const char *realmstring, 00292 void *baton, 00293 apr_pool_t *pool); 00294 00295 /** Initialize auth baton @a ab with the standard set of authentication 00296 * providers used by the command line client. 00297 * 00298 * @a non_interactive, @a username, @a password, @a config_dir, 00299 * @a no_auth_cache, and @a trust_server_cert are the values of the 00300 * command line options of the corresponding names. 00301 * 00302 * @a cfg is the @c SVN_CONFIG_CATEGORY_CONFIG configuration, and 00303 * @a cancel_func and @a cancel_baton control the cancellation of the 00304 * prompting providers that are initialized. 00305 * 00306 * Use @a pool for all allocations. 00307 * 00308 * @since New in 1.6. 00309 */ 00310 svn_error_t * 00311 svn_cmdline_set_up_auth_baton(svn_auth_baton_t **ab, 00312 svn_boolean_t non_interactive, 00313 const char *username, 00314 const char *password, 00315 const char *config_dir, 00316 svn_boolean_t no_auth_cache, 00317 svn_boolean_t trust_server_cert, 00318 svn_config_t *cfg, 00319 svn_cancel_func_t cancel_func, 00320 void *cancel_baton, 00321 apr_pool_t *pool); 00322 00323 /** Similar to svn_cmdline_set_up_auth_baton(), but with 00324 * @a trust_server_cert always set to false. 00325 * 00326 * @since New in 1.4. 00327 * @deprecated Provided for backward compatibility with the 1.5 API. 00328 * 00329 * @note This deprecation does not follow the usual pattern of putting 00330 * a new number on end of the function's name. Instead, the new 00331 * function name is distinguished from the old by a grammatical 00332 * improvement: the verb "set_up" instead of the noun "setup". 00333 */ 00334 SVN_DEPRECATED 00335 svn_error_t * 00336 svn_cmdline_setup_auth_baton(svn_auth_baton_t **ab, 00337 svn_boolean_t non_interactive, 00338 const char *username, 00339 const char *password, 00340 const char *config_dir, 00341 svn_boolean_t no_auth_cache, 00342 svn_config_t *cfg, 00343 svn_cancel_func_t cancel_func, 00344 void *cancel_baton, 00345 apr_pool_t *pool); 00346 00347 /** Wrapper for apr_getopt_init(), which see. 00348 * 00349 * @since New in 1.4. 00350 * 00351 * This is a private API for Subversion's own use. 00352 */ 00353 svn_error_t * 00354 svn_cmdline__getopt_init(apr_getopt_t **os, 00355 int argc, 00356 const char *argv[], 00357 apr_pool_t *pool); 00358 00359 #ifdef __cplusplus 00360 } 00361 #endif /* __cplusplus */ 00362 00363 #endif /* SVN_CMDLINE_H */
1.3.9.1