]> git.sur5r.net Git - openldap/blob - include/rewrite.h
Extended ber_mem functions, add context argument.
[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       0x0004
76
77 /*
78  * Rewrite info
79  */
80 struct rewrite_info;
81
82 struct berval; /* avoid include */
83
84 LDAP_BEGIN_DECL
85
86 /*
87  * Inits the info
88  */
89 LDAP_REWRITE_F (struct rewrite_info *)
90 rewrite_info_init(
91                 int mode
92 );
93
94 /*
95  * Cleans up the info structure
96  */
97 LDAP_REWRITE_F (int)
98 rewrite_info_delete(
99                 struct rewrite_info *info
100 );
101
102
103 /*
104  * Parses a config line and takes actions to fit content in rewrite structure;
105  * lines handled are of the form:
106  *
107  *      rewriteEngine           {on|off}
108  *      rewriteMaxPasses        numPasses
109  *      rewriteContext          contextName [alias aliasedRewriteContex]
110  *      rewriteRule             pattern substPattern [ruleFlags]
111  *      rewriteMap              mapType mapName [mapArgs]
112  *      rewriteParam            paramName paramValue
113  */
114 LDAP_REWRITE_F (int)
115 rewrite_parse(
116                 struct rewrite_info *info,
117                 const char *fname,
118                 int lineno,
119                 int argc,
120                 char **argv
121 );
122
123 /*
124  * process a config file that was already opened. Uses rewrite_parse.
125  */
126 LDAP_REWRITE_F (int)
127 rewrite_read(
128                 FILE *fin,
129                 struct rewrite_info *info
130 );
131
132 /*
133  * Rewrites a string according to context.
134  * If the engine is off, OK is returned, but the return string will be NULL.
135  * In case of 'unwilling to perform', UNWILLING is returned, and the
136  * return string will also be null. The same in case of error.
137  * Otherwise, OK is returned, and result will hold a newly allocated string
138  * with the rewriting.
139  *
140  * What to do in case of non-existing rewrite context is still an issue.
141  * Four possibilities:
142  *      - error,
143  *      - ok with NULL result,
144  *      - ok with copy of string as result,
145  *      - use the default rewrite context.
146  */
147 LDAP_REWRITE_F (int)
148 rewrite(
149                 struct rewrite_info *info,
150                 const char *rewriteContext,
151                 const char *string,
152                 char **result
153 );
154
155 /*
156  * Same as above; the cookie relates the rewrite to a session
157  */
158 LDAP_REWRITE_F (int)
159 rewrite_session(
160                 struct rewrite_info *info,
161                 const char *rewriteContext,
162                 const char *string,
163                 const void *cookie,
164                 char **result
165 );
166
167 /*
168  * Inits a session
169  */
170 LDAP_REWRITE_F (struct rewrite_session *)
171 rewrite_session_init(
172                 struct rewrite_info *info,
173                 const void *cookie
174 );
175
176 /*
177  * Defines and inits a variable with session scope
178  */
179 LDAP_REWRITE_F (int)
180 rewrite_session_var_set(
181                 struct rewrite_info *info,
182                 const void *cookie,
183                 const char *name,
184                 const char *value
185 );
186
187 /*
188  * Deletes a session
189  */
190 LDAP_REWRITE_F (int)
191 rewrite_session_delete(
192                 struct rewrite_info *info,
193                 const void *cookie
194 );
195
196
197 /*
198  * Params
199  */
200
201 /*
202  * Defines and inits a variable with global scope
203  */
204 LDAP_REWRITE_F (int)
205 rewrite_param_set(
206                 struct rewrite_info *info,
207                 const char *name,
208                 const char *value
209 );
210
211 /*
212  * Gets a var with global scope
213  */
214 LDAP_REWRITE_F (int)
215 rewrite_param_get(
216                 struct rewrite_info *info,
217                 const char *name,
218                 struct berval *value
219 );
220
221 /*
222  * Destroys the parameter tree
223  */
224 LDAP_REWRITE_F (int)
225 rewrite_param_destroy(
226                 struct rewrite_info *info
227 );
228
229 LDAP_END_DECL
230
231 #endif /* REWRITE_H */