1 /* Copyright 2004 IBM Corporation
3 * Redisribution and use in source and binary forms, with or without
4 * modification, are permitted only as authorizd by the OpenLADP
8 * This work originally developed by Sang Seok Lim
9 * 2004/06/18 03:20:00 slim@OpenLDAP.org
12 #ifndef _H_COMPONENT_MODULE
13 #define _H_COMPONENT_MODULE
16 #include <ac/string.h>
17 #include <ac/socket.h>
22 #include <component.h>
29 #define MAX_IDENTIFIER_LEN 128
30 #define COMPONENTNOT_NULL(ptr) ((ptr) != NULL)
32 typedef struct slap_component_type {
34 * Don't change the order of following fields
35 * They are identical the first 9 fields of
38 LDAPAttributeType ct_atype;
39 struct berval ct_cname;
40 struct slap_attribute_type *ct_sup;
41 struct slap_attribute_type **ct_subtypes;
42 MatchingRule *ct_equality;
43 MatchingRule *ct_approx;
44 MatchingRule *ct_ordering;
45 MatchingRule *ct_substr;
53 typedef struct ComponentBits {
55 ComponentDesc* comp_desc;
56 struct berval identifier;
57 char id_buf[MAX_IDENTIFIER_LEN];
61 #define GASNBITS_PRESENT(abits) ((abits)->value.bits != NULL)
62 #define COMPONENTBITS_PRESENT(abits) ((abits)->value.bits != NULL)
63 int GEncComponentBits (GenBuf *b, ComponentBits* bits);
64 int GDecComponentBits (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
65 int BDecComponentBits (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
66 int MatchingComponentBits (char* oid, ComponentSyntaxInfo *bits1 , ComponentSyntaxInfo* bits2);
67 #define ExtractingComponentBits( mem_op, cr,data ) NULL
72 typedef struct ComponentBMPString {
74 ComponentDesc* comp_desc;
75 struct berval identifier;
76 char id_buf[MAX_IDENTIFIER_LEN];
80 int GEncComponentBMPString (GenBuf *b, ComponentBMPString* bmp);
81 int GDecComponentBMPString (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
82 int BDecComponentBMPString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
83 #define MatchingComponentBMPString MatchingComponentOcts
84 #define ExtractingComponentBMPString( mem_op, cr, data ) NULL
85 #define FreeComponentBMPString FreeComponentOcts
90 typedef struct ComponentBool {
92 ComponentDesc* comp_desc;
93 struct berval identifier;
94 char id_buf[MAX_IDENTIFIER_LEN];
98 int GEncComponentBool (GenBuf *b, ComponentBool * bool );
99 int GDecComponentBool ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
100 int BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
101 int MatchingComponentBool (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
102 #define ExtractingComponentBool( mem_op, cr, data ) NULL
103 #define FreeComponentBool(v) NULL
108 typedef struct ComponentEnum {
110 ComponentDesc* comp_desc;
111 struct berval identifier;
112 char id_buf[MAX_IDENTIFIER_LEN];
114 struct berval value_identifier;/*Why this value is defined here?*/
117 int GEncComponentEnum (GenBuf *b, ComponentEnum* comp_enum);
118 int GDecComponentEnum ( void* mem_op, GenBuf *a, void *result, AsnLen *bytesDecoded,int mode);
119 int BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
120 int MatchingComponentEnum (char *oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo * b);
121 #define ExtractingComponentEnum( mem_op, cr, data ) NULL
122 #define FreeComponentEnum FreeComponentInt
127 typedef struct ComponentIA5String {
129 ComponentDesc* comp_desc;
130 struct berval identifier;
131 char id_buf[MAX_IDENTIFIER_LEN];
133 } ComponentIA5String;
135 #define GEncComponentIA5String GEncComponentUTF8String
136 #define GDecComponentIA5String GDecComponentUTF8String
138 BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
139 int BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
140 #define MatchingComponentIA5String MatchingComponentOcts
141 #define ExtractingComponentIA5String(mem_op, cr,data) NULL
142 #define FreeComponentIA5String FreeComponentOcts
148 typedef struct ComponentInt {
150 ComponentDesc* comp_desc;
151 struct berval identifier;
152 char id_buf[MAX_IDENTIFIER_LEN];
156 #define GNOT_NULL(ptr) ((ptr) != NULL)
157 int GEncComponentInt (GenBuf *b, ComponentInt *comp_int);
158 int GDecComponentInt ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode );
159 int BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
160 int MatchingComponentInt (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
161 #define ExtractingComponentInt(mem_op, cr,data) NULL
162 #define FreeComponentInt(v) NULL
165 * LIST Data Structure for C_LIST
167 typedef struct ComponentList {
169 ComponentDesc* comp_desc;
170 struct berval identifier;
171 char id_buf[MAX_IDENTIFIER_LEN];
178 typedef struct ComponentNull {
180 ComponentDesc* comp_desc;
181 struct berval identifier;
182 char id_buf[MAX_IDENTIFIER_LEN];
186 int GEncComponentNull (GenBuf *b, ComponentNull* comp_null);
187 int GDecComponentNull ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
188 int BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
189 int BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
190 int MatchingComponentNull (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
191 #define ExtractingComponentNull(mem_op, cr, data) NULL
192 #define FreeComponentNull NULL
197 typedef struct ComponentNumericString {
199 ComponentDesc* comp_desc;
200 struct berval identifier;
201 char id_buf[MAX_IDENTIFIER_LEN];
203 } ComponentNumericString;
205 #define GEncComponentNumericString GEncComponentUTF8String
206 #define GDecComponentNumericString GDecComponentUTF8String
207 int BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
208 #define MatchingComponentNumericString MatchingComponentOcts
209 #define ExtractingComponentNumericString(mem_op, cr,data) NULL
210 #define FreeComponentNumericString FreeComponentOcts
215 typedef struct ComponentOcts {
217 ComponentDesc* comp_desc;
218 struct berval identifier;
219 char id_buf[MAX_IDENTIFIER_LEN];
223 #define GASNOCTS_PRESENT(aocts) ((aocts)->value.octs != NULL)
224 int GEncComponentOcts (GenBuf *b, ComponentOcts *octs);
225 int GDecComponentOcts (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
226 int BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
227 int BDecComponentOcts (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
228 int MatchingComponentOcts (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
229 #define ExtractingComponentOcts(mem_op,cr,data) NULL
230 void FreeComponentOcts( ComponentOcts* octs );
233 * OID (Object Identifier)
235 typedef struct ComponentOid {
237 ComponentDesc* comp_desc;
238 struct berval identifier;
239 char id_buf[MAX_IDENTIFIER_LEN];
243 #define GASNOID_PRESENT(aoid) ASNOCTS_PRESENT(aoid)
244 int GEncComponentOid (GenBuf *b, ComponentOid *oid);
245 int GDecComponentOid (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
246 int BDecComponentOid (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
247 int MatchingComponentOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
248 #define ExtractingComponentOid(mem_op, cr, data) NULL
249 #define FreeComponentOid FreeComponentOcts
254 typedef struct ComponentPrintableString{
256 ComponentDesc* comp_desc;
257 struct berval identifier;
258 char id_buf[MAX_IDENTIFIER_LEN];
259 PrintableString value;
260 } ComponentPrintableString;
261 #define GEncComponentPrintableString GEncComponentUTF8String
262 #define GDecComponentPrintableString GDecComponentUTF8String
263 int BDecComponentPrintableString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
264 int BDecComponentPrintableStringTag (void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
265 #define MatchingComponentPrintableString MatchingComponentOcts
266 #define ExtractingComponentPrintableString(mem_op, cr, data) NULL
267 #define FreeComponentPrintableString FreeComponentOcts
272 typedef struct ComponentReal{
274 ComponentDesc* comp_desc;
275 struct berval identifier;
276 char id_buf[MAX_IDENTIFIER_LEN];
280 int GEncComponentReal (GenBuf *b, ComponentReal* comp_real);
281 int GDecComponentReal (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
282 int BDecComponentReal (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
283 int MatchingComponentReal (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
284 #define ExtractingComponentReal( mem_op, cr, data ) NULL
285 #define FreeComponentReal(v) NULL
291 typedef struct ComponentRelativeOid {
293 ComponentDesc* comp_desc;
294 struct berval identifier;
295 char id_buf[MAX_IDENTIFIER_LEN];
296 AsnRelativeOid value;
297 } ComponentRelativeOid;
299 int GEncComponentRelativeOid (GenBuf *b, ComponentRelativeOid *r_oid);
300 int GDecComponentRelativeOid ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
301 int BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
302 int MatchingComponentRelativeOid (char* oid, ComponentSyntaxInfo *a, ComponentSyntaxInfo *b);
303 #define ExtractingComponentRelativeOid( mem_op, cr, data ) NULL
304 #define FreeComponentRelativeOid FreeComponentOid
309 typedef struct ComponentTeletexString {
311 ComponentDesc* comp_desc;
312 struct berval identifier;
313 char id_buf[MAX_IDENTIFIER_LEN];
315 } ComponentTeletexString;
317 int GEncComponentTeletexString (GenBuf *b, ComponentTeletexString * tel_str);
318 int GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode );
319 #define BDecComponentTeletexString BDecComponentOcts
320 #define MatchingComponentTeletexString MatchingComponentOcts
321 #define ExtractingComponentTeletexString(mem_op,cr,data)
322 #define FreeComponentTeletexString FreeComponentOcts
328 typedef struct ComponentUniversalString{
330 ComponentDesc* comp_desc;
331 struct berval identifier;
332 char id_buf[MAX_IDENTIFIER_LEN];
333 UniversalString value;
334 } ComponentUniversalString;
336 int GEncComponentUniversalString (GenBuf *b, ComponentUniversalString* uni_str);
337 int GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
338 int BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
339 #define MatchingComponentUniversalString MatchingComponentOcts
340 #define ExtractingComponentUniversalString(mem_op,cr,data)
341 #define FreeComponentUniversalString FreeComponentOcts
346 typedef struct ComponentUTF8String{
348 ComponentDesc* comp_desc;
349 struct berval identifier;
350 char id_buf[MAX_IDENTIFIER_LEN];
352 } ComponentUTF8String;
354 int GEncComponentUTF8String (GenBuf *b, ComponentUTF8String * utf_str);
355 int GDecComponentUTF8String (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
356 int BDecComponentUTF8String (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
357 #define MatchingComponentUTF8String MatchingComponentOcts
358 #define ExtractingComponentUTF8String(mem_op,cr,data)
359 #define FreeComponentUTF8String FreeComponentOcts
364 typedef struct ComponentVisibleString{
366 ComponentDesc* comp_desc;
367 struct berval identifier;
368 char id_buf[MAX_IDENTIFIER_LEN];
370 } ComponentVisibleString;
372 #define GEncComponentVisibleString GEncComponentUTF8String
373 #define GDecComponentVisibleString GDecComponentUTF8String
374 int BDecComponentVisibleString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
375 #define MatchingComponentVisibleString MatchingComponentOcts
376 #define ExtractingComponentVisibleString(mem_op,cr,data)
377 #define FreeComponentVisibleString FreeComponentOcts
380 * ANY and ANY DEFINED BY
383 typedef int (*MatchFcn) (char*, void*, void*);
384 typedef void* (*ExtractFcn) (void*, ComponentReference*, void * );
386 typedef struct ComponentAnyInfo
393 gser_decoder_func* GSER_Decode;
394 ber_tag_decoder_func* BER_Decode;
401 typedef struct ComponentAnyInfo OidDecoderMapping ;
403 typedef struct ComponentAny{
405 ComponentDesc *comp_desc;
406 struct berval identifier;
407 char id_buf[MAX_IDENTIFIER_LEN];
408 ComponentAnyInfo *cai;
412 typedef ComponentAny ComponentAnyDefinedBy;
414 #define BDecComponentAnyDefinedBy BDecComponentAny
415 #define GDecComponentAnyDefinedBy GDecComponentAny
416 #define MatchingComponentAnyDefinedBy MatchingComponentAny
417 #define FreeComponentAnyDefinedBy FreeComponentAny
419 int GEncComponentAny (GenBuf *b, ComponentAny *comp_any);
420 int BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
421 int GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
422 int MatchingComponentAny (char* oid, ComponentAny *a, ComponentAny *b);
423 void FreeComponentAny ( ComponentAny*);
425 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);
427 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);
429 int CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo *v, struct berval* select );
431 OidDecoderMapping* RetrieveOidDecoderMappingbyBV( struct berval* in );
432 OidDecoderMapping* RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len );
433 OidDecoderMapping* RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len );
437 typedef ComponentVisibleString ComponentUTCTime;
438 int GEncComponentUTCTime( GenBuf* b, ComponentUTCTime* utc_time);
439 #define GDecComponentUTCTime GDecComponentVisibleString
440 #define BDecComponentUTCTime BDecComponentOcts
441 #define MatchingComponentUTCTime MatchingComponentOcts
442 #define ExtractingComponentUTCTime(mem_op,cr,data) NULL
443 #define FreeComponentUTCTime FreeComponentOcts
448 typedef ComponentVisibleString ComponentGeneralizedTime;
449 int GEncComponentGeneralizedTime (GenBuf *b, ComponentGeneralizedTime *gen_time);
450 #define GDecComponentGeneralizedTime GDecComponentVisibleString
451 #define BDecComponentGeneralizedTime BDecComponentOcts
452 #define MatchingComponentGeneralizedTime MatchingComponentOcts
453 #define ExtractingComponentGeneralizedTime(mem_op,cr,data) NULL
454 #define FreeComponentGeneralizedTime FreeComponentOcts
456 typedef int converter_func LDAP_P ((
457 struct berval* in ));
459 typedef struct asntype_to_syntax {
460 AsnTypeId ats_typeId;
461 /* Syntax Descriptor */
468 typedef struct asntype_to_comp_matchingrule {
469 AsnTypeId atc_typeId;
474 } AsnTypetoCompMatchingRule;
476 typedef struct asntype_to_comp_desc {
477 AsnTypeId atcd_typeId;
478 ComponentDesc atcd_cd;
481 typedef struct asntype_to_comp_type {
483 ComponentType ac_comp_type;
486 /* refined matching purpose */
487 typedef struct asntype_to_matchingrule {
488 AsnTypeId atmr_typeId;
490 /*Implicitly corresponding LDAP syntax OID*/
492 MatchingRule *atmr_mr;
493 } AsnTypetoMatchingRule;
495 typedef struct asntype_to_matchingrule_table {
497 struct asntype_to_matchingrule atmr_table[ASNTYPE_END];
498 struct asntype_to_matchingrule_table* atmr_table_next;
499 } AsnTypetoMatchingRuleTable;
501 #define MAX_OID_LEN 256
502 #define MAX_OD_ENTRY 8
505 * Object Identifier and corresponding Syntax Decoder Table
507 typedef struct OID_Decoder_entry {
508 char oe_oid[MAX_OID_LEN];
509 gser_decoder_func* oe_gser_decoder;
510 ber_decoder_func* oe_ber_decoder;
511 converter_func* oe_converter;
512 struct OID_Decoder_entry* oe_next;
513 struct OID_Decoder_entry* oe_prev;
517 m_convert_asn_to_ldap ( ComponentSyntaxInfo* csi, struct berval* bv);
519 m_convert_assert_to_comp ( gser_decoder_func* decoder, struct berval* bv,
520 ComponentSyntaxInfo** csi, int len, int mode );
522 m_convert_attr_to_comp ( Attribute* a, struct berval* bv );
526 * Different operation is required to handle Decoding(2), Extracted Component
527 * decoding(0), ANY DEFINED TYPe(2)
528 * b0 : Component Alloc(yes)
529 * Constructed type : Component Alloc (Yes)
530 * Primitive type : Component Alloc (Yes)
531 * set to mode 2 in inner decoders
532 * b1 : Component Alloc (No)
533 * Constructed type : Component Alloc (No)
534 * Primitive type : Component Alloc (No)
535 * set to mode 2 in inner decoders
537 * Constructed type : Component Alloc (Yes)
538 * Primitive type : Component Alloc (No)
539 * in addition to above modes, the 4th bit has special meaning,
540 * b4 : if the 4th bit is clear, DecxxxContent is called
541 * b4 : if the 4th bit is set, Decxxx is called, then it is cleared.
543 #define DEC_ALLOC_MODE_0 0x01
544 #define DEC_ALLOC_MODE_1 0x02
545 #define DEC_ALLOC_MODE_2 0x04
546 #define CALL_TAG_DECODER 0x08
547 #define CALL_CONTENT_DECODER ~0x08
549 #define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6"
550 #define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2"
551 #define MAX_LDAP_STR_LEN 128
554 retrieve_matching_rule( char* mr_oid, AsnTypeId type );
556 #define INITIAL_DN_SIZE 128
557 #define INITIAL_ATTR_SIZE 256
558 #define INCREMENT_SIZE 32
560 * Followings are for conversion from ASN.1 RDN and DN to
563 #define MAX_ALIASING_ENTRY 128
564 int increment_bv_mem ( struct berval* in );
565 int intToAscii ( int value, char* buf );
566 typedef ComponentList irRDNSequence;
567 typedef ComponentList irRelativeDistinguishedName;
568 typedef ComponentOid irAttributeType;
569 typedef struct comp_irAttributeTypeAndValue /* SEQUENCE */
572 ComponentDesc* comp_desc;
573 struct berval identifier;
574 char id_buf[MAX_IDENTIFIER_LEN];
575 irAttributeType type; /* AttributeType */
576 ComponentAnyDefinedBy value; /* ANY DEFINED BY type */
577 } irAttributeTypeAndValue;
578 #define RDN_MATCH_OID "1.2.36.79672281.1.13.3"
579 #define DN_MATCH_OID "2.5.13.1"
581 extern AsnTypetoSyntax asn_to_syntax_mapping_tbl[];
582 extern AsnTypetoCompMatchingRule asntype_to_compMR_mapping_tbl[];
583 extern AsnTypetoCompType asntype_to_compType_mapping_tbl[];
584 extern AsnTypetoCompDesc asntype_to_compdesc_mapping_tbl[];
586 int ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out );
587 int ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out );
589 void* comp_nibble_memory_allocator ( int init_mem, int inc_mem );