#include "lutil.h"
#include <ldap.h>
#include "slap.h"
-
#include "component.h"
+
+#include "componentlib.h"
#include "asn.h"
#include <asn-gser.h>
#include <stdlib.h>
FreeAsnBits( &v->value );
}
+/*
+ * GSER Encoder : BIT STRING
+ */
+int
+GEncComponentBits ( GenBuf *b, ComponentBits *in )
+{
+ GAsnBits bits = {0};
+
+ bits.value = in->value;
+ if ( !in )
+ return (-1);
+ return GEncAsnBitsContent ( b, &bits);
+}
+
+
/*
* GSER Decoder : BIT STRING
*/
int
-GDecComponentBits ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBits**) v;
- *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) );
+ *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnBitsContent (b, &result, bytesDecoded );
+ if ( GDecAsnBitsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_BITSTRING);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
-
- /* Real Decoding code need to be followed */
return LDAP_SUCCESS;
}
* Component BER Decoder : BIT STRING
*/
int
-BDecComponentBitsTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentBits ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentBits ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentBits ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentBits* k, **k2;
AsnBits result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBits**) v;
- *k2 = (ComponentBits*) malloc( sizeof( ComponentBits ) );
- if ( !*k2 ) return -1;
+ *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnBits (b, &result, bytesDecoded );
+ rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnBitsContent (b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnBitsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
- k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( rc < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBits;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBits;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentBits;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BITSTRING;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBits;
+
+ k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_BITSTRING);
return LDAP_SUCCESS;
}
+/*
+ * Component GSER BMPString Encoder
+ */
+int
+GEncComponentBMPString ( GenBuf *b, ComponentBMPString *in )
+{
+ GBMPString t = {0};
+
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncBMPStringContent ( b, &t );
+}
+
/*
* Component GSER BMPString Decoder
*/
int
-GDecComponentBMPString (GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
+GDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode)
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBMPString**) v;
- *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) );
- if ( !*k2 ) return -1;
+ *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
*bytesDecoded = 0;
- GDecBMPStringContent ( b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecBMPStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
+
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_BMP_STR);
return LDAP_SUCCESS;
* Component BER BMPString Decoder
*/
int
-BDecComponentBMPStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentBMPString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentBMPString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentBMPString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentBMPString* k, **k2;
BMPString result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBMPString**) v;
- *k2 = (ComponentBMPString*) malloc( sizeof( ComponentBMPString ) );
+ *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecBMPString ( b, &result, bytesDecoded );
+ rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );
} else {
- BDecBMPStringContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecBMPStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
- k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( rc < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBMPString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBMPString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentBMPString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BMP_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBMPString;
+
+ k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_BMP_STR);
return LDAP_SUCCESS;
}
+/*
+ * Component GSER Encoder : UTF8 String
+ */
+int
+GEncComponentUTF8String ( GenBuf *b, ComponentUTF8String *in )
+{
+ GUTF8String t = {0};
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncUTF8StringContent ( b, &t );
+}
+
/*
* Component GSER Decoder : UTF8 String
*/
int
-GDecComponentUTF8String (GenBuf *b, void *v,
- AsnLen *bytesDecoded, int mode) {
+GDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,
+ AsnLen *bytesDecoded, int mode) {
char* peek_head;
int i, strLen;
void* component_values;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentUTF8String**) v;
- *k2 = (ComponentUTF8String*)malloc( sizeof( ComponentUTF8String ) );
+ *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
*bytesDecoded = 0;
- GDecUTF8StringContent ( b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecUTF8StringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
+
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_UTF8_STR);
return LDAP_SUCCESS;
}
* Component BER Decoder : UTF8String
*/
int
-BDecComponentUTF8StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentUTF8String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentUTF8String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentUTF8String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len,
+ void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentUTF8String* k, **k2;
UTF8String result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentUTF8String**) v;
- *k2 = (ComponentUTF8String*) malloc( sizeof( ComponentUTF8String ) );
+ *k2 = (ComponentUTF8String*) CompAlloc( mem_op, sizeof( ComponentUTF8String ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecUTF8String ( b, &result, bytesDecoded );
+ rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );
} else {
- BDecUTF8StringContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecUTF8StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
+ if ( rc < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+
k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_UTF8_STR);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUTF8String;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUTF8String;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentUTF8String;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_UTF8_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUTF8String;
+ return LDAP_SUCCESS;
+}
+
+/*
+ * Component GSER Encoder : Teletex String
+ */
+int
+GEncComponentTeletexString ( GenBuf *b, ComponentTeletexString *in )
+{
+ GTeletexString t = {0};
+
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncTeletexStringContent ( b, &t );
}
/*
* Component GSER Decoder : Teletex String
*/
int
-GDecComponentTeletexString (GenBuf *b, void *v,
+GDecComponentTeletexString ( void* mem_op, GenBuf *b, void *v,
AsnLen *bytesDecoded, int mode) {
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentTeletexString**) v;
- *k2 = (ComponentTeletexString*)malloc( sizeof( ComponentTeletexString ) );
+ *k2 = (ComponentTeletexString*)CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
*bytesDecoded = 0;
- GDecTeletexStringContent ( b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecTeletexStringContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTeletexString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTeletexString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentTeletexString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_VIDEOTEX_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTeletexString;
+
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_VIDEOTEX_STR);
return LDAP_SUCCESS;
}
return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : BOOLEAN
+ */
+int
+GEncComponentBool ( GenBuf *b, ComponentBool *in )
+{
+ GAsnBool t = {0};
+
+ if ( !in )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnBoolContent ( b, &t );
+}
+
/*
* GSER Decoder : BOOLEAN
*/
int
-GDecComponentBool ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBool**) v;
- *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) );
+ *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnBoolContent( b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecAsnBoolContent( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
+
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_BOOLEAN);
return LDAP_SUCCESS;
}
* Component BER Decoder : BOOLEAN
*/
int
-BDecComponentBoolTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentBool ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentBoolTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentBool ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentBool ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentBool ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
ComponentBool* k, **k2;
AsnBool result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentBool**) v;
- *k2 = (ComponentBool*) malloc( sizeof( ComponentBool ) );
+ *k2 = (ComponentBool*) CompAlloc( mem_op, sizeof( ComponentBool ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnBool ( b, &result, bytesDecoded );
+ rc = BDecAsnBool ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnBoolContent( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnBoolContent( mem_op, b, tagId, len, &result, bytesDecoded );
}
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+
k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_BOOLEAN);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentBool;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentBool;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_BOOLEAN;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentBool;
-
return LDAP_SUCCESS;
}
return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : ENUMERATE
+ */
+int
+GEncComponentEnum ( GenBuf *b, ComponentEnum *in )
+{
+ GAsnEnum t = {0};
+
+ if ( !in )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnEnumContent ( b, &t );
+}
+
/*
* GSER Decoder : ENUMERATE
*/
int
-GDecComponentEnum ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentEnum ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentEnum**) v;
- *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) );
+ *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnEnumContent ( b, &result, bytesDecoded );
+ if ( GDecAsnEnumContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+
k->value_identifier.bv_val = result.value_identifier;
k->value_identifier.bv_len = result.len;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
* Component BER Decoder : ENUMERATE
*/
int
-BDecComponentEnumTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentEnum ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentEnumTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentEnum ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentEnum ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentEnum ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentEnum* k, **k2;
AsnEnum result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentEnum**) v;
- *k2 = (ComponentEnum*) malloc( sizeof( ComponentEnum ) );
+ *k2 = (ComponentEnum*) CompAlloc( mem_op, sizeof( ComponentEnum ) );
+ if ( k ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnEnum ( b, &result, bytesDecoded );
+ rc = BDecAsnEnum ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnEnumContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnEnumContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentEnum;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentEnum;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentEnum;
k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_ENUMERATED;
}
/*
- * IA5String
+ * Component GSER Encoder : IA5String
*/
+int
+GEncComponentIA5Stirng ( GenBuf *b, ComponentIA5String* in )
+{
+ GIA5String t = {0};
+ t.value = in->value;
+ if ( !in || in->value.octetLen <= 0 ) return (-1);
+ return GEncIA5StringContent( b, &t );
+}
+
/*
* Component BER Decoder : IA5String
*/
int
-BDecComponentIA5StringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentIA5String ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentIA5StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentIA5String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentIA5String ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentIA5String ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentIA5String* k, **k2;
IA5String result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentIA5String**) v;
- *k2 = (ComponentIA5String*) malloc( sizeof( ComponentIA5String ) );
+ *k2 = (ComponentIA5String*) CompAlloc( mem_op, sizeof( ComponentIA5String ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecIA5String ( b, &result, bytesDecoded );
+ rc = BDecIA5String ( mem_op, b, &result, bytesDecoded );
} else {
- BDecIA5StringContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecIA5StringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentIA5String;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentIA5String;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentIA5String;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentIA5String;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_IA5_STR;
return ( a->value == b->value ) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : INTEGER
+ */
+int
+GEncComponentInt ( GenBuf *b, ComponentInt* in )
+{
+ GAsnInt t = {0};
+
+ if ( !in )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnIntContent ( b, &t );
+}
+
/*
* GSER Decoder : INTEGER
*/
int
-GDecComponentInt( GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
+GDecComponentInt( void* mem_op, GenBuf * b, void *v, AsnLen *bytesDecoded, int mode)
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentInt**) v;
- *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) );
+ *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnIntContent (b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecAsnIntContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_INTEGER );
return LDAP_SUCCESS;
}
* Component BER Decoder : INTEGER
*/
int
-BDecComponentIntTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentInt ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentIntTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentInt ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentInt ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentInt ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentInt* k, **k2;
AsnInt result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentInt**) v;
- *k2 = (ComponentInt*) malloc( sizeof( ComponentInt ) );
+ *k2 = (ComponentInt*) CompAlloc( mem_op, sizeof( ComponentInt ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnInt (b, &result, bytesDecoded );
+ rc = BDecAsnInt ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnIntContent (b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnIntContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_INTEGER;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt;
+ k->comp_desc = get_component_description (BASICTYPE_INTEGER );
return LDAP_SUCCESS;
}
return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : NULL
+ */
+int
+GEncComponentNull ( GenBuf *b, ComponentNull *in )
+{
+ GAsnNull t = {0};
+
+ if ( !in )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnNullContent ( b, &t );
+}
+
/*
* GSER Decoder : NULL
*/
int
-GDecComponentNull ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentNull ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentNull**) v;
- *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) );
+ *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnNullContent ( b, &result, bytesDecoded );
+ if ( GDecAsnNullContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
k->value = result.value;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_NULL;
* Component BER Decoder : NULL
*/
int
-BDecComponentNullTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+BDecComponentNullTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
- BDecComponentNull ( b, 0, 0, v,bytesDecoded,
- mode|CALL_TAG_DECODER );
+ return BDecComponentNull ( mem_op, b, 0, 0, v,bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentNull ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentNull ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentNull* k, **k2;
AsnNull result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentNull**) v;
- *k2 = (ComponentNull*) malloc( sizeof( ComponentNull ) );
+ *k2 = (ComponentNull*) CompAlloc( mem_op, sizeof( ComponentNull ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnNull ( b, &result, bytesDecoded );
+ rc = BDecAsnNull ( mem_op, b, &result, bytesDecoded );
}
else {
- BDecAsnNullContent ( b, tagId, len, &result, bytesDecoded);
+ rc = BDecAsnNullContent ( mem_op, b, tagId, len, &result, bytesDecoded);
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNull;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNull;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNull;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentNull;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_NULL;
* Component BER Decoder : NumericString
*/
int
-BDecComponentNumericStringTag ( GenBuf *b, void *v,
- AsnLen *bytesDecoded, int mode ) {
- BDecComponentNumericString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentNumericStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentNumericString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentNumericString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentNumericString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentNumericString* k, **k2;
NumericString result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentNumericString**) v;
- *k2 = (ComponentNumericString*) malloc( sizeof( ComponentNumericString ) );
+ *k2 = (ComponentNumericString*) CompAlloc( mem_op, sizeof( ComponentNumericString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecNumericString ( b, &result, bytesDecoded );
+ rc = BDecNumericString ( mem_op, b, &result, bytesDecoded );
} else {
- BDecNumericStringContent ( b, tagId, len, &result, bytesDecoded);
+ rc = BDecNumericStringContent ( mem_op, b, tagId, len, &result, bytesDecoded);
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentNumericString;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentNumericString;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentNumericString;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentNumericString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_NUMERIC_STR;
return LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : OCTET STRING
+ */
+int
+GEncComponentOcts ( GenBuf* b, ComponentOcts *in )
+{
+ GAsnOcts t = {0};
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+
+ t.value = in->value;
+ return GEncAsnOctsContent ( b, &t );
+}
+
/*
* GSER Decoder : OCTET STRING
*/
int
-GDecComponentOcts ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentOcts ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char *peek_head, *data;
int i, j, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentOcts**) v;
- *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) );
+ *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnOctsContent ( b, &result, bytesDecoded );
+ if ( GDecAsnOctsContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
k->value = result.value;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
* Component BER Decoder : OCTET STRING
*/
int
-BDecComponentOctsTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentOcts ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentOctsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentOcts ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentOcts ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentOcts ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char *peek_head, *data;
- int i, j, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentOcts* k, **k2;
AsnOcts result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentOcts**) v;
- *k2 = (ComponentOcts*) malloc( sizeof( ComponentOcts ) );
+ *k2 = (ComponentOcts*) CompAlloc( mem_op, sizeof( ComponentOcts ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnOcts ( b, &result, bytesDecoded );
+ rc = BDecAsnOcts ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnOctsContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnOctsContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentOcts;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOcts;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOcts;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentOcts;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_OCTETSTRING;
return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : OID
+ */
+GEncComponentOid ( GenBuf *b, ComponentOid *in )
+{
+ GAsnOid t = {0};
+
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnOidContent( b, (GAsnOcts*)&t );
+}
+
/*
* GSER Decoder : OID
*/
+int
+GDecAsnDescOidContent ( void* mem_op, GenBuf *b, GAsnOid *result, AsnLen *bytesDecoded ){
+ AttributeType *ad_type;
+ struct berval name;
+ char* peek_head;
+ int strLen;
+
+ strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_NO_COPY );
+ name.bv_val = peek_head;
+ name.bv_len = strLen;
+
+ ad_type = at_bvfind( &name );
+
+ if ( !ad_type )
+ return LDAP_DECODING_ERROR;
+
+ peek_head = ad_type->sat_atype.at_oid;
+ strLen = strlen ( peek_head );
+
+ result->value.octs = (char*)EncodeComponentOid ( mem_op, peek_head , &strLen );
+ result->value.octetLen = strLen;
+ return LDAP_SUCCESS;
+}
+
+int
+IsNumericOid ( char* peek_head , int strLen ) {
+ int i;
+ int num_dot;
+ for ( i = 0, num_dot = 0 ; i < strLen ; i++ ) {
+ if ( peek_head[i] == '.' ) num_dot++;
+ else if ( peek_head[i] > '9' || peek_head[i] < '0' )
+ return (-1);
+ }
+ if ( num_dot )
+ return (1);
+ else
+ return (-1);
+}
int
-GDecComponentOid ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentOid ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen, rc;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentOid**) v;
- *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) );
+ *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
-
- if ( (rc = GDecAsnOidContent ( b, &result, bytesDecoded )) == -1 )
- return rc;
- k->value = result.value;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ strLen = LocateNextGSERToken ( mem_op, b, &peek_head, GSER_PEEK );
+ if ( IsNumericOid ( peek_head , strLen ) >= 1 ) {
+ /* numeric-oid */
+ if ( GDecAsnOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_OID;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
+ else {
+ /*descr*/
+ if ( GDecAsnDescOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ){
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+ }
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_OID);
return LDAP_SUCCESS;
}
* Component BER Decoder : OID
*/
int
-BDecComponentOidTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentOid ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
+BDecComponentOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v,
AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentOid* k, **k2;
AsnOid result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentOid**) v;
- *k2 = (ComponentOid*) malloc( sizeof( ComponentOid ) );
+ *k2 = (ComponentOid*) CompAlloc( mem_op, sizeof( ComponentOid ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnOid ( b, &result, bytesDecoded );
+ rc = BDecAsnOid ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnOidContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentOid;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentOid;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentOid;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_OID;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentOid;
+ k->comp_desc = get_component_description (BASICTYPE_OID);
+
return LDAP_SUCCESS;
}
*/
int
-BDecComponentPrintableStringTag ( GenBuf *b, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentPrintableStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
- BDecComponentPrintableString ( b, 0, 0, v, bytesDecoded,
- mode|CALL_TAG_DECODER );
+ return BDecComponentPrintableString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentPrintableString( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentPrintableString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentPrintableString* k, **k2;
AsnOid result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentPrintableString**) v;
- *k2 = (ComponentPrintableString*) malloc( sizeof( ComponentPrintableString ) );
+ *k2 = (ComponentPrintableString*) CompAlloc( mem_op, sizeof( ComponentPrintableString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ) {
mode = mode & CALL_CONTENT_DECODER;
- BDecPrintableString ( b, &result, bytesDecoded );
+ rc = BDecPrintableString ( mem_op, b, &result, bytesDecoded );
} else {
- BDecPrintableStringContent ( b, tagId, len, &result, bytesDecoded );
- }
+ rc = BDecPrintableStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
k->value = result;
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = get_component_description (BASICTYPE_PRINTABLE_STR);
+
+ return LDAP_SUCCESS;
+}
+
+/*
+ * Component BER Decoder : TeletexString
+ */
+
+int
+BDecComponentTeletexStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+{
+ return BDecComponentTeletexString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+}
+
+int
+BDecComponentTeletexString( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
+{
+ char* peek_head;
+ int i, strLen, rc;
+ void* component_values;
+ ComponentTeletexString* k, **k2;
+ AsnOid result;
+
+ k = (ComponentTeletexString*) v;
+
+ if ( mode & DEC_ALLOC_MODE_0 ) {
+ k2 = (ComponentTeletexString**) v;
+ *k2 = (ComponentTeletexString*) CompAlloc( mem_op, sizeof( ComponentTeletexString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
+ k = *k2;
+ }
+
+ if ( mode & CALL_TAG_DECODER ) {
+ mode = mode & CALL_CONTENT_DECODER;
+ rc = BDecTeletexString ( mem_op, b, &result, bytesDecoded );
+ } else {
+ rc = BDecTeletexStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentPrintableString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentPrintableString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentPrintableString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_PRINTABLE_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentPrintableString;
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+ k->value = result;
+
+ k->comp_desc = get_component_description (BASICTYPE_T61_STR);
+
return LDAP_SUCCESS;
}
+
/*
* Matching function : Real
*/
return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : Real
+ */
+int
+GEncComponentReal ( GenBuf *b, ComponentReal *in )
+{
+ GAsnReal t = {0};
+ if ( !in )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnRealContent ( b, &t );
+}
+
/*
* GSER Decoder : Real
*/
int
-GDecComponentReal ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentReal ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentReal**) v;
- *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) );
+ *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnRealContent ( b, &result, bytesDecoded );
- k->value = result.value;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( GDecAsnRealContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_REAL;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
+ k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_REAL);
return LDAP_SUCCESS;
}
* Component BER Decoder : Real
*/
int
-BDecComponentRealTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentReal ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentRealTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentReal ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentReal ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentReal ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentReal* k, **k2;
AsnReal result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentReal**) v;
- *k2 = (ComponentReal*) malloc( sizeof( ComponentReal ) );
+ *k2 = (ComponentReal*) CompAlloc( mem_op, sizeof( ComponentReal ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnReal ( b, &result, bytesDecoded );
+ rc = BDecAsnReal ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnRealContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnRealContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
- k->value = result;
-
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentReal;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentReal;
- k->comp_desc->cd_free = (comp_free_func*)NULL;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_REAL;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentReal;
+ k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_REAL);
return LDAP_SUCCESS;
}
return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;
}
+/*
+ * GSER Encoder : RELATIVE_OID.
+ */
+int
+GEncComponentRelativeOid ( GenBuf *b, ComponentRelativeOid *in )
+{
+ GAsnRelativeOid t = {0};
+
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncAsnRelativeOidContent ( b , (GAsnOcts*)&t );
+}
+
/*
* GSER Decoder : RELATIVE_OID.
*/
int
-GDecComponentRelativeOid ( GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentRelativeOid ( void* mem_op, GenBuf *b,void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
int i, strLen;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentRelativeOid**) v;
- *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) );
+ *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
- GDecAsnRelativeOidContent ( b, &result, bytesDecoded );
+ if ( GDecAsnRelativeOidContent ( mem_op, b, &result, bytesDecoded ) < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
k->value = result.value;
+ k->comp_desc = get_component_description (BASICTYPE_OID);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_OID;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
-
return LDAP_SUCCESS;
}
* Component BER Decoder : RELATIVE_OID.
*/
int
-BDecComponentRelativeOidTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentRelativeOid ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentRelativeOidTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentRelativeOid ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentRelativeOid ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentRelativeOid ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentRelativeOid* k, **k2;
AsnRelativeOid result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentRelativeOid**) v;
- *k2 = (ComponentRelativeOid*) malloc( sizeof( ComponentRelativeOid ) );
+ *k2 = (ComponentRelativeOid*) CompAlloc( mem_op, sizeof( ComponentRelativeOid ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecAsnRelativeOid ( b, &result, bytesDecoded );
+ rc = BDecAsnRelativeOid ( mem_op, b, &result, bytesDecoded );
} else {
- BDecAsnRelativeOidContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecAsnRelativeOidContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_OID);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeOid;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeOid;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentRelativeOid;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_RELATIVE_OID;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeOid;
return LDAP_SUCCESS;
}
/*
- * GSER Decoder : UniverseString
+ * GSER Encoder : UniversalString
+ */
+int
+GEncComponentUniversalString ( GenBuf *b, ComponentUniversalString *in )
+{
+ GUniversalString t = {0};
+ if ( !in || in->value.octetLen <= 0 )
+ return (-1);
+ t.value = in->value;
+ return GEncUniversalStringContent( b, &t );
+}
+
+/*
+ * GSER Decoder : UniversalString
*/
static int
UTF8toUniversalString( char* octs, int len){
/* Need to be Implemented */
- return 1;
+ return LDAP_SUCCESS;
}
int
-GDecComponentUniversalString ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
+GDecComponentUniversalString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode )
{
- GDecComponentUTF8String (b, v, bytesDecoded, mode);
- UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs,
- ((ComponentUniversalString*)v)->value.octetLen );
+ if ( GDecComponentUTF8String ( mem_op, b, v, bytesDecoded, mode) < 0 )
+ UTF8toUniversalString( ((ComponentUniversalString*)v)->value.octs, ((ComponentUniversalString*)v)->value.octetLen );
+ return LDAP_DECODING_ERROR;
}
/*
* Component BER Decoder : UniverseString
*/
int
-BDecComponentUniversalStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded,
- int mode ) {
- BDecComponentUniversalString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentUniversalStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentUniversalString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentUniversalString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentUniversalString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentUniversalString* k, **k2;
UniversalString result;
-
+
k = (ComponentUniversalString*) v;
-
+
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentUniversalString**) v;
- *k2 = (ComponentUniversalString*) malloc( sizeof( ComponentUniversalString ) );
+ *k2 = (ComponentUniversalString*) CompAlloc( mem_op, sizeof( ComponentUniversalString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecUniversalString ( b, &result, bytesDecoded );
+ rc = BDecUniversalString ( mem_op, b, &result, bytesDecoded );
} else {
- BDecUniversalStringContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecUniversalStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
+ }
+ if ( rc < 0 ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_UNIVERSAL_STR);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentUniversalString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentUniversalString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentUniversalString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_UNIVERSAL_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentUniversalString;
return LDAP_SUCCESS;
}
-
-
/*
* Component BER Decoder : VisibleString
*/
int
-BDecComponentVisibleStringTag ( GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
- BDecComponentVisibleString ( b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
+BDecComponentVisibleStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {
+ return BDecComponentVisibleString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );
}
int
-BDecComponentVisibleString ( GenBuf *b, AsnTag tagId, AsnLen len, void *v,
- AsnLen *bytesDecoded, int mode )
+BDecComponentVisibleString ( void* mem_op, GenBuf *b, AsnTag tagId, AsnLen len, void *v, AsnLen *bytesDecoded, int mode )
{
char* peek_head;
- int i, strLen;
+ int i, strLen, rc;
void* component_values;
ComponentVisibleString* k, **k2;
VisibleString result;
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentVisibleString**) v;
- *k2 = (ComponentVisibleString*) malloc( sizeof( ComponentVisibleString ) );
+ *k2 = (ComponentVisibleString*) CompAlloc( mem_op, sizeof( ComponentVisibleString ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ( mode & CALL_TAG_DECODER ){
mode = mode & CALL_CONTENT_DECODER;
- BDecVisibleString ( b, &result, bytesDecoded );
+ rc = BDecVisibleString ( mem_op, b, &result, bytesDecoded );
} else {
- BDecVisibleStringContent ( b, tagId, len, &result, bytesDecoded );
+ rc = BDecVisibleStringContent ( mem_op, b, tagId, len, &result, bytesDecoded );
}
k->value = result;
+ k->comp_desc = get_component_description (BASICTYPE_VISIBLE_STR);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
- }
- k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentVisibleString;
- k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentVisibleString;
- k->comp_desc->cd_free = (comp_free_func*)FreeComponentVisibleString;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
- k->comp_desc->cd_extract_i = NULL;
- k->comp_desc->cd_type = ASN_BASIC;
- k->comp_desc->cd_type_id = BASICTYPE_VISIBLE_STR;
- k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentVisibleString;
return LDAP_SUCCESS;
}
/*
* Routines for handling an ANY DEFINED Type
*/
-void
+
+/* Check if the <select> type CR and the OID of the given ANY type */
+int
+CheckSelectTypeCorrect ( void* mem_op, ComponentAnyInfo* cai, struct berval* select ) {
+ int strLen;
+ AttributeType* ad_type;
+ char* oid;
+ char* result;
+
+ if ( IsNumericOid ( select->bv_val , select->bv_len ) ) {
+ oid = select->bv_val;
+ strLen = select->bv_len;
+ } else {
+ ad_type = at_bvfind( select );
+
+ if ( !ad_type )
+ return LDAP_DECODING_ERROR;
+
+ oid = ad_type->sat_atype.at_oid;
+ strLen = strlen ( oid );
+ }
+ result = EncodeComponentOid ( mem_op, oid , &strLen );
+ if ( !result || strLen <= 0 ) return (-1);
+
+ if ( cai->oid.octetLen == strLen &&
+ strncmp ( cai->oid.octs, result, strLen ) == 0 )
+ return (1);
+ else
+ return (-1);
+}
+
+int
SetAnyTypeByComponentOid ( ComponentAny *v, ComponentOid *id ) {
Hash hash;
void *anyInfo;
* Yet-to-be-Implemented
*/
}
+ return LDAP_SUCCESS;
}
void
}
int
-BDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
+GEncComponentAny ( GenBuf *b, ComponentAny *in )
+{
+ if ( in->cai != NULL && in->cai->Encode != NULL )
+ return in->cai->Encode(b, &in->value );
+ else
+ return (-1);
+}
+
+int
+BEncComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode)
+{
ComponentAny *k, **k2;
k = (ComponentAny*) result;
+
+ if ( !k ) return (-1);
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentAny**) result;
- *k2 = (ComponentAny*) malloc( sizeof( ComponentAny) );
+ *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
- result->value = (void*) malloc ( result->cai->size );
+ result->value = (void*) CompAlloc ( mem_op, result->cai->size );
if ( !result->value ) return 0;
- result->cai->BER_Decode (b, result->value, (int*)bytesDecoded,
- DEC_ALLOC_MODE_1);
+ result->cai->BER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
- k->comp_desc->cd_pretty = (slap_syntax_transform_func*)NULL;
- k->comp_desc->cd_validate = (slap_syntax_validate_func*)NULL;
k->comp_desc->cd_extract_i = NULL;
k->comp_desc->cd_type = ASN_BASIC;
k->comp_desc->cd_type_id = BASICTYPE_ANY;
}
int
-GDecComponentAny (GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
+BDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
+ int rc;
ComponentAny *k, **k2;
k = (ComponentAny*) result;
+
+ if ( !k ) return (-1);
if ( mode & DEC_ALLOC_MODE_0 ) {
k2 = (ComponentAny**) result;
- *k2 = (ComponentAny*) malloc( sizeof( ComponentAny) );
+ *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
+ k = *k2;
+ }
+
+ if ((result->cai != NULL) && (result->cai->BER_Decode != NULL)) {
+ result->cai->BER_Decode ( mem_op, b, (ComponentSyntaxInfo*)&result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_0 );
+
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
+ }
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
+ k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
+ k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
+ k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
+ k->comp_desc->cd_extract_i = NULL;
+ k->comp_desc->cd_type = ASN_BASIC;
+ k->comp_desc->cd_type_id = BASICTYPE_ANY;
+ k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAny;
+ return LDAP_SUCCESS;
+ }
+ else {
+ Asn1Error ("ERROR - Component ANY Decode routine is NULL\n");
+ return 0;
+ }
+}
+
+int
+GDecComponentAny ( void* mem_op, GenBuf *b, ComponentAny *result, AsnLen *bytesDecoded, int mode) {
+ ComponentAny *k, **k2;
+
+ k = (ComponentAny*) result;
+
+ if ( mode & DEC_ALLOC_MODE_0 ) {
+ k2 = (ComponentAny**) result;
+ *k2 = (ComponentAny*) CompAlloc( mem_op, sizeof( ComponentAny ) );
+ if ( !*k2 ) return LDAP_DECODING_ERROR;
k = *k2;
}
if ((result->cai != NULL) && (result->cai->GSER_Decode != NULL)) {
- result->value = (void*) malloc ( result->cai->size );
+ result->value = (void*) CompAlloc ( mem_op, result->cai->size );
if ( !result->value ) return 0;
- result->cai->GSER_Decode (b, result->value, (int*)bytesDecoded,
- DEC_ALLOC_MODE_1);
- k->comp_desc = malloc( sizeof( ComponentDesc ) );
- if ( mode & DEC_ALLOC_MODE_0 && !k->comp_desc ) {
- free ( *k2 );
- return -1;
+ result->cai->GSER_Decode ( mem_op, b, result->value, (int*)bytesDecoded, DEC_ALLOC_MODE_1);
+ k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) );
+ if ( !k->comp_desc ) {
+ if ( k ) CompFree ( mem_op, k );
+ return LDAP_DECODING_ERROR;
}
+ k->comp_desc->cd_gser_encoder = (encoder_func*)GEncComponentAny;
k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAny;
k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAny;
k->comp_desc->cd_free = (comp_free_func*)FreeComponentAny;
}
void*
-ExtractingComponentAny ( ComponentReference* cr, ComponentAny *result ) {
+ExtractingComponentAny ( void* mem_op, ComponentReference* cr, ComponentAny *result ) {
if ((result->cai != NULL) && (result->cai->Extract != NULL)) {
- return (void*) result->cai->Extract( cr , result->value );
+ return (void*) result->cai->Extract( mem_op, cr , result->value );
}
else {
Asn1Error ("ERROR - ANY Extracting routine is NULL\n");
ComponentAnyInfo *a;
Hash h;
- a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
+ a = (ComponentAnyInfo*) malloc(sizeof (ComponentAnyInfo));
a->anyId = anyId;
a->oid.octs = NULL;
a->oid.octetLen = 0;
Insert(anyIntHashTblG, a, h);
}
+
+/*
+ * OID and its corresponding decoder can be registerd with this func.
+ * If contained types constrained by <select> are used,
+ * their OID and decoder MUST be registered, otherwise it will return no entry.
+ * An open type(ANY type) also need be registered.
+ */
+void
+InstallOidDecoderMapping ( char* ch_oid, EncodeFcn encode, gser_decoder_func* G_decode, ber_tag_decoder_func* B_decode, ExtractFcn extract, MatchFcn match ) {
+ AsnOid oid;
+ int strLen;
+ void* mem_op;
+
+ strLen = strlen( ch_oid );
+ if( strLen <= 0 ) return;
+ mem_op = comp_nibble_memory_allocator ( 128, 16 );
+ oid.octs = EncodeComponentOid ( mem_op, ch_oid, &strLen );
+ oid.octetLen = strLen;
+ if( strLen <= 0 ) return;
+
+
+ InstallAnyByComponentOid ( 0, &oid, 0, encode, G_decode, B_decode,
+ extract, match, NULL, NULL);
+ comp_nibble_memory_free(mem_op);
+}
+
+/*
+ * Look up Oid-decoder mapping table by berval have either
+ * oid or description
+ */
+OidDecoderMapping*
+RetrieveOidDecoderMappingbyBV( struct berval* in ) {
+ if ( IsNumericOid ( in->bv_val, in->bv_len ) )
+ return RetrieveOidDecoderMappingbyOid( in->bv_val, in->bv_len );
+ else
+ return RetrieveOidDecoderMappingbyDesc( in->bv_val, in->bv_len );
+}
+
+/*
+ * Look up Oid-decoder mapping table by dotted OID
+ */
+OidDecoderMapping*
+RetrieveOidDecoderMappingbyOid( char* ch_oid, int oid_len ) {
+ Hash hash;
+ void *anyInfo;
+ AsnOid oid;
+ int strLen;
+ void* mem_op;
+
+ mem_op = comp_nibble_memory_allocator ( 128, 16 );
+ oid.octs = EncodeComponentOid ( mem_op, ch_oid, &oid_len);
+ oid.octetLen = oid_len;
+ if( oid_len <= 0 ) {
+ comp_nibble_memory_free( mem_op );
+ return NULL;
+ }
+
+ /* use encoded oid as hash string */
+ hash = MakeHash ( oid.octs, oid.octetLen);
+ comp_nibble_memory_free( mem_op );
+ if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
+ return (OidDecoderMapping*) anyInfo;
+ else
+ return (OidDecoderMapping*) NULL;
+
+}
+
+/*
+ * Look up Oid-decoder mapping table by description
+ */
+OidDecoderMapping*
+RetrieveOidDecoderMappingbyDesc( char* desc, int desc_len ) {
+ Hash hash;
+ void *anyInfo;
+ AsnOid oid;
+ AttributeType* ad_type;
+ struct berval bv;
+ void* mem_op;
+
+ bv.bv_val = desc;
+ bv.bv_len = desc_len;
+ ad_type = at_bvfind( &bv );
+
+ oid.octs = ad_type->sat_atype.at_oid;
+ oid.octetLen = strlen ( oid.octs );
+
+ if ( !ad_type )
+ return (OidDecoderMapping*) NULL;
+
+ mem_op = comp_nibble_memory_allocator ( 128, 16 );
+
+ oid.octs = EncodeComponentOid ( mem_op, oid.octs , (int*)&oid.octetLen );
+ if( oid.octetLen <= 0 ) {
+ comp_nibble_memory_free( mem_op );
+ return (OidDecoderMapping*) NULL;
+ }
+
+ /* use encoded oid as hash string */
+ hash = MakeHash ( oid.octs, oid.octetLen);
+ comp_nibble_memory_free( mem_op );
+ if (CheckForAndReturnValue (anyOidHashTblG, hash, &anyInfo))
+ return (OidDecoderMapping*) anyInfo;
+ else
+ return (OidDecoderMapping*) NULL;
+
+}
void
InstallAnyByComponentOid (int anyId, AsnOid *oid, unsigned int size,
EncodeFcn encode, gser_decoder_func* G_decode,
a = (ComponentAnyInfo*) malloc (sizeof (ComponentAnyInfo));
a->anyId = anyId;
- a->oid.octs = NULL;
- a->oid.octetLen = 0;
+ if ( oid ) {
+ a->oid.octs = malloc( oid->octetLen );
+ memcpy ( a->oid.octs, oid->octs, oid->octetLen );
+ a->oid.octetLen = oid->octetLen;
+ }
a->size = size;
a->Encode = encode;
a->GSER_Decode = G_decode;
int
BDecComponentTop (
ber_decoder_func *decoder _AND_
+void* mem_op _AND_
GenBuf *b _AND_
AsnTag tag _AND_
AsnLen elmtLen _AND_
int mode) {
tag = BDecTag ( b, bytesDecoded );
elmtLen = BDecLen ( b, bytesDecoded );
+ if ( elmtLen <= 0 ) return (-1);
if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) {
- printf("Invliad Tag\n");
- exit (1);
+ return (-1);
}
- return (*decoder)( b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
+ return (*decoder)( mem_op, b, tag, elmtLen, (ComponentSyntaxInfo*)v,(int*)bytesDecoded, mode );
+}
+
+/*
+ * ASN.1 specification of a distinguished name
+ * DistinguishedName ::= RDNSequence
+ * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+ * RelativeDistinguishedName ::= SET SIZE(1..MAX) OF AttributeTypeandValue
+ * AttributeTypeandValue ::= SEQUENCE {
+ * type AttributeType
+ * value AttributeValue
+ * }
+ * When dnMatch/rdnMatch is used in a component assertion value
+ * the component in DistinguishedName/RelativeDistinguishedName
+ * need to be converted to the LDAP encodings in RFC2253
+ * in order to be matched against the assertion value
+ * If allComponentMatch is used, the assertion value may be
+ * decoded into the Internal Representation(Component Tree)
+ * by the corresponding GSER or BER decoder
+ * Following routine converts a component tree(DistinguishedName) into
+ * LDAP encodings in RFC2253
+ * Example)
+ * IR : ComponentRDNSequence
+ * GSER : { { type cn, value sang },{ type o, value ibm}, {type c, value us} }
+ * LDAP Encodings : cn=sang,o=ibm,c=us
+ */
+
+increment_bv_mem_by_size ( struct berval* in, int size ) {
+ int new_size = in->bv_len + size;
+ in->bv_val = realloc( in->bv_val, new_size );
+ in->bv_len = new_size;
+}
+
+int
+ConvertBER2Desc( char* in, int size, struct berval* out, int* pos ) {
+ int desc_size;
+ char* desc_ptr;
+ unsigned int firstArcNum;
+ unsigned int arcNum;
+ int i, rc, start_pos = *pos;
+ char buf[MAX_OID_LEN];
+ AttributeType *at;
+ struct berval bv_name;
+
+ /*convert BER oid to desc*/
+ for ( i = 0, arcNum = 0; (i < size) && (in[i] & 0x80 ); i++ )
+ arcNum = (arcNum << 7) + (in[i] & 0x7f);
+ arcNum = (arcNum << 7) + (in[i] & 0x7f);
+ i++;
+ firstArcNum = (unsigned short)(arcNum/40);
+ if ( firstArcNum > 2 )
+ firstArcNum = 2;
+
+ arcNum = arcNum - (firstArcNum * 40 );
+
+ rc = intToAscii ( arcNum, buf );
+
+ /*check if the buffer can store the first/second arc and two dots*/
+ if ( out->bv_len < *pos + 2 + 1 + rc )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+
+ if ( firstArcNum == 1)
+ out->bv_val[*pos] = '1';
+ else
+ out->bv_val[*pos] = '2';
+ (*pos)++;
+ out->bv_val[*pos] = '.';
+ (*pos)++;
+
+ memcpy( out->bv_val + *pos, buf, rc );
+ *pos += rc;
+ out->bv_val[*pos] = '.';
+ (*pos)++;
+
+ for ( ; i < size ; ) {
+ for ( arcNum=0; (i < size) && (in[i] & 0x80) ; i++ )
+ arcNum = (arcNum << 7) + (in[i] & 0x7f);
+ arcNum = (arcNum << 7) + (in[i] & 0x7f);
+ i++;
+
+ rc = intToAscii ( arcNum, buf );
+
+ if ( out->bv_len < *pos + rc + 1 )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+
+ memcpy( out->bv_val + *pos, buf, rc );
+ *pos += rc;
+ out->bv_val[*pos] = '.';
+ (*pos)++;
+ }
+ (*pos)--;/*remove the last '.'*/
+
+ /*
+ * lookup OID database to locate desc
+ * then overwrite OID with desc in *out
+ * If failed to look up desc, OID form is used
+ */
+ bv_name.bv_val = out->bv_val + start_pos;
+ bv_name.bv_len = *pos - start_pos;
+ at = at_bvfind( &bv_name );
+ if ( !at )
+ return LDAP_SUCCESS;
+ desc_size = at->sat_cname.bv_len;
+ memcpy( out->bv_val + start_pos, at->sat_cname.bv_val, desc_size );
+ *pos = start_pos + desc_size;
+ return LDAP_SUCCESS;
+}
+
+int
+ConvertComponentAttributeTypeAndValue2RFC2253 ( irAttributeTypeAndValue* in, struct berval* out, int *pos ) {
+ int rc;
+ int value_size = ((ComponentUTF8String*)in->value.value)->value.octetLen;
+ char* value_ptr = ((ComponentUTF8String*)in->value.value)->value.octs;
+
+ rc = ConvertBER2Desc( in->type.value.octs, in->type.value.octetLen, out, pos );
+ if ( rc != LDAP_SUCCESS ) return rc;
+ if ( out->bv_len < *pos + 1/*for '='*/ )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+ /*Between type and value, put '='*/
+ out->bv_val[*pos] = '=';
+ (*pos)++;
+
+ /*Assume it is string*/
+ if ( out->bv_len < *pos + value_size )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+ memcpy( out->bv_val + *pos, value_ptr, value_size );
+ out->bv_len += value_size;
+ *pos += value_size;
+
+ return LDAP_SUCCESS;
+}
+
+int
+ConvertRelativeDistinguishedName2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out , int* pos) {
+ irAttributeTypeAndValue* attr_typeNvalue;
+ int rc;
+
+
+ FOR_EACH_LIST_ELMT( attr_typeNvalue, &in->comp_list)
+ {
+ rc = ConvertComponentAttributeTypeAndValue2RFC2253( attr_typeNvalue, out, pos );
+ if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
+
+ if ( out->bv_len < *pos + 1/*for '+'*/ )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+ /*between multivalued RDNs, put comma*/
+ out->bv_val[(*pos)++] = '+';
+ }
+ (*pos)--;/*remove the last '+'*/
+ return LDAP_SUCCESS;
+}
+
+int
+ConvertRDN2RFC2253 ( irRelativeDistinguishedName* in, struct berval *out ) {
+ int rc, pos = 0;
+ out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
+ out->bv_len = INITIAL_DN_SIZE;
+
+ rc = ConvertRelativeDistinguishedName2RFC2253 ( in, out , &pos);
+ if ( rc != LDAP_SUCCESS ) return rc;
+ out->bv_val[pos] = '\0';
+ out->bv_len = pos;
+ return LDAP_SUCCESS;
+}
+
+int
+ConvertRDNSequence2RFC2253( irRDNSequence *in, struct berval* out ) {
+ irRelativeDistinguishedName* rdn_seq;
+ AsnList* seq = &in->comp_list;
+ int pos = 0, rc ;
+
+ out->bv_val = (char*)malloc( INITIAL_DN_SIZE );
+ out->bv_len = INITIAL_DN_SIZE;
+
+ FOR_EACH_LIST_ELMT( rdn_seq, seq )
+ {
+ rc = ConvertRelativeDistinguishedName2RFC2253( rdn_seq, out, &pos );
+ if ( rc != LDAP_SUCCESS ) return LDAP_INVALID_SYNTAX;
+
+ if ( out->bv_len < pos + 1/*for ','*/ )
+ increment_bv_mem_by_size ( out, INCREMENT_SIZE );
+ /*Between RDN, put comma*/
+ out->bv_val[pos++] = ',';
+ }
+ pos--;/*remove the last '+'*/
+ out->bv_val[pos] = '\0';
+ out->bv_len =pos;
+ return LDAP_SUCCESS;
}
#endif