ra_svn.h revision 362181
1/* 2 * ra_svn.h : private declarations for the ra_svn module 3 * 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 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 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 20 * under the License. 21 * ==================================================================== 22 */ 23 24 25 26#ifndef RA_SVN_H 27#define RA_SVN_H 28 29#ifdef __cplusplus 30extern "C" { 31#endif /* __cplusplus */ 32 33#include <apr_network_io.h> 34#include <apr_file_io.h> 35#include <apr_thread_proc.h> 36#include "svn_ra.h" 37#include "svn_ra_svn.h" 38 39#include "private/svn_ra_svn_private.h" 40 41/* Callback function that indicates if a svn_ra_svn__stream_t has pending 42 * data. 43 */ 44typedef svn_boolean_t (*ra_svn_pending_fn_t)(void *baton); 45 46/* Callback function that sets the timeout value for a svn_ra_svn__stream_t. */ 47typedef void (*ra_svn_timeout_fn_t)(void *baton, apr_interval_time_t timeout); 48 49/* A stream abstraction for ra_svn. 50 * 51 * This is different from svn_stream_t in that it provides timeouts and 52 * the ability to check for pending data. 53 */ 54typedef struct svn_ra_svn__stream_st svn_ra_svn__stream_t; 55 56/* Handler for blocked writes. */ 57typedef svn_error_t *(*ra_svn_block_handler_t)(svn_ra_svn_conn_t *conn, 58 apr_pool_t *pool, 59 void *baton); 60 61/* The default "user agent". */ 62#define SVN_RA_SVN__DEFAULT_USERAGENT "SVN/" SVN_VER_NUMBER\ 63 " (" SVN_BUILD_TARGET ")" 64 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) 69 70/* Create forward reference */ 71typedef struct svn_ra_svn__session_baton_t svn_ra_svn__session_baton_t; 72 73/* This structure is opaque to the server. The client pokes at the 74 * first few fields during setup and cleanup. */ 75struct svn_ra_svn_conn_st { 76 77 /* I/O buffers */ 78 char write_buf[SVN_RA_SVN__WRITEBUF_SIZE]; 79 char read_buf[SVN_RA_SVN__READBUF_SIZE]; 80 char *read_ptr; 81 char *read_end; 82 apr_size_t write_pos; 83 84 svn_ra_svn__stream_t *stream; 85 svn_ra_svn__session_baton_t *session; 86#ifdef SVN_HAVE_SASL 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. */ 90 apr_socket_t *sock; 91 svn_boolean_t encrypted; 92#endif 93 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; 98 99 /* I/O limits and tracking */ 100 apr_uint64_t max_in; 101 apr_uint64_t current_in; 102 apr_uint64_t max_out; 103 apr_uint64_t current_out; 104 105 /* repository info */ 106 const char *uuid; 107 const char *repos_root; 108 109 /* TX block notification target */ 110 ra_svn_block_handler_t block_handler; 111 void *block_baton; 112 113 /* server settings */ 114 apr_hash_t *capabilities; 115 int compression_level; 116 apr_size_t zero_copy_limit; 117 118 /* who's on the other side of the connection? */ 119 char *remote_ip; 120 121 /* EV2 support*/ 122 svn_delta_shim_callbacks_t *shim_callbacks; 123 124 /* our pool */ 125 apr_pool_t *pool; 126}; 127 128/* The session's URL state for client and server side. 129 * 130 * This keeps track of the respective client-side and server-side "parent" 131 * URLs. It tells us whether we may have to send reparent commands to the 132 * server and how to tweak path parameters when we decided to handle 133 * reparent requests on the client side only. */ 134typedef struct svn_ra_svn__parent_t { 135 /* Client-side session base URL, i.e. client's parent path. */ 136 svn_stringbuf_t *client_url; 137 138 /* Server-side base URL, i.e. server's parent path. */ 139 svn_stringbuf_t *server_url; 140 141 /* Relative path to add to a client-side parameter to translate it for the 142 * server-side. I.e. the relative path from SERVER_URL to CLIENT_URL. */ 143 svn_stringbuf_t *path; 144} svn_ra_svn__parent_t; 145 146struct svn_ra_svn__session_baton_t { 147 apr_pool_t *pool; 148 svn_ra_svn_conn_t *conn; 149 svn_boolean_t is_tunneled; 150 svn_auth_baton_t *auth_baton; 151 svn_ra_svn__parent_t *parent; 152 const char *user; 153 const char *hostname; /* The remote hostname. */ 154 const char *realm_prefix; 155 const char *tunnel_name; 156 const char **tunnel_argv; 157 const svn_ra_callbacks2_t *callbacks; 158 void *callbacks_baton; 159 apr_hash_t *config; 160 apr_off_t bytes_read, bytes_written; /* apr_off_t's because that's what 161 the callback interface uses */ 162 const char *useragent; 163}; 164 165/* Set a callback for blocked writes on conn. This handler may 166 * perform reads on the connection in order to prevent deadlock due to 167 * pipelining. If callback is NULL, the connection goes back to 168 * normal blocking I/O for writes. 169 */ 170void svn_ra_svn__set_block_handler(svn_ra_svn_conn_t *conn, 171 ra_svn_block_handler_t callback, 172 void *baton); 173 174/* Return true if there is input waiting on conn. */ 175svn_error_t *svn_ra_svn__data_available(svn_ra_svn_conn_t *conn, 176 svn_boolean_t *data_available); 177 178/* Signal a new request / response pair on CONN. That resets the I/O 179 * counters we use to limit the size of individual requests / response pairs. 180 */ 181void 182svn_ra_svn__reset_command_io_counters(svn_ra_svn_conn_t *conn); 183 184/* CRAM-MD5 client implementation. */ 185svn_error_t *svn_ra_svn__cram_client(svn_ra_svn_conn_t *conn, apr_pool_t *pool, 186 const char *user, const char *password, 187 const char **message); 188 189/* Return a pointer to the error chain child of ERR which contains the 190 * first "real" error message, not merely one of the 191 * SVN_ERR_RA_SVN_CMD_ERR wrapper errors. */ 192svn_error_t *svn_ra_svn__locate_real_error_child(svn_error_t *err); 193 194/* Return an error chain based on @a params (which contains a 195 * command response indicating failure). The error chain will be 196 * in the same order as the errors indicated in @a params. */ 197svn_error_t * 198svn_ra_svn__handle_failure_status(const svn_ra_svn__list_t *params); 199 200/* Returns a stream that reads/writes from/to SOCK. */ 201svn_ra_svn__stream_t *svn_ra_svn__stream_from_sock(apr_socket_t *sock, 202 apr_pool_t *pool); 203 204/* Returns a stream that reads from IN_STREAM and writes to OUT_STREAM, 205 creating a timeout callback for OUT_STREAM if possible */ 206svn_ra_svn__stream_t *svn_ra_svn__stream_from_streams(svn_stream_t *in_stream, 207 svn_stream_t *out_stream, 208 apr_pool_t *pool); 209 210/* Create an svn_ra_svn__stream_t using READ_CB, WRITE_CB, TIMEOUT_CB, 211 * PENDING_CB, and BATON. 212 */ 213svn_ra_svn__stream_t *svn_ra_svn__stream_create(svn_stream_t *in_stream, 214 svn_stream_t *out_stream, 215 void *timeout_baton, 216 ra_svn_timeout_fn_t timeout_cb, 217 apr_pool_t *result_pool); 218 219/* Write *LEN bytes from DATA to STREAM, returning the number of bytes 220 * written in *LEN. 221 */ 222svn_error_t *svn_ra_svn__stream_write(svn_ra_svn__stream_t *stream, 223 const char *data, apr_size_t *len); 224 225/* Read *LEN bytes from STREAM into DATA, returning the number of bytes 226 * read in *LEN. 227 */ 228svn_error_t *svn_ra_svn__stream_read(svn_ra_svn__stream_t *stream, 229 char *data, apr_size_t *len); 230 231/* Read the command word from CONN, return it in *COMMAND and skip to the 232 * end of the command. Allocate data in POOL. 233 */ 234svn_error_t *svn_ra_svn__read_command_only(svn_ra_svn_conn_t *conn, 235 apr_pool_t *pool, 236 const char **command); 237 238/* Set the timeout for operations on STREAM to INTERVAL. */ 239void svn_ra_svn__stream_timeout(svn_ra_svn__stream_t *stream, 240 apr_interval_time_t interval); 241 242/* Return whether or not there is data pending on STREAM. */ 243svn_error_t * 244svn_ra_svn__stream_data_available(svn_ra_svn__stream_t *stream, 245 svn_boolean_t *data_available); 246 247/* Respond to an auth request and perform authentication. Use the Cyrus 248 * SASL library for mechanism negotiation and for creating authentication 249 * tokens. */ 250svn_error_t * 251svn_ra_svn__do_cyrus_auth(svn_ra_svn__session_baton_t *sess, 252 const svn_ra_svn__list_t *mechlist, 253 const char *realm, apr_pool_t *pool); 254 255/* Same as svn_ra_svn__do_cyrus_auth, but uses the built-in implementation of 256 * the CRAM-MD5, ANONYMOUS and EXTERNAL mechanisms. Return the error 257 * SVN_ERR_RA_SVN_NO_MECHANSIMS if we cannot negotiate an authentication 258 * mechanism with the server. */ 259svn_error_t * 260svn_ra_svn__do_internal_auth(svn_ra_svn__session_baton_t *sess, 261 const svn_ra_svn__list_t *mechlist, 262 const char *realm, apr_pool_t *pool); 263 264/* Having picked a mechanism, start authentication by writing out an 265 * auth response. MECH_ARG may be NULL for mechanisms with no 266 * initial client response. */ 267svn_error_t *svn_ra_svn__auth_response(svn_ra_svn_conn_t *conn, 268 apr_pool_t *pool, 269 const char *mech, const char *mech_arg); 270 271/* Looks for MECH as a word in MECHLIST. */ 272svn_boolean_t svn_ra_svn__find_mech(const svn_ra_svn__list_t *mechlist, 273 const char *mech); 274 275/* Initialize the SASL library. */ 276svn_error_t *svn_ra_svn__sasl_init(void); 277 278 279#ifdef __cplusplus 280} 281#endif /* __cplusplus */ 282 283#endif /* RA_SVN_H */ 284