Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / bin / ttdbserverd / dm_access_cache.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: dm_access_cache.h /main/3 1995/10/20 16:40:47 rswiston $                                                     */
28 /*
29  *  Tool Talk Database Manager - dm_access_cache.h
30  *
31  *  Copyright (c) 1989 Sun Microsystems, Inc.
32  *
33  *  This file contains class declarations for the oid access info cache.
34  *
35  */
36
37 #if !defined(_DM_ACCESS_CACHE_H)
38 #define _DM_ACCESS_CACHE_H
39
40 #include <util/tt_object.h>
41 #include <util/tt_string.h>
42 #include <tt_const.h>
43 #include <sys/param.h>
44
45 #include <limits.h>
46 #if !defined(NGROUPS)
47 #define NGROUPS NGROUPS_MAX
48 #endif
49
50 #define DM_OID_ACCESS_BUCKETS 97
51 #define DM_MAX_ACCESS_ELEMS  (5 * DM_OID_ACCESS_BUCKETS)
52
53 /*
54  *  OID keys' access info cache
55  */
56
57 class _Tt_oid_access : public _Tt_object {
58       public:
59         _Tt_oid_access() {}
60         _Tt_oid_access(const char *key, uid_t user, gid_t group, mode_t mode);
61         _Tt_oid_access(char *ku);
62         ~_Tt_oid_access();
63         const char      *key() const { return _key; }
64         uid_t           user() const { return _user; }
65         gid_t           group() const { return _group; }
66         mode_t          mode() const { return _mode; }
67         void            set_user(uid_t user) { _user = user; }
68         void            set_group(gid_t group) { _group = group; }
69         void            set_mode(mode_t mode) { _mode = mode; }
70         int             reclen() const { return OID_KEY_LENGTH +
71                                          sizeof(uid_t) + sizeof(gid_t) +
72                                          sizeof(mode_t); }
73         char            *rec();
74         void            print(FILE *fs = stdout) const;
75       private:
76         char            _key[OID_KEY_LENGTH];
77         uid_t           _user;
78         gid_t           _group;
79         mode_t          _mode;
80 };
81
82 declare_ptr_to(_Tt_oid_access)
83
84 class _Tt_oid_access_elem;
85 declare_ptr_to(_Tt_oid_access_elem)
86
87 class _Tt_oid_access_elem : public _Tt_object {
88       public:
89         _Tt_oid_access_elem() {}
90         _Tt_oid_access_elem(_Tt_oid_access_ptr oa, _Tt_oid_access_elem_ptr next);
91         _Tt_oid_access_ptr      oa() { return _oa; }
92         _Tt_oid_access_elem_ptr next() { return _next; }
93         void                    set_next(_Tt_oid_access_elem_ptr next)
94         { _next = next; }
95         void                    print(FILE *fs = stdout) const;
96       private:
97         _Tt_oid_access_ptr      _oa;
98         _Tt_oid_access_elem_ptr _next;
99 };
100
101 class _Tt_oid_access_queue : public _Tt_object {
102       public:
103         _Tt_oid_access_queue();
104         ~_Tt_oid_access_queue();
105         void                    enqueue(_Tt_oid_access_ptr oa);
106         _Tt_oid_access_ptr      lookup(const char *key);
107         void                    remove(_Tt_oid_access_ptr oa);
108         void                    promote(_Tt_oid_access_ptr oa);
109         void                    print(FILE *fs = stdout) const;
110       private:
111         void                    dequeue();
112         int                     hash(const char *key);
113
114         _Tt_oid_access_elem_ptr _head;
115         _Tt_oid_access_elem_ptr _tail;
116         int                     _len;
117         _Tt_oid_access_elem_ptr _table[DM_OID_ACCESS_BUCKETS];
118 };
119
120 declare_ptr_to(_Tt_oid_access_queue)
121
122
123 /*
124  *  LINK keys' access info cache
125  */
126
127 class _Tt_link_access : public _Tt_object {
128       public:
129         _Tt_link_access() {}
130         _Tt_link_access(const char *key, uid_t user, gid_t group, mode_t mode);
131         _Tt_link_access(char *ku);
132         ~_Tt_link_access();
133         const char      *key() const { return _key; }
134         uid_t           user() const { return _user; }
135         gid_t           group() const { return _group; }
136         mode_t          mode() const { return _mode; }
137         void            set_user(uid_t user) { _user = user; }
138         void            set_group(gid_t group) { _group = group; }
139         void            set_mode(mode_t mode) { _mode = mode; }
140         int             reclen() const { return OID_KEY_LENGTH +
141                                          sizeof(uid_t) + sizeof(gid_t) +
142                                          sizeof(mode_t); }
143         char            *rec();
144         void            print(FILE *fs = stdout) const;
145       private:
146         char            _key[OID_KEY_LENGTH];
147         uid_t           _user;
148         gid_t           _group;
149         mode_t          _mode;
150 };
151
152 declare_ptr_to(_Tt_link_access)
153
154 class _Tt_link_access_elem;
155 declare_ptr_to(_Tt_link_access_elem)
156
157 class _Tt_link_access_elem : public _Tt_object {
158       public:
159         _Tt_link_access_elem() {}
160         _Tt_link_access_elem(_Tt_link_access_ptr oa, _Tt_link_access_elem_ptr next);
161         _Tt_link_access_ptr     oa() { return _oa; }
162         _Tt_link_access_elem_ptr        next() { return _next; }
163         void                    set_next(_Tt_link_access_elem_ptr next)
164         { _next = next; }
165         void                    print(FILE *fs = stdout) const;
166       private:
167         _Tt_link_access_ptr     _oa;
168         _Tt_link_access_elem_ptr        _next;
169 };
170
171 class _Tt_link_access_queue : public _Tt_object {
172       public:
173         _Tt_link_access_queue();
174         ~_Tt_link_access_queue();
175         void                    enqueue(_Tt_link_access_ptr oa);
176         _Tt_link_access_ptr     lookup(const char *key);
177         void                    remove(_Tt_link_access_ptr oa);
178         void                    promote(_Tt_link_access_ptr oa);
179         void                    print(FILE *fs = stdout) const;
180       private:
181         void                    dequeue();
182         int                     hash(const char *key);
183
184         _Tt_link_access_elem_ptr        _head;
185         _Tt_link_access_elem_ptr        _tail;
186         int                             _len;
187         _Tt_link_access_elem_ptr        _table[DM_OID_ACCESS_BUCKETS];
188 };
189
190 declare_ptr_to(_Tt_link_access_queue)
191
192 // Here follow a bunch of common declarations for dbserver components.
193 // They really should have their own file. (dbserver_commmon.h?)
194 // They got stuck in dm_access_cache since they have do do with
195 // internal dbserver caching (but for fd's.)
196 #define _TT_MAX_ISFD  128
197
198 /* structure containing info open ISAM files: full path and opener's uids */
199 struct _Tt_db_info {
200         _Tt_string      db_path;
201         uid_t           opener_uid;
202         int             open_mode;      // mode file was opened with
203         int             client_has_open; // 1 iff we think somebodys using it
204         int             server_has_open; // 1 iff we opened it
205         int             reftime;         // "time" of last reference for LRU
206 };
207
208 int  cached_isopen(const char *filepath, int mode);
209 int  cached_isclose(int isfd);
210 void isgarbage_collect();
211
212
213 #endif /* _DM_ACCESS_CACHE_H */