]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/api.c
cleanup naming; minor fixes
[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 "proto-sql.h"
30
31 static backsql_api *backsqlapi;
32
33 int
34 backsql_api_config( backsql_info *bi, const char *name )
35 {
36         backsql_api     *ba;
37
38         assert( bi );
39         assert( name );
40
41         for ( ba = backsqlapi; ba; ba = ba->ba_next ) {
42                 if ( strcasecmp( name, ba->ba_name ) == 0 ) {
43                         backsql_api     *ba2;
44
45                         ba2 = ch_malloc( sizeof( backsql_api ) );
46                         *ba2 = *ba;
47                         ba2->ba_next = bi->sql_api;
48                         bi->sql_api = ba2;
49                         return 0;
50                 }
51         }
52
53         return 1;
54 }
55
56 int
57 backsql_api_register( backsql_api *ba )
58 {
59         backsql_api     *ba2;
60
61         assert( ba );
62
63         if ( ba->ba_name == NULL ) {
64                 fprintf( stderr, "API module has no name\n" );
65                 exit(EXIT_FAILURE);
66         }
67
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 );
71                         exit(EXIT_FAILURE);
72                 }
73         }
74
75         ba->ba_next = backsqlapi;
76         backsqlapi = ba;
77
78         return 0;
79 }
80
81 int
82 backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn )
83 {
84         backsql_info    *bi = (backsql_info *)op->o_bd->be_private;
85         backsql_api     *ba;
86         int             rc;
87         struct berval   bv;
88
89         ba = bi->sql_api;
90
91         if ( ba == NULL ) {
92                 return 0;
93         }
94
95         ber_dupbv( &bv, dn );
96
97         for ( ; ba; ba = ba->ba_next ) {
98                 if ( ba->ba_dn2odbc ) {
99                         rc = ( *ba->ba_dn2odbc )( op, rs, &bv );
100
101                         if ( rc ) {
102                                 return rc;
103                         }
104                 }
105         }
106
107         *dn = bv;
108
109         return 0;
110 }
111
112 int
113 backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn )
114 {
115         backsql_info    *bi = (backsql_info *)op->o_bd->be_private;
116         backsql_api     *ba;
117         int             rc;
118         struct berval   bv;
119
120         ba = bi->sql_api;
121
122         if ( ba == NULL ) {
123                 return 0;
124         }
125
126         ber_dupbv( &bv, dn );
127
128         for ( ; ba; ba = ba->ba_next ) {
129                 if ( ba->ba_dn2odbc ) {
130                         rc = ( *ba->ba_odbc2dn )( op, rs, &bv );
131
132                         if ( rc ) {
133                                 return rc;
134                         }
135                 }
136         }
137
138         *dn = bv;
139
140         return 0;
141 }
142
143 #endif /* SLAPD_SQL */
144