svn_cmdline_private.h revision 362181
1/** 2 * @copyright 3 * ==================================================================== 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 * ==================================================================== 21 * @endcopyright 22 * 23 * @file svn_cmdline_private.h 24 * @brief Private functions for Subversion cmdline. 25 */ 26 27#ifndef SVN_CMDLINE_PRIVATE_H 28#define SVN_CMDLINE_PRIVATE_H 29 30#include <apr_pools.h> 31#include <apr_hash.h> 32 33#include "svn_string.h" 34#include "svn_error.h" 35#include "svn_io.h" 36 37#ifdef __cplusplus 38extern "C" { 39#endif /* __cplusplus */ 40 41/** Write a property as an XML element into @a *outstr. 42 * 43 * If @a outstr is NULL, allocate @a *outstr in @a pool; else append to 44 * @a *outstr, allocating in @a outstr's pool 45 * 46 * @a propname is the property name. @a propval is the property value, which 47 * will be encoded if it contains unsafe bytes. 48 * 49 * If @a inherited_prop is TRUE then @a propname is an inherited property, 50 * otherwise @a propname is an explicit property. 51 */ 52void 53svn_cmdline__print_xml_prop(svn_stringbuf_t **outstr, 54 const char *propname, 55 svn_string_t *propval, 56 svn_boolean_t inherited_prop, 57 apr_pool_t *pool); 58 59 60/** An implementation of @c svn_auth_gnome_keyring_unlock_prompt_func_t that 61 * prompts the user for default GNOME Keyring password. 62 * 63 * Expects a @c svn_cmdline_prompt_baton2_t to be passed as @a baton. 64 * 65 * @since New in 1.6. 66 * @deprecated Only used by old libgome-keyring implementation. 67 */ 68svn_error_t * 69svn_cmdline__auth_gnome_keyring_unlock_prompt(char **keyring_password, 70 const char *keyring_name, 71 void *baton, 72 apr_pool_t *pool); 73 74/** Container for config options parsed with svn_cmdline__parse_config_option 75 * 76 * @since New in 1.7. 77 */ 78typedef struct svn_cmdline__config_argument_t 79{ 80 const char *file; 81 const char *section; 82 const char *option; 83 const char *value; 84} svn_cmdline__config_argument_t; 85 86/** Parser for 'FILE:SECTION:OPTION=[VALUE]'-style option arguments. 87 * 88 * Parses @a opt_arg and places its value in @a config_options, an apr array 89 * containing svn_cmdline__config_argument_t* elements, allocating the option 90 * data in @a pool 91 * 92 * [Since 1.9:] If the file, section, or option value is not recognized, 93 * warn to @c stderr, using @a prefix as in svn_handle_warning2(). 94 * 95 * @since New in 1.7. 96 */ 97svn_error_t * 98svn_cmdline__parse_config_option(apr_array_header_t *config_options, 99 const char *opt_arg, 100 const char *prefix, 101 apr_pool_t *pool); 102 103/** Sets the config options in @a config_options, an apr array containing 104 * @c svn_cmdline__config_argument_t* elements, to the configuration in @a cfg, 105 * a hash mapping of <tt>const char *</tt> configuration file names to 106 * @c svn_config_t *'s. Write warnings to stderr. 107 * 108 * Use @a prefix as prefix and @a argument_name in warning messages. 109 * 110 * @since New in 1.7. 111 */ 112svn_error_t * 113svn_cmdline__apply_config_options(apr_hash_t *config, 114 const apr_array_header_t *config_options, 115 const char *prefix, 116 const char *argument_name); 117 118/* Return a string allocated in POOL that is a copy of STR but with each 119 * line prefixed with INDENT. A line is all characters up to the first 120 * CR-LF, LF-CR, CR or LF, or the end of STR if sooner. */ 121const char * 122svn_cmdline__indent_string(const char *str, 123 const char *indent, 124 apr_pool_t *pool); 125 126/* Print to stdout a hash PROP_HASH that maps property names (char *) to 127 property values (svn_string_t *). The names are assumed to be in UTF-8 128 format; the values are either in UTF-8 (the special Subversion props) or 129 plain binary values. 130 131 If OUT is not NULL, then write to it rather than stdout. 132 133 If NAMES_ONLY is true, print just names, else print names and 134 values. */ 135svn_error_t * 136svn_cmdline__print_prop_hash(svn_stream_t *out, 137 apr_hash_t *prop_hash, 138 svn_boolean_t names_only, 139 apr_pool_t *pool); 140 141/* Similar to svn_cmdline__print_prop_hash(), only output xml to *OUTSTR. 142 If INHERITED_PROPS is true, then PROP_HASH contains inherited properties, 143 otherwise PROP_HASH contains explicit properties. If *OUTSTR is NULL, 144 allocate it first from POOL, otherwise append to it. */ 145svn_error_t * 146svn_cmdline__print_xml_prop_hash(svn_stringbuf_t **outstr, 147 apr_hash_t *prop_hash, 148 svn_boolean_t names_only, 149 svn_boolean_t inherited_props, 150 apr_pool_t *pool); 151 152 153/* Search for a text editor command in standard environment variables, 154 and invoke it to edit PATH. Use POOL for all allocations. 155 156 If EDITOR_CMD is not NULL, it is the name of the external editor 157 command to use, overriding anything else that might determine the 158 editor. 159 160 CONFIG is a hash of svn_config_t * items keyed on a configuration 161 category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL. */ 162svn_error_t * 163svn_cmdline__edit_file_externally(const char *path, 164 const char *editor_cmd, 165 apr_hash_t *config, 166 apr_pool_t *pool); 167 168/* Search for a text editor command in standard environment variables, 169 and invoke it to edit CONTENTS (using a temporary file created in 170 directory BASE_DIR). Return the new contents in *EDITED_CONTENTS, 171 or set *EDITED_CONTENTS to NULL if no edit was performed. 172 173 If EDITOR_CMD is not NULL, it is the name of the external editor 174 command to use, overriding anything else that might determine the 175 editor. 176 177 If TMPFILE_LEFT is NULL, the temporary file will be destroyed. 178 Else, the file will be left on disk, and its path returned in 179 *TMPFILE_LEFT. 180 181 CONFIG is a hash of svn_config_t * items keyed on a configuration 182 category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL. 183 184 If AS_TEXT is TRUE, recode CONTENTS and convert to native eol-style before 185 editing and back again afterwards. In this case, ENCODING determines the 186 encoding used during editing. If non-NULL, use the named encoding, else 187 use the system encoding. If AS_TEXT is FALSE, don't do any translation. 188 In that case, ENCODING is ignored. 189 190 Use POOL for all allocations. Use PREFIX as the prefix for the 191 temporary file used by the editor. 192 193 If return error, *EDITED_CONTENTS is not touched. */ 194svn_error_t * 195svn_cmdline__edit_string_externally(svn_string_t **edited_contents, 196 const char **tmpfile_left, 197 const char *editor_cmd, 198 const char *base_dir, 199 const svn_string_t *contents, 200 const char *prefix, 201 apr_hash_t *config, 202 svn_boolean_t as_text, 203 const char *encoding, 204 apr_pool_t *pool); 205 206 207/** Wrapper for apr_getopt_init(), which see. 208 * 209 * @since New in 1.4. 210 */ 211svn_error_t * 212svn_cmdline__getopt_init(apr_getopt_t **os, 213 int argc, 214 const char *argv[], 215 apr_pool_t *pool); 216 217/* */ 218svn_boolean_t 219svn_cmdline__stdin_is_a_terminal(void); 220 221/* */ 222svn_boolean_t 223svn_cmdline__stdout_is_a_terminal(void); 224 225/* */ 226svn_boolean_t 227svn_cmdline__stderr_is_a_terminal(void); 228 229/* Determine whether interactive mode should be enabled, based on whether 230 * the user passed the --non-interactive or --force-interactive options. 231 * If neither option was passed, interactivity is enabled if standard 232 * input is connected to a terminal device. 233 * 234 * @since New in 1.8. 235 */ 236svn_boolean_t 237svn_cmdline__be_interactive(svn_boolean_t non_interactive, 238 svn_boolean_t force_interactive); 239 240/* Parses the argument value of '--trust-server-cert-failures' OPT_ARG into 241 * the expected booleans for passing to svn_cmdline_create_auth_baton2() 242 * 243 * @since New in 1.9. 244 */ 245svn_error_t * 246svn_cmdline__parse_trust_options( 247 svn_boolean_t *trust_server_cert_unknown_ca, 248 svn_boolean_t *trust_server_cert_cn_mismatch, 249 svn_boolean_t *trust_server_cert_expired, 250 svn_boolean_t *trust_server_cert_not_yet_valid, 251 svn_boolean_t *trust_server_cert_other_failure, 252 const char *opt_arg, 253 apr_pool_t *scratch_pool); 254 255/* Setup signal handlers for signals such as SIGINT and return a 256 cancellation handler function. This also sets some other signals 257 to be ignored. */ 258svn_cancel_func_t 259svn_cmdline__setup_cancellation_handler(void); 260 261/* Set the handlers for signals such as SIGINT back to default. */ 262void 263svn_cmdline__disable_cancellation_handler(void); 264 265/* Exit this process with a status that indicates the cancellation 266 signal, or return without exiting if there is no signal. This 267 allows the shell to use WIFSIGNALED and WTERMSIG to detect the 268 signal. See http://www.cons.org/cracauer/sigint.html */ 269void 270svn_cmdline__cancellation_exit(void); 271 272/** Reads a string from stdin until a newline or EOF is found 273 * 274 * @since New in 1.10. 275 */ 276svn_error_t * 277svn_cmdline__stdin_readline(const char **result, 278 apr_pool_t *result_pool, 279 apr_pool_t *scratch_pool); 280 281#ifdef __cplusplus 282} 283#endif /* __cplusplus */ 284 285#endif /* SVN_CMDLINE_PRIVATE_H */ 286