1126878Strhodes/* 2126878Strhodes * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 3126878Strhodes * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4126878Strhodes * 5126878Strhodes * Redistribution and use in source and binary forms, with or without 6126878Strhodes * modification, are permitted provided that the following conditions 7126878Strhodes * are met: 8126878Strhodes * 1. Redistributions of source code must retain the above copyright 9126878Strhodes * notice, this list of conditions and the following disclaimer. 10126878Strhodes * 2. Redistributions in binary form must reproduce the above copyright 11126878Strhodes * notice, this list of conditions and the following disclaimer in the 12126878Strhodes * documentation and/or other materials provided with the distribution. 13126878Strhodes * 3. The name of the author may not be used to endorse or promote products 14126878Strhodes * derived from this software without specific prior written permission. 15126878Strhodes * 16126878Strhodes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17126878Strhodes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18126878Strhodes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19126878Strhodes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20126878Strhodes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21126878Strhodes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22126878Strhodes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23126878Strhodes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24290225Sbapt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25126878Strhodes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26126878Strhodes */ 27126878Strhodes#ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ 28126878Strhodes#define EVENT2_RPC_STRUCT_H_INCLUDED_ 29130420Sru 30130420Sru#ifdef __cplusplus 31130420Sruextern "C" { 32126878Strhodes#endif 33126878Strhodes 34126878Strhodes/** @file event2/rpc_struct.h 35126878Strhodes 36126878Strhodes Structures used by rpc.h. Using these structures directly may harm 37126878Strhodes forward compatibility: be careful! 38126878Strhodes 39126878Strhodes */ 40126878Strhodes 41126878Strhodes/** 42126878Strhodes * provides information about the completed RPC request. 43126878Strhodes */ 44126878Strhodesstruct evrpc_status { 45126878Strhodes#define EVRPC_STATUS_ERR_NONE 0 46126878Strhodes#define EVRPC_STATUS_ERR_TIMEOUT 1 47126878Strhodes#define EVRPC_STATUS_ERR_BADPAYLOAD 2 48126878Strhodes#define EVRPC_STATUS_ERR_UNSTARTED 3 49126878Strhodes#define EVRPC_STATUS_ERR_HOOKABORTED 4 50130420Sru int error; 51126878Strhodes 52126878Strhodes /* for looking at headers or other information */ 53130420Sru struct evhttp_request *http_req; 54126878Strhodes}; 55126878Strhodes 56130420Sru/* the structure below needs to be synchronized with evrpc_req_generic */ 57126878Strhodes 58130420Sru/* Encapsulates a request */ 59126878Strhodesstruct evrpc { 60126878Strhodes TAILQ_ENTRY(evrpc) next; 61130420Sru 62126878Strhodes /* the URI at which the request handler lives */ 63180019Ssobomax const char* uri; 64126878Strhodes 65180019Ssobomax /* creates a new request structure */ 66126878Strhodes void *(*request_new)(void *); 67130420Sru void *request_new_arg; 68130420Sru 69126878Strhodes /* frees the request structure */ 70126878Strhodes void (*request_free)(void *); 71126878Strhodes 72208649Sgordon /* unmarshals the buffer into the proper request structure */ 73208649Sgordon int (*request_unmarshal)(void *, struct evbuffer *); 74208649Sgordon 75208649Sgordon /* creates a new reply structure */ 76208649Sgordon void *(*reply_new)(void *); 77126878Strhodes void *reply_new_arg; 78126878Strhodes 79126878Strhodes /* frees the reply structure */ 80126878Strhodes void (*reply_free)(void *); 81126878Strhodes 82208649Sgordon /* verifies that the reply is valid */ 83208649Sgordon int (*reply_complete)(void *); 84126878Strhodes 85126878Strhodes /* marshals the reply into a buffer */ 86126878Strhodes void (*reply_marshal)(struct evbuffer*, void *); 87130420Sru 88126878Strhodes /* the callback invoked for each received rpc */ 89126878Strhodes void (*cb)(struct evrpc_req_generic *, void *); 90126878Strhodes void *cb_arg; 91126878Strhodes 92126878Strhodes /* reference for further configuration */ 93126878Strhodes struct evrpc_base *base; 94126878Strhodes}; 95126878Strhodes 96126878Strhodes#ifdef __cplusplus 97126878Strhodes} 98126878Strhodes#endif 99126878Strhodes 100126878Strhodes#endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ 101126878Strhodes