00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2000-2006, 2008 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_ra_svn.h 00019 * @brief libsvn_ra_svn functions used by the server 00020 */ 00021 00022 00023 00024 00025 #ifndef SVN_RA_SVN_H 00026 #define SVN_RA_SVN_H 00027 00028 #include <apr.h> 00029 #include <apr_pools.h> 00030 #include <apr_network_io.h> 00031 #include "svn_config.h" 00032 00033 #include "svn_delta.h" 00034 #include "svn_types.h" 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif /* __cplusplus */ 00039 00040 /** The well-known svn port number. */ 00041 #define SVN_RA_SVN_PORT 3690 00042 00043 /** Currently-defined capabilities. */ 00044 #define SVN_RA_SVN_CAP_EDIT_PIPELINE "edit-pipeline" 00045 #define SVN_RA_SVN_CAP_SVNDIFF1 "svndiff1" 00046 #define SVN_RA_SVN_CAP_ABSENT_ENTRIES "absent-entries" 00047 /* maps to SVN_RA_CAPABILITY_COMMIT_REVPROPS: */ 00048 #define SVN_RA_SVN_CAP_COMMIT_REVPROPS "commit-revprops" 00049 /* maps to SVN_RA_CAPABILITY_MERGEINFO: */ 00050 #define SVN_RA_SVN_CAP_MERGEINFO "mergeinfo" 00051 /* maps to SVN_RA_CAPABILITY_DEPTH: */ 00052 #define SVN_RA_SVN_CAP_DEPTH "depth" 00053 /* maps to SVN_RA_CAPABILITY_LOG_REVPROPS */ 00054 #define SVN_RA_SVN_CAP_LOG_REVPROPS "log-revprops" 00055 /* maps to SVN_RA_CAPABILITY_PARTIAL_REPLAY */ 00056 #define SVN_RA_SVN_CAP_PARTIAL_REPLAY "partial-replay" 00057 00058 /** ra_svn passes @c svn_dirent_t fields over the wire as a list of 00059 * words, these are the values used to represent each field. 00060 * 00061 * @defgroup ra_svn_dirent_fields Definitions of ra_svn dirent fields 00062 * @{ 00063 */ 00064 00065 /** The ra_svn way of saying @c SVN_DIRENT_KIND. */ 00066 #define SVN_RA_SVN_DIRENT_KIND "kind" 00067 00068 /** The ra_svn way of saying @c SVN_DIRENT_SIZE. */ 00069 #define SVN_RA_SVN_DIRENT_SIZE "size" 00070 00071 /** The ra_svn way of saying @c SVN_DIRENT_HAS_PROPS. */ 00072 #define SVN_RA_SVN_DIRENT_HAS_PROPS "has-props" 00073 00074 /** The ra_svn way of saying @c SVN_DIRENT_CREATED_REV. */ 00075 #define SVN_RA_SVN_DIRENT_CREATED_REV "created-rev" 00076 00077 /** The ra_svn way of saying @c SVN_DIRENT_TIME. */ 00078 #define SVN_RA_SVN_DIRENT_TIME "time" 00079 00080 /** The ra_svn way of saying @c SVN_DIRENT_LAST_AUTHOR. */ 00081 #define SVN_RA_SVN_DIRENT_LAST_AUTHOR "last-author" 00082 00083 /** @} */ 00084 00085 /** A value used to indicate an optional number element in a tuple that was 00086 * not received. 00087 */ 00088 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0) 00089 00090 /** A specialized form of @c SVN_ERR to deal with errors which occur in an 00091 * svn_ra_svn_command_handler(). 00092 * 00093 * An error returned with this macro will be passed back to the other side 00094 * of the connection. Use this macro when performing the requested operation; 00095 * use the regular @c SVN_ERR when performing I/O with the client. 00096 */ 00097 #define SVN_CMD_ERR(expr) \ 00098 do { \ 00099 svn_error_t *svn_err__temp = (expr); \ 00100 if (svn_err__temp) \ 00101 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \ 00102 svn_err__temp, NULL); \ 00103 } while (0) 00104 00105 /** an ra_svn connection. */ 00106 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t; 00107 00108 /** Command handler, used by svn_ra_svn_handle_commands(). */ 00109 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn, 00110 apr_pool_t *pool, 00111 apr_array_header_t *params, 00112 void *baton); 00113 00114 /** Command table, used by svn_ra_svn_handle_commands(). 00115 */ 00116 typedef struct svn_ra_svn_cmd_entry_t 00117 { 00118 /** Name of the command */ 00119 const char *cmdname; 00120 00121 /** Handler for the command */ 00122 svn_ra_svn_command_handler handler; 00123 00124 /** Termination flag. If set, command-handling will cease after 00125 * command is processed. */ 00126 svn_boolean_t terminate; 00127 } svn_ra_svn_cmd_entry_t; 00128 00129 /** Memory representation of an on-the-wire data item. */ 00130 typedef struct svn_ra_svn_item_t 00131 { 00132 /** Variant indicator. */ 00133 enum { 00134 SVN_RA_SVN_NUMBER, 00135 SVN_RA_SVN_STRING, 00136 SVN_RA_SVN_WORD, 00137 SVN_RA_SVN_LIST 00138 } kind; 00139 /** Variant data. */ 00140 union { 00141 apr_uint64_t number; 00142 svn_string_t *string; 00143 const char *word; 00144 00145 /** Contains @c svn_ra_svn_item_t's. */ 00146 apr_array_header_t *list; 00147 } u; 00148 } svn_ra_svn_item_t; 00149 00150 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton); 00151 00152 /** Initialize a connection structure for the given socket or 00153 * input/output files. 00154 * 00155 * Either @a sock or @a in_file/@a out_file must be set, not both. 00156 */ 00157 svn_ra_svn_conn_t * 00158 svn_ra_svn_create_conn(apr_socket_t *sock, 00159 apr_file_t *in_file, 00160 apr_file_t *out_file, 00161 apr_pool_t *pool); 00162 00163 /** Add the capabilities in @a list to @a conn's capabilities. 00164 * @a list contains svn_ra_svn_item_t entries (which should be of type 00165 * SVN_RA_SVN_WORD; a malformed data error will result if any are not). 00166 * 00167 * This is idempotent: if a given capability was already set for 00168 * @a conn, it remains set. 00169 */ 00170 svn_error_t * 00171 svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn, 00172 apr_array_header_t *list); 00173 00174 /** Return @c TRUE if @a conn has the capability @a capability, or 00175 * @c FALSE if it does not. */ 00176 svn_boolean_t 00177 svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn, 00178 const char *capability); 00179 00180 /** Returns the remote address of the connection as a string, if known, 00181 * or NULL if inapplicable. */ 00182 const char * 00183 svn_ra_svn_conn_remote_host(svn_ra_svn_conn_t *conn); 00184 00185 /** Write a number over the net. 00186 * 00187 * Writes will be buffered until the next read or flush. 00188 */ 00189 svn_error_t * 00190 svn_ra_svn_write_number(svn_ra_svn_conn_t *conn, 00191 apr_pool_t *pool, 00192 apr_uint64_t number); 00193 00194 /** Write a string over the net. 00195 * 00196 * Writes will be buffered until the next read or flush. 00197 */ 00198 svn_error_t * 00199 svn_ra_svn_write_string(svn_ra_svn_conn_t *conn, 00200 apr_pool_t *pool, 00201 const svn_string_t *str); 00202 00203 /** Write a cstring over the net. 00204 * 00205 * Writes will be buffered until the next read or flush. 00206 */ 00207 svn_error_t * 00208 svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn, 00209 apr_pool_t *pool, 00210 const char *s); 00211 00212 /** Write a word over the net. 00213 * 00214 * Writes will be buffered until the next read or flush. 00215 */ 00216 svn_error_t * 00217 svn_ra_svn_write_word(svn_ra_svn_conn_t *conn, 00218 apr_pool_t *pool, 00219 const char *word); 00220 00221 /** Write a list of properties over the net. @a props is allowed to be NULL, 00222 * in which case an empty list will be written out. 00223 * 00224 * @since New in 1.5. 00225 */ 00226 svn_error_t * 00227 svn_ra_svn_write_proplist(svn_ra_svn_conn_t *conn, 00228 apr_pool_t *pool, 00229 apr_hash_t *props); 00230 00231 /** Begin a list. Writes will be buffered until the next read or flush. */ 00232 svn_error_t * 00233 svn_ra_svn_start_list(svn_ra_svn_conn_t *conn, 00234 apr_pool_t *pool); 00235 00236 /** End a list. Writes will be buffered until the next read or flush. */ 00237 svn_error_t * 00238 svn_ra_svn_end_list(svn_ra_svn_conn_t *conn, 00239 apr_pool_t *pool); 00240 00241 /** Flush the write buffer. 00242 * 00243 * Normally this shouldn't be necessary, since the write buffer is flushed 00244 * when a read is attempted. 00245 */ 00246 svn_error_t * 00247 svn_ra_svn_flush(svn_ra_svn_conn_t *conn, 00248 apr_pool_t *pool); 00249 00250 /** Write a tuple, using a printf-like interface. 00251 * 00252 * The format string @a fmt may contain: 00253 * 00254 *@verbatim 00255 Spec Argument type Item type 00256 ---- -------------------- --------- 00257 n apr_uint64_t Number 00258 r svn_revnum_t Number 00259 s const svn_string_t * String 00260 c const char * String 00261 w const char * Word 00262 b svn_boolean_t Word ("true" or "false") 00263 ( Begin tuple 00264 ) End tuple 00265 ? Remaining elements optional 00266 ! (at beginning or end) Suppress opening or closing of tuple 00267 @endverbatim 00268 * 00269 * Inside the optional part of a tuple, 'r' values may be @c 00270 * SVN_INVALID_REVNUM, 'n' values may be 00271 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be 00272 * @c NULL; in these cases no data will be written. 'b' and '(' may 00273 * not appear in the optional part of a tuple. Either all or none of 00274 * the optional values should be valid. 00275 * 00276 * (If we ever have a need for an optional boolean value, we should 00277 * invent a 'B' specifier which stores a boolean into an int, using -1 00278 * for unspecified. Right now there is no need for such a thing.) 00279 * 00280 * Use the '!' format specifier to write partial tuples when you have 00281 * to transmit an array or other unusual data. For example, to write 00282 * a tuple containing a revision, an array of words, and a boolean: 00283 * @verbatim 00284 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev)); 00285 for (i = 0; i < n; i++) 00286 SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i])); 00287 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag)); @endverbatim 00288 */ 00289 svn_error_t * 00290 svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn, 00291 apr_pool_t *pool, 00292 const char *fmt, ...); 00293 00294 /** Read an item from the network into @a *item. */ 00295 svn_error_t * 00296 svn_ra_svn_read_item(svn_ra_svn_conn_t *conn, 00297 apr_pool_t *pool, 00298 svn_ra_svn_item_t **item); 00299 00300 /** Scan data on @a conn until we find something which looks like the 00301 * beginning of an svn server greeting (an open paren followed by a 00302 * whitespace character). This function is appropriate for beginning 00303 * a client connection opened in tunnel mode, since people's dotfiles 00304 * sometimes write output to stdout. It may only be called at the 00305 * beginning of a client connection. 00306 */ 00307 svn_error_t * 00308 svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn, 00309 apr_pool_t *pool); 00310 00311 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a 00312 * printf-like interface. The format string @a fmt may contain: 00313 * 00314 *@verbatim 00315 Spec Argument type Item type 00316 ---- -------------------- --------- 00317 n apr_uint64_t * Number 00318 r svn_revnum_t * Number 00319 s svn_string_t ** String 00320 c const char ** String 00321 w const char ** Word 00322 b svn_boolean_t * Word ("true" or "false") 00323 B apr_uint64_t * Word ("true" or "false") 00324 l apr_array_header_t ** List 00325 ( Begin tuple 00326 ) End tuple 00327 ? Tuple is allowed to end here 00328 @endverbatim 00329 * 00330 * Note that a tuple is only allowed to end precisely at a '?', or at 00331 * the end of the specification. So if @a fmt is "c?cc" and @a list 00332 * contains two elements, an error will result. 00333 * 00334 * 'B' is similar to 'b', but may be used in the optional tuple specification. 00335 * It returns TRUE, FALSE, or SVN_RA_SVN_UNSPECIFIED_NUMBER. 00336 * 00337 * If an optional part of a tuple contains no data, 'r' values will be 00338 * set to @c SVN_INVALID_REVNUM, 'n' and 'B' values will be set to 00339 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values 00340 * will be set to @c NULL. 'b' may not appear inside an optional 00341 * tuple specification; use 'B' instead. 00342 */ 00343 svn_error_t * 00344 svn_ra_svn_parse_tuple(apr_array_header_t *list, 00345 apr_pool_t *pool, 00346 const char *fmt, ...); 00347 00348 /** Read a tuple from the network and parse it as a tuple, using the 00349 * format string notation from svn_ra_svn_parse_tuple(). 00350 */ 00351 svn_error_t * 00352 svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn, 00353 apr_pool_t *pool, 00354 const char *fmt, ...); 00355 00356 /** Parse an array of @c svn_ra_svn_item_t structures as a list of 00357 * properties, storing the properties in a hash table. 00358 * 00359 * @since New in 1.5. 00360 */ 00361 svn_error_t * 00362 svn_ra_svn_parse_proplist(apr_array_header_t *list, 00363 apr_pool_t *pool, 00364 apr_hash_t **props); 00365 00366 /** Read a command response from the network and parse it as a tuple, using 00367 * the format string notation from svn_ra_svn_parse_tuple(). 00368 */ 00369 svn_error_t * 00370 svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn, 00371 apr_pool_t *pool, 00372 const char *fmt, ...); 00373 00374 /** Accept commands over the network and handle them according to @a 00375 * commands. Command handlers will be passed @a conn, a subpool of @a 00376 * pool (cleared after each command is handled), the parameters of the 00377 * command, and @a baton. Commands will be accepted until a 00378 * terminating command is received (a command with "terminate" set in 00379 * the command table). If a command handler returns an error wrapped 00380 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error 00381 * will be reported to the other side of the connection and the 00382 * command loop will continue; any other kind of error (typically a 00383 * network or protocol error) is passed through to the caller. 00384 * 00385 * @since New in 1.6. 00386 * 00387 */ 00388 svn_error_t * 00389 svn_ra_svn_handle_commands2(svn_ra_svn_conn_t *conn, 00390 apr_pool_t *pool, 00391 const svn_ra_svn_cmd_entry_t *commands, 00392 void *baton, 00393 svn_boolean_t error_on_disconnect); 00394 00395 /** Similar to svn_ra_svn_handle_commands2 but @a error_on_disconnect 00396 * is always @c FALSE. 00397 * 00398 * @deprecated Provided for backward compatibility with the 1.5 API. 00399 */ 00400 SVN_DEPRECATED 00401 svn_error_t * 00402 svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn, 00403 apr_pool_t *pool, 00404 const svn_ra_svn_cmd_entry_t *commands, 00405 void *baton); 00406 00407 /** Write a command over the network, using the same format string notation 00408 * as svn_ra_svn_write_tuple(). 00409 */ 00410 svn_error_t * 00411 svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn, 00412 apr_pool_t *pool, 00413 const char *cmdname, 00414 const char *fmt, ...); 00415 00416 /** Write a successful command response over the network, using the 00417 * same format string notation as svn_ra_svn_write_tuple(). Do not use 00418 * partial tuples with this function; if you need to use partial 00419 * tuples, just write out the "success" and argument tuple by hand. 00420 */ 00421 svn_error_t * 00422 svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn, 00423 apr_pool_t *pool, 00424 const char *fmt, ...); 00425 00426 /** Write an unsuccessful command response over the network. */ 00427 svn_error_t * 00428 svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn, 00429 apr_pool_t *pool, 00430 svn_error_t *err); 00431 00432 /** Set @a *editor and @a *edit_baton to an editor which will pass editing 00433 * operations over the network, using @a conn and @a pool. 00434 * 00435 * Upon successful completion of the edit, the editor will invoke @a callback 00436 * with @a callback_baton as an argument. 00437 */ 00438 void 00439 svn_ra_svn_get_editor(const svn_delta_editor_t **editor, 00440 void **edit_baton, 00441 svn_ra_svn_conn_t *conn, 00442 apr_pool_t *pool, 00443 svn_ra_svn_edit_callback callback, 00444 void *callback_baton); 00445 00446 /** Receive edit commands over the network and use them to drive @a editor 00447 * with @a edit_baton. On return, @a *aborted will be set if the edit was 00448 * aborted. The drive can be terminated with a finish-replay command only 00449 * if @a for_replay is TRUE. 00450 */ 00451 svn_error_t * 00452 svn_ra_svn_drive_editor2(svn_ra_svn_conn_t *conn, 00453 apr_pool_t *pool, 00454 const svn_delta_editor_t *editor, 00455 void *edit_baton, 00456 svn_boolean_t *aborted, 00457 svn_boolean_t for_replay); 00458 00459 /** Like svn_ra_svn_drive_editor2, but with @a for_replay always FALSE. 00460 */ 00461 svn_error_t * 00462 svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn, 00463 apr_pool_t *pool, 00464 const svn_delta_editor_t *editor, 00465 void *edit_baton, 00466 svn_boolean_t *aborted); 00467 00468 /** This function is only intended for use by svnserve. 00469 * 00470 * Perform CRAM-MD5 password authentication. On success, return 00471 * SVN_NO_ERROR with *user set to the username and *success set to 00472 * TRUE. On an error which can be reported to the client, report the 00473 * error and return SVN_NO_ERROR with *success set to FALSE. On 00474 * communications failure, return an error. 00475 */ 00476 svn_error_t * 00477 svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, 00478 apr_pool_t *pool, 00479 svn_config_t *pwdb, 00480 const char **user, 00481 svn_boolean_t *success); 00482 00483 /** 00484 * Get libsvn_ra_svn version information. 00485 * @since New in 1.1. 00486 */ 00487 const svn_version_t * 00488 svn_ra_svn_version(void); 00489 00490 #ifdef __cplusplus 00491 } 00492 #endif /* __cplusplus */ 00493 00494 #endif /* SVN_RA_SVN_H */
1.3.9.1