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 return GEncAsnBitsContent ( b, &in->value );
77 * GSER Decoder : BIT STRING
80 GDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
84 void* component_values;
85 ComponentBits* k, **k2;
88 k = (ComponentBits*) v;
90 if ( mode & DEC_ALLOC_MODE_0 ) {
91 k2 = (ComponentBits**) v;
92 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
93 if ( !*k2 ) return LDAP_DECODING_ERROR;
97 if ( GDecAsnBitsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
98 if ( k ) CompFree( mem_op, k );
99 return LDAP_DECODING_ERROR;
101 k->value = result.value;
103 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
104 if ( !k->comp_desc ) {
105 if ( k ) CompFree( mem_op, k );
106 return LDAP_DECODING_ERROR;
108 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
109 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
110 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
111 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
112 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
113 k->comp_desc->cd_extract_i = NULL;
114 k->comp_desc->cd_type = ASN_BASIC;
115 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
116 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
118 /* Real Decoding code need to be followed */
123 * Component BER Decoder : BIT STRING
126 BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
127 return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
131 BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
132 AsnLen *bytesDecoded, int mode )
136 void* component_values;
137 ComponentBits* k, **k2;
140 k = (ComponentBits*) v;
142 if ( mode & DEC_ALLOC_MODE_0 ) {
143 k2 = (ComponentBits**) v;
144 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
145 if ( !*k2 ) return LDAP_DECODING_ERROR;
149 if ( mode & CALL_TAG_DECODER ){
150 mode = mode & CALL_CONTENT_DECODER;
151 rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );
153 rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
157 if ( k ) CompFree( mem_op, k );
158 return LDAP_DECODING_ERROR;
163 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
164 if ( !k->comp_desc ) {
165 if ( k ) CompFree( mem_op, k );
166 return LDAP_DECODING_ERROR;
168 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
169 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
170 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
171 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
172 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
173 k->comp_desc->cd_extract_i = NULL;
174 k->comp_desc->cd_type = ASN_BASIC;
175 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
176 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
182 * Component GSER BMPString Encoder
185 GEncComponentBMPString ( GenBuf *b, ComponentBMPString *in )
187 if ( !in || in->value.octetLen <= 0 ) return (-1);
188 return GEncBMPStringContent ( b, &in->value );
192 * Component GSER BMPString Decoder
195 GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
199 void* component_values;
200 ComponentBMPString* k, **k2;
203 k = (ComponentBMPString*) v;
205 if ( mode & DEC_ALLOC_MODE_0 ) {
206 k2 = (ComponentBMPString**) v;
207 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
208 if ( !*k2 ) return LDAP_DECODING_ERROR;
214 if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
215 if ( k ) CompFree( mem_op, k );
216 return LDAP_DECODING_ERROR;
219 k->value = result.value;
221 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
222 if ( !k->comp_desc ) {
223 if ( k ) CompFree( mem_op, k );
224 return LDAP_DECODING_ERROR;
226 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
227 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
228 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
229 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
230 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
231 k->comp_desc->cd_extract_i = NULL;
232 k->comp_desc->cd_type = ASN_BASIC;
233 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
234 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
241 * Component BER BMPString Decoder
244 BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
245 return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
249 BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
250 AsnLen *bytesDecoded, int mode )
254 void* component_values;
255 ComponentBMPString* k, **k2;
258 k = (ComponentBMPString*) v;
260 if ( mode & DEC_ALLOC_MODE_0 ) {
261 k2 = (ComponentBMPString**) v;
262 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
263 if ( !*k2 ) return LDAP_DECODING_ERROR;
267 if ( mode & CALL_TAG_DECODER ){
268 mode = mode & CALL_CONTENT_DECODER;
269 rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );
271 rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
275 if ( k ) CompFree( mem_op, k );
276 return LDAP_DECODING_ERROR;
281 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
282 if ( !k->comp_desc ) {
283 if ( k ) CompFree ( mem_op, k );
284 return LDAP_DECODING_ERROR;
286 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
287 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
288 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
289 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
290 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
291 k->comp_desc->cd_extract_i = NULL;
292 k->comp_desc->cd_type = ASN_BASIC;
293 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
294 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
301 * Component GSER Encoder : UTF8 String
304 GEncComponentUTF8String ( GenBuf *b, ComponentUTF8String *in )
306 if ( !in || in->value.octetLen <= 0 )
308 return GEncUTF8StringContent ( b, &in->value );
312 * Component GSER Decoder : UTF8 String
315 GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,
316 AsnLen *bytesDecoded, int mode) {
319 void* component_values;
320 ComponentUTF8String* k, **k2;
323 k = (ComponentUTF8String*) v;
325 if ( mode & DEC_ALLOC_MODE_0 ) {
326 k2 = (ComponentUTF8String**) v;
327 *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
328 if ( !*k2 ) return LDAP_DECODING_ERROR;
334 if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
335 if ( k ) CompFree( mem_op, k );
336 return LDAP_DECODING_ERROR;
339 k->value = result.value;
341 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
342 if ( !k->comp_desc ) {
343 if ( k ) CompFree( mem_op, k );
344 return LDAP_DECODING_ERROR;
346 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
347 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
348 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
349 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
350 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
351 k->comp_desc->cd_extract_i = NULL;
352 k->comp_desc->cd_type = ASN_BASIC;
353 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
354 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
360 * Component BER Decoder : UTF8String
363 BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
364 return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
368 BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len,
369 void *v, AsnLen *bytesDecoded, int mode )
373 void* component_values;
374 ComponentUTF8String* k, **k2;
377 k = (ComponentUTF8String*) v;
379 if ( mode & DEC_ALLOC_MODE_0 ) {
380 k2 = (ComponentUTF8String**) v;
381 *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
382 if ( !*k2 ) return LDAP_DECODING_ERROR;
386 if ( mode & CALL_TAG_DECODER ){
387 mode = mode & CALL_CONTENT_DECODER;
388 rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );
390 rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
393 if ( k ) CompFree( mem_op, k );
394 return LDAP_DECODING_ERROR;
399 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
400 if ( !k->comp_desc ) {
401 if ( k ) CompFree ( mem_op, k );
402 return LDAP_DECODING_ERROR;
404 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
405 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
406 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
407 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
408 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
409 k->comp_desc->cd_extract_i = NULL;
410 k->comp_desc->cd_type = ASN_BASIC;
411 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
412 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
416 * Component GSER Encoder : Teletex String
419 GEncComponentTeletexString ( GenBuf *b, ComponentTeletexString *in )
421 if ( !in || in->value.octetLen <= 0 )
423 return GEncTeletexStringContent ( b, &in->value );
427 * Component GSER Decoder : Teletex String
430 GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v,
431 AsnLen *bytesDecoded, int mode) {
434 void* component_values;
435 ComponentTeletexString* k, **k2;
436 GTeletexString result;
438 k = (ComponentTeletexString*) v;
440 if ( mode & DEC_ALLOC_MODE_0 ) {
441 k2 = (ComponentTeletexString**) v;
442 *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
443 if ( !*k2 ) return LDAP_DECODING_ERROR;
449 if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
450 if ( k ) CompFree( mem_op, k );
451 return LDAP_DECODING_ERROR;
454 k->value = result.value;
456 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
457 if ( !k->comp_desc ) {
458 if ( k ) CompFree ( mem_op, k );
459 return LDAP_DECODING_ERROR;
461 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString;
462 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString;
463 k->comp_desc->cd_free = (comp_free_func*)FreeComponentTeletexString;
464 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
465 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
466 k->comp_desc->cd_extract_i = NULL;
467 k->comp_desc->cd_type = ASN_BASIC;
468 k->comp_desc->cd_type_id = BASICTYPE_VIDEOTEX_STR;
469 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTeletexString;
476 * Matching function : BOOLEAN
479 MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr,
480 ComponentSyntaxInfo* csi_assert )
483 ComponentBool *a, *b;
486 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
488 return component_value_match( mr, csi_attr , csi_assert );
491 a = ((ComponentBool*)csi_attr);
492 b = ((ComponentBool*)csi_assert);
494 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
498 * GSER Encoder : BOOLEAN
501 GEncComponentBool ( GenBuf *b, ComponentBool *in )
505 return GEncAsnBoolContent ( b, &in->value );
509 * GSER Decoder : BOOLEAN
512 GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
516 ComponentBool* k, **k2;
519 k = (ComponentBool*) v;
521 if ( mode & DEC_ALLOC_MODE_0 ) {
522 k2 = (ComponentBool**) v;
523 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
524 if ( !*k2 ) return LDAP_DECODING_ERROR;
528 if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) {
529 if ( k ) CompFree ( mem_op, k );
530 return LDAP_DECODING_ERROR;
533 k->value = result.value;
535 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
536 if ( !k->comp_desc ) {
537 if ( k ) CompFree ( mem_op, k );
538 return LDAP_DECODING_ERROR;
540 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
541 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
542 k->comp_desc->cd_free = (comp_free_func*)NULL;
543 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
544 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
545 k->comp_desc->cd_extract_i = NULL;
546 k->comp_desc->cd_type = ASN_BASIC;
547 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
548 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
554 * Component BER Decoder : BOOLEAN
557 BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
558 return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
562 BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
563 AsnLen *bytesDecoded, int mode )
567 ComponentBool* k, **k2;
570 k = (ComponentBool*) v;
572 if ( mode & DEC_ALLOC_MODE_0 ) {
573 k2 = (ComponentBool**) v;
574 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
575 if ( !*k2 ) return LDAP_DECODING_ERROR;
579 if ( mode & CALL_TAG_DECODER ){
580 mode = mode & CALL_CONTENT_DECODER;
581 rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded );
583 rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded );
586 if ( k ) CompFree ( mem_op, k );
587 return LDAP_DECODING_ERROR;
592 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
593 if ( !k->comp_desc ) {
594 if ( k ) CompFree ( mem_op, k );
595 return LDAP_DECODING_ERROR;
597 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
598 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
599 k->comp_desc->cd_free = (comp_free_func*)NULL;
600 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
601 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
602 k->comp_desc->cd_extract_i = NULL;
603 k->comp_desc->cd_type = ASN_BASIC;
604 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
605 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
611 * Matching function : ENUMERATE
614 MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr,
615 ComponentSyntaxInfo *csi_assert )
619 ComponentEnum *a, *b;
622 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
624 return component_value_match( mr, csi_attr , csi_assert );
626 a = ((ComponentEnum*)csi_attr);
627 b = ((ComponentEnum*)csi_assert);
628 rc = (a->value == b->value);
630 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
634 * GSER Encoder : ENUMERATE
637 GEncComponentEnum ( GenBuf *b, ComponentEnum *in )
641 return GEncAsnEnumContent ( b, &in->value );
645 * GSER Decoder : ENUMERATE
648 GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
652 void* component_values;
653 ComponentEnum* k, **k2;
656 k = (ComponentEnum*) v;
658 if ( mode & DEC_ALLOC_MODE_0 ) {
659 k2 = (ComponentEnum**) v;
660 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
661 if ( !*k2 ) return LDAP_DECODING_ERROR;
665 if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
666 if ( k ) CompFree ( mem_op, k );
667 return LDAP_DECODING_ERROR;
670 k->value_identifier.bv_val = result.value_identifier;
671 k->value_identifier.bv_len = result.len;
673 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
674 if ( !k->comp_desc ) {
675 if ( k ) CompFree ( mem_op, k );
676 return LDAP_DECODING_ERROR;
678 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
679 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
680 k->comp_desc->cd_free = (comp_free_func*)NULL;
681 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
682 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
683 k->comp_desc->cd_extract_i = NULL;
684 k->comp_desc->cd_type = ASN_BASIC;
685 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
686 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
692 * Component BER Decoder : ENUMERATE
695 BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
696 return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
700 BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
701 AsnLen *bytesDecoded, int mode )
705 void* component_values;
706 ComponentEnum* k, **k2;
709 k = (ComponentEnum*) v;
711 if ( mode & DEC_ALLOC_MODE_0 ) {
712 k2 = (ComponentEnum**) v;
713 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
714 if ( k ) return LDAP_DECODING_ERROR;
718 if ( mode & CALL_TAG_DECODER ){
719 mode = mode & CALL_CONTENT_DECODER;
720 rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded );
722 rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded );
725 if ( k ) CompFree ( mem_op, k );
726 return LDAP_DECODING_ERROR;
731 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
732 if ( !k->comp_desc ) {
733 if ( k ) CompFree ( mem_op, k );
734 return LDAP_DECODING_ERROR;
736 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
737 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
738 k->comp_desc->cd_free = (comp_free_func*)NULL;
739 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
740 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
741 k->comp_desc->cd_extract_i = NULL;
742 k->comp_desc->cd_type = ASN_BASIC;
743 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
744 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
750 * Component GSER Encoder : IA5String
753 GEncComponentIA5Stirng ( GenBuf *b, ComponentIA5String* in )
755 if ( !in || in->value.octetLen <= 0 ) return (-1);
756 return GEncIA5StringContent( b, &in->value );
760 * Component BER Decoder : IA5String
763 BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
764 return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
768 BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
769 AsnLen *bytesDecoded, int mode )
773 void* component_values;
774 ComponentIA5String* k, **k2;
777 k = (ComponentIA5String*) v;
779 if ( mode & DEC_ALLOC_MODE_0 ) {
780 k2 = (ComponentIA5String**) v;
781 *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) );
782 if ( !*k2 ) return LDAP_DECODING_ERROR;
786 if ( mode & CALL_TAG_DECODER ){
787 mode = mode & CALL_CONTENT_DECODER;
788 rc = BDecIA5String ( mem_op, b, &result, bytesDecoded );
790 rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
793 if ( k ) CompFree ( mem_op, k );
794 return LDAP_DECODING_ERROR;
799 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
800 if ( !k->comp_desc ) {
801 if ( k ) CompFree ( mem_op, k );
802 return LDAP_DECODING_ERROR;
804 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String;
805 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String;
806 k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String;
807 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
808 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
809 k->comp_desc->cd_extract_i = NULL;
810 k->comp_desc->cd_type = ASN_BASIC;
811 k->comp_desc->cd_type_id = BASICTYPE_IA5_STR;
812 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentIA5String;
818 * Matching function : INTEGER
821 MatchingComponentInt(char* oid, ComponentSyntaxInfo* csi_attr,
822 ComponentSyntaxInfo* csi_assert )
828 /* check if this ASN type's matching rule is overrided */
829 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
830 /* if existing function is overrided, call the overriding
833 return component_value_match( mr, csi_attr , csi_assert );
835 a = ((ComponentInt*)csi_attr);
836 b = ((ComponentInt*)csi_assert);
838 return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
842 * GSER Encoder : INTEGER
845 GEncComponentInt ( GenBuf *b, ComponentInt* in )
847 if ( !in ) return (-1);
848 return GEncAsnIntContent ( b, &in->value );
852 * GSER Decoder : INTEGER
855 GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
859 void* component_values;
860 ComponentInt* k, **k2;
863 k = (ComponentInt*) v;
865 if ( mode & DEC_ALLOC_MODE_0 ) {
866 k2 = (ComponentInt**) v;
867 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
868 if ( !*k2 ) return LDAP_DECODING_ERROR;
872 if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
873 if ( k ) CompFree ( mem_op, k );
874 return LDAP_DECODING_ERROR;
876 k->value = result.value;
878 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
879 if ( !k->comp_desc ) {
880 if ( k ) CompFree ( mem_op, k );
881 return LDAP_DECODING_ERROR;
883 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
884 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
885 k->comp_desc->cd_free = (comp_free_func*)NULL;
886 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
887 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
888 k->comp_desc->cd_extract_i = NULL;
889 k->comp_desc->cd_type = ASN_BASIC;
890 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
891 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
897 * Component BER Decoder : INTEGER
900 BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
901 return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
905 BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
906 AsnLen *bytesDecoded, int mode )
910 void* component_values;
911 ComponentInt* k, **k2;
914 k = (ComponentInt*) v;
916 if ( mode & DEC_ALLOC_MODE_0 ) {
917 k2 = (ComponentInt**) v;
918 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
919 if ( !*k2 ) return LDAP_DECODING_ERROR;
923 if ( mode & CALL_TAG_DECODER ){
924 mode = mode & CALL_CONTENT_DECODER;
925 rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded );
927 rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded );
931 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
932 if ( !k->comp_desc ) {
933 if ( k ) CompFree ( mem_op, k );
934 return LDAP_DECODING_ERROR;
936 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
937 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
938 k->comp_desc->cd_free = (comp_free_func*)NULL;
939 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
940 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
941 k->comp_desc->cd_extract_i = NULL;
942 k->comp_desc->cd_type = ASN_BASIC;
943 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
944 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
950 * Matching function : NULL
953 MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr,
954 ComponentSyntaxInfo *csi_assert )
957 ComponentNull *a, *b;
960 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
962 return component_value_match( mr, csi_attr , csi_assert );
964 a = ((ComponentNull*)csi_attr);
965 b = ((ComponentNull*)csi_assert);
967 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
971 * GSER Encoder : NULL
974 GEncComponentNull ( GenBuf *b, ComponentNull *in )
976 if ( !in ) return (-1);
977 return GEncAsnNullContent ( b, &in->value );
981 * GSER Decoder : NULL
984 GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
988 void* component_values;
989 ComponentNull* k, **k2;
992 k = (ComponentNull*) v;
994 if ( mode & DEC_ALLOC_MODE_0 ) {
995 k2 = (ComponentNull**) v;
996 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
997 if ( !*k2 ) return LDAP_DECODING_ERROR;
1001 if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1002 if ( k ) CompFree ( mem_op, k );
1003 return LDAP_DECODING_ERROR;
1005 k->value = result.value;
1007 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1008 if ( !k->comp_desc ) {
1009 if ( k ) CompFree ( mem_op, k );
1010 return LDAP_DECODING_ERROR;
1012 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1013 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1014 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1015 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1016 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1017 k->comp_desc->cd_extract_i = NULL;
1018 k->comp_desc->cd_type = ASN_BASIC;
1019 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1020 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1022 return LDAP_SUCCESS;
1026 * Component BER Decoder : NULL
1029 BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1031 return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER );
1035 BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1036 AsnLen *bytesDecoded, int mode )
1040 void* component_values;
1041 ComponentNull* k, **k2;
1044 k = (ComponentNull*) v;
1046 if ( mode & DEC_ALLOC_MODE_0 ) {
1047 k2 = (ComponentNull**) v;
1048 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
1049 if ( !*k2 ) return LDAP_DECODING_ERROR;
1053 if ( mode & CALL_TAG_DECODER ){
1054 mode = mode & CALL_CONTENT_DECODER;
1055 rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded );
1058 rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1061 if ( k ) CompFree ( mem_op, k );
1062 return LDAP_DECODING_ERROR;
1066 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1067 if ( !k->comp_desc ) {
1068 if ( k ) CompFree ( mem_op, k );
1069 return LDAP_DECODING_ERROR;
1071 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1072 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1073 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1074 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1075 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1076 k->comp_desc->cd_extract_i = NULL;
1077 k->comp_desc->cd_type = ASN_BASIC;
1078 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1079 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1080 return LDAP_SUCCESS;
1084 * Component BER Decoder : NumericString
1087 BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1088 return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1092 BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1096 void* component_values;
1097 ComponentNumericString* k, **k2;
1098 NumericString result;
1100 k = (ComponentNumericString*) v;
1102 if ( mode & DEC_ALLOC_MODE_0 ) {
1103 k2 = (ComponentNumericString**) v;
1104 *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) );
1105 if ( !*k2 ) return LDAP_DECODING_ERROR;
1109 if ( mode & CALL_TAG_DECODER ){
1110 mode = mode & CALL_CONTENT_DECODER;
1111 rc = BDecNumericString ( mem_op, b, &result, bytesDecoded );
1113 rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1116 if ( k ) CompFree ( mem_op, k );
1117 return LDAP_DECODING_ERROR;
1121 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1122 if ( !k->comp_desc ) {
1123 if ( k ) CompFree ( mem_op, k );
1124 return LDAP_DECODING_ERROR;
1126 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString;
1127 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString;
1128 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString;
1129 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1130 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1131 k->comp_desc->cd_extract_i = NULL;
1132 k->comp_desc->cd_type = ASN_BASIC;
1133 k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR;
1134 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNumericString;
1136 return LDAP_SUCCESS;
1141 * Free function : OCTET STRING
1144 FreeComponentOcts ( ComponentOcts* v) {
1145 FreeAsnOcts( &v->value );
1149 * Matching function : OCTET STRING
1152 MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr,
1153 ComponentSyntaxInfo* csi_assert )
1157 ComponentOcts *a, *b;
1160 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1162 return component_value_match( mr, csi_attr , csi_assert );
1164 a = (ComponentOcts*) csi_attr;
1165 b = (ComponentOcts*) csi_assert;
1166 /* Assume that both of OCTET string has end of string character */
1167 if ( (a->value.octetLen == b->value.octetLen) &&
1168 strncmp ( a->value.octs, b->value.octs, a->value.octetLen ) == 0 )
1169 return LDAP_COMPARE_TRUE;
1171 return LDAP_COMPARE_FALSE;
1175 * GSER Encoder : OCTET STRING
1178 GEncComponentOcts ( GenBuf* b, ComponentOcts *in )
1180 if ( !in || in->value.octetLen <= 0 )
1182 return GEncAsnOctsContent ( b, &in->value );
1186 * GSER Decoder : OCTET STRING
1189 GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1191 char *peek_head, *data;
1193 void* component_values;
1194 ComponentOcts* k, **k2;
1197 k = (ComponentOcts*) v;
1199 if ( mode & DEC_ALLOC_MODE_0 ) {
1200 k2 = (ComponentOcts**) v;
1201 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1202 if ( !*k2 ) return LDAP_DECODING_ERROR;
1206 if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1207 if ( k ) CompFree ( mem_op, k );
1208 return LDAP_DECODING_ERROR;
1210 k->value = result.value;
1212 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1213 if ( !k->comp_desc ) {
1214 if ( k ) CompFree ( mem_op, k );
1215 return LDAP_DECODING_ERROR;
1217 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1218 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1219 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1220 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1221 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1222 k->comp_desc->cd_extract_i = NULL;
1223 k->comp_desc->cd_type = ASN_BASIC;
1224 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1225 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1227 return LDAP_SUCCESS;
1231 * Component BER Decoder : OCTET STRING
1234 BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1235 return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1239 BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1240 AsnLen *bytesDecoded, int mode )
1242 char *peek_head, *data;
1244 void* component_values;
1245 ComponentOcts* k, **k2;
1248 k = (ComponentOcts*) v;
1250 if ( mode & DEC_ALLOC_MODE_0 ) {
1251 k2 = (ComponentOcts**) v;
1252 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1253 if ( !*k2 ) return LDAP_DECODING_ERROR;
1257 if ( mode & CALL_TAG_DECODER ){
1258 mode = mode & CALL_CONTENT_DECODER;
1259 rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded );
1261 rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1264 if ( k ) CompFree ( mem_op, k );
1265 return LDAP_DECODING_ERROR;
1269 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1270 if ( !k->comp_desc ) {
1271 if ( k ) CompFree ( mem_op, k );
1272 return LDAP_DECODING_ERROR;
1274 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1275 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1276 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1277 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1278 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1279 k->comp_desc->cd_extract_i = NULL;
1280 k->comp_desc->cd_type = ASN_BASIC;
1281 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1282 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1283 return LDAP_SUCCESS;
1287 * Matching function : OBJECT IDENTIFIER
1290 MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr ,
1291 ComponentSyntaxInfo *csi_assert )
1295 ComponentOid *a, *b;
1298 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1300 return component_value_match( mr, csi_attr , csi_assert );
1303 a = (ComponentOid*)csi_attr;
1304 b = (ComponentOid*)csi_assert;
1305 if ( a->value.octetLen != b->value.octetLen )
1306 return LDAP_COMPARE_FALSE;
1307 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1309 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1313 * GSER Encoder : OID
1315 GEncComponentOid ( GenBuf *b, ComponentOid *in )
1317 if ( !in || in->value.octetLen <= 0 ) return (-1);
1318 return GEncAsnOidContent( b, &in->value );
1322 * GSER Decoder : OID
1325 GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){
1326 AttributeType *ad_type;
1331 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY );
1332 name.bv_val = peek_head;
1333 name.bv_len = strLen;
1335 ad_type = at_bvfind( &name );
1338 return LDAP_DECODING_ERROR;
1340 peek_head = ad_type->sat_atype.at_oid;
1341 strLen = strlen ( peek_head );
1343 result->value.octs = EncodeComponentOid ( mem_op, peek_head , &strLen );
1344 result->value.octetLen = strLen;
1345 return LDAP_SUCCESS;
1349 IsNumericOid ( char* peek_head , int strLen ) {
1352 for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) {
1353 if ( peek_head[i] == '.' ) num_dot++;
1354 else if ( peek_head[i] > '9' || peek_head[i] < '0' )
1364 GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1368 void* component_values;
1369 ComponentOid* k, **k2;
1372 k = (ComponentOid*) v;
1374 if ( mode & DEC_ALLOC_MODE_0 ) {
1375 k2 = (ComponentOid**) v;
1376 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1377 if ( !*k2 ) return LDAP_DECODING_ERROR;
1381 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK );
1382 if ( IsNumericOid ( peek_head , strLen ) >= 1 ) {
1384 if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1385 if ( k ) CompFree ( mem_op, k );
1386 return LDAP_DECODING_ERROR;
1391 if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){
1392 if ( k ) CompFree ( mem_op, k );
1393 return LDAP_DECODING_ERROR;
1396 k->value = result.value;
1398 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1399 if ( !k->comp_desc ) {
1400 if ( k ) CompFree ( mem_op, k );
1401 return LDAP_DECODING_ERROR;
1403 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1404 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1405 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1406 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1407 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1408 k->comp_desc->cd_extract_i = NULL;
1409 k->comp_desc->cd_type = ASN_BASIC;
1410 k->comp_desc->cd_type_id = BASICTYPE_OID;
1411 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1413 return LDAP_SUCCESS;
1417 * Component BER Decoder : OID
1420 BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1421 return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1425 BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1426 AsnLen *bytesDecoded, int mode )
1430 void* component_values;
1431 ComponentOid* k, **k2;
1434 k = (ComponentOid*) v;
1436 if ( mode & DEC_ALLOC_MODE_0 ) {
1437 k2 = (ComponentOid**) v;
1438 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1439 if ( !*k2 ) return LDAP_DECODING_ERROR;
1443 if ( mode & CALL_TAG_DECODER ){
1444 mode = mode & CALL_CONTENT_DECODER;
1445 rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded );
1447 rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1450 if ( k ) CompFree ( mem_op, k );
1451 return LDAP_DECODING_ERROR;
1455 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1456 if ( !k->comp_desc ) {
1457 if ( k ) CompFree ( mem_op, k );
1458 return LDAP_DECODING_ERROR;
1460 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1461 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1462 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1463 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1464 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1465 k->comp_desc->cd_extract_i = NULL;
1466 k->comp_desc->cd_type = ASN_BASIC;
1467 k->comp_desc->cd_type_id = BASICTYPE_OID;
1468 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1469 return LDAP_SUCCESS;
1473 * Component BER Decoder : PrintiableString
1477 BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1479 return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1483 BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1487 void* component_values;
1488 ComponentPrintableString* k, **k2;
1491 k = (ComponentPrintableString*) v;
1493 if ( mode & DEC_ALLOC_MODE_0 ) {
1494 k2 = (ComponentPrintableString**) v;
1495 *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) );
1496 if ( !*k2 ) return LDAP_DECODING_ERROR;
1500 if ( mode & CALL_TAG_DECODER ) {
1501 mode = mode & CALL_CONTENT_DECODER;
1502 rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded );
1504 rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1507 if ( k ) CompFree ( mem_op, k );
1508 return LDAP_DECODING_ERROR;
1512 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1513 if ( !k->comp_desc ) {
1514 if ( k ) CompFree ( mem_op, k );
1515 return LDAP_DECODING_ERROR;
1517 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString;
1518 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString;
1519 k->comp_desc->cd_free = (comp_free_func*)FreeComponentPrintableString;
1520 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1521 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1522 k->comp_desc->cd_extract_i = NULL;
1523 k->comp_desc->cd_type = ASN_BASIC;
1524 k->comp_desc->cd_type_id = BASICTYPE_PRINTABLE_STR;
1525 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentPrintableString;
1526 return LDAP_SUCCESS;
1530 * Matching function : Real
1533 MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr,
1534 ComponentSyntaxInfo *csi_assert )
1538 ComponentReal *a, *b;
1541 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1543 return component_value_match( mr, csi_attr , csi_assert );
1545 a = (ComponentReal*)csi_attr;
1546 b = (ComponentReal*)csi_assert;
1547 rc = (a->value == b->value);
1549 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1553 * GSER Encoder : Real
1556 GEncComponentReal ( GenBuf *b, ComponentReal *in )
1560 return GEncAsnRealContent ( b, &in->value );
1564 * GSER Decoder : Real
1567 GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1571 void* component_values;
1572 ComponentReal* k, **k2;
1575 k = (ComponentReal*) v;
1577 if ( mode & DEC_ALLOC_MODE_0 ) {
1578 k2 = (ComponentReal**) v;
1579 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1580 if ( !*k2 ) return LDAP_DECODING_ERROR;
1584 if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1585 if ( k ) CompFree ( mem_op, k );
1586 return LDAP_DECODING_ERROR;
1588 k->value = result.value;
1590 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1591 if ( !k->comp_desc ) {
1592 if ( k ) CompFree ( mem_op, k );
1593 return LDAP_DECODING_ERROR;
1595 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1596 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1597 k->comp_desc->cd_free = (comp_free_func*)NULL;
1598 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1599 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1600 k->comp_desc->cd_extract_i = NULL;
1601 k->comp_desc->cd_type = ASN_BASIC;
1602 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1603 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1605 return LDAP_SUCCESS;
1609 * Component BER Decoder : Real
1612 BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1613 return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1617 BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1621 void* component_values;
1622 ComponentReal* k, **k2;
1625 k = (ComponentReal*) v;
1627 if ( mode & DEC_ALLOC_MODE_0 ) {
1628 k2 = (ComponentReal**) v;
1629 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1630 if ( !*k2 ) return LDAP_DECODING_ERROR;
1634 if ( mode & CALL_TAG_DECODER ){
1635 mode = mode & CALL_CONTENT_DECODER;
1636 rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded );
1638 rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1641 if ( k ) CompFree ( mem_op, k );
1642 return LDAP_DECODING_ERROR;
1646 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1647 if ( !k->comp_desc ) {
1648 if ( k ) CompFree ( mem_op, k );
1649 return LDAP_DECODING_ERROR;
1651 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1652 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1653 k->comp_desc->cd_free = (comp_free_func*)NULL;
1654 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1655 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1656 k->comp_desc->cd_extract_i = NULL;
1657 k->comp_desc->cd_type = ASN_BASIC;
1658 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1659 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1661 return LDAP_SUCCESS;
1665 * Matching function : Relative OID
1668 MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr,
1669 ComponentSyntaxInfo *csi_assert )
1673 ComponentRelativeOid *a, *b;
1676 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1678 return component_value_match( mr, csi_attr , csi_assert );
1681 a = (ComponentRelativeOid*)csi_attr;
1682 b = (ComponentRelativeOid*)csi_assert;
1684 if ( a->value.octetLen != b->value.octetLen )
1685 return LDAP_COMPARE_FALSE;
1686 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1688 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1692 * GSER Encoder : RELATIVE_OID.
1695 GEncComponentRelativeOid ( GenBuf *b, ComponentRelativeOid *in )
1697 if ( !in || in->value.octetLen <= 0 )
1699 return GEncAsnRelativeOidContent ( b , &in->value );
1703 * GSER Decoder : RELATIVE_OID.
1706 GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
1710 void* component_values;
1711 ComponentRelativeOid* k, **k2;
1712 GAsnRelativeOid result;
1714 k = (ComponentRelativeOid*) v;
1716 if ( mode & DEC_ALLOC_MODE_0 ) {
1717 k2 = (ComponentRelativeOid**) v;
1718 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1719 if ( !*k2 ) return LDAP_DECODING_ERROR;
1723 if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1724 if ( k ) CompFree ( mem_op, k );
1725 return LDAP_DECODING_ERROR;
1727 k->value = result.value;
1729 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1730 if ( !k->comp_desc ) {
1731 if ( k ) CompFree ( mem_op, k );
1732 return LDAP_DECODING_ERROR;
1734 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1735 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1736 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1737 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1738 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1739 k->comp_desc->cd_extract_i = NULL;
1740 k->comp_desc->cd_type = ASN_BASIC;
1741 k->comp_desc->cd_type_id = BASICTYPE_OID;
1742 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1744 return LDAP_SUCCESS;
1748 * Component BER Decoder : RELATIVE_OID.
1751 BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1752 return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1756 BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1760 void* component_values;
1761 ComponentRelativeOid* k, **k2;
1762 AsnRelativeOid result;
1764 k = (ComponentRelativeOid*) v;
1766 if ( mode & DEC_ALLOC_MODE_0 ) {
1767 k2 = (ComponentRelativeOid**) v;
1768 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1769 if ( !*k2 ) return LDAP_DECODING_ERROR;
1773 if ( mode & CALL_TAG_DECODER ){
1774 mode = mode & CALL_CONTENT_DECODER;
1775 rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded );
1777 rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1780 if ( k ) CompFree ( mem_op, k );
1781 return LDAP_DECODING_ERROR;
1785 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1786 if ( !k->comp_desc ) {
1787 if ( k ) CompFree ( mem_op, k );
1788 return LDAP_DECODING_ERROR;
1790 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1791 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1792 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1793 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1794 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1795 k->comp_desc->cd_extract_i = NULL;
1796 k->comp_desc->cd_type = ASN_BASIC;
1797 k->comp_desc->cd_type_id = BASICTYPE_RELATIVE_OID;
1798 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1799 return LDAP_SUCCESS;
1803 * GSER Encoder : UniversalString
1806 GEncComponentUniversalString ( GenBuf *b, ComponentUniversalString *in )
1808 if ( !in || in->value.octetLen <= 0 )
1810 return GEncUniversalStringContent( b, &in->value );
1814 * GSER Decoder : UniversalString
1817 UTF8toUniversalString( char* octs, int len){
1818 /* Need to be Implemented */
1819 return LDAP_SUCCESS;
1823 GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1825 if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 )
1826 UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen );
1827 return LDAP_DECODING_ERROR;
1831 * Component BER Decoder : UniverseString
1834 BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1835 return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1839 BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1843 void* component_values;
1844 ComponentUniversalString* k, **k2;
1845 UniversalString result;
1847 k = (ComponentUniversalString*) v;
1849 if ( mode & DEC_ALLOC_MODE_0 ) {
1850 k2 = (ComponentUniversalString**) v;
1851 *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) );
1852 if ( !*k2 ) return LDAP_DECODING_ERROR;
1856 if ( mode & CALL_TAG_DECODER ){
1857 mode = mode & CALL_CONTENT_DECODER;
1858 rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded );
1860 rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1863 if ( k ) CompFree ( mem_op, k );
1864 return LDAP_DECODING_ERROR;
1868 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1869 if ( !k->comp_desc ) {
1870 if ( k ) CompFree ( mem_op, k );
1871 return LDAP_DECODING_ERROR;
1873 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString;
1874 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString;
1875 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUniversalString;
1876 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1877 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1878 k->comp_desc->cd_extract_i = NULL;
1879 k->comp_desc->cd_type = ASN_BASIC;
1880 k->comp_desc->cd_type_id = BASICTYPE_UNIVERSAL_STR;
1881 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUniversalString;
1882 return LDAP_SUCCESS;
1886 * Component BER Decoder : VisibleString
1889 BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1890 return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1894 BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1898 void* component_values;
1899 ComponentVisibleString* k, **k2;
1900 VisibleString result;
1902 k = (ComponentVisibleString*) v;
1904 if ( mode & DEC_ALLOC_MODE_0 ) {
1905 k2 = (ComponentVisibleString**) v;
1906 *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) );
1907 if ( !*k2 ) return LDAP_DECODING_ERROR;
1911 if ( mode & CALL_TAG_DECODER ){
1912 mode = mode & CALL_CONTENT_DECODER;
1913 rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded );
1915 rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
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_decoder = (gser_decoder_func*)GDecComponentVisibleString;
1925 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString;
1926 k->comp_desc->cd_free = (comp_free_func*)FreeComponentVisibleString;
1927 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1928 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1929 k->comp_desc->cd_extract_i = NULL;
1930 k->comp_desc->cd_type = ASN_BASIC;
1931 k->comp_desc->cd_type_id = BASICTYPE_VISIBLE_STR;
1932 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentVisibleString;
1933 return LDAP_SUCCESS;
1937 * Routines for handling an ANY DEFINED Type
1940 /* Check if the <select> type CR and the OID of the given ANY type */
1942 CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo* cai, struct berval* select ) {
1944 AttributeType* ad_type;
1948 if ( IsNumericOid ( select->bv_val , select->bv_len ) ) {
1949 oid = select->bv_val;
1950 strLen = select->bv_len;
1952 ad_type = at_bvfind( select );
1955 return LDAP_DECODING_ERROR;
1957 oid = ad_type->sat_atype.at_oid;
1958 strLen = strlen ( oid );
1960 result = EncodeComponentOid ( mem_op, oid , &strLen );
1961 if ( !result || strLen <= 0 ) return (-1);
1963 if ( cai->oid.octetLen == strLen &&
1964 strncmp ( cai->oid.octs, result, strLen ) == 0 )
1971 SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) {
1975 /* use encoded oid as hash string */
1976 hash = MakeHash (id->value.octs, id->value.octetLen);
1977 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
1978 v->cai = (ComponentAnyInfo*) anyInfo;
1984 * If not found, the data considered as octet chunk
1985 * Yet-to-be-Implemented
1988 return LDAP_SUCCESS;
1992 SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) {
1996 hash = MakeHash ((char*)&id, sizeof (id));
1997 if (CheckForAndReturnValue (anyIntHashTblG, hash, &anyInfo))
1998 v->cai = (ComponentAnyInfo*) anyInfo;
2004 GEncComponentAny ( GenBuf *b, ComponentAny *in )
2006 if ( in->cai != NULL && in->cai->Encode != NULL )
2007 return in->cai->Encode(b, &in->value );
2012 BEncComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode)
2014 ComponentAny *k, **k2;
2016 k = (ComponentAny*) result;
2018 if ( !k ) return (-1);
2020 if ( mode & DEC_ALLOC_MODE_0 ) {
2021 k2 = (ComponentAny**) result;
2022 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2023 if ( !*k2 ) return LDAP_DECODING_ERROR;
2027 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
2028 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2029 if ( !result->value ) return 0;
2030 result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
2032 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2033 if ( !k->comp_desc ) {
2034 if ( k ) CompFree ( mem_op, k );
2035 return LDAP_DECODING_ERROR;
2037 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2038 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2039 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2040 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
2041 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
2042 k->comp_desc->cd_extract_i = NULL;
2043 k->comp_desc->cd_type = ASN_BASIC;
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 - Component ANY Decode routine is NULL\n");
2055 BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
2057 ComponentAny *k, **k2;
2059 k = (ComponentAny*) result;
2061 if ( !k ) return (-1);
2063 if ( mode & DEC_ALLOC_MODE_0 ) {
2064 k2 = (ComponentAny**) result;
2065 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2066 if ( !*k2 ) return LDAP_DECODING_ERROR;
2070 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
2072 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2073 if ( !result->value ) return 0;
2075 result->cai->BER_Decode ( mem_op, b, &result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_0 );
2077 rc = BDecComponentTop( result->cai->BER_Decode, mem_op, 0, 0, &result->value, bytesDecoded, DEC_ALLOC_MODE_0 );
2078 if ( rc != LDAP_SUCCESS ) return rc;
2081 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2082 if ( !k->comp_desc ) {
2083 if ( k ) CompFree ( mem_op, k );
2084 return LDAP_DECODING_ERROR;
2086 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2087 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2088 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2089 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
2090 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
2091 k->comp_desc->cd_extract_i = NULL;
2092 k->comp_desc->cd_type = ASN_BASIC;
2093 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2094 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2095 return LDAP_SUCCESS;
2098 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
2104 GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
2105 ComponentAny *k, **k2;
2107 k = (ComponentAny*) result;
2109 if ( mode & DEC_ALLOC_MODE_0 ) {
2110 k2 = (ComponentAny**) result;
2111 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2112 if ( !*k2 ) return LDAP_DECODING_ERROR;
2115 if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {
2116 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2117 if ( !result->value ) return 0;
2118 result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
2119 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2120 if ( !k->comp_desc ) {
2121 if ( k ) CompFree ( mem_op, k );
2122 return LDAP_DECODING_ERROR;
2124 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2125 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2126 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2127 k->comp_desc->cd_type = ASN_BASIC;
2128 k->comp_desc->cd_extract_i = NULL;
2129 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2130 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2131 return LDAP_SUCCESS;
2134 Asn1Error ("ERROR - ANY Decode routine is NULL\n");
2140 MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) {
2141 void *comp1, *comp2;
2143 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2144 comp1 = result->value;
2148 if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2149 comp2 = result2->value;
2153 if ((result->cai != NULL) && (result->cai->Match != NULL)) {
2154 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2155 return result->cai->Match(oid, comp1, comp2 );
2156 else if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2157 return result2->cai->Match(oid, comp1, comp2);
2159 return LDAP_INVALID_SYNTAX;
2162 Asn1Error ("ERROR - ANY Matching routine is NULL\n");
2163 return LDAP_INVALID_SYNTAX;
2168 ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) {
2169 if ((result->cai != NULL) && (result->cai->Extract != NULL)) {
2170 return (void*) result->cai->Extract( mem_op, cr , result->value );
2173 Asn1Error ("ERROR - ANY Extracting routine is NULL\n");
2179 FreeComponentAny (ComponentAny* any) {
2180 if ( any->cai != NULL && any->cai->Free != NULL ) {
2181 any->cai->Free( any->value );
2182 free ( ((ComponentSyntaxInfo*)any->value)->csi_comp_desc );
2183 free ( any->value );
2186 Asn1Error ("ERROR - ANY Free routine is NULL\n");
2190 InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size,
2191 EncodeFcn encode, gser_decoder_func* G_decode,
2192 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2193 MatchFcn match, FreeFcn free,
2196 ComponentAnyInfo *a;
2199 a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo));
2202 a->oid.octetLen = 0;
2206 a->GSER_Decode = G_decode;
2207 a->BER_Decode = B_decode;
2209 a->Extract = extract;
2213 if (anyIntHashTblG == NULL)
2214 anyIntHashTblG = InitHash();
2216 h = MakeHash ((char*)&intId, sizeof (intId));
2218 if(anyIntHashTblG != NULL)
2219 Insert(anyIntHashTblG, a, h);
2224 * OID and its corresponding decoder can be registerd with this func.
2225 * If contained types constrained by <select> are used,
2226 * their OID and decoder MUST be registered, otherwise it will return no entry.
2227 * An open type(ANY type) also need be registered.
2230 InstallOidDecoderMapping ( char* ch_oid, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match ) {
2235 strLen = strlen( ch_oid );
2236 if( strLen <= 0 ) return;
2237 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2238 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &strLen );
2239 oid.octetLen = strLen;
2240 if( strLen <= 0 ) return;
2243 InstallAnyByComponentOid ( 0, &oid, 0, encode, G_decode, B_decode,
2244 extract, match, NULL, NULL);
2245 comp_nibble_memory_free(mem_op);
2249 * Look up Oid-decoder mapping table by berval have either
2250 * oid or description
2253 RetrieveOidDecoderMappingbyBV( struct berval* in ) {
2254 if ( IsNumericOid ( in->bv_val, in->bv_len ) )
2255 return RetrieveOidDecoderMappingbyOid( in->bv_val, in->bv_len );
2257 return RetrieveOidDecoderMappingbyDesc( in->bv_val, in->bv_len );
2261 * Look up Oid-decoder mapping table by dotted OID
2264 RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len ) {
2271 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2272 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &oid_len);
2273 oid.octetLen = oid_len;
2275 comp_nibble_memory_free( mem_op );
2279 /* use encoded oid as hash string */
2280 hash = MakeHash ( oid.octs, oid.octetLen);
2281 comp_nibble_memory_free( mem_op );
2282 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2283 return (OidDecoderMapping*) anyInfo;
2285 return (OidDecoderMapping*) NULL;
2290 * Look up Oid-decoder mapping table by description
2293 RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len ) {
2297 AttributeType* ad_type;
2302 bv.bv_len = desc_len;
2303 ad_type = at_bvfind( &bv );
2305 oid.octs = ad_type->sat_atype.at_oid;
2306 oid.octetLen = strlen ( oid.octs );
2309 return (OidDecoderMapping*) NULL;
2311 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2313 oid.octs = EncodeComponentOid ( mem_op, oid.octs , &oid.octetLen );
2314 if( oid.octetLen <= 0 ) {
2315 comp_nibble_memory_free( mem_op );
2316 return (OidDecoderMapping*) NULL;
2319 /* use encoded oid as hash string */
2320 hash = MakeHash ( oid.octs, oid.octetLen);
2321 comp_nibble_memory_free( mem_op );
2322 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2323 return (OidDecoderMapping*) anyInfo;
2325 return (OidDecoderMapping*) NULL;
2329 InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size,
2330 EncodeFcn encode, gser_decoder_func* G_decode,
2331 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2332 MatchFcn match, FreeFcn free, PrintFcn print)
2334 ComponentAnyInfo *a;
2337 a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
2340 a->oid.octs = malloc( oid->octetLen );
2341 memcpy ( a->oid.octs, oid->octs, oid->octetLen );
2342 a->oid.octetLen = oid->octetLen;
2346 a->GSER_Decode = G_decode;
2347 a->BER_Decode = B_decode;
2349 a->Extract = extract;
2353 h = MakeHash (oid->octs, oid->octetLen);
2355 if (anyOidHashTblG == NULL)
2356 anyOidHashTblG = InitHash();
2358 if(anyOidHashTblG != NULL)
2359 Insert(anyOidHashTblG, a, h);
2364 ber_decoder_func *decoder _AND_
2368 AsnLen elmtLen _AND_
2370 AsnLen *bytesDecoded _AND_
2372 tag = BDecTag ( b, bytesDecoded );
2373 elmtLen = BDecLen ( b, bytesDecoded );
2374 if ( elmtLen <= 0 ) return (-1);
2375 if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
2379 return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
2383 * ASN.1 specification of a distinguished name
2384 * DistinguishedName ::= RDNSequence
2385 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
2386 * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue
2387 * AttributeTypeandValue ::= SEQUENCE {
2388 * type AttributeType
2389 * value AttributeValue
2391 * When dnMatch/rdnMatch is used in a component assertion value
2392 * the component in DistinguishedName/RelativeDistinguishedName
2393 * need to be converted to the LDAP encodings in RFC2253
2394 * in order to be matched against the assertion value
2395 * If allComponentMatch is used, the assertion value may be
2396 * decoded into the Internal Representation(Component Tree)
2397 * by the corresponding GSER or BER decoder
2398 * Following routine converts a component tree(DistinguishedName) into
2399 * LDAP encodings in RFC2253
2401 * IR : ComponentRDNSequence
2402 * GSER : { { type cn, value sang },{ type o, value ibm}, {type c, value us} }
2403 * LDAP Encodings : cn=sang,o=ibm,c=us
2406 increment_bv_mem_by_size ( struct berval* in, int size ) {
2407 int new_size = in->bv_len + size;
2408 in->bv_val = realloc( in->bv_val, new_size );
2409 in->bv_len = new_size;
2413 ConvertBER2Desc( char* in, int size, struct berval* out, int* pos ) {
2416 unsigned int firstArcNum;
2417 unsigned int arcNum;
2418 int i, rc, start_pos = *pos;
2419 char buf[MAX_OID_LEN];
2421 struct berval bv_name;
2423 /*convert BER oid to desc*/
2424 for ( i = 0, arcNum = 0; (i < size) && (in[i] & 0x80 ); i++ )
2425 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2426 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2428 firstArcNum = (unsigned short)(arcNum/40);
2429 if ( firstArcNum > 2 )
2432 arcNum = arcNum - (firstArcNum * 40 );
2434 rc = intToAscii ( arcNum, buf );
2436 /*check if the buffer can store the first/second arc and two dots*/
2437 if ( out->bv_len < *pos + 2 + 1 + rc )
2438 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2440 if ( firstArcNum == 1)
2441 out->bv_val[*pos] = '1';
2443 out->bv_val[*pos] = '2';
2445 out->bv_val[*pos] = '.';
2448 memcpy( out->bv_val + *pos, buf, rc );
2450 out->bv_val[*pos] = '.';
2453 for ( ; i < size ; ) {
2454 for ( arcNum=0; (i < size) && (in[i] & 0x80) ; i++ )
2455 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2456 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2459 rc = intToAscii ( arcNum, buf );
2461 if ( out->bv_len < *pos + rc + 1 )
2462 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2464 memcpy( out->bv_val + *pos, buf, rc );
2466 out->bv_val[*pos] = '.';
2469 (*pos)--;/*remove the last '.'*/
2472 * lookup OID database to locate desc
2473 * then overwrite OID with desc in *out
2474 * If failed to look up desc, OID form is used
2476 bv_name.bv_val = out->bv_val + start_pos;
2477 bv_name.bv_len = *pos - start_pos;
2478 at = at_bvfind( &bv_name );
2480 return LDAP_SUCCESS;
2481 desc_size = at->sat_cname.bv_len;
2482 memcpy( out->bv_val + start_pos, at->sat_cname.bv_val, desc_size );
2483 *pos = start_pos + desc_size;
2484 return LDAP_SUCCESS;
2488 ConvertComponentAttributeTypeAndValue2RFC2253 ( irAttributeTypeAndValue* in, struct berval* out, int *pos ) {
2490 int value_size = ((ComponentUTF8String*)in->value.value)->value.octetLen;
2491 char* value_ptr = ((ComponentUTF8String*)in->value.value)->value.octs;
2493 rc = ConvertBER2Desc( in->type.value.octs, in->type.value.octetLen, out, pos );
2494 if ( rc != LDAP_SUCCESS ) return rc;
2495 if ( out->bv_len < *pos + 1/*for '='*/ )
2496 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2497 /*Between type and value, put '='*/
2498 out->bv_val[*pos] = '=';
2501 /*Assume it is string*/
2502 if ( out->bv_len < *pos + value_size )
2503 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2504 memcpy( out->bv_val + *pos, value_ptr, value_size );
2505 out->bv_len += value_size;
2508 return LDAP_SUCCESS;
2512 ConvertRelativeDistinguishedName2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out , int* pos) {
2513 irAttributeTypeAndValue* attr_typeNvalue;
2517 FOR_EACH_LIST_ELMT( attr_typeNvalue, &in->comp_list)
2519 rc = ConvertComponentAttributeTypeAndValue2RFC2253( attr_typeNvalue, out, pos );
2520 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2522 if ( out->bv_len < *pos + 1/*for '+'*/ )
2523 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2524 /*between multivalued RDNs, put comma*/
2525 out->bv_val[(*pos)++] = '+';
2527 (*pos)--;/*remove the last '+'*/
2528 return LDAP_SUCCESS;
2532 ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out ) {
2534 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2535 out->bv_len = INITIAL_DN_SIZE;
2537 rc = ConvertRelativeDistinguishedName2RFC2253 ( in, out , &pos);
2538 if ( rc != LDAP_SUCCESS ) return rc;
2539 out->bv_val[pos] = '\0';
2541 return LDAP_SUCCESS;
2545 ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out ) {
2546 irRelativeDistinguishedName* rdn_seq;
2547 AsnList* seq = &in->comp_list;
2550 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2551 out->bv_len = INITIAL_DN_SIZE;
2553 FOR_EACH_LIST_ELMT( rdn_seq, seq )
2555 rc = ConvertRelativeDistinguishedName2RFC2253( rdn_seq, out, &pos );
2556 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2558 if ( out->bv_len < pos + 1/*for ','*/ )
2559 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2560 /*Between RDN, put comma*/
2561 out->bv_val[pos++] = ',';
2563 pos--;/*remove the last '+'*/
2564 out->bv_val[pos] = '\0';
2566 return LDAP_SUCCESS;