req.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <refentry id="refreq">
  2. <refmeta>
  3. <refentrytitle>ne_request_create</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_request_create">ne_request_create</refname>
  8. <refname id="ne_request_dispatch">ne_request_dispatch</refname>
  9. <refname id="ne_request_destroy">ne_request_destroy</refname>
  10. <refpurpose>low-level HTTP request handling</refpurpose>
  11. </refnamediv>
  12. <refsynopsisdiv>
  13. <funcsynopsis>
  14. <funcsynopsisinfo>#include &lt;ne_request.h&gt;</funcsynopsisinfo>
  15. <funcprototype>
  16. <funcdef>ne_request *<function>ne_request_create</function></funcdef>
  17. <paramdef>ne_session *<parameter>session</parameter></paramdef>
  18. <paramdef>const char *<parameter>method</parameter></paramdef>
  19. <paramdef>const char *<parameter>path</parameter></paramdef>
  20. </funcprototype>
  21. <funcprototype>
  22. <funcdef>int <function>ne_request_dispatch</function></funcdef>
  23. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  24. </funcprototype>
  25. <funcprototype>
  26. <funcdef>void <function>ne_request_destroy</function></funcdef>
  27. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  28. </funcprototype>
  29. </funcsynopsis>
  30. </refsynopsisdiv>
  31. <refsect1>
  32. <title>Description</title>
  33. <para>The <type>ne_request</type> object represents an HTTP
  34. request and the associated response.
  35. The <function>ne_request_create</function> function creates a
  36. new request object for the
  37. given <parameter>session</parameter>. The target resource for
  38. the request is identified by the <parameter>path</parameter>,
  39. and the method to be performed on that resource via
  40. the <parameter>method</parameter> parameter.</para>
  41. <para>The <parameter>path</parameter> string used must conform to the
  42. <literal>abs_path</literal> definition given in RFC2396, with an
  43. optional "?query" part, and must be URI-escaped by the caller (for
  44. instance, using <function>ne_path_escape</function>). If the string
  45. comes from an untrusted source, failure to perform URI-escaping
  46. results in a security vulnerability.</para>
  47. <para>To dispatch a request, and process the response, the
  48. <function>ne_request_dispatch</function> function can be used. An
  49. alternative is to use the (more complex, but more flexible)
  50. combination of the <function>ne_begin_request</function>,
  51. <function>ne_end_request</function>, and
  52. <function>ne_read_response_block</function> functions; see
  53. <function>ne_begin_request</function>.</para>
  54. <para>To add extra headers in the request, the functions <xref
  55. linkend="ne_add_request_header"/> and <xref
  56. linkend="ne_print_request_header"/> can be used. To include a message
  57. body with the request, one of the functions
  58. <function>ne_set_request_body_buffer</function>, <function>ne_set_request_body_fd</function>, or
  59. <function>ne_set_request_body_provider</function> can be used.</para>
  60. <para>The return value of
  61. <function>ne_request_dispatch</function> indicates merely whether the
  62. request was sent and the response read successfully. To discover the
  63. result of the operation, <xref linkend="ne_get_status"/>, along with
  64. any processing of the response headers and message body.</para>
  65. <para>A request can only be dispatched once: calling
  66. <function>ne_request_dispatch</function> more than once on a
  67. single <type>ne_request</type> object produces undefined
  68. behaviour. Once all processing associated with the request
  69. object is complete, use the
  70. <function>ne_request_destroy</function> function to destroy
  71. the resources associated with it. Any subsequent use of the
  72. request object produces undefined behaviour.</para>
  73. <para>For a request with a non-idempotent method such
  74. as <literal>POST</literal>, the
  75. <literal>NE_REQFLAG_IDEMPOTENT</literal> flag should be
  76. disabled; see <xref linkend="ne_set_request_flag"/>.</para>
  77. </refsect1>
  78. <refsect1>
  79. <title>Return value</title>
  80. <para>The <function>ne_request_create</function> function
  81. returns a pointer to a request object (and never &null;).</para>
  82. <para>The <function>ne_request_dispatch</function> function
  83. returns zero if the request was dispatched successfully, and a
  84. non-zero error code otherwise.</para>
  85. </refsect1>
  86. <!-- TODO: abs_path description in a NOTES section -->
  87. <refsect1>
  88. <title>Errors</title>
  89. <variablelist>
  90. <varlistentry><term><errorcode>NE_ERROR</errorcode></term>
  91. <listitem>
  92. <simpara>Request failed (see session error string)</simpara>
  93. </listitem>
  94. </varlistentry>
  95. <varlistentry><term><errorcode>NE_LOOKUP</errorcode></term>
  96. <listitem>
  97. <simpara>The DNS lookup for the server (or proxy server) failed.</simpara>
  98. </listitem>
  99. </varlistentry>
  100. <varlistentry><term><errorcode>NE_AUTH</errorcode></term>
  101. <listitem>
  102. <simpara>Authentication failed on the server.</simpara>
  103. </listitem>
  104. </varlistentry>
  105. <varlistentry><term><errorcode>NE_PROXYAUTH</errorcode></term>
  106. <listitem>
  107. <simpara>Authentication failed on the proxy server.</simpara>
  108. </listitem>
  109. </varlistentry>
  110. <varlistentry><term><errorcode>NE_CONNECT</errorcode></term>
  111. <listitem>
  112. <simpara>A connection to the server could not be established.</simpara>
  113. </listitem>
  114. </varlistentry>
  115. <varlistentry><term><errorcode>NE_TIMEOUT</errorcode></term>
  116. <listitem>
  117. <simpara>A timeout occurred while waiting for the server to respond.</simpara>
  118. </listitem>
  119. </varlistentry>
  120. </variablelist>
  121. </refsect1>
  122. <refsect1>
  123. <title>Example</title>
  124. <para>An example of applying a <literal>MKCOL</literal>
  125. operation to the resource at the location
  126. <literal>http://www.example.com/foo/bar/</literal>:</para>
  127. <programlisting>ne_session *sess = ne_session_create("http", "www.example.com", 80);
  128. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  129. if (ne_request_dispatch(req)) {
  130. printf("Request failed: %s\n", ne_get_error(sess));
  131. }
  132. ne_request_destroy(req);</programlisting>
  133. </refsect1>
  134. <refsect1>
  135. <title>See also</title>
  136. <para><xref linkend="ne_get_error"/>, <xref
  137. linkend="ne_set_error"/>, <xref linkend="ne_get_status"/>, <xref
  138. linkend="ne_add_request_header"/>, <xref
  139. linkend="ne_set_request_body_buffer"/>, <xref linkend="ne_set_request_flag"/>.</para>
  140. </refsect1>
  141. </refentry>