xref: /freebsd/usr.sbin/nscd/protocol.h (revision cc426dd31990b8b50b210efc450e404596548ca1)
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 /* maximum buffer size to receive - larger buffers are not allowed */
33 #define MAX_BUFFER_SIZE (1 << 20)
34 
35 /* buffer size correctness checking routine */
36 #define BUFSIZE_CORRECT(x) (((x) > 0) && ((x) < MAX_BUFFER_SIZE))
37 #define BUFSIZE_INVALID(x) (!BUFSIZE_CORRECT(x))
38 
39 /* structures below represent the data that are sent/received by the daemon */
40 struct cache_write_request {
41 	char	*entry;
42 	char	*cache_key;
43 	char	*data;
44 
45 	size_t	entry_length;
46 	size_t	cache_key_size;
47 	size_t	data_size;
48 };
49 
50 struct cache_write_response {
51 	int	error_code;
52 };
53 
54 struct cache_read_request {
55 	char	*entry;
56 	char	*cache_key;
57 
58 	size_t	entry_length;
59 	size_t	cache_key_size;
60 };
61 
62 struct cache_read_response {
63 	char	*data;			// ignored if error_code is not 0
64 	size_t	data_size;		// ignored if error_code is not 0
65 
66 	int	error_code;
67 };
68 
69 enum transformation_type {
70 	TT_USER = 0,	// transform only the entries of the caller
71 	TT_ALL = 1	// transform all entries
72 };
73 
74 struct cache_transform_request {
75 	char	*entry; 		// ignored if entry_length is 0
76 	size_t	entry_length;
77 
78 	int	transformation_type;
79 };
80 
81 struct cache_transform_response {
82 	int	error_code;
83 };
84 
85 struct cache_mp_write_session_request {
86 	char	*entry;
87 	size_t	entry_length;
88 };
89 
90 struct cache_mp_write_session_response {
91 	int	error_code;
92 };
93 
94 struct cache_mp_write_session_write_request {
95 	char	*data;
96 	size_t	data_size;
97 };
98 
99 struct cache_mp_write_session_write_response {
100 	int	error_code;
101 };
102 
103 struct cache_mp_read_session_request {
104 	char	*entry;
105 	size_t	entry_length;
106 };
107 
108 struct cache_mp_read_session_response {
109 	int	error_code;
110 };
111 
112 struct cache_mp_read_session_read_response {
113 	char	*data;
114 	size_t	data_size;
115 
116 	int	error_code;
117 };
118 
119 
120 enum comm_element_t {
121 	CET_UNDEFINED 	= 0,
122 	CET_WRITE_REQUEST = 1,
123 	CET_WRITE_RESPONSE = 2,
124 	CET_READ_REQUEST = 3,
125 	CET_READ_RESPONSE = 4,
126 	CET_TRANSFORM_REQUEST = 5,
127 	CET_TRANSFORM_RESPONSE = 6,
128 	CET_MP_WRITE_SESSION_REQUEST = 7,
129 	CET_MP_WRITE_SESSION_RESPONSE = 8,
130 	CET_MP_WRITE_SESSION_WRITE_REQUEST = 9,
131 	CET_MP_WRITE_SESSION_WRITE_RESPONSE = 10,
132 	CET_MP_WRITE_SESSION_CLOSE_NOTIFICATION = 11,
133 	CET_MP_WRITE_SESSION_ABANDON_NOTIFICATION = 12,
134 	CET_MP_READ_SESSION_REQUEST = 13,
135 	CET_MP_READ_SESSION_RESPONSE = 14,
136 	CET_MP_READ_SESSION_READ_REQUEST = 15,
137 	CET_MP_READ_SESSION_READ_RESPONSE = 16,
138 	CET_MP_READ_SESSION_CLOSE_NOTIFICATION = 17,
139 	CET_MAX = 18
140 };
141 
142 /*
143  * The comm_element is used as the holder of any known (defined above) data
144  * type that is to be sent/received.
145  */
146 struct comm_element {
147 	union {
148 	struct cache_write_request c_write_request;
149 	struct cache_write_response c_write_response;
150 	struct cache_read_request c_read_request;
151 	struct cache_read_response c_read_response;
152 	struct cache_transform_request c_transform_request;
153 	struct cache_transform_response c_transform_response;
154 
155 	struct cache_mp_write_session_request c_mp_ws_request;
156 	struct cache_mp_write_session_response c_mp_ws_response;
157 	struct cache_mp_write_session_write_request c_mp_ws_write_request;
158 	struct cache_mp_write_session_write_response c_mp_ws_write_response;
159 
160 	struct cache_mp_read_session_request c_mp_rs_request;
161 	struct cache_mp_read_session_response c_mp_rs_response;
162 	struct cache_mp_read_session_read_response c_mp_rs_read_response;
163 	} /* anonymous */;
164 	enum comm_element_t type;
165 };
166 
167 void init_comm_element(struct comm_element *, enum comm_element_t type);
168 void finalize_comm_element(struct comm_element *);
169 
170 /*
171  * For each type of data, there is three functions (init/finalize/get), that
172  * used with comm_element structure
173  */
174 void init_cache_write_request(struct cache_write_request *);
175 void finalize_cache_write_request(struct cache_write_request *);
176 struct cache_write_request *get_cache_write_request(struct comm_element *);
177 
178 void init_cache_write_response(struct cache_write_response *);
179 void finalize_cache_write_response(struct cache_write_response *);
180 struct cache_write_response *get_cache_write_response(struct comm_element *);
181 
182 void init_cache_read_request(struct cache_read_request *);
183 void finalize_cache_read_request(struct cache_read_request *);
184 struct cache_read_request *get_cache_read_request(struct comm_element *);
185 
186 void init_cache_read_response(struct cache_read_response *);
187 void finalize_cache_read_response(struct cache_read_response *);
188 struct cache_read_response *get_cache_read_response(struct comm_element *);
189 
190 void init_cache_transform_request(struct cache_transform_request *);
191 void finalize_cache_transform_request(struct cache_transform_request *);
192 struct cache_transform_request *get_cache_transform_request(
193 	struct comm_element *);
194 
195 void init_cache_transform_response(struct cache_transform_response *);
196 void finalize_cache_transform_response(struct cache_transform_response *);
197 struct cache_transform_response *get_cache_transform_response(
198 	struct comm_element *);
199 
200 void init_cache_mp_write_session_request(
201 	struct cache_mp_write_session_request *);
202 void finalize_cache_mp_write_session_request(
203 	struct cache_mp_write_session_request *);
204 struct cache_mp_write_session_request *
205     	get_cache_mp_write_session_request(struct comm_element *);
206 
207 void init_cache_mp_write_session_response(
208 	struct cache_mp_write_session_response *);
209 void finalize_cache_mp_write_session_response(
210 	struct cache_mp_write_session_response *);
211 struct cache_mp_write_session_response *
212 	get_cache_mp_write_session_response(struct comm_element *);
213 
214 void init_cache_mp_write_session_write_request(
215 	struct cache_mp_write_session_write_request *);
216 void finalize_cache_mp_write_session_write_request(
217 	struct cache_mp_write_session_write_request *);
218 struct cache_mp_write_session_write_request *
219 	get_cache_mp_write_session_write_request(struct comm_element *);
220 
221 void init_cache_mp_write_session_write_response(
222 	struct cache_mp_write_session_write_response *);
223 void finalize_cache_mp_write_session_write_response(
224 	struct cache_mp_write_session_write_response *);
225 struct cache_mp_write_session_write_response *
226 	get_cache_mp_write_session_write_response(struct comm_element *);
227 
228 void init_cache_mp_read_session_request(
229 	struct cache_mp_read_session_request *);
230 void finalize_cache_mp_read_session_request(
231 	struct cache_mp_read_session_request *);
232 struct cache_mp_read_session_request *get_cache_mp_read_session_request(
233 	struct comm_element *);
234 
235 void init_cache_mp_read_session_response(
236 	struct cache_mp_read_session_response *);
237 void finalize_cache_mp_read_session_response(
238 	struct cache_mp_read_session_response *);
239 struct cache_mp_read_session_response *
240     	get_cache_mp_read_session_response(struct comm_element *);
241 
242 void init_cache_mp_read_session_read_response(
243 	struct cache_mp_read_session_read_response *);
244 void finalize_cache_mp_read_session_read_response(
245 	struct cache_mp_read_session_read_response *);
246 struct cache_mp_read_session_read_response *
247 	get_cache_mp_read_session_read_response(struct comm_element *);
248 
249 #endif
250