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