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