]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - subversion/include/private/svn_repos_private.h
Import Subversion-1.10.0
[FreeBSD/FreeBSD.git] / subversion / include / private / svn_repos_private.h
1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_repos_private.h
24  * @brief Subversion-internal repos APIs.
25  */
26
27 #ifndef SVN_REPOS_PRIVATE_H
28 #define SVN_REPOS_PRIVATE_H
29
30 #include <apr_pools.h>
31
32 #include "svn_types.h"
33 #include "svn_repos.h"
34 #include "svn_editor.h"
35 #include "svn_config.h"
36
37 #include "private/svn_object_pool.h"
38 #include "private/svn_string_private.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif /* __cplusplus */
43
44
45 /** Validate that property @a name with @a value is valid (as an addition
46  * or edit or deletion) in a Subversion repository.  Return an error if not.
47  *
48  * If @a value is NULL, return #SVN_NO_ERROR to indicate that any property
49  * may be deleted, even an invalid one.  Otherwise, if the @a name is not
50  * of kind #svn_prop_regular_kind (see #svn_prop_kind_t), return
51  * #SVN_ERR_REPOS_BAD_ARGS.  Otherwise, for some "svn:" properties, also
52  * perform some validations on the @a value (e.g., for such properties,
53  * typically the @a value must be in UTF-8 with LF linefeeds), and return
54  * #SVN_ERR_BAD_PROPERTY_VALUE if it is not valid.
55  *
56  * Validations may be added in future releases, for example, for
57  * newly-added #SVN_PROP_PREFIX properties.  However, user-defined
58  * (non-#SVN_PROP_PREFIX) properties will never have their @a value
59  * validated in any way.
60  *
61  * Use @a pool for temporary allocations.
62  *
63  * @note This function is used to implement server-side validation.
64  * Consequently, if you make this function stricter in what it accepts, you
65  * (a) break svnsync'ing of existing repositories that contain now-invalid
66  * properties, (b) do not preclude such invalid values from entering the
67  * repository via tools that use the svn_fs_* API directly (possibly
68  * including svnadmin and svnlook).  This has happened before and there
69  * are known (documented, but unsupported) upgrade paths in some cases.
70  *
71  * @since New in 1.7.
72  */
73 svn_error_t *
74 svn_repos__validate_prop(const char *name,
75                          const svn_string_t *value,
76                          apr_pool_t *pool);
77
78 /* Attempt to normalize a Subversion property if it "needs translation"
79  * (according to svn_prop_needs_translation(), currently all svn:* props).
80  *
81  * At this time, the only performed normalization is translation of
82  * the line endings of the property value so that it would only contain
83  * LF (\n) characters. "\r" characters found mid-line are replaced with "\n".
84  * "\r\n" sequences are replaced with "\n".
85  *
86  * NAME is used to check that VALUE should be normalized, and if this
87  * is the case, VALUE is then normalized, allocated from RESULT_POOL.
88  * If no normalization is required, VALUE will be copied to RESULT_POOL
89  * unchanged.  If NORMALIZED_P is not NULL, and the normalization
90  * happened, set *NORMALIZED_P to non-zero.  If the property is returned
91  * unchanged and NORMALIZED_P is not NULL, then *NORMALIZED_P will be
92  * set to zero.  SCRATCH_POOL will be used for temporary allocations.
93  */
94 svn_error_t *
95 svn_repos__normalize_prop(const svn_string_t **result_p,
96                           svn_boolean_t *normalized_p,
97                           const char *name,
98                           const svn_string_t *value,
99                           apr_pool_t *result_pool,
100                           apr_pool_t *scratch_pool);
101
102 /**
103  * Given the error @a err from svn_repos_fs_commit_txn(), return an
104  * string containing either or both of the svn_fs_commit_txn() error
105  * and the SVN_ERR_REPOS_POST_COMMIT_HOOK_FAILED wrapped error from
106  * the post-commit hook.  Any error tracing placeholders in the error
107  * chain are skipped over.
108  *
109  * This function does not modify @a err.
110  *
111  * ### This method should not be necessary, but there are a few
112  * ### places, e.g. mod_dav_svn, where only a single error message
113  * ### string is returned to the caller and it is useful to have both
114  * ### error messages included in the message.
115  *
116  * Use @a pool to do any allocations in.
117  *
118  * @since New in 1.7.
119  */
120 const char *
121 svn_repos__post_commit_error_str(svn_error_t *err,
122                                  apr_pool_t *pool);
123
124 /* A repos version of svn_fs_type */
125 svn_error_t *
126 svn_repos__fs_type(const char **fs_type,
127                    const char *repos_path,
128                    apr_pool_t *pool);
129
130
131 /* Create a commit editor for REPOS, based on REVISION.  */
132 svn_error_t *
133 svn_repos__get_commit_ev2(svn_editor_t **editor,
134                           svn_repos_t *repos,
135                           svn_authz_t *authz,
136                           const char *authz_repos_name,
137                           const char *authz_user,
138                           apr_hash_t *revprops,
139                           svn_commit_callback2_t commit_cb,
140                           void *commit_baton,
141                           svn_cancel_func_t cancel_func,
142                           void *cancel_baton,
143                           apr_pool_t *result_pool,
144                           apr_pool_t *scratch_pool);
145
146 svn_error_t *
147 svn_repos__replay_ev2(svn_fs_root_t *root,
148                       const char *base_dir,
149                       svn_revnum_t low_water_mark,
150                       svn_editor_t *editor,
151                       svn_repos_authz_func_t authz_read_func,
152                       void *authz_read_baton,
153                       apr_pool_t *scratch_pool);
154
155 /**
156  * Non-deprecated alias for svn_repos_get_logs4.
157  *
158  * Since the mapping of log5 to ra_get_log is would basically duplicate the
159  * log5->log4 adapter, we provide this log4 wrapper that does not create a
160  * deprecation warning.
161  */
162 svn_error_t *
163 svn_repos__get_logs_compat(svn_repos_t *repos,
164                            const apr_array_header_t *paths,
165                            svn_revnum_t start,
166                            svn_revnum_t end,
167                            int limit,
168                            svn_boolean_t discover_changed_paths,
169                            svn_boolean_t strict_node_history,
170                            svn_boolean_t include_merged_revisions,
171                            const apr_array_header_t *revprops,
172                            svn_repos_authz_func_t authz_read_func,
173                            void *authz_read_baton,
174                            svn_log_entry_receiver_t receiver,
175                            void *receiver_baton,
176                            apr_pool_t *pool);
177
178 /**
179  * @defgroup svn_config_pool Configuration object pool API
180  * @{
181  */
182
183 /* Opaque thread-safe factory and container for configuration objects.
184  *
185  * Instances handed out are read-only and may be given to multiple callers
186  * from multiple threads.  Configuration objects no longer referenced by
187  * any user may linger for a while before being cleaned up.
188  */
189 typedef svn_object_pool__t svn_repos__config_pool_t;
190
191 /* Create a new configuration pool object with a lifetime determined by
192  * POOL and return it in *CONFIG_POOL.
193  *
194  * The THREAD_SAFE flag indicates whether the pool actually needs to be
195  * thread-safe and POOL must be also be thread-safe if this flag is set.
196  */
197 svn_error_t *
198 svn_repos__config_pool_create(svn_repos__config_pool_t **config_pool,
199                               svn_boolean_t thread_safe,
200                               apr_pool_t *pool);
201
202 /* Set *CFG to a read-only reference to the current contents of the
203  * configuration specified by PATH.  If the latter is a URL, we read the
204  * data from a local repository.  CONFIG_POOL will store the configuration
205  * and make further callers use the same instance if the content matches.
206  * Section and option names will be case-insensitive.
207  *
208  * If MUST_EXIST is TRUE, a missing config file is also an error, *CFG
209  * is otherwise simply NULL.
210  *
211  * PREFERRED_REPOS is only used if it is not NULL and PATH is a URL.
212  * If it matches the URL, access the repository through this object
213  * instead of creating a new repo instance.  Note that this might not
214  * return the latest content.
215  *
216  * POOL determines the minimum lifetime of *CFG (may remain cached after
217  * release) but must not exceed the lifetime of the pool provided to
218  * #svn_repos__config_pool_create.
219  */
220 svn_error_t *
221 svn_repos__config_pool_get(svn_config_t **cfg,
222                            svn_repos__config_pool_t *config_pool,
223                            const char *path,
224                            svn_boolean_t must_exist,
225                            svn_repos_t *preferred_repos,
226                            apr_pool_t *pool);
227
228 /** @} */
229
230 /* Adjust mergeinfo paths and revisions in ways that are useful when loading
231  * a dump stream.
232  *
233  * Set *NEW_VALUE_P to an adjusted version of the mergeinfo property value
234  * supplied in OLD_VALUE, with the following adjustments.
235  *
236  *   - Normalize line endings: if all CRLF, change to LF; but error if
237  *     mixed. If this normalization is performed, send a notification type
238  *     svn_repos_notify_load_normalized_mergeinfo to NOTIFY_FUNC/NOTIFY_BATON.
239  *
240  *   - Prefix all the merge source paths with PARENT_DIR, if not null.
241  *
242  *   - Adjust any mergeinfo revisions not older than OLDEST_DUMPSTREAM_REV
243  *     by using REV_MAP which maps (svn_revnum_t) old rev to (svn_revnum_t)
244  *     new rev.
245  *
246  *   - Adjust any mergeinfo revisions older than OLDEST_DUMPSTREAM_REV by
247  *     (-OLDER_REVS_OFFSET), dropping any revisions that become <= 0.
248  *
249  * Allocate *NEW_VALUE_P in RESULT_POOL.
250  */
251 svn_error_t *
252 svn_repos__adjust_mergeinfo_property(svn_string_t **new_value_p,
253                                      const svn_string_t *old_value,
254                                      const char *parent_dir,
255                                      apr_hash_t *rev_map,
256                                      svn_revnum_t oldest_dumpstream_rev,
257                                      apr_int32_t older_revs_offset,
258                                      svn_repos_notify_func_t notify_func,
259                                      void *notify_baton,
260                                      apr_pool_t *result_pool,
261                                      apr_pool_t *scratch_pool);
262
263 /* A (nearly) opaque representation of an ordered list of header lines.
264  */
265 typedef struct apr_array_header_t svn_repos__dumpfile_headers_t;
266
267 /* Create an empty set of headers.
268  */
269 svn_repos__dumpfile_headers_t *
270 svn_repos__dumpfile_headers_create(apr_pool_t *pool);
271
272 /* Push the header (KEY, VAL) onto HEADERS.
273  *
274  * Duplicate the key and value into HEADERS's pool.
275  */
276 void
277 svn_repos__dumpfile_header_push(svn_repos__dumpfile_headers_t *headers,
278                                 const char *key,
279                                 const char *val);
280
281 /* Push the header (KEY, val = VAL_FMT ...) onto HEADERS.
282  *
283  * Duplicate the key and value into HEADERS's pool.
284  */
285 void
286 svn_repos__dumpfile_header_pushf(svn_repos__dumpfile_headers_t *headers,
287                                  const char *key,
288                                  const char *val_fmt,
289                                  ...)
290         __attribute__((format(printf, 3, 4)));
291
292 /* Write to STREAM the headers in HEADERS followed by a blank line.
293  */
294 svn_error_t *
295 svn_repos__dump_headers(svn_stream_t *stream,
296                         svn_repos__dumpfile_headers_t *headers,
297                         apr_pool_t *scratch_pool);
298
299 /* Write a revision record to DUMP_STREAM for revision REVISION with revision
300  * properies REVPROPS, creating appropriate headers.
301  *
302  * Include all of the headers in EXTRA_HEADERS (if non-null), ignoring
303  * the revision number header and the three content length headers (which
304  * will be recreated as needed). EXTRA_HEADERS maps (char *) key to
305  * (char *) value.
306  *
307  * REVPROPS maps (char *) key to (svn_string_t *) value.
308  *
309  * Iff PROPS_SECTION_ALWAYS is true, include a prop content section (and
310  * corresponding header) even when REVPROPS is empty. This option exists
311  * to support a historical difference between svndumpfilter and svnadmin
312  * dump.
313  *
314  * Finally write another blank line.
315  */
316 svn_error_t *
317 svn_repos__dump_revision_record(svn_stream_t *dump_stream,
318                                 svn_revnum_t revision,
319                                 apr_hash_t *extra_headers,
320                                 apr_hash_t *revprops,
321                                 svn_boolean_t props_section_always,
322                                 apr_pool_t *scratch_pool);
323
324 /* Output node headers and props.
325  *
326  * Output HEADERS, content length headers, blank line, and
327  * then PROPS_STR (if non-null) to DUMP_STREAM.
328  *
329  * HEADERS is an array of headers as struct {const char *key, *val;}.
330  * Write them all in the given order.
331  *
332  * PROPS_STR is the property content block, including a terminating
333  * 'PROPS_END\n' line. Iff PROPS_STR is non-null, write a
334  * Prop-content-length header and the prop content block.
335  *
336  * Iff HAS_TEXT is true, write a Text-content length, using the value
337  * TEXT_CONTENT_LENGTH.
338  *
339  * Write a Content-length header, its value being the sum of the
340  * Prop- and Text- content length headers, if props and/or text are present
341  * or if CONTENT_LENGTH_ALWAYS is true.
342  */
343 svn_error_t *
344 svn_repos__dump_node_record(svn_stream_t *dump_stream,
345                             svn_repos__dumpfile_headers_t *headers,
346                             svn_stringbuf_t *props_str,
347                             svn_boolean_t has_text,
348                             svn_filesize_t text_content_length,
349                             svn_boolean_t content_length_always,
350                             apr_pool_t *scratch_pool);
351
352 #ifdef __cplusplus
353 }
354 #endif /* __cplusplus */
355
356 #endif /* SVN_REPOS_PRIVATE_H */