]> git.sur5r.net Git - openldap/blob - contrib/slapd-modules/comp_match/component.h
1) <all> type component reference support
[openldap] / contrib / slapd-modules / comp_match / component.h
1 /* Copyright 2004 IBM Corporation
2  * All rights reserved.
3  * Redisribution and use in source and binary forms, with or without
4  * modification, are permitted only as  authorizd by the OpenLADP
5  * Public License.
6  */
7 /* ACKNOWLEDGEMENTS
8  * This work originally developed by Sang Seok Lim
9  * 2004/06/18   03:20:00        slim@OpenLDAP.org
10  */
11
12 #ifndef _H_COMPONENT_MODULE
13 #define _H_COMPONENT_MODULE
14
15 #include "portable.h"
16 #include <ac/string.h>
17 #include <ac/socket.h>
18 #include <ldap_pvt.h>
19 #include "lutil.h"
20 #include <ldap.h>
21 #include <slap.h>
22
23 #include <asn-incl.h>
24 #include "asn.h"
25 #include <asn-gser.h>
26 #include <string.h>
27
28 #define MAX_IDENTIFIER_LEN      128
29 #define COMPONENTNOT_NULL(ptr)  ((ptr) != NULL)
30
31 /*
32  * BIT STRING
33  */
34 typedef struct ComponentBits {
35         void* syntax;
36         ComponentDesc* comp_desc;
37         struct berval identifier;
38         char id_buf[MAX_IDENTIFIER_LEN];
39         AsnBits value;
40 } ComponentBits;
41
42 #define GASNBITS_PRESENT(abits) ((abits)->value.bits != NULL)
43 #define COMPONENTBITS_PRESENT(abits) ((abits)->value.bits != NULL)
44 int GDecComponentBits (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
45 int BDecComponentBits (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
46 int MatchingComponentBits (char* oid, ComponentSyntaxInfo *bits1 , ComponentSyntaxInfo* bits2);
47 #define ExtractingComponentBits( mem_op, cr,data ) NULL
48
49 /*
50  * BMP String
51  */
52 typedef struct ComponentBMPString {
53         void* syntax;
54         ComponentDesc* comp_desc;
55         struct berval identifier;
56         char id_buf[MAX_IDENTIFIER_LEN];
57         BMPString value;
58 } ComponentBMPString;
59
60 int GDecComponentBMPString (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
61 int BDecComponentBMPString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
62 #define MatchingComponentBMPString MatchingComponentOcts
63 #define ExtractingComponentBMPString( mem_op, cr, data ) NULL
64 #define FreeComponentBMPString FreeComponentOcts
65
66 /*
67  * BOOLEAN
68  */
69 typedef struct ComponentBool {
70         void* syntax;
71         ComponentDesc* comp_desc;
72         struct berval identifier;
73         char id_buf[MAX_IDENTIFIER_LEN];
74         AsnBool value;
75 } ComponentBool;
76
77 int GDecComponentBool ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
78 int BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
79 int MatchingComponentBool (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
80 #define ExtractingComponentBool( mem_op, cr, data ) NULL
81 #define FreeComponentBool(v) NULL
82
83 /*
84  * ENUMERTED
85  */
86 typedef struct ComponentEnum {
87         void* syntax;
88         ComponentDesc* comp_desc;
89         struct berval identifier;
90         char id_buf[MAX_IDENTIFIER_LEN];
91         AsnEnum value;
92         struct berval value_identifier;/*Why this value is defined here?*/
93 } ComponentEnum;
94
95 int GDecComponentEnum ( void* mem_op, GenBuf *a, void *result, AsnLen *bytesDecoded,int mode);
96 int BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
97 int MatchingComponentEnum (char *oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo * b);
98 #define ExtractingComponentEnum( mem_op, cr, data ) NULL
99 #define FreeComponentEnum FreeComponentInt
100
101 /*
102  * IA5 String
103  */
104 typedef struct ComponentIA5String {
105         void* syntax;
106         ComponentDesc* comp_desc;
107         struct berval identifier;
108         char id_buf[MAX_IDENTIFIER_LEN];
109         IA5String value;
110 } ComponentIA5String;
111
112 #define GDecComponentIA5String GDecComponentUTF8String
113 int BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
114 #define MatchingComponentIA5String MatchingComponentOcts
115 #define ExtractingComponentIA5String(mem_op, cr,data)   NULL
116 #define FreeComponentIA5String FreeComponentOcts
117
118
119 /*
120  * INTEGER
121  */
122 typedef struct ComponentInt {
123         void* syntax;
124         ComponentDesc* comp_desc;
125         struct berval identifier;
126         char id_buf[MAX_IDENTIFIER_LEN];
127         int value;
128 } ComponentInt;
129
130 #define GNOT_NULL(ptr) ((ptr) != NULL)
131
132 int GDecComponentInt ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode );
133 int BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
134 int MatchingComponentInt (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
135 #define ExtractingComponentInt(mem_op, cr,data) NULL
136 #define FreeComponentInt(v) NULL
137
138 /*
139  * LIST Data Structure for C_LIST
140  */
141 typedef struct ComponentList {
142         void* syntax;
143         ComponentDesc* comp_desc;
144         struct berval identifier;
145         char id_buf[MAX_IDENTIFIER_LEN];
146         AsnList comp_list;
147 } ComponentList;
148
149 /*
150  * NULL
151  */
152 typedef struct ComponentNull {
153         void* syntax;
154         ComponentDesc* comp_desc;
155         struct berval identifier;
156         char id_buf[MAX_IDENTIFIER_LEN];
157         AsnNull value;
158 } ComponentNull;
159
160 int GDecComponentNull ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
161 int BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
162 int BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
163 int MatchingComponentNull (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
164 #define ExtractingComponentNull(mem_op, cr, data)       NULL
165 #define FreeComponentNull NULL
166
167 /*
168  * Numeric String
169  */
170 typedef struct ComponentNumericString {
171         void* syntax;
172         ComponentDesc* comp_desc;
173         struct berval identifier;
174         char id_buf[MAX_IDENTIFIER_LEN];
175         NumericString value;
176 } ComponentNumericString;
177
178 #define GDecComponentNumericString GDecComponentUTF8String
179 int BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
180 #define MatchingComponentNumericString MatchingComponentOcts
181 #define ExtractingComponentNumericString(mem_op, cr,data)       NULL
182 #define FreeComponentNumericString FreeComponentOcts
183
184 /*
185  * OCTETS STRING
186  */
187 typedef struct ComponentOcts {
188         void* syntax;
189         ComponentDesc* comp_desc;
190         struct berval identifier;
191         char id_buf[MAX_IDENTIFIER_LEN];
192         AsnOcts value;
193 } ComponentOcts;
194
195 #define GASNOCTS_PRESENT(aocts) ((aocts)->value.octs != NULL)
196
197 int GDecComponentOcts (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
198 int BDecComponentOcts (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
199 int MatchingComponentOcts (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
200 #define ExtractingComponentOcts(mem_op,cr,data) NULL
201 void FreeComponentOcts( ComponentOcts* octs );
202
203 /*
204  * OID (Object Identifier)
205  */
206 typedef struct ComponentOid {
207         void* syntax;
208         ComponentDesc* comp_desc;
209         struct berval identifier;
210         char id_buf[MAX_IDENTIFIER_LEN];
211         AsnOid value;
212 } ComponentOid;
213
214 #define GASNOID_PRESENT(aoid) ASNOCTS_PRESENT(aoid)
215
216 int GDecComponentOid (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
217 int BDecComponentOid (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
218 int MatchingComponentOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
219 #define ExtractingComponentOid(mem_op, cr, data)        NULL
220 #define FreeComponentOid FreeComponentOcts
221
222 /*
223  * Printable String
224  */
225 typedef struct ComponentPrintableString{
226         void* syntax;
227         ComponentDesc* comp_desc;
228         struct berval identifier;
229         char id_buf[MAX_IDENTIFIER_LEN];
230         PrintableString value;
231 } ComponentPrintableString;
232
233 #define GDecComponentPrintableString GDecComponentUTF8String
234 int BDecComponentPrintableString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
235 int BDecComponentPrintableStringTag (void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
236 #define MatchingComponentPrintableString MatchingComponentOcts
237 #define ExtractingComponentPrintableString(mem_op, cr, data)    NULL
238 #define FreeComponentPrintableString FreeComponentOcts
239
240 /*
241  * REAL
242  */
243 typedef struct ComponentReal{
244         void* syntax;
245         ComponentDesc* comp_desc;
246         struct berval identifier;
247         char id_buf[MAX_IDENTIFIER_LEN];
248         AsnReal value;
249 } ComponentReal;
250
251 int GDecComponentReal (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
252 int BDecComponentReal (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
253 int MatchingComponentReal (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
254 #define ExtractingComponentReal( mem_op, cr, data )     NULL
255 #define FreeComponentReal(v) NULL
256
257 /*
258  * Relative OID
259  */
260
261 typedef struct ComponentRelativeOid {
262         void* syntax;
263         ComponentDesc* comp_desc;
264         struct berval identifier;
265         char id_buf[MAX_IDENTIFIER_LEN];
266         AsnRelativeOid value;
267 } ComponentRelativeOid;
268
269 int GDecComponentRelativeOid ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
270 int BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
271 int MatchingComponentRelativeOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
272 #define ExtractingComponentRelativeOid( mem_op, cr, data ) NULL
273 #define FreeComponentRelativeOid FreeComponentOid
274
275 /*
276  * Teletex String
277  */
278 typedef struct ComponentTeletexString {
279         void* syntax;
280         ComponentDesc* comp_desc;
281         struct berval identifier;
282         char id_buf[MAX_IDENTIFIER_LEN];
283         TeletexString value;
284 } ComponentTeletexString;
285
286 int GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode );
287 #define BDecComponentTeletexString BDecComponentOcts
288 #define MatchingComponentTeletexString MatchingComponentOcts
289 #define ExtractingComponentTeletexString(mem_op,cr,data)
290 #define FreeComponentTeletexString FreeComponentOcts
291
292
293 /*
294  * Universal String
295  */
296 typedef struct ComponentUniversalString{
297         void* syntax;
298         ComponentDesc* comp_desc;
299         struct berval identifier;
300         char id_buf[MAX_IDENTIFIER_LEN];
301         UniversalString value;
302 } ComponentUniversalString;
303
304 int GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
305 int BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
306 #define MatchingComponentUniversalString MatchingComponentOcts
307 #define ExtractingComponentUniversalString(mem_op,cr,data)
308 #define FreeComponentUniversalString FreeComponentOcts
309
310 /*
311  * UTF8 String
312  */
313 typedef struct ComponentUTF8String{
314         void* syntax;
315         ComponentDesc* comp_desc;
316         struct berval identifier;
317         char id_buf[MAX_IDENTIFIER_LEN];
318         UTF8String value;
319 } ComponentUTF8String;
320
321 int GDecComponentUTF8String (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
322 int BDecComponentUTF8String (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
323 #define MatchingComponentUTF8String MatchingComponentOcts
324 #define ExtractingComponentUTF8String(mem_op,cr,data)
325 #define FreeComponentUTF8String FreeComponentOcts
326
327 /*
328  * Visible String
329  */
330 typedef struct ComponentVisibleString{
331         void* syntax;
332         ComponentDesc* comp_desc;
333         struct berval identifier;
334         char id_buf[MAX_IDENTIFIER_LEN];
335         VisibleString value;
336 } ComponentVisibleString;
337
338 #define GDecComponentVisibleString GDecComponentUTF8String
339 int BDecComponentVisibleString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
340 #define MatchingComponentVisibleString MatchingComponentOcts
341 #define ExtractingComponentVisibleString(mem_op,cr,data)
342 #define FreeComponentVisibleString FreeComponentOcts
343
344 /*
345  * ANY and ANY DEFINED BY
346  */
347
348 typedef int (*MatchFcn) (char*, void*, void*);
349 typedef void* (*ExtractFcn) (void*, ComponentReference*, void * );
350
351 typedef struct ComponentAnyInfo
352 {
353         int             anyId;
354         AsnOid          oid;
355         ComponentInt    intId;
356         unsigned int    size;
357         EncodeFcn       Encode;
358         gser_decoder_func* GSER_Decode;
359         ber_tag_decoder_func* BER_Decode;
360         ExtractFcn      Extract;
361         MatchFcn        Match;
362         FreeFcn         Free;
363         PrintFcn        Print;
364 } ComponentAnyInfo;
365
366 typedef struct ComponentAny{
367         void*           syntax;
368         ComponentDesc   *comp_desc;
369         struct berval   identifier;
370         char id_buf[MAX_IDENTIFIER_LEN];
371         ComponentAnyInfo        *cai;
372         void            *value;
373 } ComponentAny;
374
375 typedef ComponentAny ComponentAnyDefinedBy;
376
377 #define BDecComponentAnyDefinedBy BDecComponentAny
378 #define GDecComponentAnyDefinedBy GDecComponentAny
379 #define MatchingComponentAnyDefinedBy MatchingComponentAny
380 #define FreeComponentAnyDefinedBy FreeComponentAny
381
382 int BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
383 int GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
384 int MatchingComponentAny (char* oid, ComponentAny *a, ComponentAny *b);
385 void FreeComponentAny ( ComponentAny*);
386
387 void InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func B_decode, ExtractFcn extract, MatchFcn match, FreeFcn free, PrintFcn print);
388
389 void InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match, FreeFcn free, PrintFcn print);
390
391
392 /*
393  * UTCTime
394  */
395 typedef ComponentVisibleString ComponentUTCTime;
396 #define GDecComponentUTCTime GDecComponentVisibleString
397 #define BDecComponentUTCTime BDecComponentOcts
398 #define MatchingComponentUTCTime MatchingComponentOcts
399 #define ExtractingComponentUTCTime(mem_op,cr,data) NULL
400 #define FreeComponentUTCTime FreeComponentOcts
401
402 /*
403  * GeneralizedTime
404  */
405 typedef ComponentVisibleString ComponentGeneralizedTime;
406 #define GDecComponentGeneralizedTime GDecComponentVisibleString
407 #define BDecComponentGeneralizedTime BDecComponentOcts
408 #define MatchingComponentGeneralizedTime MatchingComponentOcts
409 #define ExtractingComponentGeneralizedTime(mem_op,cr,data) NULL
410 #define FreeComponentGeneralizedTime FreeComponentOcts
411
412 typedef int converter_func LDAP_P ((
413         struct berval* in ));
414
415 typedef struct asntype_to_syntax {
416         AsnTypeId       ats_typeId;
417         /* Syntax Descriptor */
418         char            *ats_syn_name;
419         /* Syntax OID */
420         char            *ats_syn_oid;
421         Syntax          *ats_syn;
422 } AsnTypetoSyntax;
423
424 typedef struct asntype_to_matchingrule {
425         AsnTypeId       atmr_typeId;
426         char*           atmr_mr_name;
427         /*Implicitly corresponding LDAP syntax OID*/
428         char*           atmr_syn_oid;
429         MatchingRule    *atmr_mr;
430 } AsnTypetoMatchingRule;
431
432 typedef struct asntype_to_matchingrule_table {
433         char*   atmr_oid;
434         struct asntype_to_matchingrule atmr_table[ASNTYPE_END];
435         struct asntype_to_matchingrule_table* atmr_table_next;
436 } AsnTypetoMatchingRuleTable;
437
438 extern AsnTypetoSyntax asn_to_syntax_mapping_tbl[];
439
440 #define MAX_OID_LEN 256
441 #define MAX_OD_ENTRY 8
442
443 /*
444  * Object Identifier and corresponding Syntax Decoder Table
445  */
446 typedef struct OID_Decoder_entry {
447         char            oe_oid[MAX_OID_LEN];
448         gser_decoder_func*   oe_gser_decoder;
449         ber_decoder_func*   oe_ber_decoder;
450         converter_func* oe_converter;
451         struct OID_Decoder_entry*       oe_next;
452         struct OID_Decoder_entry*       oe_prev;
453 } OD_entry;
454
455 void
456 m_convert_asn_to_ldap ( ComponentSyntaxInfo* csi, struct berval* bv);
457 int
458 m_convert_assert_to_comp ( gser_decoder_func* decoder, struct berval* bv,
459                         ComponentSyntaxInfo** csi, int len, int mode );
460 void*
461 m_convert_attr_to_comp ( Attribute* a, struct berval* bv );
462
463 /*
464  * Decoder Modes
465  * Different operation is required to handle Decoding(2), Extracted Component
466  * decoding(0), ANY DEFINED TYPe(2)
467  * b0 : Component Alloc(yes)
468  *      Constructed type : Component Alloc (Yes)
469  *      Primitive type : Component Alloc (Yes)
470  *      set to mode 2 in inner decoders
471  * b1 : Component Alloc (No)
472  *      Constructed type : Component Alloc (No)
473  *      Primitive type : Component Alloc (No)
474  *      set to mode 2 in inner decoders
475  * b2 : Default Mode
476  *      Constructed type : Component Alloc (Yes)
477  *      Primitive type : Component Alloc (No)
478  * in addition to above modes, the 4th bit has special meaning,
479  * b4 : if the 4th bit is clear, DecxxxContent is called
480  * b4 : if the 4th bit is set, Decxxx is called, then it is cleared.
481  */
482 #define DEC_ALLOC_MODE_0        0x01
483 #define DEC_ALLOC_MODE_1        0x02
484 #define DEC_ALLOC_MODE_2        0x04
485 #define CALL_TAG_DECODER        0x08
486 #define CALL_CONTENT_DECODER    ~0x08
487
488 #define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6"
489 #define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2"
490 #define MAX_LDAP_STR_LEN 128
491
492 MatchingRule*
493 retrieve_matching_rule( char* mr_oid, AsnTypeId type );
494
495 #endif