1 /*        $NetBSD: rpc_struct.h,v 1.6 2024/08/18 20:47:22 christos Exp $        */
2 
3 /*
4  * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
5  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_
30 #define EVENT2_RPC_STRUCT_H_INCLUDED_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /** @file event2/rpc_struct.h
37 
38   Structures used by rpc.h.  Using these structures directly may harm
39   forward compatibility: be careful!
40 
41  */
42 
43 /* Fix so that people don't have to run with <sys/queue.h> */
44 #ifndef TAILQ_ENTRY
45 #define EVENT_DEFINED_TQENTRY_
46 #define TAILQ_ENTRY(type)                                                       \
47 struct {                                                                        \
48           struct type *tqe_next;        /* next element */                      \
49           struct type **tqe_prev;       /* address of previous next element */  \
50 }
51 #endif /* !TAILQ_ENTRY */
52 
53 /**
54  * provides information about the completed RPC request.
55  */
56 struct evrpc_status {
57 #define EVRPC_STATUS_ERR_NONE           0
58 #define EVRPC_STATUS_ERR_TIMEOUT        1
59 #define EVRPC_STATUS_ERR_BADPAYLOAD     2
60 #define EVRPC_STATUS_ERR_UNSTARTED      3
61 #define EVRPC_STATUS_ERR_HOOKABORTED    4
62           int error;
63 
64           /* for looking at headers or other information */
65           struct evhttp_request *http_req;
66 };
67 
68 /* the structure below needs to be synchronized with evrpc_req_generic */
69 
70 /* Encapsulates a request */
71 struct evrpc {
72           TAILQ_ENTRY(evrpc) next;
73 
74           /* the URI at which the request handler lives */
75           const char* uri;
76 
77           /* creates a new request structure */
78           void *(*request_new)(void *);
79           void *request_new_arg;
80 
81           /* frees the request structure */
82           void (*request_free)(void *);
83 
84           /* unmarshals the buffer into the proper request structure */
85           int (*request_unmarshal)(void *, struct evbuffer *);
86 
87           /* creates a new reply structure */
88           void *(*reply_new)(void *);
89           void *reply_new_arg;
90 
91           /* frees the reply structure */
92           void (*reply_free)(void *);
93 
94           /* verifies that the reply is valid */
95           int (*reply_complete)(void *);
96 
97           /* marshals the reply into a buffer */
98           void (*reply_marshal)(struct evbuffer*, void *);
99 
100           /* the callback invoked for each received rpc */
101           void (*cb)(struct evrpc_req_generic *, void *);
102           void *cb_arg;
103 
104           /* reference for further configuration */
105           struct evrpc_base *base;
106 };
107 
108 #ifdef EVENT_DEFINED_TQENTRY_
109 #undef TAILQ_ENTRY
110 #endif
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */
117