+/* $OpenLDAP$ */
/*
- * Copyright 1998 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
#include "lber.h"
#include "ldap_log.h"
+#include "lber_pvt.h"
LDAP_BEGIN_DECL
-#define LBER_ITEM_BERELEMENT 1
-#define LBER_ITEM_SOCKBUF 2
+LBER_F (BER_ERRNO_FN) ber_int_errno_fn;
-extern int lber_int_debug;
+struct lber_options {
+ short lbo_valid;
+ unsigned short lbo_options;
+ int lbo_debug;
+ long lbo_meminuse;
+};
+
+#ifdef NEW_LOGGING
+# ifdef LDAP_DEBUG
+# ifdef LDAP_LOG
+# undef LDAP_LOG
+# endif
+# define LDAP_LOG(a) ber_pvt_log_output a
+# define BER_DUMP(a) ber_output_dump a
+# else
+# define LDAP_LOG(a)
+# define BER_DUMP(a)
+# endif
+#endif
+
+#define LBER_UNINITIALIZED 0x0
+#define LBER_INITIALIZED 0x1
+#define LBER_VALID_BERELEMENT 0x2
+#define LBER_VALID_SOCKBUF 0x3
+
+LBER_F (struct lber_options) ber_int_options;
+#define ber_int_debug ber_int_options.lbo_debug
struct berelement {
- short ber_item_type; /* always LBER_ITEM_BERELEMENT */
- short ber_options;
- int ber_debug;
+ struct lber_options ber_opts;
+#define ber_valid ber_opts.lbo_valid
+#define ber_options ber_opts.lbo_options
+#define ber_debug ber_opts.lbo_debug
- int ber_usertag;
+ ber_tag_t ber_usertag;
- unsigned long ber_tag;
- unsigned long ber_len;
+ ber_tag_t ber_tag;
+ ber_len_t ber_len;
char *ber_buf;
char *ber_ptr;
struct seqorset *ber_sos;
char *ber_rwptr;
- BERTranslateProc ber_encode_translate_proc;
- BERTranslateProc ber_decode_translate_proc;
};
-#define NULLBER ((BerElement *) 0)
+#define BER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
+
+#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
+#define ber_pvt_ber_total(ber) ((ber)->ber_end - (ber)->ber_buf)
+#define ber_pvt_ber_write(ber) ((ber)->ber_ptr - (ber)->ber_buf)
struct sockbuf {
- short sb_item_type; /* always LBER_ITEM_SOCKBUF */
- short sb_options; /* to support copying ber elements */
- int sb_debug;
-
- int sb_fd;
-#ifndef MACOS
- int sb_sd;
-#else /* MACOS */
- void *sb_sd;
-#endif /* MACOS */
-
- long sb_max_incoming;
-
- BerElement sb_ber;
-
- int sb_naddr; /* > 0 implies using CLDAP (UDP) */
- void *sb_useaddr; /* pointer to sockaddr to use next */
- void *sb_fromaddr; /* pointer to message source sockaddr */
- void **sb_addrs; /* actually an array of pointers to
- sockaddrs */
+ struct lber_options sb_opts;
+ Sockbuf_IO_Desc *sb_iod; /* I/O functions */
+#define sb_valid sb_opts.lbo_valid
+#define sb_options sb_opts.lbo_options
+#define sb_debug sb_opts.lbo_debug
+ ber_socket_t sb_fd;
+ unsigned int sb_trans_needs_read:1;
+ unsigned int sb_trans_needs_write:1;
};
+
+#define SOCKBUF_VALID( sb ) ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
+
#define READBUFSIZ 8192
struct seqorset {
BerElement *sos_ber;
- unsigned long sos_clen;
- unsigned long sos_tag;
+ ber_len_t sos_clen;
+ ber_tag_t sos_tag;
char *sos_first;
char *sos_ptr;
struct seqorset *sos_next;
};
-#define NULLSEQORSET ((Seqorset *) 0)
+
/*
- * bprint.c
+ * io.c
*/
-LDAP_F int lber_log_printf LDAP_P((
- int errlvl,
- int loglvl,
- char *fmt,
- ... ));
+int ber_realloc LDAP_P((
+ BerElement *ber,
+ ber_len_t len ));
-LDAP_F int lber_log_bprint LDAP_P((
+/*
+ * bprint.c
+ */
+#define ber_log_printf ber_pvt_log_printf
+
+#ifdef NEW_LOGGING
+LBER_F( int )
+ber_output_dump LDAP_P((
+ char *subsys,
+ int level,
+ BerElement *ber,
+ int inout ));
+#endif
+
+LBER_F( int )
+ber_log_bprint LDAP_P((
int errlvl,
int loglvl,
- char *data,
- int len ));
+ const char *data,
+ ber_len_t len ));
-LDAP_F int lber_log_dump LDAP_P((
+LBER_F( int )
+ber_log_dump LDAP_P((
int errlvl,
int loglvl,
BerElement *ber,
int inout ));
-LDAP_F int lber_log_sos_dump LDAP_P((
+LBER_F( int )
+ber_log_sos_dump LDAP_P((
int errlvl,
int loglvl,
Seqorset *sos ));
+
+/* memory.c */
+ /* simple macros to realloc for now */
+LBER_F (BerMemoryFunctions *) ber_int_memory_fns;
+
+#ifdef CSRIMALLOC
+#define LBER_INT_MALLOC malloc
+#define LBER_INT_CALLOC calloc
+#define LBER_INT_REALLOC realloc
+#define LBER_INT_FREE free
+#define LBER_INT_VFREE ber_memvfree
+#define LBER_INT_STRDUP strdup
+
+#define LBER_MALLOC malloc
+#define LBER_CALLOC calloc
+#define LBER_REALLOC realloc
+#define LBER_FREE free
+#define LBER_VFREE ber_memvfree
+#define LBER_STRDUP strdup
+
+#else
+#define LBER_INT_MALLOC(s) ber_memalloc((s))
+#define LBER_INT_CALLOC(n,s) ber_memcalloc((n),(s))
+#define LBER_INT_REALLOC(p,s) ber_memrealloc((p),(s))
+#define LBER_INT_FREE(p) ber_memfree((p))
+#define LBER_INT_VFREE(v) ber_memvfree((void**)(v))
+#define LBER_INT_STRDUP(s) ber_strdup((s))
+
+#define LBER_MALLOC(s) ber_memalloc((s))
+#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
+#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
+#define LBER_FREE(p) ber_memfree((p))
+#define LBER_VFREE(v) ber_memvfree((void**)(v))
+#define LBER_STRDUP(s) ber_strdup((s))
+#endif
+
+/* sockbuf.c */
+
+LBER_F( int )
+ber_int_sb_init LDAP_P(( Sockbuf *sb ));
+
+LBER_F( int )
+ber_int_sb_close LDAP_P(( Sockbuf *sb ));
+
+LBER_F( int )
+ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
+
+LBER_F( ber_slen_t )
+ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
+
+LBER_F( ber_slen_t )
+ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
+
+LDAP_END_DECL
+
#endif /* _LBER_INT_H */