12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 32b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 42b15cb3dSCy Schubert * 52b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 62b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 72b15cb3dSCy Schubert * are met: 82b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 92b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 102b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 112b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 122b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 132b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 142b15cb3dSCy Schubert * derived from this software without specific prior written permission. 152b15cb3dSCy Schubert * 162b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 172b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 182b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 192b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 202b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 212b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 252b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262b15cb3dSCy Schubert */ 272b15cb3dSCy Schubert #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ 282b15cb3dSCy Schubert #define EVENT2_RPC_STRUCT_H_INCLUDED_ 292b15cb3dSCy Schubert 302b15cb3dSCy Schubert #ifdef __cplusplus 312b15cb3dSCy Schubert extern "C" { 322b15cb3dSCy Schubert #endif 332b15cb3dSCy Schubert 342b15cb3dSCy Schubert /** @file event2/rpc_struct.h 352b15cb3dSCy Schubert 362b15cb3dSCy Schubert Structures used by rpc.h. Using these structures directly may harm 372b15cb3dSCy Schubert forward compatibility: be careful! 382b15cb3dSCy Schubert 392b15cb3dSCy Schubert */ 402b15cb3dSCy Schubert 41*a466cc55SCy Schubert /* Fix so that people don't have to run with <sys/queue.h> */ 42*a466cc55SCy Schubert #ifndef TAILQ_ENTRY 43*a466cc55SCy Schubert #define EVENT_DEFINED_TQENTRY_ 44*a466cc55SCy Schubert #define TAILQ_ENTRY(type) \ 45*a466cc55SCy Schubert struct { \ 46*a466cc55SCy Schubert struct type *tqe_next; /* next element */ \ 47*a466cc55SCy Schubert struct type **tqe_prev; /* address of previous next element */ \ 48*a466cc55SCy Schubert } 49*a466cc55SCy Schubert #endif /* !TAILQ_ENTRY */ 50*a466cc55SCy Schubert 512b15cb3dSCy Schubert /** 522b15cb3dSCy Schubert * provides information about the completed RPC request. 532b15cb3dSCy Schubert */ 542b15cb3dSCy Schubert struct evrpc_status { 552b15cb3dSCy Schubert #define EVRPC_STATUS_ERR_NONE 0 562b15cb3dSCy Schubert #define EVRPC_STATUS_ERR_TIMEOUT 1 572b15cb3dSCy Schubert #define EVRPC_STATUS_ERR_BADPAYLOAD 2 582b15cb3dSCy Schubert #define EVRPC_STATUS_ERR_UNSTARTED 3 592b15cb3dSCy Schubert #define EVRPC_STATUS_ERR_HOOKABORTED 4 602b15cb3dSCy Schubert int error; 612b15cb3dSCy Schubert 622b15cb3dSCy Schubert /* for looking at headers or other information */ 632b15cb3dSCy Schubert struct evhttp_request *http_req; 642b15cb3dSCy Schubert }; 652b15cb3dSCy Schubert 662b15cb3dSCy Schubert /* the structure below needs to be synchronized with evrpc_req_generic */ 672b15cb3dSCy Schubert 682b15cb3dSCy Schubert /* Encapsulates a request */ 692b15cb3dSCy Schubert struct evrpc { 702b15cb3dSCy Schubert TAILQ_ENTRY(evrpc) next; 712b15cb3dSCy Schubert 722b15cb3dSCy Schubert /* the URI at which the request handler lives */ 732b15cb3dSCy Schubert const char* uri; 742b15cb3dSCy Schubert 752b15cb3dSCy Schubert /* creates a new request structure */ 762b15cb3dSCy Schubert void *(*request_new)(void *); 772b15cb3dSCy Schubert void *request_new_arg; 782b15cb3dSCy Schubert 792b15cb3dSCy Schubert /* frees the request structure */ 802b15cb3dSCy Schubert void (*request_free)(void *); 812b15cb3dSCy Schubert 822b15cb3dSCy Schubert /* unmarshals the buffer into the proper request structure */ 832b15cb3dSCy Schubert int (*request_unmarshal)(void *, struct evbuffer *); 842b15cb3dSCy Schubert 852b15cb3dSCy Schubert /* creates a new reply structure */ 862b15cb3dSCy Schubert void *(*reply_new)(void *); 872b15cb3dSCy Schubert void *reply_new_arg; 882b15cb3dSCy Schubert 892b15cb3dSCy Schubert /* frees the reply structure */ 902b15cb3dSCy Schubert void (*reply_free)(void *); 912b15cb3dSCy Schubert 922b15cb3dSCy Schubert /* verifies that the reply is valid */ 932b15cb3dSCy Schubert int (*reply_complete)(void *); 942b15cb3dSCy Schubert 952b15cb3dSCy Schubert /* marshals the reply into a buffer */ 962b15cb3dSCy Schubert void (*reply_marshal)(struct evbuffer*, void *); 972b15cb3dSCy Schubert 982b15cb3dSCy Schubert /* the callback invoked for each received rpc */ 992b15cb3dSCy Schubert void (*cb)(struct evrpc_req_generic *, void *); 1002b15cb3dSCy Schubert void *cb_arg; 1012b15cb3dSCy Schubert 1022b15cb3dSCy Schubert /* reference for further configuration */ 1032b15cb3dSCy Schubert struct evrpc_base *base; 1042b15cb3dSCy Schubert }; 1052b15cb3dSCy Schubert 106*a466cc55SCy Schubert #ifdef EVENT_DEFINED_TQENTRY_ 107*a466cc55SCy Schubert #undef TAILQ_ENTRY 108*a466cc55SCy Schubert #endif 109*a466cc55SCy Schubert 1102b15cb3dSCy Schubert #ifdef __cplusplus 1112b15cb3dSCy Schubert } 1122b15cb3dSCy Schubert #endif 1132b15cb3dSCy Schubert 1142b15cb3dSCy Schubert #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ 115