3 * ====================================================================
4 * Copyright (c) 2000-2004, 2008-2009 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief Support functions for command line programs
28 #include <apr_pools.h>
29 #include <apr_getopt.h>
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 #define APR_WANT_STDIO
36 #include "svn_types.h"
38 #include "svn_config.h"
42 #endif /* __cplusplus */
45 /** Set up the locale for character conversion, and initialize APR.
46 * If @a error_stream is non-NULL, print error messages to the stream,
47 * using @a progname as the program name. Attempt to set @c stdout to
48 * line-buffered mode, and @a error_stream to unbuffered mode. Return
49 * @c EXIT_SUCCESS if successful, otherwise @c EXIT_FAILURE.
51 * @note This function should be called exactly once at program startup,
52 * before calling any other APR or Subversion functions.
55 svn_cmdline_init(const char *progname
,
59 /** Set @a *dest to an output-encoded C string from UTF-8 C string @a
60 * src; allocate @a *dest in @a pool.
63 svn_cmdline_cstring_from_utf8(const char **dest
,
67 /** Like svn_utf_cstring_from_utf8_fuzzy(), but converts to an
68 * output-encoded C string. */
70 svn_cmdline_cstring_from_utf8_fuzzy(const char *src
,
73 /** Set @a *dest to a UTF-8-encoded C string from input-encoded C
74 * string @a src; allocate @a *dest in @a pool.
77 svn_cmdline_cstring_to_utf8(const char **dest
,
81 /** Set @a *dest to an output-encoded natively-formatted path string
82 * from canonical path @a src; allocate @a *dest in @a pool.
85 svn_cmdline_path_local_style_from_utf8(const char **dest
,
89 /** Write to stdout, using a printf-like format string @a fmt, passed
90 * through apr_pvsprintf(). All string arguments are in UTF-8; the output
91 * is converted to the output encoding. Use @a pool for temporary
97 svn_cmdline_printf(apr_pool_t
*pool
,
100 __attribute__((format(printf
, 2, 3)));
102 /** Write to the stdio @a stream, using a printf-like format string @a fmt,
103 * passed through apr_pvsprintf(). All string arguments are in UTF-8;
104 * the output is converted to the output encoding. Use @a pool for
105 * temporary allocation.
110 svn_cmdline_fprintf(FILE *stream
,
114 __attribute__((format(printf
, 3, 4)));
116 /** Output the @a string to the stdio @a stream, converting from UTF-8
117 * to the output encoding. Use @a pool for temporary allocation.
122 svn_cmdline_fputs(const char *string
,
126 /** Flush output buffers of the stdio @a stream, returning an error if that
127 * fails. This is just a wrapper for the standard fflush() function for
128 * consistent error handling.
133 svn_cmdline_fflush(FILE *stream
);
135 /** Return the name of the output encoding allocated in @a pool, or @c
136 * APR_LOCALE_CHARSET if the output encoding is the same as the locale
142 svn_cmdline_output_encoding(apr_pool_t
*pool
);
144 /** Handle @a error in preparation for immediate exit from a
145 * command-line client. Specifically:
147 * Call svn_handle_error2(@a error, stderr, FALSE, @a prefix), clear
148 * @a error, destroy @a pool iff it is non-NULL, and return EXIT_FAILURE.
153 svn_cmdline_handle_exit_error(svn_error_t
*error
,
157 /** A cancellation function/baton pair, and the path to the configuration
158 * directory. To be passed as the baton argument to the
159 * @c svn_cmdline_*_prompt functions.
163 typedef struct svn_cmdline_prompt_baton2_t
{
164 svn_cancel_func_t cancel_func
;
166 const char *config_dir
;
167 } svn_cmdline_prompt_baton2_t
;
169 /** Like svn_cmdline_prompt_baton2_t, but without the path to the
170 * configuration directory.
173 * @deprecated Provided for backward compatibility with the 1.5 API.
175 typedef struct svn_cmdline_prompt_baton_t
{
176 svn_cancel_func_t cancel_func
;
178 } svn_cmdline_prompt_baton_t
;
180 /** Prompt the user for input, using @a prompt_str for the prompt and
181 * @a baton (which may be @c NULL) for cancellation, and returning the
182 * user's response in @a result, allocated in @a pool.
187 svn_cmdline_prompt_user2(const char **result
,
188 const char *prompt_str
,
189 svn_cmdline_prompt_baton_t
*baton
,
192 /** Similar to svn_cmdline_prompt_user2, but without cancellation
195 * @deprecated Provided for backward compatibility with the 1.4 API.
199 svn_cmdline_prompt_user(const char **result
,
200 const char *prompt_str
,
203 /** An implementation of @c svn_auth_simple_prompt_func_t that prompts
204 * the user for keyboard input on the command line.
208 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton.
211 svn_cmdline_auth_simple_prompt(svn_auth_cred_simple_t
**cred_p
,
214 const char *username
,
215 svn_boolean_t may_save
,
219 /** An implementation of @c svn_auth_username_prompt_func_t that prompts
220 * the user for their username via the command line.
224 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton.
227 svn_cmdline_auth_username_prompt(svn_auth_cred_username_t
**cred_p
,
230 svn_boolean_t may_save
,
234 /** An implementation of @c svn_auth_ssl_server_trust_prompt_func_t that
235 * asks the user if they trust a specific ssl server via the command line.
239 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton.
242 svn_cmdline_auth_ssl_server_trust_prompt
243 (svn_auth_cred_ssl_server_trust_t
**cred_p
,
246 apr_uint32_t failures
,
247 const svn_auth_ssl_server_cert_info_t
*cert_info
,
248 svn_boolean_t may_save
,
252 /** An implementation of @c svn_auth_ssl_client_cert_prompt_func_t that
253 * prompts the user for the filename of their SSL client certificate via
256 * Records absolute path of the SSL client certificate file.
260 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton.
263 svn_cmdline_auth_ssl_client_cert_prompt
264 (svn_auth_cred_ssl_client_cert_t
**cred_p
,
267 svn_boolean_t may_save
,
271 /** An implementation of @c svn_auth_ssl_client_cert_pw_prompt_func_t that
272 * prompts the user for their SSL certificate password via the command line.
276 * Expects a @c svn_cmdline_prompt_baton_t to be passed as @a baton.
279 svn_cmdline_auth_ssl_client_cert_pw_prompt
280 (svn_auth_cred_ssl_client_cert_pw_t
**cred_p
,
283 svn_boolean_t may_save
,
286 /** An implementation of @c svn_auth_plaintext_prompt_func_t that
287 * prompts the user whether storing unencypted passwords to disk is OK.
289 * Expects a @c svn_cmdline_prompt_baton2_t to be passed as @a baton.
294 svn_cmdline_auth_plaintext_prompt(svn_boolean_t
*may_save_plaintext
,
295 const char *realmstring
,
299 /** An implementation of @c svn_auth_plaintext_passphrase_prompt_func_t that
300 * prompts the user whether storing unencypted passphrase to disk is OK.
302 * Expects a @c svn_cmdline_prompt_baton2_t to be passed as @a baton.
307 svn_cmdline_auth_plaintext_passphrase_prompt(svn_boolean_t
*may_save_plaintext
,
308 const char *realmstring
,
313 /** Set @a *ab to an authentication baton allocated from @a pool and
314 * initialized with the standard set of authentication providers used
315 * by the command line client.
317 * @a non_interactive, @a username, @a password, @a config_dir,
318 * @a no_auth_cache, and @a trust_server_cert are the values of the
319 * command line options of the corresponding names.
321 * @a cfg is the @c SVN_CONFIG_CATEGORY_CONFIG configuration, and
322 * @a cancel_func and @a cancel_baton control the cancellation of the
323 * prompting providers that are initialized.
325 * Use @a pool for all allocations.
330 svn_cmdline_create_auth_baton(svn_auth_baton_t
**ab
,
331 svn_boolean_t non_interactive
,
332 const char *username
,
333 const char *password
,
334 const char *config_dir
,
335 svn_boolean_t no_auth_cache
,
336 svn_boolean_t trust_server_cert
,
338 svn_cancel_func_t cancel_func
,
342 /** Similar to svn_cmdline_create_auth_baton(), but with
343 * @a trust_server_cert always set to false.
346 * @deprecated Provided for backward compatibility with the 1.5 API.
347 * Use svn_cmdline_create_auth_baton() instead.
349 * @note This deprecation does not follow the usual pattern of putting
350 * a new number on end of the function's name. Instead, the new
351 * function name is distinguished from the old by a grammatical
352 * improvement: the verb "create" instead of the noun "setup".
356 svn_cmdline_setup_auth_baton(svn_auth_baton_t
**ab
,
357 svn_boolean_t non_interactive
,
358 const char *username
,
359 const char *password
,
360 const char *config_dir
,
361 svn_boolean_t no_auth_cache
,
363 svn_cancel_func_t cancel_func
,
367 /** Wrapper for apr_getopt_init(), which see.
371 * This is a private API for Subversion's own use.
374 svn_cmdline__getopt_init(apr_getopt_t
**os
,
381 #endif /* __cplusplus */
383 #endif /* SVN_CMDLINE_H */