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$ 27158115Sume */ 28158115Sume 29171795Sbushman#ifndef __NSCD_QUERY_H__ 30171795Sbushman#define __NSCD_QUERY_H__ 31158115Sume 32158115Sume#include "cachelib.h" 33158115Sume#include "config.h" 34158115Sume#include "protocol.h" 35158115Sume 36158115Sumestruct query_state; 37158115Sumestruct configuration; 38158115Sumestruct configuration_entry; 39158115Sume 40158115Sumetypedef int (*query_process_func)(struct query_state *); 41158115Sumetypedef void (*query_destroy_func)(struct query_state *); 42158115Sumetypedef ssize_t (*query_read_func)(struct query_state *, void *, size_t); 43194112Sdestypedef ssize_t (*query_write_func)(struct query_state *, const void *, size_t); 44158115Sume 45158115Sume/* 46158115Sume * The query state structure contains the information to process all types of 47158115Sume * requests and to send all types of responses. 48158115Sume */ 49158115Sumestruct query_state { 50158115Sume struct timeval creation_time; 51158115Sume struct timeval timeout; 52158115Sume 53158115Sume struct comm_element request; 54158115Sume struct comm_element response; 55158115Sume struct configuration_entry *config_entry; 56158115Sume void *mdata; 57158115Sume 58158115Sume query_process_func process_func; /* called on each event */ 59158115Sume query_destroy_func destroy_func; /* called on destroy */ 60158115Sume 61158115Sume /* 62158115Sume * By substituting these functions we can opaquely send and received 63158115Sume * very large buffers 64158115Sume */ 65158115Sume query_write_func write_func; /* data write function */ 66158115Sume query_read_func read_func; /* data read function */ 67158115Sume 68158115Sume char *eid_str; /* the user-identifying string (euid_egid_) */ 69158115Sume size_t eid_str_length; 70158115Sume 71158115Sume uid_t euid; /* euid of the caller, received via getpeereid */ 72158115Sume uid_t uid; /* uid of the caller, received via credentials */ 73158115Sume gid_t egid; /* egid of the caller, received via getpeereid */ 74158115Sume gid_t gid; /* gid of the caller received via credentials */ 75158115Sume 76158115Sume size_t io_buffer_size; 77158115Sume size_t io_buffer_watermark; 78158115Sume size_t kevent_watermark; /* bytes to be sent/received */ 79158115Sume int sockfd; /* the unix socket to read/write */ 80158115Sume int kevent_filter; /* EVFILT_READ or EVFILT_WRITE */ 81158115Sume int socket_failed; /* set to 1 if the socket doesn't work correctly */ 82158115Sume 83158115Sume /* 84158115Sume * These fields are used to opaquely proceed sending/receiving of 85158115Sume * the large buffers 86158115Sume */ 87158115Sume char *io_buffer; 88158115Sume char *io_buffer_p; 89158115Sume int io_buffer_filter; 90158115Sume int use_alternate_io; 91158115Sume}; 92158115Sume 93194112Sdesint check_query_eids(struct query_state *); 94158115Sume 95194112Sdesssize_t query_io_buffer_read(struct query_state *, void *, size_t); 96194112Sdesssize_t query_io_buffer_write(struct query_state *, const void *, size_t); 97158115Sume 98194112Sdesssize_t query_socket_read(struct query_state *, void *, size_t); 99194112Sdesssize_t query_socket_write(struct query_state *, const void *, size_t); 100158115Sume 101194112Sdesstruct query_state *init_query_state(int, size_t, uid_t, gid_t); 102194112Sdesvoid destroy_query_state(struct query_state *); 103158115Sume 104158115Sume#endif 105