]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/api.c
Added provisions for a layer between the backend and the ODBC
[openldap] / servers / slapd / back-sql / api.c
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2  *
3  * Copyright 1999-2004 The OpenLDAP Foundation.
4  * Portions Copyright 1999 Dmitry Kovalev.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
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>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by Dmitry Kovalev for inclusion
17  * by OpenLDAP Software.
18  */
19
20 #include "portable.h"
21
22 #ifdef SLAPD_SQL
23
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include "ac/string.h"
27
28 #include "slap.h"
29 #include "lber_pvt.h"
30 #include "ldap_pvt.h"
31 #include "proto-sql.h"
32
33 static backsql_api *backsqlapi;
34
35 int
36 backsql_api_config( backsql_info *si, const char *name )
37 {
38         backsql_api     *ba;
39
40         assert( si );
41         assert( name );
42
43         for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
44                 if ( strcasecmp( name, ba->ba_name ) == 0 ) {
45                         backsql_api     *ba2;
46
47                         ba2 = ch_malloc( sizeof( backsql_api ) );
48                         *ba2 = *ba;
49                         ba2->ba_next = si->si_api;
50                         si->si_api = ba2;
51                         return 0;
52                 }
53         }
54
55         return 1;
56 }
57
58 int
59 backsql_api_register( backsql_api *ba )
60 {
61         backsql_api     *ba2;
62
63         assert( ba );
64
65         if ( ba->ba_name == NULL ) {
66                 fprintf( stderr, "API module has no name\n" );
67                 exit(EXIT_FAILURE);
68         }
69
70         for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
71                 if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
72                         fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
73                         exit(EXIT_FAILURE);
74                 }
75         }
76
77         ba->ba_next = backsqlapi;
78         backsqlapi = ba;
79
80         return 0;
81 }
82
83 int
84 backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
85 {
86         backsql_info    *si = (backsql_info *)op->o_bd->be_private;
87         backsql_api     *ba;
88         int             rc;
89         struct berval   bv;
90
91         ba = si->si_api;
92
93         if ( ba == NULL ) {
94                 return 0;
95         }
96
97         ber_dupbv( &bv, dn );
98
99         for ( ; ba; ba = ba->ba_next ) {
100                 if ( ba->ba_dn2odbc ) {
101                         rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
102
103                         if ( rc ) {
104                                 return rc;
105                         }
106                 }
107         }
108
109         *dn = bv;
110
111         return 0;
112 }
113
114 int
115 backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
116 {
117         backsql_info    *si = (backsql_info *)op->o_bd->be_private;
118         backsql_api     *ba;
119         int             rc;
120         struct berval   bv;
121
122         ba = si->si_api;
123
124         if ( ba == NULL ) {
125                 return 0;
126         }
127
128         ber_dupbv( &bv, dn );
129
130         for ( ; ba; ba = ba->ba_next ) {
131                 if ( ba->ba_dn2odbc ) {
132                         rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
133
134                         if ( rc ) {
135                                 return rc;
136                         }
137                 }
138         }
139
140         *dn = bv;
141
142         return 0;
143 }
144
145 #endif /* SLAPD_SQL */
146