bdeafc827a829e3df5d3a9a888b8074cffed28c6
[samba.git] / source / lib / ldb / ldb_map / ldb_map.h
1 /* 
2    ldb database library - map backend
3
4    Copyright (C) Jelmer Vernooij 2005
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 #ifndef __LDB_MAP_H__
26 #define __LDB_MAP_H__
27
28 /* ldb_map is a skeleton LDB module that can be used for any other modules
29  * that need to map attributes.
30  *
31  * The term 'remote' in this header refers to the connection where the 
32  * original schema is used on while 'local' means the local connection 
33  * that any upper layers will use.
34  *
35  * All local attributes will have to have a definition. Not all remote 
36  * attributes need a definition as LDB is a lot less stricter then LDAP 
37  * (in other words, sending unknown attributes to an LDAP server hurts us, 
38  * returning too much attributes in ldb_search() doesn't)
39  */
40
41 struct ldb_map_attribute 
42 {
43         const char *local_name; /* local name */
44
45         enum { 
46                 MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely.  */
47                 MAP_KEEP,   /* Keep as is */
48                 MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */
49                 MAP_CONVERT, /* Rename + convert data */
50                 MAP_GENERATE /* Use generate function for generating new name/data. 
51                                                 Used for generating attributes based on 
52                                                 multiple remote attributes. */
53         } type;
54         
55         /* if set, will be called for expressions that contain this attribute */
56         struct ldb_parse_tree *(*convert_operator) (TALLOC_CTX *ctx, const struct ldb_parse_tree *);    
57
58         union { 
59                 struct {
60                         const char *remote_name;
61                 } rename;
62                 
63                 struct {
64                         const char *remote_name;
65
66                         struct ldb_message_element *(*convert_local) (
67                                 TALLOC_CTX *ctx, 
68                                 const char *remote_attr,
69                                 const struct ldb_message_element *);
70
71                         struct ldb_message_element *(*convert_remote) (
72                                 TALLOC_CTX *ctx,
73                                 const char *local_attr,
74                                 const struct ldb_message_element *);
75                 } convert;
76         
77                 struct {
78                         /* Generate the local attribute from remote message */
79                         struct ldb_message_element *(*generate_local) (
80                                         TALLOC_CTX *ctx, 
81                                         const char *attr, 
82                                         const struct ldb_message *remote);
83
84                         /* Update remote message with information from local message */
85                         void (*generate_remote) (
86                                         const char *local_attr,
87                                         const struct ldb_message *local, 
88                                         struct ldb_message *remote);
89
90                         /* Name(s) for this attribute on the remote server. This is an array since 
91                          * one local attribute's data can be split up into several attributes 
92                          * remotely */
93 #define LDB_MAP_MAX_REMOTE_NAMES 10
94                         const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES];
95                 } generate;
96         } u;
97 };
98
99 struct ldb_map_objectclass 
100 {
101         const char *local_name;
102         const char *remote_name;
103 };
104
105 #endif /* __LDB_MAP_H__ */