Lines Matching defs:ber

57 /* io.c - ber general i/o routines */
203 * Note: ber_read() only uses the ber_end and ber_ptr elements of ber.
206 * the ber structure, those functions will need to be changed as well.
210 ber_read( BerElement *ber, char *buf, ber_len_t len )
215 nleft = ber->ber_end - ber->ber_ptr;
218 SAFEMEMCPY( buf, ber->ber_ptr, (size_t)actuallen );
220 ber->ber_ptr += actuallen;
226 * enlarge the ber buffer.
230 nslberi_ber_realloc( BerElement *ber, ber_len_t len )
238 have_bytes = ber->ber_end - ber->ber_buf;
243 oldbuf = ber->ber_buf;
245 if (ber->ber_buf == NULL) {
246 if ( (ber->ber_buf = (char *)NSLBERI_MALLOC( (size_t)total ))
250 ber->ber_flags &= ~LBER_FLAG_NO_FREE_BUFFER;
252 if ( ber->ber_flags & LBER_FLAG_NO_FREE_BUFFER ) {
254 if ( (ber->ber_buf = (char *)NSLBERI_MALLOC(
258 ber->ber_flags &= ~LBER_FLAG_NO_FREE_BUFFER;
260 SAFEMEMCPY( ber->ber_buf, oldbuf, have_bytes );
262 if ( (ber->ber_buf = (char *)NSLBERI_REALLOC(
263 ber->ber_buf,(size_t)total )) == NULL ) {
269 ber->ber_end = ber->ber_buf + total;
273 * reset all the sos and ber pointers. Offsets would've been
277 if ( ber->ber_buf != oldbuf ) {
278 ber->ber_ptr = ber->ber_buf + (ber->ber_ptr - oldbuf);
280 for ( s = ber->ber_sos; s != NULLSEQORSET; s = s->sos_next ) {
282 s->sos_first = ber->ber_buf + off;
285 s->sos_ptr = ber->ber_buf + off;
297 ber_write( BerElement *ber, char *buf, ber_len_t len, int nosos )
299 if ( nosos || ber->ber_sos == NULL ) {
300 if ( ber->ber_ptr + len > ber->ber_end ) {
301 if ( nslberi_ber_realloc( ber, len ) != 0 )
304 SAFEMEMCPY( ber->ber_ptr, buf, (size_t)len );
305 ber->ber_ptr += len;
308 if ( ber->ber_sos->sos_ptr + len > ber->ber_end ) {
309 if ( nslberi_ber_realloc( ber, len ) != 0 )
312 SAFEMEMCPY( ber->ber_sos->sos_ptr, buf, (size_t)len );
313 ber->ber_sos->sos_ptr += len;
314 ber->ber_sos->sos_clen += len;
321 ber_free( BerElement *ber, int freebuf )
323 if ( ber != NULL ) {
325 !(ber->ber_flags & LBER_FLAG_NO_FREE_BUFFER)) {
326 NSLBERI_FREE(ber->ber_buf);
328 NSLBERI_FREE( (char *) ber );
337 ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
341 if ( ber->ber_rwptr == NULL ) {
342 ber->ber_rwptr = ber->ber_buf;
343 } else if (ber->ber_rwptr >= ber->ber_end) {
348 towrite = ber->ber_ptr - ber->ber_rwptr;
354 sb->sb_sd, ber->ber_rwptr != ber->ber_buf ? " (re-flush)"
358 lber_bprint( ber->ber_rwptr, towrite );
363 rc = write( sb->sb_copyfd, ber->ber_buf, towrite );
374 rc = udp_write( sb, ber->ber_buf + nwritten,
391 sb->sb_sd, ber->ber_rwptr, (size_t)towrite,
397 if ( (rc = BerWrite( sb, ber->ber_rwptr,
405 ber->ber_rwptr += rc;
409 ber_free( ber, 1 );
420 BerElement *ber;
422 if ( (ber = (BerElement*)NSLBERI_CALLOC( 1,
436 ber->ber_tag = LBER_DEFAULT;
437 ber->ber_options = options;
438 ber->ber_buf = (char*)ber + sizeof(struct berelement);
439 ber->ber_ptr = ber->ber_buf;
440 ber->ber_end = ber->ber_buf + EXBUFSIZ;
441 ber->ber_flags = LBER_FLAG_NO_FREE_BUFFER;
443 return( ber );
463 ber_dup( BerElement *ber )
470 *new = *ber;
478 ber_init_w_nullchar( BerElement *ber, int options )
480 (void) memset( (char *)ber, '\0', sizeof(struct berelement) );
481 ber->ber_tag = LBER_DEFAULT;
492 ber->ber_options = options;
498 ber_reset( BerElement *ber, int was_writing )
501 ber->ber_end = ber->ber_ptr;
502 ber->ber_ptr = ber->ber_buf;
504 ber->ber_ptr = ber->ber_end;
507 ber->ber_rwptr = NULL;
514 ber_dump( BerElement *ber, int inout )
518 ber->ber_buf, ber->ber_ptr, ber->ber_rwptr, ber->ber_end );
522 ber->ber_end - ber->ber_ptr );
524 lber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
527 ber->ber_ptr - ber->ber_buf );
529 lber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
593 ber_get_next( Sockbuf *sb, ber_len_t *len, BerElement *ber )
608 * Any ber element looks like this: tag length contents.
624 if ( ber->ber_rwptr == NULL ) {
632 ber->ber_tag = tag;
659 ber->ber_len = *len;
663 * It's this buffer that's passed to all the other ber decoding
678 if ( (ber->ber_buf = (char *)NSLBERI_CALLOC( 1,(size_t)*len ))
682 ber->ber_flags &= ~LBER_FLAG_NO_FREE_BUFFER;
683 ber->ber_ptr = ber->ber_buf;
684 ber->ber_end = ber->ber_buf + *len;
685 ber->ber_rwptr = ber->ber_buf;
688 toread = (uintptr_t)ber->ber_end - (uintptr_t)ber->ber_rwptr;
690 if ( (rc = BerRead( sb, ber->ber_rwptr, (ber_int_t)toread )) <= 0 ) {
695 ber->ber_rwptr += rc;
702 tag, ber->ber_len );
705 ber_dump( ber, 1 );
709 *len = ber->ber_len;
710 ber->ber_rwptr = NULL;
711 return( ber->ber_tag );
746 ber_set_option( struct berelement *ber, int option, void *value )
751 * NULL for ber. Handle this as a special case.
761 * NULL for ber. Handle this as a special case.
771 * all the rest require a non-NULL ber
773 if ( !NSLBERI_VALID_BERELEMENT_POINTER( ber )) {
781 ber->ber_options |= option;
783 ber->ber_options &= ~option;
787 ber->ber_end = ber->ber_ptr + *((ber_uint_t *)value);
790 ber->ber_end = ber->ber_buf + *((ber_uint_t *)value);
793 ber->ber_ptr = ber->ber_buf + *((ber_uint_t *)value);
807 ber_get_option( struct berelement *ber, int option, void *value )
811 * NULL for ber. Handle this as a special case
821 * NULL for ber. Handle this as a special case.
830 * all the rest require a non-NULL ber
832 if ( !NSLBERI_VALID_BERELEMENT_POINTER( ber )) {
839 *((int *) value) = (ber->ber_options & option);
842 *((ber_uint_t *) value) = ber->ber_end - ber->ber_ptr;
845 *((ber_uint_t *) value) = ber->ber_end - ber->ber_buf;
848 *((ber_uint_t *) value) = ber->ber_ptr - ber->ber_buf;
982 * This routine also allocates a ber data buffer within the same block, thus
1012 ber_special_free(void* buf, BerElement *ber)
1014 if (!(ber->ber_flags & LBER_FLAG_NO_FREE_BUFFER)) {
1015 NSLBERI_FREE(ber->ber_buf);
1090 BerElement *ber, ber_uint_t *Bytes_Scanned )
1092 return (ber_get_next_buffer_ext( buffer, buffer_size, len, ber,
1099 BerElement *ber, ber_uint_t *Bytes_Scanned, Sockbuf *sock )
1111 * Any ber element looks like this: tag length contents.
1130 if ( ber->ber_rwptr == NULL ) {
1138 ber->ber_tag = tag;
1165 ber->ber_len = *len;
1169 * It's this buffer that's passed to all the other ber decoding
1185 if ( ber->ber_buf + *len > ber->ber_end ) {
1186 if ( nslberi_ber_realloc( ber, *len ) != 0 )
1189 ber->ber_ptr = ber->ber_buf;
1190 ber->ber_end = ber->ber_buf + *len;
1191 ber->ber_rwptr = ber->ber_buf;
1194 toread = (uintptr_t)ber->ber_end - (uintptr_t)ber->ber_rwptr;
1196 if ( (rc = read_bytes( &sb, (unsigned char *)ber->ber_rwptr,
1202 ber->ber_rwptr += rc;
1205 *len = ber->ber_len;
1207 return( ber->ber_tag );
1220 * are a BER encoding taken from the ber argument. The bvPtr pointer
1230 ber_flatten( BerElement *ber, struct berval **bvPtr )
1245 if ( ber == NULL ) {
1249 len = ber->ber_ptr - ber->ber_buf;
1254 SAFEMEMCPY( new->bv_val, ber->ber_buf, (size_t)len );
1275 BerElement *ber;
1278 if (( ber = ber_alloc_t( 0 )) != NULLBER ) {
1281 if ( (ber_write ( ber, bv->bv_val, bv->bv_len, 0 ))
1283 ber_free( ber, 1 );
1290 * and initialized ber element can be READ
1292 ber_reset( ber, 1);
1298 return( ber );