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