3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2017 The OpenLDAP Foundation.
6 * Portions Copyright 2000-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by Pierangelo Masarati for
19 * inclusion in OpenLDAP Software.
26 * Default rewrite context
28 #define REWRITE_DEFAULT_CONTEXT "default"
31 * Rewrite engine states
33 #define REWRITE_OFF 0x0000
34 #define REWRITE_ON 0x0001
35 #define REWRITE_DEFAULT REWRITE_OFF
38 * Rewrite internal status returns
40 #define REWRITE_SUCCESS LDAP_SUCCESS
41 #define REWRITE_ERR LDAP_OTHER
44 * Rewrite modes (input values for rewrite_info_init); determine the
45 * behavior in case a null or non existent context is required:
47 * REWRITE_MODE_ERR error
48 * REWRITE_MODE_OK no error but no rewrite
49 * REWRITE_MODE_COPY_INPUT a copy of the input is returned
50 * REWRITE_MODE_USE_DEFAULT the default context is used.
52 #define REWRITE_MODE_ERR 0x0010
53 #define REWRITE_MODE_OK 0x0011
54 #define REWRITE_MODE_COPY_INPUT 0x0012
55 #define REWRITE_MODE_USE_DEFAULT 0x0013
58 * Rewrite status returns
60 * REWRITE_REGEXEC_OK success (result may be empty in case
62 * REWRITE_REGEXEC_ERR error (internal error,
63 * misconfiguration, map not working ...)
64 * REWRITE_REGEXEC_STOP internal use; never returned
65 * REWRITE_REGEXEC_UNWILLING the server should issue an 'unwilling
68 #define REWRITE_REGEXEC_OK (0)
69 #define REWRITE_REGEXEC_ERR (-1)
70 #define REWRITE_REGEXEC_STOP (-2)
71 #define REWRITE_REGEXEC_UNWILLING (-3)
72 #define REWRITE_REGEXEC_USER (1) /* and above: LDAP errors */
75 * Rewrite variable flags
76 * REWRITE_VAR_INSERT insert mode (default) when adding
77 * a variable; if not set during value
78 * update, the variable is not inserted
80 * REWRITE_VAR_UPDATE update mode (default) when updating
81 * a variable; if not set during insert,
82 * the value is not updated if the
83 * variable already exists
84 * REWRITE_VAR_COPY_NAME copy the variable name; if not set,
85 * the name is not copied; be sure the
86 * referenced string is available for
87 * the entire life scope of the variable.
88 * REWRITE_VAR_COPY_VALUE copy the variable value; if not set,
89 * the value is not copied; be sure the
90 * referenced string is available for
91 * the entire life scope of the variable.
93 #define REWRITE_VAR_NONE 0x0000
94 #define REWRITE_VAR_INSERT 0x0001
95 #define REWRITE_VAR_UPDATE 0x0002
96 #define REWRITE_VAR_COPY_NAME 0x0004
97 #define REWRITE_VAR_COPY_VALUE 0x0008
104 struct berval; /* avoid include */
111 LDAP_REWRITE_F (struct rewrite_info *)
117 * Cleans up the info structure
121 struct rewrite_info **info
126 * Parses a config line and takes actions to fit content in rewrite structure;
127 * lines handled are of the form:
129 * rewriteEngine {on|off}
130 * rewriteMaxPasses numPasses
131 * rewriteContext contextName [alias aliasedRewriteContex]
132 * rewriteRule pattern substPattern [ruleFlags]
133 * rewriteMap mapType mapName [mapArgs]
134 * rewriteParam paramName paramValue
138 struct rewrite_info *info,
146 * process a config file that was already opened. Uses rewrite_parse.
151 struct rewrite_info *info
155 * Rewrites a string according to context.
156 * If the engine is off, OK is returned, but the return string will be NULL.
157 * In case of 'unwilling to perform', UNWILLING is returned, and the
158 * return string will also be null. The same in case of error.
159 * Otherwise, OK is returned, and result will hold a newly allocated string
160 * with the rewriting.
162 * What to do in case of non-existing rewrite context is still an issue.
163 * Four possibilities:
165 * - ok with NULL result,
166 * - ok with copy of string as result,
167 * - use the default rewrite context.
171 struct rewrite_info *info,
172 const char *rewriteContext,
178 * Same as above; the cookie relates the rewrite to a session
182 struct rewrite_info *info,
183 const char *rewriteContext,
192 LDAP_REWRITE_F (struct rewrite_session *)
193 rewrite_session_init(
194 struct rewrite_info *info,
199 * Defines and inits a variable with session scope
202 rewrite_session_var_set_f(
203 struct rewrite_info *info,
210 #define rewrite_session_var_set(info, cookie, name, value) \
211 rewrite_session_var_set_f((info), (cookie), (name), (value), \
212 REWRITE_VAR_INSERT|REWRITE_VAR_UPDATE|REWRITE_VAR_COPY_NAME|REWRITE_VAR_COPY_VALUE)
218 rewrite_session_delete(
219 struct rewrite_info *info,
229 * Defines and inits a variable with global scope
233 struct rewrite_info *info,
239 * Gets a var with global scope
243 struct rewrite_info *info,
249 * Destroys the parameter tree
252 rewrite_param_destroy(
253 struct rewrite_info *info
257 * Mapping implementations
260 struct rewrite_mapper;
262 typedef void * (rewrite_mapper_config)(
268 typedef int (rewrite_mapper_apply)(
271 struct berval *retval );
273 typedef int (rewrite_mapper_destroy)(
276 typedef struct rewrite_mapper {
278 rewrite_mapper_config *rm_config;
279 rewrite_mapper_apply *rm_apply;
280 rewrite_mapper_destroy *rm_destroy;
283 /* For dynamic loading and unloading of mappers */
285 rewrite_mapper_register(
286 const rewrite_mapper *map );
289 rewrite_mapper_unregister(
290 const rewrite_mapper *map );
292 LDAP_REWRITE_F (const rewrite_mapper *)
298 #endif /* REWRITE_H */