⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componentlib.c

📁 ldap服务器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Copyright 2004 IBM Corporation * All rights reserved. * Redisribution and use in source and binary forms, with or without * modification, are permitted only as authorizd by the OpenLADP * Public License. *//* ACKNOWLEDGEMENTS * This work originally developed by Sang Seok Lim * 2004/06/18	03:20:00	slim@OpenLDAP.org */#include "portable.h"#include <ac/string.h>#include <ac/socket.h>#include <ldap_pvt.h>#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>#include <string.h>#ifndef SLAPD_COMP_MATCH#define SLAPD_COMP_MATCH SLAPD_MOD_DYNAMIC#endif#ifdef SLAPD_COMP_MATCH/* * Matching function : BIT STRING */intMatchingComponentBits ( char* oid, ComponentSyntaxInfo *csi_attr,			ComponentSyntaxInfo *csi_assert ){	int rc;        MatchingRule* mr;        ComponentBits *a, *b;                                                                                  if ( oid ) {                mr = retrieve_matching_rule(oid, (AsnTypeId)csi_attr->csi_comp_desc->cd_type_id );                if ( mr )                        return component_value_match( mr, csi_attr , csi_assert );        }        a = ((ComponentBits*)csi_attr);        b = ((ComponentBits*)csi_assert);	rc = ( a->value.bitLen == b->value.bitLen && 		strncmp( a->value.bits,b->value.bits,a->value.bitLen ) == 0 );        return rc ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;}/* * Free function: BIT STRING */voidFreeComponentBits ( ComponentBits* v ) {	FreeAsnBits( &v->value );}/* * GSER Encoder : BIT STRING */intGEncComponentBits ( GenBuf *b, ComponentBits *in ){	GAsnBits bits = {0};	bits.value = in->value;	if ( !in )		return (-1);	return GEncAsnBitsContent ( b, &bits);}/* * GSER Decoder : BIT STRING */intGDecComponentBits ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ){        char* peek_head;        int i, strLen;        void* component_values;        ComponentBits* k, **k2;	GAsnBits result;        k = (ComponentBits*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentBits**) v;                *k2 = (ComponentBits*) CompAlloc( mem_op, sizeof( ComponentBits ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }        	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);	return LDAP_SUCCESS;}/* * Component BER Decoder : BIT STRING */intBDecComponentBitsTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {	return BDecComponentBits ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );}intBDecComponentBits ( 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;        ComponentBits* k, **k2;	AsnBits result;                                                                                  k = (ComponentBits*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentBits**) v;                *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;		rc = BDecAsnBits ( mem_op, b, &result, bytesDecoded );	} else {		rc = BDecAsnBitsContent ( 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_BITSTRING); 	return LDAP_SUCCESS;}/* * Component GSER BMPString Encoder */intGEncComponentBMPString ( 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 */intGDecComponentBMPString ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode){        char* peek_head;        int i, strLen;        void* component_values;        ComponentBMPString* k, **k2;	GBMPString result;                                                                                  k = (ComponentBMPString*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentBMPString**) v;                *k2 = (ComponentBMPString*) CompAlloc( mem_op, sizeof( ComponentBMPString ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }        *bytesDecoded = 0;	if ( GDecBMPStringContent ( 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_BMP_STR); 	return LDAP_SUCCESS;}/* * Component BER BMPString Decoder */intBDecComponentBMPStringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {	return BDecComponentBMPString ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );}intBDecComponentBMPString ( 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;        ComponentBMPString* k, **k2;	BMPString result;                                                                                  k = (ComponentBMPString*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentBMPString**) v;                *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;		rc = BDecBMPString ( mem_op, b, &result, bytesDecoded );	} else {		rc = BDecBMPStringContent ( 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_BMP_STR); 	return LDAP_SUCCESS;}/* * Component GSER Encoder : UTF8 String */intGEncComponentUTF8String ( 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 */intGDecComponentUTF8String ( void* mem_op, GenBuf *b, void *v,				AsnLen *bytesDecoded, int mode) {        char* peek_head;        int i, strLen;        void* component_values;        ComponentUTF8String* k, **k2;	GUTF8String result;                                                                                  k = (ComponentUTF8String*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentUTF8String**) v;                *k2 = (ComponentUTF8String*)CompAlloc( mem_op, sizeof( ComponentUTF8String ) );		if ( !*k2 ) return LDAP_DECODING_ERROR;                k = *k2;        }        *bytesDecoded = 0;	if ( GDecUTF8StringContent ( 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_UTF8_STR); 	return LDAP_SUCCESS;}/* * Component BER Decoder : UTF8String */intBDecComponentUTF8StringTag ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ) {	return BDecComponentUTF8String ( mem_op, b, 0, 0, v, bytesDecoded, mode|CALL_TAG_DECODER );}intBDecComponentUTF8String ( 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;        ComponentUTF8String* k, **k2;	UTF8String result;                                                                                  k = (ComponentUTF8String*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentUTF8String**) v;                *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;		rc = BDecUTF8String ( mem_op, b, &result, bytesDecoded );	} else {		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);	return LDAP_SUCCESS;}/* * Component GSER Encoder :  Teletex String */intGEncComponentTeletexString ( 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 */intGDecComponentTeletexString  ( void* mem_op, GenBuf *b, void *v,					AsnLen *bytesDecoded, int mode) {        char* peek_head;        int i, strLen;        void* component_values;        ComponentTeletexString* k, **k2;	GTeletexString 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;        }        *bytesDecoded = 0;	if ( GDecTeletexStringContent ( 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_VIDEOTEX_STR); 	return LDAP_SUCCESS;}/* * Matching function : BOOLEAN */intMatchingComponentBool(char* oid, ComponentSyntaxInfo* csi_attr,                        ComponentSyntaxInfo* csi_assert ){        MatchingRule* mr;        ComponentBool *a, *b;                                                                                  if( oid ) {                mr = retrieve_matching_rule(oid, csi_attr->csi_comp_desc->cd_type_id );                if ( mr )                        return component_value_match( mr, csi_attr , csi_assert );        }        a = ((ComponentBool*)csi_attr);        b = ((ComponentBool*)csi_assert);        return (a->value == b->value) ? LDAP_COMPARE_TRUE:LDAP_COMPARE_FALSE;}/* * GSER Encoder : BOOLEAN */intGEncComponentBool ( GenBuf *b, ComponentBool *in ){	GAsnBool t = {0};	if ( !in )		return (-1);	t.value = in->value;	return GEncAsnBoolContent ( b, &t );}/* * GSER Decoder : BOOLEAN */intGDecComponentBool ( void* mem_op, GenBuf *b, void *v, AsnLen *bytesDecoded, int mode ){        char* peek_head;        int i, strLen;        ComponentBool* k, **k2;	GAsnBool result;                                                                                  k = (ComponentBool*) v;                                                                                  if ( mode & DEC_ALLOC_MODE_0 ) {                k2 = (ComponentBool**) v;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -