libxml2-uri.html revision 6ad5c4af742de7f56ae5e0eaf89f174775a1e822
1<?xml version="1.0" encoding="UTF-8"?> 2<html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 5 <title>uri: library of generic URI related routines</title> 6 <meta name="generator" content="Libxml2 devhelp stylesheet"/> 7 <link rel="start" href="index.html" title="libxml2 Reference Manual"/> 8 <link rel="up" href="general.html" title="API"/> 9 <link rel="stylesheet" href="style.css" type="text/css"/> 10 <link rel="chapter" href="general.html" title="API"/> 11 </head> 12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13 <table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"> 14 <tr valign="middle"> 15 <td> 16 <a accesskey="p" href="libxml2-tree.html"> 17 <img src="left.png" width="24" height="24" border="0" alt="Prev"/> 18 </a> 19 </td> 20 <td> 21 <a accesskey="u" href="general.html"> 22 <img src="up.png" width="24" height="24" border="0" alt="Up"/> 23 </a> 24 </td> 25 <td> 26 <a accesskey="h" href="index.html"> 27 <img src="home.png" width="24" height="24" border="0" alt="Home"/> 28 </a> 29 </td> 30 <td> 31 <a accesskey="n" href="libxml2-valid.html"> 32 <img src="right.png" width="24" height="24" border="0" alt="Next"/> 33 </a> 34 </td> 35 <th width="100%" align="center">libxml2 Reference Manual</th> 36 </tr> 37 </table> 38 <h2> 39 <span class="refentrytitle">uri</span> 40 </h2> 41 <p>uri - library of generic URI related routines</p> 42 <p>library of generic URI related routines Implements RFC 2396 </p> 43 <p>Author(s): Daniel Veillard </p> 44 <div class="refsynopsisdiv"> 45 <h2>Synopsis</h2> 46 <pre class="synopsis">typedef struct _xmlURI <a href="#xmlURI">xmlURI</a>; 47typedef <a href="libxml2-uri.html#xmlURI">xmlURI</a> * <a href="#xmlURIPtr">xmlURIPtr</a>; 48int <a href="#xmlNormalizeURIPath">xmlNormalizeURIPath</a> (char * path); 49void <a href="#xmlPrintURI">xmlPrintURI</a> (FILE * stream, <br/> <a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri); 50<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> <a href="#xmlParseURIRaw">xmlParseURIRaw</a> (const char * str, <br/> int raw); 51char * <a href="#xmlURIUnescapeString">xmlURIUnescapeString</a> (const char * str, <br/> int len, <br/> char * target); 52<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> <a href="#xmlParseURI">xmlParseURI</a> (const char * str); 53<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> <a href="#xmlCreateURI">xmlCreateURI</a> (void); 54<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlURIEscapeStr">xmlURIEscapeStr</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * str, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * list); 55<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlPathToURI">xmlPathToURI</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * path); 56<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlCanonicPath">xmlCanonicPath</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * path); 57void <a href="#xmlFreeURI">xmlFreeURI</a> (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri); 58int <a href="#xmlParseURIReference">xmlParseURIReference</a> (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri, <br/> const char * str); 59<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlBuildRelativeURI">xmlBuildRelativeURI</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * URI, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * base); 60<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlSaveUri">xmlSaveUri</a> (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri); 61<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlURIEscape">xmlURIEscape</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * str); 62<a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * <a href="#xmlBuildURI">xmlBuildURI</a> (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * URI, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * base); 63</pre> 64 </div> 65 <div class="refsect1" lang="en"> 66 <h2>Description</h2> 67 </div> 68 <div class="refsect1" lang="en"> 69 <h2>Details</h2> 70 <div class="refsect2" lang="en"> 71 <div class="refsect2" lang="en"><h3><a name="xmlURI">Structure </a>xmlURI</h3><pre class="programlisting">struct _xmlURI { 72 char * scheme : the URI scheme 73 char * opaque : opaque part 74 char * authority : the authority part 75 char * server : the server part 76 char * user : the user part 77 int port : the port number 78 char * path : the path string 79 char * query : the query string 80 char * fragment : the fragment identifier 81 int cleanup : parsing potentially unclean URI 82} xmlURI; 83</pre><p/> 84</div> 85 <hr/> 86 <div class="refsect2" lang="en"><h3><a name="xmlURIPtr">Typedef </a>xmlURIPtr</h3><pre class="programlisting"><a href="libxml2-uri.html#xmlURI">xmlURI</a> * xmlURIPtr; 87</pre><p/> 88</div> 89 <hr/> 90 <div class="refsect2" lang="en"><h3><a name="xmlBuildRelativeURI"/>xmlBuildRelativeURI ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlBuildRelativeURI (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * URI, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * base)<br/> 91</pre><p>Expresses the URI of the <a href="libxml2-SAX.html#reference">reference</a> in terms relative to the base. Some examples of this operation include: base = "http://site1.com/docs/book1.html" URI input URI returned docs/pic1.gif pic1.gif docs/img/pic1.gif img/pic1.gif img/pic1.gif /img/pic1.gif http://site1.com/docs/pic1.gif pic1.gif http://site2.com/docs/pic1.gif http://site2.com/docs/pic1.gif base = "docs/book1.html" URI input URI returned docs/pic1.gif pic1.gif docs/img/pic1.gif img/pic1.gif img/pic1.gif /img/pic1.gif http://site1.com/docs/pic1.gif http://site1.com/docs/pic1.gif Note: if the URI <a href="libxml2-SAX.html#reference">reference</a> is really wierd or complicated, it may be worthwhile to first convert it into a "nice" one by calling <a href="libxml2-uri.html#xmlBuildURI">xmlBuildURI</a> (using 'base') before calling this routine, since this routine (for reasonable efficiency) assumes URI has already been through some validation.</p> 92<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URI</tt></i>:</span></td><td>the URI <a href="libxml2-SAX.html#reference">reference</a> under consideration</td></tr><tr><td><span class="term"><i><tt>base</tt></i>:</span></td><td>the base value</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new URI string (to be freed by the caller) or NULL in case error.</td></tr></tbody></table></div></div> 93 <hr/> 94 <div class="refsect2" lang="en"><h3><a name="xmlBuildURI"/>xmlBuildURI ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlBuildURI (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * URI, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * base)<br/> 95</pre><p>Computes he final URI of the <a href="libxml2-SAX.html#reference">reference</a> done by checking that the given URI is valid, and building the final URI using the base URI. This is processed according to section 5.2 of the RFC 2396 5.2. Resolving Relative References to Absolute Form</p> 96<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URI</tt></i>:</span></td><td>the URI instance found in the document</td></tr><tr><td><span class="term"><i><tt>base</tt></i>:</span></td><td>the base value</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new URI string (to be freed by the caller) or NULL in case of error.</td></tr></tbody></table></div></div> 97 <hr/> 98 <div class="refsect2" lang="en"><h3><a name="xmlCanonicPath"/>xmlCanonicPath ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlCanonicPath (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * path)<br/> 99</pre><p>Constructs a canonic path from the specified path.</p> 100<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>path</tt></i>:</span></td><td>the resource locator in a filesystem notation</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new canonic path, or a duplicate of the path parameter if the construction fails. The caller is responsible for freeing the memory occupied by the returned string. If there is insufficient memory available, or the argument is NULL, the function returns NULL.</td></tr></tbody></table></div></div> 101 <hr/> 102 <div class="refsect2" lang="en"><h3><a name="xmlCreateURI"/>xmlCreateURI ()</h3><pre class="programlisting"><a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> xmlCreateURI (void)<br/> 103</pre><p>Simply creates an empty <a href="libxml2-uri.html#xmlURI">xmlURI</a></p> 104<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the new structure or NULL in case of error</td></tr></tbody></table></div></div> 105 <hr/> 106 <div class="refsect2" lang="en"><h3><a name="xmlFreeURI"/>xmlFreeURI ()</h3><pre class="programlisting">void xmlFreeURI (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri)<br/> 107</pre><p>Free up the <a href="libxml2-uri.html#xmlURI">xmlURI</a> struct</p> 108<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>uri</tt></i>:</span></td><td>pointer to an <a href="libxml2-uri.html#xmlURI">xmlURI</a></td></tr></tbody></table></div></div> 109 <hr/> 110 <div class="refsect2" lang="en"><h3><a name="xmlNormalizeURIPath"/>xmlNormalizeURIPath ()</h3><pre class="programlisting">int xmlNormalizeURIPath (char * path)<br/> 111</pre><p>Applies the 5 normalization steps to a path string--that is, RFC 2396 Section 5.2, steps 6.c through 6.g. Normalization occurs directly on the string, no new allocation is done</p> 112<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>path</tt></i>:</span></td><td>pointer to the path string</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>0 or an error code</td></tr></tbody></table></div></div> 113 <hr/> 114 <div class="refsect2" lang="en"><h3><a name="xmlParseURI"/>xmlParseURI ()</h3><pre class="programlisting"><a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> xmlParseURI (const char * str)<br/> 115</pre><p>Parse an URI URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]</p> 116<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the URI string to analyze</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a newly built <a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> or NULL in case of error</td></tr></tbody></table></div></div> 117 <hr/> 118 <div class="refsect2" lang="en"><h3><a name="xmlParseURIRaw"/>xmlParseURIRaw ()</h3><pre class="programlisting"><a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> xmlParseURIRaw (const char * str, <br/> int raw)<br/> 119</pre><p>Parse an URI but allows to keep intact the original fragments. URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]</p> 120<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the URI string to analyze</td></tr><tr><td><span class="term"><i><tt>raw</tt></i>:</span></td><td>if 1 unescaping of URI pieces are disabled</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a newly built <a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> or NULL in case of error</td></tr></tbody></table></div></div> 121 <hr/> 122 <div class="refsect2" lang="en"><h3><a name="xmlParseURIReference"/>xmlParseURIReference ()</h3><pre class="programlisting">int xmlParseURIReference (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri, <br/> const char * str)<br/> 123</pre><p>Parse an URI <a href="libxml2-SAX.html#reference">reference</a> string and fills in the appropriate fields of the @uri structure URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]</p> 124<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>uri</tt></i>:</span></td><td>pointer to an URI structure</td></tr><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the string to analyze</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>0 or the error code</td></tr></tbody></table></div></div> 125 <hr/> 126 <div class="refsect2" lang="en"><h3><a name="xmlPathToURI"/>xmlPathToURI ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlPathToURI (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * path)<br/> 127</pre><p>Constructs an URI expressing the existing path</p> 128<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>path</tt></i>:</span></td><td>the resource locator in a filesystem notation</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new URI, or a duplicate of the path parameter if the construction fails. The caller is responsible for freeing the memory occupied by the returned string. If there is insufficient memory available, or the argument is NULL, the function returns NULL.</td></tr></tbody></table></div></div> 129 <hr/> 130 <div class="refsect2" lang="en"><h3><a name="xmlPrintURI"/>xmlPrintURI ()</h3><pre class="programlisting">void xmlPrintURI (FILE * stream, <br/> <a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri)<br/> 131</pre><p>Prints the URI in the stream @stream.</p> 132<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>stream</tt></i>:</span></td><td>a FILE* for the output</td></tr><tr><td><span class="term"><i><tt>uri</tt></i>:</span></td><td>pointer to an <a href="libxml2-uri.html#xmlURI">xmlURI</a></td></tr></tbody></table></div></div> 133 <hr/> 134 <div class="refsect2" lang="en"><h3><a name="xmlSaveUri"/>xmlSaveUri ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlSaveUri (<a href="libxml2-uri.html#xmlURIPtr">xmlURIPtr</a> uri)<br/> 135</pre><p>Save the URI as an escaped string</p> 136<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>uri</tt></i>:</span></td><td>pointer to an <a href="libxml2-uri.html#xmlURI">xmlURI</a></td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new string (to be deallocated by caller)</td></tr></tbody></table></div></div> 137 <hr/> 138 <div class="refsect2" lang="en"><h3><a name="xmlURIEscape"/>xmlURIEscape ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlURIEscape (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * str)<br/> 139</pre><p>Escaping routine, does not do validity checks ! It will try to escape the chars needing this, but this is heuristic based it's impossible to be sure.</p> 140<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the string of the URI to escape</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>an copy of the string, but escaped 25 May 2001 Uses <a href="libxml2-uri.html#xmlParseURI">xmlParseURI</a> and <a href="libxml2-uri.html#xmlURIEscapeStr">xmlURIEscapeStr</a> to try to escape correctly according to RFC2396. - Carl Douglas</td></tr></tbody></table></div></div> 141 <hr/> 142 <div class="refsect2" lang="en"><h3><a name="xmlURIEscapeStr"/>xmlURIEscapeStr ()</h3><pre class="programlisting"><a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * xmlURIEscapeStr (const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * str, <br/> const <a href="libxml2-xmlstring.html#xmlChar">xmlChar</a> * list)<br/> 143</pre><p>This routine escapes a string to hex, ignoring reserved <a href="libxml2-SAX.html#characters">characters</a> (a-z) and the <a href="libxml2-SAX.html#characters">characters</a> in the exception list.</p> 144<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>string to escape</td></tr><tr><td><span class="term"><i><tt>list</tt></i>:</span></td><td>exception list string of chars not to escape</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>a new escaped string or NULL in case of error.</td></tr></tbody></table></div></div> 145 <hr/> 146 <div class="refsect2" lang="en"><h3><a name="xmlURIUnescapeString"/>xmlURIUnescapeString ()</h3><pre class="programlisting">char * xmlURIUnescapeString (const char * str, <br/> int len, <br/> char * target)<br/> 147</pre><p>Unescaping routine, does not do validity checks ! Output is direct unsigned char translation of %XX values (no encoding)</p> 148<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the string to unescape</td></tr><tr><td><span class="term"><i><tt>len</tt></i>:</span></td><td>the length in bytes to unescape (or <= 0 to indicate full string)</td></tr><tr><td><span class="term"><i><tt>target</tt></i>:</span></td><td>optional destination buffer</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>an copy of the string, but unescaped</td></tr></tbody></table></div></div> 149 <hr/> 150 </div> 151 </div> 152 </body> 153</html> 154