1 /*
2    HTTP URI handling
3    Copyright (C) 1999-2002, Joe Orton <joe@manyfish.co.uk>
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 BEGIN_NEON_DECLS
28 
29 /* Un-escapes a path. Returns malloc-allocated path on success, or
30  * NULL on an invalid %<HEX><HEX> sequence. */
31 char *ne_path_unescape(const char *uri);
32 
33 /* Escapes the a path segment: returns malloc-allocated string on
34  * success, or NULL on malloc failure.  */
35 char *ne_path_escape(const char *abs_path);
36 
37 /* Returns malloc-allocated parent of path, or NULL if path has no
38  * parent (such as "/"). */
39 char *ne_path_parent(const char *path);
40 
41 /* Returns strcmp-like value giving comparison between p1 and p2,
42  * ignoring trailing-slashes. */
43 int ne_path_compare(const char *p1, const char *p2);
44 
45 /* Returns non-zero if child is a child of parent */
46 int ne_path_childof(const char *parent, const char *child);
47 
48 /* Returns non-zero if path has a trailing slash character */
49 int ne_path_has_trailing_slash(const char *path);
50 
51 /* Return the default port for the given scheme, or 0 if none is
52  * known. */
53 unsigned int ne_uri_defaultport(const char *scheme);
54 
55 typedef struct {
56     char *scheme;
57     char *host;
58     unsigned int port;
59     char *path;
60     char *authinfo;
61 } ne_uri;
62 
63 /* Parse absoluteURI 'uri' and place parsed segments in *parsed.
64  * Returns zero on success, non-zero on parse error. Fields of *parsed
65  * are malloc'ed, structure should be free'd with uri_free on
66  * successful return.  Any unspecified URI fields are set to NULL or 0
67  * appropriately in *parsed. */
68 int ne_uri_parse(const char *uri, ne_uri *parsed);
69 
70 /* Turns a URI structure back into a string.  String is
71  * malloc-allocated, and must be free'd by the caller. */
72 char *ne_uri_unparse(const ne_uri *uri);
73 
74 /* Compares URIs u1 and u2, returns non-zero if they are found to be
75  * non-equal.  The sign of the return value is <0 if 'u1' is less than
76  * 'u2', or >0 if 'u2' is greater than 'u1'. */
77 int ne_uri_cmp(const ne_uri *u1, const ne_uri *u2);
78 
79 /* Free URI object. */
80 void ne_uri_free(ne_uri *parsed);
81 
82 END_NEON_DECLS
83 
84 #endif /* NE_URI_H */
85 
86