2 * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef _EVRPC_INTERNAL_H_
28 #define _EVRPC_INTERNAL_H_
30 #include "http-internal.h"
33 struct evrpc_request_wrapper
;
35 #define EVRPC_URI_PREFIX "/.rpc."
38 TAILQ_ENTRY(evrpc_hook
) next
;
40 /* returns EVRPC_TERMINATE; if the rpc should be aborted.
41 * a hook is is allowed to rewrite the evbuffer
43 int (*process
)(void *, struct evhttp_request
*,
44 struct evbuffer
*, void *);
48 TAILQ_HEAD(evrpc_hook_list
, evrpc_hook
);
51 * this is shared between the base and the pool, so that we can reuse
52 * the hook adding functions; we alias both evrpc_pool and evrpc_base
53 * to this common structure.
56 struct evrpc_hook_ctx
;
57 TAILQ_HEAD(evrpc_pause_list
, evrpc_hook_ctx
);
60 /* hooks for processing outbound and inbound rpcs */
61 struct evrpc_hook_list in_hooks
;
62 struct evrpc_hook_list out_hooks
;
64 struct evrpc_pause_list pause_requests
;
67 #define input_hooks common.in_hooks
68 #define output_hooks common.out_hooks
69 #define paused_requests common.pause_requests
72 struct _evrpc_hooks common
;
74 /* the HTTP server under which we register our RPC calls */
75 struct evhttp
* http_server
;
77 /* a list of all RPCs registered with us */
78 TAILQ_HEAD(evrpc_list
, evrpc
) registered_rpcs
;
81 struct evrpc_req_generic
;
82 void evrpc_reqstate_free(struct evrpc_req_generic
* rpc_state
);
84 /* A pool for holding evhttp_connection objects */
86 struct _evrpc_hooks common
;
88 struct event_base
*base
;
90 struct evconq connections
;
94 TAILQ_HEAD(evrpc_requestq
, evrpc_request_wrapper
) (requests
);
97 struct evrpc_hook_ctx
{
98 TAILQ_ENTRY(evrpc_hook_ctx
) next
;
101 void (*cb
)(void *, enum EVRPC_HOOK_RESULT
);
105 TAILQ_ENTRY(evrpc_meta
) next
;
112 TAILQ_HEAD(evrpc_meta_list
, evrpc_meta
);
114 struct evrpc_hook_meta
{
115 struct evrpc_meta_list meta_data
;
116 struct evhttp_connection
*evcon
;
119 /* allows association of meta data with a request */
120 static void evrpc_hook_associate_meta(struct evrpc_hook_meta
**pctx
,
121 struct evhttp_connection
*evcon
);
123 /* creates a new meta data store */
124 static struct evrpc_hook_meta
*evrpc_hook_meta_new(void);
126 /* frees the meta data associated with a request */
127 static void evrpc_hook_context_free(struct evrpc_hook_meta
*ctx
);
129 /* the server side of an rpc */
131 /* We alias the RPC specific structs to this voided one */
132 struct evrpc_req_generic
{
134 * allows association of meta data via hooks - needs to be
135 * synchronized with evrpc_request_wrapper
137 struct evrpc_hook_meta
*hook_meta
;
139 /* the unmarshaled request object */
142 /* the empty reply object that needs to be filled in */
146 * the static structure for this rpc; that can be used to
147 * automatically unmarshal and marshal the http buffers.
152 * the http request structure on which we need to answer.
154 struct evhttp_request
* http_req
;
157 * Temporary data store for marshaled data
159 struct evbuffer
* rpc_data
;
162 /* the client side of an rpc request */
163 struct evrpc_request_wrapper
{
165 * allows association of meta data via hooks - needs to be
166 * synchronized with evrpc_req_generic.
168 struct evrpc_hook_meta
*hook_meta
;
170 TAILQ_ENTRY(evrpc_request_wrapper
) next
;
172 /* pool on which this rpc request is being made */
173 struct evrpc_pool
*pool
;
175 /* connection on which the request is being sent */
176 struct evhttp_connection
*evcon
;
178 /* the actual request */
179 struct evhttp_request
*req
;
181 /* event for implementing request timeouts */
182 struct event ev_timeout
;
184 /* the name of the rpc */
188 void (*cb
)(struct evrpc_status
*, void *request
, void *reply
, void *arg
);
194 /* unmarshals the buffer into the proper request structure */
195 void (*request_marshal
)(struct evbuffer
*, void *);
197 /* removes all stored state in the reply */
198 void (*reply_clear
)(void *);
200 /* marshals the reply into a buffer */
201 int (*reply_unmarshal
)(void *, struct evbuffer
*);
204 #endif /* _EVRPC_INTERNAL_H_ */