/contrib/bind9/lib/lwres/man/lwres_buffer.docbook

https://bitbucket.org/freebsd/freebsd-head/ · Unknown · 394 lines · 369 code · 25 blank · 0 comment · 0 complexity · 3f9c06e59886e4cd9665ee85f47a9a1a MD5 · raw file

  1. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY mdash "&#8212;">]>
  4. <!--
  5. - Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
  6. - Copyright (C) 2000, 2001 Internet Software Consortium.
  7. -
  8. - Permission to use, copy, modify, and/or distribute this software for any
  9. - purpose with or without fee is hereby granted, provided that the above
  10. - copyright notice and this permission notice appear in all copies.
  11. -
  12. - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  13. - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  14. - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  15. - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  16. - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  17. - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. - PERFORMANCE OF THIS SOFTWARE.
  19. -->
  20. <!-- $Id: lwres_buffer.docbook,v 1.10 2007/06/18 23:47:51 tbox Exp $ -->
  21. <refentry>
  22. <refentryinfo>
  23. <date>Jun 30, 2000</date>
  24. </refentryinfo>
  25. <refmeta>
  26. <refentrytitle>lwres_buffer</refentrytitle>
  27. <manvolnum>3</manvolnum>
  28. <refmiscinfo>BIND9</refmiscinfo>
  29. </refmeta>
  30. <docinfo>
  31. <copyright>
  32. <year>2004</year>
  33. <year>2005</year>
  34. <year>2007</year>
  35. <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
  36. </copyright>
  37. <copyright>
  38. <year>2000</year>
  39. <year>2001</year>
  40. <holder>Internet Software Consortium.</holder>
  41. </copyright>
  42. </docinfo>
  43. <refnamediv>
  44. <refname>lwres_buffer_init</refname>
  45. <refname>lwres_buffer_invalidate</refname>
  46. <refname>lwres_buffer_add</refname>
  47. <refname>lwres_buffer_subtract</refname>
  48. <refname>lwres_buffer_clear</refname>
  49. <refname>lwres_buffer_first</refname>
  50. <refname>lwres_buffer_forward</refname>
  51. <refname>lwres_buffer_back</refname>
  52. <refname>lwres_buffer_getuint8</refname>
  53. <refname>lwres_buffer_putuint8</refname>
  54. <refname>lwres_buffer_getuint16</refname>
  55. <refname>lwres_buffer_putuint16</refname>
  56. <refname>lwres_buffer_getuint32</refname>
  57. <refname>lwres_buffer_putuint32</refname>
  58. <refname>lwres_buffer_putmem</refname>
  59. <refname>lwres_buffer_getmem</refname>
  60. <refpurpose>lightweight resolver buffer management</refpurpose>
  61. </refnamediv>
  62. <refsynopsisdiv>
  63. <funcsynopsis>
  64. <funcsynopsisinfo>
  65. #include &lt;lwres/lwbuffer.h&gt;
  66. </funcsynopsisinfo>
  67. <funcprototype>
  68. <funcdef>
  69. void
  70. <function>lwres_buffer_init</function></funcdef>
  71. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  72. <paramdef>void *<parameter>base</parameter></paramdef>
  73. <paramdef>unsigned int <parameter>length</parameter></paramdef>
  74. </funcprototype>
  75. <funcprototype>
  76. <funcdef>
  77. void
  78. <function>lwres_buffer_invalidate</function></funcdef>
  79. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  80. </funcprototype>
  81. <funcprototype>
  82. <funcdef>
  83. void
  84. <function>lwres_buffer_add</function></funcdef>
  85. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  86. <paramdef>unsigned int <parameter>n</parameter></paramdef>
  87. </funcprototype>
  88. <funcprototype>
  89. <funcdef>
  90. void
  91. <function>lwres_buffer_subtract</function></funcdef>
  92. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  93. <paramdef>unsigned int <parameter>n</parameter></paramdef>
  94. </funcprototype>
  95. <funcprototype>
  96. <funcdef>
  97. void
  98. <function>lwres_buffer_clear</function></funcdef>
  99. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  100. </funcprototype>
  101. <funcprototype>
  102. <funcdef>
  103. void
  104. <function>lwres_buffer_first</function></funcdef>
  105. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  106. </funcprototype>
  107. <funcprototype>
  108. <funcdef>
  109. void
  110. <function>lwres_buffer_forward</function></funcdef>
  111. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  112. <paramdef>unsigned int <parameter>n</parameter></paramdef>
  113. </funcprototype>
  114. <funcprototype>
  115. <funcdef>
  116. void
  117. <function>lwres_buffer_back</function></funcdef>
  118. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  119. <paramdef>unsigned int <parameter>n</parameter></paramdef>
  120. </funcprototype>
  121. <funcprototype>
  122. <funcdef>
  123. lwres_uint8_t
  124. <function>lwres_buffer_getuint8</function></funcdef>
  125. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  126. </funcprototype>
  127. <funcprototype>
  128. <funcdef>
  129. void
  130. <function>lwres_buffer_putuint8</function></funcdef>
  131. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  132. <paramdef>lwres_uint8_t <parameter>val</parameter></paramdef>
  133. </funcprototype>
  134. <funcprototype>
  135. <funcdef>
  136. lwres_uint16_t
  137. <function>lwres_buffer_getuint16</function></funcdef>
  138. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  139. </funcprototype>
  140. <funcprototype>
  141. <funcdef>
  142. void
  143. <function>lwres_buffer_putuint16</function></funcdef>
  144. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  145. <paramdef>lwres_uint16_t <parameter>val</parameter></paramdef>
  146. </funcprototype>
  147. <funcprototype>
  148. <funcdef>
  149. lwres_uint32_t
  150. <function>lwres_buffer_getuint32</function></funcdef>
  151. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  152. </funcprototype>
  153. <funcprototype>
  154. <funcdef>
  155. void
  156. <function>lwres_buffer_putuint32</function></funcdef>
  157. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  158. <paramdef>lwres_uint32_t <parameter>val</parameter></paramdef>
  159. </funcprototype>
  160. <funcprototype>
  161. <funcdef>
  162. void
  163. <function>lwres_buffer_putmem</function></funcdef>
  164. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  165. <paramdef>const unsigned char *<parameter>base</parameter></paramdef>
  166. <paramdef>unsigned int <parameter>length</parameter></paramdef>
  167. </funcprototype>
  168. <funcprototype>
  169. <funcdef>
  170. void
  171. <function>lwres_buffer_getmem</function></funcdef>
  172. <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
  173. <paramdef>unsigned char *<parameter>base</parameter></paramdef>
  174. <paramdef>unsigned int <parameter>length</parameter></paramdef>
  175. </funcprototype>
  176. </funcsynopsis>
  177. </refsynopsisdiv>
  178. <refsect1>
  179. <title>DESCRIPTION</title>
  180. <para>
  181. These functions provide bounds checked access to a region of memory
  182. where data is being read or written.
  183. They are based on, and similar to, the
  184. <literal>isc_buffer_</literal>
  185. functions in the ISC library.
  186. </para>
  187. <para>
  188. A buffer is a region of memory, together with a set of related
  189. subregions.
  190. The <emphasis>used region</emphasis> and the
  191. <emphasis>available</emphasis> region are disjoint, and
  192. their union is the buffer's region.
  193. The used region extends from the beginning of the buffer region to the
  194. last used byte.
  195. The available region extends from one byte greater than the last used
  196. byte to the end of the buffer's region.
  197. The size of the used region can be changed using various
  198. buffer commands.
  199. Initially, the used region is empty.
  200. </para>
  201. <para>
  202. The used region is further subdivided into two disjoint regions: the
  203. <emphasis>consumed region</emphasis> and the <emphasis>remaining region</emphasis>.
  204. The union of these two regions is the used region.
  205. The consumed region extends from the beginning of the used region to
  206. the byte before the <emphasis>current</emphasis> offset (if any).
  207. The <emphasis>remaining</emphasis> region the current pointer to the end
  208. of the used
  209. region.
  210. The size of the consumed region can be changed using various
  211. buffer commands.
  212. Initially, the consumed region is empty.
  213. </para>
  214. <para>
  215. The <emphasis>active region</emphasis> is an (optional) subregion of the
  216. remaining
  217. region.
  218. It extends from the current offset to an offset in the
  219. remaining region.
  220. Initially, the active region is empty.
  221. If the current offset advances beyond the chosen offset,
  222. the active region will also be empty.
  223. </para>
  224. <para><programlisting>
  225. /------------entire length---------------\\
  226. /----- used region -----\\/-- available --\\
  227. +----------------------------------------+
  228. | consumed | remaining | |
  229. +----------------------------------------+
  230. a b c d e
  231. </programlisting>
  232. </para>
  233. <para><programlisting>
  234. a == base of buffer.
  235. b == current pointer. Can be anywhere between a and d.
  236. c == active pointer. Meaningful between b and d.
  237. d == used pointer.
  238. e == length of buffer.
  239. </programlisting>
  240. </para>
  241. <para><programlisting>
  242. a-e == entire length of buffer.
  243. a-d == used region.
  244. a-b == consumed region.
  245. b-d == remaining region.
  246. b-c == optional active region.
  247. </programlisting>
  248. </para>
  249. <para><function>lwres_buffer_init()</function>
  250. initializes the
  251. <type>lwres_buffer_t</type>
  252. <parameter>*b</parameter>
  253. and assocates it with the memory region of size
  254. <parameter>length</parameter>
  255. bytes starting at location
  256. <parameter>base.</parameter>
  257. </para>
  258. <para><function>lwres_buffer_invalidate()</function>
  259. marks the buffer <parameter>*b</parameter>
  260. as invalid. Invalidating a buffer after use is not required,
  261. but makes it possible to catch its possible accidental use.
  262. </para>
  263. <para>
  264. The functions
  265. <function>lwres_buffer_add()</function>
  266. and
  267. <function>lwres_buffer_subtract()</function>
  268. respectively increase and decrease the used space in
  269. buffer
  270. <parameter>*b</parameter>
  271. by
  272. <parameter>n</parameter>
  273. bytes.
  274. <function>lwres_buffer_add()</function>
  275. checks for buffer overflow and
  276. <function>lwres_buffer_subtract()</function>
  277. checks for underflow.
  278. These functions do not allocate or deallocate memory.
  279. They just change the value of
  280. <structfield>used</structfield>.
  281. </para>
  282. <para>
  283. A buffer is re-initialised by
  284. <function>lwres_buffer_clear()</function>.
  285. The function sets
  286. <structfield>used</structfield>,
  287. <structfield>current</structfield>
  288. and
  289. <structfield>active</structfield>
  290. to zero.
  291. </para>
  292. <para><function>lwres_buffer_first</function>
  293. makes the consumed region of buffer
  294. <parameter>*p</parameter>
  295. empty by setting
  296. <structfield>current</structfield>
  297. to zero (the start of the buffer).
  298. </para>
  299. <para><function>lwres_buffer_forward()</function>
  300. increases the consumed region of buffer
  301. <parameter>*b</parameter>
  302. by
  303. <parameter>n</parameter>
  304. bytes, checking for overflow.
  305. Similarly,
  306. <function>lwres_buffer_back()</function>
  307. decreases buffer
  308. <parameter>b</parameter>'s
  309. consumed region by
  310. <parameter>n</parameter>
  311. bytes and checks for underflow.
  312. </para>
  313. <para><function>lwres_buffer_getuint8()</function>
  314. reads an unsigned 8-bit integer from
  315. <parameter>*b</parameter>
  316. and returns it.
  317. <function>lwres_buffer_putuint8()</function>
  318. writes the unsigned 8-bit integer
  319. <parameter>val</parameter>
  320. to buffer
  321. <parameter>*b</parameter>.
  322. </para>
  323. <para><function>lwres_buffer_getuint16()</function>
  324. and
  325. <function>lwres_buffer_getuint32()</function>
  326. are identical to
  327. <function>lwres_buffer_putuint8()</function>
  328. except that they respectively read an unsigned 16-bit or 32-bit integer
  329. in network byte order from
  330. <parameter>b</parameter>.
  331. Similarly,
  332. <function>lwres_buffer_putuint16()</function>
  333. and
  334. <function>lwres_buffer_putuint32()</function>
  335. writes the unsigned 16-bit or 32-bit integer
  336. <parameter>val</parameter>
  337. to buffer
  338. <parameter>b</parameter>,
  339. in network byte order.
  340. </para>
  341. <para>
  342. Arbitrary amounts of data are read or written from a lightweight
  343. resolver buffer with
  344. <function>lwres_buffer_getmem()</function>
  345. and
  346. <function>lwres_buffer_putmem()</function>
  347. respectively.
  348. <function>lwres_buffer_putmem()</function>
  349. copies
  350. <parameter>length</parameter>
  351. bytes of memory at
  352. <parameter>base</parameter>
  353. to
  354. <parameter>b</parameter>.
  355. Conversely,
  356. <function>lwres_buffer_getmem()</function>
  357. copies
  358. <parameter>length</parameter>
  359. bytes of memory from
  360. <parameter>b</parameter>
  361. to
  362. <parameter>base</parameter>.
  363. </para>
  364. </refsect1>
  365. </refentry><!--
  366. - Local variables:
  367. - mode: sgml
  368. - End:
  369. -->