]> git.sur5r.net Git - openldap/blob - libraries/libldap/tmpltest.c
"const"ify some static arrays, and related parameters/variables
[openldap] / libraries / libldap / tmpltest.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 #include "portable.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include <ac/socket.h>
11 #include <ac/time.h>
12
13 #ifdef HAVE_CONSOLE_H
14 #include <console.h>
15 #endif /* MACOS */
16
17 #include "lber.h"
18 #include "ldap.h"
19 #include "disptmpl.h"
20 #include "srchpref.h"
21
22 static void dump_tmpl    ( struct ldap_disptmpl *tmpl );
23 static void dump_srchpref( struct ldap_searchobj *sp );
24
25 #define NULLSTRINGIFNULL( s )   ( s == NULL ? "(null)" : s )
26
27 int
28 main( int argc, char **argv )
29 {
30     struct ldap_disptmpl        *templates, *dtp;
31     struct ldap_searchobj       *so, *sop;
32     int                         err;
33
34 #ifdef HAVE_CONSOLE_H
35         ccommand( &argv );
36         for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
37             ;
38         }
39         cshow( stdout );
40 #endif /* MACOS */
41
42     if (( err = ldap_init_templates( "ldaptemplates.conf", &templates ))
43             != 0 ) {
44         fprintf( stderr, "ldap_init_templates failed (%d)\n", err );
45         exit( 1 );
46     }
47
48     if (( err = ldap_init_searchprefs( "ldapsearchprefs.conf", &so ))
49             != 0 ) {
50         fprintf( stderr, "ldap_init_searchprefs failed (%d)\n", err );
51         exit( 1 );
52     }
53
54     if ( argc == 1 ) {
55         printf( "*** Display Templates:\n" );
56         for ( dtp = ldap_first_disptmpl( templates ); dtp != NULLDISPTMPL;
57                 dtp = ldap_next_disptmpl( templates, dtp )) {
58             dump_tmpl( dtp );
59             printf( "\n\n" );
60         }
61
62         printf( "\n\n*** Search Objects:\n" );
63         for ( sop = ldap_first_searchobj( so ); sop != NULLSEARCHOBJ;
64                     sop = ldap_next_searchobj( so, sop )) {
65             dump_srchpref( sop );
66             printf( "\n\n" );
67         }
68
69     } else {
70         if (( dtp = ldap_oc2template( ++argv, templates )) == NULL ) {
71             fprintf( stderr, "no matching template found\n" );
72         } else {
73             dump_tmpl( dtp );
74         }
75     }
76
77
78     ldap_free_templates( templates );
79     ldap_free_searchprefs( so );
80
81     exit( 0 );
82 }
83
84
85 static const char *const syn_name[] = {
86     "?", "CIS", "MLS", "DN", "BOOL", "JPEG", "JPEGBTN", "FAX", "FAXBTN",
87     "AUDIOBTN", "TIME", "DATE", "URL", "SEARCHACT", "LINKACT", "ADDDNACT",
88     "VERIFYACT",
89 };
90
91 static const char *const syn_type[] = {
92     "?", "txt", "img", "?", "bool", "?", "?", "?", "btn",
93     "?", "?", "?", "?", "?", "?", "?",
94     "action", "?"
95 };
96
97 static char *includeattrs[] = { "objectClass", "sn", NULL };
98
99 static const char *const item_opts[] = {
100     "ro", "sort", "1val", "hide", "required", "hideiffalse", NULL
101 };
102
103 static const unsigned long item_opt_vals[] = {
104     LDAP_DITEM_OPT_READONLY,            LDAP_DITEM_OPT_SORTVALUES,
105     LDAP_DITEM_OPT_SINGLEVALUED,        LDAP_DITEM_OPT_HIDEIFEMPTY,
106     LDAP_DITEM_OPT_VALUEREQUIRED,       LDAP_DITEM_OPT_HIDEIFFALSE,
107 };
108
109
110 void
111 dump_tmpl( struct ldap_disptmpl *tmpl )
112 {
113     struct ldap_tmplitem        *rowp, *colp;
114     int                         i, rowcnt, colcnt;
115     char                        **fetchattrs;
116     struct ldap_oclist          *ocp;
117     struct ldap_adddeflist      *adp;
118
119     printf( "** Template \"%s\" (plural \"%s\", icon \"%s\")\n",
120             NULLSTRINGIFNULL( tmpl->dt_name ),
121             NULLSTRINGIFNULL( tmpl->dt_pluralname ),
122             NULLSTRINGIFNULL( tmpl->dt_iconname ));
123
124     printf( "object class list:\n" );
125     for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = ocp->oc_next ) {
126         for ( i = 0; ocp->oc_objclasses[ i ] != NULL; ++i ) {
127             printf( "%s%s", i == 0 ? "  " : " & ",
128                     NULLSTRINGIFNULL( ocp->oc_objclasses[ i ] ));
129         }
130         putchar( '\n' );
131     }
132     putchar( '\n' );
133
134     printf( "template options:          " );
135     if ( tmpl->dt_options == 0L ) {
136         printf( "NONE\n" );
137     } else {
138         printf( "%s %s %s\n", LDAP_IS_DISPTMPL_OPTION_SET( tmpl,
139                 LDAP_DTMPL_OPT_ADDABLE ) ? "addable" : "",
140                 LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALLOWMODRDN )
141                 ? "modrdn" : "",
142                 LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALTVIEW )
143                 ? "altview" : "" );
144     }
145
146     printf( "authenticate as attribute: %s\n", tmpl->dt_authattrname != NULL ?
147             tmpl->dt_authattrname : "<default>" );
148
149     printf( "default RDN attribute:     %s\n", tmpl->dt_defrdnattrname != NULL ?
150             tmpl->dt_defrdnattrname : "NONE" );
151
152     printf( "default add location:      %s\n", tmpl->dt_defaddlocation != NULL ?
153             tmpl->dt_defaddlocation : "NONE" );
154
155     printf( "\nnew entry value default rules:\n" );
156     for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = adp->ad_next ) {
157         if ( adp->ad_source == LDAP_ADSRC_CONSTANTVALUE ) {
158             printf( "  attribute %s <-- constant value \"%s\"\n",
159                 NULLSTRINGIFNULL( adp->ad_attrname),
160                 NULLSTRINGIFNULL( adp->ad_value ));
161         } else {
162             printf( "  attribute %s <-- adder's DN\n",
163                     NULLSTRINGIFNULL( adp->ad_attrname ));
164         }
165     }
166     putchar( '\n' );
167
168     printf( "\nfetch attributes & values:\n" );
169     if (( fetchattrs = ldap_tmplattrs( tmpl, includeattrs, 1,
170                 LDAP_SYN_OPT_DEFER )) == NULL ) {
171         printf( "  <none>\n" );
172     } else {
173         for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
174             printf( "  %s\n", fetchattrs[ i ] );
175             free( fetchattrs[ i ] );
176         }
177         free( (char *)fetchattrs );
178     }
179
180     printf( "\nfetch attributes only:\n" );
181     if (( fetchattrs = ldap_tmplattrs( tmpl, NULL, 0,
182                 LDAP_SYN_OPT_DEFER )) == NULL ) {
183         printf( "  <none>\n" );
184     } else {
185         for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
186             printf( "  %s\n", fetchattrs[ i ] );
187             free( fetchattrs[ i ] );
188         }
189         free( (char *)fetchattrs );
190     }
191
192     printf( "\ntemplate items:\n" );
193     rowcnt = 0;
194     for ( rowp = ldap_first_tmplrow( tmpl ); rowp != NULLTMPLITEM;
195             rowp = ldap_next_tmplrow( tmpl, rowp )) {
196         ++rowcnt;
197         colcnt = 0;
198         for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULLTMPLITEM;
199                 colp = ldap_next_tmplcol( tmpl, rowp, colp )) {
200             ++colcnt;
201             printf( "  %2d-%d: %s (%s%s", rowcnt, colcnt,
202                 syn_name[ colp->ti_syntaxid & 0x0000FFFF ],
203                 syn_type[ LDAP_GET_SYN_TYPE( colp->ti_syntaxid ) >> 24 ],
204                 (( LDAP_GET_SYN_OPTIONS( colp->ti_syntaxid ) &
205                 LDAP_SYN_OPT_DEFER ) != 0 ) ? ",defer" : "" );
206
207             for ( i = 0; item_opts[ i ] != NULL; ++i ) {
208                 if ( LDAP_IS_TMPLITEM_OPTION_SET( colp, item_opt_vals[ i ] )) {
209                     printf( ",%s", NULLSTRINGIFNULL( item_opts[ i ] ));
210                 }
211             }
212
213             printf( "), %s, %s", NULLSTRINGIFNULL( colp->ti_attrname ),
214                     NULLSTRINGIFNULL( colp->ti_label ));
215             if ( colp->ti_args != NULL ) {
216                 printf( ",args=" );
217                 for ( i = 0; colp->ti_args[ i ] != NULL; ++i ) {
218                     printf( "<%s>", NULLSTRINGIFNULL( colp->ti_args[ i ] ));
219                 }
220             }
221
222             putchar( '\n' );
223         }
224     }
225 }
226
227
228 void
229 dump_srchpref( struct ldap_searchobj *so )
230 {
231     int i;
232     struct ldap_searchattr *sa;
233     struct ldap_searchmatch *sm;
234
235     printf( "Object type prompt:  %s\n",
236             NULLSTRINGIFNULL( so->so_objtypeprompt ));
237     printf( "Options:             %s\n",
238             LDAP_IS_SEARCHOBJ_OPTION_SET( so, LDAP_SEARCHOBJ_OPT_INTERNAL ) ?
239             "internal" : "NONE" );
240     printf( "Prompt:              %s\n", NULLSTRINGIFNULL( so->so_prompt ));
241     printf( "Scope:               " );
242     switch ( so->so_defaultscope ) {
243     case LDAP_SCOPE_BASE:
244         printf( "LDAP_SCOPE_BASE" );
245         break;
246     case LDAP_SCOPE_ONELEVEL:
247         printf( "LDAP_SCOPE_ONELEVEL" );
248         break;
249     case LDAP_SCOPE_SUBTREE:
250         printf( "LDAP_SCOPE_SUBTREE" );
251         break;
252     default:
253         printf("*** unknown!" );
254     }
255     puts( "\n" );
256     printf( "Filter prefix:       %s\n",
257             NULLSTRINGIFNULL( so->so_filterprefix ));
258     printf( "Filter tag:          %s\n",
259             NULLSTRINGIFNULL( so->so_filtertag ));
260     printf( "Default select attr: %s\n",
261             NULLSTRINGIFNULL( so->so_defaultselectattr ));
262     printf( "Default select text: %s\n",
263             NULLSTRINGIFNULL( so->so_defaultselecttext ));
264     printf( "Searchable attributes ---- \n" );
265     for ( sa = so->so_salist; sa != NULL; sa = sa->sa_next ) {
266         printf( "  Label: %s\n", NULLSTRINGIFNULL( sa->sa_attrlabel ));
267         printf( "  Attribute: %s\n", NULLSTRINGIFNULL( sa->sa_attr ));
268         printf( "  Select attr: %s\n", NULLSTRINGIFNULL( sa->sa_selectattr ));
269         printf( "  Select text: %s\n", NULLSTRINGIFNULL( sa->sa_selecttext ));
270         printf( "  Match types ---- \n" );
271         for ( i = 0, sm = so->so_smlist; sm != NULL; i++, sm = sm->sm_next ) {
272             if (( sa->sa_matchtypebitmap >> i ) & 1 ) {
273                 printf( "    %s (%s)\n",
274                         NULLSTRINGIFNULL( sm->sm_matchprompt ),
275                         NULLSTRINGIFNULL( sm->sm_filter ));
276             }
277         }
278     }
279 }