refsess.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ne_session_create</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="neon HTTP/WebDAV client library"><link rel="up" href="ref.html" title="neon API reference"><link rel="prev" href="refalloc.html" title="ne_malloc"><link rel="next" href="refproxy.html" title="ne_session_proxy"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ne_session_create</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="refalloc.html">Prev</a> </td><th width="60%" align="center">neon API reference</th><td width="20%" align="right"> <a accesskey="n" href="refproxy.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="refsess"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ne_session_create, ne_close_connection, ne_session_destroy — set up HTTP sessions</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;ne_session.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">ne_session *<b class="fsfunc">ne_session_create</b>(</code></td><td>const char *<var class="pdparam">scheme</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">host</var>, </td></tr><tr><td> </td><td>unsigned int <var class="pdparam">port</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">ne_close_connection</b>(</code></td><td>ne_session *<var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">ne_session_destroy</b>(</code></td><td>ne_session *<var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="id2826"></a><h2>Description</h2><p>An <em class="type">ne_session</em> object represents an HTTP
  2. session - a logical grouping of a sequence of HTTP requests made to a
  3. certain server. Any requests made using the session can use a
  4. persistent connection, share cached authentication credentials and any
  5. other common attributes.</p><p>A new HTTP session is created using the
  6. <code class="function">ne_session_create</code> function; the
  7. <code class="parameter">host</code> and <code class="parameter">port</code>
  8. parameters specify the origin server to use, along with
  9. the <code class="parameter">scheme</code> (usually <code class="literal">"http"</code>).
  10. Before the first use of <code class="function">ne_session_create</code> in a
  11. process, <a class="xref" href="refsockinit.html#ne_sock_init">ne_sock_init</a> must have been called to
  12. perform any global initialization needed by any libraries used by
  13. neon.</p><p>To enable SSL/TLS for the session, pass the string
  14. <code class="literal">"https"</code> as the
  15. <code class="parameter">scheme</code>, and either register a
  16. certificate verification function (see <a class="xref" href="refsslvfy.html#ne_ssl_set_verify">ne_ssl_set_verify</a>) or trust the appropriate
  17. certificate (see <a class="xref" href="refsslca.html#ne_ssl_trust_cert">ne_ssl_trust_cert</a>, <a class="xref" href="refsslca.html#ne_ssl_trust_default_ca">ne_ssl_trust_default_ca</a>).</p><p>The <code class="parameter">host</code> parameter must follow
  18. the definition of host <code class="literal">host</code> in <a class="ulink" href="https://www.rfc-editor.org/rfc/rfc3986" target="_top">RFC 3986</a>,
  19. which can be an IP-literal or registered (DNS) hostname. Valid
  20. examples of each: <code class="literal">"198.51.100.42"</code> (IPv4
  21. literal address), <code class="literal">"[2001:db8::42]"</code> (IPv6
  22. literal, which <span class="emphasis"><em>MUST</em></span> be enclosed in square
  23. brackets), or <code class="literal">"www.example.com"</code> (DNS
  24. hostname). The <a class="ulink" href="https://www.rfc-editor.org/rfc/rfc6874" target="_top">RFC 6874</a>
  25. syntax for scoped IPv6 link-local literal addresses is also
  26. permitted, for example <code class="literal">"[fe80::1%25eth0]"</code>.
  27. </p><p>The <code class="parameter">scheme</code> parameter is used to
  28. determine the URI for resources identified during request
  29. handling. Other than special handling of the string
  30. <code class="literal">"https"</code>, no other interpretation or
  31. checking of the <code class="parameter">scheme</code> is
  32. performed. For example, if an HTTP-to-FTP proxy is configured,
  33. a scheme of <code class="literal">"ftp"</code> could be used to access
  34. resources.</p><p>To use a proxy server for the session, it must be
  35. configured (see <a class="xref" href="refproxy.html#ne_session_proxy">ne_session_proxy</a>) before any
  36. requests are created from session object.</p><p>Further per-session options may be changed using the
  37. <a class="xref" href="refsessflags.html#ne_set_session_flag">ne_set_session_flag</a> interface.</p><p>If it is known that the session will not be used for a
  38. significant period of time, <code class="function">ne_close_connection</code>
  39. can be called to close the connection, if one remains open. Use of
  40. this function is entirely optional, but it must not be called if there
  41. is a request active using the session.</p><p>Once a session has been completed,
  42. <code class="function">ne_session_destroy</code> must be called to
  43. destroy the resources associated with the session. Any
  44. subsequent use of the session pointer produces undefined
  45. behaviour. The session object must not be destroyed until
  46. after all associated request objects have been
  47. destroyed.</p></div><div class="refsect1"><a name="id2867"></a><h2>Notes</h2><p>If a hostname is passed to
  48. <code class="function">ne_session_create</code>, it will be resolved when the first
  49. request using the session is dispatched; a DNS resolution failure can
  50. only be detected at that time (using the <code class="literal">NE_LOOKUP</code>
  51. error code); see <a class="xref" href="refreq.html#ne_request_dispatch">ne_request_dispatch</a> for
  52. details.</p></div><div class="refsect1"><a name="id2873"></a><h2>Return Values</h2><p><code class="function">ne_session_create</code> will return
  53. a pointer to a new session object (and never <code class="literal">NULL</code>).</p></div><div class="refsect1"><a name="id2878"></a><h2>Examples</h2><p>Create and destroy a session:</p><pre class="programlisting">ne_session *sess;
  54. sess = ne_session_create("http", "host.example.com", 80);
  55. /* ... use sess ... */
  56. ne_session_destroy(sess);
  57. </pre></div><div class="refsect1"><a name="id2882"></a><h2>See Also</h2><p><a class="xref" href="refsslvfy.html#ne_ssl_set_verify">ne_ssl_set_verify</a>, <a class="xref" href="refsslca.html#ne_ssl_trust_cert">ne_ssl_trust_cert</a>, <a class="xref" href="refsockinit.html#ne_sock_init">ne_sock_init</a>, <a class="xref" href="refsessflags.html#ne_set_session_flag">ne_set_session_flag</a>, <a class="xref" href="refproxy.html#ne_session_proxy">ne_session_proxy</a></p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="refalloc.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="refproxy.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ne_malloc </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ne_session_proxy</td></tr></table></div></body></html>