1275970Scy/*
2275970Scy * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4275970Scy *
5275970Scy * Redistribution and use in source and binary forms, with or without
6275970Scy * modification, are permitted provided that the following conditions
7275970Scy * are met:
8275970Scy * 1. Redistributions of source code must retain the above copyright
9275970Scy *    notice, this list of conditions and the following disclaimer.
10275970Scy * 2. Redistributions in binary form must reproduce the above copyright
11275970Scy *    notice, this list of conditions and the following disclaimer in the
12275970Scy *    documentation and/or other materials provided with the distribution.
13275970Scy * 3. The name of the author may not be used to endorse or promote products
14275970Scy *    derived from this software without specific prior written permission.
15275970Scy *
16275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26275970Scy */
27275970Scy#ifndef EVENT2_RPC_STRUCT_H_INCLUDED_
28275970Scy#define EVENT2_RPC_STRUCT_H_INCLUDED_
29275970Scy
30275970Scy#ifdef __cplusplus
31275970Scyextern "C" {
32275970Scy#endif
33275970Scy
34275970Scy/** @file event2/rpc_struct.h
35275970Scy
36275970Scy  Structures used by rpc.h.  Using these structures directly may harm
37275970Scy  forward compatibility: be careful!
38275970Scy
39275970Scy */
40275970Scy
41275970Scy/**
42275970Scy * provides information about the completed RPC request.
43275970Scy */
44275970Scystruct evrpc_status {
45275970Scy#define EVRPC_STATUS_ERR_NONE		0
46275970Scy#define EVRPC_STATUS_ERR_TIMEOUT	1
47275970Scy#define EVRPC_STATUS_ERR_BADPAYLOAD	2
48275970Scy#define EVRPC_STATUS_ERR_UNSTARTED	3
49275970Scy#define EVRPC_STATUS_ERR_HOOKABORTED	4
50275970Scy	int error;
51275970Scy
52275970Scy	/* for looking at headers or other information */
53275970Scy	struct evhttp_request *http_req;
54275970Scy};
55275970Scy
56275970Scy/* the structure below needs to be synchronized with evrpc_req_generic */
57275970Scy
58275970Scy/* Encapsulates a request */
59275970Scystruct evrpc {
60275970Scy	TAILQ_ENTRY(evrpc) next;
61275970Scy
62275970Scy	/* the URI at which the request handler lives */
63275970Scy	const char* uri;
64275970Scy
65275970Scy	/* creates a new request structure */
66275970Scy	void *(*request_new)(void *);
67275970Scy	void *request_new_arg;
68275970Scy
69275970Scy	/* frees the request structure */
70275970Scy	void (*request_free)(void *);
71275970Scy
72275970Scy	/* unmarshals the buffer into the proper request structure */
73275970Scy	int (*request_unmarshal)(void *, struct evbuffer *);
74275970Scy
75275970Scy	/* creates a new reply structure */
76275970Scy	void *(*reply_new)(void *);
77275970Scy	void *reply_new_arg;
78275970Scy
79275970Scy	/* frees the reply structure */
80275970Scy	void (*reply_free)(void *);
81275970Scy
82275970Scy	/* verifies that the reply is valid */
83275970Scy	int (*reply_complete)(void *);
84275970Scy
85275970Scy	/* marshals the reply into a buffer */
86275970Scy	void (*reply_marshal)(struct evbuffer*, void *);
87275970Scy
88275970Scy	/* the callback invoked for each received rpc */
89275970Scy	void (*cb)(struct evrpc_req_generic *, void *);
90275970Scy	void *cb_arg;
91275970Scy
92275970Scy	/* reference for further configuration */
93275970Scy	struct evrpc_base *base;
94275970Scy};
95275970Scy
96275970Scy#ifdef __cplusplus
97275970Scy}
98275970Scy#endif
99275970Scy
100275970Scy#endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */
101