1 /* $NetBSD: evrpc-internal.h,v 1.1.1.2 2013/04/11 16:43:20 christos Exp $ */
3 * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
4 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
28 #ifndef _EVRPC_INTERNAL_H_
29 #define _EVRPC_INTERNAL_H_
31 #include "http-internal.h"
34 struct evrpc_request_wrapper
;
36 #define EVRPC_URI_PREFIX "/.rpc."
39 TAILQ_ENTRY(evrpc_hook
) next
;
41 /* returns EVRPC_TERMINATE; if the rpc should be aborted.
42 * a hook is is allowed to rewrite the evbuffer
44 int (*process
)(void *, struct evhttp_request
*,
45 struct evbuffer
*, void *);
49 TAILQ_HEAD(evrpc_hook_list
, evrpc_hook
);
52 * this is shared between the base and the pool, so that we can reuse
53 * the hook adding functions; we alias both evrpc_pool and evrpc_base
54 * to this common structure.
57 struct evrpc_hook_ctx
;
58 TAILQ_HEAD(evrpc_pause_list
, evrpc_hook_ctx
);
61 /* hooks for processing outbound and inbound rpcs */
62 struct evrpc_hook_list in_hooks
;
63 struct evrpc_hook_list out_hooks
;
65 struct evrpc_pause_list pause_requests
;
68 #define input_hooks common.in_hooks
69 #define output_hooks common.out_hooks
70 #define paused_requests common.pause_requests
73 struct _evrpc_hooks common
;
75 /* the HTTP server under which we register our RPC calls */
76 struct evhttp
* http_server
;
78 /* a list of all RPCs registered with us */
79 TAILQ_HEAD(evrpc_list
, evrpc
) registered_rpcs
;
82 struct evrpc_req_generic
;
83 void evrpc_reqstate_free(struct evrpc_req_generic
* rpc_state
);
85 /* A pool for holding evhttp_connection objects */
87 struct _evrpc_hooks common
;
89 struct event_base
*base
;
91 struct evconq connections
;
95 TAILQ_HEAD(evrpc_requestq
, evrpc_request_wrapper
) (requests
);
98 struct evrpc_hook_ctx
{
99 TAILQ_ENTRY(evrpc_hook_ctx
) next
;
102 void (*cb
)(void *, enum EVRPC_HOOK_RESULT
);
106 TAILQ_ENTRY(evrpc_meta
) next
;
113 TAILQ_HEAD(evrpc_meta_list
, evrpc_meta
);
115 struct evrpc_hook_meta
{
116 struct evrpc_meta_list meta_data
;
117 struct evhttp_connection
*evcon
;
120 /* allows association of meta data with a request */
121 static void evrpc_hook_associate_meta(struct evrpc_hook_meta
**pctx
,
122 struct evhttp_connection
*evcon
);
124 /* creates a new meta data store */
125 static struct evrpc_hook_meta
*evrpc_hook_meta_new(void);
127 /* frees the meta data associated with a request */
128 static void evrpc_hook_context_free(struct evrpc_hook_meta
*ctx
);
130 /* the server side of an rpc */
132 /* We alias the RPC specific structs to this voided one */
133 struct evrpc_req_generic
{
135 * allows association of meta data via hooks - needs to be
136 * synchronized with evrpc_request_wrapper
138 struct evrpc_hook_meta
*hook_meta
;
140 /* the unmarshaled request object */
143 /* the empty reply object that needs to be filled in */
147 * the static structure for this rpc; that can be used to
148 * automatically unmarshal and marshal the http buffers.
153 * the http request structure on which we need to answer.
155 struct evhttp_request
* http_req
;
158 * Temporary data store for marshaled data
160 struct evbuffer
* rpc_data
;
163 /* the client side of an rpc request */
164 struct evrpc_request_wrapper
{
166 * allows association of meta data via hooks - needs to be
167 * synchronized with evrpc_req_generic.
169 struct evrpc_hook_meta
*hook_meta
;
171 TAILQ_ENTRY(evrpc_request_wrapper
) next
;
173 /* pool on which this rpc request is being made */
174 struct evrpc_pool
*pool
;
176 /* connection on which the request is being sent */
177 struct evhttp_connection
*evcon
;
179 /* the actual request */
180 struct evhttp_request
*req
;
182 /* event for implementing request timeouts */
183 struct event ev_timeout
;
185 /* the name of the rpc */
189 void (*cb
)(struct evrpc_status
*, void *request
, void *reply
, void *arg
);
195 /* unmarshals the buffer into the proper request structure */
196 void (*request_marshal
)(struct evbuffer
*, void *);
198 /* removes all stored state in the reply */
199 void (*reply_clear
)(void *);
201 /* marshals the reply into a buffer */
202 int (*reply_unmarshal
)(void *, struct evbuffer
*);
205 #endif /* _EVRPC_INTERNAL_H_ */