dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / ldap / common / etest.c
blobbd48878d1d004bae2f4ecb3d5298be6dbf27b00b
1 /*
3 * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
6 */
7 #pragma ident "%Z%%M% %I% %E% SMI"
8 /* test.c - lber encoding test program */
9 /*
10 * Copyright (c) 1990 Regents of the University of Michigan.
11 * All rights reserved.
14 #include <stdio.h>
15 #include <string.h>
16 #ifdef MACOS
17 #include <stdlib.h>
18 #include <unix.h>
19 #include <fcntl.h>
20 #include <console.h>
21 #else /* MACOS */
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #endif /* MACOS */
25 #include "lber.h"
27 static usage( char *name )
29 fprintf( stderr, "usage: %s fmtstring\n", name );
32 main( int argc, char **argv )
34 int i, num, len;
35 char *s, *p;
36 Seqorset *sos = NULLSEQORSET;
37 BerElement *ber;
38 Sockbuf sb;
39 extern char *optarg;
41 if ( argc < 2 ) {
42 usage( argv[0] );
43 exit( 1 );
46 bzero( &sb, sizeof(sb) );
47 sb.sb_sd = 1;
48 sb.sb_ber.ber_buf = NULL;
50 #ifdef MACOS
51 ccommand( &argv );
52 cshow( stdout );
54 if (( sb.sb_sd = open( "lber-test", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY ))
55 < 0 ) {
56 perror( "open" );
57 exit( 1 );
59 #endif /* MACOS */
61 if ( (ber = ber_alloc()) == NULLBER ) {
62 perror( "ber_alloc" );
63 exit( 1 );
66 num = 7;
67 if ( ber_printf( ber, "{ti}", 0x1f44, num ) == -1 ) {
68 fprintf( stderr, "ber_printf returns -1" );
69 exit( 1 );
72 if ( ber_flush( &sb, ber, 1 ) == -1 ) {
73 perror( "ber_flush" );
74 exit( 1 );
76 #ifdef notdef
77 for ( s = argv[1]; *s; s++ ) {
78 if ( fgets( buf, sizeof(buf), stdin ) == NULL )
79 break;
80 if ( (p = strchr( buf, '\n' )) != NULL )
81 *p = '\0';
83 switch ( *s ) {
84 case 'i': /* int */
85 case 'b': /* boolean */
86 i = atoi( buf );
87 if ( ber_printf( ber, "i", i ) == -1 ) {
88 fprintf( stderr, "ber_printf i\n" );
89 exit( 1 );
91 break;
93 case 'e': /* enumeration */
94 i = va_arg( ap, int );
95 rc = ber_put_enum( ber, i, (char)ber->ber_tag );
96 break;
98 case 'n': /* null */
99 rc = ber_put_null( ber, (char)ber->ber_tag );
100 break;
102 case 'o': /* octet string (non-null terminated) */
103 s = va_arg( ap, char * );
104 len = va_arg( ap, int );
105 rc = ber_put_ostring( ber, s, len, (char)ber->ber_tag );
106 break;
108 case 's': /* string */
109 s = va_arg( ap, char * );
110 rc = ber_put_string( ber, s, (char)ber->ber_tag );
111 break;
113 case 'B': /* bit string */
114 s = va_arg( ap, char * );
115 len = va_arg( ap, int ); /* in bits */
116 rc = ber_put_bitstring( ber, s, len, (char)ber->ber_tag );
117 break;
119 case 't': /* tag for the next element */
120 ber->ber_tag = va_arg( ap, int );
121 ber->ber_usertag = 1;
122 break;
124 case 'v': /* vector of strings */
125 if ( (ss = va_arg( ap, char ** )) == NULL )
126 break;
127 for ( i = 0; ss[i] != NULL; i++ ) {
128 if ( (rc = ber_put_string( ber, ss[i],
129 (char)ber->ber_tag )) == -1 )
130 break;
132 break;
134 case 'V': /* sequences of strings + lengths */
135 if ( (bv = va_arg( ap, struct berval ** )) == NULL )
136 break;
137 for ( i = 0; bv[i] != NULL; i++ ) {
138 if ( (rc = ber_put_ostring( ber, bv[i]->bv_val,
139 bv[i]->bv_len, (char)ber->ber_tag )) == -1 )
140 break;
142 break;
144 case '{': /* begin sequence */
145 rc = ber_start_seq( ber, (char)ber->ber_tag );
146 break;
148 case '}': /* end sequence */
149 rc = ber_put_seqorset( ber );
150 break;
152 case '[': /* begin set */
153 rc = ber_start_set( ber, (char)ber->ber_tag );
154 break;
156 case ']': /* end set */
157 rc = ber_put_seqorset( ber );
158 break;
160 default:
161 #ifndef NO_USERINTERFACE
162 fprintf( stderr, "unknown fmt %c\n", *fmt );
163 #endif /* NO_USERINTERFACE */
164 rc = -1;
165 break;
170 #endif
172 return( 0 );