]> git.sur5r.net Git - openldap/blob - include/rewrite.h
Fix filter printing
[openldap] / include / rewrite.h
1 /******************************************************************************
2  *
3  * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
4  * All rights reserved.
5  *
6  * Permission is granted to anyone to use this software for any purpose
7  * on any computer system, and to alter it and redistribute it, subject
8  * to the following restrictions:
9  *
10  * 1. The author is not responsible for the consequences of use of this
11  * software, no matter how awful, even if they arise from flaws in it.
12  *
13  * 2. The origin of this software must not be misrepresented, either by
14  * explicit claim or by omission.  Since few users ever read sources,
15  * credits should appear in the documentation.
16  *
17  * 3. Altered versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.  Since few users
19  * ever read sources, credits should appear in the documentation.
20  * 
21  * 4. This notice may not be removed or altered.
22  *
23  ******************************************************************************/
24
25 #ifndef REWRITE_H
26 #define REWRITE_H
27
28 LDAP_BEGIN_DECL
29
30 /*
31  * Default rewrite context
32  */
33 #define REWRITE_DEFAULT_CONTEXT         "default"
34
35 /*
36  * Rewrite engine states
37  */
38 #define REWRITE_OFF                     0x0000
39 #define REWRITE_ON                      0x0001
40 #define REWRITE_DEFAULT                 REWRITE_OFF
41
42 /*
43  * Rewrite internal status returns
44  */
45 #define REWRITE_SUCCESS                 LDAP_SUCCESS
46 #define REWRITE_ERR                     LDAP_OPERATIONS_ERROR
47 #define REWRITE_NO_SUCH_OBJECT          LDAP_NO_SUCH_OBJECT
48
49 /*
50  * Rewrite modes (input values for rewrite_info_init); determine the
51  * behavior in case a null or non existent context is required:
52  * 
53  *      REWRITE_MODE_ERR                error
54  *      REWRITE_MODE_OK                 no error but no rewrite
55  *      REWRITE_MODE_COPY_INPUT         a copy of the input is returned
56  *      REWRITE_MODE_USE_DEFAULT        the default context is used.
57  */
58 #define REWRITE_MODE_ERR                0x0010
59 #define REWRITE_MODE_OK                 0x0011
60 #define REWRITE_MODE_COPY_INPUT         0x0012
61 #define REWRITE_MODE_USE_DEFAULT        0x0013
62
63 /*
64  * Rewrite status returns
65  * 
66  *      REWRITE_REGEXEC_OK              success (result may be empty in case
67  *                                      of no match)
68  *      REWRITE_REGEXEC_ERR             error (internal error,
69  *                                      misconfiguration, map not working ...)
70  *      REWRITE_REGEXEC_STOP            internal use; never returned
71  *      REWRITE_REGEXEC_UNWILLING       the server should issue an 'unwilling
72  *                                      to perform' error
73  */
74 #define REWRITE_REGEXEC_OK              0x0000
75 #define REWRITE_REGEXEC_ERR             0x0001
76 #define REWRITE_REGEXEC_STOP            0x0002
77 #define REWRITE_REGEXEC_UNWILLING       0x0004
78
79 /*
80  * Rewrite info
81  */
82 struct rewrite_info;
83 struct berval;
84
85 /*
86  * Inits the info
87  */
88 extern struct rewrite_info *
89 rewrite_info_init(
90                 int mode
91 );
92
93 /*
94  * Cleans up the info structure
95  */
96 extern int
97 rewrite_info_delete(
98                 struct rewrite_info *info
99 );
100
101
102 /*
103  * Parses a config line and takes actions to fit content in rewrite structure;
104  * lines handled are of the form:
105  *
106  *      rewriteEngine           {on|off}
107  *      rewriteMaxPasses        numPasses
108  *      rewriteContext          contextName [alias aliasedRewriteContex]
109  *      rewriteRule             pattern substPattern [ruleFlags]
110  *      rewriteMap              mapType mapName [mapArgs]
111  *      rewriteParam            paramName paramValue
112  */
113 extern int
114 rewrite_parse(
115                 struct rewrite_info *info,
116                 const char *fname,
117                 int lineno,
118                 int argc,
119                 char **argv
120 );
121
122 /*
123  * Rewrites a string according to context.
124  * If the engine is off, OK is returned, but the return string will be NULL.
125  * In case of 'unwilling to perform', UNWILLING is returned, and the
126  * return string will also be null. The same in case of error.
127  * Otherwise, OK is returned, and result will hold a newly allocated string
128  * with the rewriting.
129  *
130  * What to do in case of non-existing rewrite context is still an issue.
131  * Four possibilities:
132  *      - error, 
133  *      - ok with NULL result, 
134  *      - ok with copy of string as result,
135  *      - use the default rewrite context.
136  */
137 extern int
138 rewrite(
139                 struct rewrite_info *info,
140                 const char *rewriteContext,
141                 const char *string,
142                 char **result
143 );
144
145 /*
146  * Same as above; the cookie relates the rewrite to a session
147  */
148 extern int
149 rewrite_session(
150                 struct rewrite_info *info,
151                 const char *rewriteContext,
152                 const char *string,
153                 const void *cookie,
154                 char **result
155 );
156
157 /*
158  * Inits a session
159  */
160 extern struct rewrite_session *
161 rewrite_session_init(
162                 struct rewrite_info *info,
163                 const void *cookie
164 );
165
166 /*
167  * Defines and inits a variable with session scope
168  */
169 extern int
170 rewrite_session_var_set(
171                 struct rewrite_info *info,
172                 const void *cookie,
173                 const char *name,
174                 const char *value
175 );
176
177 /*
178  * Deletes a session
179  */
180 extern int
181 rewrite_session_delete(
182                 struct rewrite_info *info,
183                 const void *cookie
184 );
185
186
187 /*
188  * Params
189  */
190
191 /*
192  * Defines and inits a variable with global scope
193  */
194 extern int
195 rewrite_param_set(
196                 struct rewrite_info *info,
197                 const char *name,
198                 const char *value
199 );
200
201 /*
202  * Gets a var with global scope
203  */
204 extern int
205 rewrite_param_get(
206                 struct rewrite_info *info,
207                 const char *name,
208                 struct berval *value
209 );
210
211 /* 
212  * Destroys the parameter tree
213  */
214 extern int
215 rewrite_param_destroy(
216                 struct rewrite_info *info
217 );
218
219 LDAP_END_DECL
220
221 #endif /* REWRITE_H */
222