]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ndb/back-ndb.h
Happy New Year
[openldap] / servers / slapd / back-ndb / back-ndb.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2008-2018 The OpenLDAP Foundation.
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 Howard Chu for inclusion
17  * in OpenLDAP Software. This work was sponsored by MySQL.
18  */
19
20 #ifndef SLAPD_NDB_H
21 #define SLAPD_NDB_H
22
23 #include "slap.h"
24
25 #include <mysql.h>
26 #include <NdbApi.hpp>
27
28 LDAP_BEGIN_DECL
29
30 /* The general design is to use one relational table per objectclass. This is
31  * complicated by objectclass inheritance and auxiliary classes though.
32  *
33  * Attributes must only occur in a single table. For objectclasses that inherit
34  * from other classes, attributes defined in the superior class are only stored
35  * in the superior class' table. When multiple unrelated classes define the same
36  * attributes, an attributeSet should be defined instead, containing all of the
37  * common attributes.
38  *
39  * The no_set table lists which other attributeSets apply to the current
40  * objectClass. The no_attrs table lists all of the non-inherited attributes of
41  * the class, including those residing in an attributeSet.
42  *
43  * Usually the table is named identically to the objectClass, but it can also
44  * be explicitly named something else if needed.
45  */
46 #define NDB_MAX_OCSETS  8
47
48 struct ndb_attrinfo;
49
50 typedef struct ndb_ocinfo {
51         struct berval no_name;  /* objectclass cname */
52         struct berval no_table;
53         ObjectClass *no_oc;
54         struct ndb_ocinfo *no_sets[NDB_MAX_OCSETS];
55         struct ndb_attrinfo **no_attrs;
56         int no_flag;
57         int no_nsets;
58         int no_nattrs;
59 } NdbOcInfo;
60
61 #define NDB_INFO_ATLEN  0x01
62 #define NDB_INFO_ATSET  0x02
63 #define NDB_INFO_INDEX  0x04
64 #define NDB_INFO_ATBLOB 0x08
65
66 typedef struct ndb_attrinfo {
67         struct berval na_name;  /* attribute cname */
68         AttributeDescription *na_desc;
69         AttributeType *na_attr;
70         NdbOcInfo *na_oi;
71         int na_flag;
72         int na_len;
73         int na_column;
74         int na_ixcol;
75 } NdbAttrInfo;
76
77 typedef struct ListNode {
78         struct ListNode *ln_next;
79         void *ln_data;
80 } ListNode;
81
82 #define NDB_IS_OPEN(ni) (ni->ni_cluster != NULL)
83
84 struct ndb_info {
85         /* NDB connection */
86         char *ni_connectstr;
87         char *ni_dbname;
88         Ndb_cluster_connection **ni_cluster;
89
90         /* MySQL connection parameters */
91         MYSQL ni_sql;
92         char *ni_hostname;
93         char *ni_username;
94         char *ni_password;
95         char *ni_socket;
96         unsigned long ni_clflag;
97         unsigned int ni_port;
98
99         /* Search filter processing */
100         int ni_search_stack_depth;
101         void *ni_search_stack;
102
103 #define DEFAULT_SEARCH_STACK_DEPTH      16
104 #define MINIMUM_SEARCH_STACK_DEPTH      8
105
106         /* Schema config */
107         NdbOcInfo *ni_opattrs;
108         ListNode *ni_attridxs;
109         ListNode *ni_attrlens;
110         ListNode *ni_attrsets;
111         ListNode *ni_attrblobs;
112         ldap_pvt_thread_rdwr_t ni_ai_rwlock;
113         Avlnode *ni_ai_tree;
114         ldap_pvt_thread_rdwr_t ni_oc_rwlock;
115         Avlnode *ni_oc_tree;
116         int ni_nconns;  /* number of connections to open */
117         int ni_nextconn;        /* next conn to use */
118         ldap_pvt_thread_mutex_t ni_conn_mutex;
119 };
120
121 #define NDB_MAX_RDNS    16
122 #define NDB_RDN_LEN     128
123 #define NDB_MAX_OCS     64
124
125 #define DN2ID_TABLE     "OL_dn2id"
126 #define EID_COLUMN      0U
127 #define VID_COLUMN      1U
128 #define OCS_COLUMN      1U
129 #define RDN_COLUMN      2U
130 #define IDX_COLUMN      (2U+NDB_MAX_RDNS)
131
132 #define NEXTID_TABLE    "OL_nextid"
133
134 #define NDB_OC_BUFLEN   1026    /* 1024 data plus 2 len bytes */
135
136 #define INDEX_NAME      "OL_index"
137
138 typedef struct NdbRdns {
139         short nr_num;
140         char nr_buf[NDB_MAX_RDNS][NDB_RDN_LEN+1];
141 } NdbRdns;
142
143 typedef struct NdbOcs {
144         int no_ninfo;
145         int no_ntext;
146         int no_nitext;  /* number of implicit classes */
147         NdbOcInfo *no_info[NDB_MAX_OCS];
148         struct berval no_text[NDB_MAX_OCS];
149         struct berval no_itext[NDB_MAX_OCS];    /* implicit classes */
150 } NdbOcs;
151
152 typedef struct NdbArgs {
153         Ndb *ndb;
154         NdbTransaction *txn;
155         Entry *e;
156         NdbRdns *rdns;
157         struct berval *ocs;
158         int erdns;
159 } NdbArgs;
160
161 #define NDB_NO_SUCH_OBJECT      626
162 #define NDB_ALREADY_EXISTS      630
163
164 LDAP_END_DECL
165
166 #include "proto-ndb.h"
167
168 #endif