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