17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	db_scheme_c.x
247c478bd9Sstevel@tonic-gate  *
25*a87701e9SGary Mills  * Copyright 2015 Gary Mills
26a506a34cSth  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27a506a34cSth  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30*a87701e9SGary Mills #if RPC_XDR
31*a87701e9SGary Mills %#include "ldap_xdr.h"
32*a87701e9SGary Mills #endif /* RPC_XDR */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #if RPC_HDR
357c478bd9Sstevel@tonic-gate %#ifndef _DB_SCHEMA_H
367c478bd9Sstevel@tonic-gate %#define _DB_SCHEMA_H
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef USINGC
397c478bd9Sstevel@tonic-gate %#include "db_item_c.h"
407c478bd9Sstevel@tonic-gate %#include "db_entry_c.h"
417c478bd9Sstevel@tonic-gate #else
427c478bd9Sstevel@tonic-gate %#include "db_item.h"
437c478bd9Sstevel@tonic-gate %#include "db_entry.h"
44a506a34cSth #endif /* USINGC */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate const DB_KEY_CASE = TA_CASE;
477c478bd9Sstevel@tonic-gate 
48a506a34cSth #endif /* RPC_HDR */
497c478bd9Sstevel@tonic-gate %
507c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h"
517c478bd9Sstevel@tonic-gate %
527c478bd9Sstevel@tonic-gate %/* Positional information of where field starts within record
537c478bd9Sstevel@tonic-gate %   and its maximum length in terms of bytes. */
547c478bd9Sstevel@tonic-gate struct db_posn_info {
557c478bd9Sstevel@tonic-gate   short int start_column;
567c478bd9Sstevel@tonic-gate   short int max_len;
577c478bd9Sstevel@tonic-gate };
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate %/* Description of a key */
607c478bd9Sstevel@tonic-gate struct db_key_desc {
617c478bd9Sstevel@tonic-gate   item *key_name;
627c478bd9Sstevel@tonic-gate   unsigned long key_flags;  /* corresponds to tc_flags in table_col defn */
637c478bd9Sstevel@tonic-gate   int column_number;        /* column within data structure */
647c478bd9Sstevel@tonic-gate   db_posn_info where;       /* where within record entry is 'key' located */
657c478bd9Sstevel@tonic-gate   short int store_type;     /* ISAM or SS ?  maybe useless */
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate %/* Description of the data field. */
697c478bd9Sstevel@tonic-gate struct db_data_desc {
707c478bd9Sstevel@tonic-gate   db_posn_info where;       /* where within record entry is 'data' located */
717c478bd9Sstevel@tonic-gate   short int store_type;     /* ISAM or SS ? maybe useless */
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate %/* A scheme is a description of the fields of a table. */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
777c478bd9Sstevel@tonic-gate #ifdef USINGC
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate struct db_scheme {
807c478bd9Sstevel@tonic-gate   db_key_desc keys<>;
817c478bd9Sstevel@tonic-gate   short int max_columns;  /* applies to data only ? */
827c478bd9Sstevel@tonic-gate   db_data_desc data;
837c478bd9Sstevel@tonic-gate   __nisdb_rwlock_t scheme_rwlock;
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate typedef struct db_scheme  * db_scheme_p;
87a506a34cSth #endif /* USINGC */
88a506a34cSth #endif /* RPC_HDR */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #ifndef USINGC
917c478bd9Sstevel@tonic-gate #ifdef RPC_HDR
927c478bd9Sstevel@tonic-gate %
937c478bd9Sstevel@tonic-gate %class db_scheme {
947c478bd9Sstevel@tonic-gate % protected:
957c478bd9Sstevel@tonic-gate %  struct {
967c478bd9Sstevel@tonic-gate %	int keys_len;
977c478bd9Sstevel@tonic-gate %	db_key_desc *keys_val;
987c478bd9Sstevel@tonic-gate %  } keys;
997c478bd9Sstevel@tonic-gate %  short int max_columns;  /* applies to data only ? */
1007c478bd9Sstevel@tonic-gate %  db_data_desc data;
1017c478bd9Sstevel@tonic-gate %  STRUCTRWLOCK(scheme);
1027c478bd9Sstevel@tonic-gate %
1037c478bd9Sstevel@tonic-gate % public:
1047c478bd9Sstevel@tonic-gate %/* Accessor: return number of keys in scheme. */
1057c478bd9Sstevel@tonic-gate %  int numkeys() { return keys.keys_len; }
1067c478bd9Sstevel@tonic-gate %
1077c478bd9Sstevel@tonic-gate %/* Accessor:  return location of array of key_desc's. */
1087c478bd9Sstevel@tonic-gate %  db_key_desc* keyloc () { return keys.keys_val; }
1097c478bd9Sstevel@tonic-gate %
1107c478bd9Sstevel@tonic-gate %/* Constructor:  create empty scheme */
1117c478bd9Sstevel@tonic-gate %  db_scheme() {
1127c478bd9Sstevel@tonic-gate %	keys.keys_len = 0;
1137c478bd9Sstevel@tonic-gate %	keys.keys_val = NULL;
1147c478bd9Sstevel@tonic-gate %	(void) __nisdb_rwinit(&scheme_rwlock);
1157c478bd9Sstevel@tonic-gate %  }
1167c478bd9Sstevel@tonic-gate %
1177c478bd9Sstevel@tonic-gate %/* Constructor:  create new scheme by making copy of 'orig'.
1187c478bd9Sstevel@tonic-gate %   All items within old scheme are also copied (i.e. no shared pointers). */
1197c478bd9Sstevel@tonic-gate %  db_scheme( db_scheme* orig );
1207c478bd9Sstevel@tonic-gate %
1217c478bd9Sstevel@tonic-gate %/* Constructor:  create new sheme by using information in 'zdesc'. */
1227c478bd9Sstevel@tonic-gate %  db_scheme( table_obj * );
1237c478bd9Sstevel@tonic-gate %
1247c478bd9Sstevel@tonic-gate %/* Destructor:  delete all keys associated with scheme and scheme itself. */
1257c478bd9Sstevel@tonic-gate %  ~db_scheme();
1267c478bd9Sstevel@tonic-gate %
1277c478bd9Sstevel@tonic-gate %/* Free space occupied by columns. */
1287c478bd9Sstevel@tonic-gate %  void clear_columns( int );
1297c478bd9Sstevel@tonic-gate %
1307c478bd9Sstevel@tonic-gate %/* Predicate:  return whether given string is one of the index names
1317c478bd9Sstevel@tonic-gate %   of this scheme.  If so, return in 'result' the index's number. */
1327c478bd9Sstevel@tonic-gate %  bool_t find_index( char*, int* );
1337c478bd9Sstevel@tonic-gate %
1347c478bd9Sstevel@tonic-gate %/* Print out description of table. */
1357c478bd9Sstevel@tonic-gate %  void print();
1367c478bd9Sstevel@tonic-gate %
1377c478bd9Sstevel@tonic-gate %/* Size of the non-MT/LDAP portion of the db_scheme structure */
1387c478bd9Sstevel@tonic-gate %  ulong_t oldstructsize(void) {
1397c478bd9Sstevel@tonic-gate %	return ((ulong_t)&(this->scheme_rwlock) - (ulong_t)this);
1407c478bd9Sstevel@tonic-gate %  }
1417c478bd9Sstevel@tonic-gate %
1427c478bd9Sstevel@tonic-gate %/* Locking methods */
1437c478bd9Sstevel@tonic-gate %
1447c478bd9Sstevel@tonic-gate %  int acqexcl(void) {
1457c478bd9Sstevel@tonic-gate %	return (WLOCK(scheme));
1467c478bd9Sstevel@tonic-gate %  }
1477c478bd9Sstevel@tonic-gate %
1487c478bd9Sstevel@tonic-gate %  int relexcl(void) {
1497c478bd9Sstevel@tonic-gate %	return (WULOCK(scheme));
1507c478bd9Sstevel@tonic-gate %  }
1517c478bd9Sstevel@tonic-gate %
1527c478bd9Sstevel@tonic-gate %  int acqnonexcl(void) {
1537c478bd9Sstevel@tonic-gate %	return (RLOCK(scheme));
1547c478bd9Sstevel@tonic-gate %  }
1557c478bd9Sstevel@tonic-gate %
1567c478bd9Sstevel@tonic-gate %  int relnonexcl(void) {
1577c478bd9Sstevel@tonic-gate %	return (RULOCK(scheme));
1587c478bd9Sstevel@tonic-gate %  }
1597c478bd9Sstevel@tonic-gate %};
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate %typedef class db_scheme * db_scheme_p;
162a506a34cSth #endif /* RPC_HDR */
163a506a34cSth #endif /* USINGC */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #if RPC_HDR
166a506a34cSth %#endif /* _DB_SCHEMA_H */
1677c478bd9Sstevel@tonic-gate 
168a506a34cSth #endif /* RPC_HDR */
169