Subversion
|
A library to manipulate URIs, relative paths and directory entries. More...
Go to the source code of this file.
Functions | |
const char * | svn_dirent_internal_style (const char *dirent, apr_pool_t *pool) |
Convert dirent from the local style to the canonical internal style. | |
const char * | svn_dirent_local_style (const char *dirent, apr_pool_t *pool) |
Convert dirent from the internal style to the local style. | |
const char * | svn_relpath__internal_style (const char *relpath, apr_pool_t *pool) |
Convert relpath from the local style to the canonical internal style. | |
char * | svn_dirent_join (const char *base, const char *component, apr_pool_t *pool) |
Join a base dirent (base) with a component (component), allocated in pool. | |
char * | svn_dirent_join_many (apr_pool_t *pool, const char *base,...) |
Join multiple components onto a base dirent, allocated in pool. | |
char * | svn_relpath_join (const char *base, const char *component, apr_pool_t *pool) |
Join a base relpath (base) with a component (component), allocating the result in pool. | |
const char * | svn_dirent_basename (const char *dirent, apr_pool_t *pool) |
Gets the name of the specified canonicalized dirent as it is known within its parent directory. | |
char * | svn_dirent_dirname (const char *dirent, apr_pool_t *pool) |
Get the dirname of the specified canonicalized dirent, defined as the dirent with its basename removed. | |
void | svn_dirent_split (const char **dirpath, const char **base_name, const char *dirent, apr_pool_t *pool) |
Divide the canonicalized dirent into *dirpath and *base_name, allocated in pool. | |
void | svn_relpath_split (const char **dirpath, const char **base_name, const char *relpath, apr_pool_t *pool) |
Divide the canonicalized relpath into *dirpath and *base_name, allocated in pool. | |
const char * | svn_relpath_basename (const char *relpath, apr_pool_t *pool) |
Get the basename of the specified canonicalized relpath. | |
char * | svn_relpath_dirname (const char *relpath, apr_pool_t *pool) |
Get the dirname of the specified canonicalized relpath, defined as the relpath with its basename removed. | |
void | svn_uri_split (const char **dirpath, const char **base_name, const char *uri, apr_pool_t *pool) |
Divide the canonicalized uri into a uri *dirpath and a (URI-decoded) relpath *base_name, allocated in pool. | |
const char * | svn_uri_basename (const char *uri, apr_pool_t *pool) |
Get the (URI-decoded) basename of the specified canonicalized uri. | |
char * | svn_uri_dirname (const char *uri, apr_pool_t *pool) |
Get the dirname of the specified canonicalized uri, defined as the uri with its basename removed. | |
svn_boolean_t | svn_dirent_is_absolute (const char *dirent) |
Return TRUE if dirent is considered absolute on the platform at hand. | |
svn_boolean_t | svn_dirent_is_root (const char *dirent, apr_size_t len) |
Return TRUE if dirent is considered a root directory on the platform at hand. | |
svn_boolean_t | svn_uri_is_root (const char *uri, apr_size_t len) |
Return TRUE if uri is a root URL (e.g., "http://server"). | |
const char * | svn_dirent_canonicalize (const char *dirent, apr_pool_t *pool) |
Return a new dirent like dirent, but transformed such that some types of dirent specification redundancies are removed. | |
const char * | svn_relpath_canonicalize (const char *relpath, apr_pool_t *pool) |
Return a new relpath like relpath, but transformed such that some types of relpath specification redundancies are removed. | |
const char * | svn_uri_canonicalize (const char *uri, apr_pool_t *pool) |
Return a new uri like uri, but transformed such that some types of uri specification redundancies are removed. | |
svn_boolean_t | svn_dirent_is_canonical (const char *dirent, apr_pool_t *pool) |
Return TRUE iff dirent is canonical. | |
svn_boolean_t | svn_relpath_is_canonical (const char *relpath) |
Return TRUE iff relpath is canonical. | |
svn_boolean_t | svn_uri_is_canonical (const char *uri, apr_pool_t *pool) |
Return TRUE iff uri is canonical. | |
char * | svn_dirent_get_longest_ancestor (const char *dirent1, const char *dirent2, apr_pool_t *pool) |
Return the longest common dirent shared by two canonicalized dirents, dirent1 and dirent2. | |
char * | svn_relpath_get_longest_ancestor (const char *relpath1, const char *relpath2, apr_pool_t *pool) |
Return the longest common path shared by two relative paths, relpath1 and relpath2. | |
char * | svn_uri_get_longest_ancestor (const char *uri1, const char *uri2, apr_pool_t *pool) |
Return the longest common path shared by two canonicalized uris, uri1 and uri2. | |
svn_error_t * | svn_dirent_get_absolute (const char **pabsolute, const char *relative, apr_pool_t *pool) |
Convert relative canonicalized dirent to an absolute dirent and return the results in *pabsolute, allocated in pool. | |
const char * | svn_uri__is_child (const char *parent_uri, const char *child_uri, apr_pool_t *pool) |
Similar to svn_uri_skip_ancestor(), except that if child_uri is the same as parent_uri, it is not considered a child, so the result is NULL ; an empty string is never returned. | |
const char * | svn_dirent_is_child (const char *parent_dirent, const char *child_dirent, apr_pool_t *pool) |
Similar to svn_dirent_skip_ancestor(), except that if child_dirent is the same as parent_dirent, it is not considered a child, so the result is NULL ; an empty string is never returned. | |
const char * | svn_relpath__is_child (const char *parent_relpath, const char *child_relpath, apr_pool_t *pool) |
Similar to svn_relpath_skip_ancestor(), except that if child_relpath is the same as parent_relpath, it is not considered a child, so the result is NULL ; an empty string is never returned. | |
svn_boolean_t | svn_dirent_is_ancestor (const char *parent_dirent, const char *child_dirent) |
Return TRUE if parent_dirent is an ancestor of child_dirent or the dirents are equal, and FALSE otherwise. | |
svn_boolean_t | svn_relpath__is_ancestor (const char *parent_relpath, const char *child_relpath) |
Return TRUE if parent_relpath is an ancestor of child_relpath or the relpaths are equal, and FALSE otherwise. | |
svn_boolean_t | svn_uri__is_ancestor (const char *parent_uri, const char *child_uri) |
Return TRUE if parent_uri is an ancestor of child_uri or the uris are equal, and FALSE otherwise. | |
const char * | svn_dirent_skip_ancestor (const char *parent_dirent, const char *child_dirent) |
Return the relative path part of child_dirent that is below parent_dirent, or just "" if parent_dirent is equal to child_dirent. | |
const char * | svn_relpath_skip_ancestor (const char *parent_relpath, const char *child_relpath) |
Return the relative path part of child_relpath that is below parent_relpath, or just "" if parent_relpath is equal to child_relpath. | |
const char * | svn_uri_skip_ancestor (const char *parent_uri, const char *child_uri, apr_pool_t *result_pool) |
Return the URI-decoded relative path of child_uri that is below parent_uri, or just "" if parent_uri is equal to child_uri. | |
svn_error_t * | svn_dirent_condense_targets (const char **pcommon, apr_array_header_t **pcondensed_targets, const apr_array_header_t *targets, svn_boolean_t remove_redundancies, apr_pool_t *result_pool, apr_pool_t *scratch_pool) |
Find the common prefix of the canonicalized dirents in targets (an array of const char * 's), and remove redundant dirents if remove_redundancies is TRUE. | |
svn_error_t * | svn_uri_condense_targets (const char **pcommon, apr_array_header_t **pcondensed_targets, const apr_array_header_t *targets, svn_boolean_t remove_redundancies, apr_pool_t *result_pool, apr_pool_t *scratch_pool) |
Find the common prefix of the canonicalized uris in targets (an array of const char * 's), and remove redundant uris if remove_redundancies is TRUE. | |
svn_error_t * | svn_dirent_is_under_root (svn_boolean_t *under_root, const char **result_path, const char *base_path, const char *path, apr_pool_t *result_pool) |
Join path onto base_path, checking that path does not attempt to traverse above base_path. | |
svn_error_t * | svn_uri_get_dirent_from_file_url (const char **dirent, const char *url, apr_pool_t *pool) |
Set *dirent to the path corresponding to the file:// URL url, using the platform-specific file:// rules. | |
svn_error_t * | svn_uri_get_file_url_from_dirent (const char **url, const char *dirent, apr_pool_t *pool) |
Set *url to a file:// URL, corresponding to dirent using the platform specific dirent and file:// rules. |
A library to manipulate URIs, relative paths and directory entries.
This library makes a clear distinction between several path formats:
This distinction is needed because on Windows we have to handle some dirents and URIs differently. Since it's not possible to determine from the path string if it's a dirent or a URI, it's up to the API user to make this choice. See also issue #2028.
All of these functions expect paths passed into them to be in canonical form, except:
svn_dirent_canonicalize()
svn_dirent_is_canonical()
svn_dirent_internal_style()
svn_relpath_canonicalize()
svn_relpath_is_canonical()
svn_relpath__internal_style()
svn_uri_canonicalize()
svn_uri_is_canonical()
The Subversion codebase also recognizes some other classes of path:
So, which path API is appropriate for your use-case?
When translating between local paths (dirents) and uris code should always go via the relative path format, perhaps by truncating a parent portion from a path with svn_*_skip_ancestor(), or by converting portions to basenames and then joining to existing paths.
SECURITY WARNING: If a path that is received from an untrusted source -- such as from the network -- is converted to a dirent it should be tested with svn_dirent_is_under_root() before you can assume the path to be a safe local path.
Definition in file svn_dirent_uri.h.
const char* svn_dirent_basename | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Gets the name of the specified canonicalized dirent as it is known within its parent directory.
If the dirent is root, return "". The returned value will not have slashes in it.
Example: svn_dirent_basename("/foo/bar") -> "bar"
The returned basename will be allocated in pool. If pool is NULL a pointer to the basename in dirent is returned.
const char* svn_dirent_canonicalize | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Return a new dirent like dirent, but transformed such that some types of dirent specification redundancies are removed.
This involves:
and possibly other semantically inoperative transformations.
The returned dirent may be allocated statically or from pool.
svn_error_t* svn_dirent_condense_targets | ( | const char ** | pcommon, |
apr_array_header_t ** | pcondensed_targets, | ||
const apr_array_header_t * | targets, | ||
svn_boolean_t | remove_redundancies, | ||
apr_pool_t * | result_pool, | ||
apr_pool_t * | scratch_pool | ||
) |
Find the common prefix of the canonicalized dirents in targets (an array of const char *
's), and remove redundant dirents if remove_redundancies is TRUE.
Else if there is exactly one target, then
If there are no items in targets, set *pcommon and (if applicable) *pcondensed_targets to NULL
.
Allocates *pcommon and *targets in result_pool. All intermediate allocations will be performed in scratch_pool.
char* svn_dirent_dirname | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Get the dirname of the specified canonicalized dirent, defined as the dirent with its basename removed.
If dirent is root ("/", "X:/", "//server/share/") or "", it is returned unchanged.
The returned dirname will be allocated in pool.
svn_error_t* svn_dirent_get_absolute | ( | const char ** | pabsolute, |
const char * | relative, | ||
apr_pool_t * | pool | ||
) |
Convert relative canonicalized dirent to an absolute dirent and return the results in *pabsolute, allocated in pool.
Raise SVN_ERR_BAD_FILENAME if the absolute dirent cannot be determined.
char* svn_dirent_get_longest_ancestor | ( | const char * | dirent1, |
const char * | dirent2, | ||
apr_pool_t * | pool | ||
) |
Return the longest common dirent shared by two canonicalized dirents, dirent1 and dirent2.
If there's no common ancestor, return the empty path.
const char* svn_dirent_internal_style | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Convert dirent from the local style to the canonical internal style.
"Local style" means native path separators and "." for the empty path.
svn_boolean_t svn_dirent_is_absolute | ( | const char * | dirent | ) |
Return TRUE if dirent is considered absolute on the platform at hand.
E.g. '/foo' on Posix platforms or 'X:/foo', '//server/share/foo' on Windows.
svn_boolean_t svn_dirent_is_ancestor | ( | const char * | parent_dirent, |
const char * | child_dirent | ||
) |
Return TRUE if parent_dirent is an ancestor of child_dirent or the dirents are equal, and FALSE otherwise.
### TODO: Deprecate, as the semantics are trivially obtainable from *_skip_ancestor().
svn_boolean_t svn_dirent_is_canonical | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Return TRUE
iff dirent is canonical.
Use pool for temporary allocations.
const char* svn_dirent_is_child | ( | const char * | parent_dirent, |
const char * | child_dirent, | ||
apr_pool_t * | pool | ||
) |
Similar to svn_dirent_skip_ancestor(), except that if child_dirent is the same as parent_dirent, it is not considered a child, so the result is NULL
; an empty string is never returned.
### TODO: Deprecate, as the semantics are trivially obtainable from *_skip_ancestor().
svn_boolean_t svn_dirent_is_root | ( | const char * | dirent, |
apr_size_t | len | ||
) |
Return TRUE if dirent is considered a root directory on the platform at hand.
E.g.: On Posix: '/' On Windows: '/', 'X:/', '//server/share', 'X:'
Note that on Windows '/' and 'X:' are roots, but paths starting with this root are not absolute.
svn_error_t* svn_dirent_is_under_root | ( | svn_boolean_t * | under_root, |
const char ** | result_path, | ||
const char * | base_path, | ||
const char * | path, | ||
apr_pool_t * | result_pool | ||
) |
Join path onto base_path, checking that path does not attempt to traverse above base_path.
If path or any ".." component within it resolves to a path above base_path, or if path is an absolute path, then set *under_root to FALSE
. Otherwise, set *under_root to TRUE
and, if result_path is not NULL
, set *result_path to the resulting path, allocated in result_pool.
path need not be canonical. base_path must be canonical and *result_path will be canonical.
Note: Use of this function is strongly encouraged. Do not roll your own. (http://cve.mitre.org/cgi-bin/cvename.cgi?name=2007-3846)
char* svn_dirent_join | ( | const char * | base, |
const char * | component, | ||
apr_pool_t * | pool | ||
) |
Join a base dirent (base) with a component (component), allocated in pool.
If either base or component is the empty string, then the other argument will be copied and returned. If both are the empty string then empty string is returned.
If the component is an absolute dirent, then it is copied and returned. The platform specific rules for joining paths are used to join the components.
This function is NOT appropriate for native (local) file dirents. Only for "internal" canonicalized dirents, since it uses '/' for the separator.
char* svn_dirent_join_many | ( | apr_pool_t * | pool, |
const char * | base, | ||
... | |||
) |
Join multiple components onto a base dirent, allocated in pool.
The components are terminated by a NULL
.
If any component is the empty string, it will be ignored.
If any component is an absolute dirent, then it resets the base and further components will be appended to it.
See svn_dirent_join() for further notes about joining dirents.
const char* svn_dirent_local_style | ( | const char * | dirent, |
apr_pool_t * | pool | ||
) |
Convert dirent from the internal style to the local style.
"Local style" means native path separators and "." for the empty path. If the input is not canonical, the output may not be canonical.
const char* svn_dirent_skip_ancestor | ( | const char * | parent_dirent, |
const char * | child_dirent | ||
) |
Return the relative path part of child_dirent that is below parent_dirent, or just "" if parent_dirent is equal to child_dirent.
If child_dirent is not below or equal to parent_dirent, return NULL.
If one of parent_dirent and child_dirent is absolute and the other relative, return NULL.
void svn_dirent_split | ( | const char ** | dirpath, |
const char ** | base_name, | ||
const char * | dirent, | ||
apr_pool_t * | pool | ||
) |
Divide the canonicalized dirent into *dirpath and *base_name, allocated in pool.
If dirpath or base_name is NULL, then don't set that one.
Either dirpath or base_name may be dirent's own address, but they may not both be the same address, or the results are undefined.
If dirent has two or more components, the separator between dirpath and base_name is not included in either of the new names.
Examples:
"/foo/bar/baz" ==> "/foo/bar" and "baz"
"/bar" ==> "/" and "bar"
"/" ==> "/" and ""
"bar" ==> "" and "bar"
"" ==> "" and ""Windows: -
"X:/" ==> "X:/" and ""
"X:/foo" ==> "X:/" and "foo"
"X:foo" ==> "X:" and "foo"Posix: -
"X:foo" ==> "" and "X:foo"
const char* svn_relpath__internal_style | ( | const char * | relpath, |
apr_pool_t * | pool | ||
) |
Convert relpath from the local style to the canonical internal style.
"Local style" means native path separators and "." for the empty path.
const char* svn_relpath_basename | ( | const char * | relpath, |
apr_pool_t * | pool | ||
) |
Get the basename of the specified canonicalized relpath.
The basename is defined as the last component of the relpath. If the relpath has only one component then that is returned. The returned value will have no slashes in it.
Example: svn_relpath_basename("/trunk/foo/bar") -> "bar"
The returned basename will be allocated in pool. If pool is NULL a pointer to the basename in relpath is returned.
const char* svn_relpath_canonicalize | ( | const char * | relpath, |
apr_pool_t * | pool | ||
) |
Return a new relpath like relpath, but transformed such that some types of relpath specification redundancies are removed.
This involves:
and possibly other semantically inoperative transformations.
The returned relpath may be allocated statically or from pool.
char* svn_relpath_dirname | ( | const char * | relpath, |
apr_pool_t * | pool | ||
) |
Get the dirname of the specified canonicalized relpath, defined as the relpath with its basename removed.
If relpath is empty, "" is returned.
The returned relpath will be allocated in pool.
char* svn_relpath_get_longest_ancestor | ( | const char * | relpath1, |
const char * | relpath2, | ||
apr_pool_t * | pool | ||
) |
Return the longest common path shared by two relative paths, relpath1 and relpath2.
If there's no common ancestor, return the empty path.
svn_boolean_t svn_relpath_is_canonical | ( | const char * | relpath | ) |
char* svn_relpath_join | ( | const char * | base, |
const char * | component, | ||
apr_pool_t * | pool | ||
) |
Join a base relpath (base) with a component (component), allocating the result in pool.
component need not be a single component.
If either base or component is the empty path, then the other argument will be copied and returned. If both are the empty path the empty path is returned.
const char* svn_relpath_skip_ancestor | ( | const char * | parent_relpath, |
const char * | child_relpath | ||
) |
Return the relative path part of child_relpath that is below parent_relpath, or just "" if parent_relpath is equal to child_relpath.
If child_relpath is not below or equal to parent_relpath, return NULL.
void svn_relpath_split | ( | const char ** | dirpath, |
const char ** | base_name, | ||
const char * | relpath, | ||
apr_pool_t * | pool | ||
) |
Divide the canonicalized relpath into *dirpath and *base_name, allocated in pool.
If dirpath or base_name is NULL, then don't set that one.
Either dirpath or base_name may be relpaths's own address, but they may not both be the same address, or the results are undefined.
If relpath has two or more components, the separator between dirpath and base_name is not included in either of the new names.
examples:
"foo/bar/baz" ==> "foo/bar" and "baz"
"bar" ==> "" and "bar"
"" ==> "" and ""
const char* svn_uri_basename | ( | const char * | uri, |
apr_pool_t * | pool | ||
) |
Get the (URI-decoded) basename of the specified canonicalized uri.
The basename is defined as the last component of the uri. If the uri is root then that is returned. Otherwise, the returned value will have no slashes in it.
Example: svn_uri_basename("http://server/foo/bar") -> "bar"
The returned basename will be allocated in pool.
const char* svn_uri_canonicalize | ( | const char * | uri, |
apr_pool_t * | pool | ||
) |
Return a new uri like uri, but transformed such that some types of uri specification redundancies are removed.
This involves:
and possibly other semantically inoperative transformations.
The returned uri may be allocated statically or from pool.
svn_error_t* svn_uri_condense_targets | ( | const char ** | pcommon, |
apr_array_header_t ** | pcondensed_targets, | ||
const apr_array_header_t * | targets, | ||
svn_boolean_t | remove_redundancies, | ||
apr_pool_t * | result_pool, | ||
apr_pool_t * | scratch_pool | ||
) |
Find the common prefix of the canonicalized uris in targets (an array of const char *
's), and remove redundant uris if remove_redundancies is TRUE.
Else if there is exactly one target, then
If there are no items in targets, set *pcommon and (if applicable) *pcondensed_targets to NULL
.
Allocate *pcommon and *targets in result_pool. Temporary allocations will be performed in scratch_pool.
char* svn_uri_dirname | ( | const char * | uri, |
apr_pool_t * | pool | ||
) |
Get the dirname of the specified canonicalized uri, defined as the uri with its basename removed.
If uri is root (e.g. "http://server"), it is returned unchanged.
The returned dirname will be allocated in pool.
svn_error_t* svn_uri_get_dirent_from_file_url | ( | const char ** | dirent, |
const char * | url, | ||
apr_pool_t * | pool | ||
) |
svn_error_t* svn_uri_get_file_url_from_dirent | ( | const char ** | url, |
const char * | dirent, | ||
apr_pool_t * | pool | ||
) |
char* svn_uri_get_longest_ancestor | ( | const char * | uri1, |
const char * | uri2, | ||
apr_pool_t * | pool | ||
) |
Return the longest common path shared by two canonicalized uris, uri1 and uri2.
If there's no common ancestor, return the empty path. In order for two URLs to have a common ancestor, they must (a) have the same protocol (since two URLs with the same path but different protocols may point at completely different resources), and (b) share a common ancestor in their path component, i.e. 'protocol://' is not a sufficient ancestor.
svn_boolean_t svn_uri_is_canonical | ( | const char * | uri, |
apr_pool_t * | pool | ||
) |
Return TRUE
iff uri is canonical.
Use pool for temporary allocations.
svn_boolean_t svn_uri_is_root | ( | const char * | uri, |
apr_size_t | len | ||
) |
Return TRUE if uri is a root URL (e.g., "http://server").
const char* svn_uri_skip_ancestor | ( | const char * | parent_uri, |
const char * | child_uri, | ||
apr_pool_t * | result_pool | ||
) |
Return the URI-decoded relative path of child_uri that is below parent_uri, or just "" if parent_uri is equal to child_uri.
If child_uri is not below or equal to parent_uri, return NULL. Allocate the result in result_pool.
void svn_uri_split | ( | const char ** | dirpath, |
const char ** | base_name, | ||
const char * | uri, | ||
apr_pool_t * | pool | ||
) |
Divide the canonicalized uri into a uri *dirpath and a (URI-decoded) relpath *base_name, allocated in pool.
If dirpath or base_name is NULL, then don't set that one.
Either dirpath or base_name may be uri's own address, but they may not both be the same address, or the results are undefined.
If uri has two or more components, the separator between dirpath and base_name is not included in either of the new names.
Examples:
"http://server/foo/bar" ==> "http://server/foo" and "bar"