protocol.h revision 194112
1258945Sroberto/*-
2280849Scy * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
3258945Sroberto * All rights reserved.
4258945Sroberto *
5258945Sroberto * Redistribution and use in source and binary forms, with or without
6258945Sroberto * modification, are permitted provided that the following conditions
7258945Sroberto * are met:
8258945Sroberto * 1. Redistributions of source code must retain the above copyright
9258945Sroberto *    notice, this list of conditions and the following disclaimer.
10258945Sroberto * 2. Redistributions in binary form must reproduce the above copyright
11258945Sroberto *    notice, this list of conditions and the following disclaimer in the
12258945Sroberto *    documentation and/or other materials provided with the distribution.
13258945Sroberto *
14258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15258945Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16258945Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17258945Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18280849Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19258945Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20258945Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21258945Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22258945Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23258945Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24258945Sroberto * SUCH DAMAGE.
25258945Sroberto *
26258945Sroberto * $FreeBSD: head/usr.sbin/nscd/protocol.h 194112 2009-06-13 14:12:55Z des $
27280849Scy */
28280849Scy
29280849Scy#ifndef __NSCD_PROTOCOL_H__
30280849Scy#define __NSCD_PROTOCOL_H__
31258945Sroberto
32280849Scy/* maximum buffer size to receive - larger buffers are not allowed */
33280849Scy#define MAX_BUFFER_SIZE (1 << 20)
34280849Scy
35280849Scy/* buffer size correctness checking routine */
36258945Sroberto#define BUFSIZE_CORRECT(x) (((x) > 0) && ((x) < MAX_BUFFER_SIZE))
37258945Sroberto#define BUFSIZE_INVALID(x) (!BUFSIZE_CORRECT(x))
38258945Sroberto
39258945Sroberto/* structures below represent the data that are sent/received by the daemon */
40258945Srobertostruct cache_write_request {
41258945Sroberto	char	*entry;
42258945Sroberto	char	*cache_key;
43258945Sroberto	char	*data;
44258945Sroberto
45258945Sroberto	size_t	entry_length;
46258945Sroberto	size_t	cache_key_size;
47258945Sroberto	size_t	data_size;
48258945Sroberto};
49258945Sroberto
50258945Srobertostruct cache_write_response {
51258945Sroberto	int	error_code;
52258945Sroberto};
53258945Sroberto
54258945Srobertostruct cache_read_request {
55258945Sroberto	char	*entry;
56258945Sroberto	char	*cache_key;
57258945Sroberto
58258945Sroberto	size_t	entry_length;
59258945Sroberto	size_t	cache_key_size;
60258945Sroberto};
61258945Sroberto
62258945Srobertostruct cache_read_response {
63258945Sroberto	char	*data;			// ignored if error_code is not 0
64258945Sroberto	size_t	data_size;		// ignored if error_code is not 0
65258945Sroberto
66258945Sroberto	int	error_code;
67258945Sroberto};
68258945Sroberto
69258945Srobertoenum transformation_type {
70258945Sroberto	TT_USER = 0,	// tranform only the entries of the caller
71258945Sroberto	TT_ALL = 1	// transform all entries
72258945Sroberto};
73258945Sroberto
74258945Srobertostruct cache_transform_request {
75258945Sroberto	char	*entry; 		// ignored if entry_length is 0
76258945Sroberto	size_t	entry_length;
77258945Sroberto
78258945Sroberto	int	transformation_type;
79258945Sroberto};
80258945Sroberto
81258945Srobertostruct cache_transform_response {
82258945Sroberto	int	error_code;
83258945Sroberto};
84258945Sroberto
85280849Scystruct cache_mp_write_session_request {
86280849Scy	char	*entry;
87280849Scy	size_t	entry_length;
88280849Scy};
89280849Scy
90280849Scystruct cache_mp_write_session_response {
91280849Scy	int	error_code;
92280849Scy};
93280849Scy
94280849Scystruct cache_mp_write_session_write_request {
95280849Scy	char	*data;
96280849Scy	size_t	data_size;
97280849Scy};
98280849Scy
99280849Scystruct cache_mp_write_session_write_response {
100280849Scy	int	error_code;
101280849Scy};
102280849Scy
103280849Scystruct cache_mp_read_session_request {
104	char	*entry;
105	size_t	entry_length;
106};
107
108struct cache_mp_read_session_response {
109	int	error_code;
110};
111
112struct cache_mp_read_session_read_response {
113	char	*data;
114	size_t	data_size;
115
116	int	error_code;
117};
118
119
120enum 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 */
146struct 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
167void init_comm_element(struct comm_element *, enum comm_element_t type);
168void 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 */
174void init_cache_write_request(struct cache_write_request *);
175void finalize_cache_write_request(struct cache_write_request *);
176struct cache_write_request *get_cache_write_request(struct comm_element *);
177
178void init_cache_write_response(struct cache_write_response *);
179void finalize_cache_write_response(struct cache_write_response *);
180struct cache_write_response *get_cache_write_response(struct comm_element *);
181
182void init_cache_read_request(struct cache_read_request *);
183void finalize_cache_read_request(struct cache_read_request *);
184struct cache_read_request *get_cache_read_request(struct comm_element *);
185
186void init_cache_read_response(struct cache_read_response *);
187void finalize_cache_read_response(struct cache_read_response *);
188struct cache_read_response *get_cache_read_response(struct comm_element *);
189
190void init_cache_transform_request(struct cache_transform_request *);
191void finalize_cache_transform_request(struct cache_transform_request *);
192struct cache_transform_request *get_cache_transform_request(
193	struct comm_element *);
194
195void init_cache_transform_response(struct cache_transform_response *);
196void finalize_cache_transform_response(struct cache_transform_response *);
197struct cache_transform_response *get_cache_transform_response(
198	struct comm_element *);
199
200void init_cache_mp_write_session_request(
201	struct cache_mp_write_session_request *);
202void finalize_cache_mp_write_session_request(
203	struct cache_mp_write_session_request *);
204struct cache_mp_write_session_request *
205    	get_cache_mp_write_session_request(struct comm_element *);
206
207void init_cache_mp_write_session_response(
208	struct cache_mp_write_session_response *);
209void finalize_cache_mp_write_session_response(
210	struct cache_mp_write_session_response *);
211struct cache_mp_write_session_response *
212	get_cache_mp_write_session_response(struct comm_element *);
213
214void init_cache_mp_write_session_write_request(
215	struct cache_mp_write_session_write_request *);
216void finalize_cache_mp_write_session_write_request(
217	struct cache_mp_write_session_write_request *);
218struct cache_mp_write_session_write_request *
219	get_cache_mp_write_session_write_request(struct comm_element *);
220
221void init_cache_mp_write_session_write_response(
222	struct cache_mp_write_session_write_response *);
223void finalize_cache_mp_write_session_write_response(
224	struct cache_mp_write_session_write_response *);
225struct cache_mp_write_session_write_response *
226	get_cache_mp_write_session_write_response(struct comm_element *);
227
228void init_cache_mp_read_session_request(
229	struct cache_mp_read_session_request *);
230void finalize_cache_mp_read_session_request(
231	struct cache_mp_read_session_request *);
232struct cache_mp_read_session_request *get_cache_mp_read_session_request(
233	struct comm_element *);
234
235void init_cache_mp_read_session_response(
236	struct cache_mp_read_session_response *);
237void finalize_cache_mp_read_session_response(
238	struct cache_mp_read_session_response *);
239struct cache_mp_read_session_response *
240    	get_cache_mp_read_session_response(struct comm_element *);
241
242void init_cache_mp_read_session_read_response(
243	struct cache_mp_read_session_read_response *);
244void finalize_cache_mp_read_session_read_response(
245	struct cache_mp_read_session_read_response *);
246struct cache_mp_read_session_read_response *
247	get_cache_mp_read_session_read_response(struct comm_element *);
248
249#endif
250