blob: 075ae4817ecfa83ffb909bf05404d81eca3c8baf [file] [log] [blame]
Daniel Veillard1db4a662005-09-12 13:10:09 +00001<?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>nanohttp: minimal HTTP implementation</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-nanoftp.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-parser.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">nanohttp</span>
40 </h2>
41 <p>nanohttp - minimal HTTP implementation</p>
42 <p>minimal HTTP implementation allowing to fetch resources like external subset. </p>
43 <p>Author(s): Daniel Veillard </p>
44 <div class="refsynopsisdiv">
45 <h2>Synopsis</h2>
46 <pre class="synopsis">int <a href="#xmlNanoHTTPRead">xmlNanoHTTPRead</a> (void * ctx, <br/> void * dest, <br/> int len);
47int <a href="#xmlNanoHTTPSave">xmlNanoHTTPSave</a> (void * ctxt, <br/> const char * filename);
48const char * <a href="#xmlNanoHTTPRedir">xmlNanoHTTPRedir</a> (void * ctx);
49const char * <a href="#xmlNanoHTTPAuthHeader">xmlNanoHTTPAuthHeader</a> (void * ctx);
50int <a href="#xmlNanoHTTPFetch">xmlNanoHTTPFetch</a> (const char * URL, <br/> const char * filename, <br/> char ** contentType);
51int <a href="#xmlNanoHTTPContentLength">xmlNanoHTTPContentLength</a> (void * ctx);
52const char * <a href="#xmlNanoHTTPMimeType">xmlNanoHTTPMimeType</a> (void * ctx);
53void <a href="#xmlNanoHTTPClose">xmlNanoHTTPClose</a> (void * ctx);
54void <a href="#xmlNanoHTTPCleanup">xmlNanoHTTPCleanup</a> (void);
55void * <a href="#xmlNanoHTTPMethod">xmlNanoHTTPMethod</a> (const char * URL, <br/> const char * method, <br/> const char * input, <br/> char ** contentType, <br/> const char * headers, <br/> int ilen);
56void <a href="#xmlNanoHTTPInit">xmlNanoHTTPInit</a> (void);
57void * <a href="#xmlNanoHTTPOpen">xmlNanoHTTPOpen</a> (const char * URL, <br/> char ** contentType);
58void * <a href="#xmlNanoHTTPOpenRedir">xmlNanoHTTPOpenRedir</a> (const char * URL, <br/> char ** contentType, <br/> char ** redir);
59void * <a href="#xmlNanoHTTPMethodRedir">xmlNanoHTTPMethodRedir</a> (const char * URL, <br/> const char * method, <br/> const char * input, <br/> char ** contentType, <br/> char ** redir, <br/> const char * headers, <br/> int ilen);
60void <a href="#xmlNanoHTTPScanProxy">xmlNanoHTTPScanProxy</a> (const char * URL);
61const char * <a href="#xmlNanoHTTPEncoding">xmlNanoHTTPEncoding</a> (void * ctx);
62int <a href="#xmlNanoHTTPReturnCode">xmlNanoHTTPReturnCode</a> (void * ctx);
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="xmlNanoHTTPAuthHeader"/>xmlNanoHTTPAuthHeader ()</h3><pre class="programlisting">const char * xmlNanoHTTPAuthHeader (void * ctx)<br/>
72</pre><p>Get the authentication header of an HTTP context</p>
73<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the stashed value of the WWW-Authenticate or Proxy-Authenticate header.</td></tr></tbody></table></div></div>
74 <hr/>
75 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPCleanup"/>xmlNanoHTTPCleanup ()</h3><pre class="programlisting">void xmlNanoHTTPCleanup (void)<br/>
76</pre><p>Cleanup the HTTP protocol layer.</p>
77</div>
78 <hr/>
79 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPClose"/>xmlNanoHTTPClose ()</h3><pre class="programlisting">void xmlNanoHTTPClose (void * ctx)<br/>
80</pre><p>This function closes an HTTP context, it ends up the connection and free all data related to it.</p>
81<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr></tbody></table></div></div>
82 <hr/>
83 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPContentLength"/>xmlNanoHTTPContentLength ()</h3><pre class="programlisting">int xmlNanoHTTPContentLength (void * ctx)<br/>
84</pre><p>Provides the specified content length from the HTTP header.</p>
85<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the specified content length from the HTTP header. Note that a value of -1 indicates that the content length element was not included in the response header.</td></tr></tbody></table></div></div>
86 <hr/>
87 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPEncoding"/>xmlNanoHTTPEncoding ()</h3><pre class="programlisting">const char * xmlNanoHTTPEncoding (void * ctx)<br/>
88</pre><p>Provides the specified encoding if specified in the HTTP headers.</p>
89<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the specified encoding or NULL if not available</td></tr></tbody></table></div></div>
90 <hr/>
91 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPFetch"/>xmlNanoHTTPFetch ()</h3><pre class="programlisting">int xmlNanoHTTPFetch (const char * URL, <br/> const char * filename, <br/> char ** contentType)<br/>
92</pre><p>This function try to fetch the indicated resource via HTTP GET and save it's content in the file.</p>
93<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The URL to load</td></tr><tr><td><span class="term"><i><tt>filename</tt></i>:</span></td><td>the filename where the content should be saved</td></tr><tr><td><span class="term"><i><tt>contentType</tt></i>:</span></td><td>if available the Content-Type information will be returned at that location</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>-1 in case of failure, 0 incase of success. The contentType, if provided must be freed by the caller</td></tr></tbody></table></div></div>
94 <hr/>
95 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPInit"/>xmlNanoHTTPInit ()</h3><pre class="programlisting">void xmlNanoHTTPInit (void)<br/>
96</pre><p>Initialize the HTTP protocol layer. Currently it just checks for proxy informations</p>
97</div>
98 <hr/>
99 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPMethod"/>xmlNanoHTTPMethod ()</h3><pre class="programlisting">void * xmlNanoHTTPMethod (const char * URL, <br/> const char * method, <br/> const char * input, <br/> char ** contentType, <br/> const char * headers, <br/> int ilen)<br/>
100</pre><p>This function try to open a connection to the indicated resource via HTTP using the given @method, adding the given extra headers and the input buffer for the request content.</p>
101<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The URL to load</td></tr><tr><td><span class="term"><i><tt>method</tt></i>:</span></td><td>the HTTP method to use</td></tr><tr><td><span class="term"><i><tt>input</tt></i>:</span></td><td>the input string if any</td></tr><tr><td><span class="term"><i><tt>contentType</tt></i>:</span></td><td>the Content-Type information IN and OUT</td></tr><tr><td><span class="term"><i><tt>headers</tt></i>:</span></td><td>the extra headers</td></tr><tr><td><span class="term"><i><tt>ilen</tt></i>:</span></td><td>input length</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>NULL in case of failure, otherwise a request handler. The contentType, if provided must be freed by the caller</td></tr></tbody></table></div></div>
102 <hr/>
103 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPMethodRedir"/>xmlNanoHTTPMethodRedir ()</h3><pre class="programlisting">void * xmlNanoHTTPMethodRedir (const char * URL, <br/> const char * method, <br/> const char * input, <br/> char ** contentType, <br/> char ** redir, <br/> const char * headers, <br/> int ilen)<br/>
104</pre><p>This function try to open a connection to the indicated resource via HTTP using the given @method, adding the given extra headers and the input buffer for the request content.</p>
105<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The URL to load</td></tr><tr><td><span class="term"><i><tt>method</tt></i>:</span></td><td>the HTTP method to use</td></tr><tr><td><span class="term"><i><tt>input</tt></i>:</span></td><td>the input string if any</td></tr><tr><td><span class="term"><i><tt>contentType</tt></i>:</span></td><td>the Content-Type information IN and OUT</td></tr><tr><td><span class="term"><i><tt>redir</tt></i>:</span></td><td>the redirected URL OUT</td></tr><tr><td><span class="term"><i><tt>headers</tt></i>:</span></td><td>the extra headers</td></tr><tr><td><span class="term"><i><tt>ilen</tt></i>:</span></td><td>input length</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>NULL in case of failure, otherwise a request handler. The contentType, or redir, if provided must be freed by the caller</td></tr></tbody></table></div></div>
106 <hr/>
107 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPMimeType"/>xmlNanoHTTPMimeType ()</h3><pre class="programlisting">const char * xmlNanoHTTPMimeType (void * ctx)<br/>
108</pre><p>Provides the specified Mime-Type if specified in the HTTP headers.</p>
109<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the specified Mime-Type or NULL if not available</td></tr></tbody></table></div></div>
110 <hr/>
111 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPOpen"/>xmlNanoHTTPOpen ()</h3><pre class="programlisting">void * xmlNanoHTTPOpen (const char * URL, <br/> char ** contentType)<br/>
112</pre><p>This function try to open a connection to the indicated resource via HTTP GET.</p>
113<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The URL to load</td></tr><tr><td><span class="term"><i><tt>contentType</tt></i>:</span></td><td>if available the Content-Type information will be returned at that location</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>NULL in case of failure, otherwise a request handler. The contentType, if provided must be freed by the caller</td></tr></tbody></table></div></div>
114 <hr/>
115 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPOpenRedir"/>xmlNanoHTTPOpenRedir ()</h3><pre class="programlisting">void * xmlNanoHTTPOpenRedir (const char * URL, <br/> char ** contentType, <br/> char ** redir)<br/>
116</pre><p>This function try to open a connection to the indicated resource via HTTP GET.</p>
117<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The URL to load</td></tr><tr><td><span class="term"><i><tt>contentType</tt></i>:</span></td><td>if available the Content-Type information will be returned at that location</td></tr><tr><td><span class="term"><i><tt>redir</tt></i>:</span></td><td>if available the redirected URL will be returned</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>NULL in case of failure, otherwise a request handler. The contentType, if provided must be freed by the caller</td></tr></tbody></table></div></div>
118 <hr/>
119 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPRead"/>xmlNanoHTTPRead ()</h3><pre class="programlisting">int xmlNanoHTTPRead (void * ctx, <br/> void * dest, <br/> int len)<br/>
120</pre><p>This function tries to read @len bytes from the existing HTTP connection and saves them in @dest. This is a blocking call.</p>
121<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>dest</tt></i>:</span></td><td>a buffer</td></tr><tr><td><span class="term"><i><tt>len</tt></i>:</span></td><td>the buffer length</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the number of byte read. 0 is an indication of an end of connection. -1 indicates a parameter error.</td></tr></tbody></table></div></div>
122 <hr/>
123 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPRedir"/>xmlNanoHTTPRedir ()</h3><pre class="programlisting">const char * xmlNanoHTTPRedir (void * ctx)<br/>
124</pre><p>Provides the specified redirection URL if available from the HTTP header.</p>
125<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the specified redirection URL or NULL if not redirected.</td></tr></tbody></table></div></div>
126 <hr/>
127 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPReturnCode"/>xmlNanoHTTPReturnCode ()</h3><pre class="programlisting">int xmlNanoHTTPReturnCode (void * ctx)<br/>
128</pre><p>Get the latest HTTP return code received</p>
129<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the HTTP return code for the request.</td></tr></tbody></table></div></div>
130 <hr/>
131 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPSave"/>xmlNanoHTTPSave ()</h3><pre class="programlisting">int xmlNanoHTTPSave (void * ctxt, <br/> const char * filename)<br/>
132</pre><p>This function saves the output of the HTTP transaction to a file It closes and free the context at the end</p>
133<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>ctxt</tt></i>:</span></td><td>the HTTP context</td></tr><tr><td><span class="term"><i><tt>filename</tt></i>:</span></td><td>the filename where the content should be saved</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>-1 in case of failure, 0 incase of success.</td></tr></tbody></table></div></div>
134 <hr/>
135 <div class="refsect2" lang="en"><h3><a name="xmlNanoHTTPScanProxy"/>xmlNanoHTTPScanProxy ()</h3><pre class="programlisting">void xmlNanoHTTPScanProxy (const char * URL)<br/>
136</pre><p>(Re)Initialize the HTTP Proxy context by parsing the URL and finding the protocol host port it indicates. Should be like http://myproxy/ or http://myproxy:3128/ A NULL URL cleans up proxy informations.</p>
137<div class="variablelist"><table border="0"><col align="left"/><tbody><tr><td><span class="term"><i><tt>URL</tt></i>:</span></td><td>The proxy URL used to initialize the proxy context</td></tr></tbody></table></div></div>
138 <hr/>
139 </div>
140 </div>
141 </body>
142</html>