Fix compiler warning due to missing function prototype.
[svn.git] / subversion / include / svn_ra_svn.h
blob8f65aad05b45c8306a8e1b7a4185e999345996a8
1 /**
2 * @copyright
3 * ====================================================================
4 * Copyright (c) 2000-2006 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 * ====================================================================
16 * @endcopyright
18 * @file svn_ra_svn.h
19 * @brief libsvn_ra_svn functions used by the server
25 #ifndef SVN_RA_SVN_H
26 #define SVN_RA_SVN_H
28 #include <apr.h>
29 #include <apr_pools.h>
30 #include <apr_network_io.h>
31 #include "svn_config.h"
33 #include "svn_delta.h"
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
39 /** The well-known svn port number. */
40 #define SVN_RA_SVN_PORT 3690
42 /** Currently-defined capabilities. */
43 #define SVN_RA_SVN_CAP_EDIT_PIPELINE "edit-pipeline"
44 #define SVN_RA_SVN_CAP_SVNDIFF1 "svndiff1"
45 #define SVN_RA_SVN_CAP_ABSENT_ENTRIES "absent-entries"
46 /* maps to SVN_RA_CAPABILITY_COMMIT_REVPROPS: */
47 #define SVN_RA_SVN_CAP_COMMIT_REVPROPS "commit-revprops"
48 /* maps to SVN_RA_CAPABILITY_MERGEINFO: */
49 #define SVN_RA_SVN_CAP_MERGEINFO "mergeinfo"
50 /* maps to SVN_RA_CAPABILITY_DEPTH: */
51 #define SVN_RA_SVN_CAP_DEPTH "depth"
52 /* maps to SVN_RA_CAPABILITY_LOG_REVPROPS */
53 #define SVN_RA_SVN_CAP_LOG_REVPROPS "log-revprops"
54 /* maps to SVN_RA_CAPABILITY_PARTIAL_REPLAY */
55 #define SVN_RA_SVN_CAP_PARTIAL_REPLAY "partial-replay"
57 /** ra_svn passes @c svn_dirent_t fields over the wire as a list of
58 * words, these are the values used to represent each field.
60 * @defgroup ra_svn_dirent_fields Definitions of ra_svn dirent fields
61 * @{
64 /** The ra_svn way of saying @c SVN_DIRENT_KIND. */
65 #define SVN_RA_SVN_DIRENT_KIND "kind"
67 /** The ra_svn way of saying @c SVN_DIRENT_SIZE. */
68 #define SVN_RA_SVN_DIRENT_SIZE "size"
70 /** The ra_svn way of saying @c SVN_DIRENT_HAS_PROPS. */
71 #define SVN_RA_SVN_DIRENT_HAS_PROPS "has-props"
73 /** The ra_svn way of saying @c SVN_DIRENT_CREATED_REV. */
74 #define SVN_RA_SVN_DIRENT_CREATED_REV "created-rev"
76 /** The ra_svn way of saying @c SVN_DIRENT_TIME. */
77 #define SVN_RA_SVN_DIRENT_TIME "time"
79 /** The ra_svn way of saying @c SVN_DIRENT_LAST_AUTHOR. */
80 #define SVN_RA_SVN_DIRENT_LAST_AUTHOR "last-author"
82 /** @} */
84 /** A value used to indicate an optional number element in a tuple that was
85 * not received.
87 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0)
89 /** A specialized form of @c SVN_ERR to deal with errors which occur in an
90 * svn_ra_svn_command_handler().
92 * An error returned with this macro will be passed back to the other side
93 * of the connection. Use this macro when performing the requested operation;
94 * use the regular @c SVN_ERR when performing I/O with the client.
96 #define SVN_CMD_ERR(expr) \
97 do { \
98 svn_error_t *svn_err__temp = (expr); \
99 if (svn_err__temp) \
100 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \
101 svn_err__temp, NULL); \
102 } while (0)
104 /** an ra_svn connection. */
105 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t;
107 /** Command handler, used by svn_ra_svn_handle_commands(). */
108 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn,
109 apr_pool_t *pool,
110 apr_array_header_t *params,
111 void *baton);
113 /** Command table, used by svn_ra_svn_handle_commands().
115 typedef struct svn_ra_svn_cmd_entry_t
117 /** Name of the command */
118 const char *cmdname;
120 /** Handler for the command */
121 svn_ra_svn_command_handler handler;
123 /** Termination flag. If set, command-handling will cease after
124 * command is processed. */
125 svn_boolean_t terminate;
126 } svn_ra_svn_cmd_entry_t;
128 /** Memory representation of an on-the-wire data item. */
129 typedef struct svn_ra_svn_item_t
131 /** Variant indicator. */
132 enum {
133 SVN_RA_SVN_NUMBER,
134 SVN_RA_SVN_STRING,
135 SVN_RA_SVN_WORD,
136 SVN_RA_SVN_LIST
137 } kind;
138 /** Variant data. */
139 union {
140 apr_uint64_t number;
141 svn_string_t *string;
142 const char *word;
144 /** Contains @c svn_ra_svn_item_t's. */
145 apr_array_header_t *list;
146 } u;
147 } svn_ra_svn_item_t;
149 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton);
151 /** Initialize a connection structure for the given socket or
152 * input/output files.
154 * Either @a sock or @a in_file/@a out_file must be set, not both.
156 svn_ra_svn_conn_t *svn_ra_svn_create_conn(apr_socket_t *sock,
157 apr_file_t *in_file,
158 apr_file_t *out_file,
159 apr_pool_t *pool);
161 /** Add the capabilities in @a list to @a conn's capabilities.
162 * @a list contains svn_ra_svn_item_t entries (which should be of type
163 * SVN_RA_SVN_WORD; a malformed data error will result if any are not).
165 * This is idempotent: if a given capability was already set for
166 * @a conn, it remains set.
168 svn_error_t *svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn,
169 apr_array_header_t *list);
171 /** Return @c TRUE if @a conn has the capability @a capability, or
172 * @c FALSE if it does not. */
173 svn_boolean_t svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn,
174 const char *capability);
176 /** Returns the remote address of the connection as a string, if known,
177 * or NULL if inapplicable. */
178 const char *svn_ra_svn_conn_remote_host(svn_ra_svn_conn_t *conn);
180 /** Write a number over the net.
182 * Writes will be buffered until the next read or flush.
184 svn_error_t *svn_ra_svn_write_number(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
185 apr_uint64_t number);
187 /** Write a string over the net.
189 * Writes will be buffered until the next read or flush.
191 svn_error_t *svn_ra_svn_write_string(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
192 const svn_string_t *str);
194 /** Write a cstring over the net.
196 * Writes will be buffered until the next read or flush.
198 svn_error_t *svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn,
199 apr_pool_t *pool, const char *s);
201 /** Write a word over the net.
203 * Writes will be buffered until the next read or flush.
205 svn_error_t *svn_ra_svn_write_word(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
206 const char *word);
208 /** Write a list of properties over the net. @a props is allowed to be NULL,
209 * in which case an empty list will be written out.
211 * @since New in 1.5.
213 svn_error_t *svn_ra_svn_write_proplist(svn_ra_svn_conn_t *conn,
214 apr_pool_t *pool,
215 apr_hash_t *props);
217 /** Begin a list. Writes will be buffered until the next read or flush. */
218 svn_error_t *svn_ra_svn_start_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
220 /** End a list. Writes will be buffered until the next read or flush. */
221 svn_error_t *svn_ra_svn_end_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
223 /** Flush the write buffer.
225 * Normally this shouldn't be necessary, since the write buffer is flushed
226 * when a read is attempted.
228 svn_error_t *svn_ra_svn_flush(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
230 /** Write a tuple, using a printf-like interface.
232 * The format string @a fmt may contain:
234 *@verbatim
235 Spec Argument type Item type
236 ---- -------------------- ---------
237 n apr_uint64_t Number
238 r svn_revnum_t Number
239 s const svn_string_t * String
240 c const char * String
241 w const char * Word
242 b svn_boolean_t Word ("true" or "false")
243 ( Begin tuple
244 ) End tuple
245 ? Remaining elements optional
246 ! (at beginning or end) Suppress opening or closing of tuple
247 @endverbatim
249 * Inside the optional part of a tuple, 'r' values may be @c
250 * SVN_INVALID_REVNUM, 'n' values may be
251 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be
252 * @c NULL; in these cases no data will be written. 'b' and '(' may
253 * not appear in the optional part of a tuple. Either all or none of
254 * the optional values should be valid.
256 * (If we ever have a need for an optional boolean value, we should
257 * invent a 'B' specifier which stores a boolean into an int, using -1
258 * for unspecified. Right now there is no need for such a thing.)
260 * Use the '!' format specifier to write partial tuples when you have
261 * to transmit an array or other unusual data. For example, to write
262 * a tuple containing a revision, an array of words, and a boolean:
263 * @verbatim
264 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev));
265 for (i = 0; i < n; i++)
266 SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i]));
267 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag)); @endverbatim
269 svn_error_t *svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
270 const char *fmt, ...);
272 /** Read an item from the network into @a *item. */
273 svn_error_t *svn_ra_svn_read_item(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
274 svn_ra_svn_item_t **item);
276 /** Scan data on @a conn until we find something which looks like the
277 * beginning of an svn server greeting (an open paren followed by a
278 * whitespace character). This function is appropriate for beginning
279 * a client connection opened in tunnel mode, since people's dotfiles
280 * sometimes write output to stdout. It may only be called at the
281 * beginning of a client connection.
283 svn_error_t *svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn,
284 apr_pool_t *pool);
286 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a
287 * printf-like interface. The format string @a fmt may contain:
289 *@verbatim
290 Spec Argument type Item type
291 ---- -------------------- ---------
292 n apr_uint64_t * Number
293 r svn_revnum_t * Number
294 s svn_string_t ** String
295 c const char ** String
296 w const char ** Word
297 b svn_boolean_t * Word ("true" or "false")
298 B apr_uint64_t * Word ("true" or "false")
299 l apr_array_header_t ** List
300 ( Begin tuple
301 ) End tuple
302 ? Tuple is allowed to end here
303 @endverbatim
305 * Note that a tuple is only allowed to end precisely at a '?', or at
306 * the end of the specification. So if @a fmt is "c?cc" and @a list
307 * contains two elements, an error will result.
309 * 'B' is similar to 'b', but may be used in the optional tuple specification.
310 * It returns TRUE, FALSE, or SVN_RA_SVN_UNSPECIFIED_NUMBER.
312 * If an optional part of a tuple contains no data, 'r' values will be
313 * set to @c SVN_INVALID_REVNUM, 'n' and 'B' values will be set to
314 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values
315 * will be set to @c NULL. 'b' may not appear inside an optional
316 * tuple specification; use 'B' instead.
318 svn_error_t *svn_ra_svn_parse_tuple(apr_array_header_t *list,
319 apr_pool_t *pool,
320 const char *fmt, ...);
322 /** Read a tuple from the network and parse it as a tuple, using the
323 * format string notation from svn_ra_svn_parse_tuple().
325 svn_error_t *svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
326 const char *fmt, ...);
328 /** Parse an array of @c svn_ra_svn_item_t structures as a list of
329 * properties, storing the properties in a hash table.
331 * @since New in 1.5.
333 svn_error_t *svn_ra_svn_parse_proplist(apr_array_header_t *list,
334 apr_pool_t *pool,
335 apr_hash_t **props);
337 /** Read a command response from the network and parse it as a tuple, using
338 * the format string notation from svn_ra_svn_parse_tuple().
340 svn_error_t *svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn,
341 apr_pool_t *pool,
342 const char *fmt, ...);
344 /** Accept commands over the network and handle them according to @a
345 * commands. Command handlers will be passed @a conn, a subpool of @a
346 * pool (cleared after each command is handled), the parameters of the
347 * command, and @a baton. Commands will be accepted until a
348 * terminating command is received (a command with "terminate" set in
349 * the command table). If a command handler returns an error wrapped
350 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error
351 * will be reported to the other side of the connection and the
352 * command loop will continue; any other kind of error (typically a
353 * network or protocol error) is passed through to the caller.
355 * @since New in 1.6.
358 svn_error_t *svn_ra_svn_handle_commands2(svn_ra_svn_conn_t *conn,
359 apr_pool_t *pool,
360 const svn_ra_svn_cmd_entry_t *commands,
361 void *baton,
362 svn_boolean_t error_on_disconnect);
364 /** Similar to svn_ra_svn_handle_commands2 but @a error_on_disconnect
365 * is always @c FALSE.
367 * @deprecated Provided for backward compatibility with the 1.5 API.
369 svn_error_t *svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn,
370 apr_pool_t *pool,
371 const svn_ra_svn_cmd_entry_t *commands,
372 void *baton);
374 /** Write a command over the network, using the same format string notation
375 * as svn_ra_svn_write_tuple().
377 svn_error_t *svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
378 const char *cmdname, const char *fmt, ...);
380 /** Write a successful command response over the network, using the
381 * same format string notation as svn_ra_svn_write_tuple(). Do not use
382 * partial tuples with this function; if you need to use partial
383 * tuples, just write out the "success" and argument tuple by hand.
385 svn_error_t *svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn,
386 apr_pool_t *pool,
387 const char *fmt, ...);
389 /** Write an unsuccessful command response over the network. */
390 svn_error_t *svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn,
391 apr_pool_t *pool, svn_error_t *err);
393 /** Set @a *editor and @a *edit_baton to an editor which will pass editing
394 * operations over the network, using @a conn and @a pool.
396 * Upon successful completion of the edit, the editor will invoke @a callback
397 * with @a callback_baton as an argument.
399 void svn_ra_svn_get_editor(const svn_delta_editor_t **editor,
400 void **edit_baton, svn_ra_svn_conn_t *conn,
401 apr_pool_t *pool, svn_ra_svn_edit_callback callback,
402 void *callback_baton);
404 /** Receive edit commands over the network and use them to drive @a editor
405 * with @a edit_baton. On return, @a *aborted will be set if the edit was
406 * aborted. The drive can be terminated with a finish-replay command only
407 * if @a for_replay is TRUE.
409 svn_error_t *svn_ra_svn_drive_editor2(svn_ra_svn_conn_t *conn,
410 apr_pool_t *pool,
411 const svn_delta_editor_t *editor,
412 void *edit_baton,
413 svn_boolean_t *aborted,
414 svn_boolean_t for_replay);
416 /** Like svn_ra_svn_drive_editor2, but with @a for_replay always FALSE.
418 svn_error_t *svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
419 const svn_delta_editor_t *editor,
420 void *edit_baton,
421 svn_boolean_t *aborted);
423 /** This function is only intended for use by svnserve.
425 * Perform CRAM-MD5 password authentication. On success, return
426 * SVN_NO_ERROR with *user set to the username and *success set to
427 * TRUE. On an error which can be reported to the client, report the
428 * error and return SVN_NO_ERROR with *success set to FALSE. On
429 * communications failure, return an error.
431 svn_error_t *svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
432 svn_config_t *pwdb, const char **user,
433 svn_boolean_t *success);
436 * Get libsvn_ra_svn version information.
437 * @since New in 1.1.
439 const svn_version_t *svn_ra_svn_version(void);
441 #ifdef __cplusplus
443 #endif /* __cplusplus */
445 #endif /* SVN_RA_SVN_H */