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"
29
#include "svn_version.h"
34
#endif /* __cplusplus */
37
/** Spill-to-file Buffers
39
* @defgroup svn_spillbuf_t Spill-to-file Buffers
43
/** A buffer that collects blocks of content, possibly using a file.
45
* The spill-buffer is created with two basic parameters: the size of the
46
* blocks that will be written into the spill-buffer ("blocksize"), and
47
* the (approximate) maximum size that will be allowed in memory ("maxsize").
48
* Once the maxsize is reached, newly written content will be "spilled"
49
* into a temporary file.
51
* When writing, content will be buffered into memory unless a given write
52
* will cause the amount of in-memory content to exceed the specified
53
* maxsize. At that point, the file is created, and the content will be
54
* written to that file.
56
* To read information back out of a spill buffer, there are two approaches
57
* available to the application:
59
* *) reading blocks using svn_spillbuf_read() (a "pull" model)
60
* *) having blocks passed to a callback via svn_spillbuf_process()
61
* (a "push" model to your application)
63
* In both cases, the spill-buffer will provide you with a block of N bytes
64
* that you must fully consume before asking for more data. The callback
65
* style provides for a "stop" parameter to temporarily pause the reading
66
* until another read is desired. The two styles of reading may be mixed,
67
* as the caller desires. Generally, N will be the blocksize, and will be
68
* less when the end of the content is reached.
70
* For a more stream-oriented style of reading, where the caller specifies
71
* the number of bytes to read into a caller-provided buffer, please see
72
* svn_spillbuf_reader_t. That overlaid type will cause more memory copies
73
* to be performed (whereas the bare spill-buffer type hands you a buffer
76
* Writes may be interleaved with reading, and content will be returned
77
* in a FIFO manner. Thus, if content has been placed into the spill-buffer
78
* you will always read the earliest-written data, and any newly-written
79
* content will be appended to the buffer.
81
* Note: the file is created in the same pool where the spill-buffer was
82
* created. If the content is completely read from that file, it will be
83
* closed and deleted. Should writing further content cause another spill
84
* file to be created, that will increase the size of the pool. There is
85
* no bound on the amount of file-related resources that may be consumed
86
* from the pool. It is entirely related to the read/write pattern and
87
* whether spill files are repeatedly created.
89
typedef struct svn_spillbuf_t svn_spillbuf_t;
92
/* Create a spill buffer. */
94
svn_spillbuf__create(apr_size_t blocksize,
96
apr_pool_t *result_pool);
99
/* Determine how much content is stored in the spill buffer. */
101
svn_spillbuf__get_size(const svn_spillbuf_t *buf);
104
/* Write some data into the spill buffer. */
106
svn_spillbuf__write(svn_spillbuf_t *buf,
109
apr_pool_t *scratch_pool);
112
/* Read a block of memory from the spill buffer. @a *data will be set to
113
NULL if no content remains. Otherwise, @a data and @a len will point to
114
data that must be fully-consumed by the caller. This data will remain
115
valid until another call to svn_spillbuf_write(), svn_spillbuf_read(),
116
or svn_spillbuf_process(), or if the spill buffer's pool is cleared. */
118
svn_spillbuf__read(const char **data,
121
apr_pool_t *scratch_pool);
124
/* Callback for reading content out of the spill buffer. Set @a stop if
125
you want to stop the processing (and will call svn_spillbuf_process
126
again, at a later time). */
127
typedef svn_error_t * (*svn_spillbuf_read_t)(svn_boolean_t *stop,
131
apr_pool_t *scratch_pool);
134
/* Process the content stored in the spill buffer. @a exhausted will be
135
set to TRUE if all of the content is processed by @a read_func. This
136
function may return early if the callback returns TRUE for its 'stop'
139
svn_spillbuf__process(svn_boolean_t *exhausted,
141
svn_spillbuf_read_t read_func,
143
apr_pool_t *scratch_pool);
146
/** Classic stream reading layer on top of spill-buffers.
148
* This type layers upon a spill-buffer to enable a caller to read a
149
* specified number of bytes into the caller's provided buffer. This
150
* implies more memory copies than the standard spill-buffer reading
151
* interface, but is sometimes required by spill-buffer users.
153
typedef struct svn_spillbuf_reader_t svn_spillbuf_reader_t;
156
/* Create a spill-buffer and a reader for it. */
157
svn_spillbuf_reader_t *
158
svn_spillbuf__reader_create(apr_size_t blocksize,
160
apr_pool_t *result_pool);
163
/* Read @a len bytes from @a reader into @a data. The number of bytes
164
actually read is stored in @a amt. If the content is exhausted, then
165
@a amt is set to zero. It will always be non-zero if the spill-buffer
168
If @a len is zero, then SVN_ERR_INCORRECT_PARAMS is returned. */
170
svn_spillbuf__reader_read(apr_size_t *amt,
171
svn_spillbuf_reader_t *reader,
174
apr_pool_t *scratch_pool);
177
/* Read a single character from @a reader, and place it in @a c. If there
178
is no content in the spill-buffer, then SVN_ERR_STREAM_UNEXPECTED_EOF
181
svn_spillbuf__reader_getc(char *c,
182
svn_spillbuf_reader_t *reader,
183
apr_pool_t *scratch_pool);
186
/* Write @a len bytes from @a data into the spill-buffer in @a reader. */
188
svn_spillbuf__reader_write(svn_spillbuf_reader_t *reader,
191
apr_pool_t *scratch_pool);
194
/* Return a stream built on top of a spillbuf, using the same arguments as
195
svn_spillbuf__create(). This stream can be used for reading and writing,
196
but implements the same basic sematics of a spillbuf for the underlying
199
svn_stream__from_spillbuf(apr_size_t blocksize,
201
apr_pool_t *result_pool);
206
* Internal function for creating a MD5 checksum from a binary digest.
211
svn_checksum__from_digest_md5(const unsigned char *digest,
212
apr_pool_t *result_pool);
215
* Internal function for creating a SHA1 checksum from a binary
221
svn_checksum__from_digest_sha1(const unsigned char *digest,
222
apr_pool_t *result_pool);
226
* @defgroup svn_hash_support Hash table serialization support
230
/*----------------------------------------------------*/
233
* @defgroup svn_hash_misc Miscellaneous hash APIs
241
* @defgroup svn_hash_getters Specialized getter APIs for hashes
245
/** Find the value of a @a key in @a hash, return the value.
247
* If @a hash is @c NULL or if the @a key cannot be found, the
248
* @a default_value will be returned.
253
svn_hash__get_cstring(apr_hash_t *hash,
255
const char *default_value);
257
/** Like svn_hash_get_cstring(), but for boolean values.
259
* Parses the value as a boolean value. The recognized representations
260
* are 'TRUE'/'FALSE', 'yes'/'no', 'on'/'off', '1'/'0'; case does not
266
svn_hash__get_bool(apr_hash_t *hash,
268
svn_boolean_t default_value);
273
* @defgroup svn_hash_create Create optimized APR hash tables
277
/** Returns a hash table, allocated in @a pool, with the same ordering of
278
* elements as APR 1.4.5 or earlier (using apr_hashfunc_default) but uses
279
* a faster hash function implementation.
284
svn_hash__make(apr_pool_t *pool);
291
/** Apply the changes described by @a prop_changes to @a original_props and
292
* return the result. The inverse of svn_prop_diffs().
294
* Allocate the resulting hash from @a pool, but allocate its keys and
295
* values from @a pool and/or by reference to the storage of the inputs.
297
* Note: some other APIs use an array of pointers to svn_prop_t.
302
svn_prop__patch(const apr_hash_t *original_props,
303
const apr_array_header_t *prop_changes,
308
* @defgroup svn_version Version number dotted triplet parsing
312
/* Set @a *version to a version structure parsed from the version
313
* string representation in @a version_string. Return
314
* @c SVN_ERR_MALFORMED_VERSION_STRING if the string fails to parse
320
svn_version__parse_version_string(svn_version_t **version,
321
const char *version_string,
322
apr_pool_t *result_pool);
324
/* Return true iff @a version represents a version number of at least
325
* the level represented by @a major, @a minor, and @a patch.
330
svn_version__at_least(svn_version_t *version,
335
/** Like svn_ver_check_list(), but with a @a comparator parameter.
336
* Private backport of svn_ver_check_list2() from trunk.
339
svn_ver__check_list2(const svn_version_t *my_version,
340
const svn_version_checklist_t *checklist,
341
svn_boolean_t (*comparator)(const svn_version_t *,
342
const svn_version_t *));
344
/** To minimize merge churn in callers, alias the trunk name privately. */
345
#define svn_ver_check_list2 svn_ver__check_list2
351
#endif /* __cplusplus */
353
#endif /* SVN_SUBR_PRIVATE_H */