2 * svn_subr_private.h : private definitions from libsvn_subr
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 * ====================================================================
24 #ifndef SVN_SUBR_PRIVATE_H
25 #define SVN_SUBR_PRIVATE_H
27 #include "svn_types.h"
33 #endif /* __cplusplus */
36 /** Spill-to-file Buffers
38 * @defgroup svn_spillbuf_t Spill-to-file Buffers
42 /** A buffer that collects blocks of content, possibly using a file.
44 * The spill-buffer is created with two basic parameters: the size of the
45 * blocks that will be written into the spill-buffer ("blocksize"), and
46 * the (approximate) maximum size that will be allowed in memory ("maxsize").
47 * Once the maxsize is reached, newly written content will be "spilled"
48 * into a temporary file.
50 * When writing, content will be buffered into memory unless a given write
51 * will cause the amount of in-memory content to exceed the specified
52 * maxsize. At that point, the file is created, and the content will be
53 * written to that file.
55 * To read information back out of a spill buffer, there are two approaches
56 * available to the application:
58 * *) reading blocks using svn_spillbuf_read() (a "pull" model)
59 * *) having blocks passed to a callback via svn_spillbuf_process()
60 * (a "push" model to your application)
62 * In both cases, the spill-buffer will provide you with a block of N bytes
63 * that you must fully consume before asking for more data. The callback
64 * style provides for a "stop" parameter to temporarily pause the reading
65 * until another read is desired. The two styles of reading may be mixed,
66 * as the caller desires. Generally, N will be the blocksize, and will be
67 * less when the end of the content is reached.
69 * For a more stream-oriented style of reading, where the caller specifies
70 * the number of bytes to read into a caller-provided buffer, please see
71 * svn_spillbuf_reader_t. That overlaid type will cause more memory copies
72 * to be performed (whereas the bare spill-buffer type hands you a buffer
75 * Writes may be interleaved with reading, and content will be returned
76 * in a FIFO manner. Thus, if content has been placed into the spill-buffer
77 * you will always read the earliest-written data, and any newly-written
78 * content will be appended to the buffer.
80 * Note: the file is created in the same pool where the spill-buffer was
81 * created. If the content is completely read from that file, it will be
82 * closed and deleted. Should writing further content cause another spill
83 * file to be created, that will increase the size of the pool. There is
84 * no bound on the amount of file-related resources that may be consumed
85 * from the pool. It is entirely related to the read/write pattern and
86 * whether spill files are repeatedly created.
88 typedef struct svn_spillbuf_t svn_spillbuf_t;
91 /* Create a spill buffer. */
93 svn_spillbuf__create(apr_size_t blocksize,
95 apr_pool_t *result_pool);
98 /* Determine how much content is stored in the spill buffer. */
100 svn_spillbuf__get_size(const svn_spillbuf_t *buf);
103 /* Write some data into the spill buffer. */
105 svn_spillbuf__write(svn_spillbuf_t *buf,
108 apr_pool_t *scratch_pool);
111 /* Read a block of memory from the spill buffer. @a *data will be set to
112 NULL if no content remains. Otherwise, @a data and @a len will point to
113 data that must be fully-consumed by the caller. This data will remain
114 valid until another call to svn_spillbuf_write(), svn_spillbuf_read(),
115 or svn_spillbuf_process(), or if the spill buffer's pool is cleared. */
117 svn_spillbuf__read(const char **data,
120 apr_pool_t *scratch_pool);
123 /* Callback for reading content out of the spill buffer. Set @a stop if
124 you want to stop the processing (and will call svn_spillbuf_process
125 again, at a later time). */
126 typedef svn_error_t * (*svn_spillbuf_read_t)(svn_boolean_t *stop,
130 apr_pool_t *scratch_pool);
133 /* Process the content stored in the spill buffer. @a exhausted will be
134 set to TRUE if all of the content is processed by @a read_func. This
135 function may return early if the callback returns TRUE for its 'stop'
138 svn_spillbuf__process(svn_boolean_t *exhausted,
140 svn_spillbuf_read_t read_func,
142 apr_pool_t *scratch_pool);
145 /** Classic stream reading layer on top of spill-buffers.
147 * This type layers upon a spill-buffer to enable a caller to read a
148 * specified number of bytes into the caller's provided buffer. This
149 * implies more memory copies than the standard spill-buffer reading
150 * interface, but is sometimes required by spill-buffer users.
152 typedef struct svn_spillbuf_reader_t svn_spillbuf_reader_t;
155 /* Create a spill-buffer and a reader for it. */
156 svn_spillbuf_reader_t *
157 svn_spillbuf__reader_create(apr_size_t blocksize,
159 apr_pool_t *result_pool);
162 /* Read @a len bytes from @a reader into @a data. The number of bytes
163 actually read is stored in @a amt. If the content is exhausted, then
164 @a amt is set to zero. It will always be non-zero if the spill-buffer
167 If @a len is zero, then SVN_ERR_INCORRECT_PARAMS is returned. */
169 svn_spillbuf__reader_read(apr_size_t *amt,
170 svn_spillbuf_reader_t *reader,
173 apr_pool_t *scratch_pool);
176 /* Read a single character from @a reader, and place it in @a c. If there
177 is no content in the spill-buffer, then SVN_ERR_STREAM_UNEXPECTED_EOF
180 svn_spillbuf__reader_getc(char *c,
181 svn_spillbuf_reader_t *reader,
182 apr_pool_t *scratch_pool);
185 /* Write @a len bytes from @a data into the spill-buffer in @a reader. */
187 svn_spillbuf__reader_write(svn_spillbuf_reader_t *reader,
190 apr_pool_t *scratch_pool);
193 /* Return a stream built on top of a spillbuf, using the same arguments as
194 svn_spillbuf__create(). This stream can be used for reading and writing,
195 but implements the same basic sematics of a spillbuf for the underlying
198 svn_stream__from_spillbuf(apr_size_t blocksize,
200 apr_pool_t *result_pool);
205 * Internal function for creating a MD5 checksum from a binary digest.
210 svn_checksum__from_digest_md5(const unsigned char *digest,
211 apr_pool_t *result_pool);
214 * Internal function for creating a SHA1 checksum from a binary
220 svn_checksum__from_digest_sha1(const unsigned char *digest,
221 apr_pool_t *result_pool);
225 * @defgroup svn_hash_support Hash table serialization support
229 /*----------------------------------------------------*/
232 * @defgroup svn_hash_misc Miscellaneous hash APIs
240 * @defgroup svn_hash_getters Specialized getter APIs for hashes
244 /** Find the value of a @a key in @a hash, return the value.
246 * If @a hash is @c NULL or if the @a key cannot be found, the
247 * @a default_value will be returned.
252 svn_hash__get_cstring(apr_hash_t *hash,
254 const char *default_value);
256 /** Like svn_hash_get_cstring(), but for boolean values.
258 * Parses the value as a boolean value. The recognized representations
259 * are 'TRUE'/'FALSE', 'yes'/'no', 'on'/'off', '1'/'0'; case does not
265 svn_hash__get_bool(apr_hash_t *hash,
267 svn_boolean_t default_value);
272 * @defgroup svn_hash_create Create optimized APR hash tables
276 /** Returns a hash table, allocated in @a pool, with the same ordering of
277 * elements as APR 1.4.5 or earlier (using apr_hashfunc_default) but uses
278 * a faster hash function implementation.
283 svn_hash__make(apr_pool_t *pool);
290 /** Apply the changes described by @a prop_changes to @a original_props and
291 * return the result. The inverse of svn_prop_diffs().
293 * Allocate the resulting hash from @a pool, but allocate its keys and
294 * values from @a pool and/or by reference to the storage of the inputs.
296 * Note: some other APIs use an array of pointers to svn_prop_t.
301 svn_prop__patch(const apr_hash_t *original_props,
302 const apr_array_header_t *prop_changes,
307 * @defgroup svn_version Version number dotted triplet parsing
311 /* Set @a *version to a version structure parsed from the version
312 * string representation in @a version_string. Return
313 * @c SVN_ERR_MALFORMED_VERSION_STRING if the string fails to parse
319 svn_version__parse_version_string(svn_version_t **version,
320 const char *version_string,
321 apr_pool_t *result_pool);
323 /* Return true iff @a version represents a version number of at least
324 * the level represented by @a major, @a minor, and @a patch.
329 svn_version__at_least(svn_version_t *version,
338 #endif /* __cplusplus */
340 #endif /* SVN_SUBR_PRIVATE_H */