lberh.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. (* $OpenLDAP: pkg/ldap/include/lber.h,v 1.83.2.11 2005/01/20 17:00:58 kurt Exp $ *)
  2. (* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2005 The OpenLDAP Foundation.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted only as authorized by the OpenLDAP
  9. * Public License.
  10. *
  11. * A copy of this license is available in file LICENSE in the
  12. * top-level directory of the distribution or, alternatively, at
  13. * <http://www.OpenLDAP.org/license.html>.
  14. *)
  15. (* Portions Copyright (c) 1990 Regents of the University of Michigan.
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms are permitted
  19. * provided that this notice is preserved and that due credit is given
  20. * to the University of Michigan at Ann Arbor. The name of the University
  21. * may not be used to endorse or promote products derived from this
  22. * software without specific prior written permission. This software
  23. * is provided ``as is'' without express or implied warranty.
  24. *)
  25. (* Overview of LBER tag construction
  26. *
  27. * Bits
  28. * ______
  29. * 8 7 | CLASS
  30. * 0 0 = UNIVERSAL
  31. * 0 1 = APPLICATION
  32. * 1 0 = CONTEXT-SPECIFIC
  33. * 1 1 = PRIVATE
  34. * _____
  35. * | 6 | DATA-TYPE
  36. * 0 = PRIMITIVE
  37. * 1 = CONSTRUCTED
  38. * ___________
  39. * | 5 ... 1 | TAG-NUMBER
  40. *)
  41. const
  42. (* BER classes and mask *)
  43. LBER_CLASS_UNIVERSAL = ber_tag_t($00);
  44. LBER_CLASS_APPLICATION = ber_tag_t($40);
  45. LBER_CLASS_CONTEXT = ber_tag_t($80);
  46. LBER_CLASS_PRIVATE = ber_tag_t($c0);
  47. LBER_CLASS_MASK = ber_tag_t($c0);
  48. (* BER encoding type and mask *)
  49. LBER_PRIMITIVE = ber_tag_t($00);
  50. LBER_CONSTRUCTED = ber_tag_t($20);
  51. LBER_ENCODING_MASK = ber_tag_t($20);
  52. LBER_BIG_TAG_MASK = ber_tag_t($1f);
  53. LBER_MORE_TAG_MASK = ber_tag_t($80);
  54. (*
  55. * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
  56. * as valid BER tags, and so it is safe to use them to report errors. In
  57. * fact, any tag for which the following is true is invalid:
  58. *)
  59. function LBER_INVALID(t: ber_tag_t): ber_tag_t;
  60. const
  61. LBER_ERROR = ber_tag_t(-1);
  62. LBER_DEFAULT = ber_tag_t(-1);
  63. (* general BER types we know about *)
  64. LBER_BOOLEAN = ber_tag_t($01);
  65. LBER_INTEGER = ber_tag_t($02);
  66. LBER_BITSTRING = ber_tag_t($03);
  67. LBER_OCTETSTRING = ber_tag_t($04);
  68. LBER_NULL = ber_tag_t($05);
  69. LBER_ENUMERATED = ber_tag_t($0a);
  70. LBER_SEQUENCE = ber_tag_t($30); (* constructed *)
  71. LBER_SET = ber_tag_t($31); (* constructed *)
  72. (* LBER BerElement options *)
  73. LBER_USE_DER = $01;
  74. (* get/set options for BerElement *)
  75. LBER_OPT_BER_OPTIONS = $01;
  76. LBER_OPT_BER_DEBUG = $02;
  77. LBER_OPT_BER_REMAINING_BYTES = $03;
  78. LBER_OPT_BER_TOTAL_BYTES = $04;
  79. LBER_OPT_BER_BYTES_TO_WRITE = $05;
  80. LBER_OPT_BER_MEMCTX = $06;
  81. LBER_OPT_DEBUG_LEVEL = LBER_OPT_BER_DEBUG;
  82. LBER_OPT_REMAINING_BYTES = LBER_OPT_BER_REMAINING_BYTES;
  83. LBER_OPT_TOTAL_BYTES = LBER_OPT_BER_TOTAL_BYTES;
  84. LBER_OPT_BYTES_TO_WRITE = LBER_OPT_BER_BYTES_TO_WRITE;
  85. LBER_OPT_LOG_PRINT_FN = $8001;
  86. LBER_OPT_MEMORY_FNS = $8002;
  87. LBER_OPT_ERROR_FN = $8003;
  88. LBER_OPT_LOG_PRINT_FILE = $8004;
  89. (* get/set Memory Debug options *)
  90. LBER_OPT_MEMORY_INUSE = $8005; (* for memory debugging *)
  91. LBER_OPT_LOG_PROC = $8006; (* for external logging function *)
  92. type
  93. BER_ERRNO_FN = function: pcint; cdecl;
  94. BER_LOG_PRINT_FN = procedure(const buf: pcchar); cdecl;
  95. BER_MEMALLOC_FN = function(size: ber_len_t): Pointer; cdecl;
  96. BER_MEMCALLOC_FN = function(n: ber_len_t; size: ber_len_t): Pointer; cdecl;
  97. BER_MEMREALLOC_FN = function(p: Pointer; size: ber_len_t): Pointer; cdecl;
  98. BER_MEMFREE_FN = function(p: Pointer): Pointer; cdecl;
  99. plber_memory_fns = ^lber_memory_fns;
  100. lber_memory_fns = record
  101. bmf_malloc : BER_MEMALLOC_FN;
  102. bmf_calloc : BER_MEMCALLOC_FN;
  103. bmf_realloc : BER_MEMREALLOC_FN;
  104. bmf_free : BER_MEMFREE_FN;
  105. end;
  106. PBerMemoryFunctions = ^BerMemoryFunctions;
  107. BerMemoryFunctions = lber_memory_fns;
  108. const
  109. (* LBER Sockbuf_IO options *)
  110. LBER_SB_OPT_GET_FD = 1;
  111. LBER_SB_OPT_SET_FD = 2;
  112. LBER_SB_OPT_HAS_IO = 3;
  113. LBER_SB_OPT_SET_NONBLOCK = 4;
  114. LBER_SB_OPT_GET_SSL = 7;
  115. LBER_SB_OPT_DATA_READY = 8;
  116. LBER_SB_OPT_SET_READAHEAD = 9;
  117. LBER_SB_OPT_DRAIN = 10;
  118. LBER_SB_OPT_NEEDS_READ = 11;
  119. LBER_SB_OPT_NEEDS_WRITE = 12;
  120. LBER_SB_OPT_GET_MAX_INCOMING = 13;
  121. LBER_SB_OPT_SET_MAX_INCOMING = 14;
  122. (* Largest option used by the library *)
  123. LBER_SB_OPT_OPT_MAX = 14;
  124. (* LBER IO operations stacking levels *)
  125. LBER_SBIOD_LEVEL_PROVIDER = 10;
  126. LBER_SBIOD_LEVEL_TRANSPORT = 20;
  127. LBER_SBIOD_LEVEL_APPLICATION = 30;
  128. (* get/set options for Sockbuf *)
  129. LBER_OPT_SOCKBUF_DESC = $1000;
  130. LBER_OPT_SOCKBUF_OPTIONS = $1001;
  131. LBER_OPT_SOCKBUF_DEBUG = $1002;
  132. LBER_OPT_SUCCESS = 0;
  133. LBER_OPT_ERROR = -1;
  134. (* on/off values *)
  135. const
  136. LBER_OPT_OFF = Pointer(0);
  137. var
  138. ber_pvt_opt_on: cchar; cvar; external;
  139. function LBER_OPT_ON: Pointer;
  140. (* Structure for LBER IO operarion descriptor *)
  141. type
  142. PBerElement = Pointer;
  143. PSockbuf = Pointer;
  144. PSeqorset = Pointer;
  145. PSockbuf_IO = ^Sockbuf_IO;
  146. PSockbuf_IO_Desc = ^Sockbuf_IO_Desc;
  147. Sockbuf_IO_Desc = record
  148. sbiod_level : cint;
  149. sbiod_sb : PSockbuf;
  150. sbiod_io : PSockbuf_IO;
  151. sbiod_pvt : Pointer;
  152. sbiod_next : PSockbuf_IO_Desc;
  153. end;
  154. (* Structure for LBER IO operation functions *)
  155. Sockbuf_IO = record
  156. sbi_setup : function(sbiod: PSockbuf_IO_Desc; arg: Pointer): cint; cdecl;
  157. sbi_remove : function(sbiod: PSockbuf_IO_Desc): cint; cdecl;
  158. sbi_ctrl : function(sbiod: PSockbuf_IO_Desc; opt: cint; arg: Pointer): cint; cdecl;
  159. sbi_read : function(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t; cdecl;
  160. sbi_write : function(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t; cdecl;
  161. sbi_close : function(sbiod: PSockbuf_IO_Desc): cint; cdecl;
  162. end;
  163. (* Helper macros for LBER IO functions *)
  164. function LBER_SBIOD_READ_NEXT(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t;
  165. function LBER_SBIOD_WRITE_NEXT(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t;
  166. function LBER_SBIOD_CTRL_NEXT(sbiod: PSockbuf_IO_Desc; opt: cint; arg: Pointer): cint;
  167. (* structure for returning a sequence of octet strings + length *)
  168. type
  169. PPPBerval = ^PPBerval;
  170. PPBerval = ^PBerval;
  171. PBerval = ^Berval;
  172. Berval = record
  173. bv_len : ber_len_t;
  174. bv_val : pcchar;
  175. end;
  176. PBerVarray = ^BerVarray;
  177. BerVarray = ^PBerval; (* To distinguish from a single bv *)
  178. (* this should be moved to lber-cint.h *)
  179. (*
  180. * in bprint.c:
  181. *)
  182. procedure ber_error_print(const data: pcchar); cdecl; external;
  183. procedure ber_bprint(const data: pcchar; len: ber_len_t); cdecl; external;
  184. procedure ber_dump(ber: PBerElement; inout : cint); cdecl; external;
  185. procedure ber_sos_dump(sos: PSeqorset); cdecl; external;
  186. (*
  187. * in decode.c:
  188. *)
  189. type
  190. BERDecodeCallback = function(ber: PBerElement; data: Pointer; mode: cint): cint; cdecl;
  191. function ber_get_tag(ber: PBerElement): ber_tag_t; cdecl; external;
  192. function ber_skip_tag(ber: PBerElement; var len: ber_len_t): ber_tag_t; cdecl; external;
  193. function ber_peek_tag(ber: PBerElement; var len: ber_len_t): ber_tag_t; cdecl; external;
  194. function ber_get_int(ber: PBerElement; var num: ber_int_t): ber_tag_t; cdecl; external;
  195. function ber_get_enum(ber: PBerElement; var num: ber_int_t): ber_tag_t; cdecl; external;
  196. function ber_get_stringb(ber: PBerElement; buf: pcchar; var len: ber_len_t): ber_tag_t; cdecl; external;
  197. function ber_get_stringbv(ber: PBerElement; bv: PBerval; alloc: cbool): ber_tag_t; cdecl; external;
  198. function ber_get_stringa(ber: PBerElement; var buf: pcchar): ber_tag_t; cdecl; external;
  199. function ber_get_stringal(ber: PBerElement; var bv: PBerval): ber_tag_t; cdecl; external;
  200. function ber_get_bitstringa(ber: PBerElement; var buf: pcchar; var len: ber_len_t): ber_tag_t; cdecl; external;
  201. function ber_get_null(ber: PBerElement): ber_tag_t; cdecl; external;
  202. function ber_get_Boolean(ber: PBerElement; var boolval: ber_int_t): ber_tag_t; cdecl; external;
  203. function ber_first_element(ber: PBerElement; var len: ber_len_t; var last: pcchar): ber_tag_t; cdecl; external;
  204. function ber_next_element(ber: PBerElement; var len: ber_len_t; const last: pcchar): ber_tag_t; cdecl; external;
  205. function ber_scanf(ber: PBerElement;const fmt: pcchar): ber_tag_t; cdecl; varargs; external;
  206. (*
  207. * in encode.c
  208. *)
  209. type
  210. BEREncodeCallback = function(ber: PBerElement; data: Pointer): cint;
  211. function ber_put_enum(ber: PBerElement; num: ber_int_t; tag: ber_tag_t): cint; cdecl; external;
  212. function ber_put_int(ber: PBerElement; num: ber_int_t; tag: ber_tag_t): cint; cdecl; external;
  213. function ber_put_ostring(ber: PBerElement; const str: pcchar; len: ber_len_t; tag: ber_tag_t): cint; cdecl; external;
  214. function ber_put_berval(ber: PBerElement; bv: PBerval; tag: ber_tag_t): cint; cdecl; external;
  215. function ber_put_string(ber: PBerElement; const str: pcchar; tag: ber_tag_t): cint; cdecl; external;
  216. function ber_put_bitstring(ber: PBerElement; const str: pcchar; bitlen: ber_len_t; tag: ber_tag_t): cint; cdecl; external;
  217. function ber_put_null(ber: PBerElement; tag: ber_tag_t): cint; cdecl; external;
  218. function ber_put_boolean(ber: PBerElement; boolval: ber_int_t; tag: ber_tag_t): cint; cdecl; external;
  219. function ber_start_seq(ber: PBerElement; tag: ber_tag_t): cint; cdecl; external;
  220. function ber_start_set(ber: PBerElement; tag: ber_tag_t): cint; cdecl; external;
  221. function ber_put_seq(ber: PBerElement): cint; cdecl; external;
  222. function ber_put_set(ber: PBerElement): cint; cdecl; external;
  223. function ber_printf(ber: PBerElement; const fmt: pcchar): cint; cdecl; varargs; external;
  224. (*
  225. * in io.c:
  226. *)
  227. function ber_read(ber: PBerElement; buf: pcchar; len: ber_len_t): ber_slen_t; cdecl; external;
  228. function ber_write(ber: PBerElement; const buf: pcchar; len: ber_len_t; nosos: cint): ber_slen_t; cdecl; external;
  229. procedure ber_free(ber: PBerElement; freebuf: cbool); cdecl; external;
  230. procedure ber_free_buf(ber: PBerElement); cdecl; external;
  231. function ber_flush(sb: PSockbuf; ber: PBerElement; freeit: cbool): cint; cdecl; external;
  232. function ber_alloc: PBerElement; cdecl; external; deprecated;
  233. function der_alloc: PBerElement; cdecl; external; deprecated;
  234. function ber_alloc_t(beroptions: cint): PBerElement; cdecl; external;
  235. function ber_dup(ber: PBerElement): PBerElement; cdecl; external;
  236. function ber_get_next(sb: PSockbuf; var len: ber_len_t; ber: PBerElement): ber_tag_t; cdecl; external;
  237. procedure ber_init2(ber: PBerElement; bv: PBerval; options: cint); cdecl; external;
  238. procedure ber_init_w_nullc(ber: PBerElement; options: cint); cdecl; external; deprecated;
  239. procedure ber_reset(ber: PBerElement; was_writing: cbool); cdecl; external;
  240. function ber_init(bv: PBerval): PBerElement; cdecl; external;
  241. function ber_flatten(ber: PBerElement; var bvPtr: PBerval): cint; cdecl; external;
  242. function ber_flatten2(ber: PBerElement; bv: PBerval; alloc: cbool): cint; cdecl; external;
  243. function ber_remaining(ber: PBerElement): cint; cdecl; external;
  244. (*
  245. * LBER ber accessor functions
  246. *)
  247. function ber_get_option(item: Pointer; option: cint; outvalue: Pointer): cint; cdecl; external;
  248. function ber_set_option(item: Pointer; option: cint; const invalue: Pointer): cint; cdecl; external;
  249. (*
  250. * LBER sockbuf.c
  251. *)
  252. function ber_sockbuf_alloc: PSockbuf; cdecl; external;
  253. procedure ber_sockbuf_free(sb: PSockbuf); cdecl; external;
  254. function ber_sockbuf_add_io(sb: PSockbuf; sbio: PSockbuf_IO; layer: cint; arg: Pointer): cint; cdecl; external;
  255. function ber_sockbuf_remove_io(sb: PSockbuf; sbio: PSockbuf_IO; layer: cint): cint; cdecl; external;
  256. function ber_sockbuf_ctrl(sb: PSockbuf; opt: cint; arg: Pointer): cint; cdecl; external;
  257. var
  258. ber_sockbuf_io_tcp : Sockbuf_IO; cvar; external;
  259. ber_sockbuf_io_readahead : Sockbuf_IO; cvar; external;
  260. ber_sockbuf_io_fd : Sockbuf_IO; cvar; external;
  261. ber_sockbuf_io_debug : Sockbuf_IO; cvar; external;
  262. {$IFDEF LDAP_CONNECTIONLESS}
  263. ber_sockbuf_io_udp : Sockbuf_IO; cvar; external;
  264. {$ENDIF}
  265. (*
  266. * LBER memory.c
  267. *)
  268. function ber_memalloc(s: ber_len_t): Pointer; cdecl; external;
  269. function ber_memrealloc(p: Pointer; s: ber_len_t): Pointer; cdecl; external;
  270. function ber_memcalloc(n: ber_len_t; s: ber_len_t): Pointer; cdecl; external;
  271. procedure ber_memfree(p: Pointer); cdecl; external;
  272. procedure ber_memvfree(vector: PPointer); cdecl; external;
  273. procedure ber_bvfree(bv: PBerval); cdecl; external;
  274. procedure ber_bvecfree(bv: PPBerval); cdecl; external;
  275. function ber_bvecadd(var bvec: PPBerval; bv: PBerval): cint; cdecl; external;
  276. function ber_dupbv(dst: PBerval; src: PBerval): PBerval; cdecl; external;
  277. function ber_bvdup(src: PBerval): PBerval; cdecl; external;
  278. function ber_str2bv(const str: pcchar; len: ber_len_t; duplicate: cbool; bv: PBerval): PBerval; cdecl; external;
  279. function ber_mem2bv(const str: pcchar; len: ber_len_t; duplicate: cbool; bv: PBerval): PBerval; cdecl; external;
  280. function ber_bvstr(const str: pcchar): PBerval;
  281. function ber_bvstrdup(const str: pcchar): PBerval;
  282. function ber_strdup(const str: pcchar): pcchar; cdecl; external;
  283. procedure ber_bvarray_free(p: BerVarray); cdecl; external;
  284. function ber_bvarray_add(p: PBerVarray; bv: PBerval): cint; cdecl; external;
  285. function ber_bvcmp(v1, v2: PBerval): cint;
  286. (*
  287. * error.c
  288. *)
  289. function ber_errno_addr: pcint; cdecl; external;
  290. function ber_errno: cint;
  291. const
  292. LBER_ERROR_NONE = $0;
  293. LBER_ERROR_PARAM = $1;
  294. LBER_ERROR_MEMORY = $2;