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 32
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
int BDecComponentTeletexStringTag (void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode );
320
int BDecComponentTeletexString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode );
321
#define MatchingComponentTeletexString MatchingComponentOcts
322
#define ExtractingComponentTeletexString(mem_op,cr,data)
323
#define FreeComponentTeletexString FreeComponentOcts
329
typedef struct ComponentUniversalString{
331
ComponentDesc* comp_desc;
332
struct berval identifier;
333
char id_buf[MAX_IDENTIFIER_LEN];
334
UniversalString value;
335
} ComponentUniversalString;
337
int GEncComponentUniversalString (GenBuf *b, ComponentUniversalString* uni_str);
338
int GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
339
int BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
340
#define MatchingComponentUniversalString MatchingComponentOcts
341
#define ExtractingComponentUniversalString(mem_op,cr,data)
342
#define FreeComponentUniversalString FreeComponentOcts
347
typedef struct ComponentUTF8String{
349
ComponentDesc* comp_desc;
350
struct berval identifier;
351
char id_buf[MAX_IDENTIFIER_LEN];
353
} ComponentUTF8String;
355
int GEncComponentUTF8String (GenBuf *b, ComponentUTF8String * utf_str);
356
int GDecComponentUTF8String (void* mem_op, GenBuf *b, void *result, AsnLen *bytesDecoded, int mode);
357
int BDecComponentUTF8String (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
358
#define MatchingComponentUTF8String MatchingComponentOcts
359
#define ExtractingComponentUTF8String(mem_op,cr,data)
360
#define FreeComponentUTF8String FreeComponentOcts
365
typedef struct ComponentVisibleString{
367
ComponentDesc* comp_desc;
368
struct berval identifier;
369
char id_buf[MAX_IDENTIFIER_LEN];
371
} ComponentVisibleString;
373
#define GEncComponentVisibleString GEncComponentUTF8String
374
#define GDecComponentVisibleString GDecComponentUTF8String
375
int BDecComponentVisibleString (void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *result, AsnLen *bytesDecoded, int mode);
376
#define MatchingComponentVisibleString MatchingComponentOcts
377
#define ExtractingComponentVisibleString(mem_op,cr,data)
378
#define FreeComponentVisibleString FreeComponentOcts
381
* ANY and ANY DEFINED BY
384
typedef int (*MatchFcn) (char*, void*, void*);
385
typedef void* (*ExtractFcn) (void*, ComponentReference*, void * );
387
typedef struct ComponentAnyInfo
394
gser_decoder_func* GSER_Decode;
395
ber_tag_decoder_func* BER_Decode;
402
typedef struct ComponentAnyInfo OidDecoderMapping ;
404
typedef struct ComponentAny{
406
ComponentDesc *comp_desc;
407
struct berval identifier;
408
char id_buf[MAX_IDENTIFIER_LEN];
409
ComponentAnyInfo *cai;
413
typedef ComponentAny ComponentAnyDefinedBy;
415
#define BDecComponentAnyDefinedBy BDecComponentAny
416
#define GDecComponentAnyDefinedBy GDecComponentAny
417
#define MatchingComponentAnyDefinedBy MatchingComponentAny
418
#define FreeComponentAnyDefinedBy FreeComponentAny
420
int GEncComponentAny (GenBuf *b, ComponentAny *comp_any);
421
int BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
422
int GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode);
423
int MatchingComponentAny (char* oid, ComponentAny *a, ComponentAny *b);
424
void FreeComponentAny ( ComponentAny*);
426
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);
428
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);
430
int CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo *v, struct berval* select );
432
OidDecoderMapping* RetrieveOidDecoderMappingbyBV( struct berval* in );
433
OidDecoderMapping* RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len );
434
OidDecoderMapping* RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len );
438
typedef ComponentVisibleString ComponentUTCTime;
439
#define GEncComponentUTCTime GEncComponentUTF8String
440
#define GDecComponentUTCTime GDecComponentVisibleString
441
#define BDecComponentUTCTime BDecComponentOcts
442
#define MatchingComponentUTCTime MatchingComponentOcts
443
#define ExtractingComponentUTCTime(mem_op,cr,data) NULL
444
#define FreeComponentUTCTime FreeComponentOcts
449
typedef ComponentVisibleString ComponentGeneralizedTime;
450
int GEncComponentGeneralizedTime (GenBuf *b, ComponentGeneralizedTime *gen_time);
451
#define GDecComponentGeneralizedTime GDecComponentVisibleString
452
#define BDecComponentGeneralizedTime BDecComponentOcts
453
#define MatchingComponentGeneralizedTime MatchingComponentOcts
454
#define ExtractingComponentGeneralizedTime(mem_op,cr,data) NULL
455
#define FreeComponentGeneralizedTime FreeComponentOcts
457
typedef int converter_func LDAP_P ((
458
struct berval* in ));
460
typedef struct asntype_to_syntax {
461
AsnTypeId ats_typeId;
462
/* Syntax Descriptor */
469
typedef struct asntype_to_comp_matchingrule {
470
AsnTypeId atc_typeId;
475
} AsnTypetoCompMatchingRule;
477
typedef struct asntype_to_comp_desc {
478
AsnTypeId atcd_typeId;
479
ComponentDesc atcd_cd;
482
typedef struct asntype_to_comp_type {
484
ComponentType ac_comp_type;
487
/* refined matching purpose */
488
typedef struct asntype_to_matchingrule {
489
AsnTypeId atmr_typeId;
491
/*Implicitly corresponding LDAP syntax OID*/
493
MatchingRule *atmr_mr;
494
} AsnTypetoMatchingRule;
496
typedef struct asntype_to_matchingrule_table {
498
struct asntype_to_matchingrule atmr_table[ASNTYPE_END];
499
struct asntype_to_matchingrule_table* atmr_table_next;
500
} AsnTypetoMatchingRuleTable;
502
#define MAX_OID_LEN 256
503
#define MAX_OD_ENTRY 8
506
* Object Identifier and corresponding Syntax Decoder Table
508
typedef struct OID_Decoder_entry {
509
char oe_oid[MAX_OID_LEN];
510
gser_decoder_func* oe_gser_decoder;
511
ber_decoder_func* oe_ber_decoder;
512
converter_func* oe_converter;
513
struct OID_Decoder_entry* oe_next;
514
struct OID_Decoder_entry* oe_prev;
518
m_convert_asn_to_ldap ( ComponentSyntaxInfo* csi, struct berval* bv);
520
m_convert_assert_to_comp ( gser_decoder_func* decoder, struct berval* bv,
521
ComponentSyntaxInfo** csi, int len, int mode );
523
m_convert_attr_to_comp ( Attribute* a, struct berval* bv );
527
* Different operation is required to handle Decoding(2), Extracted Component
528
* decoding(0), ANY DEFINED TYPe(2)
529
* b0 : Component Alloc(yes)
530
* Constructed type : Component Alloc (Yes)
531
* Primitive type : Component Alloc (Yes)
532
* set to mode 2 in inner decoders
533
* b1 : Component Alloc (No)
534
* Constructed type : Component Alloc (No)
535
* Primitive type : Component Alloc (No)
536
* set to mode 2 in inner decoders
538
* Constructed type : Component Alloc (Yes)
539
* Primitive type : Component Alloc (No)
540
* in addition to above modes, the 4th bit has special meaning,
541
* b4 : if the 4th bit is clear, DecxxxContent is called
542
* b4 : if the 4th bit is set, Decxxx is called, then it is cleared.
544
#define DEC_ALLOC_MODE_0 0x01
545
#define DEC_ALLOC_MODE_1 0x02
546
#define DEC_ALLOC_MODE_2 0x04
547
#define CALL_TAG_DECODER 0x08
548
#define CALL_CONTENT_DECODER ~0x08
550
#define OID_ALL_COMP_MATCH "1.2.36.79672281.1.13.6"
551
#define OID_COMP_FILTER_MATCH "1.2.36.79672281.1.13.2"
552
#define MAX_LDAP_STR_LEN 128
555
retrieve_matching_rule( char* mr_oid, AsnTypeId type );
557
#define INITIAL_DN_SIZE 128
558
#define INITIAL_ATTR_SIZE 256
559
#define INCREMENT_SIZE 32
561
* Followings are for conversion from ASN.1 RDN and DN to
564
#define MAX_ALIASING_ENTRY 128
565
int increment_bv_mem ( struct berval* in );
566
int intToAscii ( int value, char* buf );
567
typedef ComponentList irRDNSequence;
568
typedef ComponentList irRelativeDistinguishedName;
569
typedef ComponentOid irAttributeType;
570
typedef struct comp_irAttributeTypeAndValue /* SEQUENCE */
573
ComponentDesc* comp_desc;
574
struct berval identifier;
575
char id_buf[MAX_IDENTIFIER_LEN];
576
irAttributeType type; /* AttributeType */
577
ComponentAnyDefinedBy value; /* ANY DEFINED BY type */
578
} irAttributeTypeAndValue;
579
#define RDN_MATCH_OID "1.2.36.79672281.1.13.3"
580
#define DN_MATCH_OID "2.5.13.1"
582
extern AsnTypetoSyntax asn_to_syntax_mapping_tbl[];
583
extern AsnTypetoCompMatchingRule asntype_to_compMR_mapping_tbl[];
584
extern AsnTypetoCompType asntype_to_compType_mapping_tbl[];
585
extern AsnTypetoCompDesc asntype_to_compdesc_mapping_tbl[];
587
int ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out );
588
int ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out );
590
void* comp_nibble_memory_allocator ( int init_mem, int inc_mem );
592
ComponentDesc* get_ComponentDesc( int id );