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;
106 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
107 if ( !k->comp_desc ) {
108 if ( k ) CompFree( mem_op, k );
109 return LDAP_DECODING_ERROR;
111 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBits;
112 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
113 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
114 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
115 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
116 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
117 k->comp_desc->cd_extract_i = NULL;
118 k->comp_desc->cd_type = ASN_BASIC;
119 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
120 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
122 /* Real Decoding code need to be followed */
127 * Component BER Decoder : BIT STRING
130 BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
131 return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
135 BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
136 AsnLen *bytesDecoded, int mode )
140 void* component_values;
141 ComponentBits* k, **k2;
144 k = (ComponentBits*) v;
146 if ( mode & DEC_ALLOC_MODE_0 ) {
147 k2 = (ComponentBits**) v;
148 *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
149 if ( !*k2 ) return LDAP_DECODING_ERROR;
153 if ( mode & CALL_TAG_DECODER ){
154 mode = mode & CALL_CONTENT_DECODER;
155 rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );
157 rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
161 if ( k ) CompFree( mem_op, k );
162 return LDAP_DECODING_ERROR;
167 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
168 if ( !k->comp_desc ) {
169 if ( k ) CompFree( mem_op, k );
170 return LDAP_DECODING_ERROR;
172 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBits;
173 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
174 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
175 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
176 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
177 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
178 k->comp_desc->cd_extract_i = NULL;
179 k->comp_desc->cd_type = ASN_BASIC;
180 k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
181 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
187 * Component GSER BMPString Encoder
190 GEncComponentBMPString ( GenBuf *b, ComponentBMPString *in )
194 if ( !in || in->value.octetLen <= 0 )
197 return GEncBMPStringContent ( b, &t );
201 * Component GSER BMPString Decoder
204 GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
208 void* component_values;
209 ComponentBMPString* k, **k2;
212 k = (ComponentBMPString*) v;
214 if ( mode & DEC_ALLOC_MODE_0 ) {
215 k2 = (ComponentBMPString**) v;
216 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
217 if ( !*k2 ) return LDAP_DECODING_ERROR;
223 if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
224 if ( k ) CompFree( mem_op, k );
225 return LDAP_DECODING_ERROR;
228 k->value = result.value;
230 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
231 if ( !k->comp_desc ) {
232 if ( k ) CompFree( mem_op, k );
233 return LDAP_DECODING_ERROR;
235 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBMPString;
236 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
237 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
238 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
239 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
240 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
241 k->comp_desc->cd_extract_i = NULL;
242 k->comp_desc->cd_type = ASN_BASIC;
243 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
244 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
251 * Component BER BMPString Decoder
254 BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
255 return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
259 BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
260 AsnLen *bytesDecoded, int mode )
264 void* component_values;
265 ComponentBMPString* k, **k2;
268 k = (ComponentBMPString*) v;
270 if ( mode & DEC_ALLOC_MODE_0 ) {
271 k2 = (ComponentBMPString**) v;
272 *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
273 if ( !*k2 ) return LDAP_DECODING_ERROR;
277 if ( mode & CALL_TAG_DECODER ){
278 mode = mode & CALL_CONTENT_DECODER;
279 rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );
281 rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
285 if ( k ) CompFree( mem_op, k );
286 return LDAP_DECODING_ERROR;
291 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
292 if ( !k->comp_desc ) {
293 if ( k ) CompFree ( mem_op, k );
294 return LDAP_DECODING_ERROR;
296 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBMPString;
297 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
298 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
299 k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
300 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
301 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
302 k->comp_desc->cd_extract_i = NULL;
303 k->comp_desc->cd_type = ASN_BASIC;
304 k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
305 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
312 * Component GSER Encoder : UTF8 String
315 GEncComponentUTF8String ( GenBuf *b, ComponentUTF8String *in )
318 if ( !in || in->value.octetLen <= 0 )
321 return GEncUTF8StringContent ( b, &t );
325 * Component GSER Decoder : UTF8 String
328 GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,
329 AsnLen *bytesDecoded, int mode) {
332 void* component_values;
333 ComponentUTF8String* k, **k2;
336 k = (ComponentUTF8String*) v;
338 if ( mode & DEC_ALLOC_MODE_0 ) {
339 k2 = (ComponentUTF8String**) v;
340 *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
341 if ( !*k2 ) return LDAP_DECODING_ERROR;
347 if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
348 if ( k ) CompFree( mem_op, k );
349 return LDAP_DECODING_ERROR;
352 k->value = result.value;
354 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
355 if ( !k->comp_desc ) {
356 if ( k ) CompFree( mem_op, k );
357 return LDAP_DECODING_ERROR;
359 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentUTF8String;
360 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
361 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
362 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
363 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
364 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
365 k->comp_desc->cd_extract_i = NULL;
366 k->comp_desc->cd_type = ASN_BASIC;
367 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
368 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
374 * Component BER Decoder : UTF8String
377 BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
378 return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
382 BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len,
383 void *v, AsnLen *bytesDecoded, int mode )
387 void* component_values;
388 ComponentUTF8String* k, **k2;
391 k = (ComponentUTF8String*) v;
393 if ( mode & DEC_ALLOC_MODE_0 ) {
394 k2 = (ComponentUTF8String**) v;
395 *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
396 if ( !*k2 ) return LDAP_DECODING_ERROR;
400 if ( mode & CALL_TAG_DECODER ){
401 mode = mode & CALL_CONTENT_DECODER;
402 rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );
404 rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
407 if ( k ) CompFree( mem_op, k );
408 return LDAP_DECODING_ERROR;
413 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
414 if ( !k->comp_desc ) {
415 if ( k ) CompFree ( mem_op, k );
416 return LDAP_DECODING_ERROR;
418 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentUTF8String;
419 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
420 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
421 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
422 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
423 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
424 k->comp_desc->cd_extract_i = NULL;
425 k->comp_desc->cd_type = ASN_BASIC;
426 k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
427 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
431 * Component GSER Encoder : Teletex String
434 GEncComponentTeletexString ( GenBuf *b, ComponentTeletexString *in )
436 GTeletexString t = {0};
438 if ( !in || in->value.octetLen <= 0 )
441 return GEncTeletexStringContent ( b, &t );
445 * Component GSER Decoder : Teletex String
448 GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v,
449 AsnLen *bytesDecoded, int mode) {
452 void* component_values;
453 ComponentTeletexString* k, **k2;
454 GTeletexString result;
456 k = (ComponentTeletexString*) v;
458 if ( mode & DEC_ALLOC_MODE_0 ) {
459 k2 = (ComponentTeletexString**) v;
460 *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
461 if ( !*k2 ) return LDAP_DECODING_ERROR;
467 if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
468 if ( k ) CompFree( mem_op, k );
469 return LDAP_DECODING_ERROR;
472 k->value = result.value;
474 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
475 if ( !k->comp_desc ) {
476 if ( k ) CompFree ( mem_op, k );
477 return LDAP_DECODING_ERROR;
479 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentTeletexString;
480 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString;
481 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString;
482 k->comp_desc->cd_free = (comp_free_func*)FreeComponentTeletexString;
483 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
484 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
485 k->comp_desc->cd_extract_i = NULL;
486 k->comp_desc->cd_type = ASN_BASIC;
487 k->comp_desc->cd_type_id = BASICTYPE_VIDEOTEX_STR;
488 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTeletexString;
495 * Matching function : BOOLEAN
498 MatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr,
499 ComponentSyntaxInfo* csi_assert )
502 ComponentBool *a, *b;
505 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
507 return component_value_match( mr, csi_attr , csi_assert );
510 a = ((ComponentBool*)csi_attr);
511 b = ((ComponentBool*)csi_assert);
513 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
517 * GSER Encoder : BOOLEAN
520 GEncComponentBool ( GenBuf *b, ComponentBool *in )
527 return GEncAsnBoolContent ( b, &t );
531 * GSER Decoder : BOOLEAN
534 GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
538 ComponentBool* k, **k2;
541 k = (ComponentBool*) v;
543 if ( mode & DEC_ALLOC_MODE_0 ) {
544 k2 = (ComponentBool**) v;
545 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
546 if ( !*k2 ) return LDAP_DECODING_ERROR;
550 if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) {
551 if ( k ) CompFree ( mem_op, k );
552 return LDAP_DECODING_ERROR;
555 k->value = result.value;
557 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
558 if ( !k->comp_desc ) {
559 if ( k ) CompFree ( mem_op, k );
560 return LDAP_DECODING_ERROR;
562 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBool;
563 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
564 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
565 k->comp_desc->cd_free = (comp_free_func*)NULL;
566 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
567 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
568 k->comp_desc->cd_extract_i = NULL;
569 k->comp_desc->cd_type = ASN_BASIC;
570 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
571 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
577 * Component BER Decoder : BOOLEAN
580 BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
581 return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
585 BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
586 AsnLen *bytesDecoded, int mode )
590 ComponentBool* k, **k2;
593 k = (ComponentBool*) v;
595 if ( mode & DEC_ALLOC_MODE_0 ) {
596 k2 = (ComponentBool**) v;
597 *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
598 if ( !*k2 ) return LDAP_DECODING_ERROR;
602 if ( mode & CALL_TAG_DECODER ){
603 mode = mode & CALL_CONTENT_DECODER;
604 rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded );
606 rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded );
609 if ( k ) CompFree ( mem_op, k );
610 return LDAP_DECODING_ERROR;
615 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
616 if ( !k->comp_desc ) {
617 if ( k ) CompFree ( mem_op, k );
618 return LDAP_DECODING_ERROR;
620 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentBool;
621 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
622 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
623 k->comp_desc->cd_free = (comp_free_func*)NULL;
624 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
625 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
626 k->comp_desc->cd_extract_i = NULL;
627 k->comp_desc->cd_type = ASN_BASIC;
628 k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
629 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
635 * Matching function : ENUMERATE
638 MatchingComponentEnum ( char* oid, ComponentSyntaxInfo *csi_attr,
639 ComponentSyntaxInfo *csi_assert )
643 ComponentEnum *a, *b;
646 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
648 return component_value_match( mr, csi_attr , csi_assert );
650 a = ((ComponentEnum*)csi_attr);
651 b = ((ComponentEnum*)csi_assert);
652 rc = (a->value == b->value);
654 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
658 * GSER Encoder : ENUMERATE
661 GEncComponentEnum ( GenBuf *b, ComponentEnum *in )
668 return GEncAsnEnumContent ( b, &t );
672 * GSER Decoder : ENUMERATE
675 GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
679 void* component_values;
680 ComponentEnum* k, **k2;
683 k = (ComponentEnum*) v;
685 if ( mode & DEC_ALLOC_MODE_0 ) {
686 k2 = (ComponentEnum**) v;
687 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
688 if ( !*k2 ) return LDAP_DECODING_ERROR;
692 if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
693 if ( k ) CompFree ( mem_op, k );
694 return LDAP_DECODING_ERROR;
697 k->value_identifier.bv_val = result.value_identifier;
698 k->value_identifier.bv_len = result.len;
700 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
701 if ( !k->comp_desc ) {
702 if ( k ) CompFree ( mem_op, k );
703 return LDAP_DECODING_ERROR;
705 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
706 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
707 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
708 k->comp_desc->cd_free = (comp_free_func*)NULL;
709 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
710 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
711 k->comp_desc->cd_extract_i = NULL;
712 k->comp_desc->cd_type = ASN_BASIC;
713 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
714 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
720 * Component BER Decoder : ENUMERATE
723 BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
724 return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
728 BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
729 AsnLen *bytesDecoded, int mode )
733 void* component_values;
734 ComponentEnum* k, **k2;
737 k = (ComponentEnum*) v;
739 if ( mode & DEC_ALLOC_MODE_0 ) {
740 k2 = (ComponentEnum**) v;
741 *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
742 if ( k ) return LDAP_DECODING_ERROR;
746 if ( mode & CALL_TAG_DECODER ){
747 mode = mode & CALL_CONTENT_DECODER;
748 rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded );
750 rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded );
753 if ( k ) CompFree ( mem_op, k );
754 return LDAP_DECODING_ERROR;
759 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
760 if ( !k->comp_desc ) {
761 if ( k ) CompFree ( mem_op, k );
762 return LDAP_DECODING_ERROR;
764 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
765 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
766 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
767 k->comp_desc->cd_free = (comp_free_func*)NULL;
768 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
769 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
770 k->comp_desc->cd_extract_i = NULL;
771 k->comp_desc->cd_type = ASN_BASIC;
772 k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
773 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentEnum;
779 * Component GSER Encoder : IA5String
782 GEncComponentIA5Stirng ( GenBuf *b, ComponentIA5String* in )
786 if ( !in || in->value.octetLen <= 0 ) return (-1);
787 return GEncIA5StringContent( b, &t );
791 * Component BER Decoder : IA5String
794 BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
795 return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
799 BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
800 AsnLen *bytesDecoded, int mode )
804 void* component_values;
805 ComponentIA5String* k, **k2;
808 k = (ComponentIA5String*) v;
810 if ( mode & DEC_ALLOC_MODE_0 ) {
811 k2 = (ComponentIA5String**) v;
812 *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) );
813 if ( !*k2 ) return LDAP_DECODING_ERROR;
817 if ( mode & CALL_TAG_DECODER ){
818 mode = mode & CALL_CONTENT_DECODER;
819 rc = BDecIA5String ( mem_op, b, &result, bytesDecoded );
821 rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
824 if ( k ) CompFree ( mem_op, k );
825 return LDAP_DECODING_ERROR;
830 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
831 if ( !k->comp_desc ) {
832 if ( k ) CompFree ( mem_op, k );
833 return LDAP_DECODING_ERROR;
835 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentIA5String;
836 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String;
837 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String;
838 k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String;
839 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
840 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
841 k->comp_desc->cd_extract_i = NULL;
842 k->comp_desc->cd_type = ASN_BASIC;
843 k->comp_desc->cd_type_id = BASICTYPE_IA5_STR;
844 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentIA5String;
850 * Matching function : INTEGER
853 MatchingComponentInt(char* oid, ComponentSyntaxInfo* csi_attr,
854 ComponentSyntaxInfo* csi_assert )
860 /* check if this ASN type's matching rule is overrided */
861 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
862 /* if existing function is overrided, call the overriding
865 return component_value_match( mr, csi_attr , csi_assert );
867 a = ((ComponentInt*)csi_attr);
868 b = ((ComponentInt*)csi_assert);
870 return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
874 * GSER Encoder : INTEGER
877 GEncComponentInt ( GenBuf *b, ComponentInt* in )
884 return GEncAsnIntContent ( b, &t );
888 * GSER Decoder : INTEGER
891 GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
895 void* component_values;
896 ComponentInt* k, **k2;
899 k = (ComponentInt*) v;
901 if ( mode & DEC_ALLOC_MODE_0 ) {
902 k2 = (ComponentInt**) v;
903 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
904 if ( !*k2 ) return LDAP_DECODING_ERROR;
908 if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
909 if ( k ) CompFree ( mem_op, k );
910 return LDAP_DECODING_ERROR;
912 k->value = result.value;
914 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
915 if ( !k->comp_desc ) {
916 if ( k ) CompFree ( mem_op, k );
917 return LDAP_DECODING_ERROR;
919 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentInt;
920 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
921 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
922 k->comp_desc->cd_free = (comp_free_func*)NULL;
923 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
924 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
925 k->comp_desc->cd_extract_i = NULL;
926 k->comp_desc->cd_type = ASN_BASIC;
927 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
928 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
934 * Component BER Decoder : INTEGER
937 BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
938 return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
942 BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
943 AsnLen *bytesDecoded, int mode )
947 void* component_values;
948 ComponentInt* k, **k2;
951 k = (ComponentInt*) v;
953 if ( mode & DEC_ALLOC_MODE_0 ) {
954 k2 = (ComponentInt**) v;
955 *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
956 if ( !*k2 ) return LDAP_DECODING_ERROR;
960 if ( mode & CALL_TAG_DECODER ){
961 mode = mode & CALL_CONTENT_DECODER;
962 rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded );
964 rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded );
968 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
969 if ( !k->comp_desc ) {
970 if ( k ) CompFree ( mem_op, k );
971 return LDAP_DECODING_ERROR;
973 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentInt;
974 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
975 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
976 k->comp_desc->cd_free = (comp_free_func*)NULL;
977 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
978 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
979 k->comp_desc->cd_extract_i = NULL;
980 k->comp_desc->cd_type = ASN_BASIC;
981 k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
982 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
988 * Matching function : NULL
991 MatchingComponentNull ( char *oid, ComponentSyntaxInfo *csi_attr,
992 ComponentSyntaxInfo *csi_assert )
995 ComponentNull *a, *b;
998 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1000 return component_value_match( mr, csi_attr , csi_assert );
1002 a = ((ComponentNull*)csi_attr);
1003 b = ((ComponentNull*)csi_assert);
1005 return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1009 * GSER Encoder : NULL
1012 GEncComponentNull ( GenBuf *b, ComponentNull *in )
1018 t.value = in->value;
1019 return GEncAsnNullContent ( b, &t );
1023 * GSER Decoder : NULL
1026 GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1030 void* component_values;
1031 ComponentNull* k, **k2;
1034 k = (ComponentNull*) v;
1036 if ( mode & DEC_ALLOC_MODE_0 ) {
1037 k2 = (ComponentNull**) v;
1038 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
1039 if ( !*k2 ) return LDAP_DECODING_ERROR;
1043 if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1044 if ( k ) CompFree ( mem_op, k );
1045 return LDAP_DECODING_ERROR;
1047 k->value = result.value;
1049 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1050 if ( !k->comp_desc ) {
1051 if ( k ) CompFree ( mem_op, k );
1052 return LDAP_DECODING_ERROR;
1054 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
1055 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1056 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1057 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1058 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1059 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1060 k->comp_desc->cd_extract_i = NULL;
1061 k->comp_desc->cd_type = ASN_BASIC;
1062 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1063 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1065 return LDAP_SUCCESS;
1069 * Component BER Decoder : NULL
1072 BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1074 return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER );
1078 BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1079 AsnLen *bytesDecoded, int mode )
1083 void* component_values;
1084 ComponentNull* k, **k2;
1087 k = (ComponentNull*) v;
1089 if ( mode & DEC_ALLOC_MODE_0 ) {
1090 k2 = (ComponentNull**) v;
1091 *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
1092 if ( !*k2 ) return LDAP_DECODING_ERROR;
1096 if ( mode & CALL_TAG_DECODER ){
1097 mode = mode & CALL_CONTENT_DECODER;
1098 rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded );
1101 rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1104 if ( k ) CompFree ( mem_op, k );
1105 return LDAP_DECODING_ERROR;
1109 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1110 if ( !k->comp_desc ) {
1111 if ( k ) CompFree ( mem_op, k );
1112 return LDAP_DECODING_ERROR;
1114 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
1115 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
1116 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
1117 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
1118 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1119 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1120 k->comp_desc->cd_extract_i = NULL;
1121 k->comp_desc->cd_type = ASN_BASIC;
1122 k->comp_desc->cd_type_id = BASICTYPE_NULL;
1123 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNull;
1124 return LDAP_SUCCESS;
1128 * Component BER Decoder : NumericString
1131 BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1132 return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1136 BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1140 void* component_values;
1141 ComponentNumericString* k, **k2;
1142 NumericString result;
1144 k = (ComponentNumericString*) v;
1146 if ( mode & DEC_ALLOC_MODE_0 ) {
1147 k2 = (ComponentNumericString**) v;
1148 *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) );
1149 if ( !*k2 ) return LDAP_DECODING_ERROR;
1153 if ( mode & CALL_TAG_DECODER ){
1154 mode = mode & CALL_CONTENT_DECODER;
1155 rc = BDecNumericString ( mem_op, b, &result, bytesDecoded );
1157 rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded);
1160 if ( k ) CompFree ( mem_op, k );
1161 return LDAP_DECODING_ERROR;
1165 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1166 if ( !k->comp_desc ) {
1167 if ( k ) CompFree ( mem_op, k );
1168 return LDAP_DECODING_ERROR;
1170 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNumericString;
1171 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString;
1172 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString;
1173 k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString;
1174 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1175 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1176 k->comp_desc->cd_extract_i = NULL;
1177 k->comp_desc->cd_type = ASN_BASIC;
1178 k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR;
1179 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentNumericString;
1181 return LDAP_SUCCESS;
1186 * Free function : OCTET STRING
1189 FreeComponentOcts ( ComponentOcts* v) {
1190 FreeAsnOcts( &v->value );
1194 * Matching function : OCTET STRING
1197 MatchingComponentOcts ( char* oid, ComponentSyntaxInfo* csi_attr,
1198 ComponentSyntaxInfo* csi_assert )
1202 ComponentOcts *a, *b;
1205 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1207 return component_value_match( mr, csi_attr , csi_assert );
1209 a = (ComponentOcts*) csi_attr;
1210 b = (ComponentOcts*) csi_assert;
1211 /* Assume that both of OCTET string has end of string character */
1212 if ( (a->value.octetLen == b->value.octetLen) &&
1213 strncmp ( a->value.octs, b->value.octs, a->value.octetLen ) == 0 )
1214 return LDAP_COMPARE_TRUE;
1216 return LDAP_COMPARE_FALSE;
1220 * GSER Encoder : OCTET STRING
1223 GEncComponentOcts ( GenBuf* b, ComponentOcts *in )
1226 if ( !in || in->value.octetLen <= 0 )
1229 t.value = in->value;
1230 return GEncAsnOctsContent ( b, &t );
1234 * GSER Decoder : OCTET STRING
1237 GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1239 char *peek_head, *data;
1241 void* component_values;
1242 ComponentOcts* k, **k2;
1245 k = (ComponentOcts*) v;
1247 if ( mode & DEC_ALLOC_MODE_0 ) {
1248 k2 = (ComponentOcts**) v;
1249 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1250 if ( !*k2 ) return LDAP_DECODING_ERROR;
1254 if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1255 if ( k ) CompFree ( mem_op, k );
1256 return LDAP_DECODING_ERROR;
1258 k->value = result.value;
1260 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1261 if ( !k->comp_desc ) {
1262 if ( k ) CompFree ( mem_op, k );
1263 return LDAP_DECODING_ERROR;
1265 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
1266 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1267 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1268 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1269 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1270 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1271 k->comp_desc->cd_extract_i = NULL;
1272 k->comp_desc->cd_type = ASN_BASIC;
1273 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1274 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1276 return LDAP_SUCCESS;
1280 * Component BER Decoder : OCTET STRING
1283 BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1284 return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1288 BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1289 AsnLen *bytesDecoded, int mode )
1291 char *peek_head, *data;
1293 void* component_values;
1294 ComponentOcts* k, **k2;
1297 k = (ComponentOcts*) v;
1299 if ( mode & DEC_ALLOC_MODE_0 ) {
1300 k2 = (ComponentOcts**) v;
1301 *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
1302 if ( !*k2 ) return LDAP_DECODING_ERROR;
1306 if ( mode & CALL_TAG_DECODER ){
1307 mode = mode & CALL_CONTENT_DECODER;
1308 rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded );
1310 rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1313 if ( k ) CompFree ( mem_op, k );
1314 return LDAP_DECODING_ERROR;
1318 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1319 if ( !k->comp_desc ) {
1320 if ( k ) CompFree ( mem_op, k );
1321 return LDAP_DECODING_ERROR;
1323 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
1324 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
1325 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
1326 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
1327 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1328 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1329 k->comp_desc->cd_extract_i = NULL;
1330 k->comp_desc->cd_type = ASN_BASIC;
1331 k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
1332 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOcts;
1333 return LDAP_SUCCESS;
1337 * Matching function : OBJECT IDENTIFIER
1340 MatchingComponentOid ( char *oid, ComponentSyntaxInfo *csi_attr ,
1341 ComponentSyntaxInfo *csi_assert )
1345 ComponentOid *a, *b;
1348 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1350 return component_value_match( mr, csi_attr , csi_assert );
1353 a = (ComponentOid*)csi_attr;
1354 b = (ComponentOid*)csi_assert;
1355 if ( a->value.octetLen != b->value.octetLen )
1356 return LDAP_COMPARE_FALSE;
1357 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1359 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1363 * GSER Encoder : OID
1365 GEncComponentOid ( GenBuf *b, ComponentOid *in )
1369 if ( !in || in->value.octetLen <= 0 )
1371 t.value = in->value;
1372 return GEncAsnOidContent( b, (GAsnOcts*)&t );
1376 * GSER Decoder : OID
1379 GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){
1380 AttributeType *ad_type;
1385 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY );
1386 name.bv_val = peek_head;
1387 name.bv_len = strLen;
1389 ad_type = at_bvfind( &name );
1392 return LDAP_DECODING_ERROR;
1394 peek_head = ad_type->sat_atype.at_oid;
1395 strLen = strlen ( peek_head );
1397 result->value.octs = (char*)EncodeComponentOid ( mem_op, peek_head , &strLen );
1398 result->value.octetLen = strLen;
1399 return LDAP_SUCCESS;
1403 IsNumericOid ( char* peek_head , int strLen ) {
1406 for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) {
1407 if ( peek_head[i] == '.' ) num_dot++;
1408 else if ( peek_head[i] > '9' || peek_head[i] < '0' )
1418 GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1422 void* component_values;
1423 ComponentOid* k, **k2;
1426 k = (ComponentOid*) v;
1428 if ( mode & DEC_ALLOC_MODE_0 ) {
1429 k2 = (ComponentOid**) v;
1430 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1431 if ( !*k2 ) return LDAP_DECODING_ERROR;
1435 strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK );
1436 if ( IsNumericOid ( peek_head , strLen ) >= 1 ) {
1438 if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1439 if ( k ) CompFree ( mem_op, k );
1440 return LDAP_DECODING_ERROR;
1445 if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){
1446 if ( k ) CompFree ( mem_op, k );
1447 return LDAP_DECODING_ERROR;
1450 k->value = result.value;
1452 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1453 if ( !k->comp_desc ) {
1454 if ( k ) CompFree ( mem_op, k );
1455 return LDAP_DECODING_ERROR;
1457 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOid;
1458 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1459 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1460 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1461 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1462 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1463 k->comp_desc->cd_extract_i = NULL;
1464 k->comp_desc->cd_type = ASN_BASIC;
1465 k->comp_desc->cd_type_id = BASICTYPE_OID;
1466 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1468 return LDAP_SUCCESS;
1472 * Component BER Decoder : OID
1475 BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1476 return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1480 BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
1481 AsnLen *bytesDecoded, int mode )
1485 void* component_values;
1486 ComponentOid* k, **k2;
1489 k = (ComponentOid*) v;
1491 if ( mode & DEC_ALLOC_MODE_0 ) {
1492 k2 = (ComponentOid**) v;
1493 *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
1494 if ( !*k2 ) return LDAP_DECODING_ERROR;
1498 if ( mode & CALL_TAG_DECODER ){
1499 mode = mode & CALL_CONTENT_DECODER;
1500 rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded );
1502 rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1505 if ( k ) CompFree ( mem_op, k );
1506 return LDAP_DECODING_ERROR;
1510 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1511 if ( !k->comp_desc ) {
1512 if ( k ) CompFree ( mem_op, k );
1513 return LDAP_DECODING_ERROR;
1515 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOid;
1516 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
1517 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
1518 k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
1519 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1520 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1521 k->comp_desc->cd_extract_i = NULL;
1522 k->comp_desc->cd_type = ASN_BASIC;
1523 k->comp_desc->cd_type_id = BASICTYPE_OID;
1524 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
1525 return LDAP_SUCCESS;
1529 * Component BER Decoder : PrintiableString
1533 BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1535 return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1539 BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1543 void* component_values;
1544 ComponentPrintableString* k, **k2;
1547 k = (ComponentPrintableString*) v;
1549 if ( mode & DEC_ALLOC_MODE_0 ) {
1550 k2 = (ComponentPrintableString**) v;
1551 *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) );
1552 if ( !*k2 ) return LDAP_DECODING_ERROR;
1556 if ( mode & CALL_TAG_DECODER ) {
1557 mode = mode & CALL_CONTENT_DECODER;
1558 rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded );
1560 rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1563 if ( k ) CompFree ( mem_op, k );
1564 return LDAP_DECODING_ERROR;
1568 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1569 if ( !k->comp_desc ) {
1570 if ( k ) CompFree ( mem_op, k );
1571 return LDAP_DECODING_ERROR;
1573 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentPrintableString;
1574 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString;
1575 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString;
1576 k->comp_desc->cd_free = (comp_free_func*)FreeComponentPrintableString;
1577 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1578 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1579 k->comp_desc->cd_extract_i = NULL;
1580 k->comp_desc->cd_type = ASN_BASIC;
1581 k->comp_desc->cd_type_id = BASICTYPE_PRINTABLE_STR;
1582 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentPrintableString;
1583 return LDAP_SUCCESS;
1587 * Matching function : Real
1590 MatchingComponentReal (char* oid, ComponentSyntaxInfo *csi_attr,
1591 ComponentSyntaxInfo *csi_assert )
1595 ComponentReal *a, *b;
1598 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1600 return component_value_match( mr, csi_attr , csi_assert );
1602 a = (ComponentReal*)csi_attr;
1603 b = (ComponentReal*)csi_assert;
1604 rc = (a->value == b->value);
1606 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1610 * GSER Encoder : Real
1613 GEncComponentReal ( GenBuf *b, ComponentReal *in )
1618 t.value = in->value;
1619 return GEncAsnRealContent ( b, &t );
1623 * GSER Decoder : Real
1626 GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1630 void* component_values;
1631 ComponentReal* k, **k2;
1634 k = (ComponentReal*) v;
1636 if ( mode & DEC_ALLOC_MODE_0 ) {
1637 k2 = (ComponentReal**) v;
1638 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1639 if ( !*k2 ) return LDAP_DECODING_ERROR;
1643 if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1644 if ( k ) CompFree ( mem_op, k );
1645 return LDAP_DECODING_ERROR;
1647 k->value = result.value;
1649 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1650 if ( !k->comp_desc ) {
1651 if ( k ) CompFree ( mem_op, k );
1652 return LDAP_DECODING_ERROR;
1654 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentReal;
1655 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1656 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1657 k->comp_desc->cd_free = (comp_free_func*)NULL;
1658 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1659 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1660 k->comp_desc->cd_extract_i = NULL;
1661 k->comp_desc->cd_type = ASN_BASIC;
1662 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1663 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1665 return LDAP_SUCCESS;
1669 * Component BER Decoder : Real
1672 BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1673 return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1677 BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1681 void* component_values;
1682 ComponentReal* k, **k2;
1685 k = (ComponentReal*) v;
1687 if ( mode & DEC_ALLOC_MODE_0 ) {
1688 k2 = (ComponentReal**) v;
1689 *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
1690 if ( !*k2 ) return LDAP_DECODING_ERROR;
1694 if ( mode & CALL_TAG_DECODER ){
1695 mode = mode & CALL_CONTENT_DECODER;
1696 rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded );
1698 rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1701 if ( k ) CompFree ( mem_op, k );
1702 return LDAP_DECODING_ERROR;
1706 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1707 if ( !k->comp_desc ) {
1708 if ( k ) CompFree ( mem_op, k );
1709 return LDAP_DECODING_ERROR;
1711 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentReal;
1712 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
1713 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
1714 k->comp_desc->cd_free = (comp_free_func*)NULL;
1715 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1716 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1717 k->comp_desc->cd_extract_i = NULL;
1718 k->comp_desc->cd_type = ASN_BASIC;
1719 k->comp_desc->cd_type_id = BASICTYPE_REAL;
1720 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
1722 return LDAP_SUCCESS;
1726 * Matching function : Relative OID
1729 MatchingComponentRelativeOid ( char* oid, ComponentSyntaxInfo *csi_attr,
1730 ComponentSyntaxInfo *csi_assert )
1734 ComponentRelativeOid *a, *b;
1737 mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );
1739 return component_value_match( mr, csi_attr , csi_assert );
1742 a = (ComponentRelativeOid*)csi_attr;
1743 b = (ComponentRelativeOid*)csi_assert;
1745 if ( a->value.octetLen != b->value.octetLen )
1746 return LDAP_COMPARE_FALSE;
1747 rc = ( strncmp( a->value.octs, b->value.octs, a->value.octetLen ) == 0 );
1749 return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
1753 * GSER Encoder : RELATIVE_OID.
1756 GEncComponentRelativeOid ( GenBuf *b, ComponentRelativeOid *in )
1758 GAsnRelativeOid t = {0};
1760 if ( !in || in->value.octetLen <= 0 )
1762 t.value = in->value;
1763 return GEncAsnRelativeOidContent ( b , (GAsnOcts*)&t );
1767 * GSER Decoder : RELATIVE_OID.
1770 GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
1774 void* component_values;
1775 ComponentRelativeOid* k, **k2;
1776 GAsnRelativeOid result;
1778 k = (ComponentRelativeOid*) v;
1780 if ( mode & DEC_ALLOC_MODE_0 ) {
1781 k2 = (ComponentRelativeOid**) v;
1782 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1783 if ( !*k2 ) return LDAP_DECODING_ERROR;
1787 if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
1788 if ( k ) CompFree ( mem_op, k );
1789 return LDAP_DECODING_ERROR;
1791 k->value = result.value;
1793 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1794 if ( !k->comp_desc ) {
1795 if ( k ) CompFree ( mem_op, k );
1796 return LDAP_DECODING_ERROR;
1798 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentRelativeOid;
1799 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1800 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1801 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1802 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1803 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1804 k->comp_desc->cd_extract_i = NULL;
1805 k->comp_desc->cd_type = ASN_BASIC;
1806 k->comp_desc->cd_type_id = BASICTYPE_OID;
1807 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1809 return LDAP_SUCCESS;
1813 * Component BER Decoder : RELATIVE_OID.
1816 BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1817 return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1821 BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1825 void* component_values;
1826 ComponentRelativeOid* k, **k2;
1827 AsnRelativeOid result;
1829 k = (ComponentRelativeOid*) v;
1831 if ( mode & DEC_ALLOC_MODE_0 ) {
1832 k2 = (ComponentRelativeOid**) v;
1833 *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
1834 if ( !*k2 ) return LDAP_DECODING_ERROR;
1838 if ( mode & CALL_TAG_DECODER ){
1839 mode = mode & CALL_CONTENT_DECODER;
1840 rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded );
1842 rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1845 if ( k ) CompFree ( mem_op, k );
1846 return LDAP_DECODING_ERROR;
1850 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1851 if ( !k->comp_desc ) {
1852 if ( k ) CompFree ( mem_op, k );
1853 return LDAP_DECODING_ERROR;
1855 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentRelativeOid;
1856 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
1857 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
1858 k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
1859 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1860 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1861 k->comp_desc->cd_extract_i = NULL;
1862 k->comp_desc->cd_type = ASN_BASIC;
1863 k->comp_desc->cd_type_id = BASICTYPE_RELATIVE_OID;
1864 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
1865 return LDAP_SUCCESS;
1869 * GSER Encoder : UniversalString
1872 GEncComponentUniversalString ( GenBuf *b, ComponentUniversalString *in )
1874 GUniversalString t = {0};
1875 if ( !in || in->value.octetLen <= 0 )
1877 t.value = in->value;
1878 return GEncUniversalStringContent( b, &t );
1882 * GSER Decoder : UniversalString
1885 UTF8toUniversalString( char* octs, int len){
1886 /* Need to be Implemented */
1887 return LDAP_SUCCESS;
1891 GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
1893 if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 )
1894 UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen );
1895 return LDAP_DECODING_ERROR;
1899 * Component BER Decoder : UniverseString
1902 BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1903 return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1907 BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1911 void* component_values;
1912 ComponentUniversalString* k, **k2;
1913 UniversalString result;
1915 k = (ComponentUniversalString*) v;
1917 if ( mode & DEC_ALLOC_MODE_0 ) {
1918 k2 = (ComponentUniversalString**) v;
1919 *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) );
1920 if ( !*k2 ) return LDAP_DECODING_ERROR;
1924 if ( mode & CALL_TAG_DECODER ){
1925 mode = mode & CALL_CONTENT_DECODER;
1926 rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded );
1928 rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1931 if ( k ) CompFree ( mem_op, k );
1932 return LDAP_DECODING_ERROR;
1936 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1937 if ( !k->comp_desc ) {
1938 if ( k ) CompFree ( mem_op, k );
1939 return LDAP_DECODING_ERROR;
1941 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentUniversalString;
1942 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString;
1943 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString;
1944 k->comp_desc->cd_free = (comp_free_func*)FreeComponentUniversalString;
1945 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1946 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1947 k->comp_desc->cd_extract_i = NULL;
1948 k->comp_desc->cd_type = ASN_BASIC;
1949 k->comp_desc->cd_type_id = BASICTYPE_UNIVERSAL_STR;
1950 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUniversalString;
1951 return LDAP_SUCCESS;
1955 * Component BER Decoder : VisibleString
1958 BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
1959 return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
1963 BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
1967 void* component_values;
1968 ComponentVisibleString* k, **k2;
1969 VisibleString result;
1971 k = (ComponentVisibleString*) v;
1973 if ( mode & DEC_ALLOC_MODE_0 ) {
1974 k2 = (ComponentVisibleString**) v;
1975 *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) );
1976 if ( !*k2 ) return LDAP_DECODING_ERROR;
1980 if ( mode & CALL_TAG_DECODER ){
1981 mode = mode & CALL_CONTENT_DECODER;
1982 rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded );
1984 rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
1988 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
1989 if ( !k->comp_desc ) {
1990 if ( k ) CompFree ( mem_op, k );
1991 return LDAP_DECODING_ERROR;
1993 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentVisibleString;
1994 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentVisibleString;
1995 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString;
1996 k->comp_desc->cd_free = (comp_free_func*)FreeComponentVisibleString;
1997 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
1998 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
1999 k->comp_desc->cd_extract_i = NULL;
2000 k->comp_desc->cd_type = ASN_BASIC;
2001 k->comp_desc->cd_type_id = BASICTYPE_VISIBLE_STR;
2002 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentVisibleString;
2003 return LDAP_SUCCESS;
2007 * Routines for handling an ANY DEFINED Type
2010 /* Check if the <select> type CR and the OID of the given ANY type */
2012 CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo* cai, struct berval* select ) {
2014 AttributeType* ad_type;
2018 if ( IsNumericOid ( select->bv_val , select->bv_len ) ) {
2019 oid = select->bv_val;
2020 strLen = select->bv_len;
2022 ad_type = at_bvfind( select );
2025 return LDAP_DECODING_ERROR;
2027 oid = ad_type->sat_atype.at_oid;
2028 strLen = strlen ( oid );
2030 result = EncodeComponentOid ( mem_op, oid , &strLen );
2031 if ( !result || strLen <= 0 ) return (-1);
2033 if ( cai->oid.octetLen == strLen &&
2034 strncmp ( cai->oid.octs, result, strLen ) == 0 )
2041 SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) {
2045 /* use encoded oid as hash string */
2046 hash = MakeHash (id->value.octs, id->value.octetLen);
2047 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2048 v->cai = (ComponentAnyInfo*) anyInfo;
2054 * If not found, the data considered as octet chunk
2055 * Yet-to-be-Implemented
2058 return LDAP_SUCCESS;
2062 SetAnyTypeByComponentInt( ComponentAny *v, ComponentInt id) {
2066 hash = MakeHash ((char*)&id, sizeof (id));
2067 if (CheckForAndReturnValue (anyIntHashTblG, hash, &anyInfo))
2068 v->cai = (ComponentAnyInfo*) anyInfo;
2074 GEncComponentAny ( GenBuf *b, ComponentAny *in )
2076 if ( in->cai != NULL && in->cai->Encode != NULL )
2077 return in->cai->Encode(b, &in->value );
2083 BEncComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode)
2085 ComponentAny *k, **k2;
2087 k = (ComponentAny*) result;
2089 if ( !k ) return (-1);
2091 if ( mode & DEC_ALLOC_MODE_0 ) {
2092 k2 = (ComponentAny**) result;
2093 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2094 if ( !*k2 ) return LDAP_DECODING_ERROR;
2098 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
2099 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2100 if ( !result->value ) return 0;
2101 result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
2103 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2104 if ( !k->comp_desc ) {
2105 if ( k ) CompFree ( mem_op, k );
2106 return LDAP_DECODING_ERROR;
2108 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
2109 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2110 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2111 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2112 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
2113 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
2114 k->comp_desc->cd_extract_i = NULL;
2115 k->comp_desc->cd_type = ASN_BASIC;
2116 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2117 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2118 return LDAP_SUCCESS;
2121 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
2127 BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
2129 ComponentAny *k, **k2;
2131 k = (ComponentAny*) result;
2133 if ( !k ) return (-1);
2135 if ( mode & DEC_ALLOC_MODE_0 ) {
2136 k2 = (ComponentAny**) result;
2137 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2138 if ( !*k2 ) return LDAP_DECODING_ERROR;
2142 if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
2144 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2145 if ( !result->value ) return 0;
2147 result->cai->BER_Decode ( mem_op, b, (ComponentSyntaxInfo*)&result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_0 );
2149 rc = BDecComponentTop( result->cai->BER_Decode, mem_op, 0, 0, &result->value, bytesDecoded, DEC_ALLOC_MODE_0 );
2150 if ( rc != LDAP_SUCCESS ) return rc;
2153 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2154 if ( !k->comp_desc ) {
2155 if ( k ) CompFree ( mem_op, k );
2156 return LDAP_DECODING_ERROR;
2158 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
2159 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2160 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2161 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2162 k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
2163 k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
2164 k->comp_desc->cd_extract_i = NULL;
2165 k->comp_desc->cd_type = ASN_BASIC;
2166 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2167 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2168 return LDAP_SUCCESS;
2171 Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
2177 GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
2178 ComponentAny *k, **k2;
2180 k = (ComponentAny*) result;
2182 if ( mode & DEC_ALLOC_MODE_0 ) {
2183 k2 = (ComponentAny**) result;
2184 *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
2185 if ( !*k2 ) return LDAP_DECODING_ERROR;
2188 if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {
2189 result->value = (void*) CompAlloc ( mem_op, result->cai->size );
2190 if ( !result->value ) return 0;
2191 result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
2192 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
2193 if ( !k->comp_desc ) {
2194 if ( k ) CompFree ( mem_op, k );
2195 return LDAP_DECODING_ERROR;
2197 k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
2198 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
2199 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
2200 k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
2201 k->comp_desc->cd_type = ASN_BASIC;
2202 k->comp_desc->cd_extract_i = NULL;
2203 k->comp_desc->cd_type_id = BASICTYPE_ANY;
2204 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
2205 return LDAP_SUCCESS;
2208 Asn1Error ("ERROR - ANY Decode routine is NULL\n");
2214 MatchingComponentAny (char* oid, ComponentAny *result, ComponentAny *result2) {
2215 void *comp1, *comp2;
2217 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2218 comp1 = result->value;
2222 if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2223 comp2 = result2->value;
2227 if ((result->cai != NULL) && (result->cai->Match != NULL)) {
2228 if ( result->comp_desc->cd_type_id == BASICTYPE_ANY )
2229 return result->cai->Match(oid, comp1, comp2 );
2230 else if ( result2->comp_desc->cd_type_id == BASICTYPE_ANY )
2231 return result2->cai->Match(oid, comp1, comp2);
2233 return LDAP_INVALID_SYNTAX;
2236 Asn1Error ("ERROR - ANY Matching routine is NULL\n");
2237 return LDAP_INVALID_SYNTAX;
2242 ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) {
2243 if ((result->cai != NULL) && (result->cai->Extract != NULL)) {
2244 return (void*) result->cai->Extract( mem_op, cr , result->value );
2247 Asn1Error ("ERROR - ANY Extracting routine is NULL\n");
2253 FreeComponentAny (ComponentAny* any) {
2254 if ( any->cai != NULL && any->cai->Free != NULL ) {
2255 any->cai->Free( any->value );
2256 free ( ((ComponentSyntaxInfo*)any->value)->csi_comp_desc );
2257 free ( any->value );
2260 Asn1Error ("ERROR - ANY Free routine is NULL\n");
2264 InstallAnyByComponentInt (int anyId, ComponentInt intId, unsigned int size,
2265 EncodeFcn encode, gser_decoder_func* G_decode,
2266 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2267 MatchFcn match, FreeFcn free,
2270 ComponentAnyInfo *a;
2273 a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo));
2276 a->oid.octetLen = 0;
2280 a->GSER_Decode = G_decode;
2281 a->BER_Decode = B_decode;
2283 a->Extract = extract;
2287 if (anyIntHashTblG == NULL)
2288 anyIntHashTblG = InitHash();
2290 h = MakeHash ((char*)&intId, sizeof (intId));
2292 if(anyIntHashTblG != NULL)
2293 Insert(anyIntHashTblG, a, h);
2298 * OID and its corresponding decoder can be registerd with this func.
2299 * If contained types constrained by <select> are used,
2300 * their OID and decoder MUST be registered, otherwise it will return no entry.
2301 * An open type(ANY type) also need be registered.
2304 InstallOidDecoderMapping ( char* ch_oid, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match ) {
2309 strLen = strlen( ch_oid );
2310 if( strLen <= 0 ) return;
2311 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2312 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &strLen );
2313 oid.octetLen = strLen;
2314 if( strLen <= 0 ) return;
2317 InstallAnyByComponentOid ( 0, &oid, 0, encode, G_decode, B_decode,
2318 extract, match, NULL, NULL);
2319 comp_nibble_memory_free(mem_op);
2323 * Look up Oid-decoder mapping table by berval have either
2324 * oid or description
2327 RetrieveOidDecoderMappingbyBV( struct berval* in ) {
2328 if ( IsNumericOid ( in->bv_val, in->bv_len ) )
2329 return RetrieveOidDecoderMappingbyOid( in->bv_val, in->bv_len );
2331 return RetrieveOidDecoderMappingbyDesc( in->bv_val, in->bv_len );
2335 * Look up Oid-decoder mapping table by dotted OID
2338 RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len ) {
2345 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2346 oid.octs = EncodeComponentOid ( mem_op, ch_oid, &oid_len);
2347 oid.octetLen = oid_len;
2349 comp_nibble_memory_free( mem_op );
2353 /* use encoded oid as hash string */
2354 hash = MakeHash ( oid.octs, oid.octetLen);
2355 comp_nibble_memory_free( mem_op );
2356 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2357 return (OidDecoderMapping*) anyInfo;
2359 return (OidDecoderMapping*) NULL;
2364 * Look up Oid-decoder mapping table by description
2367 RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len ) {
2371 AttributeType* ad_type;
2376 bv.bv_len = desc_len;
2377 ad_type = at_bvfind( &bv );
2379 oid.octs = ad_type->sat_atype.at_oid;
2380 oid.octetLen = strlen ( oid.octs );
2383 return (OidDecoderMapping*) NULL;
2385 mem_op = comp_nibble_memory_allocator ( 128, 16 );
2387 oid.octs = EncodeComponentOid ( mem_op, oid.octs , (int*)&oid.octetLen );
2388 if( oid.octetLen <= 0 ) {
2389 comp_nibble_memory_free( mem_op );
2390 return (OidDecoderMapping*) NULL;
2393 /* use encoded oid as hash string */
2394 hash = MakeHash ( oid.octs, oid.octetLen);
2395 comp_nibble_memory_free( mem_op );
2396 if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
2397 return (OidDecoderMapping*) anyInfo;
2399 return (OidDecoderMapping*) NULL;
2403 InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size,
2404 EncodeFcn encode, gser_decoder_func* G_decode,
2405 ber_tag_decoder_func* B_decode, ExtractFcn extract,
2406 MatchFcn match, FreeFcn free, PrintFcn print)
2408 ComponentAnyInfo *a;
2411 a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
2414 a->oid.octs = malloc( oid->octetLen );
2415 memcpy ( a->oid.octs, oid->octs, oid->octetLen );
2416 a->oid.octetLen = oid->octetLen;
2420 a->GSER_Decode = G_decode;
2421 a->BER_Decode = B_decode;
2423 a->Extract = extract;
2427 h = MakeHash (oid->octs, oid->octetLen);
2429 if (anyOidHashTblG == NULL)
2430 anyOidHashTblG = InitHash();
2432 if(anyOidHashTblG != NULL)
2433 Insert(anyOidHashTblG, a, h);
2438 ber_decoder_func *decoder _AND_
2442 AsnLen elmtLen _AND_
2444 AsnLen *bytesDecoded _AND_
2446 tag = BDecTag ( b, bytesDecoded );
2447 elmtLen = BDecLen ( b, bytesDecoded );
2448 if ( elmtLen <= 0 ) return (-1);
2449 if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
2453 return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
2457 * ASN.1 specification of a distinguished name
2458 * DistinguishedName ::= RDNSequence
2459 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
2460 * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue
2461 * AttributeTypeandValue ::= SEQUENCE {
2462 * type AttributeType
2463 * value AttributeValue
2465 * When dnMatch/rdnMatch is used in a component assertion value
2466 * the component in DistinguishedName/RelativeDistinguishedName
2467 * need to be converted to the LDAP encodings in RFC2253
2468 * in order to be matched against the assertion value
2469 * If allComponentMatch is used, the assertion value may be
2470 * decoded into the Internal Representation(Component Tree)
2471 * by the corresponding GSER or BER decoder
2472 * Following routine converts a component tree(DistinguishedName) into
2473 * LDAP encodings in RFC2253
2475 * IR : ComponentRDNSequence
2476 * GSER : { { type cn, value sang },{ type o, value ibm}, {type c, value us} }
2477 * LDAP Encodings : cn=sang,o=ibm,c=us
2480 increment_bv_mem_by_size ( struct berval* in, int size ) {
2481 int new_size = in->bv_len + size;
2482 in->bv_val = realloc( in->bv_val, new_size );
2483 in->bv_len = new_size;
2487 ConvertBER2Desc( char* in, int size, struct berval* out, int* pos ) {
2490 unsigned int firstArcNum;
2491 unsigned int arcNum;
2492 int i, rc, start_pos = *pos;
2493 char buf[MAX_OID_LEN];
2495 struct berval bv_name;
2497 /*convert BER oid to desc*/
2498 for ( i = 0, arcNum = 0; (i < size) && (in[i] & 0x80 ); i++ )
2499 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2500 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2502 firstArcNum = (unsigned short)(arcNum/40);
2503 if ( firstArcNum > 2 )
2506 arcNum = arcNum - (firstArcNum * 40 );
2508 rc = intToAscii ( arcNum, buf );
2510 /*check if the buffer can store the first/second arc and two dots*/
2511 if ( out->bv_len < *pos + 2 + 1 + rc )
2512 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2514 if ( firstArcNum == 1)
2515 out->bv_val[*pos] = '1';
2517 out->bv_val[*pos] = '2';
2519 out->bv_val[*pos] = '.';
2522 memcpy( out->bv_val + *pos, buf, rc );
2524 out->bv_val[*pos] = '.';
2527 for ( ; i < size ; ) {
2528 for ( arcNum=0; (i < size) && (in[i] & 0x80) ; i++ )
2529 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2530 arcNum = (arcNum << 7) + (in[i] & 0x7f);
2533 rc = intToAscii ( arcNum, buf );
2535 if ( out->bv_len < *pos + rc + 1 )
2536 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2538 memcpy( out->bv_val + *pos, buf, rc );
2540 out->bv_val[*pos] = '.';
2543 (*pos)--;/*remove the last '.'*/
2546 * lookup OID database to locate desc
2547 * then overwrite OID with desc in *out
2548 * If failed to look up desc, OID form is used
2550 bv_name.bv_val = out->bv_val + start_pos;
2551 bv_name.bv_len = *pos - start_pos;
2552 at = at_bvfind( &bv_name );
2554 return LDAP_SUCCESS;
2555 desc_size = at->sat_cname.bv_len;
2556 memcpy( out->bv_val + start_pos, at->sat_cname.bv_val, desc_size );
2557 *pos = start_pos + desc_size;
2558 return LDAP_SUCCESS;
2562 ConvertComponentAttributeTypeAndValue2RFC2253 ( irAttributeTypeAndValue* in, struct berval* out, int *pos ) {
2564 int value_size = ((ComponentUTF8String*)in->value.value)->value.octetLen;
2565 char* value_ptr = ((ComponentUTF8String*)in->value.value)->value.octs;
2567 rc = ConvertBER2Desc( in->type.value.octs, in->type.value.octetLen, out, pos );
2568 if ( rc != LDAP_SUCCESS ) return rc;
2569 if ( out->bv_len < *pos + 1/*for '='*/ )
2570 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2571 /*Between type and value, put '='*/
2572 out->bv_val[*pos] = '=';
2575 /*Assume it is string*/
2576 if ( out->bv_len < *pos + value_size )
2577 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2578 memcpy( out->bv_val + *pos, value_ptr, value_size );
2579 out->bv_len += value_size;
2582 return LDAP_SUCCESS;
2586 ConvertRelativeDistinguishedName2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out , int* pos) {
2587 irAttributeTypeAndValue* attr_typeNvalue;
2591 FOR_EACH_LIST_ELMT( attr_typeNvalue, &in->comp_list)
2593 rc = ConvertComponentAttributeTypeAndValue2RFC2253( attr_typeNvalue, out, pos );
2594 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2596 if ( out->bv_len < *pos + 1/*for '+'*/ )
2597 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2598 /*between multivalued RDNs, put comma*/
2599 out->bv_val[(*pos)++] = '+';
2601 (*pos)--;/*remove the last '+'*/
2602 return LDAP_SUCCESS;
2606 ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out ) {
2608 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2609 out->bv_len = INITIAL_DN_SIZE;
2611 rc = ConvertRelativeDistinguishedName2RFC2253 ( in, out , &pos);
2612 if ( rc != LDAP_SUCCESS ) return rc;
2613 out->bv_val[pos] = '\0';
2615 return LDAP_SUCCESS;
2619 ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out ) {
2620 irRelativeDistinguishedName* rdn_seq;
2621 AsnList* seq = &in->comp_list;
2624 out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
2625 out->bv_len = INITIAL_DN_SIZE;
2627 FOR_EACH_LIST_ELMT( rdn_seq, seq )
2629 rc = ConvertRelativeDistinguishedName2RFC2253( rdn_seq, out, &pos );
2630 if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
2632 if ( out->bv_len < pos + 1/*for ','*/ )
2633 increment_bv_mem_by_size ( out, INCREMENT_SIZE );
2634 /*Between RDN, put comma*/
2635 out->bv_val[pos++] = ',';
2637 pos--;/*remove the last '+'*/
2638 out->bv_val[pos] = '\0';
2640 return LDAP_SUCCESS;