1 /*
2  * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2011 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
15  *
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.
26  */
27 
28 /** @file event2/rpc_struct.h
29 
30   Structures used by rpc.h.  Using these structures directly may harm
31   forward compatibility: be careful!
32 
33  */
34 module deimos.event2.rpc_struct;
35 
36 import deimos.event2._tailq;
37 import deimos.event2._d_util;
38 
39 extern (C):
40 nothrow:
41 
42 struct evhttp_request;
43 /**
44  * provides information about the completed RPC request.
45  */
46 struct evrpc_status {
47 enum EVRPC_STATUS_ERR_NONE = 0;
48 enum EVRPC_STATUS_ERR_TIMEOUT = 1;
49 enum EVRPC_STATUS_ERR_BADPAYLOAD = 2;
50 enum EVRPC_STATUS_ERR_UNSTARTED = 3;
51 enum EVRPC_STATUS_ERR_HOOKABORTED = 4;
52 	int error;
53 
54 	/* for looking at headers or other information */
55 	evhttp_request* http_req;
56 };
57 
58 /* the structure below needs to be synchronized with evrpc_req_generic */
59 
60 static import deimos.event2._opaque_structs;
61 
62 alias evbuffer = deimos.event2._opaque_structs.evbuffer;
63 alias evrpc_req_generic = deimos.event2._opaque_structs.evrpc_req_generic;
64 alias evrpc_base = deimos.event2._opaque_structs.evrpc_base;
65 
66 /* Encapsulates a request */
67 struct evrpc {
68 	TAILQ_ENTRY!evrpc next;
69 
70 	/* the URI at which the request handler lives */
71 	const(char)* uri;
72 
73 	/* creates a new request structure */
74 	ExternC!(void* function(void*)) request_new;
75 	void* request_new_arg;
76 
77 	/* frees the request structure */
78 	ExternC!(void function(void*)) request_free;
79 
80 	/* unmarshals the buffer into the proper request structure */
81 	ExternC!(int function(void*, evbuffer*)) request_unmarshal;
82 
83 	/* creates a new reply structure */
84 	ExternC!(void* function(void*)) reply_new;
85 	void* reply_new_arg;
86 
87 	/* frees the reply structure */
88 	ExternC!(void function(void*)) reply_free;
89 
90 	/* verifies that the reply is valid */
91 	ExternC!(int function(void*)) reply_complete;
92 
93 	/* marshals the reply into a buffer */
94 	ExternC!(void function(evbuffer*, void*)) reply_marshal;
95 
96 	/* the callback invoked for each received rpc */
97 	ExternC!(void function(evrpc_req_generic*, void*)) cb;
98 	void* cb_arg;
99 
100 	/* reference for further configuration */
101 	evrpc_base* base;
102 };