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