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 SVN_VA_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 ...) SVN_NEEDS_SENTINEL_NULL; 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 /** Return a maximum of @a max_components components of @a relpath. This is 00358 * an efficient way of calling svn_relpath_dirname() multiple times until only 00359 * a specific number of components is left. 00360 * 00361 * Allocate the result in @a result_pool (or statically in case of 0) 00362 * 00363 * @since New in 1.9. 00364 */ 00365 const char * 00366 svn_relpath_prefix(const char *relpath, 00367 int max_components, 00368 apr_pool_t *result_pool); 00369 00370 00371 /** Divide the canonicalized @a uri into a uri @a *dirpath and a 00372 * (URI-decoded) relpath @a *base_name. 00373 * 00374 * If @a dirpath or @a base_name is NULL, then don't set that one. 00375 * 00376 * Either @a dirpath or @a base_name may be @a uri's own address, but they 00377 * may not both be the same address, or the results are undefined. 00378 * 00379 * If @a uri has two or more components, the separator between @a dirpath 00380 * and @a base_name is not included in either of the new names. 00381 * 00382 * Examples: 00383 * - <pre>"http://server/foo/bar" ==> "http://server/foo" and "bar"</pre> 00384 * 00385 * Allocate the result in @a result_pool. 00386 * 00387 * @since New in 1.7. 00388 */ 00389 void 00390 svn_uri_split(const char **dirpath, 00391 const char **base_name, 00392 const char *uri, 00393 apr_pool_t *result_pool); 00394 00395 /** Get the (URI-decoded) basename of the specified canonicalized @a 00396 * uri. The basename is defined as the last component of the uri. If 00397 * the @a uri is root, return "". The returned value will have no 00398 * slashes in it. 00399 * 00400 * Example: svn_uri_basename("http://server/foo/bar") -> "bar" 00401 * 00402 * Allocate the result in @a result_pool. 00403 * 00404 * @since New in 1.7. 00405 */ 00406 const char * 00407 svn_uri_basename(const char *uri, 00408 apr_pool_t *result_pool); 00409 00410 /** Get the dirname of the specified canonicalized @a uri, defined as 00411 * the uri with its basename removed. 00412 * 00413 * If @a uri is root (e.g. "http://server"), it is returned 00414 * unchanged. 00415 * 00416 * Allocate the result in @a result_pool. 00417 * 00418 * @since New in 1.7. 00419 */ 00420 char * 00421 svn_uri_dirname(const char *uri, 00422 apr_pool_t *result_pool); 00423 00424 /** Return TRUE if @a dirent is considered absolute on the platform at 00425 * hand. E.g. '/foo' on Posix platforms or 'X:/foo', '//server/share/foo' 00426 * on Windows. 00427 * 00428 * @since New in 1.6. 00429 */ 00430 svn_boolean_t 00431 svn_dirent_is_absolute(const char *dirent); 00432 00433 /** Return TRUE if @a dirent is considered a root directory on the platform 00434 * at hand. 00435 * E.g.: 00436 * On Posix: '/' 00437 * On Windows: '/', 'X:/', '//server/share', 'X:' 00438 * 00439 * Note that on Windows '/' and 'X:' are roots, but paths starting with this 00440 * root are not absolute. 00441 * 00442 * @since New in 1.5. 00443 */ 00444 svn_boolean_t 00445 svn_dirent_is_root(const char *dirent, 00446 apr_size_t len); 00447 00448 /** Return TRUE if @a uri is a root URL (e.g., "http://server"). 00449 * 00450 * @since New in 1.7 00451 */ 00452 svn_boolean_t 00453 svn_uri_is_root(const char *uri, 00454 apr_size_t len); 00455 00456 /** Return a new dirent like @a dirent, but transformed such that some types 00457 * of dirent specification redundancies are removed. 00458 * 00459 * This involves: 00460 * - collapsing redundant "/./" elements 00461 * - removing multiple adjacent separator characters 00462 * - removing trailing separator characters 00463 * - converting the server name of a UNC path to lower case (on Windows) 00464 * - converting a drive letter to upper case (on Windows) 00465 * 00466 * and possibly other semantically inoperative transformations. 00467 * 00468 * Allocate the result in @a result_pool. 00469 * 00470 * @since New in 1.6. 00471 */ 00472 const char * 00473 svn_dirent_canonicalize(const char *dirent, 00474 apr_pool_t *result_pool); 00475 00476 00477 /** Return a new relpath like @a relpath, but transformed such that some types 00478 * of relpath specification redundancies are removed. 00479 * 00480 * This involves: 00481 * - collapsing redundant "/./" elements 00482 * - removing multiple adjacent separator characters 00483 * - removing trailing separator characters 00484 * 00485 * and possibly other semantically inoperative transformations. 00486 * 00487 * Allocate the result in @a result_pool. 00488 * 00489 * @since New in 1.7. 00490 */ 00491 const char * 00492 svn_relpath_canonicalize(const char *relpath, 00493 apr_pool_t *result_pool); 00494 00495 00496 /** Return a new uri like @a uri, but transformed such that some types 00497 * of uri specification redundancies are removed. 00498 * 00499 * This involves: 00500 * - collapsing redundant "/./" elements 00501 * - removing multiple adjacent separator characters 00502 * - removing trailing separator characters 00503 * - normalizing the escaping of the path component by unescaping 00504 * characters that don't need escaping and escaping characters that do 00505 * need escaping but weren't 00506 * - removing the port number if it is the default port number (80 for 00507 * http, 443 for https, 3690 for svn) 00508 * 00509 * and possibly other semantically inoperative transformations. 00510 * 00511 * Allocate the result in @a result_pool. 00512 * 00513 * @since New in 1.7. 00514 */ 00515 const char * 00516 svn_uri_canonicalize(const char *uri, 00517 apr_pool_t *result_pool); 00518 00519 /** Return @c TRUE iff @a dirent is canonical. 00520 * 00521 * Use @a scratch_pool for temporary allocations. 00522 * 00523 * @note The test for canonicalization is currently defined as 00524 * "looks exactly the same as @c svn_dirent_canonicalize() would make 00525 * it look". 00526 * 00527 * @see svn_dirent_canonicalize() 00528 * @since New in 1.6. 00529 */ 00530 svn_boolean_t 00531 svn_dirent_is_canonical(const char *dirent, 00532 apr_pool_t *scratch_pool); 00533 00534 /** Return @c TRUE iff @a relpath is canonical. 00535 * 00536 * @see svn_relpath_canonicalize() 00537 * @since New in 1.7. 00538 */ 00539 svn_boolean_t 00540 svn_relpath_is_canonical(const char *relpath); 00541 00542 /** Return @c TRUE iff @a uri is canonical. 00543 * 00544 * Use @a scratch_pool for temporary allocations. 00545 * 00546 * @see svn_uri_canonicalize() 00547 * @since New in 1.7. 00548 */ 00549 svn_boolean_t 00550 svn_uri_is_canonical(const char *uri, 00551 apr_pool_t *scratch_pool); 00552 00553 /** Return the longest common dirent shared by two canonicalized dirents, 00554 * @a dirent1 and @a dirent2. 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.6. 00560 */ 00561 char * 00562 svn_dirent_get_longest_ancestor(const char *dirent1, 00563 const char *dirent2, 00564 apr_pool_t *result_pool); 00565 00566 /** Return the longest common path shared by two relative paths, 00567 * @a relpath1 and @a relpath2. If there's no common ancestor, return the 00568 * empty path. 00569 * 00570 * Allocate the result in @a result_pool. 00571 * 00572 * @since New in 1.7. 00573 */ 00574 char * 00575 svn_relpath_get_longest_ancestor(const char *relpath1, 00576 const char *relpath2, 00577 apr_pool_t *result_pool); 00578 00579 /** Return the longest common path shared by two canonicalized uris, 00580 * @a uri1 and @a uri2. If there's no common ancestor, return the 00581 * empty path. In order for two URLs to have a common ancestor, they 00582 * must (a) have the same protocol (since two URLs with the same path 00583 * but different protocols may point at completely different 00584 * resources), and (b) share a common ancestor in their path 00585 * component, i.e. 'protocol://' is not a sufficient ancestor. 00586 * 00587 * Allocate the result in @a result_pool. 00588 * 00589 * @since New in 1.7. 00590 */ 00591 char * 00592 svn_uri_get_longest_ancestor(const char *uri1, 00593 const char *uri2, 00594 apr_pool_t *result_pool); 00595 00596 /** Convert @a relative canonicalized dirent to an absolute dirent and 00597 * return the results in @a *pabsolute. 00598 * Raise SVN_ERR_BAD_FILENAME if the absolute dirent cannot be determined. 00599 * 00600 * Allocate the result in @a result_pool. 00601 * 00602 * @since New in 1.6. 00603 */ 00604 svn_error_t * 00605 svn_dirent_get_absolute(const char **pabsolute, 00606 const char *relative, 00607 apr_pool_t *result_pool); 00608 00609 /** Similar to svn_dirent_skip_ancestor(), except that if @a child_dirent is 00610 * the same as @a parent_dirent, it is not considered a child, so the result 00611 * is @c NULL; an empty string is never returned. 00612 * 00613 * If @a result_pool is NULL, return a pointer into @a child_dirent, otherwise 00614 * allocate the result in @a result_pool. 00615 * 00616 * ### TODO: Deprecate, as the semantics are trivially 00617 * obtainable from *_skip_ancestor(). 00618 * 00619 * @since New in 1.6. 00620 */ 00621 const char * 00622 svn_dirent_is_child(const char *parent_dirent, 00623 const char *child_dirent, 00624 apr_pool_t *result_pool); 00625 00626 /** Return TRUE if @a parent_dirent is an ancestor of @a child_dirent or 00627 * the dirents are equal, and FALSE otherwise. 00628 * 00629 * ### TODO: Deprecate, as the semantics are trivially 00630 * obtainable from *_skip_ancestor(). 00631 * 00632 * @since New in 1.6. 00633 */ 00634 svn_boolean_t 00635 svn_dirent_is_ancestor(const char *parent_dirent, 00636 const char *child_dirent); 00637 00638 /** Return TRUE if @a parent_uri is an ancestor of @a child_uri or 00639 * the uris are equal, and FALSE otherwise. 00640 */ 00641 svn_boolean_t 00642 svn_uri__is_ancestor(const char *parent_uri, 00643 const char *child_uri); 00644 00645 00646 /** Return the relative path part of @a child_dirent that is below 00647 * @a parent_dirent, or just "" if @a parent_dirent is equal to 00648 * @a child_dirent. If @a child_dirent is not below or equal to 00649 * @a parent_dirent, return NULL. 00650 * 00651 * If one of @a parent_dirent and @a child_dirent is absolute and 00652 * the other relative, return NULL. 00653 * 00654 * @since New in 1.7. 00655 */ 00656 const char * 00657 svn_dirent_skip_ancestor(const char *parent_dirent, 00658 const char *child_dirent); 00659 00660 /** Return the relative path part of @a child_relpath that is below 00661 * @a parent_relpath, or just "" if @a parent_relpath is equal to 00662 * @a child_relpath. If @a child_relpath is not below @a parent_relpath, 00663 * return NULL. 00664 * 00665 * @since New in 1.7. 00666 */ 00667 const char * 00668 svn_relpath_skip_ancestor(const char *parent_relpath, 00669 const char *child_relpath); 00670 00671 /** Return the URI-decoded relative path of @a child_uri that is below 00672 * @a parent_uri, or just "" if @a parent_uri is equal to @a child_uri. If 00673 * @a child_uri is not below @a parent_uri, return NULL. 00674 * 00675 * Allocate the result in @a result_pool. 00676 * 00677 * @since New in 1.7. 00678 */ 00679 const char * 00680 svn_uri_skip_ancestor(const char *parent_uri, 00681 const char *child_uri, 00682 apr_pool_t *result_pool); 00683 00684 /** Find the common prefix of the canonicalized dirents in @a targets 00685 * (an array of <tt>const char *</tt>'s), and remove redundant dirents if @a 00686 * remove_redundancies is TRUE. 00687 * 00688 * - Set @a *pcommon to the absolute dirent of the dirent common to 00689 * all of the targets. If the targets have no common prefix (e.g. 00690 * "C:/file" and "D:/file" on Windows), set @a *pcommon to the empty 00691 * string. 00692 * 00693 * - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets 00694 * to an array of targets relative to @a *pcommon, and if 00695 * @a remove_redundancies is TRUE, omit any dirents that are 00696 * descendants of another dirent in @a targets. If *pcommon 00697 * is empty, @a *pcondensed_targets will contain absolute dirents; 00698 * redundancies can still be removed. If @a pcondensed_targets is NULL, 00699 * leave it alone. 00700 * 00701 * Else if there is exactly one target, then 00702 * 00703 * - Set @a *pcommon to that target, and 00704 * 00705 * - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets 00706 * to an array containing zero elements. Else if 00707 * @a pcondensed_targets is NULL, leave it alone. 00708 * 00709 * If there are no items in @a targets, set @a *pcommon and (if 00710 * applicable) @a *pcondensed_targets to @c NULL. 00711 * 00712 * Allocate the results in @a result_pool. Use @a scratch_pool for 00713 * temporary allocations. 00714 * 00715 * @since New in 1.7. 00716 */ 00717 svn_error_t * 00718 svn_dirent_condense_targets(const char **pcommon, 00719 apr_array_header_t **pcondensed_targets, 00720 const apr_array_header_t *targets, 00721 svn_boolean_t remove_redundancies, 00722 apr_pool_t *result_pool, 00723 apr_pool_t *scratch_pool); 00724 00725 /** Find the common prefix of the canonicalized uris in @a targets 00726 * (an array of <tt>const char *</tt>'s), and remove redundant uris if @a 00727 * remove_redundancies is TRUE. 00728 * 00729 * - Set @a *pcommon to the common base uri of all of the targets. 00730 * If the targets have no common prefix (e.g. "http://srv1/file" 00731 * and "http://srv2/file"), set @a *pcommon to the empty 00732 * string. 00733 * 00734 * - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets 00735 * to an array of URI-decoded targets relative to @a *pcommon, and 00736 * if @a remove_redundancies is TRUE, omit any uris that are 00737 * descendants of another uri in @a targets. If *pcommon is 00738 * empty, @a *pcondensed_targets will contain absolute uris; 00739 * redundancies can still be removed. If @a pcondensed_targets is 00740 * NULL, leave it alone. 00741 * 00742 * Else if there is exactly one target, then 00743 * 00744 * - Set @a *pcommon to that target, and 00745 * 00746 * - If @a pcondensed_targets is non-NULL, set @a *pcondensed_targets 00747 * to an array containing zero elements. Else if 00748 * @a pcondensed_targets is NULL, leave it alone. 00749 * 00750 * If there are no items in @a targets, set @a *pcommon and (if 00751 * applicable) @a *pcondensed_targets to @c NULL. 00752 * 00753 * Allocate the results in @a result_pool. Use @a scratch_pool for 00754 * temporary allocations. 00755 * 00756 * @since New in 1.7. 00757 */ 00758 svn_error_t * 00759 svn_uri_condense_targets(const char **pcommon, 00760 apr_array_header_t **pcondensed_targets, 00761 const apr_array_header_t *targets, 00762 svn_boolean_t remove_redundancies, 00763 apr_pool_t *result_pool, 00764 apr_pool_t *scratch_pool); 00765 00766 /** Join @a path onto @a base_path, checking that @a path does not attempt 00767 * to traverse above @a base_path. If @a path or any ".." component within 00768 * it resolves to a path above @a base_path, or if @a path is an absolute 00769 * path, then set @a *under_root to @c FALSE. Otherwise, set @a *under_root 00770 * to @c TRUE and, if @a result_path is not @c NULL, set @a *result_path to 00771 * the resulting path. 00772 * 00773 * @a path need not be canonical. @a base_path must be canonical and 00774 * @a *result_path will be canonical. 00775 * 00776 * Allocate the result in @a result_pool. 00777 * 00778 * @note Use of this function is strongly encouraged. Do not roll your own. 00779 * (http://cve.mitre.org/cgi-bin/cvename.cgi?name=2007-3846) 00780 * 00781 * @since New in 1.7. 00782 */ 00783 svn_error_t * 00784 svn_dirent_is_under_root(svn_boolean_t *under_root, 00785 const char **result_path, 00786 const char *base_path, 00787 const char *path, 00788 apr_pool_t *result_pool); 00789 00790 /** Set @a *dirent to the path corresponding to the file:// URL @a url, using 00791 * the platform-specific file:// rules. 00792 * 00793 * Allocate the result in @a result_pool. 00794 * 00795 * @since New in 1.7. 00796 */ 00797 svn_error_t * 00798 svn_uri_get_dirent_from_file_url(const char **dirent, 00799 const char *url, 00800 apr_pool_t *result_pool); 00801 00802 /** Set @a *url to a file:// URL, corresponding to @a dirent using the 00803 * platform specific dirent and file:// rules. 00804 * 00805 * Allocate the result in @a result_pool. 00806 * 00807 * @since New in 1.7. 00808 */ 00809 svn_error_t * 00810 svn_uri_get_file_url_from_dirent(const char **url, 00811 const char *dirent, 00812 apr_pool_t *result_pool); 00813 00814 #ifdef __cplusplus 00815 } 00816 #endif /* __cplusplus */ 00817 00818 #endif /* SVN_DIRENT_URI_H */
1.6.1