1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/evrpc-internal.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,204 @@ 1.4 +/* 1.5 + * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 1.6 + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 3. The name of the author may not be used to endorse or promote products 1.17 + * derived from this software without specific prior written permission. 1.18 + * 1.19 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1.20 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1.21 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.22 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1.23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1.24 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.25 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.26 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.27 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1.28 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.29 + */ 1.30 +#ifndef _EVRPC_INTERNAL_H_ 1.31 +#define _EVRPC_INTERNAL_H_ 1.32 + 1.33 +#include "http-internal.h" 1.34 + 1.35 +struct evrpc; 1.36 +struct evrpc_request_wrapper; 1.37 + 1.38 +#define EVRPC_URI_PREFIX "/.rpc." 1.39 + 1.40 +struct evrpc_hook { 1.41 + TAILQ_ENTRY(evrpc_hook) next; 1.42 + 1.43 + /* returns EVRPC_TERMINATE; if the rpc should be aborted. 1.44 + * a hook is is allowed to rewrite the evbuffer 1.45 + */ 1.46 + int (*process)(void *, struct evhttp_request *, 1.47 + struct evbuffer *, void *); 1.48 + void *process_arg; 1.49 +}; 1.50 + 1.51 +TAILQ_HEAD(evrpc_hook_list, evrpc_hook); 1.52 + 1.53 +/* 1.54 + * this is shared between the base and the pool, so that we can reuse 1.55 + * the hook adding functions; we alias both evrpc_pool and evrpc_base 1.56 + * to this common structure. 1.57 + */ 1.58 + 1.59 +struct evrpc_hook_ctx; 1.60 +TAILQ_HEAD(evrpc_pause_list, evrpc_hook_ctx); 1.61 + 1.62 +struct _evrpc_hooks { 1.63 + /* hooks for processing outbound and inbound rpcs */ 1.64 + struct evrpc_hook_list in_hooks; 1.65 + struct evrpc_hook_list out_hooks; 1.66 + 1.67 + struct evrpc_pause_list pause_requests; 1.68 +}; 1.69 + 1.70 +#define input_hooks common.in_hooks 1.71 +#define output_hooks common.out_hooks 1.72 +#define paused_requests common.pause_requests 1.73 + 1.74 +struct evrpc_base { 1.75 + struct _evrpc_hooks common; 1.76 + 1.77 + /* the HTTP server under which we register our RPC calls */ 1.78 + struct evhttp* http_server; 1.79 + 1.80 + /* a list of all RPCs registered with us */ 1.81 + TAILQ_HEAD(evrpc_list, evrpc) registered_rpcs; 1.82 +}; 1.83 + 1.84 +struct evrpc_req_generic; 1.85 +void evrpc_reqstate_free(struct evrpc_req_generic* rpc_state); 1.86 + 1.87 +/* A pool for holding evhttp_connection objects */ 1.88 +struct evrpc_pool { 1.89 + struct _evrpc_hooks common; 1.90 + 1.91 + struct event_base *base; 1.92 + 1.93 + struct evconq connections; 1.94 + 1.95 + int timeout; 1.96 + 1.97 + TAILQ_HEAD(evrpc_requestq, evrpc_request_wrapper) (requests); 1.98 +}; 1.99 + 1.100 +struct evrpc_hook_ctx { 1.101 + TAILQ_ENTRY(evrpc_hook_ctx) next; 1.102 + 1.103 + void *ctx; 1.104 + void (*cb)(void *, enum EVRPC_HOOK_RESULT); 1.105 +}; 1.106 + 1.107 +struct evrpc_meta { 1.108 + TAILQ_ENTRY(evrpc_meta) next; 1.109 + char *key; 1.110 + 1.111 + void *data; 1.112 + size_t data_size; 1.113 +}; 1.114 + 1.115 +TAILQ_HEAD(evrpc_meta_list, evrpc_meta); 1.116 + 1.117 +struct evrpc_hook_meta { 1.118 + struct evrpc_meta_list meta_data; 1.119 + struct evhttp_connection *evcon; 1.120 +}; 1.121 + 1.122 +/* allows association of meta data with a request */ 1.123 +static void evrpc_hook_associate_meta(struct evrpc_hook_meta **pctx, 1.124 + struct evhttp_connection *evcon); 1.125 + 1.126 +/* creates a new meta data store */ 1.127 +static struct evrpc_hook_meta *evrpc_hook_meta_new(void); 1.128 + 1.129 +/* frees the meta data associated with a request */ 1.130 +static void evrpc_hook_context_free(struct evrpc_hook_meta *ctx); 1.131 + 1.132 +/* the server side of an rpc */ 1.133 + 1.134 +/* We alias the RPC specific structs to this voided one */ 1.135 +struct evrpc_req_generic { 1.136 + /* 1.137 + * allows association of meta data via hooks - needs to be 1.138 + * synchronized with evrpc_request_wrapper 1.139 + */ 1.140 + struct evrpc_hook_meta *hook_meta; 1.141 + 1.142 + /* the unmarshaled request object */ 1.143 + void *request; 1.144 + 1.145 + /* the empty reply object that needs to be filled in */ 1.146 + void *reply; 1.147 + 1.148 + /* 1.149 + * the static structure for this rpc; that can be used to 1.150 + * automatically unmarshal and marshal the http buffers. 1.151 + */ 1.152 + struct evrpc *rpc; 1.153 + 1.154 + /* 1.155 + * the http request structure on which we need to answer. 1.156 + */ 1.157 + struct evhttp_request* http_req; 1.158 + 1.159 + /* 1.160 + * Temporary data store for marshaled data 1.161 + */ 1.162 + struct evbuffer* rpc_data; 1.163 +}; 1.164 + 1.165 +/* the client side of an rpc request */ 1.166 +struct evrpc_request_wrapper { 1.167 + /* 1.168 + * allows association of meta data via hooks - needs to be 1.169 + * synchronized with evrpc_req_generic. 1.170 + */ 1.171 + struct evrpc_hook_meta *hook_meta; 1.172 + 1.173 + TAILQ_ENTRY(evrpc_request_wrapper) next; 1.174 + 1.175 + /* pool on which this rpc request is being made */ 1.176 + struct evrpc_pool *pool; 1.177 + 1.178 + /* connection on which the request is being sent */ 1.179 + struct evhttp_connection *evcon; 1.180 + 1.181 + /* the actual request */ 1.182 + struct evhttp_request *req; 1.183 + 1.184 + /* event for implementing request timeouts */ 1.185 + struct event ev_timeout; 1.186 + 1.187 + /* the name of the rpc */ 1.188 + char *name; 1.189 + 1.190 + /* callback */ 1.191 + void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg); 1.192 + void *cb_arg; 1.193 + 1.194 + void *request; 1.195 + void *reply; 1.196 + 1.197 + /* unmarshals the buffer into the proper request structure */ 1.198 + void (*request_marshal)(struct evbuffer *, void *); 1.199 + 1.200 + /* removes all stored state in the reply */ 1.201 + void (*reply_clear)(void *); 1.202 + 1.203 + /* marshals the reply into a buffer */ 1.204 + int (*reply_unmarshal)(void *, struct evbuffer*); 1.205 +}; 1.206 + 1.207 +#endif /* _EVRPC_INTERNAL_H_ */