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>
19 #include "component.h"
21 #include "componentlib.h"
28 #ifndef SLAPD_COMP_MATCH
29 #define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC
32 #ifdef SLAPD_COMP_MATCH
34 * Matching function : BIT STRING
37 MatchingComponentBits ( char* oid, ComponentSyntaxInfo *csi_attr,
38 ComponentSyntaxInfo *csi_assert )
45 mr = retrieve_matching_rule(oid, (AsnTypeId)csi_attr->csi_comp_desc->cd_type_id );
47 return component_value_match( mr, csi_attr , csi_assert );
49 a = ((ComponentBits*)csi_attr);
50 b = ((ComponentBits*)csi_assert);
51 rc = ( a->value.bitLen == b->value.bitLen &&
52 strncmp( a->value.bits,b->value.bits,a->value.bitLen ) == 0 );
53 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
57 * Free function: BIT STRING
60 FreeComponentBits ( ComponentBits* v ) {
61 FreeAsnBits( &v->value );
65 * GSER Encoder : BIT STRING
68 GEncComponentBits ( GenBuf *b, ComponentBits *in )
72 bits.value = in->value;
75 return GEncAsnBitsContent ( b, &bits);
80 * GSER Decoder : BIT STRING
83 GDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
87 void* component_values;
88 ComponentBits* k, **k2;
91 k = (ComponentBits*) v;
93 if ( mode & DEC_ALLOC_MODE_0 ) {
94 k2 = (ComponentBits**) v;
95 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
96 if ( !*k2 ) return LDAP_DECODING_ERROR;
100 if ( GDecAsnBitsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
101 if ( k ) CompFree( mem_op, k );
102 return LDAP_DECODING_ERROR;
104 k->value = result.value;
105 k->comp_desc = get_component_description (BASICTYPE_BITSTRING);
111 * Component BER Decoder : BIT STRING
114 BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
115 return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
119 BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
120 AsnLen *bytesDecoded, int mode )
124 void* component_values;
125 ComponentBits* k, **k2;
128 k = (ComponentBits*) v;
130 if ( mode & DEC_ALLOC_MODE_0 ) {
131 k2 = (ComponentBits**) v;
132 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
133 if ( !*k2 ) return LDAP_DECODING_ERROR;
137 if ( mode & CALL_TAG_DECODER ){
138 mode = mode & CALL_CONTENT_DECODER;
139 rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );
141 rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
145 if ( k ) CompFree( mem_op, k );
146 return LDAP_DECODING_ERROR;
150 k->comp_desc = get_component_description (BASICTYPE_BITSTRING);
156 * Component GSER BMPString Encoder
159 GEncComponentBMPString ( GenBuf *b, ComponentBMPString *in )
163 if ( !in || in->value.octetLen <= 0 )
166 return GEncBMPStringContent ( b, &t );
170 * Component GSER BMPString Decoder
173 GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
177 void* component_values;
178 ComponentBMPString* k, **k2;
181 k = (ComponentBMPString*) v;
183 if ( mode & DEC_ALLOC_MODE_0 ) {
184 k2 = (ComponentBMPString**) v;
185 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
186 if ( !*k2 ) return LDAP_DECODING_ERROR;
192 if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
193 if ( k ) CompFree( mem_op, k );
194 return LDAP_DECODING_ERROR;
197 k->value = result.value;
198 k->comp_desc = get_component_description (BASICTYPE_BMP_STR);
205 * Component BER BMPString Decoder
208 BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
209 return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
213 BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
214 AsnLen *bytesDecoded, int mode )
218 void* component_values;
219 ComponentBMPString* k, **k2;
222 k = (ComponentBMPString*) v;
224 if ( mode & DEC_ALLOC_MODE_0 ) {
225 k2 = (ComponentBMPString**) v;
226 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
227 if ( !*k2 ) return LDAP_DECODING_ERROR;
231 if ( mode & CALL_TAG_DECODER ){
232 mode = mode & CALL_CONTENT_DECODER;
233 rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );
235 rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
239 if ( k ) CompFree( mem_op, k );
240 return LDAP_DECODING_ERROR;
244 k->comp_desc = get_component_description (BASICTYPE_BMP_STR);
251 * Component GSER Encoder : UTF8 String
254 GEncComponentUTF8String ( GenBuf *b, ComponentUTF8String *in )
257 if ( !in || in->value.octetLen <= 0 )
260 return GEncUTF8StringContent ( b, &t );
264 * Component GSER Decoder : UTF8 String
267 GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,
268 AsnLen *bytesDecoded, int mode) {
271 void* component_values;
272 ComponentUTF8String* k, **k2;
275 k = (ComponentUTF8String*) v;
277 if ( mode & DEC_ALLOC_MODE_0 ) {
278 k2 = (ComponentUTF8String**) v;
279 *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
280 if ( !*k2 ) return LDAP_DECODING_ERROR;
286 if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
287 if ( k ) CompFree( mem_op, k );
288 return LDAP_DECODING_ERROR;
291 k->value = result.value;
292 k->comp_desc = get_component_description (BASICTYPE_UTF8_STR);
298 * Component BER Decoder : UTF8String
301 BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
302 return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
306 BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len,
307 void *v, AsnLen *bytesDecoded, int mode )
311 void* component_values;
312 ComponentUTF8String* k, **k2;
315 k = (ComponentUTF8String*) v;
317 if ( mode & DEC_ALLOC_MODE_0 ) {
318 k2 = (ComponentUTF8String**) v;
319 *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
320 if ( !*k2 ) return LDAP_DECODING_ERROR;
324 if ( mode & CALL_TAG_DECODER ){
325 mode = mode & CALL_CONTENT_DECODER;
326 rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );
328 rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
331 if ( k ) CompFree( mem_op, k );
332 return LDAP_DECODING_ERROR;
336 k->comp_desc = get_component_description (BASICTYPE_UTF8_STR);
342 * Component GSER Encoder : Teletex String
345 GEncComponentTeletexString ( GenBuf *b, ComponentTeletexString *in )
347 GTeletexString t = {0};
349 if ( !in || in->value.octetLen <= 0 )
352 return GEncTeletexStringContent ( b, &t );
356 * Component GSER Decoder : Teletex String
359 GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v,
360 AsnLen *bytesDecoded, int mode) {
363 void* component_values;
364 ComponentTeletexString* k, **k2;
365 GTeletexString result;
367 k = (ComponentTeletexString*) v;
369 if ( mode & DEC_ALLOC_MODE_0 ) {
370 k2 = (ComponentTeletexString**) v;
371 *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
372 if ( !*k2 ) return LDAP_DECODING_ERROR;
378 if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
379 if ( k ) CompFree( mem_op, k );
380 return LDAP_DECODING_ERROR;
383 k->value = result.value;
384 k->comp_desc = get_component_description (BASICTYPE_VIDEOTEX_STR);
391 * Matching function : BOOLEAN
394 MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr,
395 ComponentSyntaxInfo* csi_assert )
398 ComponentBool *a, *b;
401 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
403 return component_value_match( mr, csi_attr , csi_assert );
406 a = ((ComponentBool*)csi_attr);
407 b = ((ComponentBool*)csi_assert);
409 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
413 * GSER Encoder : BOOLEAN
416 GEncComponentBool ( GenBuf *b, ComponentBool *in )
423 return GEncAsnBoolContent ( b, &t );
427 * GSER Decoder : BOOLEAN
430 GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
434 ComponentBool* k, **k2;
437 k = (ComponentBool*) v;
439 if ( mode & DEC_ALLOC_MODE_0 ) {
440 k2 = (ComponentBool**) v;
441 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
442 if ( !*k2 ) return LDAP_DECODING_ERROR;
446 if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) {
447 if ( k ) CompFree ( mem_op, k );
448 return LDAP_DECODING_ERROR;
451 k->value = result.value;
452 k->comp_desc = get_component_description (BASICTYPE_BOOLEAN);
458 * Component BER Decoder : BOOLEAN
461 BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
462 return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
466 BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
467 AsnLen *bytesDecoded, int mode )
471 ComponentBool* k, **k2;
474 k = (ComponentBool*) v;
476 if ( mode & DEC_ALLOC_MODE_0 ) {
477 k2 = (ComponentBool**) v;
478 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
479 if ( !*k2 ) return LDAP_DECODING_ERROR;
483 if ( mode & CALL_TAG_DECODER ){
484 mode = mode & CALL_CONTENT_DECODER;
485 rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded );
487 rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded );
490 if ( k ) CompFree ( mem_op, k );
491 return LDAP_DECODING_ERROR;
495 k->comp_desc = get_component_description (BASICTYPE_BOOLEAN);
501 * Matching function : ENUMERATE
504 MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr,
505 ComponentSyntaxInfo *csi_assert )
509 ComponentEnum *a, *b;
512 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
514 return component_value_match( mr, csi_attr , csi_assert );
516 a = ((ComponentEnum*)csi_attr);
517 b = ((ComponentEnum*)csi_assert);
518 rc = (a->value == b->value);
520 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
524 * GSER Encoder : ENUMERATE
527 GEncComponentEnum ( GenBuf *b, ComponentEnum *in )
534 return GEncAsnEnumContent ( b, &t );
538 * GSER Decoder : ENUMERATE
541 GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
545 void* component_values;
546 ComponentEnum* k, **k2;
549 k = (ComponentEnum*) v;
551 if ( mode & DEC_ALLOC_MODE_0 ) {
552 k2 = (ComponentEnum**) v;
553 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
554 if ( !*k2 ) return LDAP_DECODING_ERROR;
558 if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
559 if ( k ) CompFree ( mem_op, k );
560 return LDAP_DECODING_ERROR;
563 k->value_identifier.bv_val = result.value_identifier;
564 k->value_identifier.bv_len = result.len;
566 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
567 if ( !k->comp_desc ) {
568 if ( k ) CompFree ( mem_op, k );
569 return LDAP_DECODING_ERROR;
571 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
572 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
573 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
574 k->comp_desc->cd_free = (comp_free_func*)NULL;
575 k->comp_desc->cd_extract_i = NULL;
576 k->comp_desc->cd_type = ASN_BASIC;
577 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
578 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
584 * Component BER Decoder : ENUMERATE
587 BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
588 return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
592 BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
593 AsnLen *bytesDecoded, int mode )
597 void* component_values;
598 ComponentEnum* k, **k2;
601 k = (ComponentEnum*) v;
603 if ( mode & DEC_ALLOC_MODE_0 ) {
604 k2 = (ComponentEnum**) v;
605 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
606 if ( k ) return LDAP_DECODING_ERROR;
610 if ( mode & CALL_TAG_DECODER ){
611 mode = mode & CALL_CONTENT_DECODER;
612 rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded );
614 rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded );
617 if ( k ) CompFree ( mem_op, k );
618 return LDAP_DECODING_ERROR;
623 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
624 if ( !k->comp_desc ) {
625 if ( k ) CompFree ( mem_op, k );
626 return LDAP_DECODING_ERROR;
628 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
629 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
630 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
631 k->comp_desc->cd_free = (comp_free_func*)NULL;
632 k->comp_desc->cd_extract_i = NULL;
633 k->comp_desc->cd_type = ASN_BASIC;
634 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
635 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
641 * Component GSER Encoder : IA5String
644 GEncComponentIA5Stirng ( GenBuf *b, ComponentIA5String* in )
648 if ( !in || in->value.octetLen <= 0 ) return (-1);
649 return GEncIA5StringContent( b, &t );
653 * Component BER Decoder : IA5String
656 BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
657 return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
661 BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
662 AsnLen *bytesDecoded, int mode )
666 void* component_values;
667 ComponentIA5String* k, **k2;
670 k = (ComponentIA5String*) v;
672 if ( mode & DEC_ALLOC_MODE_0 ) {
673 k2 = (ComponentIA5String**) v;
674 *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) );
675 if ( !*k2 ) return LDAP_DECODING_ERROR;
679 if ( mode & CALL_TAG_DECODER ){
680 mode = mode & CALL_CONTENT_DECODER;
681 rc = BDecIA5String ( mem_op, b, &result, bytesDecoded );
683 rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
686 if ( k ) CompFree ( mem_op, k );
687 return LDAP_DECODING_ERROR;
692 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
693 if ( !k->comp_desc ) {
694 if ( k ) CompFree ( mem_op, k );
695 return LDAP_DECODING_ERROR;
697 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentIA5String;
698 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String;
699 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String;
700 k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String;
701 k->comp_desc->cd_extract_i = NULL;
702 k->comp_desc->cd_type = ASN_BASIC;
703 k->comp_desc->cd_type_id = BASICTYPE_IA5_STR;
704 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentIA5String;
710 * Matching function : INTEGER
713 MatchingComponentInt(char* oid, ComponentSyntaxInfo* csi_attr,
714 ComponentSyntaxInfo* csi_assert )
720 /* check if this ASN type's matching rule is overrided */
721 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
722 /* if existing function is overrided, call the overriding
725 return component_value_match( mr, csi_attr , csi_assert );
727 a = ((ComponentInt*)csi_attr);
728 b = ((ComponentInt*)csi_assert);
730 return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
734 * GSER Encoder : INTEGER
737 GEncComponentInt ( GenBuf *b, ComponentInt* in )
744 return GEncAsnIntContent ( b, &t );
748 * GSER Decoder : INTEGER
751 GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
755 void* component_values;
756 ComponentInt* k, **k2;
759 k = (ComponentInt*) v;
761 if ( mode & DEC_ALLOC_MODE_0 ) {
762 k2 = (ComponentInt**) v;
763 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
764 if ( !*k2 ) return LDAP_DECODING_ERROR;
768 if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
769 if ( k ) CompFree ( mem_op, k );
770 return LDAP_DECODING_ERROR;
772 k->value = result.value;
773 k->comp_desc = get_component_description (BASICTYPE_INTEGER );
779 * Component BER Decoder : INTEGER
782 BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
783 return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
787 BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
788 AsnLen *bytesDecoded, int mode )
792 void* component_values;
793 ComponentInt* k, **k2;
796 k = (ComponentInt*) v;
798 if ( mode & DEC_ALLOC_MODE_0 ) {
799 k2 = (ComponentInt**) v;
800 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
801 if ( !*k2 ) return LDAP_DECODING_ERROR;
805 if ( mode & CALL_TAG_DECODER ){
806 mode = mode & CALL_CONTENT_DECODER;
807 rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded );
809 rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded );
813 k->comp_desc = get_component_description (BASICTYPE_INTEGER );
819 * Matching function : NULL
822 MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr,
823 ComponentSyntaxInfo *csi_assert )
826 ComponentNull *a, *b;
829 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
831 return component_value_match( mr, csi_attr , csi_assert );
833 a = ((ComponentNull*)csi_attr);
834 b = ((ComponentNull*)csi_assert);
836 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
840 * GSER Encoder : NULL
843 GEncComponentNull ( GenBuf *b, ComponentNull *in )
850 return GEncAsnNullContent ( b, &t );
854 * GSER Decoder : NULL
857 GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
861 void* component_values;
862 ComponentNull* k, **k2;
865 k = (ComponentNull*) v;
867 if ( mode & DEC_ALLOC_MODE_0 ) {
868 k2 = (ComponentNull**) v;
869 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
870 if ( !*k2 ) return LDAP_DECODING_ERROR;
874 if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
875 if ( k ) CompFree ( mem_op, k );
876 return LDAP_DECODING_ERROR;
878 k->value = result.value;
880 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
881 if ( !k->comp_desc ) {
882 if ( k ) CompFree ( mem_op, k );
883 return LDAP_DECODING_ERROR;
885 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
886 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
887 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
888 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
889 k->comp_desc->cd_extract_i = NULL;
890 k->comp_desc->cd_type = ASN_BASIC;
891 k->comp_desc->cd_type_id = BASICTYPE_NULL;
892 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
898 * Component BER Decoder : NULL
901 BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
903 return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER );
907 BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
908 AsnLen *bytesDecoded, int mode )
912 void* component_values;
913 ComponentNull* k, **k2;
916 k = (ComponentNull*) v;
918 if ( mode & DEC_ALLOC_MODE_0 ) {
919 k2 = (ComponentNull**) v;
920 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
921 if ( !*k2 ) return LDAP_DECODING_ERROR;
925 if ( mode & CALL_TAG_DECODER ){
926 mode = mode & CALL_CONTENT_DECODER;
927 rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded );
930 rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded);
933 if ( k ) CompFree ( mem_op, k );
934 return LDAP_DECODING_ERROR;
938 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
939 if ( !k->comp_desc ) {
940 if ( k ) CompFree ( mem_op, k );
941 return LDAP_DECODING_ERROR;
943 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
944 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
945 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
946 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
947 k->comp_desc->cd_extract_i = NULL;
948 k->comp_desc->cd_type = ASN_BASIC;
949 k->comp_desc->cd_type_id = BASICTYPE_NULL;
950 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
955 * Component BER Decoder : NumericString
958 BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
959 return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
963 BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
967 void* component_values;
968 ComponentNumericString* k, **k2;
969 NumericString result;
971 k = (ComponentNumericString*) v;
973 if ( mode & DEC_ALLOC_MODE_0 ) {
974 k2 = (ComponentNumericString**) v;
975 *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) );
976 if ( !*k2 ) return LDAP_DECODING_ERROR;
980 if ( mode & CALL_TAG_DECODER ){
981 mode = mode & CALL_CONTENT_DECODER;
982 rc = BDecNumericString ( mem_op, b, &result, bytesDecoded );
984 rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded);
987 if ( k ) CompFree ( mem_op, k );
988 return LDAP_DECODING_ERROR;
992 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
993 if ( !k->comp_desc ) {
994 if ( k ) CompFree ( mem_op, k );
995 return LDAP_DECODING_ERROR;
997 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNumericString;
998 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString;
999 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString;
1000 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString;
1001 k->comp_desc->cd_extract_i = NULL;
1002 k->comp_desc->cd_type = ASN_BASIC;
1003 k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR;
1004 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNumericString;
1006 return LDAP_SUCCESS;
1011 * Free function : OCTET STRING
1014 FreeComponentOcts ( ComponentOcts* v) {
1015 FreeAsnOcts( &v->value );
1019 * Matching function : OCTET STRING
1022 MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr,
1023 ComponentSyntaxInfo* csi_assert )
1027 ComponentOcts *a, *b;
1030 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1032 return component_value_match( mr, csi_attr , csi_assert );
1034 a = (ComponentOcts*) csi_attr;
1035 b = (ComponentOcts*) csi_assert;
1036 /* Assume that both of OCTET string has end of string character */
1037 if ( (a->value.octetLen == b->value.octetLen) &&
1038 strncmp ( a->value.octs, b->value.octs, a->value.octetLen ) == 0 )
1039 return LDAP_COMPARE_TRUE;
1041 return LDAP_COMPARE_FALSE;
1045 * GSER Encoder : OCTET STRING
1048 GEncComponentOcts ( GenBuf* b, ComponentOcts *in )
1051 if ( !in || in->value.octetLen <= 0 )
1054 t.value = in->value;
1055 return GEncAsnOctsContent ( b, &t );
1059 * GSER Decoder : OCTET STRING
1062 GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1064 char *peek_head, *data;
1066 void* component_values;
1067 ComponentOcts* k, **k2;
1070 k = (ComponentOcts*) v;
1072 if ( mode & DEC_ALLOC_MODE_0 ) {
1073 k2 = (ComponentOcts**) v;
1074 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1075 if ( !*k2 ) return LDAP_DECODING_ERROR;
1079 if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1080 if ( k ) CompFree ( mem_op, k );
1081 return LDAP_DECODING_ERROR;
1083 k->value = result.value;
1085 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1086 if ( !k->comp_desc ) {
1087 if ( k ) CompFree ( mem_op, k );
1088 return LDAP_DECODING_ERROR;
1090 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
1091 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1092 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1093 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1094 k->comp_desc->cd_extract_i = NULL;
1095 k->comp_desc->cd_type = ASN_BASIC;
1096 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1097 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1099 return LDAP_SUCCESS;
1103 * Component BER Decoder : OCTET STRING
1106 BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1107 return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1111 BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1112 AsnLen *bytesDecoded, int mode )
1114 char *peek_head, *data;
1116 void* component_values;
1117 ComponentOcts* k, **k2;
1120 k = (ComponentOcts*) v;
1122 if ( mode & DEC_ALLOC_MODE_0 ) {
1123 k2 = (ComponentOcts**) v;
1124 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1125 if ( !*k2 ) return LDAP_DECODING_ERROR;
1129 if ( mode & CALL_TAG_DECODER ){
1130 mode = mode & CALL_CONTENT_DECODER;
1131 rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded );
1133 rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1136 if ( k ) CompFree ( mem_op, k );
1137 return LDAP_DECODING_ERROR;
1141 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1142 if ( !k->comp_desc ) {
1143 if ( k ) CompFree ( mem_op, k );
1144 return LDAP_DECODING_ERROR;
1146 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
1147 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1148 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1149 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1150 k->comp_desc->cd_extract_i = NULL;
1151 k->comp_desc->cd_type = ASN_BASIC;
1152 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1153 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1154 return LDAP_SUCCESS;
1158 * Matching function : OBJECT IDENTIFIER
1161 MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr ,
1162 ComponentSyntaxInfo *csi_assert )
1166 ComponentOid *a, *b;
1169 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1171 return component_value_match( mr, csi_attr , csi_assert );
1174 a = (ComponentOid*)csi_attr;
1175 b = (ComponentOid*)csi_assert;
1176 if ( a->value.octetLen != b->value.octetLen )
1177 return LDAP_COMPARE_FALSE;
1178 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1180 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1184 * GSER Encoder : OID
1186 GEncComponentOid ( GenBuf *b, ComponentOid *in )
1190 if ( !in || in->value.octetLen <= 0 )
1192 t.value = in->value;
1193 return GEncAsnOidContent( b, (GAsnOcts*)&t );
1197 * GSER Decoder : OID
1200 GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){
1201 AttributeType *ad_type;
1206 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY );
1207 name.bv_val = peek_head;
1208 name.bv_len = strLen;
1210 ad_type = at_bvfind( &name );
1213 return LDAP_DECODING_ERROR;
1215 peek_head = ad_type->sat_atype.at_oid;
1216 strLen = strlen ( peek_head );
1218 result->value.octs = (char*)EncodeComponentOid ( mem_op, peek_head , &strLen );
1219 result->value.octetLen = strLen;
1220 return LDAP_SUCCESS;
1224 IsNumericOid ( char* peek_head , int strLen ) {
1227 for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) {
1228 if ( peek_head[i] == '.' ) num_dot++;
1229 else if ( peek_head[i] > '9' || peek_head[i] < '0' )
1239 GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1243 void* component_values;
1244 ComponentOid* k, **k2;
1247 k = (ComponentOid*) v;
1249 if ( mode & DEC_ALLOC_MODE_0 ) {
1250 k2 = (ComponentOid**) v;
1251 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1252 if ( !*k2 ) return LDAP_DECODING_ERROR;
1256 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK );
1257 if ( IsNumericOid ( peek_head , strLen ) >= 1 ) {
1259 if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1260 if ( k ) CompFree ( mem_op, k );
1261 return LDAP_DECODING_ERROR;
1266 if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){
1267 if ( k ) CompFree ( mem_op, k );
1268 return LDAP_DECODING_ERROR;
1271 k->value = result.value;
1272 k->comp_desc = get_component_description (BASICTYPE_OID);
1274 return LDAP_SUCCESS;
1278 * Component BER Decoder : OID
1281 BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1282 return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1286 BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1287 AsnLen *bytesDecoded, int mode )
1291 void* component_values;
1292 ComponentOid* k, **k2;
1295 k = (ComponentOid*) v;
1297 if ( mode & DEC_ALLOC_MODE_0 ) {
1298 k2 = (ComponentOid**) v;
1299 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1300 if ( !*k2 ) return LDAP_DECODING_ERROR;
1304 if ( mode & CALL_TAG_DECODER ){
1305 mode = mode & CALL_CONTENT_DECODER;
1306 rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded );
1308 rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1311 if ( k ) CompFree ( mem_op, k );
1312 return LDAP_DECODING_ERROR;
1316 k->comp_desc = get_component_description (BASICTYPE_OID);
1318 return LDAP_SUCCESS;
1322 * Component BER Decoder : PrintiableString
1326 BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1328 return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1332 BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1336 void* component_values;
1337 ComponentPrintableString* k, **k2;
1340 k = (ComponentPrintableString*) v;
1342 if ( mode & DEC_ALLOC_MODE_0 ) {
1343 k2 = (ComponentPrintableString**) v;
1344 *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) );
1345 if ( !*k2 ) return LDAP_DECODING_ERROR;
1349 if ( mode & CALL_TAG_DECODER ) {
1350 mode = mode & CALL_CONTENT_DECODER;
1351 rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded );
1353 rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1356 if ( k ) CompFree ( mem_op, k );
1357 return LDAP_DECODING_ERROR;
1361 k->comp_desc = get_component_description (BASICTYPE_PRINTABLE_STR);
1363 return LDAP_SUCCESS;
1367 * Component BER Decoder : TeletexString
1371 BDecComponentTeletexStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1373 return BDecComponentTeletexString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1377 BDecComponentTeletexString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1381 void* component_values;
1382 ComponentTeletexString* k, **k2;
1385 k = (ComponentTeletexString*) v;
1387 if ( mode & DEC_ALLOC_MODE_0 ) {
1388 k2 = (ComponentTeletexString**) v;
1389 *k2 = (ComponentTeletexString*) CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
1390 if ( !*k2 ) return LDAP_DECODING_ERROR;
1394 if ( mode & CALL_TAG_DECODER ) {
1395 mode = mode & CALL_CONTENT_DECODER;
1396 rc = BDecTeletexString ( mem_op, b, &result, bytesDecoded );
1398 rc = BDecTeletexStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1401 if ( k ) CompFree ( mem_op, k );
1402 return LDAP_DECODING_ERROR;
1406 k->comp_desc = get_component_description (BASICTYPE_T61_STR);
1408 return LDAP_SUCCESS;
1413 * Matching function : Real
1416 MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr,
1417 ComponentSyntaxInfo *csi_assert )
1421 ComponentReal *a, *b;
1424 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1426 return component_value_match( mr, csi_attr , csi_assert );
1428 a = (ComponentReal*)csi_attr;
1429 b = (ComponentReal*)csi_assert;
1430 rc = (a->value == b->value);
1432 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1436 * GSER Encoder : Real
1439 GEncComponentReal ( GenBuf *b, ComponentReal *in )
1444 t.value = in->value;
1445 return GEncAsnRealContent ( b, &t );
1449 * GSER Decoder : Real
1452 GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1456 void* component_values;
1457 ComponentReal* k, **k2;
1460 k = (ComponentReal*) v;
1462 if ( mode & DEC_ALLOC_MODE_0 ) {
1463 k2 = (ComponentReal**) v;
1464 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1465 if ( !*k2 ) return LDAP_DECODING_ERROR;
1469 if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1470 if ( k ) CompFree ( mem_op, k );
1471 return LDAP_DECODING_ERROR;
1473 k->value = result.value;
1474 k->comp_desc = get_component_description (BASICTYPE_REAL);
1476 return LDAP_SUCCESS;
1480 * Component BER Decoder : Real
1483 BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1484 return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1488 BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1492 void* component_values;
1493 ComponentReal* k, **k2;
1496 k = (ComponentReal*) v;
1498 if ( mode & DEC_ALLOC_MODE_0 ) {
1499 k2 = (ComponentReal**) v;
1500 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1501 if ( !*k2 ) return LDAP_DECODING_ERROR;
1505 if ( mode & CALL_TAG_DECODER ){
1506 mode = mode & CALL_CONTENT_DECODER;
1507 rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded );
1509 rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1512 if ( k ) CompFree ( mem_op, k );
1513 return LDAP_DECODING_ERROR;
1516 k->comp_desc = get_component_description (BASICTYPE_REAL);
1518 return LDAP_SUCCESS;
1522 * Matching function : Relative OID
1525 MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr,
1526 ComponentSyntaxInfo *csi_assert )
1530 ComponentRelativeOid *a, *b;
1533 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1535 return component_value_match( mr, csi_attr , csi_assert );
1538 a = (ComponentRelativeOid*)csi_attr;
1539 b = (ComponentRelativeOid*)csi_assert;
1541 if ( a->value.octetLen != b->value.octetLen )
1542 return LDAP_COMPARE_FALSE;
1543 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1545 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1549 * GSER Encoder : RELATIVE_OID.
1552 GEncComponentRelativeOid ( GenBuf *b, ComponentRelativeOid *in )
1554 GAsnRelativeOid t = {0};
1556 if ( !in || in->value.octetLen <= 0 )
1558 t.value = in->value;
1559 return GEncAsnRelativeOidContent ( b , (GAsnOcts*)&t );
1563 * GSER Decoder : RELATIVE_OID.
1566 GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
1570 void* component_values;
1571 ComponentRelativeOid* k, **k2;
1572 GAsnRelativeOid result;
1574 k = (ComponentRelativeOid*) v;
1576 if ( mode & DEC_ALLOC_MODE_0 ) {
1577 k2 = (ComponentRelativeOid**) v;
1578 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1579 if ( !*k2 ) return LDAP_DECODING_ERROR;
1583 if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1584 if ( k ) CompFree ( mem_op, k );
1585 return LDAP_DECODING_ERROR;
1587 k->value = result.value;
1588 k->comp_desc = get_component_description (BASICTYPE_OID);
1590 return LDAP_SUCCESS;
1594 * Component BER Decoder : RELATIVE_OID.
1597 BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1598 return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1602 BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1606 void* component_values;
1607 ComponentRelativeOid* k, **k2;
1608 AsnRelativeOid result;
1610 k = (ComponentRelativeOid*) v;
1612 if ( mode & DEC_ALLOC_MODE_0 ) {
1613 k2 = (ComponentRelativeOid**) v;
1614 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1615 if ( !*k2 ) return LDAP_DECODING_ERROR;
1619 if ( mode & CALL_TAG_DECODER ){
1620 mode = mode & CALL_CONTENT_DECODER;
1621 rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded );
1623 rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1626 if ( k ) CompFree ( mem_op, k );
1627 return LDAP_DECODING_ERROR;
1630 k->comp_desc = get_component_description (BASICTYPE_OID);
1632 return LDAP_SUCCESS;
1636 * GSER Encoder : UniversalString
1639 GEncComponentUniversalString ( GenBuf *b, ComponentUniversalString *in )
1641 GUniversalString t = {0};
1642 if ( !in || in->value.octetLen <= 0 )
1644 t.value = in->value;
1645 return GEncUniversalStringContent( b, &t );
1649 * GSER Decoder : UniversalString
1652 UTF8toUniversalString( char* octs, int len){
1653 /* Need to be Implemented */
1654 return LDAP_SUCCESS;
1658 GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1660 if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 )
1661 UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen );
1662 return LDAP_DECODING_ERROR;
1666 * Component BER Decoder : UniverseString
1669 BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1670 return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1674 BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1678 void* component_values;
1679 ComponentUniversalString* k, **k2;
1680 UniversalString result;
1682 k = (ComponentUniversalString*) v;
1684 if ( mode & DEC_ALLOC_MODE_0 ) {
1685 k2 = (ComponentUniversalString**) v;
1686 *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) );
1687 if ( !*k2 ) return LDAP_DECODING_ERROR;
1691 if ( mode & CALL_TAG_DECODER ){
1692 mode = mode & CALL_CONTENT_DECODER;
1693 rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded );
1695 rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1698 if ( k ) CompFree ( mem_op, k );
1699 return LDAP_DECODING_ERROR;
1702 k->comp_desc = get_component_description (BASICTYPE_UNIVERSAL_STR);
1704 return LDAP_SUCCESS;
1708 * Component BER Decoder : VisibleString
1711 BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1712 return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1716 BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1720 void* component_values;
1721 ComponentVisibleString* k, **k2;
1722 VisibleString result;
1724 k = (ComponentVisibleString*) v;
1726 if ( mode & DEC_ALLOC_MODE_0 ) {
1727 k2 = (ComponentVisibleString**) v;
1728 *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) );
1729 if ( !*k2 ) return LDAP_DECODING_ERROR;
1733 if ( mode & CALL_TAG_DECODER ){
1734 mode = mode & CALL_CONTENT_DECODER;
1735 rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded );
1737 rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1740 k->comp_desc = get_component_description (BASICTYPE_VISIBLE_STR);
1742 return LDAP_SUCCESS;
1746 * Routines for handling an ANY DEFINED Type
1749 /* Check if the <select> type CR and the OID of the given ANY type */
1751 CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo* cai, struct berval* select ) {
1753 AttributeType* ad_type;
1757 if ( IsNumericOid ( select->bv_val , select->bv_len ) ) {
1758 oid = select->bv_val;
1759 strLen = select->bv_len;
1761 ad_type = at_bvfind( select );
1764 return LDAP_DECODING_ERROR;
1766 oid = ad_type->sat_atype.at_oid;
1767 strLen = strlen ( oid );
1769 result = EncodeComponentOid ( mem_op, oid , &strLen );
1770 if ( !result || strLen <= 0 ) return (-1);
1772 if ( cai->oid.octetLen == strLen &&
1773 strncmp ( cai->oid.octs, result, strLen ) == 0 )
1780 SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) {
1784 /* use encoded oid as hash string */
1785 hash = MakeHash (id->value.octs, id->value.octetLen);
1786 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
1787 v->cai = (ComponentAnyInfo*) anyInfo;
1793 * If not found, the data considered as octet chunk
1794 * Yet-to-be-Implemented
1797 return LDAP_SUCCESS;
1801 SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) {
1805 hash = MakeHash ((char*)&id, sizeof (id));
1806 if (CheckForAndReturnValue (anyIntHashTblG, hash, &anyInfo))
1807 v->cai = (ComponentAnyInfo*) anyInfo;
1813 GEncComponentAny ( GenBuf *b, ComponentAny *in )
1815 if ( in->cai != NULL && in->cai->Encode != NULL )
1816 return in->cai->Encode(b, &in->value );
1822 BEncComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode)
1824 ComponentAny *k, **k2;
1826 k = (ComponentAny*) result;
1828 if ( !k ) return (-1);
1830 if ( mode & DEC_ALLOC_MODE_0 ) {
1831 k2 = (ComponentAny**) result;
1832 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
1833 if ( !*k2 ) return LDAP_DECODING_ERROR;
1837 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
1838 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
1839 if ( !result->value ) return 0;
1840 result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
1842 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1843 if ( !k->comp_desc ) {
1844 if ( k ) CompFree ( mem_op, k );
1845 return LDAP_DECODING_ERROR;
1847 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
1848 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
1849 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
1850 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
1851 k->comp_desc->cd_extract_i = NULL;
1852 k->comp_desc->cd_type = ASN_BASIC;
1853 k->comp_desc->cd_type_id = BASICTYPE_ANY;
1854 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
1855 return LDAP_SUCCESS;
1858 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
1864 BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
1866 ComponentAny *k, **k2;
1868 k = (ComponentAny*) result;
1870 if ( !k ) return (-1);
1872 if ( mode & DEC_ALLOC_MODE_0 ) {
1873 k2 = (ComponentAny**) result;
1874 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
1875 if ( !*k2 ) return LDAP_DECODING_ERROR;
1879 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
1880 result->cai->BER_Decode ( mem_op, b, (ComponentSyntaxInfo*)&result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_0 );
1882 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1883 if ( !k->comp_desc ) {
1884 if ( k ) CompFree ( mem_op, k );
1885 return LDAP_DECODING_ERROR;
1887 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
1888 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
1889 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
1890 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
1891 k->comp_desc->cd_extract_i = NULL;
1892 k->comp_desc->cd_type = ASN_BASIC;
1893 k->comp_desc->cd_type_id = BASICTYPE_ANY;
1894 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
1895 return LDAP_SUCCESS;
1898 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
1904 GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
1905 ComponentAny *k, **k2;
1907 k = (ComponentAny*) result;
1909 if ( mode & DEC_ALLOC_MODE_0 ) {
1910 k2 = (ComponentAny**) result;
1911 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
1912 if ( !*k2 ) return LDAP_DECODING_ERROR;
1915 if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {
1916 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
1917 if ( !result->value ) return 0;
1918 result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
1919 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1920 if ( !k->comp_desc ) {
1921 if ( k ) CompFree ( mem_op, k );
1922 return LDAP_DECODING_ERROR;
1924 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
1925 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
1926 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
1927 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
1928 k->comp_desc->cd_type = ASN_BASIC;
1929 k->comp_desc->cd_extract_i = NULL;
1930 k->comp_desc->cd_type_id = BASICTYPE_ANY;
1931 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
1932 return LDAP_SUCCESS;
1935 Asn1Error ("ERROR - ANY Decode routine is NULL\n");
1941 MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) {
1942 void *comp1, *comp2;
1944 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
1945 comp1 = result->value;
1949 if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
1950 comp2 = result2->value;
1954 if ((result->cai != NULL) && (result->cai->Match != NULL)) {
1955 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
1956 return result->cai->Match(oid, comp1, comp2 );
1957 else if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
1958 return result2->cai->Match(oid, comp1, comp2);
1960 return LDAP_INVALID_SYNTAX;
1963 Asn1Error ("ERROR - ANY Matching routine is NULL\n");
1964 return LDAP_INVALID_SYNTAX;
1969 ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) {
1970 if ((result->cai != NULL) && (result->cai->Extract != NULL)) {
1971 return (void*) result->cai->Extract( mem_op, cr , result->value );
1974 Asn1Error ("ERROR - ANY Extracting routine is NULL\n");
1980 FreeComponentAny (ComponentAny* any) {
1981 if ( any->cai != NULL && any->cai->Free != NULL ) {
1982 any->cai->Free( any->value );
1983 free ( ((ComponentSyntaxInfo*)any->value)->csi_comp_desc );
1984 free ( any->value );
1987 Asn1Error ("ERROR - ANY Free routine is NULL\n");
1991 InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size,
1992 EncodeFcn encode, gser_decoder_func* G_decode,
1993 ber_tag_decoder_func* B_decode, ExtractFcn extract,
1994 MatchFcn match, FreeFcn free,
1997 ComponentAnyInfo *a;
2000 a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo));
2003 a->oid.octetLen = 0;
2007 a->GSER_Decode = G_decode;
2008 a->BER_Decode = B_decode;
2010 a->Extract = extract;
2014 if (anyIntHashTblG == NULL)
2015 anyIntHashTblG = InitHash();
2017 h = MakeHash ((char*)&intId, sizeof (intId));
2019 if(anyIntHashTblG != NULL)
2020 Insert(anyIntHashTblG, a, h);
2025 * OID and its corresponding decoder can be registerd with this func.
2026 * If contained types constrained by <select> are used,
2027 * their OID and decoder MUST be registered, otherwise it will return no entry.
2028 * An open type(ANY type) also need be registered.
2031 InstallOidDecoderMapping ( char* ch_oid, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match ) {
2036 strLen = strlen( ch_oid );
2037 if( strLen <= 0 ) return;
2038 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2039 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &strLen );
2040 oid.octetLen = strLen;
2041 if( strLen <= 0 ) return;
2044 InstallAnyByComponentOid ( 0, &oid, 0, encode, G_decode, B_decode,
2045 extract, match, NULL, NULL);
2046 comp_nibble_memory_free(mem_op);
2050 * Look up Oid-decoder mapping table by berval have either
2051 * oid or description
2054 RetrieveOidDecoderMappingbyBV( struct berval* in ) {
2055 if ( IsNumericOid ( in->bv_val, in->bv_len ) )
2056 return RetrieveOidDecoderMappingbyOid( in->bv_val, in->bv_len );
2058 return RetrieveOidDecoderMappingbyDesc( in->bv_val, in->bv_len );
2062 * Look up Oid-decoder mapping table by dotted OID
2065 RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len ) {
2072 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2073 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &oid_len);
2074 oid.octetLen = oid_len;
2075 if( oid_len <= 0 ) {
2076 comp_nibble_memory_free( mem_op );
2080 /* use encoded oid as hash string */
2081 hash = MakeHash ( oid.octs, oid.octetLen);
2082 comp_nibble_memory_free( mem_op );
2083 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2084 return (OidDecoderMapping*) anyInfo;
2086 return (OidDecoderMapping*) NULL;
2091 * Look up Oid-decoder mapping table by description
2094 RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len ) {
2098 AttributeType* ad_type;
2103 bv.bv_len = desc_len;
2104 ad_type = at_bvfind( &bv );
2106 oid.octs = ad_type->sat_atype.at_oid;
2107 oid.octetLen = strlen ( oid.octs );
2110 return (OidDecoderMapping*) NULL;
2112 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2114 oid.octs = EncodeComponentOid ( mem_op, oid.octs , (int*)&oid.octetLen );
2115 if( oid.octetLen <= 0 ) {
2116 comp_nibble_memory_free( mem_op );
2117 return (OidDecoderMapping*) NULL;
2120 /* use encoded oid as hash string */
2121 hash = MakeHash ( oid.octs, oid.octetLen);
2122 comp_nibble_memory_free( mem_op );
2123 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2124 return (OidDecoderMapping*) anyInfo;
2126 return (OidDecoderMapping*) NULL;
2130 InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size,
2131 EncodeFcn encode, gser_decoder_func* G_decode,
2132 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2133 MatchFcn match, FreeFcn free, PrintFcn print)
2135 ComponentAnyInfo *a;
2138 a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
2141 a->oid.octs = malloc( oid->octetLen );
2142 memcpy ( a->oid.octs, oid->octs, oid->octetLen );
2143 a->oid.octetLen = oid->octetLen;
2147 a->GSER_Decode = G_decode;
2148 a->BER_Decode = B_decode;
2150 a->Extract = extract;
2154 h = MakeHash (oid->octs, oid->octetLen);
2156 if (anyOidHashTblG == NULL)
2157 anyOidHashTblG = InitHash();
2159 if(anyOidHashTblG != NULL)
2160 Insert(anyOidHashTblG, a, h);
2165 ber_decoder_func *decoder _AND_
2169 AsnLen elmtLen _AND_
2171 AsnLen *bytesDecoded _AND_
2173 tag = BDecTag ( b, bytesDecoded );
2174 elmtLen = BDecLen ( b, bytesDecoded );
2175 if ( elmtLen <= 0 ) return (-1);
2176 if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
2180 return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
2184 * ASN.1 specification of a distinguished name
2185 * DistinguishedName ::= RDNSequence
2186 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
2187 * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue
2188 * AttributeTypeandValue ::= SEQUENCE {
2189 * type AttributeType
2190 * value AttributeValue
2192 * When dnMatch/rdnMatch is used in a component assertion value
2193 * the component in DistinguishedName/RelativeDistinguishedName
2194 * need to be converted to the LDAP encodings in RFC2253
2195 * in order to be matched against the assertion value
2196 * If allComponentMatch is used, the assertion value may be
2197 * decoded into the Internal Representation(Component Tree)
2198 * by the corresponding GSER or BER decoder
2199 * Following routine converts a component tree(DistinguishedName) into
2200 * LDAP encodings in RFC2253
2202 * IR : ComponentRDNSequence
2203 * GSER : { { type cn, value sang },{ type o, value ibm}, {type c, value us} }
2204 * LDAP Encodings : cn=sang,o=ibm,c=us
2207 increment_bv_mem_by_size ( struct berval* in, int size ) {
2208 int new_size = in->bv_len + size;
2209 in->bv_val = realloc( in->bv_val, new_size );
2210 in->bv_len = new_size;
2214 ConvertBER2Desc( char* in, int size, struct berval* out, int* pos ) {
2217 unsigned int firstArcNum;
2218 unsigned int arcNum;
2219 int i, rc, start_pos = *pos;
2220 char buf[MAX_OID_LEN];
2222 struct berval bv_name;
2224 /*convert BER oid to desc*/
2225 for ( i = 0, arcNum = 0; (i < size) && (in[i] & 0x80 ); i++ )
2226 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2227 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2229 firstArcNum = (unsigned short)(arcNum/40);
2230 if ( firstArcNum > 2 )
2233 arcNum = arcNum - (firstArcNum * 40 );
2235 rc = intToAscii ( arcNum, buf );
2237 /*check if the buffer can store the first/second arc and two dots*/
2238 if ( out->bv_len < *pos + 2 + 1 + rc )
2239 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2241 if ( firstArcNum == 1)
2242 out->bv_val[*pos] = '1';
2244 out->bv_val[*pos] = '2';
2246 out->bv_val[*pos] = '.';
2249 memcpy( out->bv_val + *pos, buf, rc );
2251 out->bv_val[*pos] = '.';
2254 for ( ; i < size ; ) {
2255 for ( arcNum=0; (i < size) && (in[i] & 0x80) ; i++ )
2256 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2257 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2260 rc = intToAscii ( arcNum, buf );
2262 if ( out->bv_len < *pos + rc + 1 )
2263 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2265 memcpy( out->bv_val + *pos, buf, rc );
2267 out->bv_val[*pos] = '.';
2270 (*pos)--;/*remove the last '.'*/
2273 * lookup OID database to locate desc
2274 * then overwrite OID with desc in *out
2275 * If failed to look up desc, OID form is used
2277 bv_name.bv_val = out->bv_val + start_pos;
2278 bv_name.bv_len = *pos - start_pos;
2279 at = at_bvfind( &bv_name );
2281 return LDAP_SUCCESS;
2282 desc_size = at->sat_cname.bv_len;
2283 memcpy( out->bv_val + start_pos, at->sat_cname.bv_val, desc_size );
2284 *pos = start_pos + desc_size;
2285 return LDAP_SUCCESS;
2289 ConvertComponentAttributeTypeAndValue2RFC2253 ( irAttributeTypeAndValue* in, struct berval* out, int *pos ) {
2291 int value_size = ((ComponentUTF8String*)in->value.value)->value.octetLen;
2292 char* value_ptr = ((ComponentUTF8String*)in->value.value)->value.octs;
2294 rc = ConvertBER2Desc( in->type.value.octs, in->type.value.octetLen, out, pos );
2295 if ( rc != LDAP_SUCCESS ) return rc;
2296 if ( out->bv_len < *pos + 1/*for '='*/ )
2297 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2298 /*Between type and value, put '='*/
2299 out->bv_val[*pos] = '=';
2302 /*Assume it is string*/
2303 if ( out->bv_len < *pos + value_size )
2304 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2305 memcpy( out->bv_val + *pos, value_ptr, value_size );
2306 out->bv_len += value_size;
2309 return LDAP_SUCCESS;
2313 ConvertRelativeDistinguishedName2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out , int* pos) {
2314 irAttributeTypeAndValue* attr_typeNvalue;
2318 FOR_EACH_LIST_ELMT( attr_typeNvalue, &in->comp_list)
2320 rc = ConvertComponentAttributeTypeAndValue2RFC2253( attr_typeNvalue, out, pos );
2321 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2323 if ( out->bv_len < *pos + 1/*for '+'*/ )
2324 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2325 /*between multivalued RDNs, put comma*/
2326 out->bv_val[(*pos)++] = '+';
2328 (*pos)--;/*remove the last '+'*/
2329 return LDAP_SUCCESS;
2333 ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out ) {
2335 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2336 out->bv_len = INITIAL_DN_SIZE;
2338 rc = ConvertRelativeDistinguishedName2RFC2253 ( in, out , &pos);
2339 if ( rc != LDAP_SUCCESS ) return rc;
2340 out->bv_val[pos] = '\0';
2342 return LDAP_SUCCESS;
2346 ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out ) {
2347 irRelativeDistinguishedName* rdn_seq;
2348 AsnList* seq = &in->comp_list;
2351 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2352 out->bv_len = INITIAL_DN_SIZE;
2354 FOR_EACH_LIST_ELMT( rdn_seq, seq )
2356 rc = ConvertRelativeDistinguishedName2RFC2253( rdn_seq, out, &pos );
2357 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2359 if ( out->bv_len < pos + 1/*for ','*/ )
2360 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2361 /*Between RDN, put comma*/
2362 out->bv_val[pos++] = ',';
2364 pos--;/*remove the last '+'*/
2365 out->bv_val[pos] = '\0';
2367 return LDAP_SUCCESS;