3 * ====================================================================
\r
4 * Copyright (c) 2000-2006, 2008 CollabNet. All rights reserved.
\r
6 * This software is licensed as described in the file COPYING, which
\r
7 * you should have received as part of this distribution. The terms
\r
8 * are also available at http://subversion.tigris.org/license-1.html.
\r
9 * If newer versions of this license are posted there, you may use a
\r
10 * newer version instead, at your option.
\r
12 * This software consists of voluntary contributions made by many
\r
13 * individuals. For exact contribution history, see the revision
\r
14 * history and logs, available at http://subversion.tigris.org/.
\r
15 * ====================================================================
\r
18 * @file svn_ra_svn.h
\r
19 * @brief libsvn_ra_svn functions used by the server
\r
22 #ifndef SVN_RA_SVN_H
\r
23 #define SVN_RA_SVN_H
\r
26 #include <apr_pools.h>
\r
27 #include <apr_hash.h>
\r
28 #include <apr_tables.h>
\r
29 #include <apr_file_io.h> /* for apr_file_t */
\r
30 #include <apr_network_io.h> /* for apr_socket_t */
\r
32 #include "svn_types.h"
\r
33 #include "svn_string.h"
\r
34 #include "svn_config.h"
\r
35 #include "svn_delta.h"
\r
39 #endif /* __cplusplus */
\r
41 /** The well-known svn port number. */
\r
42 #define SVN_RA_SVN_PORT 3690
\r
44 /** Currently-defined capabilities. */
\r
45 #define SVN_RA_SVN_CAP_EDIT_PIPELINE "edit-pipeline"
\r
46 #define SVN_RA_SVN_CAP_SVNDIFF1 "svndiff1"
\r
47 #define SVN_RA_SVN_CAP_ABSENT_ENTRIES "absent-entries"
\r
48 /* maps to SVN_RA_CAPABILITY_COMMIT_REVPROPS: */
\r
49 #define SVN_RA_SVN_CAP_COMMIT_REVPROPS "commit-revprops"
\r
50 /* maps to SVN_RA_CAPABILITY_MERGEINFO: */
\r
51 #define SVN_RA_SVN_CAP_MERGEINFO "mergeinfo"
\r
52 /* maps to SVN_RA_CAPABILITY_DEPTH: */
\r
53 #define SVN_RA_SVN_CAP_DEPTH "depth"
\r
54 /* maps to SVN_RA_CAPABILITY_LOG_REVPROPS */
\r
55 #define SVN_RA_SVN_CAP_LOG_REVPROPS "log-revprops"
\r
56 /* maps to SVN_RA_CAPABILITY_PARTIAL_REPLAY */
\r
57 #define SVN_RA_SVN_CAP_PARTIAL_REPLAY "partial-replay"
\r
59 /** ra_svn passes @c svn_dirent_t fields over the wire as a list of
\r
60 * words, these are the values used to represent each field.
\r
62 * @defgroup ra_svn_dirent_fields Definitions of ra_svn dirent fields
\r
66 /** The ra_svn way of saying @c SVN_DIRENT_KIND. */
\r
67 #define SVN_RA_SVN_DIRENT_KIND "kind"
\r
69 /** The ra_svn way of saying @c SVN_DIRENT_SIZE. */
\r
70 #define SVN_RA_SVN_DIRENT_SIZE "size"
\r
72 /** The ra_svn way of saying @c SVN_DIRENT_HAS_PROPS. */
\r
73 #define SVN_RA_SVN_DIRENT_HAS_PROPS "has-props"
\r
75 /** The ra_svn way of saying @c SVN_DIRENT_CREATED_REV. */
\r
76 #define SVN_RA_SVN_DIRENT_CREATED_REV "created-rev"
\r
78 /** The ra_svn way of saying @c SVN_DIRENT_TIME. */
\r
79 #define SVN_RA_SVN_DIRENT_TIME "time"
\r
81 /** The ra_svn way of saying @c SVN_DIRENT_LAST_AUTHOR. */
\r
82 #define SVN_RA_SVN_DIRENT_LAST_AUTHOR "last-author"
\r
86 /** A value used to indicate an optional number element in a tuple that was
\r
89 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0)
\r
91 /** A specialized form of @c SVN_ERR to deal with errors which occur in an
\r
92 * svn_ra_svn_command_handler().
\r
94 * An error returned with this macro will be passed back to the other side
\r
95 * of the connection. Use this macro when performing the requested operation;
\r
96 * use the regular @c SVN_ERR when performing I/O with the client.
\r
98 #define SVN_CMD_ERR(expr) \
\r
100 svn_error_t *svn_err__temp = (expr); \
\r
101 if (svn_err__temp) \
\r
102 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \
\r
103 svn_err__temp, NULL); \
\r
106 /** an ra_svn connection. */
\r
107 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t;
\r
109 /** Command handler, used by svn_ra_svn_handle_commands(). */
\r
110 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn,
\r
112 apr_array_header_t *params,
\r
115 /** Command table, used by svn_ra_svn_handle_commands().
\r
117 typedef struct svn_ra_svn_cmd_entry_t
\r
119 /** Name of the command */
\r
120 const char *cmdname;
\r
122 /** Handler for the command */
\r
123 svn_ra_svn_command_handler handler;
\r
125 /** Termination flag. If set, command-handling will cease after
\r
126 * command is processed. */
\r
127 svn_boolean_t terminate;
\r
128 } svn_ra_svn_cmd_entry_t;
\r
130 /** Memory representation of an on-the-wire data item. */
\r
131 typedef struct svn_ra_svn_item_t
\r
133 /** Variant indicator. */
\r
140 /** Variant data. */
\r
142 apr_uint64_t number;
\r
143 svn_string_t *string;
\r
146 /** Contains @c svn_ra_svn_item_t's. */
\r
147 apr_array_header_t *list;
\r
149 } svn_ra_svn_item_t;
\r
151 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton);
\r
153 /** Initialize a connection structure for the given socket or
\r
154 * input/output files.
\r
156 * Either @a sock or @a in_file/@a out_file must be set, not both.
\r
158 svn_ra_svn_conn_t *
\r
159 svn_ra_svn_create_conn(apr_socket_t *sock,
\r
160 apr_file_t *in_file,
\r
161 apr_file_t *out_file,
\r
164 /** Add the capabilities in @a list to @a conn's capabilities.
\r
165 * @a list contains svn_ra_svn_item_t entries (which should be of type
\r
166 * SVN_RA_SVN_WORD; a malformed data error will result if any are not).
\r
168 * This is idempotent: if a given capability was already set for
\r
169 * @a conn, it remains set.
\r
172 svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn,
\r
173 apr_array_header_t *list);
\r
175 /** Return @c TRUE if @a conn has the capability @a capability, or
\r
176 * @c FALSE if it does not. */
\r
178 svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn,
\r
179 const char *capability);
\r
181 /** Returns the remote address of the connection as a string, if known,
\r
182 * or NULL if inapplicable. */
\r
184 svn_ra_svn_conn_remote_host(svn_ra_svn_conn_t *conn);
\r
186 /** Write a number over the net.
\r
188 * Writes will be buffered until the next read or flush.
\r
191 svn_ra_svn_write_number(svn_ra_svn_conn_t *conn,
\r
193 apr_uint64_t number);
\r
195 /** Write a string over the net.
\r
197 * Writes will be buffered until the next read or flush.
\r
200 svn_ra_svn_write_string(svn_ra_svn_conn_t *conn,
\r
202 const svn_string_t *str);
\r
204 /** Write a cstring over the net.
\r
206 * Writes will be buffered until the next read or flush.
\r
209 svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn,
\r
213 /** Write a word over the net.
\r
215 * Writes will be buffered until the next read or flush.
\r
218 svn_ra_svn_write_word(svn_ra_svn_conn_t *conn,
\r
222 /** Write a list of properties over the net. @a props is allowed to be NULL,
\r
223 * in which case an empty list will be written out.
\r
225 * @since New in 1.5.
\r
228 svn_ra_svn_write_proplist(svn_ra_svn_conn_t *conn,
\r
230 apr_hash_t *props);
\r
232 /** Begin a list. Writes will be buffered until the next read or flush. */
\r
234 svn_ra_svn_start_list(svn_ra_svn_conn_t *conn,
\r
237 /** End a list. Writes will be buffered until the next read or flush. */
\r
239 svn_ra_svn_end_list(svn_ra_svn_conn_t *conn,
\r
242 /** Flush the write buffer.
\r
244 * Normally this shouldn't be necessary, since the write buffer is flushed
\r
245 * when a read is attempted.
\r
248 svn_ra_svn_flush(svn_ra_svn_conn_t *conn,
\r
251 /** Write a tuple, using a printf-like interface.
\r
253 * The format string @a fmt may contain:
\r
256 Spec Argument type Item type
\r
257 ---- -------------------- ---------
\r
258 n apr_uint64_t Number
\r
259 r svn_revnum_t Number
\r
260 s const svn_string_t * String
\r
261 c const char * String
\r
262 w const char * Word
\r
263 b svn_boolean_t Word ("true" or "false")
\r
266 ? Remaining elements optional
\r
267 ! (at beginning or end) Suppress opening or closing of tuple
\r
270 * Inside the optional part of a tuple, 'r' values may be @c
\r
271 * SVN_INVALID_REVNUM, 'n' values may be
\r
272 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be
\r
273 * @c NULL; in these cases no data will be written. 'b' and '(' may
\r
274 * not appear in the optional part of a tuple. Either all or none of
\r
275 * the optional values should be valid.
\r
277 * (If we ever have a need for an optional boolean value, we should
\r
278 * invent a 'B' specifier which stores a boolean into an int, using -1
\r
279 * for unspecified. Right now there is no need for such a thing.)
\r
281 * Use the '!' format specifier to write partial tuples when you have
\r
282 * to transmit an array or other unusual data. For example, to write
\r
283 * a tuple containing a revision, an array of words, and a boolean:
\r
285 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev));
\r
286 for (i = 0; i < n; i++)
\r
287 SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i]));
\r
288 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag)); @endverbatim
\r
291 svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn,
\r
293 const char *fmt, ...);
\r
295 /** Read an item from the network into @a *item. */
\r
297 svn_ra_svn_read_item(svn_ra_svn_conn_t *conn,
\r
299 svn_ra_svn_item_t **item);
\r
301 /** Scan data on @a conn until we find something which looks like the
\r
302 * beginning of an svn server greeting (an open paren followed by a
\r
303 * whitespace character). This function is appropriate for beginning
\r
304 * a client connection opened in tunnel mode, since people's dotfiles
\r
305 * sometimes write output to stdout. It may only be called at the
\r
306 * beginning of a client connection.
\r
309 svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn,
\r
312 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a
\r
313 * printf-like interface. The format string @a fmt may contain:
\r
316 Spec Argument type Item type
\r
317 ---- -------------------- ---------
\r
318 n apr_uint64_t * Number
\r
319 r svn_revnum_t * Number
\r
320 s svn_string_t ** String
\r
321 c const char ** String
\r
322 w const char ** Word
\r
323 b svn_boolean_t * Word ("true" or "false")
\r
324 B apr_uint64_t * Word ("true" or "false")
\r
325 l apr_array_header_t ** List
\r
328 ? Tuple is allowed to end here
\r
331 * Note that a tuple is only allowed to end precisely at a '?', or at
\r
332 * the end of the specification. So if @a fmt is "c?cc" and @a list
\r
333 * contains two elements, an error will result.
\r
335 * 'B' is similar to 'b', but may be used in the optional tuple specification.
\r
336 * It returns TRUE, FALSE, or SVN_RA_SVN_UNSPECIFIED_NUMBER.
\r
338 * If an optional part of a tuple contains no data, 'r' values will be
\r
339 * set to @c SVN_INVALID_REVNUM, 'n' and 'B' values will be set to
\r
340 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values
\r
341 * will be set to @c NULL. 'b' may not appear inside an optional
\r
342 * tuple specification; use 'B' instead.
\r
345 svn_ra_svn_parse_tuple(apr_array_header_t *list,
\r
347 const char *fmt, ...);
\r
349 /** Read a tuple from the network and parse it as a tuple, using the
\r
350 * format string notation from svn_ra_svn_parse_tuple().
\r
353 svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn,
\r
355 const char *fmt, ...);
\r
357 /** Parse an array of @c svn_ra_svn_item_t structures as a list of
\r
358 * properties, storing the properties in a hash table.
\r
360 * @since New in 1.5.
\r
363 svn_ra_svn_parse_proplist(apr_array_header_t *list,
\r
365 apr_hash_t **props);
\r
367 /** Read a command response from the network and parse it as a tuple, using
\r
368 * the format string notation from svn_ra_svn_parse_tuple().
\r
371 svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn,
\r
373 const char *fmt, ...);
\r
375 /** Accept commands over the network and handle them according to @a
\r
376 * commands. Command handlers will be passed @a conn, a subpool of @a
\r
377 * pool (cleared after each command is handled), the parameters of the
\r
378 * command, and @a baton. Commands will be accepted until a
\r
379 * terminating command is received (a command with "terminate" set in
\r
380 * the command table). If a command handler returns an error wrapped
\r
381 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error
\r
382 * will be reported to the other side of the connection and the
\r
383 * command loop will continue; any other kind of error (typically a
\r
384 * network or protocol error) is passed through to the caller.
\r
386 * @since New in 1.6.
\r
390 svn_ra_svn_handle_commands2(svn_ra_svn_conn_t *conn,
\r
392 const svn_ra_svn_cmd_entry_t *commands,
\r
394 svn_boolean_t error_on_disconnect);
\r
396 /** Similar to svn_ra_svn_handle_commands2 but @a error_on_disconnect
\r
397 * is always @c FALSE.
\r
399 * @deprecated Provided for backward compatibility with the 1.5 API.
\r
403 svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn,
\r
405 const svn_ra_svn_cmd_entry_t *commands,
\r
408 /** Write a command over the network, using the same format string notation
\r
409 * as svn_ra_svn_write_tuple().
\r
412 svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn,
\r
414 const char *cmdname,
\r
415 const char *fmt, ...);
\r
417 /** Write a successful command response over the network, using the
\r
418 * same format string notation as svn_ra_svn_write_tuple(). Do not use
\r
419 * partial tuples with this function; if you need to use partial
\r
420 * tuples, just write out the "success" and argument tuple by hand.
\r
423 svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn,
\r
425 const char *fmt, ...);
\r
427 /** Write an unsuccessful command response over the network. */
\r
429 svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn,
\r
433 /** Set @a *editor and @a *edit_baton to an editor which will pass editing
\r
434 * operations over the network, using @a conn and @a pool.
\r
436 * Upon successful completion of the edit, the editor will invoke @a callback
\r
437 * with @a callback_baton as an argument.
\r
440 svn_ra_svn_get_editor(const svn_delta_editor_t **editor,
\r
442 svn_ra_svn_conn_t *conn,
\r
444 svn_ra_svn_edit_callback callback,
\r
445 void *callback_baton);
\r
447 /** Receive edit commands over the network and use them to drive @a editor
\r
448 * with @a edit_baton. On return, @a *aborted will be set if the edit was
\r
449 * aborted. The drive can be terminated with a finish-replay command only
\r
450 * if @a for_replay is TRUE.
\r
453 svn_ra_svn_drive_editor2(svn_ra_svn_conn_t *conn,
\r
455 const svn_delta_editor_t *editor,
\r
457 svn_boolean_t *aborted,
\r
458 svn_boolean_t for_replay);
\r
460 /** Like svn_ra_svn_drive_editor2, but with @a for_replay always FALSE.
\r
463 svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn,
\r
465 const svn_delta_editor_t *editor,
\r
467 svn_boolean_t *aborted);
\r
469 /** This function is only intended for use by svnserve.
\r
471 * Perform CRAM-MD5 password authentication. On success, return
\r
472 * SVN_NO_ERROR with *user set to the username and *success set to
\r
473 * TRUE. On an error which can be reported to the client, report the
\r
474 * error and return SVN_NO_ERROR with *success set to FALSE. On
\r
475 * communications failure, return an error.
\r
478 svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn,
\r
480 svn_config_t *pwdb,
\r
482 svn_boolean_t *success);
\r
485 * Get libsvn_ra_svn version information.
\r
486 * @since New in 1.1.
\r
488 const svn_version_t *
\r
489 svn_ra_svn_version(void);
\r
493 #endif /* __cplusplus */
\r
495 #endif /* SVN_RA_SVN_H */
\r