2 * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
26 * $FreeBSD: src/usr.sbin/nscd/protocol.c,v 1.2 2007/09/27 12:30:11 bushman Exp $
37 * Initializes the comm_element with any given type of data
40 init_comm_element(struct comm_element
*element
, enum comm_element_t type
)
43 TRACE_IN(init_comm_element
);
44 memset(element
, 0, sizeof(struct comm_element
));
47 case CET_WRITE_REQUEST
:
48 init_cache_write_request(&element
->c_write_request
);
50 case CET_WRITE_RESPONSE
:
51 init_cache_write_response(&element
->c_write_response
);
53 case CET_READ_REQUEST
:
54 init_cache_read_request(&element
->c_read_request
);
56 case CET_READ_RESPONSE
:
57 init_cache_read_response(&element
->c_read_response
);
59 case CET_TRANSFORM_REQUEST
:
60 init_cache_transform_request(&element
->c_transform_request
);
62 case CET_TRANSFORM_RESPONSE
:
63 init_cache_transform_response(&element
->c_transform_response
);
65 case CET_MP_WRITE_SESSION_REQUEST
:
66 init_cache_mp_write_session_request(&element
->c_mp_ws_request
);
68 case CET_MP_WRITE_SESSION_RESPONSE
:
69 init_cache_mp_write_session_response(&element
->c_mp_ws_response
);
71 case CET_MP_WRITE_SESSION_WRITE_REQUEST
:
72 init_cache_mp_write_session_write_request(
73 &element
->c_mp_ws_write_request
);
75 case CET_MP_WRITE_SESSION_WRITE_RESPONSE
:
76 init_cache_mp_write_session_write_response(
77 &element
->c_mp_ws_write_response
);
79 case CET_MP_READ_SESSION_REQUEST
:
80 init_cache_mp_read_session_request(&element
->c_mp_rs_request
);
82 case CET_MP_READ_SESSION_RESPONSE
:
83 init_cache_mp_read_session_response(&element
->c_mp_rs_response
);
85 case CET_MP_READ_SESSION_READ_RESPONSE
:
86 init_cache_mp_read_session_read_response(
87 &element
->c_mp_rs_read_response
);
92 LOG_ERR_2("init_comm_element", "invalid communication element");
93 TRACE_OUT(init_comm_element
);
98 TRACE_OUT(init_comm_element
);
102 finalize_comm_element(struct comm_element
*element
)
105 TRACE_IN(finalize_comm_element
);
106 switch (element
->type
) {
107 case CET_WRITE_REQUEST
:
108 finalize_cache_write_request(&element
->c_write_request
);
110 case CET_WRITE_RESPONSE
:
111 finalize_cache_write_response(&element
->c_write_response
);
113 case CET_READ_REQUEST
:
114 finalize_cache_read_request(&element
->c_read_request
);
116 case CET_READ_RESPONSE
:
117 finalize_cache_read_response(&element
->c_read_response
);
119 case CET_TRANSFORM_REQUEST
:
120 finalize_cache_transform_request(&element
->c_transform_request
);
122 case CET_TRANSFORM_RESPONSE
:
123 finalize_cache_transform_response(
124 &element
->c_transform_response
);
126 case CET_MP_WRITE_SESSION_REQUEST
:
127 finalize_cache_mp_write_session_request(
128 &element
->c_mp_ws_request
);
130 case CET_MP_WRITE_SESSION_RESPONSE
:
131 finalize_cache_mp_write_session_response(
132 &element
->c_mp_ws_response
);
134 case CET_MP_WRITE_SESSION_WRITE_REQUEST
:
135 finalize_cache_mp_write_session_write_request(
136 &element
->c_mp_ws_write_request
);
138 case CET_MP_WRITE_SESSION_WRITE_RESPONSE
:
139 finalize_cache_mp_write_session_write_response(
140 &element
->c_mp_ws_write_response
);
142 case CET_MP_READ_SESSION_REQUEST
:
143 finalize_cache_mp_read_session_request(
144 &element
->c_mp_rs_request
);
146 case CET_MP_READ_SESSION_RESPONSE
:
147 finalize_cache_mp_read_session_response(
148 &element
->c_mp_rs_response
);
150 case CET_MP_READ_SESSION_READ_RESPONSE
:
151 finalize_cache_mp_read_session_read_response(
152 &element
->c_mp_rs_read_response
);
160 element
->type
= CET_UNDEFINED
;
161 TRACE_OUT(finalize_comm_element
);
165 init_cache_write_request(struct cache_write_request
*write_request
)
168 TRACE_IN(init_cache_write_request
);
169 memset(write_request
, 0, sizeof(struct cache_write_request
));
170 TRACE_OUT(init_cache_write_request
);
174 finalize_cache_write_request(struct cache_write_request
*write_request
)
177 TRACE_IN(finalize_cache_write_request
);
178 free(write_request
->entry
);
179 free(write_request
->cache_key
);
180 free(write_request
->data
);
181 TRACE_OUT(finalize_cache_write_request
);
184 struct cache_write_request
*
185 get_cache_write_request(struct comm_element
*element
)
188 TRACE_IN(get_cache_write_request
);
189 assert(element
->type
== CET_WRITE_REQUEST
);
190 TRACE_OUT(get_cache_write_request
);
191 return (&element
->c_write_request
);
195 init_cache_write_response(struct cache_write_response
*write_response
)
198 TRACE_IN(init_cache_write_response
);
199 memset(write_response
, 0, sizeof(struct cache_write_response
));
200 TRACE_OUT(init_cache_write_response
);
204 finalize_cache_write_response(struct cache_write_response
*write_response
)
207 TRACE_IN(finalize_cache_write_response
);
208 TRACE_OUT(finalize_cache_write_response
);
211 struct cache_write_response
*
212 get_cache_write_response(struct comm_element
*element
)
215 TRACE_IN(get_cache_write_response
);
216 assert(element
->type
== CET_WRITE_RESPONSE
);
217 TRACE_OUT(get_cache_write_response
);
218 return (&element
->c_write_response
);
222 init_cache_read_request(struct cache_read_request
*read_request
)
225 TRACE_IN(init_cache_read_request
);
226 memset(read_request
, 0, sizeof(struct cache_read_request
));
227 TRACE_OUT(init_cache_read_request
);
231 finalize_cache_read_request(struct cache_read_request
*read_request
)
234 TRACE_IN(finalize_cache_read_request
);
235 free(read_request
->entry
);
236 free(read_request
->cache_key
);
237 TRACE_OUT(finalize_cache_read_request
);
240 struct cache_read_request
*
241 get_cache_read_request(struct comm_element
*element
)
244 TRACE_IN(get_cache_read_request
);
245 assert(element
->type
== CET_READ_REQUEST
);
246 TRACE_OUT(get_cache_read_request
);
247 return (&element
->c_read_request
);
251 init_cache_read_response(struct cache_read_response
*read_response
)
254 TRACE_IN(init_cache_read_response
);
255 memset(read_response
, 0, sizeof(struct cache_read_response
));
256 TRACE_OUT(init_cache_read_response
);
260 finalize_cache_read_response(struct cache_read_response
*read_response
)
263 TRACE_IN(finalize_cache_read_response
);
264 free(read_response
->data
);
265 TRACE_OUT(finalize_cache_read_response
);
268 struct cache_read_response
*
269 get_cache_read_response(struct comm_element
*element
)
272 TRACE_IN(get_cache_read_response
);
273 assert(element
->type
== CET_READ_RESPONSE
);
274 TRACE_OUT(get_cache_read_response
);
275 return (&element
->c_read_response
);
279 init_cache_transform_request(struct cache_transform_request
*transform_request
)
282 TRACE_IN(init_cache_transform_request
);
283 memset(transform_request
, 0, sizeof(struct cache_transform_request
));
284 TRACE_OUT(init_cache_transform_request
);
288 finalize_cache_transform_request(
289 struct cache_transform_request
*transform_request
)
292 TRACE_IN(finalize_cache_transform_request
);
293 free(transform_request
->entry
);
294 TRACE_OUT(finalize_cache_transform_request
);
297 struct cache_transform_request
*
298 get_cache_transform_request(struct comm_element
*element
)
301 TRACE_IN(get_cache_transform_request
);
302 assert(element
->type
== CET_TRANSFORM_REQUEST
);
303 TRACE_OUT(get_cache_transform_request
);
304 return (&element
->c_transform_request
);
308 init_cache_transform_response(
309 struct cache_transform_response
*transform_response
)
312 TRACE_IN(init_cache_transform_request
);
313 memset(transform_response
, 0, sizeof(struct cache_transform_response
));
314 TRACE_OUT(init_cache_transform_request
);
318 finalize_cache_transform_response(
319 struct cache_transform_response
*transform_response
)
322 TRACE_IN(finalize_cache_transform_response
);
323 TRACE_OUT(finalize_cache_transform_response
);
326 struct cache_transform_response
*
327 get_cache_transform_response(struct comm_element
*element
)
330 TRACE_IN(get_cache_transform_response
);
331 assert(element
->type
== CET_TRANSFORM_RESPONSE
);
332 TRACE_OUT(get_cache_transform_response
);
333 return (&element
->c_transform_response
);
338 init_cache_mp_write_session_request(
339 struct cache_mp_write_session_request
*mp_ws_request
)
342 TRACE_IN(init_cache_mp_write_session_request
);
343 memset(mp_ws_request
, 0,
344 sizeof(struct cache_mp_write_session_request
));
345 TRACE_OUT(init_cache_mp_write_session_request
);
349 finalize_cache_mp_write_session_request(
350 struct cache_mp_write_session_request
*mp_ws_request
)
353 TRACE_IN(finalize_cache_mp_write_session_request
);
354 free(mp_ws_request
->entry
);
355 TRACE_OUT(finalize_cache_mp_write_session_request
);
358 struct cache_mp_write_session_request
*
359 get_cache_mp_write_session_request(struct comm_element
*element
)
362 TRACE_IN(get_cache_mp_write_session_request
);
363 assert(element
->type
== CET_MP_WRITE_SESSION_REQUEST
);
364 TRACE_OUT(get_cache_mp_write_session_request
);
365 return (&element
->c_mp_ws_request
);
369 init_cache_mp_write_session_response(
370 struct cache_mp_write_session_response
*mp_ws_response
)
373 TRACE_IN(init_cache_mp_write_session_response
);
374 memset(mp_ws_response
, 0,
375 sizeof(struct cache_mp_write_session_response
));
376 TRACE_OUT(init_cache_mp_write_session_response
);
380 finalize_cache_mp_write_session_response(
381 struct cache_mp_write_session_response
*mp_ws_response
)
384 TRACE_IN(finalize_cache_mp_write_session_response
);
385 TRACE_OUT(finalize_cache_mp_write_session_response
);
388 struct cache_mp_write_session_response
*
389 get_cache_mp_write_session_response(struct comm_element
*element
)
392 TRACE_IN(get_cache_mp_write_session_response
);
393 assert(element
->type
== CET_MP_WRITE_SESSION_RESPONSE
);
394 TRACE_OUT(get_cache_mp_write_session_response
);
395 return (&element
->c_mp_ws_response
);
399 init_cache_mp_write_session_write_request(
400 struct cache_mp_write_session_write_request
*mp_ws_write_request
)
403 TRACE_IN(init_cache_mp_write_session_write_request
);
404 memset(mp_ws_write_request
, 0,
405 sizeof(struct cache_mp_write_session_write_request
));
406 TRACE_OUT(init_cache_mp_write_session_write_response
);
410 finalize_cache_mp_write_session_write_request(
411 struct cache_mp_write_session_write_request
*mp_ws_write_request
)
414 TRACE_IN(finalize_cache_mp_write_session_write_request
);
415 free(mp_ws_write_request
->data
);
416 TRACE_OUT(finalize_cache_mp_write_session_write_request
);
419 struct cache_mp_write_session_write_request
*
420 get_cache_mp_write_session_write_request(struct comm_element
*element
)
423 TRACE_IN(get_cache_mp_write_session_write_request
);
424 assert(element
->type
== CET_MP_WRITE_SESSION_WRITE_REQUEST
);
425 TRACE_OUT(get_cache_mp_write_session_write_request
);
426 return (&element
->c_mp_ws_write_request
);
430 init_cache_mp_write_session_write_response(
431 struct cache_mp_write_session_write_response
*mp_ws_write_response
)
434 TRACE_IN(init_cache_mp_write_session_write_response
);
435 memset(mp_ws_write_response
, 0,
436 sizeof(struct cache_mp_write_session_write_response
));
437 TRACE_OUT(init_cache_mp_write_session_write_response
);
441 finalize_cache_mp_write_session_write_response(
442 struct cache_mp_write_session_write_response
*mp_ws_write_response
)
445 TRACE_IN(finalize_cache_mp_write_session_write_response
);
446 TRACE_OUT(finalize_cache_mp_write_session_write_response
);
449 struct cache_mp_write_session_write_response
*
450 get_cache_mp_write_session_write_response(struct comm_element
*element
)
453 TRACE_IN(get_cache_mp_write_session_write_response
);
454 assert(element
->type
== CET_MP_WRITE_SESSION_WRITE_RESPONSE
);
455 TRACE_OUT(get_cache_mp_write_session_write_response
);
456 return (&element
->c_mp_ws_write_response
);
460 init_cache_mp_read_session_request(
461 struct cache_mp_read_session_request
*mp_rs_request
)
464 TRACE_IN(init_cache_mp_read_session_request
);
465 memset(mp_rs_request
, 0, sizeof(struct cache_mp_read_session_request
));
466 TRACE_OUT(init_cache_mp_read_session_request
);
470 finalize_cache_mp_read_session_request(
471 struct cache_mp_read_session_request
*mp_rs_request
)
474 TRACE_IN(finalize_cache_mp_read_session_request
);
475 free(mp_rs_request
->entry
);
476 TRACE_OUT(finalize_cache_mp_read_session_request
);
479 struct cache_mp_read_session_request
*
480 get_cache_mp_read_session_request(struct comm_element
*element
)
483 TRACE_IN(get_cache_mp_read_session_request
);
484 assert(element
->type
== CET_MP_READ_SESSION_REQUEST
);
485 TRACE_OUT(get_cache_mp_read_session_request
);
486 return (&element
->c_mp_rs_request
);
490 init_cache_mp_read_session_response(
491 struct cache_mp_read_session_response
*mp_rs_response
)
494 TRACE_IN(init_cache_mp_read_session_response
);
495 memset(mp_rs_response
, 0,
496 sizeof(struct cache_mp_read_session_response
));
497 TRACE_OUT(init_cache_mp_read_session_response
);
501 finalize_cache_mp_read_session_response(
502 struct cache_mp_read_session_response
*mp_rs_response
)
505 TRACE_IN(finalize_cache_mp_read_session_response
);
506 TRACE_OUT(finalize_cache_mp_read_session_response
);
509 struct cache_mp_read_session_response
*
510 get_cache_mp_read_session_response(struct comm_element
*element
)
513 TRACE_IN(get_cache_mp_read_session_response
);
514 assert(element
->type
== CET_MP_READ_SESSION_RESPONSE
);
515 TRACE_OUT(get_cache_mp_read_session_response
);
516 return (&element
->c_mp_rs_response
);
520 init_cache_mp_read_session_read_response(
521 struct cache_mp_read_session_read_response
*mp_ws_read_response
)
524 TRACE_IN(init_cache_mp_read_session_read_response
);
525 memset(mp_ws_read_response
, 0,
526 sizeof(struct cache_mp_read_session_read_response
));
527 TRACE_OUT(init_cache_mp_read_session_read_response
);
531 finalize_cache_mp_read_session_read_response(
532 struct cache_mp_read_session_read_response
*mp_rs_read_response
)
535 TRACE_IN(finalize_cache_mp_read_session_read_response
);
536 free(mp_rs_read_response
->data
);
537 TRACE_OUT(finalize_cache_mp_read_session_read_response
);
540 struct cache_mp_read_session_read_response
*
541 get_cache_mp_read_session_read_response(struct comm_element
*element
)
544 TRACE_IN(get_cache_mp_read_session_read_response
);
545 assert(element
->type
== CET_MP_READ_SESSION_READ_RESPONSE
);
546 TRACE_OUT(get_cache_mp_read_session_read_response
);
547 return (&element
->c_mp_rs_read_response
);