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
13 #include <ac/string.h>
14 #include <ac/socket.h>
20 #include "component.h"
27 #ifndef SLAPD_COMP_MATCH
28 #define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC
31 #ifdef SLAPD_COMP_MATCH
33 * Matching function : BIT STRING
36 MatchingComponentBits ( char* oid, ComponentSyntaxInfo *csi_attr,
37 ComponentSyntaxInfo *csi_assert )
44 mr = retrieve_matching_rule(oid, (AsnTypeId)csi_attr->csi_comp_desc->cd_type_id );
46 return component_value_match( mr, csi_attr , csi_assert );
48 a = ((ComponentBits*)csi_attr);
49 b = ((ComponentBits*)csi_assert);
50 rc = ( a->value.bitLen == b->value.bitLen &&
51 strncmp( a->value.bits,b->value.bits,a->value.bitLen ) == 0 );
52 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
56 * Free function: BIT STRING
59 FreeComponentBits ( ComponentBits* v ) {
60 FreeAsnBits( &v->value );
64 * GSER Encoder : BIT STRING
67 GEncComponentBits ( GenBuf *b, ComponentBits *in )
71 return GEncAsnBitsContent ( b, &in->value );
76 * GSER Decoder : BIT STRING
79 GDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
83 void* component_values;
84 ComponentBits* k, **k2;
87 k = (ComponentBits*) v;
89 if ( mode & DEC_ALLOC_MODE_0 ) {
90 k2 = (ComponentBits**) v;
91 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
92 if ( !*k2 ) return LDAP_DECODING_ERROR;
96 if ( GDecAsnBitsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
97 if ( k ) CompFree( mem_op, k );
98 return LDAP_DECODING_ERROR;
100 k->value = result.value;
102 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
103 if ( !k->comp_desc ) {
104 if ( k ) CompFree( mem_op, k );
105 return LDAP_DECODING_ERROR;
107 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
108 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
109 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
110 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
111 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
112 k->comp_desc->cd_extract_i = NULL;
113 k->comp_desc->cd_type = ASN_BASIC;
114 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
115 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
117 /* Real Decoding code need to be followed */
122 * Component BER Decoder : BIT STRING
125 BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
126 return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
130 BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
131 AsnLen *bytesDecoded, int mode )
135 void* component_values;
136 ComponentBits* k, **k2;
139 k = (ComponentBits*) v;
141 if ( mode & DEC_ALLOC_MODE_0 ) {
142 k2 = (ComponentBits**) v;
143 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
144 if ( !*k2 ) return LDAP_DECODING_ERROR;
148 if ( mode & CALL_TAG_DECODER ){
149 mode = mode & CALL_CONTENT_DECODER;
150 rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );
152 rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
156 if ( k ) CompFree( mem_op, k );
157 return LDAP_DECODING_ERROR;
162 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
163 if ( !k->comp_desc ) {
164 if ( k ) CompFree( mem_op, k );
165 return LDAP_DECODING_ERROR;
167 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
168 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
169 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
170 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
171 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
172 k->comp_desc->cd_extract_i = NULL;
173 k->comp_desc->cd_type = ASN_BASIC;
174 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
175 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
181 * Component GSER BMPString Encoder
184 GEncComponentBMPString ( GenBuf *b, ComponentBMPString *in )
186 if ( !in || in->value.octetLen <= 0 ) return (-1);
187 return GEncBMPStringContent ( b, &in->value );
191 * Component GSER BMPString Decoder
194 GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
198 void* component_values;
199 ComponentBMPString* k, **k2;
202 k = (ComponentBMPString*) v;
204 if ( mode & DEC_ALLOC_MODE_0 ) {
205 k2 = (ComponentBMPString**) v;
206 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
207 if ( !*k2 ) return LDAP_DECODING_ERROR;
213 if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
214 if ( k ) CompFree( mem_op, k );
215 return LDAP_DECODING_ERROR;
218 k->value = result.value;
220 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
221 if ( !k->comp_desc ) {
222 if ( k ) CompFree( mem_op, k );
223 return LDAP_DECODING_ERROR;
225 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
226 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
227 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
228 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
229 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
230 k->comp_desc->cd_extract_i = NULL;
231 k->comp_desc->cd_type = ASN_BASIC;
232 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
233 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
240 * Component BER BMPString Decoder
243 BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
244 return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
248 BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
249 AsnLen *bytesDecoded, int mode )
253 void* component_values;
254 ComponentBMPString* k, **k2;
257 k = (ComponentBMPString*) v;
259 if ( mode & DEC_ALLOC_MODE_0 ) {
260 k2 = (ComponentBMPString**) v;
261 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
262 if ( !*k2 ) return LDAP_DECODING_ERROR;
266 if ( mode & CALL_TAG_DECODER ){
267 mode = mode & CALL_CONTENT_DECODER;
268 rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );
270 rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
274 if ( k ) CompFree( mem_op, k );
275 return LDAP_DECODING_ERROR;
280 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
281 if ( !k->comp_desc ) {
282 if ( k ) CompFree ( mem_op, k );
283 return LDAP_DECODING_ERROR;
285 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
286 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
287 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
288 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
289 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
290 k->comp_desc->cd_extract_i = NULL;
291 k->comp_desc->cd_type = ASN_BASIC;
292 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
293 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
300 * Component GSER Encoder : UTF8 String
303 GEncComponentUTF8String ( GenBuf *b, ComponentUTF8String *in )
305 if ( !in || in->value.octetLen <= 0 )
307 return GEncUTF8StringContent ( b, &in->value );
311 * Component GSER Decoder : UTF8 String
314 GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,
315 AsnLen *bytesDecoded, int mode) {
318 void* component_values;
319 ComponentUTF8String* k, **k2;
322 k = (ComponentUTF8String*) v;
324 if ( mode & DEC_ALLOC_MODE_0 ) {
325 k2 = (ComponentUTF8String**) v;
326 *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
327 if ( !*k2 ) return LDAP_DECODING_ERROR;
333 if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
334 if ( k ) CompFree( mem_op, k );
335 return LDAP_DECODING_ERROR;
338 k->value = result.value;
340 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
341 if ( !k->comp_desc ) {
342 if ( k ) CompFree( mem_op, k );
343 return LDAP_DECODING_ERROR;
345 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
346 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
347 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
348 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
349 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
350 k->comp_desc->cd_extract_i = NULL;
351 k->comp_desc->cd_type = ASN_BASIC;
352 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
353 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
359 * Component BER Decoder : UTF8String
362 BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
363 return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
367 BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len,
368 void *v, AsnLen *bytesDecoded, int mode )
372 void* component_values;
373 ComponentUTF8String* k, **k2;
376 k = (ComponentUTF8String*) v;
378 if ( mode & DEC_ALLOC_MODE_0 ) {
379 k2 = (ComponentUTF8String**) v;
380 *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
381 if ( !*k2 ) return LDAP_DECODING_ERROR;
385 if ( mode & CALL_TAG_DECODER ){
386 mode = mode & CALL_CONTENT_DECODER;
387 rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );
389 rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
392 if ( k ) CompFree( mem_op, k );
393 return LDAP_DECODING_ERROR;
398 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
399 if ( !k->comp_desc ) {
400 if ( k ) CompFree ( mem_op, k );
401 return LDAP_DECODING_ERROR;
403 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
404 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
405 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
406 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
407 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
408 k->comp_desc->cd_extract_i = NULL;
409 k->comp_desc->cd_type = ASN_BASIC;
410 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
411 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
415 * Component GSER Encoder : Teletex String
418 GEncComponentTeletexString ( GenBuf *b, ComponentTeletexString *in )
420 if ( !in || in->value.octetLen <= 0 )
422 return GEncTeletexStringContent ( b, &in->value );
426 * Component GSER Decoder : Teletex String
429 GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v,
430 AsnLen *bytesDecoded, int mode) {
433 void* component_values;
434 ComponentTeletexString* k, **k2;
435 GTeletexString result;
437 k = (ComponentTeletexString*) v;
439 if ( mode & DEC_ALLOC_MODE_0 ) {
440 k2 = (ComponentTeletexString**) v;
441 *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
442 if ( !*k2 ) return LDAP_DECODING_ERROR;
448 if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
449 if ( k ) CompFree( mem_op, k );
450 return LDAP_DECODING_ERROR;
453 k->value = result.value;
455 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
456 if ( !k->comp_desc ) {
457 if ( k ) CompFree ( mem_op, k );
458 return LDAP_DECODING_ERROR;
460 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString;
461 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString;
462 k->comp_desc->cd_free = (comp_free_func*)FreeComponentTeletexString;
463 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
464 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
465 k->comp_desc->cd_extract_i = NULL;
466 k->comp_desc->cd_type = ASN_BASIC;
467 k->comp_desc->cd_type_id = BASICTYPE_VIDEOTEX_STR;
468 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTeletexString;
475 * Matching function : BOOLEAN
478 MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr,
479 ComponentSyntaxInfo* csi_assert )
482 ComponentBool *a, *b;
485 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
487 return component_value_match( mr, csi_attr , csi_assert );
490 a = ((ComponentBool*)csi_attr);
491 b = ((ComponentBool*)csi_assert);
493 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
497 * GSER Encoder : BOOLEAN
500 GEncComponentBool ( GenBuf *b, ComponentBool *in )
504 return GEncAsnBoolContent ( b, &in->value );
508 * GSER Decoder : BOOLEAN
511 GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
515 ComponentBool* k, **k2;
518 k = (ComponentBool*) v;
520 if ( mode & DEC_ALLOC_MODE_0 ) {
521 k2 = (ComponentBool**) v;
522 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
523 if ( !*k2 ) return LDAP_DECODING_ERROR;
527 if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) {
528 if ( k ) CompFree ( mem_op, k );
529 return LDAP_DECODING_ERROR;
532 k->value = result.value;
534 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
535 if ( !k->comp_desc ) {
536 if ( k ) CompFree ( mem_op, k );
537 return LDAP_DECODING_ERROR;
539 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
540 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
541 k->comp_desc->cd_free = (comp_free_func*)NULL;
542 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
543 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
544 k->comp_desc->cd_extract_i = NULL;
545 k->comp_desc->cd_type = ASN_BASIC;
546 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
547 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
553 * Component BER Decoder : BOOLEAN
556 BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
557 return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
561 BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
562 AsnLen *bytesDecoded, int mode )
566 ComponentBool* k, **k2;
569 k = (ComponentBool*) v;
571 if ( mode & DEC_ALLOC_MODE_0 ) {
572 k2 = (ComponentBool**) v;
573 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
574 if ( !*k2 ) return LDAP_DECODING_ERROR;
578 if ( mode & CALL_TAG_DECODER ){
579 mode = mode & CALL_CONTENT_DECODER;
580 rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded );
582 rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded );
585 if ( k ) CompFree ( mem_op, k );
586 return LDAP_DECODING_ERROR;
591 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
592 if ( !k->comp_desc ) {
593 if ( k ) CompFree ( mem_op, k );
594 return LDAP_DECODING_ERROR;
596 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
597 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
598 k->comp_desc->cd_free = (comp_free_func*)NULL;
599 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
600 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
601 k->comp_desc->cd_extract_i = NULL;
602 k->comp_desc->cd_type = ASN_BASIC;
603 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
604 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
610 * Matching function : ENUMERATE
613 MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr,
614 ComponentSyntaxInfo *csi_assert )
618 ComponentEnum *a, *b;
621 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
623 return component_value_match( mr, csi_attr , csi_assert );
625 a = ((ComponentEnum*)csi_attr);
626 b = ((ComponentEnum*)csi_assert);
627 rc = (a->value == b->value);
629 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
633 * GSER Encoder : ENUMERATE
636 GEncComponentEnum ( GenBuf *b, ComponentEnum *in )
640 return GEncAsnEnumContent ( b, &in->value );
644 * GSER Decoder : ENUMERATE
647 GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
651 void* component_values;
652 ComponentEnum* k, **k2;
655 k = (ComponentEnum*) v;
657 if ( mode & DEC_ALLOC_MODE_0 ) {
658 k2 = (ComponentEnum**) v;
659 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
660 if ( !*k2 ) return LDAP_DECODING_ERROR;
664 if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
665 if ( k ) CompFree ( mem_op, k );
666 return LDAP_DECODING_ERROR;
669 k->value_identifier.bv_val = result.value_identifier;
670 k->value_identifier.bv_len = result.len;
672 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
673 if ( !k->comp_desc ) {
674 if ( k ) CompFree ( mem_op, k );
675 return LDAP_DECODING_ERROR;
677 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
678 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
679 k->comp_desc->cd_free = (comp_free_func*)NULL;
680 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
681 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
682 k->comp_desc->cd_extract_i = NULL;
683 k->comp_desc->cd_type = ASN_BASIC;
684 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
685 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
691 * Component BER Decoder : ENUMERATE
694 BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
695 return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
699 BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
700 AsnLen *bytesDecoded, int mode )
704 void* component_values;
705 ComponentEnum* k, **k2;
708 k = (ComponentEnum*) v;
710 if ( mode & DEC_ALLOC_MODE_0 ) {
711 k2 = (ComponentEnum**) v;
712 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
713 if ( k ) return LDAP_DECODING_ERROR;
717 if ( mode & CALL_TAG_DECODER ){
718 mode = mode & CALL_CONTENT_DECODER;
719 rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded );
721 rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded );
724 if ( k ) CompFree ( mem_op, k );
725 return LDAP_DECODING_ERROR;
730 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
731 if ( !k->comp_desc ) {
732 if ( k ) CompFree ( mem_op, k );
733 return LDAP_DECODING_ERROR;
735 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
736 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
737 k->comp_desc->cd_free = (comp_free_func*)NULL;
738 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
739 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
740 k->comp_desc->cd_extract_i = NULL;
741 k->comp_desc->cd_type = ASN_BASIC;
742 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
743 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
749 * Component GSER Encoder : IA5String
752 GEncComponentIA5Stirng ( GenBuf *b, ComponentIA5String* in )
754 if ( !in || in->value.octetLen <= 0 ) return (-1);
755 return GEncIA5StringContent( b, &in->value );
759 * Component BER Decoder : IA5String
762 BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
763 return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
767 BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
768 AsnLen *bytesDecoded, int mode )
772 void* component_values;
773 ComponentIA5String* k, **k2;
776 k = (ComponentIA5String*) v;
778 if ( mode & DEC_ALLOC_MODE_0 ) {
779 k2 = (ComponentIA5String**) v;
780 *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) );
781 if ( !*k2 ) return LDAP_DECODING_ERROR;
785 if ( mode & CALL_TAG_DECODER ){
786 mode = mode & CALL_CONTENT_DECODER;
787 rc = BDecIA5String ( mem_op, b, &result, bytesDecoded );
789 rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
792 if ( k ) CompFree ( mem_op, k );
793 return LDAP_DECODING_ERROR;
798 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
799 if ( !k->comp_desc ) {
800 if ( k ) CompFree ( mem_op, k );
801 return LDAP_DECODING_ERROR;
803 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String;
804 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String;
805 k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String;
806 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
807 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
808 k->comp_desc->cd_extract_i = NULL;
809 k->comp_desc->cd_type = ASN_BASIC;
810 k->comp_desc->cd_type_id = BASICTYPE_IA5_STR;
811 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentIA5String;
817 * Matching function : INTEGER
820 MatchingComponentInt(char* oid, ComponentSyntaxInfo* csi_attr,
821 ComponentSyntaxInfo* csi_assert )
827 /* check if this ASN type's matching rule is overrided */
828 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
829 /* if existing function is overrided, call the overriding
832 return component_value_match( mr, csi_attr , csi_assert );
834 a = ((ComponentInt*)csi_attr);
835 b = ((ComponentInt*)csi_assert);
837 return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
841 * GSER Encoder : INTEGER
844 GEncComponentInt ( GenBuf *b, ComponentInt* in )
846 if ( !in ) return (-1);
847 return GEncAsnIntContent ( b, &in->value );
851 * GSER Decoder : INTEGER
854 GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
858 void* component_values;
859 ComponentInt* k, **k2;
862 k = (ComponentInt*) v;
864 if ( mode & DEC_ALLOC_MODE_0 ) {
865 k2 = (ComponentInt**) v;
866 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
867 if ( !*k2 ) return LDAP_DECODING_ERROR;
871 if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
872 if ( k ) CompFree ( mem_op, k );
873 return LDAP_DECODING_ERROR;
875 k->value = result.value;
877 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
878 if ( !k->comp_desc ) {
879 if ( k ) CompFree ( mem_op, k );
880 return LDAP_DECODING_ERROR;
882 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
883 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
884 k->comp_desc->cd_free = (comp_free_func*)NULL;
885 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
886 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
887 k->comp_desc->cd_extract_i = NULL;
888 k->comp_desc->cd_type = ASN_BASIC;
889 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
890 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
896 * Component BER Decoder : INTEGER
899 BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
900 return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
904 BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
905 AsnLen *bytesDecoded, int mode )
909 void* component_values;
910 ComponentInt* k, **k2;
913 k = (ComponentInt*) v;
915 if ( mode & DEC_ALLOC_MODE_0 ) {
916 k2 = (ComponentInt**) v;
917 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
918 if ( !*k2 ) return LDAP_DECODING_ERROR;
922 if ( mode & CALL_TAG_DECODER ){
923 mode = mode & CALL_CONTENT_DECODER;
924 rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded );
926 rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded );
930 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
931 if ( !k->comp_desc ) {
932 if ( k ) CompFree ( mem_op, k );
933 return LDAP_DECODING_ERROR;
935 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
936 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
937 k->comp_desc->cd_free = (comp_free_func*)NULL;
938 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
939 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
940 k->comp_desc->cd_extract_i = NULL;
941 k->comp_desc->cd_type = ASN_BASIC;
942 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
943 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
949 * Matching function : NULL
952 MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr,
953 ComponentSyntaxInfo *csi_assert )
956 ComponentNull *a, *b;
959 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
961 return component_value_match( mr, csi_attr , csi_assert );
963 a = ((ComponentNull*)csi_attr);
964 b = ((ComponentNull*)csi_assert);
966 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
970 * GSER Encoder : NULL
973 GEncComponentNull ( GenBuf *b, ComponentNull *in )
975 if ( !in ) return (-1);
976 return GEncAsnNullContent ( b, &in->value );
980 * GSER Decoder : NULL
983 GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
987 void* component_values;
988 ComponentNull* k, **k2;
991 k = (ComponentNull*) v;
993 if ( mode & DEC_ALLOC_MODE_0 ) {
994 k2 = (ComponentNull**) v;
995 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
996 if ( !*k2 ) return LDAP_DECODING_ERROR;
1000 if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1001 if ( k ) CompFree ( mem_op, k );
1002 return LDAP_DECODING_ERROR;
1004 k->value = result.value;
1006 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1007 if ( !k->comp_desc ) {
1008 if ( k ) CompFree ( mem_op, k );
1009 return LDAP_DECODING_ERROR;
1011 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1012 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1013 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1014 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1015 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1016 k->comp_desc->cd_extract_i = NULL;
1017 k->comp_desc->cd_type = ASN_BASIC;
1018 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1019 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1021 return LDAP_SUCCESS;
1025 * Component BER Decoder : NULL
1028 BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1030 return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER );
1034 BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1035 AsnLen *bytesDecoded, int mode )
1039 void* component_values;
1040 ComponentNull* k, **k2;
1043 k = (ComponentNull*) v;
1045 if ( mode & DEC_ALLOC_MODE_0 ) {
1046 k2 = (ComponentNull**) v;
1047 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
1048 if ( !*k2 ) return LDAP_DECODING_ERROR;
1052 if ( mode & CALL_TAG_DECODER ){
1053 mode = mode & CALL_CONTENT_DECODER;
1054 rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded );
1057 rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1060 if ( k ) CompFree ( mem_op, k );
1061 return LDAP_DECODING_ERROR;
1065 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1066 if ( !k->comp_desc ) {
1067 if ( k ) CompFree ( mem_op, k );
1068 return LDAP_DECODING_ERROR;
1070 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1071 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1072 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1073 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1074 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1075 k->comp_desc->cd_extract_i = NULL;
1076 k->comp_desc->cd_type = ASN_BASIC;
1077 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1078 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1079 return LDAP_SUCCESS;
1083 * Component BER Decoder : NumericString
1086 BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1087 return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1091 BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1095 void* component_values;
1096 ComponentNumericString* k, **k2;
1097 NumericString result;
1099 k = (ComponentNumericString*) v;
1101 if ( mode & DEC_ALLOC_MODE_0 ) {
1102 k2 = (ComponentNumericString**) v;
1103 *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) );
1104 if ( !*k2 ) return LDAP_DECODING_ERROR;
1108 if ( mode & CALL_TAG_DECODER ){
1109 mode = mode & CALL_CONTENT_DECODER;
1110 rc = BDecNumericString ( mem_op, b, &result, bytesDecoded );
1112 rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1115 if ( k ) CompFree ( mem_op, k );
1116 return LDAP_DECODING_ERROR;
1120 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1121 if ( !k->comp_desc ) {
1122 if ( k ) CompFree ( mem_op, k );
1123 return LDAP_DECODING_ERROR;
1125 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString;
1126 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString;
1127 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString;
1128 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1129 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1130 k->comp_desc->cd_extract_i = NULL;
1131 k->comp_desc->cd_type = ASN_BASIC;
1132 k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR;
1133 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNumericString;
1135 return LDAP_SUCCESS;
1140 * Free function : OCTET STRING
1143 FreeComponentOcts ( ComponentOcts* v) {
1144 FreeAsnOcts( &v->value );
1148 * Matching function : OCTET STRING
1151 MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr,
1152 ComponentSyntaxInfo* csi_assert )
1156 ComponentOcts *a, *b;
1159 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1161 return component_value_match( mr, csi_attr , csi_assert );
1163 a = (ComponentOcts*) csi_attr;
1164 b = (ComponentOcts*) csi_assert;
1165 /* Assume that both of OCTET string has end of string character */
1166 if ( (a->value.octetLen == b->value.octetLen) &&
1167 strncmp ( a->value.octs, b->value.octs, a->value.octetLen ) == 0 )
1168 return LDAP_COMPARE_TRUE;
1170 return LDAP_COMPARE_FALSE;
1174 * GSER Encoder : OCTET STRING
1177 GEncComponentOcts ( GenBuf* b, ComponentOcts *in )
1179 if ( !in || in->value.octetLen <= 0 )
1181 return GEncAsnOctsContent ( b, &in->value );
1185 * GSER Decoder : OCTET STRING
1188 GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1190 char *peek_head, *data;
1192 void* component_values;
1193 ComponentOcts* k, **k2;
1196 k = (ComponentOcts*) v;
1198 if ( mode & DEC_ALLOC_MODE_0 ) {
1199 k2 = (ComponentOcts**) v;
1200 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1201 if ( !*k2 ) return LDAP_DECODING_ERROR;
1205 if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1206 if ( k ) CompFree ( mem_op, k );
1207 return LDAP_DECODING_ERROR;
1209 k->value = result.value;
1211 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1212 if ( !k->comp_desc ) {
1213 if ( k ) CompFree ( mem_op, k );
1214 return LDAP_DECODING_ERROR;
1216 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1217 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1218 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1219 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1220 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1221 k->comp_desc->cd_extract_i = NULL;
1222 k->comp_desc->cd_type = ASN_BASIC;
1223 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1224 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1226 return LDAP_SUCCESS;
1230 * Component BER Decoder : OCTET STRING
1233 BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1234 return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1238 BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1239 AsnLen *bytesDecoded, int mode )
1241 char *peek_head, *data;
1243 void* component_values;
1244 ComponentOcts* k, **k2;
1247 k = (ComponentOcts*) v;
1249 if ( mode & DEC_ALLOC_MODE_0 ) {
1250 k2 = (ComponentOcts**) v;
1251 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1252 if ( !*k2 ) return LDAP_DECODING_ERROR;
1256 if ( mode & CALL_TAG_DECODER ){
1257 mode = mode & CALL_CONTENT_DECODER;
1258 rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded );
1260 rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1263 if ( k ) CompFree ( mem_op, k );
1264 return LDAP_DECODING_ERROR;
1268 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1269 if ( !k->comp_desc ) {
1270 if ( k ) CompFree ( mem_op, k );
1271 return LDAP_DECODING_ERROR;
1273 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1274 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1275 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1276 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1277 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1278 k->comp_desc->cd_extract_i = NULL;
1279 k->comp_desc->cd_type = ASN_BASIC;
1280 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1281 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1282 return LDAP_SUCCESS;
1286 * Matching function : OBJECT IDENTIFIER
1289 MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr ,
1290 ComponentSyntaxInfo *csi_assert )
1294 ComponentOid *a, *b;
1297 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1299 return component_value_match( mr, csi_attr , csi_assert );
1302 a = (ComponentOid*)csi_attr;
1303 b = (ComponentOid*)csi_assert;
1304 if ( a->value.octetLen != b->value.octetLen )
1305 return LDAP_COMPARE_FALSE;
1306 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1308 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1312 * GSER Encoder : OID
1314 GEncComponentOid ( GenBuf *b, ComponentOid *in )
1316 if ( !in || in->value.octetLen <= 0 ) return (-1);
1317 return GEncAsnOidContent( b, &in->value );
1321 * GSER Decoder : OID
1324 GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){
1325 AttributeType *ad_type;
1330 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY );
1331 name.bv_val = peek_head;
1332 name.bv_len = strLen;
1334 ad_type = at_bvfind( &name );
1337 return LDAP_DECODING_ERROR;
1339 peek_head = ad_type->sat_atype.at_oid;
1340 strLen = strlen ( peek_head );
1342 result->value.octs = EncodeComponentOid ( mem_op, peek_head , &strLen );
1343 result->value.octetLen = strLen;
1344 return LDAP_SUCCESS;
1348 IsNumericOid ( char* peek_head , int strLen ) {
1351 for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) {
1352 if ( peek_head[i] == '.' ) num_dot++;
1353 else if ( peek_head[i] > '9' || peek_head[i] < '0' )
1363 GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1367 void* component_values;
1368 ComponentOid* k, **k2;
1371 k = (ComponentOid*) v;
1373 if ( mode & DEC_ALLOC_MODE_0 ) {
1374 k2 = (ComponentOid**) v;
1375 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1376 if ( !*k2 ) return LDAP_DECODING_ERROR;
1380 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK );
1381 if ( IsNumericOid ( peek_head , strLen ) >= 1 ) {
1383 if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1384 if ( k ) CompFree ( mem_op, k );
1385 return LDAP_DECODING_ERROR;
1390 if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){
1391 if ( k ) CompFree ( mem_op, k );
1392 return LDAP_DECODING_ERROR;
1395 k->value = result.value;
1397 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1398 if ( !k->comp_desc ) {
1399 if ( k ) CompFree ( mem_op, k );
1400 return LDAP_DECODING_ERROR;
1402 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1403 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1404 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1405 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1406 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1407 k->comp_desc->cd_extract_i = NULL;
1408 k->comp_desc->cd_type = ASN_BASIC;
1409 k->comp_desc->cd_type_id = BASICTYPE_OID;
1410 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1412 return LDAP_SUCCESS;
1416 * Component BER Decoder : OID
1419 BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1420 return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1424 BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1425 AsnLen *bytesDecoded, int mode )
1429 void* component_values;
1430 ComponentOid* k, **k2;
1433 k = (ComponentOid*) v;
1435 if ( mode & DEC_ALLOC_MODE_0 ) {
1436 k2 = (ComponentOid**) v;
1437 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1438 if ( !*k2 ) return LDAP_DECODING_ERROR;
1442 if ( mode & CALL_TAG_DECODER ){
1443 mode = mode & CALL_CONTENT_DECODER;
1444 rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded );
1446 rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1449 if ( k ) CompFree ( mem_op, k );
1450 return LDAP_DECODING_ERROR;
1454 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1455 if ( !k->comp_desc ) {
1456 if ( k ) CompFree ( mem_op, k );
1457 return LDAP_DECODING_ERROR;
1459 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1460 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1461 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1462 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1463 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1464 k->comp_desc->cd_extract_i = NULL;
1465 k->comp_desc->cd_type = ASN_BASIC;
1466 k->comp_desc->cd_type_id = BASICTYPE_OID;
1467 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1468 return LDAP_SUCCESS;
1472 * Component BER Decoder : PrintiableString
1476 BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1478 return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1482 BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1486 void* component_values;
1487 ComponentPrintableString* k, **k2;
1490 k = (ComponentPrintableString*) v;
1492 if ( mode & DEC_ALLOC_MODE_0 ) {
1493 k2 = (ComponentPrintableString**) v;
1494 *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) );
1495 if ( !*k2 ) return LDAP_DECODING_ERROR;
1499 if ( mode & CALL_TAG_DECODER ) {
1500 mode = mode & CALL_CONTENT_DECODER;
1501 rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded );
1503 rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1506 if ( k ) CompFree ( mem_op, k );
1507 return LDAP_DECODING_ERROR;
1511 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1512 if ( !k->comp_desc ) {
1513 if ( k ) CompFree ( mem_op, k );
1514 return LDAP_DECODING_ERROR;
1516 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString;
1517 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString;
1518 k->comp_desc->cd_free = (comp_free_func*)FreeComponentPrintableString;
1519 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1520 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1521 k->comp_desc->cd_extract_i = NULL;
1522 k->comp_desc->cd_type = ASN_BASIC;
1523 k->comp_desc->cd_type_id = BASICTYPE_PRINTABLE_STR;
1524 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentPrintableString;
1525 return LDAP_SUCCESS;
1529 * Matching function : Real
1532 MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr,
1533 ComponentSyntaxInfo *csi_assert )
1537 ComponentReal *a, *b;
1540 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1542 return component_value_match( mr, csi_attr , csi_assert );
1544 a = (ComponentReal*)csi_attr;
1545 b = (ComponentReal*)csi_assert;
1546 rc = (a->value == b->value);
1548 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1552 * GSER Encoder : Real
1555 GEncComponentReal ( GenBuf *b, ComponentReal *in )
1559 return GEncAsnRealContent ( b, &in->value );
1563 * GSER Decoder : Real
1566 GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1570 void* component_values;
1571 ComponentReal* k, **k2;
1574 k = (ComponentReal*) v;
1576 if ( mode & DEC_ALLOC_MODE_0 ) {
1577 k2 = (ComponentReal**) v;
1578 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1579 if ( !*k2 ) return LDAP_DECODING_ERROR;
1583 if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1584 if ( k ) CompFree ( mem_op, k );
1585 return LDAP_DECODING_ERROR;
1587 k->value = result.value;
1589 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1590 if ( !k->comp_desc ) {
1591 if ( k ) CompFree ( mem_op, k );
1592 return LDAP_DECODING_ERROR;
1594 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1595 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1596 k->comp_desc->cd_free = (comp_free_func*)NULL;
1597 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1598 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1599 k->comp_desc->cd_extract_i = NULL;
1600 k->comp_desc->cd_type = ASN_BASIC;
1601 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1602 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1604 return LDAP_SUCCESS;
1608 * Component BER Decoder : Real
1611 BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1612 return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1616 BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1620 void* component_values;
1621 ComponentReal* k, **k2;
1624 k = (ComponentReal*) v;
1626 if ( mode & DEC_ALLOC_MODE_0 ) {
1627 k2 = (ComponentReal**) v;
1628 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1629 if ( !*k2 ) return LDAP_DECODING_ERROR;
1633 if ( mode & CALL_TAG_DECODER ){
1634 mode = mode & CALL_CONTENT_DECODER;
1635 rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded );
1637 rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1640 if ( k ) CompFree ( mem_op, k );
1641 return LDAP_DECODING_ERROR;
1645 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1646 if ( !k->comp_desc ) {
1647 if ( k ) CompFree ( mem_op, k );
1648 return LDAP_DECODING_ERROR;
1650 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1651 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1652 k->comp_desc->cd_free = (comp_free_func*)NULL;
1653 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1654 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1655 k->comp_desc->cd_extract_i = NULL;
1656 k->comp_desc->cd_type = ASN_BASIC;
1657 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1658 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1660 return LDAP_SUCCESS;
1664 * Matching function : Relative OID
1667 MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr,
1668 ComponentSyntaxInfo *csi_assert )
1672 ComponentRelativeOid *a, *b;
1675 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1677 return component_value_match( mr, csi_attr , csi_assert );
1680 a = (ComponentRelativeOid*)csi_attr;
1681 b = (ComponentRelativeOid*)csi_assert;
1683 if ( a->value.octetLen != b->value.octetLen )
1684 return LDAP_COMPARE_FALSE;
1685 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1687 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1691 * GSER Encoder : RELATIVE_OID.
1694 GEncComponentRelativeOid ( GenBuf *b, ComponentRelativeOid *in )
1696 if ( !in || in->value.octetLen <= 0 )
1698 return GEncAsnRelativeOidContent ( b , &in->value );
1702 * GSER Decoder : RELATIVE_OID.
1705 GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
1709 void* component_values;
1710 ComponentRelativeOid* k, **k2;
1711 GAsnRelativeOid result;
1713 k = (ComponentRelativeOid*) v;
1715 if ( mode & DEC_ALLOC_MODE_0 ) {
1716 k2 = (ComponentRelativeOid**) v;
1717 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1718 if ( !*k2 ) return LDAP_DECODING_ERROR;
1722 if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1723 if ( k ) CompFree ( mem_op, k );
1724 return LDAP_DECODING_ERROR;
1726 k->value = result.value;
1728 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1729 if ( !k->comp_desc ) {
1730 if ( k ) CompFree ( mem_op, k );
1731 return LDAP_DECODING_ERROR;
1733 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1734 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1735 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1736 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1737 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1738 k->comp_desc->cd_extract_i = NULL;
1739 k->comp_desc->cd_type = ASN_BASIC;
1740 k->comp_desc->cd_type_id = BASICTYPE_OID;
1741 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1743 return LDAP_SUCCESS;
1747 * Component BER Decoder : RELATIVE_OID.
1750 BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1751 return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1755 BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1759 void* component_values;
1760 ComponentRelativeOid* k, **k2;
1761 AsnRelativeOid result;
1763 k = (ComponentRelativeOid*) v;
1765 if ( mode & DEC_ALLOC_MODE_0 ) {
1766 k2 = (ComponentRelativeOid**) v;
1767 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1768 if ( !*k2 ) return LDAP_DECODING_ERROR;
1772 if ( mode & CALL_TAG_DECODER ){
1773 mode = mode & CALL_CONTENT_DECODER;
1774 rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded );
1776 rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1779 if ( k ) CompFree ( mem_op, k );
1780 return LDAP_DECODING_ERROR;
1784 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1785 if ( !k->comp_desc ) {
1786 if ( k ) CompFree ( mem_op, k );
1787 return LDAP_DECODING_ERROR;
1789 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1790 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1791 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1792 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1793 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1794 k->comp_desc->cd_extract_i = NULL;
1795 k->comp_desc->cd_type = ASN_BASIC;
1796 k->comp_desc->cd_type_id = BASICTYPE_RELATIVE_OID;
1797 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1798 return LDAP_SUCCESS;
1802 * GSER Encoder : UniversalString
1805 GEncComponentUniversalString ( GenBuf *b, ComponentUniversalString *in )
1807 if ( !in || in->value.octetLen <= 0 )
1809 return GEncUniversalStringContent( b, &in->value );
1813 * GSER Decoder : UniversalString
1816 UTF8toUniversalString( char* octs, int len){
1817 /* Need to be Implemented */
1818 return LDAP_SUCCESS;
1822 GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1824 if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 )
1825 UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen );
1826 return LDAP_DECODING_ERROR;
1830 * Component BER Decoder : UniverseString
1833 BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1834 return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1838 BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1842 void* component_values;
1843 ComponentUniversalString* k, **k2;
1844 UniversalString result;
1846 k = (ComponentUniversalString*) v;
1848 if ( mode & DEC_ALLOC_MODE_0 ) {
1849 k2 = (ComponentUniversalString**) v;
1850 *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) );
1851 if ( !*k2 ) return LDAP_DECODING_ERROR;
1855 if ( mode & CALL_TAG_DECODER ){
1856 mode = mode & CALL_CONTENT_DECODER;
1857 rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded );
1859 rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1862 if ( k ) CompFree ( mem_op, k );
1863 return LDAP_DECODING_ERROR;
1867 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1868 if ( !k->comp_desc ) {
1869 if ( k ) CompFree ( mem_op, k );
1870 return LDAP_DECODING_ERROR;
1872 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString;
1873 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString;
1874 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUniversalString;
1875 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1876 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1877 k->comp_desc->cd_extract_i = NULL;
1878 k->comp_desc->cd_type = ASN_BASIC;
1879 k->comp_desc->cd_type_id = BASICTYPE_UNIVERSAL_STR;
1880 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUniversalString;
1881 return LDAP_SUCCESS;
1885 * Component BER Decoder : VisibleString
1888 BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1889 return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1893 BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1897 void* component_values;
1898 ComponentVisibleString* k, **k2;
1899 VisibleString result;
1901 k = (ComponentVisibleString*) v;
1903 if ( mode & DEC_ALLOC_MODE_0 ) {
1904 k2 = (ComponentVisibleString**) v;
1905 *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) );
1906 if ( !*k2 ) return LDAP_DECODING_ERROR;
1910 if ( mode & CALL_TAG_DECODER ){
1911 mode = mode & CALL_CONTENT_DECODER;
1912 rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded );
1914 rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1918 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1919 if ( !k->comp_desc ) {
1920 if ( k ) CompFree ( mem_op, k );
1921 return LDAP_DECODING_ERROR;
1923 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentVisibleString;
1924 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString;
1925 k->comp_desc->cd_free = (comp_free_func*)FreeComponentVisibleString;
1926 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1927 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1928 k->comp_desc->cd_extract_i = NULL;
1929 k->comp_desc->cd_type = ASN_BASIC;
1930 k->comp_desc->cd_type_id = BASICTYPE_VISIBLE_STR;
1931 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentVisibleString;
1932 return LDAP_SUCCESS;
1936 * Routines for handling an ANY DEFINED Type
1939 SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) {
1943 /* use encoded oid as hash string */
1944 hash = MakeHash (id->value.octs, id->value.octetLen);
1945 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
1946 v->cai = (ComponentAnyInfo*) anyInfo;
1952 * If not found, the data considered as octet chunk
1953 * Yet-to-be-Implemented
1959 SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) {
1963 hash = MakeHash ((char*)&id, sizeof (id));
1964 if (CheckForAndReturnValue (anyIntHashTblG, hash, &anyInfo))
1965 v->cai = (ComponentAnyInfo*) anyInfo;
1971 GEncComponentAny ( GenBuf *b, ComponentAny *in )
1973 if ( in->cai != NULL && in->cai->Encode != NULL )
1974 return in->cai->Encode(b, &in->value );
1979 BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
1980 ComponentAny *k, **k2;
1982 k = (ComponentAny*) result;
1984 if ( mode & DEC_ALLOC_MODE_0 ) {
1985 k2 = (ComponentAny**) result;
1986 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
1987 if ( !*k2 ) return LDAP_DECODING_ERROR;
1991 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
1992 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
1993 if ( !result->value ) return 0;
1994 result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
1996 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1997 if ( !k->comp_desc ) {
1998 if ( k ) CompFree ( mem_op, k );
1999 return LDAP_DECODING_ERROR;
2001 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2002 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2003 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2004 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
2005 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
2006 k->comp_desc->cd_extract_i = NULL;
2007 k->comp_desc->cd_type = ASN_BASIC;
2008 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2009 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2010 return LDAP_SUCCESS;
2013 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
2019 GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
2020 ComponentAny *k, **k2;
2022 k = (ComponentAny*) result;
2024 if ( mode & DEC_ALLOC_MODE_0 ) {
2025 k2 = (ComponentAny**) result;
2026 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2027 if ( !*k2 ) return LDAP_DECODING_ERROR;
2030 if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {
2031 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2032 if ( !result->value ) return 0;
2033 result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
2034 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2035 if ( !k->comp_desc ) {
2036 if ( k ) CompFree ( mem_op, k );
2037 return LDAP_DECODING_ERROR;
2039 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2040 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2041 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2042 k->comp_desc->cd_type = ASN_BASIC;
2043 k->comp_desc->cd_extract_i = NULL;
2044 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2045 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2046 return LDAP_SUCCESS;
2049 Asn1Error ("ERROR - ANY Decode routine is NULL\n");
2055 MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) {
2056 void *comp1, *comp2;
2058 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2059 comp1 = result->value;
2063 if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2064 comp2 = result2->value;
2068 if ((result->cai != NULL) && (result->cai->Match != NULL)) {
2069 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2070 return result->cai->Match(oid, comp1, comp2 );
2071 else if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2072 return result2->cai->Match(oid, comp1, comp2);
2074 return LDAP_INVALID_SYNTAX;
2077 Asn1Error ("ERROR - ANY Matching routine is NULL\n");
2078 return LDAP_INVALID_SYNTAX;
2083 ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) {
2084 if ((result->cai != NULL) && (result->cai->Extract != NULL)) {
2085 return (void*) result->cai->Extract( mem_op, cr , result->value );
2088 Asn1Error ("ERROR - ANY Extracting routine is NULL\n");
2094 FreeComponentAny (ComponentAny* any) {
2095 if ( any->cai != NULL && any->cai->Free != NULL ) {
2096 any->cai->Free( any->value );
2097 free ( ((ComponentSyntaxInfo*)any->value)->csi_comp_desc );
2098 free ( any->value );
2101 Asn1Error ("ERROR - ANY Free routine is NULL\n");
2105 InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size,
2106 EncodeFcn encode, gser_decoder_func* G_decode,
2107 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2108 MatchFcn match, FreeFcn free,
2111 ComponentAnyInfo *a;
2114 a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo));
2117 a->oid.octetLen = 0;
2121 a->GSER_Decode = G_decode;
2122 a->BER_Decode = B_decode;
2124 a->Extract = extract;
2128 if (anyIntHashTblG == NULL)
2129 anyIntHashTblG = InitHash();
2131 h = MakeHash ((char*)&intId, sizeof (intId));
2133 if(anyIntHashTblG != NULL)
2134 Insert(anyIntHashTblG, a, h);
2138 InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size,
2139 EncodeFcn encode, gser_decoder_func* G_decode,
2140 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2141 MatchFcn match, FreeFcn free, PrintFcn print)
2143 ComponentAnyInfo *a;
2146 a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
2149 a->oid.octetLen = 0;
2152 a->GSER_Decode = G_decode;
2153 a->BER_Decode = B_decode;
2155 a->Extract = extract;
2159 h = MakeHash (oid->octs, oid->octetLen);
2161 if (anyOidHashTblG == NULL)
2162 anyOidHashTblG = InitHash();
2164 if(anyOidHashTblG != NULL)
2165 Insert(anyOidHashTblG, a, h);
2170 ber_decoder_func *decoder _AND_
2174 AsnLen elmtLen _AND_
2176 AsnLen *bytesDecoded _AND_
2178 tag = BDecTag ( b, bytesDecoded );
2179 elmtLen = BDecLen ( b, bytesDecoded );
2180 if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
2181 printf("Invliad Tag\n");
2185 return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
2189 * ASN.1 specification of a distinguished name
2190 * DistinguishedName ::= RDNSequence
2191 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
2192 * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue
2193 * AttributeTypeandValue ::= SEQUENCE {
2194 * type AttributeType
2195 * value AttributeValue
2197 * When dnMatch/rdnMatch is used in a component assertion value
2198 * the component in DistinguishedName/RelativeDistinguishedName
2199 * need to be converted to the LDAP encodings in RFC2253
2200 * in order to be matched against the assertion value
2201 * If allComponentMatch is used, the assertion value may be
2202 * decoded into the Internal Representation(Component Tree)
2203 * by the corresponding GSER or BER decoder
2204 * Following routine converts a component tree(DistinguishedName) into
2205 * LDAP encodings in RFC2253
2207 * IR : ComponentRDNSequence
2208 * GSER : { { type cn, value sang },{ type o, value ibm}, {type c, value us} }
2209 * LDAP Encodings : cn=sang,o=ibm,c=us
2213 increment_bv_mem ( struct berval* in ) {
2214 int new_size = in->bv_len + INCREMENT_SIZE;
2215 in->bv_val = realloc( in->bv_val, new_size );
2216 in->bv_len = new_size;
2220 ConvertBER2Desc( char* in, int size, struct berval* out, int* pos ) {
2223 unsigned int firstArcNum;
2224 unsigned int arcNum;
2225 int i, rc, start_pos = *pos;
2226 char buf[MAX_OID_LEN];
2228 struct berval bv_name;
2230 /*convert BER oid to desc*/
2231 for ( i = 0, arcNum = 0; (i < size) && (in[i] & 0x80 ); i++ )
2232 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2233 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2235 firstArcNum = (unsigned short)(arcNum/40);
2236 if ( firstArcNum > 2 )
2239 arcNum = arcNum - (firstArcNum * 40 );
2241 rc = intToAscii ( arcNum, buf );
2243 /*check if the buffer can store the first/second arc and two dots*/
2244 if ( out->bv_len < *pos + 2 + 1 + rc )
2245 increment_bv_mem ( out );
2247 if ( firstArcNum == 1)
2248 out->bv_val[*pos] = '1';
2250 out->bv_val[*pos] = '2';
2252 out->bv_val[*pos] = '.';
2255 memcpy( out->bv_val + *pos, buf, rc );
2257 out->bv_val[*pos] = '.';
2260 for ( ; i < size ; ) {
2261 for ( arcNum=0; (i < size) && (in[i] & 0x80) ; i++ )
2262 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2263 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2266 rc = intToAscii ( arcNum, buf );
2268 if ( out->bv_len < *pos + rc + 1 )
2269 increment_bv_mem ( out );
2271 memcpy( out->bv_val + *pos, buf, rc );
2273 out->bv_val[*pos] = '.';
2276 (*pos)--;/*remove the last '.'*/
2279 * lookup OID database to locate desc
2280 * then overwrite OID with desc in *out
2281 * If failed to look up desc, OID form is used
2283 bv_name.bv_val = out->bv_val + start_pos;
2284 bv_name.bv_len = *pos - start_pos;
2285 at = at_bvfind( &bv_name );
2287 return LDAP_SUCCESS;
2288 desc_size = at->sat_cname.bv_len;
2289 memcpy( out->bv_val + start_pos, at->sat_cname.bv_val, desc_size );
2290 *pos = start_pos + desc_size;
2291 return LDAP_SUCCESS;
2295 ConvertComponentAttributeTypeAndValue2RFC2253 ( irAttributeTypeAndValue* in, struct berval* out, int *pos ) {
2297 int value_size = ((ComponentUTF8String*)in->value.value)->value.octetLen;
2298 char* value_ptr = ((ComponentUTF8String*)in->value.value)->value.octs;
2300 rc = ConvertBER2Desc( in->type.value.octs, in->type.value.octetLen, out, pos );
2301 if ( rc != LDAP_SUCCESS ) return rc;
2302 if ( out->bv_len < *pos + 1/*for '='*/ )
2303 increment_bv_mem ( out );
2304 /*Between type and value, put '='*/
2305 out->bv_val[*pos] = '=';
2308 /*Assume it is string*/
2309 if ( out->bv_len < *pos + value_size )
2310 increment_bv_mem ( out );
2311 memcpy( out->bv_val + *pos, value_ptr, value_size );
2312 out->bv_len += value_size;
2315 return LDAP_SUCCESS;
2319 ConvertRelativeDistinguishedName2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out , int* pos) {
2320 irAttributeTypeAndValue* attr_typeNvalue;
2324 FOR_EACH_LIST_ELMT( attr_typeNvalue, &in->comp_list)
2326 rc = ConvertComponentAttributeTypeAndValue2RFC2253( attr_typeNvalue, out, pos );
2327 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2329 if ( out->bv_len < pos + 1/*for '+'*/ )
2330 increment_bv_mem ( out );
2331 /*between multivalued RDNs, put comma*/
2332 out->bv_val[*pos++] = '+';
2334 (*pos)--;/*remove the last '+'*/
2335 return LDAP_SUCCESS;
2339 ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out ) {
2341 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2342 out->bv_len = INITIAL_DN_SIZE;
2344 rc = ConvertRelativeDistinguishedName2RFC2253 ( in, out , &pos);
2345 if ( rc != LDAP_SUCCESS ) return rc;
2346 out->bv_val[pos] = '\0';
2348 return LDAP_SUCCESS;
2352 ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out ) {
2353 irRelativeDistinguishedName* rdn_seq;
2354 AsnList* seq = &in->comp_list;
2357 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2358 out->bv_len = INITIAL_DN_SIZE;
2360 FOR_EACH_LIST_ELMT( rdn_seq, seq )
2362 rc = ConvertRelativeDistinguishedName2RFC2253( rdn_seq, out, &pos );
2363 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2365 if ( out->bv_len < pos + 1/*for ','*/ )
2366 increment_bv_mem ( out );
2367 /*Between RDN, put comma*/
2368 out->bv_val[pos++] = ',';
2370 pos--;/*remove the last '+'*/
2371 out->bv_val[pos] = '\0';
2373 return LDAP_SUCCESS;