xref: /netbsd-src/external/bsd/libevent/dist/include/event2/rpc_struct.h (revision 657871a79c9a2060a6255a242fa1a1ef76b56ec6)
1 /*	$NetBSD: rpc_struct.h,v 1.1.1.4 2021/04/07 02:43:14 christos Exp $	*/
2 /*
3  * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
4  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
16  *
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.
27  */
28 #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_
29 #define EVENT2_RPC_STRUCT_H_INCLUDED_
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /** @file event2/rpc_struct.h
36 
37   Structures used by rpc.h.  Using these structures directly may harm
38   forward compatibility: be careful!
39 
40  */
41 
42 /* Fix so that people don't have to run with <sys/queue.h> */
43 #ifndef TAILQ_ENTRY
44 #define EVENT_DEFINED_TQENTRY_
45 #define TAILQ_ENTRY(type)						\
46 struct {								\
47 	struct type *tqe_next;	/* next element */			\
48 	struct type **tqe_prev;	/* address of previous next element */	\
49 }
50 #endif /* !TAILQ_ENTRY */
51 
52 /**
53  * provides information about the completed RPC request.
54  */
55 struct evrpc_status {
56 #define EVRPC_STATUS_ERR_NONE		0
57 #define EVRPC_STATUS_ERR_TIMEOUT	1
58 #define EVRPC_STATUS_ERR_BADPAYLOAD	2
59 #define EVRPC_STATUS_ERR_UNSTARTED	3
60 #define EVRPC_STATUS_ERR_HOOKABORTED	4
61 	int error;
62 
63 	/* for looking at headers or other information */
64 	struct evhttp_request *http_req;
65 };
66 
67 /* the structure below needs to be synchronized with evrpc_req_generic */
68 
69 /* Encapsulates a request */
70 struct evrpc {
71 	TAILQ_ENTRY(evrpc) next;
72 
73 	/* the URI at which the request handler lives */
74 	const char* uri;
75 
76 	/* creates a new request structure */
77 	void *(*request_new)(void *);
78 	void *request_new_arg;
79 
80 	/* frees the request structure */
81 	void (*request_free)(void *);
82 
83 	/* unmarshals the buffer into the proper request structure */
84 	int (*request_unmarshal)(void *, struct evbuffer *);
85 
86 	/* creates a new reply structure */
87 	void *(*reply_new)(void *);
88 	void *reply_new_arg;
89 
90 	/* frees the reply structure */
91 	void (*reply_free)(void *);
92 
93 	/* verifies that the reply is valid */
94 	int (*reply_complete)(void *);
95 
96 	/* marshals the reply into a buffer */
97 	void (*reply_marshal)(struct evbuffer*, void *);
98 
99 	/* the callback invoked for each received rpc */
100 	void (*cb)(struct evrpc_req_generic *, void *);
101 	void *cb_arg;
102 
103 	/* reference for further configuration */
104 	struct evrpc_base *base;
105 };
106 
107 #ifdef EVENT_DEFINED_TQENTRY_
108 #undef TAILQ_ENTRY
109 #endif
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */
116