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_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
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif /* __cplusplus */
00038
00039 /** The well-known svn port number. */
00040 #define SVN_RA_SVN_PORT 3690
00041
00042 /** Currently-defined capabilities. */
00043 #define SVN_RA_SVN_CAP_EDIT_PIPELINE "edit-pipeline"
00044
00045 /** A value used to indicate an optional number element in a tuple that was
00046 * not received.
00047 */
00048 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0)
00049
00050 /** A specialized form of @c SVN_ERR to deal with errors which occur in an
00051 * @c svn_ra_svn_command_handler.
00052 *
00053 * An error returned with this macro will be passed back to the other side
00054 * of the connection. Use this macro when performing the requested operation;
00055 * use the regular @c SVN_ERR when performing I/O with the client.
00056 */
00057 #define SVN_CMD_ERR(expr) \
00058 do { \
00059 svn_error_t *svn_err__temp = (expr); \
00060 if (svn_err__temp) \
00061 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \
00062 svn_err__temp, NULL); \
00063 } while (0)
00064
00065 /** an ra_svn connection. */
00066 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t;
00067
00068 /** Command handler, used by @c svn_ra_svn_handle_commands. */
00069 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn,
00070 apr_pool_t *pool,
00071 apr_array_header_t *params,
00072 void *baton);
00073
00074 /** Command table, used by @c svn_ra_svn_handle_commands.
00075 *
00076 * If @c terminate is set, command-handling will cease after command is
00077 * processed.
00078 */
00079 typedef struct svn_ra_svn_cmd_entry_t
00080 {
00081 const char *cmdname;
00082 svn_ra_svn_command_handler handler;
00083 svn_boolean_t terminate;
00084 } svn_ra_svn_cmd_entry_t;
00085
00086 /** Memory representation of an on-the-wire data item. */
00087 typedef struct svn_ra_svn_item_t
00088 {
00089 enum {
00090 SVN_RA_SVN_NUMBER,
00091 SVN_RA_SVN_STRING,
00092 SVN_RA_SVN_WORD,
00093 SVN_RA_SVN_LIST
00094 } kind;
00095 union {
00096 apr_uint64_t number;
00097 svn_string_t *string;
00098 const char *word;
00099
00100 /** Contains @c svn_ra_svn_item_t's. */
00101 apr_array_header_t *list;
00102 } u;
00103 } svn_ra_svn_item_t;
00104
00105 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton);
00106
00107 /** Initialize a connection structure for the given socket or
00108 * input/output files.
00109 *
00110 * Either @c sock or @c in_file/@c out_file must be set, not both.
00111 */
00112 svn_ra_svn_conn_t *svn_ra_svn_create_conn(apr_socket_t *sock,
00113 apr_file_t *in_file,
00114 apr_file_t *out_file,
00115 apr_pool_t *pool);
00116
00117 /** Initialize a connection's capabilities to the ones specified in
00118 * @a list, which contains svn_ra_svn_item_t entries (which should
00119 * be of type SVN_RA_SVN_WORD; a malformed data error will result if
00120 * any are not). */
00121 svn_error_t *svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn,
00122 apr_array_header_t *list);
00123
00124 /** Return @c TRUE if @a conn has the capability @a capability, or
00125 * @c FALSE if it does not. */
00126 svn_boolean_t svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn,
00127 const char *capability);
00128
00129 /** Write a number over the net.
00130 *
00131 * Writes will be buffered until the next read or flush.
00132 */
00133 svn_error_t *svn_ra_svn_write_number(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00134 apr_uint64_t number);
00135
00136 /** Write a string over the net.
00137 *
00138 * Writes will be buffered until the next read or flush.
00139 */
00140 svn_error_t *svn_ra_svn_write_string(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00141 const svn_string_t *str);
00142
00143 /** Write a cstring over the net.
00144 *
00145 * Writes will be buffered until the next read or flush.
00146 */
00147 svn_error_t *svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn,
00148 apr_pool_t *pool, const char *s);
00149
00150 /** Write a word over the net.
00151 *
00152 * Writes will be buffered until the next read or flush.
00153 */
00154 svn_error_t *svn_ra_svn_write_word(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00155 const char *word);
00156
00157 /** Begin a list. Writes will be buffered until the next read or flush. */
00158 svn_error_t *svn_ra_svn_start_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
00159
00160 /** End a list. Writes will be buffered until the next read or flush. */
00161 svn_error_t *svn_ra_svn_end_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
00162
00163 /** Flush the write buffer.
00164 *
00165 * Normally this shouldn't be necessary, since the write buffer is flushed
00166 * when a read is attempted.
00167 */
00168 svn_error_t *svn_ra_svn_flush(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
00169
00170 /** Write a tuple, using a printf-like interface.
00171 *
00172 * The format string @a fmt may contain:
00173 *
00174 *<pre>
00175 * Spec Argument type Item type
00176 * ---- -------------------- ---------
00177 * n apr_uint64_t Number
00178 * r svn_revnum_t Number
00179 * s const svn_string_t * String
00180 * c const char * String
00181 * w const char * Word
00182 * b svn_boolean_t Word ("true" or "false")
00183 * ( Begin tuple
00184 * ) End tuple
00185 * ? Remaining elements optional
00186 * ! (at beginning or end) Suppress opening or closing of tuple
00187 * </pre>
00188 *
00189 * Inside the optional part of a tuple, 'r' values may be @c
00190 * SVN_INVALID_REVNUM, 'n' values may be
00191 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be
00192 * @c NULL; in these cases no data will be written. 'b' and '(' may
00193 * not appear in the optional part of a tuple. Either all or none of
00194 * the optional values should be valid.
00195 *
00196 * (If we ever have a need for an optional boolean value, we should
00197 * invent a 'B' specifier which stores a boolean into an int, using -1
00198 * for unspecified. Right now there is no need for such a thing.)
00199 *
00200 * Use the '!' format specifier to write partial tuples when you have
00201 * to transmit an array or other unusual data. For example, to write
00202 * a tuple containing a revision, an array of words, and a boolean:
00203 * SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev));
00204 * for (i = 0; i < n; i++)
00205 * SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i]));
00206 * SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag));
00207 */
00208 svn_error_t *svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00209 const char *fmt, ...);
00210
00211 /** Read an item from the network into @c item. */
00212 svn_error_t *svn_ra_svn_read_item(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00213 svn_ra_svn_item_t **item);
00214
00215 /** Scan data on @c conn until we find something which looks like the
00216 * beginning of an svn server greeting (an open paren followed by a
00217 * whitespace character). This function is appropriate for beginning
00218 * a client connection opened in tunnel mode, since people's dotfiles
00219 * sometimes write output to stdout. It may only be called at the
00220 * beginning of a client connection.
00221 */
00222 svn_error_t *svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn,
00223 apr_pool_t *pool);
00224
00225 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a
00226 * printf-like interface. The format string @a fmt may contain:
00227 *
00228 *<pre>
00229 * Spec Argument type Item type
00230 * ---- -------------------- ---------
00231 * n apr_uint64_t * Number
00232 * r svn_revnum_t * Number
00233 * s svn_string_t ** String
00234 * c const char ** String
00235 * w const char ** Word
00236 * b svn_boolean_t * Word ("true" or "false")
00237 * l apr_array_header_t ** List
00238 * ( Begin tuple
00239 * ) End tuple
00240 * ? Tuple is allowed to end here
00241 *</pre>
00242 *
00243 * Note that a tuple is only allowed to end precisely at a '?', or at
00244 * the end of the specification. So if @a fmt is "c?cc" and @a list
00245 * contains two elements, an error will result.
00246 *
00247 * If an optional part of a tuple contains no data, 'r' values will be
00248 * set to @c SVN_INVALID_REVNUM, 'n' values will be set to
00249 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values
00250 * will be set to @c NULL. 'b' may not appear inside an optional
00251 * tuple specification.
00252 */
00253 svn_error_t *svn_ra_svn_parse_tuple(apr_array_header_t *list,
00254 apr_pool_t *pool,
00255 const char *fmt, ...);
00256
00257 /** Read a tuple from the network and parse it as a tuple, using the
00258 * format string notation from @c svn_ra_svn_parse_tuple.
00259 */
00260 svn_error_t *svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00261 const char *fmt, ...);
00262
00263 /** Read a command response from the network and parse it as a tuple, using
00264 * the format string notation from @c svn_ra_svn_parse_tuple.
00265 */
00266 svn_error_t *svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn,
00267 apr_pool_t *pool,
00268 const char *fmt, ...);
00269
00270 /** Accept commands over the network and handle them according to @a
00271 * commands. Command handlers will be passed @a conn, a subpool of @a
00272 * pool (cleared after each command is handled), the parameters of the
00273 * command, and @a baton. Commands will be accepted until a
00274 * terminating command is received (a command with "terminate" set in
00275 * the command table). If a command handler returns an error wrapped
00276 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error
00277 * will be reported to the other side of the connection and the
00278 * command loop will continue; any other kind of error (typically a
00279 * network or protocol error) is passed through to the caller.
00280 */
00281 svn_error_t *svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn,
00282 apr_pool_t *pool,
00283 const svn_ra_svn_cmd_entry_t *commands,
00284 void *baton);
00285
00286 /** Write a command over the network, using the same format string notation
00287 * as svn_ra_svn_write_tuple.
00288 */
00289 svn_error_t *svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00290 const char *cmdname, const char *fmt, ...);
00291
00292 /** Write a successful command response over the network, using the
00293 * same format string notation as svn_ra_svn_write_tuple. Do not use
00294 * partial tuples with this function; if you need to use partial
00295 * tuples, just write out the "success" and argument tuple by hand.
00296 */
00297 svn_error_t *svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn,
00298 apr_pool_t *pool,
00299 const char *fmt, ...);
00300
00301 /** Write an unsuccessful command response over the network. */
00302 svn_error_t *svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn,
00303 apr_pool_t *pool, svn_error_t *err);
00304
00305 /** Set @a *editor and @a *edit_baton to an editor which will pass editing
00306 * operations over the network, using @a conn and @a pool.
00307 *
00308 * Upon successful completion of the edit, the editor will invoke @a callback
00309 * with @a callback_baton as an argument.
00310 */
00311 void svn_ra_svn_get_editor(const svn_delta_editor_t **editor,
00312 void **edit_baton, svn_ra_svn_conn_t *conn,
00313 apr_pool_t *pool, svn_ra_svn_edit_callback callback,
00314 void *callback_baton);
00315
00316 /** Receive edit commands over the network and use them to drive @a editor
00317 * with @a edit_baton. On return, @a *aborted will be set if the edit was
00318 * aborted.
00319 */
00320 svn_error_t *svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00321 const svn_delta_editor_t *editor,
00322 void *edit_baton,
00323 svn_boolean_t *aborted);
00324
00325 /** This function is only intended for use by svnserve.
00326 *
00327 * Perform CRAM-MD5 password authentication. On success, return
00328 * SVN_NO_ERROR with *user set to the username and *success set to
00329 * TRUE. On an error which can be reported to the client, report the
00330 * error and return SVN_NO_ERROR with *success set to FALSE. On
00331 * communications failure, return an error.
00332 */
00333 svn_error_t *svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
00334 svn_config_t *pwdb, const char **user,
00335 svn_boolean_t *success);
00336
00337 /**
00338 * Get libsvn_ra_svn version information.
00339 * @since New in 1.1.
00340 */
00341 const svn_version_t *svn_ra_svn_version (void);
00342
00343 #ifdef __cplusplus
00344 }
00345 #endif /* __cplusplus */
00346
00347 #endif /* SVN_RA_SVN_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002