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