query.h revision 194089
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 * $FreeBSD: head/usr.sbin/nscd/query.h 194089 2009-06-13 00:06:52Z des $ 27 */ 28 29#ifndef __NSCD_QUERY_H__ 30#define __NSCD_QUERY_H__ 31 32#include "cachelib.h" 33#include "config.h" 34#include "protocol.h" 35 36struct query_state; 37struct configuration; 38struct configuration_entry; 39 40typedef int (*query_process_func)(struct query_state *); 41typedef void (*query_destroy_func)(struct query_state *); 42typedef ssize_t (*query_read_func)(struct query_state *, void *, size_t); 43typedef ssize_t (*query_write_func)(struct query_state *, const void *, 44 size_t); 45 46/* 47 * The query state structure contains the information to process all types of 48 * requests and to send all types of responses. 49 */ 50struct query_state { 51 struct timeval creation_time; 52 struct timeval timeout; 53 54 struct comm_element request; 55 struct comm_element response; 56 struct configuration_entry *config_entry; 57 void *mdata; 58 59 query_process_func process_func; /* called on each event */ 60 query_destroy_func destroy_func; /* called on destroy */ 61 62 /* 63 * By substituting these functions we can opaquely send and received 64 * very large buffers 65 */ 66 query_write_func write_func; /* data write function */ 67 query_read_func read_func; /* data read function */ 68 69 char *eid_str; /* the user-identifying string (euid_egid_) */ 70 size_t eid_str_length; 71 72 uid_t euid; /* euid of the caller, received via getpeereid */ 73 uid_t uid; /* uid of the caller, received via credentials */ 74 gid_t egid; /* egid of the caller, received via getpeereid */ 75 gid_t gid; /* gid of the caller received via credentials */ 76 77 size_t io_buffer_size; 78 size_t io_buffer_watermark; 79 size_t kevent_watermark; /* bytes to be sent/received */ 80 int sockfd; /* the unix socket to read/write */ 81 int kevent_filter; /* EVFILT_READ or EVFILT_WRITE */ 82 int socket_failed; /* set to 1 if the socket doesn't work correctly */ 83 84 /* 85 * These fields are used to opaquely proceed sending/receiving of 86 * the large buffers 87 */ 88 char *io_buffer; 89 char *io_buffer_p; 90 int io_buffer_filter; 91 int use_alternate_io; 92}; 93 94extern int check_query_eids(struct query_state *); 95 96extern ssize_t query_io_buffer_read(struct query_state *, void *, size_t); 97extern ssize_t query_io_buffer_write(struct query_state *, const void *, 98 size_t); 99 100extern ssize_t query_socket_read(struct query_state *, void *, size_t); 101extern ssize_t query_socket_write(struct query_state *, const void *, 102 size_t); 103 104extern struct query_state *init_query_state(int, size_t, uid_t, gid_t); 105extern void destroy_query_state(struct query_state *); 106 107#endif 108