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