xref: /freebsd/usr.sbin/nscd/protocol.h (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
1 /*-
2  * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef __NSCD_PROTOCOL_H__
30 #define __NSCD_PROTOCOL_H__
31 
32 #include <stdlib.h>
33 
34 /* maximum buffer size to receive - larger buffers are not allowed */
35 #define MAX_BUFFER_SIZE (1 << 20)
36 
37 /* buffer size correctness checking routine */
38 #define BUFSIZE_CORRECT(x) (((x) > 0) && ((x) < MAX_BUFFER_SIZE))
39 #define BUFSIZE_INVALID(x) (!BUFSIZE_CORRECT(x))
40 
41 /* structures below represent the data that are sent/received by the daemon */
42 struct cache_write_request
43 {
44 	char	*entry;
45 	char	*cache_key;
46 	char	*data;
47 
48 	size_t	entry_length;
49 	size_t	cache_key_size;
50 	size_t	data_size;
51 };
52 
53 struct cache_write_response
54 {
55 	int	error_code;
56 };
57 
58 struct cache_read_request
59 {
60 	char	*entry;
61 	char	*cache_key;
62 
63 	size_t	entry_length;
64 	size_t	cache_key_size;
65 };
66 
67 struct cache_read_response
68 {
69 	char	*data;			// ignored if error_code is not 0
70 	size_t	data_size;		// ignored if error_code is not 0
71 
72 	int	error_code;
73 };
74 
75 enum transformation_type {
76 	TT_USER = 0,	// tranform only the entries of the caller
77 	TT_ALL = 1	// transform all entries
78 };
79 
80 struct cache_transform_request
81 {
82 	char	*entry; 		// ignored if entry_length is 0
83 	size_t	entry_length;
84 
85 	int	transformation_type;
86 };
87 
88 struct cache_transform_response
89 {
90 	int	error_code;
91 };
92 
93 struct cache_mp_write_session_request {
94 	char	*entry;
95 	size_t	entry_length;
96 };
97 
98 struct cache_mp_write_session_response {
99 	int	error_code;
100 };
101 
102 struct cache_mp_write_session_write_request {
103 	char	*data;
104 	size_t	data_size;
105 };
106 
107 struct cache_mp_write_session_write_response {
108 	int	error_code;
109 };
110 
111 struct cache_mp_read_session_request {
112 	char	*entry;
113 	size_t	entry_length;
114 };
115 
116 struct cache_mp_read_session_response {
117 	int	error_code;
118 };
119 
120 struct cache_mp_read_session_read_response {
121 	char	*data;
122 	size_t	data_size;
123 
124 	int	error_code;
125 };
126 
127 
128 enum comm_element_t {
129 	CET_UNDEFINED 	= 0,
130 	CET_WRITE_REQUEST = 1,
131 	CET_WRITE_RESPONSE = 2,
132 	CET_READ_REQUEST = 3,
133 	CET_READ_RESPONSE = 4,
134 	CET_TRANSFORM_REQUEST = 5,
135 	CET_TRANSFORM_RESPONSE = 6,
136 	CET_MP_WRITE_SESSION_REQUEST = 7,
137 	CET_MP_WRITE_SESSION_RESPONSE = 8,
138 	CET_MP_WRITE_SESSION_WRITE_REQUEST = 9,
139 	CET_MP_WRITE_SESSION_WRITE_RESPONSE = 10,
140 	CET_MP_WRITE_SESSION_CLOSE_NOTIFICATION = 11,
141 	CET_MP_WRITE_SESSION_ABANDON_NOTIFICATION = 12,
142 	CET_MP_READ_SESSION_REQUEST = 13,
143 	CET_MP_READ_SESSION_RESPONSE = 14,
144 	CET_MP_READ_SESSION_READ_REQUEST = 15,
145 	CET_MP_READ_SESSION_READ_RESPONSE = 16,
146 	CET_MP_READ_SESSION_CLOSE_NOTIFICATION = 17,
147 	CET_MAX = 18
148 };
149 
150 /*
151  * The comm_element is used as the holder of any known (defined above) data
152  * type that is to be sent/received.
153  */
154 struct comm_element
155 {
156 	union {
157 	struct cache_write_request c_write_request;
158 	struct cache_write_response c_write_response;
159 	struct cache_read_request c_read_request;
160 	struct cache_read_response c_read_response;
161 	struct cache_transform_request c_transform_request;
162 	struct cache_transform_response c_transform_response;
163 
164 	struct cache_mp_write_session_request c_mp_ws_request;
165 	struct cache_mp_write_session_response c_mp_ws_response;
166 	struct cache_mp_write_session_write_request c_mp_ws_write_request;
167 	struct cache_mp_write_session_write_response c_mp_ws_write_response;
168 
169 	struct cache_mp_read_session_request c_mp_rs_request;
170 	struct cache_mp_read_session_response c_mp_rs_response;
171 	struct cache_mp_read_session_read_response c_mp_rs_read_response;
172 	};
173 	enum comm_element_t type;
174 };
175 
176 extern void init_comm_element(struct comm_element *, enum comm_element_t type);
177 extern void finalize_comm_element(struct comm_element *);
178 
179 /*
180  * For each type of data, there is three functions (init/finalize/get), that
181  * used with comm_element structure
182  */
183 extern void init_cache_write_request(struct cache_write_request *);
184 extern void finalize_cache_write_request(struct cache_write_request *);
185 extern struct cache_write_request *get_cache_write_request(
186 	struct comm_element *);
187 
188 extern void init_cache_write_response(struct cache_write_response *);
189 extern void finalize_cache_write_response(struct cache_write_response *);
190 extern struct cache_write_response *get_cache_write_response(
191 	struct comm_element *);
192 
193 extern void init_cache_read_request(struct cache_read_request *);
194 extern void finalize_cache_read_request(struct cache_read_request *);
195 extern struct cache_read_request *get_cache_read_request(
196 	struct comm_element *);
197 
198 extern void init_cache_read_response(struct cache_read_response *);
199 extern void finalize_cache_read_response(struct cache_read_response *);
200 extern struct cache_read_response *get_cache_read_response(
201 	struct comm_element *);
202 
203 extern void init_cache_transform_request(struct cache_transform_request *);
204 extern void finalize_cache_transform_request(struct cache_transform_request *);
205 extern struct cache_transform_request *get_cache_transform_request(
206 	struct comm_element *);
207 
208 extern void init_cache_transform_response(struct cache_transform_response *);
209 extern void finalize_cache_transform_response(
210 	struct cache_transform_response *);
211 extern struct cache_transform_response *get_cache_transform_response(
212 	struct comm_element *);
213 
214 extern void init_cache_mp_write_session_request(
215 	struct cache_mp_write_session_request *);
216 extern void finalize_cache_mp_write_session_request(
217 	struct cache_mp_write_session_request *);
218 extern struct cache_mp_write_session_request *
219     	get_cache_mp_write_session_request(
220 	struct comm_element *);
221 
222 extern void init_cache_mp_write_session_response(
223 	struct cache_mp_write_session_response *);
224 extern void finalize_cache_mp_write_session_response(
225 	struct cache_mp_write_session_response *);
226 extern struct cache_mp_write_session_response *
227 	get_cache_mp_write_session_response(struct comm_element *);
228 
229 extern void init_cache_mp_write_session_write_request(
230 	struct cache_mp_write_session_write_request *);
231 extern void finalize_cache_mp_write_session_write_request(
232 	struct cache_mp_write_session_write_request *);
233 extern struct cache_mp_write_session_write_request *
234 	get_cache_mp_write_session_write_request(struct comm_element *);
235 
236 extern void init_cache_mp_write_session_write_response(
237 	struct cache_mp_write_session_write_response *);
238 extern void finalize_cache_mp_write_session_write_response(
239 	struct cache_mp_write_session_write_response *);
240 extern struct cache_mp_write_session_write_response *
241 	get_cache_mp_write_session_write_response(struct comm_element *);
242 
243 extern void init_cache_mp_read_session_request(
244 	struct cache_mp_read_session_request *);
245 extern void finalize_cache_mp_read_session_request(
246 	struct cache_mp_read_session_request *);
247 extern struct cache_mp_read_session_request *get_cache_mp_read_session_request(
248 	struct comm_element *);
249 
250 extern void init_cache_mp_read_session_response(
251 	struct cache_mp_read_session_response *);
252 extern void finalize_cache_mp_read_session_response(
253 	struct cache_mp_read_session_response *);
254 extern struct cache_mp_read_session_response *
255     	get_cache_mp_read_session_response(
256 	struct comm_element *);
257 
258 extern void init_cache_mp_read_session_read_response(
259 	struct cache_mp_read_session_read_response *);
260 extern void finalize_cache_mp_read_session_read_response(
261 	struct cache_mp_read_session_read_response *);
262 extern struct cache_mp_read_session_read_response *
263 	get_cache_mp_read_session_read_response(struct comm_element *);
264 
265 #endif
266