xref: /titanic_41/usr/src/lib/libldap5/include/ldap/disptmpl.h (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
1 /*
2  * Copyright (c) 2001 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * The contents of this file are subject to the Netscape Public
10  * License Version 1.1 (the "License"); you may not use this file
11  * except in compliance with the License. You may obtain a copy of
12  * the License at http://www.mozilla.org/NPL/
13  *
14  * Software distributed under the License is distributed on an "AS
15  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16  * implied. See the License for the specific language governing
17  * rights and limitations under the License.
18  *
19  * The Original Code is Mozilla Communicator client code, released
20  * March 31, 1998.
21  *
22  * The Initial Developer of the Original Code is Netscape
23  * Communications Corporation. Portions created by Netscape are
24  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25  * Rights Reserved.
26  *
27  * Contributor(s):
28  */
29 
30 /*
31  * Copyright (c) 1993, 1994 Regents of the University of Michigan.
32  * All rights reserved.
33  *
34  * Redistribution and use in source and binary forms are permitted
35  * provided that this notice is preserved and that due credit is given
36  * to the University of Michigan at Ann Arbor. The name of the University
37  * may not be used to endorse or promote products derived from this
38  * software without specific prior written permission. This software
39  * is provided ``as is'' without express or implied warranty.
40  *
41  * disptmpl.h:  display template library defines
42  */
43 
44 #ifndef _DISPTMPL_H
45 #define _DISPTMPL_H
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* calling conventions used by library */
52 #ifndef LDAP_CALL
53 #if defined( _WINDOWS ) || defined( _WIN32 )
54 #define LDAP_C __cdecl
55 #ifndef _WIN32
56 #define __stdcall _far _pascal
57 #define LDAP_CALLBACK _loadds
58 #else
59 #define LDAP_CALLBACK
60 #endif /* _WIN32 */
61 #define LDAP_PASCAL __stdcall
62 #define LDAP_CALL LDAP_PASCAL
63 #else /* _WINDOWS */
64 #define LDAP_C
65 #define LDAP_CALLBACK
66 #define LDAP_PASCAL
67 #define LDAP_CALL
68 #endif /* _WINDOWS */
69 #endif /* LDAP_CALL */
70 
71 #ifndef _SOLARIS_SDK
72 
73 #define LDAP_TEMPLATE_VERSION	1
74 
75 /*
76  * general types of items (confined to most significant byte)
77  */
78 #define LDAP_SYN_TYPE_TEXT		0x01000000L
79 #define LDAP_SYN_TYPE_IMAGE		0x02000000L
80 #define LDAP_SYN_TYPE_BOOLEAN		0x04000000L
81 #define LDAP_SYN_TYPE_BUTTON		0x08000000L
82 #define LDAP_SYN_TYPE_ACTION		0x10000000L
83 
84 
85 /*
86  * syntax options (confined to second most significant byte)
87  */
88 #define LDAP_SYN_OPT_DEFER		0x00010000L
89 
90 
91 /*
92  * display template item syntax ids (defined by common agreement)
93  * these are the valid values for the ti_syntaxid of the tmplitem
94  * struct (defined below).  A general type is encoded in the
95  * most-significant 8 bits, and some options are encoded in the next
96  * 8 bits.  The lower 16 bits are reserved for the distinct types.
97  */
98 #define LDAP_SYN_CASEIGNORESTR	( 1 | LDAP_SYN_TYPE_TEXT )
99 #define LDAP_SYN_MULTILINESTR	( 2 | LDAP_SYN_TYPE_TEXT )
100 #define LDAP_SYN_DN		( 3 | LDAP_SYN_TYPE_TEXT )
101 #define LDAP_SYN_BOOLEAN	( 4 | LDAP_SYN_TYPE_BOOLEAN )
102 #define LDAP_SYN_JPEGIMAGE	( 5 | LDAP_SYN_TYPE_IMAGE )
103 #define LDAP_SYN_JPEGBUTTON	( 6 | LDAP_SYN_TYPE_BUTTON | LDAP_SYN_OPT_DEFER )
104 #define LDAP_SYN_FAXIMAGE	( 7 | LDAP_SYN_TYPE_IMAGE )
105 #define LDAP_SYN_FAXBUTTON	( 8 | LDAP_SYN_TYPE_BUTTON | LDAP_SYN_OPT_DEFER )
106 #define LDAP_SYN_AUDIOBUTTON	( 9 | LDAP_SYN_TYPE_BUTTON | LDAP_SYN_OPT_DEFER )
107 #define LDAP_SYN_TIME		( 10 | LDAP_SYN_TYPE_TEXT )
108 #define LDAP_SYN_DATE		( 11 | LDAP_SYN_TYPE_TEXT )
109 #define LDAP_SYN_LABELEDURL	( 12 | LDAP_SYN_TYPE_TEXT )
110 #define LDAP_SYN_SEARCHACTION	( 13 | LDAP_SYN_TYPE_ACTION )
111 #define LDAP_SYN_LINKACTION	( 14 | LDAP_SYN_TYPE_ACTION )
112 #define LDAP_SYN_ADDDNACTION	( 15 | LDAP_SYN_TYPE_ACTION )
113 #define LDAP_SYN_VERIFYDNACTION ( 16 | LDAP_SYN_TYPE_ACTION )
114 #define LDAP_SYN_RFC822ADDR	( 17 | LDAP_SYN_TYPE_TEXT )
115 
116 
117 /*
118  * handy macros
119  */
120 #define LDAP_GET_SYN_TYPE( syid )	((syid) & 0xFF000000UL )
121 #define LDAP_GET_SYN_OPTIONS( syid )	((syid) & 0x00FF0000UL )
122 
123 
124 /*
125  * display options for output routines (used by entry2text and friends)
126  */
127 /*
128  * use calculated label width (based on length of longest label in
129  * template) instead of contant width
130  */
131 #define LDAP_DISP_OPT_AUTOLABELWIDTH	0x00000001L
132 #define LDAP_DISP_OPT_HTMLBODYONLY	0x00000002L
133 
134 /*
135  * perform search actions (applies to ldap_entry2text_search only)
136  */
137 #define LDAP_DISP_OPT_DOSEARCHACTIONS	0x00000002L
138 
139 /*
140  * include additional info. relevant to "non leaf" entries only
141  * used by ldap_entry2html and ldap_entry2html_search to include "Browse"
142  * and "Move Up" HREFs
143  */
144 #define LDAP_DISP_OPT_NONLEAF		0x00000004L
145 
146 #endif /* ifndef _SOLARIS_SDK */
147 
148 /*
149  * display template item options (may not apply to all types)
150  * if this bit is set in ti_options, it applies.
151  */
152 #define LDAP_DITEM_OPT_READONLY		0x00000001L
153 #define LDAP_DITEM_OPT_SORTVALUES	0x00000002L
154 #define LDAP_DITEM_OPT_SINGLEVALUED	0x00000004L
155 #define LDAP_DITEM_OPT_HIDEIFEMPTY	0x00000008L
156 #define LDAP_DITEM_OPT_VALUEREQUIRED	0x00000010L
157 #define LDAP_DITEM_OPT_HIDEIFFALSE	0x00000020L	/* booleans only */
158 
159 
160 #ifndef _SOLARIS_SDK
161 
162 /*
163  * display template item structure
164  */
165 struct ldap_tmplitem {
166     unsigned long		ti_syntaxid;
167     unsigned long		ti_options;
168     char  			*ti_attrname;
169     char			*ti_label;
170     char			**ti_args;
171     struct ldap_tmplitem	*ti_next_in_row;
172     struct ldap_tmplitem	*ti_next_in_col;
173     void			*ti_appdata;
174 };
175 
176 #define NULLTMPLITEM	((struct ldap_tmplitem *)0)
177 
178 #define LDAP_SET_TMPLITEM_APPDATA( ti, datap )	\
179 	(ti)->ti_appdata = (void *)(datap)
180 
181 #define LDAP_GET_TMPLITEM_APPDATA( ti, type )	\
182 	(type)((ti)->ti_appdata)
183 
184 #define LDAP_IS_TMPLITEM_OPTION_SET( ti, option )	\
185 	(((ti)->ti_options & option ) != 0 )
186 
187 
188 /*
189  * object class array structure
190  */
191 struct ldap_oclist {
192     char		**oc_objclasses;
193     struct ldap_oclist	*oc_next;
194 };
195 
196 #define NULLOCLIST	((struct ldap_oclist *)0)
197 
198 
199 /*
200  * add defaults list
201  */
202 struct ldap_adddeflist {
203     int			ad_source;
204 #define LDAP_ADSRC_CONSTANTVALUE	1
205 #define LDAP_ADSRC_ADDERSDN		2
206     char		*ad_attrname;
207     char		*ad_value;
208     struct ldap_adddeflist	*ad_next;
209 };
210 
211 #define NULLADLIST	((struct ldap_adddeflist *)0)
212 
213 
214 /*
215  * display template global options
216  * if this bit is set in dt_options, it applies.
217  */
218 /*
219  * users should be allowed to try to add objects of these entries
220  */
221 #define LDAP_DTMPL_OPT_ADDABLE		0x00000001L
222 
223 /*
224  * users should be allowed to do "modify RDN" operation of these entries
225  */
226 #define LDAP_DTMPL_OPT_ALLOWMODRDN	0x00000002L
227 
228 /*
229  * this template is an alternate view, not a primary view
230  */
231 #define LDAP_DTMPL_OPT_ALTVIEW		0x00000004L
232 
233 
234 /*
235  * display template structure
236  */
237 struct ldap_disptmpl {
238     char			*dt_name;
239     char			*dt_pluralname;
240     char			*dt_iconname;
241     unsigned long		dt_options;
242     char			*dt_authattrname;
243     char			*dt_defrdnattrname;
244     char			*dt_defaddlocation;
245     struct ldap_oclist		*dt_oclist;
246     struct ldap_adddeflist	*dt_adddeflist;
247     struct ldap_tmplitem	*dt_items;
248     void			*dt_appdata;
249     struct ldap_disptmpl	*dt_next;
250 };
251 
252 #define NULLDISPTMPL	((struct ldap_disptmpl *)0)
253 
254 #define LDAP_SET_DISPTMPL_APPDATA( dt, datap )	\
255 	(dt)->dt_appdata = (void *)(datap)
256 
257 #define LDAP_GET_DISPTMPL_APPDATA( dt, type )	\
258 	(type)((dt)->dt_appdata)
259 
260 #define LDAP_IS_DISPTMPL_OPTION_SET( dt, option )	\
261 	(((dt)->dt_options & option ) != 0 )
262 
263 #define LDAP_TMPL_ERR_VERSION	1
264 #define LDAP_TMPL_ERR_MEM	2
265 #define LDAP_TMPL_ERR_SYNTAX	3
266 #define LDAP_TMPL_ERR_FILE	4
267 
268 /*
269  * buffer size needed for entry2text and vals2text
270  */
271 #define LDAP_DTMPL_BUFSIZ	8192
272 
273 typedef int (*writeptype)( void *writeparm, char *p, int len );
274 
275 LDAP_API(int)
276 LDAP_CALL
277 ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp );
278 
279 LDAP_API(int)
280 LDAP_CALL
281 ldap_init_templates_buf( char *buf, long buflen,
282 	struct ldap_disptmpl **tmpllistp );
283 
284 LDAP_API(void)
285 LDAP_CALL
286 ldap_free_templates( struct ldap_disptmpl *tmpllist );
287 
288 LDAP_API(struct ldap_disptmpl *)
289 LDAP_CALL
290 ldap_first_disptmpl( struct ldap_disptmpl *tmpllist );
291 
292 LDAP_API(struct ldap_disptmpl *)
293 LDAP_CALL
294 ldap_next_disptmpl( struct ldap_disptmpl *tmpllist,
295 	struct ldap_disptmpl *tmpl );
296 
297 LDAP_API(struct ldap_disptmpl *)
298 LDAP_CALL
299 ldap_name2template( char *name, struct ldap_disptmpl *tmpllist );
300 
301 LDAP_API(struct ldap_disptmpl *)
302 LDAP_CALL
303 ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist );
304 
305 LDAP_API(char **)
306 LDAP_CALL
307 ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, int exclude,
308 	 unsigned long syntaxmask );
309 
310 LDAP_API(struct ldap_tmplitem *)
311 LDAP_CALL
312 ldap_first_tmplrow( struct ldap_disptmpl *tmpl );
313 
314 LDAP_API(struct ldap_tmplitem *)
315 LDAP_CALL
316 ldap_next_tmplrow( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row );
317 
318 LDAP_API(struct ldap_tmplitem *)
319 LDAP_CALL
320 ldap_first_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row );
321 
322 LDAP_API(struct ldap_tmplitem *)
323 LDAP_CALL
324 ldap_next_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row,
325 	struct ldap_tmplitem *col );
326 
327 LDAP_API(int)
328 LDAP_CALL
329 ldap_entry2text( LDAP *ld, char *buf, LDAPMessage *entry,
330 	struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
331 	writeptype writeproc, void *writeparm, char *eol, int rdncount,
332 	unsigned long opts );
333 
334 LDAP_API(int)
335 LDAP_CALL
336 ldap_vals2text( LDAP *ld, char *buf, char **vals, char *label, int labelwidth,
337 	unsigned long syntaxid, writeptype writeproc, void *writeparm,
338 	char *eol, int rdncount );
339 
340 LDAP_API(int)
341 LDAP_CALL
342 ldap_entry2text_search( LDAP *ld, char *dn, char *base, LDAPMessage *entry,
343 	struct ldap_disptmpl *tmpllist, char **defattrs, char ***defvals,
344 	writeptype writeproc, void *writeparm, char *eol, int rdncount,
345 	unsigned long opts );
346 
347 LDAP_API(int)
348 LDAP_CALL
349 ldap_entry2html( LDAP *ld, char *buf, LDAPMessage *entry,
350 	struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
351 	writeptype writeproc, void *writeparm, char *eol, int rdncount,
352 	unsigned long opts, char *urlprefix, char *base );
353 
354 LDAP_API(int)
355 LDAP_CALL
356 ldap_vals2html( LDAP *ld, char *buf, char **vals, char *label, int labelwidth,
357 	unsigned long syntaxid, writeptype writeproc, void *writeparm,
358 	char *eol, int rdncount, char *urlprefix );
359 
360 LDAP_API(int)
361 LDAP_CALL
362 ldap_entry2html_search( LDAP *ld, char *dn, char *base, LDAPMessage *entry,
363 	struct ldap_disptmpl *tmpllist, char **defattrs, char ***defvals,
364 	writeptype writeproc, void *writeparm, char *eol, int rdncount,
365 	unsigned long opts, char *urlprefix );
366 
367 #endif /* ifndef _SOLARIS_SDK */
368 
369 LDAP_API(char *)
370 LDAP_CALL
371 ldap_tmplerr2string( int err );
372 
373 #ifdef __cplusplus
374 }
375 #endif
376 #endif /* _DISPTMPL_H */
377