]> git.sur5r.net Git - openldap/blob - include/rewrite.h
c6a64af744f232016e2ab6ed415bab3b3472571c
[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 /*
29  * Default rewrite context
30  */
31 #define REWRITE_DEFAULT_CONTEXT         "default"
32
33 /*
34  * Rewrite engine states
35  */
36 #define REWRITE_OFF                     0x0000
37 #define REWRITE_ON                      0x0001
38 #define REWRITE_DEFAULT                 REWRITE_OFF
39
40 /*
41  * Rewrite internal status returns
42  */
43 #define REWRITE_SUCCESS                 LDAP_SUCCESS
44 #define REWRITE_ERR                     LDAP_OPERATIONS_ERROR
45 #define REWRITE_NO_SUCH_OBJECT          LDAP_NO_SUCH_OBJECT
46
47 /*
48  * Rewrite modes (input values for rewrite_info_init); determine the
49  * behavior in case a null or non existent context is required:
50  *
51  *      REWRITE_MODE_ERR                error
52  *      REWRITE_MODE_OK                 no error but no rewrite
53  *      REWRITE_MODE_COPY_INPUT         a copy of the input is returned
54  *      REWRITE_MODE_USE_DEFAULT        the default context is used.
55  */
56 #define REWRITE_MODE_ERR                0x0010
57 #define REWRITE_MODE_OK                 0x0011
58 #define REWRITE_MODE_COPY_INPUT         0x0012
59 #define REWRITE_MODE_USE_DEFAULT        0x0013
60
61 /*
62  * Rewrite status returns
63  *
64  *      REWRITE_REGEXEC_OK              success (result may be empty in case
65  *                                      of no match)
66  *      REWRITE_REGEXEC_ERR             error (internal error,
67  *                                      misconfiguration, map not working ...)
68  *      REWRITE_REGEXEC_STOP            internal use; never returned
69  *      REWRITE_REGEXEC_UNWILLING       the server should issue an 'unwilling
70  *                                      to perform' error
71  */
72 #define REWRITE_REGEXEC_OK              0x0000
73 #define REWRITE_REGEXEC_ERR             0x0001
74 #define REWRITE_REGEXEC_STOP            0x0002
75 #define REWRITE_REGEXEC_UNWILLING       0x0003
76 #define REWRITE_REGEXEC_USER            0x0004 /* and above ... */
77
78 /*
79  * Rewrite variable flags
80  *      REWRITE_VAR_INSERT              insert mode (default) when adding
81  *                                      a variable; if not set during value
82  *                                      update, the variable is not inserted
83  *                                      if not present
84  *      REWRITE_VAR_UPDATE              update mode (default) when updating
85  *                                      a variable; if not set during insert,
86  *                                      the value is not updated if the
87  *                                      variable already exists
88  *      REWRITE_VAR_COPY_NAME           copy the variable name; if not set,
89  *                                      the name is not copied; be sure the
90  *                                      referenced string is available for
91  *                                      the entire life scope of the variable.
92  *      REWRITE_VAR_COPY_VALUE          copy the variable value; if not set,
93  *                                      the value is not copied; be sure the
94  *                                      referenced string is available for
95  *                                      the entire life scope of the variable.
96  */
97 #define REWRITE_VAR_NONE                0x0000
98 #define REWRITE_VAR_INSERT              0x0001
99 #define REWRITE_VAR_UPDATE              0x0002
100 #define REWRITE_VAR_COPY_NAME           0x0004
101 #define REWRITE_VAR_COPY_VALUE          0x0008
102
103 /*
104  * Rewrite info
105  */
106 struct rewrite_info;
107
108 struct berval; /* avoid include */
109
110 LDAP_BEGIN_DECL
111
112 /*
113  * Inits the info
114  */
115 LDAP_REWRITE_F (struct rewrite_info *)
116 rewrite_info_init(
117                 int mode
118 );
119
120 /*
121  * Cleans up the info structure
122  */
123 LDAP_REWRITE_F (int)
124 rewrite_info_delete(
125                 struct rewrite_info **info
126 );
127
128
129 /*
130  * Parses a config line and takes actions to fit content in rewrite structure;
131  * lines handled are of the form:
132  *
133  *      rewriteEngine           {on|off}
134  *      rewriteMaxPasses        numPasses
135  *      rewriteContext          contextName [alias aliasedRewriteContex]
136  *      rewriteRule             pattern substPattern [ruleFlags]
137  *      rewriteMap              mapType mapName [mapArgs]
138  *      rewriteParam            paramName paramValue
139  */
140 LDAP_REWRITE_F (int)
141 rewrite_parse(
142                 struct rewrite_info *info,
143                 const char *fname,
144                 int lineno,
145                 int argc,
146                 char **argv
147 );
148
149 /*
150  * process a config file that was already opened. Uses rewrite_parse.
151  */
152 LDAP_REWRITE_F (int)
153 rewrite_read(
154                 FILE *fin,
155                 struct rewrite_info *info
156 );
157
158 /*
159  * Rewrites a string according to context.
160  * If the engine is off, OK is returned, but the return string will be NULL.
161  * In case of 'unwilling to perform', UNWILLING is returned, and the
162  * return string will also be null. The same in case of error.
163  * Otherwise, OK is returned, and result will hold a newly allocated string
164  * with the rewriting.
165  *
166  * What to do in case of non-existing rewrite context is still an issue.
167  * Four possibilities:
168  *      - error,
169  *      - ok with NULL result,
170  *      - ok with copy of string as result,
171  *      - use the default rewrite context.
172  */
173 LDAP_REWRITE_F (int)
174 rewrite(
175                 struct rewrite_info *info,
176                 const char *rewriteContext,
177                 const char *string,
178                 char **result
179 );
180
181 /*
182  * Same as above; the cookie relates the rewrite to a session
183  */
184 LDAP_REWRITE_F (int)
185 rewrite_session(
186                 struct rewrite_info *info,
187                 const char *rewriteContext,
188                 const char *string,
189                 const void *cookie,
190                 char **result
191 );
192
193 /*
194  * Inits a session
195  */
196 LDAP_REWRITE_F (struct rewrite_session *)
197 rewrite_session_init(
198                 struct rewrite_info *info,
199                 const void *cookie
200 );
201
202 /*
203  * Defines and inits a variable with session scope
204  */
205 LDAP_REWRITE_F (int)
206 rewrite_session_var_set_f(
207                 struct rewrite_info *info,
208                 const void *cookie,
209                 const char *name,
210                 const char *value,
211                 int flags
212 );
213
214 #define rewrite_session_var_set(info, cookie, name, value) \
215         rewrite_session_var_set_f((info), (cookie), (name), (value), \
216                         REWRITE_VAR_INSERT|REWRITE_VAR_UPDATE|REWRITE_VAR_COPY_NAME|REWRITE_VAR_COPY_VALUE)
217
218 /*
219  * Deletes a session
220  */
221 LDAP_REWRITE_F (int)
222 rewrite_session_delete(
223                 struct rewrite_info *info,
224                 const void *cookie
225 );
226
227
228 /*
229  * Params
230  */
231
232 /*
233  * Defines and inits a variable with global scope
234  */
235 LDAP_REWRITE_F (int)
236 rewrite_param_set(
237                 struct rewrite_info *info,
238                 const char *name,
239                 const char *value
240 );
241
242 /*
243  * Gets a var with global scope
244  */
245 LDAP_REWRITE_F (int)
246 rewrite_param_get(
247                 struct rewrite_info *info,
248                 const char *name,
249                 struct berval *value
250 );
251
252 /*
253  * Destroys the parameter tree
254  */
255 LDAP_REWRITE_F (int)
256 rewrite_param_destroy(
257                 struct rewrite_info *info
258 );
259
260 LDAP_END_DECL
261
262 #endif /* REWRITE_H */