xref: /illumos-gate/usr/src/lib/libnisdb/db_scheme_c.x (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	db_scheme_c.x
24  *
25  * Copyright 2015 Gary Mills
26  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #if RPC_XDR
31 %#include "ldap_xdr.h"
32 #endif /* RPC_XDR */
33 
34 #if RPC_HDR
35 %#ifndef _DB_SCHEMA_H
36 %#define _DB_SCHEMA_H
37 
38 #ifdef USINGC
39 %#include "db_item_c.h"
40 %#include "db_entry_c.h"
41 #else
42 %#include "db_item.h"
43 %#include "db_entry.h"
44 #endif /* USINGC */
45 
46 const DB_KEY_CASE = TA_CASE;
47 
48 #endif /* RPC_HDR */
49 %
50 %#include "nisdb_rw.h"
51 %
52 %/* Positional information of where field starts within record
53 %   and its maximum length in terms of bytes. */
54 struct db_posn_info {
55   short int start_column;
56   short int max_len;
57 };
58 
59 %/* Description of a key */
60 struct db_key_desc {
61   item *key_name;
62   unsigned long key_flags;  /* corresponds to tc_flags in table_col defn */
63   int column_number;        /* column within data structure */
64   db_posn_info where;       /* where within record entry is 'key' located */
65   short int store_type;     /* ISAM or SS ?  maybe useless */
66 };
67 
68 %/* Description of the data field. */
69 struct db_data_desc {
70   db_posn_info where;       /* where within record entry is 'data' located */
71   short int store_type;     /* ISAM or SS ? maybe useless */
72 };
73 
74 %/* A scheme is a description of the fields of a table. */
75 
76 #if RPC_HDR || RPC_XDR
77 #ifdef USINGC
78 
79 struct db_scheme {
80   db_key_desc keys<>;
81   short int max_columns;  /* applies to data only ? */
82   db_data_desc data;
83   __nisdb_rwlock_t scheme_rwlock;
84 };
85 
86 typedef struct db_scheme  * db_scheme_p;
87 #endif /* USINGC */
88 #endif /* RPC_HDR */
89 
90 #ifndef USINGC
91 #ifdef RPC_HDR
92 %
93 %class db_scheme {
94 % protected:
95 %  struct {
96 %	int keys_len;
97 %	db_key_desc *keys_val;
98 %  } keys;
99 %  short int max_columns;  /* applies to data only ? */
100 %  db_data_desc data;
101 %  STRUCTRWLOCK(scheme);
102 %
103 % public:
104 %/* Accessor: return number of keys in scheme. */
105 %  int numkeys() { return keys.keys_len; }
106 %
107 %/* Accessor:  return location of array of key_desc's. */
108 %  db_key_desc* keyloc () { return keys.keys_val; }
109 %
110 %/* Constructor:  create empty scheme */
111 %  db_scheme() {
112 %	keys.keys_len = 0;
113 %	keys.keys_val = NULL;
114 %	(void) __nisdb_rwinit(&scheme_rwlock);
115 %  }
116 %
117 %/* Constructor:  create new scheme by making copy of 'orig'.
118 %   All items within old scheme are also copied (i.e. no shared pointers). */
119 %  db_scheme( db_scheme* orig );
120 %
121 %/* Constructor:  create new sheme by using information in 'zdesc'. */
122 %  db_scheme( table_obj * );
123 %
124 %/* Destructor:  delete all keys associated with scheme and scheme itself. */
125 %  ~db_scheme();
126 %
127 %/* Free space occupied by columns. */
128 %  void clear_columns( int );
129 %
130 %/* Predicate:  return whether given string is one of the index names
131 %   of this scheme.  If so, return in 'result' the index's number. */
132 %  bool_t find_index( char*, int* );
133 %
134 %/* Print out description of table. */
135 %  void print();
136 %
137 %/* Size of the non-MT/LDAP portion of the db_scheme structure */
138 %  ulong_t oldstructsize(void) {
139 %	return ((ulong_t)&(this->scheme_rwlock) - (ulong_t)this);
140 %  }
141 %
142 %/* Locking methods */
143 %
144 %  int acqexcl(void) {
145 %	return (WLOCK(scheme));
146 %  }
147 %
148 %  int relexcl(void) {
149 %	return (WULOCK(scheme));
150 %  }
151 %
152 %  int acqnonexcl(void) {
153 %	return (RLOCK(scheme));
154 %  }
155 %
156 %  int relnonexcl(void) {
157 %	return (RULOCK(scheme));
158 %  }
159 %};
160 
161 %typedef class db_scheme * db_scheme_p;
162 #endif /* RPC_HDR */
163 #endif /* USINGC */
164 
165 #if RPC_HDR
166 %#endif /* _DB_SCHEMA_H */
167 
168 #endif /* RPC_HDR */
169