| 1 |
/* |
| 2 |
URI manipulation routines. |
| 3 |
Copyright (C) 1999-2008, Joe Orton <[email protected]> |
| 4 |
|
| 5 |
This library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Library General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Library General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Library General Public |
| 16 |
License along with this library; if not, write to the Free |
| 17 |
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 |
MA 02111-1307, USA |
| 19 |
|
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef NE_URI_H |
| 23 |
#define NE_URI_H |
| 24 |
|
| 25 |
#include "ne_defs.h" |
| 26 |
|
| 27 |
NE_BEGIN_DECLS |
| 28 |
|
| 29 |
/* Return a copy of a path string with anything other than |
| 30 |
* "unreserved" and the forward-slash character percent-encoded |
| 31 |
* according to the URI encoding rules. Returns a malloc-allocated |
| 32 |
* string and never NULL. */ |
| 33 |
char *ne_path_escape(const char *path); |
| 34 |
|
| 35 |
/* Return a decoded copy of a percent-encoded path string. Returns |
| 36 |
* malloc-allocated path on success, or NULL if the string contained |
| 37 |
* any syntactically invalid percent-encoding sequences. */ |
| 38 |
char *ne_path_unescape(const char *epath); |
| 39 |
|
| 40 |
/* Returns malloc-allocated parent of path, or NULL if path has no |
| 41 |
* parent (such as "/"). */ |
| 42 |
char *ne_path_parent(const char *path); |
| 43 |
|
| 44 |
/* Returns strcmp-like value giving comparison between p1 and p2, |
| 45 |
* ignoring trailing-slashes. */ |
| 46 |
int ne_path_compare(const char *p1, const char *p2); |
| 47 |
|
| 48 |
/* Returns non-zero if child is a child of parent */ |
| 49 |
int ne_path_childof(const char *parent, const char *child); |
| 50 |
|
| 51 |
/* Returns non-zero if path has a trailing slash character */ |
| 52 |
int ne_path_has_trailing_slash(const char *path); |
| 53 |
|
| 54 |
/* Return the default port for the given scheme, or 0 if none is |
| 55 |
* known. */ |
| 56 |
unsigned int ne_uri_defaultport(const char *scheme); |
| 57 |
|
| 58 |
typedef struct { |
| 59 |
char *scheme; |
| 60 |
char *host, *userinfo; |
| 61 |
unsigned int port; |
| 62 |
char *path, *query, *fragment; |
| 63 |
} ne_uri; |
| 64 |
|
| 65 |
/* Parse a URI-reference 'uri' and place parsed components in *parsed. |
| 66 |
* Returns zero on success, non-zero on parse error. On successful or |
| 67 |
* error return, all the 'char *' fields of *parsed are either set to |
| 68 |
* NULL, or point to malloc-allocated NUL-terminated strings; |
| 69 |
* ne_uri_free can be used to free any set fields. On success, |
| 70 |
* parsed->path is guaranteed to be non-NULL. */ |
| 71 |
int ne_uri_parse(const char *uri, ne_uri *parsed); |
| 72 |
|
| 73 |
/* Turns a URI structure back into a string. The returned string is |
| 74 |
* malloc-allocated, and must be freed by the caller. */ |
| 75 |
char *ne_uri_unparse(const ne_uri *uri); |
| 76 |
|
| 77 |
/* Resolve a relative URI 'relative', with respect to base URI 'base', |
| 78 |
* placing the resultant URI in '*result'. At least both base->path |
| 79 |
* and relative->path must be non-NULL. On return, all the 'char *' |
| 80 |
* fields of *result are either set to NULL or point to |
| 81 |
* malloc-allocated NUL-terminated strings. result->path is |
| 82 |
* guaranteed to be non-NULL. ne_uri_free can be used to free the |
| 83 |
* result structure after use. Returns 'result'. */ |
| 84 |
ne_uri *ne_uri_resolve(const ne_uri *base, const ne_uri *relative, |
| 85 |
ne_uri *result); |
| 86 |
|
| 87 |
/* Compares URIs u1 and u2, returns non-zero if they are found to be |
| 88 |
* non-equal. The sign of the return value is <0 if 'u1' is less than |
| 89 |
* 'u2', or >0 if 'u2' is greater than 'u1'. */ |
| 90 |
int ne_uri_cmp(const ne_uri *u1, const ne_uri *u2); |
| 91 |
|
| 92 |
/* Copy components of URI 'src' to destination 'dest'. Returns |
| 93 |
* 'dest'. */ |
| 94 |
ne_uri *ne_uri_copy(ne_uri *dest, const ne_uri *src); |
| 95 |
|
| 96 |
/* Frees any non-NULL fields of parsed URI structure *parsed. All |
| 97 |
* fields are then zero-initialized. */ |
| 98 |
void ne_uri_free(ne_uri *parsed); |
| 99 |
|
| 100 |
NE_END_DECLS |
| 101 |
|
| 102 |
#endif /* NE_URI_H */ |
| 103 |
|