lber.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Translation of the LDAP lber headers for FreePascal
  3. Copyright (C) 2006 by Ivo Steinmann
  4. }
  5. unit lber;
  6. {$mode objfpc}
  7. interface
  8. {$linklib lber}
  9. {$include lber_typesh.inc}
  10. {$include lberh.inc}
  11. implementation
  12. function LBER_INVALID(t: ber_tag_t): ber_tag_t;
  13. // #define LBER_INVALID(t) (((t) & (ber_tag_t) = $080UL) && (((t) & (ber_tag_t) ~ = $0FF))
  14. begin
  15. LBER_INVALID := (t and $80) and (t and $FF);
  16. end;
  17. function LBER_OPT_ON: Pointer;
  18. // #define LBER_OPT_ON ((void *) &ber_pvt_opt_on)
  19. begin
  20. LBER_OPT_ON := @ber_pvt_opt_on;
  21. end;
  22. function LBER_SBIOD_READ_NEXT(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t;
  23. // #define LBER_SBIOD_READ_NEXT( sbiod, buf, len ) ( (sbiod)->sbiod_next->sbiod_io->sbi_read( (sbiod)->sbiod_next, buf, len ) )
  24. begin
  25. LBER_SBIOD_READ_NEXT := sbiod^.sbiod_next^.sbiod_io^.sbi_read(sbiod^.sbiod_next, buf, len);
  26. end;
  27. function LBER_SBIOD_WRITE_NEXT(sbiod: PSockbuf_IO_Desc; buf: Pointer; len: ber_len_t): ber_slen_t;
  28. // #define LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ) ( (sbiod)->sbiod_next->sbiod_io->sbi_write( (sbiod)->sbiod_next, buf, len ) )
  29. begin
  30. LBER_SBIOD_WRITE_NEXT := sbiod^.sbiod_next^.sbiod_io^.sbi_write(sbiod^.sbiod_next, buf, len);
  31. end;
  32. function LBER_SBIOD_CTRL_NEXT(sbiod: PSockbuf_IO_Desc; opt: cint; arg: Pointer): cint;
  33. // #define LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg ) ( (sbiod)->sbiod_next ? ( (sbiod)->sbiod_next->sbiod_io->sbi_ctrl( (sbiod)->sbiod_next, opt, arg ) ) : 0 )
  34. begin
  35. if Assigned(sbiod^.sbiod_next) then
  36. LBER_SBIOD_CTRL_NEXT := sbiod^.sbiod_next^.sbiod_io^.sbi_ctrl(sbiod^.sbiod_next, opt, arg) else
  37. LBER_SBIOD_CTRL_NEXT := 0;
  38. end;
  39. function ber_bvstr(const str: pcchar): PBerval;
  40. begin
  41. ber_bvstr := ber_str2bv(str, 0, false, nil);
  42. end;
  43. function ber_bvstrdup(const str: pcchar): PBerval;
  44. begin
  45. ber_bvstrdup := ber_str2bv(str, 0, true, nil);
  46. end;
  47. function memcmp(p1, p2: Pointer; len: cint): cint;
  48. var
  49. I: cint;
  50. begin
  51. for I := 0 to len -1 do
  52. begin
  53. if pbyte(p1)^ < pbyte(p2)^ then
  54. begin
  55. memcmp := -1;
  56. Exit;
  57. end;
  58. if pbyte(p1)^ > pbyte(p2)^ then
  59. begin
  60. memcmp := 1;
  61. Exit;
  62. end;
  63. inc(p1, 1);
  64. inc(p2, 1);
  65. end;
  66. memcmp := 0;
  67. end;
  68. function ber_bvcmp(v1, v2: PBerval): cint;
  69. // #define ber_bvcmp(v1,v2) ((v1)->bv_len < (v2)->bv_len ? -1 : ((v1)->bv_len > (v2)->bv_len ? 1 : memcmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
  70. begin
  71. if v1^.bv_len < v2^.bv_len then ber_bvcmp := -1 else
  72. if v1^.bv_len > v2^.bv_len then ber_bvcmp := 1 else
  73. ber_bvcmp := memcmp(v1^.bv_val, v2^.bv_val, v1^.bv_len);
  74. end;
  75. function ber_errno: cint;
  76. begin
  77. ber_errno := ber_errno_addr^;
  78. end;
  79. end.