*/
#define LBER_ERROR 0xffffffffL
#define LBER_DEFAULT 0xffffffffL
-#define LBER_END_SEQORSET 0xfffffffeL
+/* #define LBER_END_SEQORSET 0xfffffffeL *//* no part of LDAP C-API */
/* general BER types we know about */
#define LBER_BOOLEAN 0x01L
LDAP_F void ber_reset LDAP_P(( BerElement *ber, int was_writing ));
/*
- * LDAPv3 routines (not yet implemented)
+ * LDAP draft-ietf-ldapext-ldap-c-api-01 routines
*/
LDAP_F BerElement *ber_init LDAP_P(( struct berval *bv ));
LDAP_F int ber_flatten LDAP_P(( BerElement *ber, struct berval **bvPtr ));
*last = ber->ber_ptr + *len;
if ( *last == ber->ber_ptr ) {
+#ifdef LBER_END_SEQORSET
+ return( LBER_END_SEQORSET );
+#else
return( LBER_DEFAULT );
+#endif
}
return( ber_peek_tag( ber, len ) );
ber_next_element( BerElement *ber, unsigned long *len, char *last )
{
if ( ber->ber_ptr == last ) {
+#ifdef LBER_END_SEQORSET
+ return( LBER_END_SEQORSET );
+#else
return( LBER_DEFAULT );
+#endif
}
return( ber_peek_tag( ber, len ) );
*sss = NULL;
j = 0;
for ( tag = ber_first_element( ber, &len, &last );
- tag != LBER_DEFAULT && rc != LBER_DEFAULT;
- tag = ber_next_element( ber, &len, last ) ) {
+ tag != LBER_DEFAULT &&
+#ifdef LDAP_END_SEQORSET
+ tag != LBER_END_SEQORSET &&
+#endif
+ rc != LBER_DEFAULT;
+ tag = ber_next_element( ber, &len, last ) )
+ {
if ( *sss == NULL ) {
*sss = (char **) malloc(
2 * sizeof(char *) );
rc = ber_get_stringa( ber, &((*sss)[j]) );
j++;
}
+#ifdef LDAP_END_SEQORSET
+ if (rc != LBER_DEFAULT &&
+ tag != LBER_END_SEQORSET )
+ {
+ rc = LBER_DEFAULT;
+ }
+#endif
if ( j > 0 )
(*sss)[j] = NULL;
break;
*bv = NULL;
j = 0;
for ( tag = ber_first_element( ber, &len, &last );
- tag != LBER_DEFAULT && rc != LBER_DEFAULT;
- tag = ber_next_element( ber, &len, last ) ) {
+ tag != LBER_DEFAULT &&
+#ifdef LDAP_END_SEQORSET
+ tag != LBER_END_SEQORSET &&
+#endif
+ rc != LBER_DEFAULT;
+ tag = ber_next_element( ber, &len, last ) )
+ {
if ( *bv == NULL ) {
*bv = (struct berval **) malloc(
2 * sizeof(struct berval *) );
rc = ber_get_stringal( ber, &((*bv)[j]) );
j++;
}
+#ifdef LDAP_END_SEQORSET
+ if (rc != LBER_DEFAULT &&
+ tag != LBER_END_SEQORSET )
+ {
+ rc = LBER_DEFAULT;
+ }
+#endif
if ( j > 0 )
(*bv)[j] = NULL;
break;
void
ber_bvfree( struct berval *bv )
{
+#ifdef LBER_ASSERT
+ assert(bv != NULL); /* bv damn better point to something */
+#endif
if ( bv->bv_val != NULL )
free( bv->bv_val );
free( (char *) bv );
{
int i;
+#ifdef LBER_ASSERT
+ assert(bv != NULL); /* bv damn better point to something */
+#endif
for ( i = 0; bv[i] != NULL; i++ )
ber_bvfree( bv[i] );
free( (char *) bv );
== NULL ) {
return( NULL );
}
+
+ if ( bv->bv_val == NULL ) {
+ new->bv_val = NULL;
+ new->bv_len = 0;
+ return ( new );
+ }
+
if ( (new->bv_val = (char *) malloc( bv->bv_len + 1 )) == NULL ) {
+ free( new );
return( NULL );
}
+
SAFEMEMCPY( new->bv_val, bv->bv_val, (size_t) bv->bv_len );
new->bv_val[bv->bv_len] = '\0';
new->bv_len = bv->bv_len;
}
+/* OLD U-Mich ber_init() */
void
ber_init_w_nullc( BerElement *ber, int options )
{
ber->ber_options = (char) options;
}
+/* New C-API ber_init() */
+/* This function constructs a BerElement containing a copy
+** of the data in the bv argument.
+*/
BerElement *
ber_init( struct berval *bv )
{
- return ( NULL );
+ BerElement *ber;
+
+ if ( bv == NULL ) {
+ return NULL;
+ }
+
+ ber = ber_alloc_t( 0 );
+
+ if( ber == NULLBER ) {
+ /* allocation failed */
+ return ( NULL );
+ }
+
+ /* copy the data */
+ if ( (ber_write ( ber, bv->bv_val, bv->bv_len, 0 )) != bv->bv_len ) {
+ /* write failed, so free and return NULL */
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ ber_reset( ber, 1 ); /* reset the pointer to the start of the buffer */
+
+ return ( ber );
}
+/* New C-API ber_flatten routine */
+/* This routine allocates a struct berval whose contents are a BER
+** encoding taken from the ber argument. The bvPtr pointer pointers to
+** the returned berval.
+*/
+int ber_flatten(
+ BerElement *ber,
+ struct berval **bvPtr)
+{
+ struct berval *bv;
+
+ if(bvPtr == NULL) {
+ return( -1 );
+ }
+
+ if ( (bv = malloc( sizeof(struct berval))) == NULL ) {
+ return( -1 );
+ }
+
+ if ( ber == NULL ) {
+ /* ber is null, create an empty berval */
+ bv->bv_val = NULL;
+ bv->bv_len = 0;
+
+ } else {
+ /* copy the berval */
+ ptrdiff_t len = ber->ber_ptr - ber->ber_buf;
+
+ if ( (bv->bv_val = (char *) malloc( len + 1 )) == NULL ) {
+ ber_bvfree( bv );
+ return( -1 );
+ }
+
+ SAFEMEMCPY( bv->bv_val, ber->ber_buf, (size_t)len );
+ bv->bv_val[len] = '\0';
+ bv->bv_len = len;
+ }
+
+ *bvPtr = bv;
+ return( 0 );
+}
void
ber_reset( BerElement *ber, int was_writing )