1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 * Copyright 1999-2009 The OpenLDAP Foundation.
4 * Portions Copyright 1999 Dmitry Kovalev.
5 * Portions Copyright 2004 Pierangelo Masarati.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software. Additional significant contributors include
19 * Pierangelo Masarati.
25 #include <sys/types.h>
26 #include "ac/string.h"
29 #include "proto-sql.h"
31 static backsql_api *backsqlapi;
34 backsql_api_config( backsql_info *bi, const char *name, int argc, char *argv[] )
39 assert( name != NULL );
41 for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
42 if ( strcasecmp( name, ba->ba_name ) == 0 ) {
45 ba2 = ch_malloc( sizeof( backsql_api ) );
48 if ( ba2->ba_config ) {
49 if ( ( *ba2->ba_config )( ba2, argc, argv ) ) {
55 ba2->ba_next = bi->sql_api;
65 backsql_api_destroy( backsql_info *bi )
77 for ( ; ba; ba = ba->ba_next ) {
78 if ( ba->ba_destroy ) {
79 (void)( *ba->ba_destroy )( ba );
87 backsql_api_register( backsql_api *ba )
92 assert( ba->ba_private == NULL );
94 if ( ba->ba_name == NULL ) {
95 fprintf( stderr, "API module has no name\n" );
99 for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
100 if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
101 fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
102 exit( EXIT_FAILURE );
106 ba->ba_next = backsqlapi;
113 backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
115 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
126 ber_dupbv( &bv, dn );
128 for ( ; ba; ba = ba->ba_next ) {
129 if ( ba->ba_dn2odbc ) {
131 * The dn2odbc() helper is supposed to rewrite
132 * the contents of bv, freeing the original value
133 * with ch_free() if required and replacing it
134 * with a newly allocated one using ch_malloc()
135 * or companion functions.
137 * NOTE: it is supposed to __always__ free
138 * the value of bv in case of error, and reset
139 * it with BER_BVZERO() .
141 rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
144 /* in case of error, dn2odbc() must cleanup */
145 assert( BER_BVISNULL( &bv ) );
152 assert( !BER_BVISNULL( &bv ) );
160 backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
162 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
173 ber_dupbv( &bv, dn );
175 for ( ; ba; ba = ba->ba_next ) {
176 if ( ba->ba_dn2odbc ) {
177 rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
179 * The odbc2dn() helper is supposed to rewrite
180 * the contents of bv, freeing the original value
181 * with ch_free() if required and replacing it
182 * with a newly allocated one using ch_malloc()
183 * or companion functions.
185 * NOTE: it is supposed to __always__ free
186 * the value of bv in case of error, and reset
187 * it with BER_BVZERO() .
190 /* in case of error, odbc2dn() must cleanup */
191 assert( BER_BVISNULL( &bv ) );
198 assert( !BER_BVISNULL( &bv ) );