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.
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 )
41 for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
42 if ( strcasecmp( name, ba->ba_name ) == 0 ) {
45 ba2 = ch_malloc( sizeof( backsql_api ) );
47 ba2->ba_next = bi->sql_api;
57 backsql_api_register( backsql_api *ba )
63 if ( ba->ba_name == NULL ) {
64 fprintf( stderr, "API module has no name\n" );
68 for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
69 if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
70 fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
75 ba->ba_next = backsqlapi;
82 backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
84 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
97 for ( ; ba; ba = ba->ba_next ) {
98 if ( ba->ba_dn2odbc ) {
100 * The dn2odbc() helper is supposed to rewrite
101 * the contents of bv, freeing the original value
102 * with ch_free() if required and replacing it
103 * with a newly allocated one using ch_malloc()
104 * or companion functions.
106 * NOTE: it is supposed to __always__ free
107 * the value of bv in case of error, and reset
108 * it with BER_BVZERO() .
110 rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
113 /* in case of error, dn2odbc() must cleanup */
114 assert( BER_BVISNULL( &bv ) );
121 assert( !BER_BVISNULL( &bv ) );
129 backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
131 backsql_info *bi = (backsql_info *)op->o_bd->be_private;
142 ber_dupbv( &bv, dn );
144 for ( ; ba; ba = ba->ba_next ) {
145 if ( ba->ba_dn2odbc ) {
146 rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
148 * The odbc2dn() helper is supposed to rewrite
149 * the contents of bv, freeing the original value
150 * with ch_free() if required and replacing it
151 * with a newly allocated one using ch_malloc()
152 * or companion functions.
154 * NOTE: it is supposed to __always__ free
155 * the value of bv in case of error, and reset
156 * it with BER_BVZERO() .
159 /* in case of error, odbc2dn() must cleanup */
160 assert( BER_BVISNULL( &bv ) );
167 assert( !BER_BVISNULL( &bv ) );