Change the format of the revprops block sent in svnserve for
[svn.git] / subversion / include / svn_ra_svn.h
bloba6adec0d385348d9241c9a32e1e6957b8ed87f2e
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 #define SVN_RA_SVN_CAP_COMMIT_REVPROPS "commit-revprops"
47 /* maps to SVN_RA_CAPABILITY_MERGEINFO: */
48 #define SVN_RA_SVN_CAP_MERGEINFO "mergeinfo"
49 /* maps to SVN_RA_CAPABILITY_DEPTH: */
50 #define SVN_RA_SVN_CAP_DEPTH "depth"
51 /* maps to SVN_RA_CAPABILITY_LOG_REVPROPS */
52 #define SVN_RA_SVN_CAP_LOG_REVPROPS "log-revprops"
53 /* maps to SVN_RA_CAPABILITY_PARTIAL_REPLAY */
54 #define SVN_RA_SVN_CAP_PARTIAL_REPLAY "partial-replay"
56 /** ra_svn passes @c svn_dirent_t fields over the wire as a list of
57 * words, these are the values used to represent each field.
59 * @defgroup ra_svn_dirent_fields Definitions of ra_svn dirent fields
60 * @{
63 /** The ra_svn way of saying @c SVN_DIRENT_KIND. */
64 #define SVN_RA_SVN_DIRENT_KIND "kind"
66 /** The ra_svn way of saying @c SVN_DIRENT_SIZE. */
67 #define SVN_RA_SVN_DIRENT_SIZE "size"
69 /** The ra_svn way of saying @c SVN_DIRENT_HAS_PROPS. */
70 #define SVN_RA_SVN_DIRENT_HAS_PROPS "has-props"
72 /** The ra_svn way of saying @c SVN_DIRENT_CREATED_REV. */
73 #define SVN_RA_SVN_DIRENT_CREATED_REV "created-rev"
75 /** The ra_svn way of saying @c SVN_DIRENT_TIME. */
76 #define SVN_RA_SVN_DIRENT_TIME "time"
78 /** The ra_svn way of saying @c SVN_DIRENT_LAST_AUTHOR. */
79 #define SVN_RA_SVN_DIRENT_LAST_AUTHOR "last-author"
81 /** @} */
83 /** A value used to indicate an optional number element in a tuple that was
84 * not received.
86 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0)
88 /** A specialized form of @c SVN_ERR to deal with errors which occur in an
89 * svn_ra_svn_command_handler().
91 * An error returned with this macro will be passed back to the other side
92 * of the connection. Use this macro when performing the requested operation;
93 * use the regular @c SVN_ERR when performing I/O with the client.
95 #define SVN_CMD_ERR(expr) \
96 do { \
97 svn_error_t *svn_err__temp = (expr); \
98 if (svn_err__temp) \
99 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \
100 svn_err__temp, NULL); \
101 } while (0)
103 /** an ra_svn connection. */
104 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t;
106 /** Command handler, used by svn_ra_svn_handle_commands(). */
107 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn,
108 apr_pool_t *pool,
109 apr_array_header_t *params,
110 void *baton);
112 /** Command table, used by svn_ra_svn_handle_commands().
114 typedef struct svn_ra_svn_cmd_entry_t
116 /** Name of the command */
117 const char *cmdname;
119 /** Handler for the command */
120 svn_ra_svn_command_handler handler;
122 /** Termination flag. If set, command-handling will cease after
123 * command is processed. */
124 svn_boolean_t terminate;
125 } svn_ra_svn_cmd_entry_t;
127 /** Memory representation of an on-the-wire data item. */
128 typedef struct svn_ra_svn_item_t
130 /** Variant indicator. */
131 enum {
132 SVN_RA_SVN_NUMBER,
133 SVN_RA_SVN_STRING,
134 SVN_RA_SVN_WORD,
135 SVN_RA_SVN_LIST
136 } kind;
137 /** Variant data. */
138 union {
139 apr_uint64_t number;
140 svn_string_t *string;
141 const char *word;
143 /** Contains @c svn_ra_svn_item_t's. */
144 apr_array_header_t *list;
145 } u;
146 } svn_ra_svn_item_t;
148 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton);
150 /** Initialize a connection structure for the given socket or
151 * input/output files.
153 * Either @a sock or @a in_file/@a out_file must be set, not both.
155 svn_ra_svn_conn_t *svn_ra_svn_create_conn(apr_socket_t *sock,
156 apr_file_t *in_file,
157 apr_file_t *out_file,
158 apr_pool_t *pool);
160 /** Add the capabilities in @a list to @a conn's capabilities.
161 * @a list contains svn_ra_svn_item_t entries (which should be of type
162 * SVN_RA_SVN_WORD; a malformed data error will result if any are not).
164 * This is idempotent: if a given capability was already set for
165 * @a conn, it remains set.
167 svn_error_t *svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn,
168 apr_array_header_t *list);
170 /** Return @c TRUE if @a conn has the capability @a capability, or
171 * @c FALSE if it does not. */
172 svn_boolean_t svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn,
173 const char *capability);
175 /** Write a number over the net.
177 * Writes will be buffered until the next read or flush.
179 svn_error_t *svn_ra_svn_write_number(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
180 apr_uint64_t number);
182 /** Write a string over the net.
184 * Writes will be buffered until the next read or flush.
186 svn_error_t *svn_ra_svn_write_string(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
187 const svn_string_t *str);
189 /** Write a cstring over the net.
191 * Writes will be buffered until the next read or flush.
193 svn_error_t *svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn,
194 apr_pool_t *pool, const char *s);
196 /** Write a word over the net.
198 * Writes will be buffered until the next read or flush.
200 svn_error_t *svn_ra_svn_write_word(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
201 const char *word);
203 /** Write a list of properties over the net. @a props is allowed to be NULL,
204 * in which case an empty list will be written out.
206 * @since New in 1.5.
208 svn_error_t *svn_ra_svn_write_proplist(svn_ra_svn_conn_t *conn,
209 apr_pool_t *pool,
210 apr_hash_t *props);
212 /** Begin a list. Writes will be buffered until the next read or flush. */
213 svn_error_t *svn_ra_svn_start_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
215 /** End a list. Writes will be buffered until the next read or flush. */
216 svn_error_t *svn_ra_svn_end_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
218 /** Flush the write buffer.
220 * Normally this shouldn't be necessary, since the write buffer is flushed
221 * when a read is attempted.
223 svn_error_t *svn_ra_svn_flush(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
225 /** Write a tuple, using a printf-like interface.
227 * The format string @a fmt may contain:
229 *@verbatim
230 Spec Argument type Item type
231 ---- -------------------- ---------
232 n apr_uint64_t Number
233 r svn_revnum_t Number
234 s const svn_string_t * String
235 c const char * String
236 w const char * Word
237 b svn_boolean_t Word ("true" or "false")
238 ( Begin tuple
239 ) End tuple
240 ? Remaining elements optional
241 ! (at beginning or end) Suppress opening or closing of tuple
242 @endverbatim
244 * Inside the optional part of a tuple, 'r' values may be @c
245 * SVN_INVALID_REVNUM, 'n' values may be
246 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be
247 * @c NULL; in these cases no data will be written. 'b' and '(' may
248 * not appear in the optional part of a tuple. Either all or none of
249 * the optional values should be valid.
251 * (If we ever have a need for an optional boolean value, we should
252 * invent a 'B' specifier which stores a boolean into an int, using -1
253 * for unspecified. Right now there is no need for such a thing.)
255 * Use the '!' format specifier to write partial tuples when you have
256 * to transmit an array or other unusual data. For example, to write
257 * a tuple containing a revision, an array of words, and a boolean:
258 * @verbatim
259 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev));
260 for (i = 0; i < n; i++)
261 SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i]));
262 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag)); @endverbatim
264 svn_error_t *svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
265 const char *fmt, ...);
267 /** Read an item from the network into @a *item. */
268 svn_error_t *svn_ra_svn_read_item(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
269 svn_ra_svn_item_t **item);
271 /** Scan data on @a conn until we find something which looks like the
272 * beginning of an svn server greeting (an open paren followed by a
273 * whitespace character). This function is appropriate for beginning
274 * a client connection opened in tunnel mode, since people's dotfiles
275 * sometimes write output to stdout. It may only be called at the
276 * beginning of a client connection.
278 svn_error_t *svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn,
279 apr_pool_t *pool);
281 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a
282 * printf-like interface. The format string @a fmt may contain:
284 *@verbatim
285 Spec Argument type Item type
286 ---- -------------------- ---------
287 n apr_uint64_t * Number
288 r svn_revnum_t * Number
289 s svn_string_t ** String
290 c const char ** String
291 w const char ** Word
292 b svn_boolean_t * Word ("true" or "false")
293 B apr_uint64_t * Word ("true" or "false")
294 l apr_array_header_t ** List
295 ( Begin tuple
296 ) End tuple
297 ? Tuple is allowed to end here
298 @endverbatim
300 * Note that a tuple is only allowed to end precisely at a '?', or at
301 * the end of the specification. So if @a fmt is "c?cc" and @a list
302 * contains two elements, an error will result.
304 * 'B' is similar to 'b', but may be used in the optional tuple specification.
305 * It returns TRUE, FALSE, or SVN_RA_SVN_UNSPECIFIED_NUMBER.
307 * If an optional part of a tuple contains no data, 'r' values will be
308 * set to @c SVN_INVALID_REVNUM, 'n' and 'B' values will be set to
309 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values
310 * will be set to @c NULL. 'b' may not appear inside an optional
311 * tuple specification; use 'B' instead.
313 svn_error_t *svn_ra_svn_parse_tuple(apr_array_header_t *list,
314 apr_pool_t *pool,
315 const char *fmt, ...);
317 /** Read a tuple from the network and parse it as a tuple, using the
318 * format string notation from svn_ra_svn_parse_tuple().
320 svn_error_t *svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
321 const char *fmt, ...);
323 /** Parse an array of @c svn_ra_svn_item_t structures as a list of
324 * properties, storing the properties in a hash table.
326 * @since New in 1.5.
328 svn_error_t *svn_ra_svn_parse_proplist(apr_array_header_t *list,
329 apr_pool_t *pool,
330 apr_hash_t **props);
332 /** Read a command response from the network and parse it as a tuple, using
333 * the format string notation from svn_ra_svn_parse_tuple().
335 svn_error_t *svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn,
336 apr_pool_t *pool,
337 const char *fmt, ...);
339 /** Accept commands over the network and handle them according to @a
340 * commands. Command handlers will be passed @a conn, a subpool of @a
341 * pool (cleared after each command is handled), the parameters of the
342 * command, and @a baton. Commands will be accepted until a
343 * terminating command is received (a command with "terminate" set in
344 * the command table). If a command handler returns an error wrapped
345 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error
346 * will be reported to the other side of the connection and the
347 * command loop will continue; any other kind of error (typically a
348 * network or protocol error) is passed through to the caller.
350 svn_error_t *svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn,
351 apr_pool_t *pool,
352 const svn_ra_svn_cmd_entry_t *commands,
353 void *baton);
355 /** Write a command over the network, using the same format string notation
356 * as svn_ra_svn_write_tuple().
358 svn_error_t *svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
359 const char *cmdname, const char *fmt, ...);
361 /** Write a successful command response over the network, using the
362 * same format string notation as svn_ra_svn_write_tuple(). Do not use
363 * partial tuples with this function; if you need to use partial
364 * tuples, just write out the "success" and argument tuple by hand.
366 svn_error_t *svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn,
367 apr_pool_t *pool,
368 const char *fmt, ...);
370 /** Write an unsuccessful command response over the network. */
371 svn_error_t *svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn,
372 apr_pool_t *pool, svn_error_t *err);
374 /** Set @a *editor and @a *edit_baton to an editor which will pass editing
375 * operations over the network, using @a conn and @a pool.
377 * Upon successful completion of the edit, the editor will invoke @a callback
378 * with @a callback_baton as an argument.
380 void svn_ra_svn_get_editor(const svn_delta_editor_t **editor,
381 void **edit_baton, svn_ra_svn_conn_t *conn,
382 apr_pool_t *pool, svn_ra_svn_edit_callback callback,
383 void *callback_baton);
385 /** Receive edit commands over the network and use them to drive @a editor
386 * with @a edit_baton. On return, @a *aborted will be set if the edit was
387 * aborted. The drive can be terminated with a finish-replay command only
388 * if @a for_replay is TRUE.
390 svn_error_t *svn_ra_svn_drive_editor2(svn_ra_svn_conn_t *conn,
391 apr_pool_t *pool,
392 const svn_delta_editor_t *editor,
393 void *edit_baton,
394 svn_boolean_t *aborted,
395 svn_boolean_t for_replay);
397 /** Like svn_ra_svn_drive_editor2, but with @a for_replay always FALSE.
399 svn_error_t *svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
400 const svn_delta_editor_t *editor,
401 void *edit_baton,
402 svn_boolean_t *aborted);
404 /** This function is only intended for use by svnserve.
406 * Perform CRAM-MD5 password authentication. On success, return
407 * SVN_NO_ERROR with *user set to the username and *success set to
408 * TRUE. On an error which can be reported to the client, report the
409 * error and return SVN_NO_ERROR with *success set to FALSE. On
410 * communications failure, return an error.
412 svn_error_t *svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
413 svn_config_t *pwdb, const char **user,
414 svn_boolean_t *success);
417 * Get libsvn_ra_svn version information.
418 * @since New in 1.1.
420 const svn_version_t *svn_ra_svn_version(void);
422 #ifdef __cplusplus
424 #endif /* __cplusplus */
426 #endif /* SVN_RA_SVN_H */