2 * ra_svn.h : private declarations for the ra_svn module
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
31 #endif /* __cplusplus */
33 #include <apr_network_io.h>
34 #include <apr_file_io.h>
35 #include <apr_thread_proc.h>
37 #include "svn_ra_svn.h"
39 #include "private/svn_ra_svn_private.h"
41 /* Callback function that indicates if a svn_ra_svn__stream_t has pending
44 typedef svn_boolean_t (*ra_svn_pending_fn_t)(void *baton);
46 /* Callback function that sets the timeout value for a svn_ra_svn__stream_t. */
47 typedef void (*ra_svn_timeout_fn_t)(void *baton, apr_interval_time_t timeout);
49 /* A stream abstraction for ra_svn.
51 * This is different from svn_stream_t in that it provides timeouts and
52 * the ability to check for pending data.
54 typedef struct svn_ra_svn__stream_st svn_ra_svn__stream_t;
56 /* Handler for blocked writes. */
57 typedef svn_error_t *(*ra_svn_block_handler_t)(svn_ra_svn_conn_t *conn,
61 /* The default "user agent". */
62 #define SVN_RA_SVN__DEFAULT_USERAGENT "SVN/" SVN_VER_NUMBER\
63 " (" SVN_BUILD_TARGET ")"
65 /* The size of our per-connection read and write buffers. */
66 #define SVN_RA_SVN__PAGE_SIZE 4096
67 #define SVN_RA_SVN__READBUF_SIZE (4 * SVN_RA_SVN__PAGE_SIZE)
68 #define SVN_RA_SVN__WRITEBUF_SIZE (4 * SVN_RA_SVN__PAGE_SIZE)
70 /* Create forward reference */
71 typedef struct svn_ra_svn__session_baton_t svn_ra_svn__session_baton_t;
73 /* This structure is opaque to the server. The client pokes at the
74 * first few fields during setup and cleanup. */
75 struct svn_ra_svn_conn_st {
78 char write_buf[SVN_RA_SVN__WRITEBUF_SIZE];
79 char read_buf[SVN_RA_SVN__READBUF_SIZE];
84 svn_ra_svn__stream_t *stream;
85 svn_ra_svn__session_baton_t *session;
87 /* Although all reads and writes go through the svn_ra_svn__stream_t
88 interface, SASL still needs direct access to the underlying socket
89 for stuff like IP addresses and port numbers. */
91 svn_boolean_t encrypted;
94 /* abortion check control */
95 apr_size_t written_since_error_check;
96 apr_size_t error_check_interval;
97 svn_boolean_t may_check_for_error;
101 const char *repos_root;
103 /* TX block notification target */
104 ra_svn_block_handler_t block_handler;
107 /* server settings */
108 apr_hash_t *capabilities;
109 int compression_level;
110 apr_size_t zero_copy_limit;
112 /* who's on the other side of the connection? */
116 svn_delta_shim_callbacks_t *shim_callbacks;
122 struct svn_ra_svn__session_baton_t {
124 svn_ra_svn_conn_t *conn;
125 svn_boolean_t is_tunneled;
126 svn_auth_baton_t *auth_baton;
129 const char *hostname; /* The remote hostname. */
130 const char *realm_prefix;
131 const char *tunnel_name;
132 const char **tunnel_argv;
133 const svn_ra_callbacks2_t *callbacks;
134 void *callbacks_baton;
136 apr_off_t bytes_read, bytes_written; /* apr_off_t's because that's what
137 the callback interface uses */
138 const char *useragent;
141 /* Set a callback for blocked writes on conn. This handler may
142 * perform reads on the connection in order to prevent deadlock due to
143 * pipelining. If callback is NULL, the connection goes back to
144 * normal blocking I/O for writes.
146 void svn_ra_svn__set_block_handler(svn_ra_svn_conn_t *conn,
147 ra_svn_block_handler_t callback,
150 /* Return true if there is input waiting on conn. */
151 svn_error_t *svn_ra_svn__data_available(svn_ra_svn_conn_t *conn,
152 svn_boolean_t *data_available);
154 /* CRAM-MD5 client implementation. */
155 svn_error_t *svn_ra_svn__cram_client(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
156 const char *user, const char *password,
157 const char **message);
159 /* Return a pointer to the error chain child of ERR which contains the
160 * first "real" error message, not merely one of the
161 * SVN_ERR_RA_SVN_CMD_ERR wrapper errors. */
162 svn_error_t *svn_ra_svn__locate_real_error_child(svn_error_t *err);
164 /* Return an error chain based on @a params (which contains a
165 * command response indicating failure). The error chain will be
166 * in the same order as the errors indicated in @a params. Use
167 * @a pool for temporary allocations. */
168 svn_error_t *svn_ra_svn__handle_failure_status(const apr_array_header_t *params,
171 /* Returns a stream that reads/writes from/to SOCK. */
172 svn_ra_svn__stream_t *svn_ra_svn__stream_from_sock(apr_socket_t *sock,
175 /* Returns a stream that reads from IN_STREAM and writes to OUT_STREAM,
176 creating a timeout callback for OUT_STREAM if possible */
177 svn_ra_svn__stream_t *svn_ra_svn__stream_from_streams(svn_stream_t *in_stream,
178 svn_stream_t *out_stream,
181 /* Create an svn_ra_svn__stream_t using READ_CB, WRITE_CB, TIMEOUT_CB,
182 * PENDING_CB, and BATON.
184 svn_ra_svn__stream_t *svn_ra_svn__stream_create(svn_stream_t *in_stream,
185 svn_stream_t *out_stream,
187 ra_svn_timeout_fn_t timeout_cb,
188 apr_pool_t *result_pool);
190 /* Write *LEN bytes from DATA to STREAM, returning the number of bytes
193 svn_error_t *svn_ra_svn__stream_write(svn_ra_svn__stream_t *stream,
194 const char *data, apr_size_t *len);
196 /* Read *LEN bytes from STREAM into DATA, returning the number of bytes
199 svn_error_t *svn_ra_svn__stream_read(svn_ra_svn__stream_t *stream,
200 char *data, apr_size_t *len);
202 /* Read the command word from CONN, return it in *COMMAND and skip to the
203 * end of the command. Allocate data in POOL.
205 svn_error_t *svn_ra_svn__read_command_only(svn_ra_svn_conn_t *conn,
207 const char **command);
209 /* Set the timeout for operations on STREAM to INTERVAL. */
210 void svn_ra_svn__stream_timeout(svn_ra_svn__stream_t *stream,
211 apr_interval_time_t interval);
213 /* Return whether or not there is data pending on STREAM. */
215 svn_ra_svn__stream_data_available(svn_ra_svn__stream_t *stream,
216 svn_boolean_t *data_available);
218 /* Respond to an auth request and perform authentication. Use the Cyrus
219 * SASL library for mechanism negotiation and for creating authentication
222 svn_ra_svn__do_cyrus_auth(svn_ra_svn__session_baton_t *sess,
223 const apr_array_header_t *mechlist,
224 const char *realm, apr_pool_t *pool);
226 /* Same as svn_ra_svn__do_cyrus_auth, but uses the built-in implementation of
227 * the CRAM-MD5, ANONYMOUS and EXTERNAL mechanisms. Return the error
228 * SVN_ERR_RA_SVN_NO_MECHANSIMS if we cannot negotiate an authentication
229 * mechanism with the server. */
231 svn_ra_svn__do_internal_auth(svn_ra_svn__session_baton_t *sess,
232 const apr_array_header_t *mechlist,
233 const char *realm, apr_pool_t *pool);
235 /* Having picked a mechanism, start authentication by writing out an
236 * auth response. MECH_ARG may be NULL for mechanisms with no
237 * initial client response. */
238 svn_error_t *svn_ra_svn__auth_response(svn_ra_svn_conn_t *conn,
240 const char *mech, const char *mech_arg);
242 /* Looks for MECH as a word in MECHLIST (an array of svn_ra_svn_item_t). */
243 svn_boolean_t svn_ra_svn__find_mech(const apr_array_header_t *mechlist,
246 /* Initialize the SASL library. */
247 svn_error_t *svn_ra_svn__sasl_init(void);
252 #endif /* __cplusplus */
254 #endif /* RA_SVN_H */