1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 * Copyright 1999-2005 The OpenLDAP Foundation.
4 * Portions Copyright 1999 Dmitry Kovalev.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Dmitry Kovalev for inclusion
17 * by OpenLDAP Software.
23 #include <sys/types.h>
24 #include "ac/string.h"
27 #include "proto-sql.h"
29 static backsql_api *backsqlapi;
32 backsql_api_config( backsql_info *bi, const char *name )
39 for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
40 if ( strcasecmp( name, ba->ba_name ) == 0 ) {
43 ba2 = ch_malloc( sizeof( backsql_api ) );
45 ba2->ba_next = bi->sql_api;
55 backsql_api_register( backsql_api *ba )
61 if ( ba->ba_name == NULL ) {
62 fprintf( stderr, "API module has no name\n" );
66 for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
67 if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
68 fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
73 ba->ba_next = backsqlapi;
80 backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
82 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
95 for ( ; ba; ba = ba->ba_next ) {
96 if ( ba->ba_dn2odbc ) {
98 * The dn2odbc() helper is supposed to rewrite
99 * the contents of bv, freeing the original value
100 * with ch_free() if required and replacing it
101 * with a newly allocated one using ch_malloc()
102 * or companion functions.
104 * NOTE: it is supposed to __always__ free
105 * the value of bv in case of error, and reset
106 * it with BER_BVZERO() .
108 rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
111 /* in case of error, dn2odbc() must cleanup */
112 assert( BER_BVISNULL( &bv ) );
119 assert( !BER_BVISNULL( &bv ) );
127 backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
129 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
140 ber_dupbv( &bv, dn );
142 for ( ; ba; ba = ba->ba_next ) {
143 if ( ba->ba_dn2odbc ) {
144 rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
146 * The odbc2dn() helper is supposed to rewrite
147 * the contents of bv, freeing the original value
148 * with ch_free() if required and replacing it
149 * with a newly allocated one using ch_malloc()
150 * or companion functions.
152 * NOTE: it is supposed to __always__ free
153 * the value of bv in case of error, and reset
154 * it with BER_BVZERO() .
157 /* in case of error, odbc2dn() must cleanup */
158 assert( BER_BVISNULL( &bv ) );
165 assert( !BER_BVISNULL( &bv ) );