svn_dirent_uri.h

Go to the documentation of this file.
00001 /**
00002  * @copyright
00003  * ====================================================================
00004  *    Licensed to the Apache Software Foundation (ASF) under one
00005  *    or more contributor license agreements.  See the NOTICE file
00006  *    distributed with this work for additional information
00007  *    regarding copyright ownership.  The ASF licenses this file
00008  *    to you under the Apache License, Version 2.0 (the
00009  *    "License"); you may not use this file except in compliance
00010  *    with the License.  You may obtain a copy of the License at
00011  *
00012  *      http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  *    Unless required by applicable law or agreed to in writing,
00015  *    software distributed under the License is distributed on an
00016  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00017  *    KIND, either express or implied.  See the License for the
00018  *    specific language governing permissions and limitations
00019  *    under the License.
00020  * ====================================================================
00021  * @endcopyright
00022  *
00023  * @file svn_dirent_uri.h
00024  * @brief A library to manipulate URIs, relative paths and directory entries.
00025  *
00026  * This library makes a clear distinction between several path formats:
00027  *
00028  *  - a dirent is a path on (local) disc or a UNC path (Windows) in
00029  *    either relative or absolute format.
00030  *    Examples:
00031  *       "/foo/bar", "X:/temp", "//server/share", "A:/" (Windows only), ""
00032  *    But not:
00033  *       "http://server"
00034  *
00035  *  - a uri, for our purposes, is a percent-encoded, absolute path
00036  *    (URI) that starts with a schema definition.  In practice, these
00037  *    tend to look like URLs, but never carry query strings.
00038  *    Examples:
00039  *       "http://server", "file:///path/to/repos",
00040  *       "svn+ssh://user@host:123/My%20Stuff/file.doc"
00041  *    But not:
00042  *       "file", "dir/file", "A:/dir", "/My%20Stuff/file.doc", ""
00043  *
00044  *  - a relative path (relpath) is an unrooted path that can be joined
00045  *    to any other relative path, uri or dirent. A relative path is
00046  *    never rooted/prefixed by a '/'.
00047  *    Examples:
00048  *       "file", "dir/file", "dir/subdir/../file", ""
00049  *    But not:
00050  *       "/file", "http://server/file"
00051  *
00052  * This distinction is needed because on Windows we have to handle some
00053  * dirents and URIs differently. Since it's not possible to determine from
00054  * the path string if it's a dirent or a URI, it's up to the API user to
00055  * make this choice. See also issue #2028.
00056  *
00057  * All incoming and outgoing paths are non-NULL unless otherwise documented.
00058  *
00059  * All of these functions expect paths passed into them to be in canonical
00060  * form, except:
00061  *
00062  *    - @c svn_dirent_canonicalize()
00063  *    - @c svn_dirent_is_canonical()
00064  *    - @c svn_dirent_internal_style()
00065  *    - @c svn_relpath_canonicalize()
00066  *    - @c svn_relpath_is_canonical()
00067  *    - @c svn_relpath__internal_style()
00068  *    - @c svn_uri_canonicalize()
00069  *    - @c svn_uri_is_canonical()
00070  *
00071  * The Subversion codebase also recognizes some other classes of path:
00072  *
00073  *  - A Subversion filesystem path (fspath) -- otherwise known as a
00074  *    path within a repository -- is a path relative to the root of
00075  *    the repository filesystem, that starts with a slash ("/").  The
00076  *    rules for a fspath are the same as for a relpath except for the
00077  *    leading '/'.  A fspath never ends with '/' except when the whole
00078  *    path is just '/'.  The fspath API is private (see
00079  *    private/svn_fspath.h).
00080  *
00081  *  - A URL path (urlpath) is just the path part of a URL (the part
00082  *    that follows the schema, username, hostname, and port).  These
00083  *    are also like relpaths, except that they have a leading slash
00084  *    (like fspaths) and are URI-encoded.  The urlpath API is also
00085  *    private (see private/svn_fspath.h)
00086  *    Example:
00087  *       "/svn/repos/trunk/README",
00088  *       "/svn/repos/!svn/bc/45/file%20with%20spaces.txt"
00089  *
00090  * So, which path API is appropriate for your use-case?
00091  *
00092  *  - If your path refers to a local file, directory, symlink, etc. of
00093  *    the sort that you can examine and operate on with other software
00094  *    on your computer, it's a dirent.
00095  *
00096  *  - If your path is a full URL -- with a schema, hostname (maybe),
00097  *    and path portion -- it's a uri.
00098  *
00099  *  - If your path is relative, and is somewhat ambiguous unless it's
00100  *    joined to some other more explicit (possible absolute) base
00101  *    (such as a dirent or URL), it's a relpath.
00102  *
00103  *  - If your path is the virtual path of a versioned object inside a
00104  *    Subversion repository, it could be one of two different types of
00105  *    paths.  We'd prefer to use relpaths (relative to the root
00106  *    directory of the virtual repository filesystem) for that stuff,
00107  *    but some legacy code uses fspaths.  You'll need to figure out if
00108  *    your code expects repository paths to have a leading '/' or not.
00109  *    If so, they are fspaths; otherwise they are relpaths.
00110  *
00111  *  - If your path refers only to the path part of URL -- as if
00112  *    someone hacked off the initial schema and hostname portion --
00113  *    it's a urlpath.  To date, the ra_dav modules are the only ones
00114  *    within Subversion that make use of urlpaths, and this is because
00115  *    WebDAV makes heavy use of that form of path specification.
00116  *
00117  * When translating between local paths (dirents) and uris code should
00118  * always go via the relative path format, perhaps by truncating a
00119  * parent portion from a path with svn_*_skip_ancestor(), or by
00120  * converting portions to basenames and then joining to existing
00121  * paths.
00122  *
00123  * SECURITY WARNING: If a path that is received from an untrusted
00124  * source -- such as from the network -- is converted to a dirent it
00125  * should be tested with svn_dirent_is_under_root() before you can
00126  * assume the path to be a safe local path.
00127  *
00128  * MEMORY ALLOCATION: A function documented as allocating the result
00129  * in a pool may instead return a static string such as "." or "". If
00130  * the result is equal to an input, it will duplicate the input.
00131  */
00132 
00133 #ifndef SVN_DIRENT_URI_H
00134 #define SVN_DIRENT_URI_H
00135 
00136 #include <apr.h>
00137 #include <apr_pools.h>
00138 #include <apr_tables.h>
00139 
00140 #include "svn_types.h"
00141 
00142 #ifdef __cplusplus
00143 extern "C" {
00144 #endif /* __cplusplus */
00145 
00146 
00147 /** Convert @a dirent from the local style to the canonical internal style.
00148  * "Local style" means native path separators and "." for the empty path.
00149  *
00150  * Allocate the result in @a result_pool.
00151  *
00152  * @since New in 1.6.
00153  */
00154 const char *
00155 svn_dirent_internal_style(const char *dirent,
00156                           apr_pool_t *result_pool);
00157 
00158 /** Convert @a dirent from the internal style to the local style.
00159  * "Local style" means native path separators and "." for the empty path.
00160  * If the input is not canonical, the output may not be canonical.
00161  *
00162  * Allocate the result in @a result_pool.
00163  *
00164  * @since New in 1.6.
00165  */
00166 const char *
00167 svn_dirent_local_style(const char *dirent,
00168                        apr_pool_t *result_pool);
00169 
00170 /** Convert @a relpath from the local style to the canonical internal style.
00171  * "Local style" means native path separators and "." for the empty path.
00172  *
00173  * Allocate the result in @a result_pool.
00174  *
00175  * @since New in 1.7.
00176  */
00177 const char *
00178 svn_relpath__internal_style(const char *relpath,
00179                             apr_pool_t *result_pool);
00180 
00181 
00182 /** Join a base dirent (@a base) with a component (@a component).
00183  *
00184  * If either @a base or @a component is the empty string, then the other
00185  * argument will be copied and returned.  If both are the empty string then
00186  * empty string is returned.
00187  *
00188  * If the @a component is an absolute dirent, then it is copied and returned.
00189  * The platform specific rules for joining paths are used to join the components.
00190  *
00191  * This function is NOT appropriate for native (local) file
00192  * dirents. Only for "internal" canonicalized dirents, since it uses '/'
00193  * for the separator.
00194  *
00195  * Allocate the result in @a result_pool.
00196  *
00197  * @since New in 1.6.
00198  */
00199 char *
00200 svn_dirent_join(const char *base,
00201                 const char *component,
00202                 apr_pool_t *result_pool);
00203 
00204 /** Join multiple components onto a @a base dirent. The components are
00205  * terminated by a @c NULL.
00206  *
00207  * If any component is the empty string, it will be ignored.
00208  *
00209  * If any component is an absolute dirent, then it resets the base and
00210  * further components will be appended to it.
00211  *
00212  * See svn_dirent_join() for further notes about joining dirents.
00213  *
00214  * Allocate the result in @a result_pool.
00215  *
00216  * @since New in 1.6.
00217  */
00218 char *
00219 svn_dirent_join_many(apr_pool_t *result_pool,
00220                      const char *base,
00221                      ...);
00222 
00223 /** Join a base relpath (@a base) with a component (@a component).
00224  * @a component need not be a single component.
00225  *
00226  * If either @a base or @a component is the empty path, then the other
00227  * argument will be copied and returned.  If both are the empty path the
00228  * empty path is returned.
00229  *
00230  * Allocate the result in @a result_pool.
00231  *
00232  * @since New in 1.7.
00233  */
00234 char *
00235 svn_relpath_join(const char *base,
00236                  const char *component,
00237                  apr_pool_t *result_pool);
00238 
00239 /** Gets the name of the specified canonicalized @a dirent as it is known
00240  * within its parent directory. If the @a dirent is root, return "". The
00241  * returned value will not have slashes in it.
00242  *
00243  * Example: svn_dirent_basename("/foo/bar") -> "bar"
00244  *
00245  * If @a result_pool is NULL, return a pointer to the basename in @a dirent,
00246  * otherwise allocate the result in @a result_pool.
00247  *
00248  * @note If an empty string is passed, then an empty string will be returned.
00249  *
00250  * @since New in 1.7.
00251  */
00252 const char *
00253 svn_dirent_basename(const char *dirent,
00254                     apr_pool_t *result_pool);
00255 
00256 /** Get the dirname of the specified canonicalized @a dirent, defined as
00257  * the dirent with its basename removed.
00258  *
00259  * If @a dirent is root  ("/", "X:/", "//server/share/") or "", it is returned
00260  * unchanged.
00261  *
00262  * Allocate the result in @a result_pool.
00263  *
00264  * @since New in 1.6.
00265  */
00266 char *
00267 svn_dirent_dirname(const char *dirent,
00268                    apr_pool_t *result_pool);
00269 
00270 /** Divide the canonicalized @a dirent into @a *dirpath and @a *base_name.
00271  *
00272  * If @a dirpath or @a base_name is NULL, then don't set that one.
00273  *
00274  * Either @a dirpath or @a base_name may be @a dirent's own address, but they
00275  * may not both be the same address, or the results are undefined.
00276  *
00277  * If @a dirent has two or more components, the separator between @a dirpath
00278  * and @a base_name is not included in either of the new names.
00279  *
00280  * Examples:
00281  *             - <pre>"/foo/bar/baz"  ==>  "/foo/bar" and "baz"</pre>
00282  *             - <pre>"/bar"          ==>  "/"  and "bar"</pre>
00283  *             - <pre>"/"             ==>  "/"  and ""</pre>
00284  *             - <pre>"bar"           ==>  ""   and "bar"</pre>
00285  *             - <pre>""              ==>  ""   and ""</pre>
00286  *  Windows:   - <pre>"X:/"           ==>  "X:/" and ""</pre>
00287  *             - <pre>"X:/foo"        ==>  "X:/" and "foo"</pre>
00288  *             - <pre>"X:foo"         ==>  "X:" and "foo"</pre>
00289  *  Posix:     - <pre>"X:foo"         ==>  ""   and "X:foo"</pre>
00290  *
00291  * Allocate the results in @a result_pool.
00292  *
00293  * @since New in 1.7.
00294  */
00295 void
00296 svn_dirent_split(const char **dirpath,
00297                  const char **base_name,
00298                  const char *dirent,
00299                  apr_pool_t *result_pool);
00300 
00301 /** Divide the canonicalized @a relpath into @a *dirpath and @a *base_name.
00302  *
00303  * If @a dirpath or @a base_name is NULL, then don't set that one.
00304  *
00305  * Either @a dirpath or @a base_name may be @a relpaths's own address, but
00306  * they may not both be the same address, or the results are undefined.
00307  *
00308  * If @a relpath has two or more components, the separator between @a dirpath
00309  * and @a base_name is not included in either of the new names.
00310  *
00311  *   examples:
00312  *             - <pre>"foo/bar/baz"  ==>  "foo/bar" and "baz"</pre>
00313  *             - <pre>"bar"          ==>  ""  and "bar"</pre>
00314  *             - <pre>""              ==>  ""   and ""</pre>
00315  *
00316  * Allocate the results in @a result_pool.
00317  *
00318  * @since New in 1.7.
00319  */
00320 void
00321 svn_relpath_split(const char **dirpath,
00322                   const char **base_name,
00323                   const char *relpath,
00324                   apr_pool_t *result_pool);
00325 
00326 /** Get the basename of the specified canonicalized @a relpath.  The
00327  * basename is defined as the last component of the relpath.  If the @a
00328  * relpath has only one component then that is returned. The returned
00329  * value will have no slashes in it.
00330  *
00331  * Example: svn_relpath_basename("/trunk/foo/bar") -> "bar"
00332  *
00333  * If @a result_pool is NULL, return a pointer to the basename in @a relpath,
00334  * otherwise allocate the result in @a result_pool.
00335  *
00336  * @note If an empty string is passed, then an empty string will be returned.
00337  *
00338  * @since New in 1.7.
00339  */
00340 const char *
00341 svn_relpath_basename(const char *relpath,
00342                      apr_pool_t *result_pool);
00343 
00344 /** Get the dirname of the specified canonicalized @a relpath, defined as
00345  * the relpath with its basename removed.
00346  *
00347  * If @a relpath is empty, "" is returned.
00348  *
00349  * Allocate the result in @a result_pool.
00350  *
00351  * @since New in 1.7.
00352  */
00353 char *
00354 svn_relpath_dirname(const char *relpath,
00355                     apr_pool_t *result_pool);
00356 
00357 
00358 /** Divide the canonicalized @a uri into a uri @a *dirpath and a
00359  * (URI-decoded) relpath @a *base_name.
00360  *
00361  * If @a dirpath or @a base_name is NULL, then don't set that one.
00362  *
00363  * Either @a dirpath or @a base_name may be @a uri's own address, but they
00364  * may not both be the same address, or the results are undefined.
00365  *
00366  * If @a uri has two or more components, the separator between @a dirpath
00367  * and @a base_name is not included in either of the new names.
00368  *
00369  * Examples:
00370  *   - <pre>"http://server/foo/bar"  ==>  "http://server/foo" and "bar"</pre>
00371  *
00372  * Allocate the result in @a result_pool.
00373  *
00374  * @since New in 1.7.
00375  */
00376 void
00377 svn_uri_split(const char **dirpath,
00378               const char **base_name,
00379               const char *uri,
00380               apr_pool_t *result_pool);
00381 
00382 /** Get the (URI-decoded) basename of the specified canonicalized @a
00383  * uri.  The basename is defined as the last component of the uri.  If
00384  * the @a uri is root, return "".  The returned value will have no
00385  * slashes in it.
00386  *
00387  * Example: svn_uri_basename("http://server/foo/bar") -> "bar"
00388  *
00389  * Allocate the result in @a result_pool.
00390  *
00391  * @since New in 1.7.
00392  */
00393 const char *
00394 svn_uri_basename(const char *uri,
00395                  apr_pool_t *result_pool);
00396 
00397 /** Get the dirname of the specified canonicalized @a uri, defined as
00398  * the uri with its basename removed.
00399  *
00400  * If @a uri is root (e.g. "http://server"), it is returned
00401  * unchanged.
00402  *
00403  * Allocate the result in @a result_pool.
00404  *
00405  * @since New in 1.7.
00406  */
00407 char *
00408 svn_uri_dirname(const char *uri,
00409                 apr_pool_t *result_pool);
00410 
00411 /** Return TRUE if @a dirent is considered absolute on the platform at
00412  * hand. E.g. '/foo' on Posix platforms or 'X:/foo', '//server/share/foo'
00413  * on Windows.
00414  *
00415  * @since New in 1.6.
00416  */
00417 svn_boolean_t
00418 svn_dirent_is_absolute(const char *dirent);
00419 
00420 /** Return TRUE if @a dirent is considered a root directory on the platform
00421  * at hand.
00422  * E.g.:
00423  *  On Posix:   '/'
00424  *  On Windows: '/', 'X:/', '//server/share', 'X:'
00425  *
00426  * Note that on Windows '/' and 'X:' are roots, but paths starting with this
00427  * root are not absolute.
00428  *
00429  * @since New in 1.5.
00430  */
00431 svn_boolean_t
00432 svn_dirent_is_root(const char *dirent,
00433                    apr_size_t len);
00434 
00435 /** Return TRUE if @a uri is a root URL (e.g., "http://server").
00436  *
00437  * @since New in 1.7
00438  */
00439 svn_boolean_t
00440 svn_uri_is_root(const char *uri,
00441                 apr_size_t len);
00442 
00443 /** Return a new dirent like @a dirent, but transformed such that some types
00444  * of dirent specification redundancies are removed.
00445  *
00446  * This involves:
00447  *   - collapsing redundant "/./" elements
00448  *   - removing multiple adjacent separator characters
00449  *   - removing trailing separator characters
00450  *   - converting the server name of a UNC path to lower case (on Windows)
00451  *   - converting a drive letter to upper case (on Windows)
00452  *
00453  * and possibly other semantically inoperative transformations.
00454  *
00455  * Allocate the result in @a result_pool.
00456  *
00457  * @since New in 1.6.
00458  */
00459 const char *
00460 svn_dirent_canonicalize(const char *dirent,
00461                         apr_pool_t *result_pool);
00462 
00463 
00464 /** Return a new relpath like @a relpath, but transformed such that some types
00465  * of relpath specification redundancies are removed.
00466  *
00467  * This involves:
00468  *   - collapsing redundant "/./" elements
00469  *   - removing multiple adjacent separator characters
00470  *   - removing trailing separator characters
00471  *
00472  * and possibly other semantically inoperative transformations.
00473  *
00474  * Allocate the result in @a result_pool.
00475  *
00476  * @since New in 1.7.
00477  */
00478 const char *
00479 svn_relpath_canonicalize(const char *relpath,
00480                          apr_pool_t *result_pool);
00481 
00482 
00483 /** Return a new uri like @a uri, but transformed such that some types
00484  * of uri specification redundancies are removed.
00485  *
00486  * This involves:
00487  *   - collapsing redundant "/./" elements
00488  *   - removing multiple adjacent separator characters
00489  *   - removing trailing separator characters
00490  *   - normalizing the escaping of the path component by unescaping
00491  *     characters that don't need escaping and escaping characters that do
00492  *     need escaping but weren't
00493  *   - removing the port number if it is the default port number (80 for
00494  *     http, 443 for https, 3690 for svn)
00495  *
00496  * and possibly other semantically inoperative transformations.
00497  *
00498  * Allocate the result in @a result_pool.
00499  *
00500  * @since New in 1.7.
00501  */
00502 const char *
00503 svn_uri_canonicalize(const char *uri,
00504                      apr_pool_t *result_pool);
00505 
00506 /** Return @c TRUE iff @a dirent is canonical.
00507  *
00508  * Use @a scratch_pool for temporary allocations.
00509  *
00510  * @note The test for canonicalization is currently defined as
00511  * "looks exactly the same as @c svn_dirent_canonicalize() would make
00512  * it look".
00513  *
00514  * @see svn_dirent_canonicalize()
00515  * @since New in 1.6.
00516  */
00517 svn_boolean_t
00518 svn_dirent_is_canonical(const char *dirent,
00519                         apr_pool_t *scratch_pool);
00520 
00521 /** Return @c TRUE iff @a relpath is canonical.
00522  *
00523  * @see svn_relpath_canonicalize()
00524  * @since New in 1.7.
00525  */
00526 svn_boolean_t
00527 svn_relpath_is_canonical(const char *relpath);
00528 
00529 /** Return @c TRUE iff @a uri is canonical.
00530  *
00531  * Use @a scratch_pool for temporary allocations.
00532  *
00533  * @see svn_uri_canonicalize()
00534  * @since New in 1.7.
00535  */
00536 svn_boolean_t
00537 svn_uri_is_canonical(const char *uri,
00538                      apr_pool_t *scratch_pool);
00539 
00540 /** Return the longest common dirent shared by two canonicalized dirents,
00541  * @a dirent1 and @a dirent2.  If there's no common ancestor, return the
00542  * empty path.
00543  *
00544  * Allocate the result in @a result_pool.
00545  *
00546  * @since New in 1.6.
00547  */
00548 char *
00549 svn_dirent_get_longest_ancestor(const char *dirent1,
00550                                 const char *dirent2,
00551                                 apr_pool_t *result_pool);
00552 
00553 /** Return the longest common path shared by two relative paths,
00554  * @a relpath1 and @a relpath2.  If there's no common ancestor, return the
00555  * empty path.
00556  *
00557  * Allocate the result in @a result_pool.
00558  *
00559  * @since New in 1.7.
00560  */
00561 char *
00562 svn_relpath_get_longest_ancestor(const char *relpath1,
00563                                  const char *relpath2,
00564                                  apr_pool_t *result_pool);
00565 
00566 /** Return the longest common path shared by two canonicalized uris,
00567  * @a uri1 and @a uri2.  If there's no common ancestor, return the
00568  * empty path.  In order for two URLs to have a common ancestor, they
00569  * must (a) have the same protocol (since two URLs with the same path
00570  * but different protocols may point at completely different
00571  * resources), and (b) share a common ancestor in their path
00572  * component, i.e. 'protocol://' is not a sufficient ancestor.
00573  *
00574  * Allocate the result in @a result_pool.
00575  *
00576  * @since New in 1.7.
00577  */
00578 char *
00579 svn_uri_get_longest_ancestor(const char *uri1,
00580                              const char *uri2,
00581                              apr_pool_t *result_pool);
00582 
00583 /** Convert @a relative canonicalized dirent to an absolute dirent and
00584  * return the results in @a *pabsolute.
00585  * Raise SVN_ERR_BAD_FILENAME if the absolute dirent cannot be determined.
00586  *
00587  * Allocate the result in @a result_pool.
00588  *
00589  * @since New in 1.6.
00590  */
00591 svn_error_t *
00592 svn_dirent_get_absolute(const char **pabsolute,
00593                         const char *relative,
00594                         apr_pool_t *result_pool);
00595 
00596 /** Similar to svn_dirent_skip_ancestor(), except that if @a child_dirent is
00597  * the same as @a parent_dirent, it is not considered a child, so the result
00598  * is @c NULL; an empty string is never returned.
00599  *
00600  * If @a result_pool is NULL, return a pointer into @a child_dirent, otherwise
00601  * allocate the result in @a result_pool.
00602  *
00603  * ### TODO: Deprecate, as the semantics are trivially
00604  * obtainable from *_skip_ancestor().
00605  *
00606  * @since New in 1.6.
00607  */
00608 const char *
00609 svn_dirent_is_child(const char *parent_dirent,
00610                     const char *child_dirent,
00611                     apr_pool_t *result_pool);
00612 
00613 /** Return TRUE if @a parent_dirent is an ancestor of @a child_dirent or
00614  * the dirents are equal, and FALSE otherwise.
00615  *
00616  * ### TODO: Deprecate, as the semantics are trivially
00617  * obtainable from *_skip_ancestor().
00618  *
00619  * @since New in 1.6.
00620  */
00621 svn_boolean_t
00622 svn_dirent_is_ancestor(const char *parent_dirent,
00623                        const char *child_dirent);
00624 
00625 /** Return TRUE if @a parent_uri is an ancestor of @a child_uri or
00626  * the uris are equal, and FALSE otherwise.
00627  */
00628 svn_boolean_t
00629 svn_uri__is_ancestor(const char *parent_uri,
00630                      const char *child_uri);
00631 
00632 
00633 /** Return the relative path part of @a child_dirent that is below
00634  * @a parent_dirent, or just "" if @a parent_dirent is equal to
00635  * @a child_dirent. If @a child_dirent is not below or equal to
00636  * @a parent_dirent, return NULL.
00637  *
00638  * If one of @a parent_dirent and @a child_dirent is absolute and
00639  * the other relative, return NULL.
00640  *
00641  * @since New in 1.7.
00642  */
00643 const char *
00644 svn_dirent_skip_ancestor(const char *parent_dirent,
00645                          const char *child_dirent);
00646 
00647 /** Return the relative path part of @a child_relpath that is below
00648  * @a parent_relpath, or just "" if @a parent_relpath is equal to
00649  * @a child_relpath. If @a child_relpath is not below @a parent_relpath,
00650  * return NULL.
00651  *
00652  * @since New in 1.7.
00653  */
00654 const char *
00655 svn_relpath_skip_ancestor(const char *parent_relpath,
00656                           const char *child_relpath);
00657 
00658 /** Return the URI-decoded relative path of @a child_uri that is below
00659  * @a parent_uri, or just "" if @a parent_uri is equal to @a child_uri. If
00660  * @a child_uri is not below @a parent_uri, return NULL.
00661  *
00662  * Allocate the result in @a result_pool.
00663  *
00664  * @since New in 1.7.
00665  */
00666 const char *
00667 svn_uri_skip_ancestor(const char *parent_uri,
00668                       const char *child_uri,
00669                       apr_pool_t *result_pool);
00670 
00671 /** Find the common prefix of the canonicalized dirents in @a targets
00672  * (an array of <tt>const char *</tt>'s), and remove redundant dirents if @a
00673  * remove_redundancies is TRUE.
00674  *
00675  *   - Set @a *pcommon to the absolute dirent of the dirent common to
00676  *     all of the targets.  If the targets have no common prefix (e.g.
00677  *     "C:/file" and "D:/file" on Windows), set @a *pcommon to the empty
00678  *     string.
00679  *
00680  *   - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets
00681  *     to an array of targets relative to @a *pcommon, and if
00682  *     @a remove_redundancies is TRUE, omit any dirents that are
00683  *     descendants of another dirent in @a targets.  If *pcommon
00684  *     is empty, @a *pcondensed_targets will contain absolute dirents;
00685  *     redundancies can still be removed.  If @a pcondensed_targets is NULL,
00686  *     leave it alone.
00687  *
00688  * Else if there is exactly one target, then
00689  *
00690  *   - Set @a *pcommon to that target, and
00691  *
00692  *   - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets
00693  *     to an array containing zero elements.  Else if
00694  *     @a pcondensed_targets is NULL, leave it alone.
00695  *
00696  * If there are no items in @a targets, set @a *pcommon and (if
00697  * applicable) @a *pcondensed_targets to @c NULL.
00698  *
00699  * Allocate the results in @a result_pool. Use @a scratch_pool for
00700  * temporary allocations.
00701  *
00702  * @since New in 1.7.
00703  */
00704 svn_error_t *
00705 svn_dirent_condense_targets(const char **pcommon,
00706                             apr_array_header_t **pcondensed_targets,
00707                             const apr_array_header_t *targets,
00708                             svn_boolean_t remove_redundancies,
00709                             apr_pool_t *result_pool,
00710                             apr_pool_t *scratch_pool);
00711 
00712 /** Find the common prefix of the canonicalized uris in @a targets
00713  * (an array of <tt>const char *</tt>'s), and remove redundant uris if @a
00714  * remove_redundancies is TRUE.
00715  *
00716  *   - Set @a *pcommon to the common base uri of all of the targets.
00717  *     If the targets have no common prefix (e.g. "http://srv1/file"
00718  *     and "http://srv2/file"), set @a *pcommon to the empty
00719  *     string.
00720  *
00721  *   - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets
00722  *     to an array of URI-decoded targets relative to @a *pcommon, and
00723  *     if @a remove_redundancies is TRUE, omit any uris that are
00724  *     descendants of another uri in @a targets.  If *pcommon is
00725  *     empty, @a *pcondensed_targets will contain absolute uris;
00726  *     redundancies can still be removed.  If @a pcondensed_targets is
00727  *     NULL, leave it alone.
00728  *
00729  * Else if there is exactly one target, then
00730  *
00731  *   - Set @a *pcommon to that target, and
00732  *
00733  *   - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets
00734  *     to an array containing zero elements.  Else if
00735  *     @a pcondensed_targets is NULL, leave it alone.
00736  *
00737  * If there are no items in @a targets, set @a *pcommon and (if
00738  * applicable) @a *pcondensed_targets to @c NULL.
00739  *
00740  * Allocate the results in @a result_pool. Use @a scratch_pool for
00741  * temporary allocations.
00742  *
00743  * @since New in 1.7.
00744  */
00745 svn_error_t *
00746 svn_uri_condense_targets(const char **pcommon,
00747                          apr_array_header_t **pcondensed_targets,
00748                          const apr_array_header_t *targets,
00749                          svn_boolean_t remove_redundancies,
00750                          apr_pool_t *result_pool,
00751                          apr_pool_t *scratch_pool);
00752 
00753 /** Join @a path onto @a base_path, checking that @a path does not attempt
00754  * to traverse above @a base_path. If @a path or any ".." component within
00755  * it resolves to a path above @a base_path, or if @a path is an absolute
00756  * path, then set @a *under_root to @c FALSE. Otherwise, set @a *under_root
00757  * to @c TRUE and, if @a result_path is not @c NULL, set @a *result_path to
00758  * the resulting path.
00759  *
00760  * @a path need not be canonical. @a base_path must be canonical and
00761  * @a *result_path will be canonical.
00762  *
00763  * Allocate the result in @a result_pool.
00764  *
00765  * @note Use of this function is strongly encouraged. Do not roll your own.
00766  * (http://cve.mitre.org/cgi-bin/cvename.cgi?name=2007-3846)
00767  *
00768  * @since New in 1.7.
00769  */
00770 svn_error_t *
00771 svn_dirent_is_under_root(svn_boolean_t *under_root,
00772                          const char **result_path,
00773                          const char *base_path,
00774                          const char *path,
00775                          apr_pool_t *result_pool);
00776 
00777 /** Set @a *dirent to the path corresponding to the file:// URL @a url, using
00778  * the platform-specific file:// rules.
00779  *
00780  * Allocate the result in @a result_pool.
00781  *
00782  * @since New in 1.7.
00783  */
00784 svn_error_t *
00785 svn_uri_get_dirent_from_file_url(const char **dirent,
00786                                  const char *url,
00787                                  apr_pool_t *result_pool);
00788 
00789 /** Set @a *url to a file:// URL, corresponding to @a dirent using the
00790  * platform specific dirent and file:// rules.
00791  *
00792  * Allocate the result in @a result_pool.
00793  *
00794  * @since New in 1.7.
00795  */
00796 svn_error_t *
00797 svn_uri_get_file_url_from_dirent(const char **url,
00798                                  const char *dirent,
00799                                  apr_pool_t *result_pool);
00800 
00801 #ifdef __cplusplus
00802 }
00803 #endif /* __cplusplus */
00804 
00805 #endif /* SVN_DIRENT_URI_H */

Generated on Thu Apr 2 16:10:40 2015 for Subversion by  doxygen 1.4.7