In the command-line client, forbid
[svn.git] / subversion / include / svn_ra_svn.h
blob80f56d98f3c105e0b6966114e04fb92ea1867e19
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"
54 /** ra_svn passes @c svn_dirent_t fields over the wire as a list of
55 * words, these are the values used to represent each field.
57 * @defgroup ra_svn_dirent_fields Definitions of ra_svn dirent fields
58 * @{
61 /** The ra_svn way of saying @c SVN_DIRENT_KIND. */
62 #define SVN_RA_SVN_DIRENT_KIND "kind"
64 /** The ra_svn way of saying @c SVN_DIRENT_SIZE. */
65 #define SVN_RA_SVN_DIRENT_SIZE "size"
67 /** The ra_svn way of saying @c SVN_DIRENT_HAS_PROPS. */
68 #define SVN_RA_SVN_DIRENT_HAS_PROPS "has-props"
70 /** The ra_svn way of saying @c SVN_DIRENT_CREATED_REV. */
71 #define SVN_RA_SVN_DIRENT_CREATED_REV "created-rev"
73 /** The ra_svn way of saying @c SVN_DIRENT_TIME. */
74 #define SVN_RA_SVN_DIRENT_TIME "time"
76 /** The ra_svn way of saying @c SVN_DIRENT_LAST_AUTHOR. */
77 #define SVN_RA_SVN_DIRENT_LAST_AUTHOR "last-author"
79 /** @} */
81 /** A value used to indicate an optional number element in a tuple that was
82 * not received.
84 #define SVN_RA_SVN_UNSPECIFIED_NUMBER ~((apr_uint64_t) 0)
86 /** A specialized form of @c SVN_ERR to deal with errors which occur in an
87 * svn_ra_svn_command_handler().
89 * An error returned with this macro will be passed back to the other side
90 * of the connection. Use this macro when performing the requested operation;
91 * use the regular @c SVN_ERR when performing I/O with the client.
93 #define SVN_CMD_ERR(expr) \
94 do { \
95 svn_error_t *svn_err__temp = (expr); \
96 if (svn_err__temp) \
97 return svn_error_create(SVN_ERR_RA_SVN_CMD_ERR, \
98 svn_err__temp, NULL); \
99 } while (0)
101 /** an ra_svn connection. */
102 typedef struct svn_ra_svn_conn_st svn_ra_svn_conn_t;
104 /** Command handler, used by svn_ra_svn_handle_commands(). */
105 typedef svn_error_t *(*svn_ra_svn_command_handler)(svn_ra_svn_conn_t *conn,
106 apr_pool_t *pool,
107 apr_array_header_t *params,
108 void *baton);
110 /** Command table, used by svn_ra_svn_handle_commands().
112 typedef struct svn_ra_svn_cmd_entry_t
114 /** Name of the command */
115 const char *cmdname;
117 /** Handler for the command */
118 svn_ra_svn_command_handler handler;
120 /** Termination flag. If set, command-handling will cease after
121 * command is processed. */
122 svn_boolean_t terminate;
123 } svn_ra_svn_cmd_entry_t;
125 /** Memory representation of an on-the-wire data item. */
126 typedef struct svn_ra_svn_item_t
128 /** Variant indicator. */
129 enum {
130 SVN_RA_SVN_NUMBER,
131 SVN_RA_SVN_STRING,
132 SVN_RA_SVN_WORD,
133 SVN_RA_SVN_LIST
134 } kind;
135 /** Variant data. */
136 union {
137 apr_uint64_t number;
138 svn_string_t *string;
139 const char *word;
141 /** Contains @c svn_ra_svn_item_t's. */
142 apr_array_header_t *list;
143 } u;
144 } svn_ra_svn_item_t;
146 typedef svn_error_t *(*svn_ra_svn_edit_callback)(void *baton);
148 /** Initialize a connection structure for the given socket or
149 * input/output files.
151 * Either @a sock or @a in_file/@a out_file must be set, not both.
153 svn_ra_svn_conn_t *svn_ra_svn_create_conn(apr_socket_t *sock,
154 apr_file_t *in_file,
155 apr_file_t *out_file,
156 apr_pool_t *pool);
158 /** Initialize a connection's capabilities to the ones specified in
159 * @a list, which contains svn_ra_svn_item_t entries (which should
160 * be of type SVN_RA_SVN_WORD; a malformed data error will result if
161 * any are not). */
162 svn_error_t *svn_ra_svn_set_capabilities(svn_ra_svn_conn_t *conn,
163 apr_array_header_t *list);
165 /** Return @c TRUE if @a conn has the capability @a capability, or
166 * @c FALSE if it does not. */
167 svn_boolean_t svn_ra_svn_has_capability(svn_ra_svn_conn_t *conn,
168 const char *capability);
170 /** Write a number over the net.
172 * Writes will be buffered until the next read or flush.
174 svn_error_t *svn_ra_svn_write_number(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
175 apr_uint64_t number);
177 /** Write a string over the net.
179 * Writes will be buffered until the next read or flush.
181 svn_error_t *svn_ra_svn_write_string(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
182 const svn_string_t *str);
184 /** Write a cstring over the net.
186 * Writes will be buffered until the next read or flush.
188 svn_error_t *svn_ra_svn_write_cstring(svn_ra_svn_conn_t *conn,
189 apr_pool_t *pool, const char *s);
191 /** Write a word over the net.
193 * Writes will be buffered until the next read or flush.
195 svn_error_t *svn_ra_svn_write_word(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
196 const char *word);
198 /** Write a list of properties over the net. @a props is allowed to be NULL,
199 * in which case an empty list will be written out.
201 * @since New in 1.5.
203 svn_error_t *svn_ra_svn_write_proplist(svn_ra_svn_conn_t *conn,
204 apr_pool_t *pool,
205 apr_hash_t *props);
207 /** Begin a list. Writes will be buffered until the next read or flush. */
208 svn_error_t *svn_ra_svn_start_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
210 /** End a list. Writes will be buffered until the next read or flush. */
211 svn_error_t *svn_ra_svn_end_list(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
213 /** Flush the write buffer.
215 * Normally this shouldn't be necessary, since the write buffer is flushed
216 * when a read is attempted.
218 svn_error_t *svn_ra_svn_flush(svn_ra_svn_conn_t *conn, apr_pool_t *pool);
220 /** Write a tuple, using a printf-like interface.
222 * The format string @a fmt may contain:
224 *@verbatim
225 Spec Argument type Item type
226 ---- -------------------- ---------
227 n apr_uint64_t Number
228 r svn_revnum_t Number
229 s const svn_string_t * String
230 c const char * String
231 w const char * Word
232 b svn_boolean_t Word ("true" or "false")
233 ( Begin tuple
234 ) End tuple
235 ? Remaining elements optional
236 ! (at beginning or end) Suppress opening or closing of tuple
237 @endverbatim
239 * Inside the optional part of a tuple, 'r' values may be @c
240 * SVN_INVALID_REVNUM, 'n' values may be
241 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', and 'w' values may be
242 * @c NULL; in these cases no data will be written. 'b' and '(' may
243 * not appear in the optional part of a tuple. Either all or none of
244 * the optional values should be valid.
246 * (If we ever have a need for an optional boolean value, we should
247 * invent a 'B' specifier which stores a boolean into an int, using -1
248 * for unspecified. Right now there is no need for such a thing.)
250 * Use the '!' format specifier to write partial tuples when you have
251 * to transmit an array or other unusual data. For example, to write
252 * a tuple containing a revision, an array of words, and a boolean:
253 * @verbatim
254 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "r(!", rev));
255 for (i = 0; i < n; i++)
256 SVN_ERR(svn_ra_svn_write_word(conn, pool, words[i]));
257 SVN_ERR(svn_ra_svn_write_tuple(conn, pool, "!)b", flag)); @endverbatim
259 svn_error_t *svn_ra_svn_write_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
260 const char *fmt, ...);
262 /** Read an item from the network into @a *item. */
263 svn_error_t *svn_ra_svn_read_item(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
264 svn_ra_svn_item_t **item);
266 /** Scan data on @a conn until we find something which looks like the
267 * beginning of an svn server greeting (an open paren followed by a
268 * whitespace character). This function is appropriate for beginning
269 * a client connection opened in tunnel mode, since people's dotfiles
270 * sometimes write output to stdout. It may only be called at the
271 * beginning of a client connection.
273 svn_error_t *svn_ra_svn_skip_leading_garbage(svn_ra_svn_conn_t *conn,
274 apr_pool_t *pool);
276 /** Parse an array of @c svn_sort__item_t structures as a tuple, using a
277 * printf-like interface. The format string @a fmt may contain:
279 *@verbatim
280 Spec Argument type Item type
281 ---- -------------------- ---------
282 n apr_uint64_t * Number
283 r svn_revnum_t * Number
284 s svn_string_t ** String
285 c const char ** String
286 w const char ** Word
287 b svn_boolean_t * Word ("true" or "false")
288 B apr_uint64_t * Word ("true" or "false")
289 l apr_array_header_t ** List
290 ( Begin tuple
291 ) End tuple
292 ? Tuple is allowed to end here
293 @endverbatim
295 * Note that a tuple is only allowed to end precisely at a '?', or at
296 * the end of the specification. So if @a fmt is "c?cc" and @a list
297 * contains two elements, an error will result.
299 * 'B' is similar to 'b', but may be used in the optional tuple specification.
300 * It returns TRUE, FALSE, or SVN_RA_SVN_UNSPECIFIED_NUMBER.
302 * If an optional part of a tuple contains no data, 'r' values will be
303 * set to @c SVN_INVALID_REVNUM, 'n' and 'B' values will be set to
304 * SVN_RA_SVN_UNSPECIFIED_NUMBER, and 's', 'c', 'w', and 'l' values
305 * will be set to @c NULL. 'b' may not appear inside an optional
306 * tuple specification; use 'B' instead.
308 svn_error_t *svn_ra_svn_parse_tuple(apr_array_header_t *list,
309 apr_pool_t *pool,
310 const char *fmt, ...);
312 /** Read a tuple from the network and parse it as a tuple, using the
313 * format string notation from svn_ra_svn_parse_tuple().
315 svn_error_t *svn_ra_svn_read_tuple(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
316 const char *fmt, ...);
318 /** Parse an array of @c svn_ra_svn_item_t structures as a list of
319 * properties, storing the properties in a hash table.
321 * @since New in 1.5.
323 svn_error_t *svn_ra_svn_parse_proplist(apr_array_header_t *list,
324 apr_pool_t *pool,
325 apr_hash_t **props);
327 /** Read a command response from the network and parse it as a tuple, using
328 * the format string notation from svn_ra_svn_parse_tuple().
330 svn_error_t *svn_ra_svn_read_cmd_response(svn_ra_svn_conn_t *conn,
331 apr_pool_t *pool,
332 const char *fmt, ...);
334 /** Accept commands over the network and handle them according to @a
335 * commands. Command handlers will be passed @a conn, a subpool of @a
336 * pool (cleared after each command is handled), the parameters of the
337 * command, and @a baton. Commands will be accepted until a
338 * terminating command is received (a command with "terminate" set in
339 * the command table). If a command handler returns an error wrapped
340 * in SVN_RA_SVN_CMD_ERR (see the @c SVN_CMD_ERR macro), the error
341 * will be reported to the other side of the connection and the
342 * command loop will continue; any other kind of error (typically a
343 * network or protocol error) is passed through to the caller.
345 svn_error_t *svn_ra_svn_handle_commands(svn_ra_svn_conn_t *conn,
346 apr_pool_t *pool,
347 const svn_ra_svn_cmd_entry_t *commands,
348 void *baton);
350 /** Write a command over the network, using the same format string notation
351 * as svn_ra_svn_write_tuple().
353 svn_error_t *svn_ra_svn_write_cmd(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
354 const char *cmdname, const char *fmt, ...);
356 /** Write a successful command response over the network, using the
357 * same format string notation as svn_ra_svn_write_tuple(). Do not use
358 * partial tuples with this function; if you need to use partial
359 * tuples, just write out the "success" and argument tuple by hand.
361 svn_error_t *svn_ra_svn_write_cmd_response(svn_ra_svn_conn_t *conn,
362 apr_pool_t *pool,
363 const char *fmt, ...);
365 /** Write an unsuccessful command response over the network. */
366 svn_error_t *svn_ra_svn_write_cmd_failure(svn_ra_svn_conn_t *conn,
367 apr_pool_t *pool, svn_error_t *err);
369 /** Set @a *editor and @a *edit_baton to an editor which will pass editing
370 * operations over the network, using @a conn and @a pool.
372 * Upon successful completion of the edit, the editor will invoke @a callback
373 * with @a callback_baton as an argument.
375 void svn_ra_svn_get_editor(const svn_delta_editor_t **editor,
376 void **edit_baton, svn_ra_svn_conn_t *conn,
377 apr_pool_t *pool, svn_ra_svn_edit_callback callback,
378 void *callback_baton);
380 /** Receive edit commands over the network and use them to drive @a editor
381 * with @a edit_baton. On return, @a *aborted will be set if the edit was
382 * aborted. The drive can be terminated with a finish-replay command only
383 * if @a for_replay is TRUE.
385 svn_error_t *svn_ra_svn_drive_editor2(svn_ra_svn_conn_t *conn,
386 apr_pool_t *pool,
387 const svn_delta_editor_t *editor,
388 void *edit_baton,
389 svn_boolean_t *aborted,
390 svn_boolean_t for_replay);
392 /** Like svn_ra_svn_drive_editor2, but with @a for_replay always FALSE.
394 svn_error_t *svn_ra_svn_drive_editor(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
395 const svn_delta_editor_t *editor,
396 void *edit_baton,
397 svn_boolean_t *aborted);
399 /** This function is only intended for use by svnserve.
401 * Perform CRAM-MD5 password authentication. On success, return
402 * SVN_NO_ERROR with *user set to the username and *success set to
403 * TRUE. On an error which can be reported to the client, report the
404 * error and return SVN_NO_ERROR with *success set to FALSE. On
405 * communications failure, return an error.
407 svn_error_t *svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
408 svn_config_t *pwdb, const char **user,
409 svn_boolean_t *success);
412 * Get libsvn_ra_svn version information.
413 * @since New in 1.1.
415 const svn_version_t *svn_ra_svn_version(void);
417 #ifdef __cplusplus
419 #endif /* __cplusplus */
421 #endif /* SVN_RA_SVN_H */