query.h revision 158115
1158115Sume/*- 2158115Sume * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 3158115Sume * All rights reserved. 4158115Sume * 5158115Sume * Redistribution and use in source and binary forms, with or without 6158115Sume * modification, are permitted provided that the following conditions 7158115Sume * are met: 8158115Sume * 1. Redistributions of source code must retain the above copyright 9158115Sume * notice, this list of conditions and the following disclaimer. 10158115Sume * 2. Redistributions in binary form must reproduce the above copyright 11158115Sume * notice, this list of conditions and the following disclaimer in the 12158115Sume * documentation and/or other materials provided with the distribution. 13158115Sume * 14158115Sume * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15158115Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16158115Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17158115Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18158115Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19158115Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20158115Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21158115Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22158115Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23158115Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24158115Sume * SUCH DAMAGE. 25158115Sume * 26158115Sume * $FreeBSD: head/usr.sbin/nscd/query.h 158115 2006-04-28 12:03:38Z ume $ 27158115Sume */ 28158115Sume 29158115Sume#ifndef __CACHED_QUERY_H__ 30158115Sume#define __CACHED_QUERY_H__ 31158115Sume 32158115Sume#include <sys/types.h> 33158115Sume#include <stdlib.h> 34158115Sume#include <unistd.h> 35158115Sume#include "cachelib.h" 36158115Sume#include "config.h" 37158115Sume#include "protocol.h" 38158115Sume 39158115Sumestruct query_state; 40158115Sumestruct configuration; 41158115Sumestruct configuration_entry; 42158115Sume 43158115Sumetypedef int (*query_process_func)(struct query_state *); 44158115Sumetypedef void (*query_destroy_func)(struct query_state *); 45158115Sumetypedef ssize_t (*query_read_func)(struct query_state *, void *, size_t); 46158115Sumetypedef ssize_t (*query_write_func)(struct query_state *, const void *, 47158115Sume size_t); 48158115Sume 49158115Sume/* 50158115Sume * The query state structure contains the information to process all types of 51158115Sume * requests and to send all types of responses. 52158115Sume */ 53158115Sumestruct query_state { 54158115Sume struct timeval creation_time; 55158115Sume struct timeval timeout; 56158115Sume 57158115Sume struct comm_element request; 58158115Sume struct comm_element response; 59158115Sume struct configuration_entry *config_entry; 60158115Sume void *mdata; 61158115Sume 62158115Sume query_process_func process_func; /* called on each event */ 63158115Sume query_destroy_func destroy_func; /* called on destroy */ 64158115Sume 65158115Sume /* 66158115Sume * By substituting these functions we can opaquely send and received 67158115Sume * very large buffers 68158115Sume */ 69158115Sume query_write_func write_func; /* data write function */ 70158115Sume query_read_func read_func; /* data read function */ 71158115Sume 72158115Sume char *eid_str; /* the user-identifying string (euid_egid_) */ 73158115Sume size_t eid_str_length; 74158115Sume 75158115Sume uid_t euid; /* euid of the caller, received via getpeereid */ 76158115Sume uid_t uid; /* uid of the caller, received via credentials */ 77158115Sume gid_t egid; /* egid of the caller, received via getpeereid */ 78158115Sume gid_t gid; /* gid of the caller received via credentials */ 79158115Sume 80158115Sume size_t io_buffer_size; 81158115Sume size_t io_buffer_watermark; 82158115Sume size_t kevent_watermark; /* bytes to be sent/received */ 83158115Sume int sockfd; /* the unix socket to read/write */ 84158115Sume int kevent_filter; /* EVFILT_READ or EVFILT_WRITE */ 85158115Sume int socket_failed; /* set to 1 if the socket doesn't work correctly */ 86158115Sume 87158115Sume /* 88158115Sume * These fields are used to opaquely proceed sending/receiving of 89158115Sume * the large buffers 90158115Sume */ 91158115Sume char *io_buffer; 92158115Sume char *io_buffer_p; 93158115Sume int io_buffer_filter; 94158115Sume int use_alternate_io; 95158115Sume}; 96158115Sume 97158115Sumeextern int check_query_eids(struct query_state *); 98158115Sume 99158115Sumeextern ssize_t query_io_buffer_read(struct query_state *, void *, size_t); 100158115Sumeextern ssize_t query_io_buffer_write(struct query_state *, const void *, 101158115Sume size_t); 102158115Sume 103158115Sumeextern ssize_t query_socket_read(struct query_state *, void *, size_t); 104158115Sumeextern ssize_t query_socket_write(struct query_state *, const void *, 105158115Sume size_t); 106158115Sume 107158115Sumeextern struct query_state *init_query_state(int, size_t, uid_t, gid_t); 108158115Sumeextern void destroy_query_state(struct query_state *); 109158115Sume 110158115Sume#endif 111