1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* 7*7c478bd9Sstevel@tonic-gate * Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public License 10*7c478bd9Sstevel@tonic-gate * Version 1.0(the "NPL"); you may not use this file except in 11*7c478bd9Sstevel@tonic-gate * compliance with the NPL. You may obtain a copy of the NPL at 12*7c478bd9Sstevel@tonic-gate * http:/ /www.mozilla.org/NPL/ 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * Software distributed under the NPL is distributed on an "AS IS" basis, 15*7c478bd9Sstevel@tonic-gate * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL 16*7c478bd9Sstevel@tonic-gate * for the specific language governing rights and limitations under the 17*7c478bd9Sstevel@tonic-gate * NPL. 18*7c478bd9Sstevel@tonic-gate * 19*7c478bd9Sstevel@tonic-gate * The Initial Developer of this code under the NPL is Netscape 20*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 21*7c478bd9Sstevel@tonic-gate * Copyright(C) 1998 Netscape Communications Corporation. All Rights 22*7c478bd9Sstevel@tonic-gate * Reserved. 23*7c478bd9Sstevel@tonic-gate */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate #ifndef _LBER_H 26*7c478bd9Sstevel@tonic-gate #define _LBER_H 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 31*7c478bd9Sstevel@tonic-gate extern "C" { 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #ifndef _SOLARIS_SDK 35*7c478bd9Sstevel@tonic-gate #define _SOLARIS_SDK 36*7c478bd9Sstevel@tonic-gate #endif 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #include <stdlib.h> /* to pick up size_t typedef */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifdef _SOLARIS_SDK 41*7c478bd9Sstevel@tonic-gate #ifdef sunos4 42*7c478bd9Sstevel@tonic-gate #define SAFEMEMCPY(d, s, n) bcopy(s, d, n) 43*7c478bd9Sstevel@tonic-gate #else /* sunos4 */ 44*7c478bd9Sstevel@tonic-gate #define SAFEMEMCPY(d, s, n) memmove(d, s, n) 45*7c478bd9Sstevel@tonic-gate #endif /* sunos4 */ 46*7c478bd9Sstevel@tonic-gate #endif /* _SOLARIS_SDK */ 47*7c478bd9Sstevel@tonic-gate /* 48*7c478bd9Sstevel@tonic-gate * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear 49*7c478bd9Sstevel@tonic-gate * as valid BER tags, and so it is safe to use them to report errors. In 50*7c478bd9Sstevel@tonic-gate * fact, any tag for which the following is true is invalid: 51*7c478bd9Sstevel@tonic-gate * (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 ) 52*7c478bd9Sstevel@tonic-gate */ 53*7c478bd9Sstevel@tonic-gate #define LBER_ERROR 0xffffffffU 54*7c478bd9Sstevel@tonic-gate #define LBER_DEFAULT 0xffffffffU 55*7c478bd9Sstevel@tonic-gate #define LBER_END_OF_SEQORSET 0xfffffffeU 56*7c478bd9Sstevel@tonic-gate /* BER classes and mask */ 57*7c478bd9Sstevel@tonic-gate #define LBER_CLASS_UNIVERSAL 0x00 58*7c478bd9Sstevel@tonic-gate #define LBER_CLASS_APPLICATION 0x40 59*7c478bd9Sstevel@tonic-gate #define LBER_CLASS_CONTEXT 0x80 60*7c478bd9Sstevel@tonic-gate #define LBER_CLASS_PRIVATE 0xc0 61*7c478bd9Sstevel@tonic-gate #define LBER_CLASS_MASK 0xc0 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate /* BER encoding type and mask */ 64*7c478bd9Sstevel@tonic-gate #define LBER_PRIMITIVE 0x00 65*7c478bd9Sstevel@tonic-gate #define LBER_CONSTRUCTED 0x20 66*7c478bd9Sstevel@tonic-gate #define LBER_ENCODING_MASK 0x20 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate #define LBER_BIG_TAG_MASK 0x1f 69*7c478bd9Sstevel@tonic-gate #define LBER_MORE_TAG_MASK 0x80 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate /* general BER types we know about */ 72*7c478bd9Sstevel@tonic-gate #define LBER_BOOLEAN 0x01 73*7c478bd9Sstevel@tonic-gate #define LBER_INTEGER 0x02 74*7c478bd9Sstevel@tonic-gate #define LBER_BITSTRING 0x03 75*7c478bd9Sstevel@tonic-gate #define LBER_OCTETSTRING 0x04 76*7c478bd9Sstevel@tonic-gate #define LBER_NULL 0x05 77*7c478bd9Sstevel@tonic-gate #define LBER_ENUMERATED 0x0a 78*7c478bd9Sstevel@tonic-gate #define LBER_SEQUENCE 0x30 79*7c478bd9Sstevel@tonic-gate #define LBER_SET 0x31 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate typedef unsigned int ber_len_t; /* for BER len */ 83*7c478bd9Sstevel@tonic-gate typedef unsigned int ber_tag_t; /* for BER tags */ 84*7c478bd9Sstevel@tonic-gate typedef int ber_int_t; /* for BER ints, enums, and Booleans */ 85*7c478bd9Sstevel@tonic-gate typedef unsigned int ber_uint_t; /* unsigned equivalent of ber_int_t */ 86*7c478bd9Sstevel@tonic-gate typedef int ber_slen_t; /* signed equivalent of ber_len_t */ 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate typedef struct berval { 89*7c478bd9Sstevel@tonic-gate ber_len_t bv_len; 90*7c478bd9Sstevel@tonic-gate char *bv_val; 91*7c478bd9Sstevel@tonic-gate } BerValue; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate typedef struct berelement BerElement; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate #ifdef _SOLARIS_SDK 96*7c478bd9Sstevel@tonic-gate #define NULLBER ((BerElement *)NULL) 97*7c478bd9Sstevel@tonic-gate #endif 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate typedef int (*BERTranslateProc)(char **bufp, ber_uint_t *buflenp, 100*7c478bd9Sstevel@tonic-gate int free_input); 101*7c478bd9Sstevel@tonic-gate #ifndef macintosh 102*7c478bd9Sstevel@tonic-gate #if defined(_WINDOWS) || defined(_WIN32) || defined(_CONSOLE) 103*7c478bd9Sstevel@tonic-gate #include <winsock.h> /* for SOCKET */ 104*7c478bd9Sstevel@tonic-gate typedef SOCKET LBER_SOCKET; 105*7c478bd9Sstevel@tonic-gate #else 106*7c478bd9Sstevel@tonic-gate typedef int LBER_SOCKET; 107*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */ 108*7c478bd9Sstevel@tonic-gate #else /* macintosh */ 109*7c478bd9Sstevel@tonic-gate typedef void *LBER_SOCKET; 110*7c478bd9Sstevel@tonic-gate #endif /* macintosh */ 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate /* calling conventions used by library */ 113*7c478bd9Sstevel@tonic-gate #ifndef LDAP_CALL 114*7c478bd9Sstevel@tonic-gate #if defined(_WINDOWS) || defined(_WIN32) 115*7c478bd9Sstevel@tonic-gate #define LDAP_C __cdecl 116*7c478bd9Sstevel@tonic-gate #ifndef _WIN32 117*7c478bd9Sstevel@tonic-gate #define __stdcall _far _pascal 118*7c478bd9Sstevel@tonic-gate #define LDAP_CALLBACK _loadds 119*7c478bd9Sstevel@tonic-gate #else 120*7c478bd9Sstevel@tonic-gate #define LDAP_CALLBACK 121*7c478bd9Sstevel@tonic-gate #endif /* _WIN32 */ 122*7c478bd9Sstevel@tonic-gate #define LDAP_PASCAL __stdcall 123*7c478bd9Sstevel@tonic-gate #define LDAP_CALL LDAP_PASCAL 124*7c478bd9Sstevel@tonic-gate #else /* _WINDOWS */ 125*7c478bd9Sstevel@tonic-gate #define LDAP_C 126*7c478bd9Sstevel@tonic-gate #define LDAP_CALLBACK 127*7c478bd9Sstevel@tonic-gate #define LDAP_PASCAL 128*7c478bd9Sstevel@tonic-gate #define LDAP_CALL 129*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */ 130*7c478bd9Sstevel@tonic-gate #endif /* LDAP_CALL */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * function prototypes for lber library 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate #ifndef LDAP_API 136*7c478bd9Sstevel@tonic-gate #if defined(_WINDOWS) || defined(_WIN32) 137*7c478bd9Sstevel@tonic-gate #define LDAP_API(rt) rt 138*7c478bd9Sstevel@tonic-gate #else /* _WINDOWS */ 139*7c478bd9Sstevel@tonic-gate #define LDAP_API(rt) rt 140*7c478bd9Sstevel@tonic-gate #endif /* _WINDOWS */ 141*7c478bd9Sstevel@tonic-gate #endif /* LDAP_API */ 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate /* 144*7c478bd9Sstevel@tonic-gate * decode routines 145*7c478bd9Sstevel@tonic-gate */ 146*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_tag(BerElement *ber); 147*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_skip_tag(BerElement *ber, 148*7c478bd9Sstevel@tonic-gate ber_len_t *len); 149*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_peek_tag(BerElement *ber, 150*7c478bd9Sstevel@tonic-gate ber_len_t *len); 151*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_int(BerElement *ber, ber_int_t *num); 152*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_stringb(BerElement *ber, char *buf, 153*7c478bd9Sstevel@tonic-gate ber_len_t *len); 154*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_stringa(BerElement *ber, 155*7c478bd9Sstevel@tonic-gate char **buf); 156*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_stringal(BerElement *ber, 157*7c478bd9Sstevel@tonic-gate struct berval **bv); 158*7c478bd9Sstevel@tonic-gate ber_tag_t ber_get_bitstringa(BerElement *ber, 159*7c478bd9Sstevel@tonic-gate char **buf, ber_len_t *len); 160*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_null(BerElement *ber); 161*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_get_boolean(BerElement *ber, 162*7c478bd9Sstevel@tonic-gate int *boolval); 163*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_first_element(BerElement *ber, 164*7c478bd9Sstevel@tonic-gate ber_len_t *len, char **last); 165*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_CALL ber_next_element(BerElement *ber, 166*7c478bd9Sstevel@tonic-gate ber_len_t *len, char *last); 167*7c478bd9Sstevel@tonic-gate ber_tag_t LDAP_C ber_scanf(BerElement *ber, const char *fmt, 168*7c478bd9Sstevel@tonic-gate ...); 169*7c478bd9Sstevel@tonic-gate LDAP_API(void) LDAP_CALL ber_bvfree(struct berval *bv); 170*7c478bd9Sstevel@tonic-gate LDAP_API(void) LDAP_CALL ber_bvecfree(struct berval **bv); 171*7c478bd9Sstevel@tonic-gate struct berval *LDAP_CALL ber_bvdup(const struct berval *bv); 172*7c478bd9Sstevel@tonic-gate LDAP_API(void) LDAP_CALL ber_set_string_translators(BerElement *ber, 173*7c478bd9Sstevel@tonic-gate BERTranslateProc encode_proc, BERTranslateProc decode_proc); 174*7c478bd9Sstevel@tonic-gate LDAP_API(BerElement *) LDAP_CALL ber_init(const struct berval *bv); 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate /* 177*7c478bd9Sstevel@tonic-gate * encoding routines 178*7c478bd9Sstevel@tonic-gate */ 179*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_enum(BerElement *ber, ber_int_t num, 180*7c478bd9Sstevel@tonic-gate ber_tag_t tag); 181*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_int(BerElement *ber, ber_int_t num, 182*7c478bd9Sstevel@tonic-gate ber_tag_t tag); 183*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_ostring(BerElement *ber, char *str, 184*7c478bd9Sstevel@tonic-gate ber_len_t len, ber_tag_t tag); 185*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_string(BerElement *ber, char *str, 186*7c478bd9Sstevel@tonic-gate ber_tag_t tag); 187*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_bitstring(BerElement *ber, char *str, 188*7c478bd9Sstevel@tonic-gate ber_len_t bitlen, ber_tag_t tag); 189*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_null(BerElement *ber, ber_tag_t tag); 190*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_boolean(BerElement *ber, int boolval, 191*7c478bd9Sstevel@tonic-gate ber_tag_t tag); 192*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_start_seq(BerElement *ber, ber_tag_t tag); 193*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_start_set(BerElement *ber, ber_tag_t tag); 194*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_seq(BerElement *ber); 195*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_put_set(BerElement *ber); 196*7c478bd9Sstevel@tonic-gate int LDAP_C ber_printf(BerElement *ber, const char *fmt, ...); 197*7c478bd9Sstevel@tonic-gate int LDAP_CALL ber_flatten(BerElement *ber, 198*7c478bd9Sstevel@tonic-gate struct berval **bvPtr); 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate /* 201*7c478bd9Sstevel@tonic-gate * miscellaneous routines 202*7c478bd9Sstevel@tonic-gate */ 203*7c478bd9Sstevel@tonic-gate LDAP_API(void) LDAP_CALL ber_free(BerElement *ber, int freebuf); 204*7c478bd9Sstevel@tonic-gate LDAP_API(BerElement*) LDAP_CALL ber_alloc(void); 205*7c478bd9Sstevel@tonic-gate LDAP_API(BerElement*) LDAP_CALL der_alloc(void); 206*7c478bd9Sstevel@tonic-gate LDAP_API(BerElement*) LDAP_CALL ber_alloc_t(int options); 207*7c478bd9Sstevel@tonic-gate LDAP_API(BerElement*) LDAP_CALL ber_dup(BerElement *ber); 208*7c478bd9Sstevel@tonic-gate ber_int_t LDAP_CALL ber_read(BerElement *ber, char *buf, 209*7c478bd9Sstevel@tonic-gate ber_len_t len); 210*7c478bd9Sstevel@tonic-gate ber_int_t LDAP_CALL ber_write(BerElement *ber, char *buf, 211*7c478bd9Sstevel@tonic-gate ber_len_t len, int nosos); 212*7c478bd9Sstevel@tonic-gate LDAP_API(void) LDAP_CALL ber_reset(BerElement *ber, int was_writing); 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate #endif 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate #endif /* _LBER_H */ 219