1c43e99fdSEd Maste /* 2c43e99fdSEd Maste * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 3c43e99fdSEd Maste * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4c43e99fdSEd Maste * 5c43e99fdSEd Maste * Redistribution and use in source and binary forms, with or without 6c43e99fdSEd Maste * modification, are permitted provided that the following conditions 7c43e99fdSEd Maste * are met: 8c43e99fdSEd Maste * 1. Redistributions of source code must retain the above copyright 9c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer. 10c43e99fdSEd Maste * 2. Redistributions in binary form must reproduce the above copyright 11c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer in the 12c43e99fdSEd Maste * documentation and/or other materials provided with the distribution. 13c43e99fdSEd Maste * 3. The name of the author may not be used to endorse or promote products 14c43e99fdSEd Maste * derived from this software without specific prior written permission. 15c43e99fdSEd Maste * 16c43e99fdSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17c43e99fdSEd Maste * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18c43e99fdSEd Maste * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19c43e99fdSEd Maste * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20c43e99fdSEd Maste * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21c43e99fdSEd Maste * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22c43e99fdSEd Maste * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23c43e99fdSEd Maste * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24c43e99fdSEd Maste * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25c43e99fdSEd Maste * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26c43e99fdSEd Maste */ 27c43e99fdSEd Maste #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ 28c43e99fdSEd Maste #define EVENT2_RPC_STRUCT_H_INCLUDED_ 29c43e99fdSEd Maste 30c43e99fdSEd Maste #ifdef __cplusplus 31c43e99fdSEd Maste extern "C" { 32c43e99fdSEd Maste #endif 33c43e99fdSEd Maste 34c43e99fdSEd Maste /** @file event2/rpc_struct.h 35c43e99fdSEd Maste 36c43e99fdSEd Maste Structures used by rpc.h. Using these structures directly may harm 37c43e99fdSEd Maste forward compatibility: be careful! 38c43e99fdSEd Maste 39c43e99fdSEd Maste */ 40c43e99fdSEd Maste 41*b50261e2SCy Schubert /* Fix so that people don't have to run with <sys/queue.h> */ 42*b50261e2SCy Schubert #ifndef TAILQ_ENTRY 43*b50261e2SCy Schubert #define EVENT_DEFINED_TQENTRY_ 44*b50261e2SCy Schubert #define TAILQ_ENTRY(type) \ 45*b50261e2SCy Schubert struct { \ 46*b50261e2SCy Schubert struct type *tqe_next; /* next element */ \ 47*b50261e2SCy Schubert struct type **tqe_prev; /* address of previous next element */ \ 48*b50261e2SCy Schubert } 49*b50261e2SCy Schubert #endif /* !TAILQ_ENTRY */ 50*b50261e2SCy Schubert 51c43e99fdSEd Maste /** 52c43e99fdSEd Maste * provides information about the completed RPC request. 53c43e99fdSEd Maste */ 54c43e99fdSEd Maste struct evrpc_status { 55c43e99fdSEd Maste #define EVRPC_STATUS_ERR_NONE 0 56c43e99fdSEd Maste #define EVRPC_STATUS_ERR_TIMEOUT 1 57c43e99fdSEd Maste #define EVRPC_STATUS_ERR_BADPAYLOAD 2 58c43e99fdSEd Maste #define EVRPC_STATUS_ERR_UNSTARTED 3 59c43e99fdSEd Maste #define EVRPC_STATUS_ERR_HOOKABORTED 4 60c43e99fdSEd Maste int error; 61c43e99fdSEd Maste 62c43e99fdSEd Maste /* for looking at headers or other information */ 63c43e99fdSEd Maste struct evhttp_request *http_req; 64c43e99fdSEd Maste }; 65c43e99fdSEd Maste 66c43e99fdSEd Maste /* the structure below needs to be synchronized with evrpc_req_generic */ 67c43e99fdSEd Maste 68c43e99fdSEd Maste /* Encapsulates a request */ 69c43e99fdSEd Maste struct evrpc { 70c43e99fdSEd Maste TAILQ_ENTRY(evrpc) next; 71c43e99fdSEd Maste 72c43e99fdSEd Maste /* the URI at which the request handler lives */ 73c43e99fdSEd Maste const char* uri; 74c43e99fdSEd Maste 75c43e99fdSEd Maste /* creates a new request structure */ 76c43e99fdSEd Maste void *(*request_new)(void *); 77c43e99fdSEd Maste void *request_new_arg; 78c43e99fdSEd Maste 79c43e99fdSEd Maste /* frees the request structure */ 80c43e99fdSEd Maste void (*request_free)(void *); 81c43e99fdSEd Maste 82c43e99fdSEd Maste /* unmarshals the buffer into the proper request structure */ 83c43e99fdSEd Maste int (*request_unmarshal)(void *, struct evbuffer *); 84c43e99fdSEd Maste 85c43e99fdSEd Maste /* creates a new reply structure */ 86c43e99fdSEd Maste void *(*reply_new)(void *); 87c43e99fdSEd Maste void *reply_new_arg; 88c43e99fdSEd Maste 89c43e99fdSEd Maste /* frees the reply structure */ 90c43e99fdSEd Maste void (*reply_free)(void *); 91c43e99fdSEd Maste 92c43e99fdSEd Maste /* verifies that the reply is valid */ 93c43e99fdSEd Maste int (*reply_complete)(void *); 94c43e99fdSEd Maste 95c43e99fdSEd Maste /* marshals the reply into a buffer */ 96c43e99fdSEd Maste void (*reply_marshal)(struct evbuffer*, void *); 97c43e99fdSEd Maste 98c43e99fdSEd Maste /* the callback invoked for each received rpc */ 99c43e99fdSEd Maste void (*cb)(struct evrpc_req_generic *, void *); 100c43e99fdSEd Maste void *cb_arg; 101c43e99fdSEd Maste 102c43e99fdSEd Maste /* reference for further configuration */ 103c43e99fdSEd Maste struct evrpc_base *base; 104c43e99fdSEd Maste }; 105c43e99fdSEd Maste 106*b50261e2SCy Schubert #ifdef EVENT_DEFINED_TQENTRY_ 107*b50261e2SCy Schubert #undef TAILQ_ENTRY 108*b50261e2SCy Schubert #endif 109*b50261e2SCy Schubert 110c43e99fdSEd Maste #ifdef __cplusplus 111c43e99fdSEd Maste } 112c43e99fdSEd Maste #endif 113c43e99fdSEd Maste 114c43e99fdSEd Maste #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ 115