1N/A/*
1N/A * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A
1N/A/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1N/A *
1N/A * The contents of this file are subject to the Netscape Public License
1N/A * Version 1.0 (the "NPL"); you may not use this file except in
1N/A * compliance with the NPL. You may obtain a copy of the NPL at
1N/A * http://www.mozilla.org/NPL/
1N/A *
1N/A * Software distributed under the NPL is distributed on an "AS IS" basis,
1N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
1N/A * for the specific language governing rights and limitations under the
1N/A * NPL.
1N/A *
1N/A * The Initial Developer of the Original Code is Netscape
1N/A * Communications Corporation. Portions created by Netscape are
1N/A * Copyright (C) 1998-1999 Netscape Communications Corporation. All
1N/A * Rights Reserved.
1N/A */
1N/A
1N/A/*
1N/A * Copyright (c) 1990 Regents of the University of Michigan.
1N/A * All rights reserved.
1N/A *
1N/A * Redistribution and use in source and binary forms are permitted
1N/A * provided that this notice is preserved and that due credit is given
1N/A * to the University of Michigan at Ann Arbor. The name of the University
1N/A * may not be used to endorse or promote products derived from this
1N/A * software without specific prior written permission. This software
1N/A * is provided ``as is'' without express or implied warranty.
1N/A */
1N/A/* lbet-int.h - internal header file for liblber */
1N/A
1N/A#ifndef _LBERINT_H
1N/A#define _LBERINT_H
1N/A
1N/A#ifdef __cplusplus
1N/Aextern "C" {
1N/A#endif
1N/A
1N/A#include <stdio.h>
1N/A#include <ctype.h>
1N/A#include <stdarg.h>
1N/A#include <stdlib.h>
1N/A#ifdef LDAP_SASLIO_HOOKS
1N/A#include <sasl/sasl.h>
1N/A#endif
1N/A
1N/A#ifdef macintosh
1N/A# include "ldap-macos.h"
1N/A#else /* macintosh */
1N/A#if !defined(BSDI)
1N/A# include <malloc.h>
1N/A#endif
1N/A# include <errno.h>
1N/A# include <sys/types.h>
1N/A#if defined(SUNOS4) || defined(SCOOS)
1N/A# include <sys/time.h>
1N/A#endif
1N/A#if defined( _WINDOWS )
1N/A# define WIN32_LEAN_AND_MEAN
1N/A# include <windows.h>
1N/A# include <time.h>
1N/A/* No stderr in a 16-bit Windows DLL */
1N/A# if defined(_WINDLL) && !defined(_WIN32)
1N/A# define USE_DBG_WIN
1N/A# endif
1N/A# else
1N/A#if !defined(XP_OS2)
1N/A/* # include <sys/varargs.h> */
1N/A# include <sys/socket.h>
1N/A# include <netinet/in.h>
1N/A# include <unistd.h>
1N/A#endif
1N/A# endif /* defined( _WINDOWS ) */
1N/A#endif /* macintosh */
1N/A
1N/A#include <memory.h>
1N/A#include <string.h>
1N/A#include "portable.h"
1N/A
1N/A#ifdef _WINDOWS
1N/A#include <winsock.h>
1N/A#include <io.h>
1N/A#endif /* _WINDOWS */
1N/A
1N/A#ifdef XP_OS2
1N/A#include <os2sock.h>
1N/A#include <io.h>
1N/A#endif /* XP_OS2 */
1N/A
1N/A/* No stderr in a 16-bit Windows DLL */
1N/A#if defined(_WINDLL) && !defined(_WIN32)
1N/A#define stderr NULL
1N/A#endif
1N/A
1N/A#include "lber.h"
1N/A
1N/A#ifdef _SOLARIS_SDK
1N/A#include <libintl.h>
1N/A#include "solaris-int.h"
1N/A#endif
1N/A
1N/A#ifdef macintosh
1N/A#define NSLDAPI_LBER_SOCKET_IS_PTR
1N/A#endif
1N/A
1N/A#define OLD_LBER_SEQUENCE 0x10 /* w/o constructed bit - broken */
1N/A#define OLD_LBER_SET 0x11 /* w/o constructed bit - broken */
1N/A
1N/A#ifndef _IFP
1N/A#define _IFP
1N/Atypedef int (LDAP_C LDAP_CALLBACK *IFP)();
1N/A#endif
1N/A
1N/Atypedef struct seqorset {
1N/A ber_len_t sos_clen;
1N/A ber_tag_t sos_tag;
1N/A char *sos_first;
1N/A char *sos_ptr;
1N/A struct seqorset *sos_next;
1N/A} Seqorset;
1N/A#define NULLSEQORSET ((Seqorset *) 0)
1N/A
1N/A#define SOS_STACK_SIZE 8 /* depth of the pre-allocated sos structure stack */
1N/A
1N/Astruct berelement {
1N/A char *ber_buf;
1N/A char *ber_ptr;
1N/A char *ber_end;
1N/A struct seqorset *ber_sos;
1N/A ber_tag_t ber_tag;
1N/A ber_len_t ber_len;
1N/A int ber_usertag;
1N/A char ber_options;
1N/A char *ber_rwptr;
1N/A BERTranslateProc ber_encode_translate_proc;
1N/A BERTranslateProc ber_decode_translate_proc;
1N/A int ber_flags;
1N/A#define LBER_FLAG_NO_FREE_BUFFER 1 /* don't free ber_buf */
1N/A int ber_sos_stack_posn;
1N/A Seqorset ber_sos_stack[SOS_STACK_SIZE];
1N/A};
1N/A
1N/A#ifndef _SOLARIS_SDK
1N/A#define NULLBER ((BerElement *)NULL)
1N/A#endif
1N/A
1N/A#ifdef LDAP_DEBUG
1N/Avoid ber_dump( BerElement *ber, int inout );
1N/A#endif
1N/A
1N/A
1N/A
1N/A/*
1N/A * structure for read/write I/O callback functions.
1N/A */
1N/Astruct nslberi_io_fns {
1N/A LDAP_IOF_READ_CALLBACK *lbiof_read;
1N/A LDAP_IOF_WRITE_CALLBACK *lbiof_write;
1N/A};
1N/A
1N/A
1N/Astruct sockbuf {
1N/A LBER_SOCKET sb_sd;
1N/A BerElement sb_ber;
1N/A int sb_naddr; /* > 0 implies using CLDAP (UDP) */
1N/A void *sb_useaddr; /* pointer to sockaddr to use next */
1N/A void *sb_fromaddr; /* pointer to message source sockaddr */
1N/A void **sb_addrs; /* actually an array of pointers to
1N/A sockaddrs */
1N/A
1N/A int sb_options; /* to support copying ber elements */
1N/A LBER_SOCKET sb_copyfd; /* for LBER_SOCKBUF_OPT_TO_FILE* opts */
1N/A ber_uint_t sb_max_incoming;
1N/A
1N/A struct nslberi_io_fns
1N/A sb_io_fns; /* classic I/O callback functions */
1N/A
1N/A struct lber_x_ext_io_fns
1N/A sb_ext_io_fns; /* extended I/O callback functions */
1N/A#ifdef LDAP_SASLIO_HOOKS
1N/A sasl_conn_t *sb_sasl_ctx; /* pointer to sasl context */
1N/A char *sb_sasl_ibuf; /* sasl decrypted input buffer */
1N/A char *sb_sasl_iptr; /* current location in buffer */
1N/A int sb_sasl_bfsz; /* Alloc'd size of input buffer */
1N/A int sb_sasl_ilen; /* remaining length to process */
1N/A struct lber_x_ext_io_fns
1N/A sb_sasl_fns; /* sasl redirect copy ext I/O funcs */
1N/A void *sb_sasl_prld; /* reverse ld pointer for callbacks */
1N/A#endif
1N/A};
1N/A#define NULLSOCKBUF ((Sockbuf *)NULL)
1N/A
1N/A
1N/A#ifndef NSLBERI_LBER_INT_FRIEND
1N/A/*
1N/A * Everything from this point on is excluded if NSLBERI_LBER_INT_FRIEND is
1N/A * defined. The code under ../libraries/libldap defines this.
1N/A */
1N/A
1N/A#define READBUFSIZ 8192
1N/A
1N/A/*
1N/A * macros used to check validity of data structures and parameters
1N/A */
1N/A#define NSLBERI_VALID_BERELEMENT_POINTER( ber ) \
1N/A ( (ber) != NULLBER )
1N/A
1N/A#define NSLBERI_VALID_SOCKBUF_POINTER( sb ) \
1N/A ( (sb) != NULLSOCKBUF )
1N/A
1N/A
1N/A#if defined(_WIN32) && defined(_ALPHA)
1N/A#define LBER_HTONL( _l ) \
1N/A ((((_l)&0xff)<<24) + (((_l)&0xff00)<<8) + \
1N/A (((_l)&0xff0000)>>8) + (((_l)&0xff000000)>>24))
1N/A#define LBER_NTOHL(_l) LBER_HTONL(_l)
1N/A
1N/A#elif !defined(__alpha) || defined(VMS)
1N/A
1N/A#define LBER_HTONL( l ) htonl( l )
1N/A#define LBER_NTOHL( l ) ntohl( l )
1N/A
1N/A#else /* __alpha */
1N/A/*
1N/A * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
1N/A * lower-order 32-bits of a (64-bit) long, so we define correct versions
1N/A * here.
1N/A */
1N/A#define LBER_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
1N/A | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
1N/A
1N/A#define LBER_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
1N/A | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
1N/A#endif /* __alpha */
1N/A
1N/A
1N/A/* function prototypes */
1N/A#ifdef LDAP_DEBUG
1N/Avoid lber_bprint( char *data, int len );
1N/A#endif
1N/Avoid ber_err_print( char *data );
1N/Avoid *nslberi_malloc( size_t size );
1N/Avoid *nslberi_calloc( size_t nelem, size_t elsize );
1N/Avoid *nslberi_realloc( void *ptr, size_t size );
1N/Avoid nslberi_free( void *ptr );
1N/Aint nslberi_ber_realloc( BerElement *ber, ber_len_t len );
1N/A
1N/A
1N/A
1N/A/* blame: dboreham
1N/A * slapd spends much of its time doing memcpy's for the ber code.
1N/A * Most of these are single-byte, so we special-case those and speed
1N/A * things up considerably.
1N/A */
1N/A
1N/A#ifdef sunos4
1N/A#define THEMEMCPY( d, s, n ) bcopy( s, d, n )
1N/A#else /* sunos4 */
1N/A#define THEMEMCPY( d, s, n ) memmove( d, s, n )
1N/A#endif /* sunos4 */
1N/A
1N/A#ifdef SAFEMEMCPY
1N/A#undef SAFEMEMCPY
1N/A#define SAFEMEMCPY(d,s,n) if (1 == n) *((char*)d) = *((char*)s); else THEMEMCPY(d,s,n);
1N/A#endif
1N/A
1N/A/*
1N/A * Memory allocation done in liblber should all go through one of the
1N/A * following macros. This is so we can plug-in alternative memory
1N/A * allocators, etc. as the need arises.
1N/A */
1N/A#define NSLBERI_MALLOC( size ) nslberi_malloc( size )
1N/A#define NSLBERI_CALLOC( nelem, elsize ) nslberi_calloc( nelem, elsize )
1N/A#define NSLBERI_REALLOC( ptr, size ) nslberi_realloc( ptr, size )
1N/A#define NSLBERI_FREE( ptr ) nslberi_free( ptr )
1N/A
1N/A/* allow the library to access the debug variable */
1N/A
1N/Aextern int lber_debug;
1N/A
1N/A#endif /* !NSLBERI_LBER_INT_FRIEND */
1N/A
1N/A
1N/A#ifdef __cplusplus
1N/A}
1N/A#endif
1N/A#endif /* _LBERINT_H */