BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file NCDRequestClient.h
3 * @author Ambroz Bizjak <ambrop7@gmail.com>
4 *
5 * @section LICENSE
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 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. Neither the name of the author nor the
15 * names of its contributors may 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29  
30 #ifndef BADVPN_NCDREQUESTCLIENT_H
31 #define BADVPN_NCDREQUESTCLIENT_H
32  
33 #include <stdint.h>
34  
35 #include <misc/debug.h>
36 #include <misc/debugerror.h>
37 #include <misc/debugcounter.h>
38 #include <structure/BAVL.h>
39 #include <base/DebugObject.h>
40 #include <system/BConnection.h>
41 #include <system/BConnectionGeneric.h>
42 #include <flow/PacketProtoDecoder.h>
43 #include <flow/PacketStreamSender.h>
44 #include <flow/PacketPassFifoQueue.h>
45 #include <ncd/NCDValGenerator.h>
46 #include <ncd/NCDValParser.h>
47  
48 struct NCDRequestClient_req;
49  
50 typedef void (*NCDRequestClient_handler_error) (void *user);
51 typedef void (*NCDRequestClient_handler_connected) (void *user);
52 typedef void (*NCDRequestClientRequest_handler_sent) (void *user);
53 typedef void (*NCDRequestClientRequest_handler_reply) (void *user, NCDValMem reply_mem, NCDValRef reply_value);
54 typedef void (*NCDRequestClientRequest_handler_finished) (void *user, int is_error);
55  
56 typedef struct {
57 BReactor *reactor;
58 NCDStringIndex *string_index;
59 void *user;
60 NCDRequestClient_handler_error handler_error;
61 NCDRequestClient_handler_connected handler_connected;
62 BConnector connector;
63 BConnection con;
64 PacketPassFifoQueue send_queue;
65 PacketStreamSender send_sender;
66 PacketProtoDecoder recv_decoder;
67 PacketPassInterface recv_if;
68 BAVL reqs_tree;
69 uint32_t next_request_id;
70 int state;
71 int is_error;
72 DebugCounter d_reqests_ctr;
73 DebugError d_err;
74 DebugObject d_obj;
75 } NCDRequestClient;
76  
77 typedef struct {
78 NCDRequestClient *client;
79 void *user;
80 NCDRequestClientRequest_handler_sent handler_sent;
81 NCDRequestClientRequest_handler_reply handler_reply;
82 NCDRequestClientRequest_handler_finished handler_finished;
83 struct NCDRequestClient_req *req;
84 DebugError d_err;
85 DebugObject d_obj;
86 } NCDRequestClientRequest;
87  
88 struct NCDRequestClient_req {
89 NCDRequestClientRequest *creq;
90 NCDRequestClient *client;
91 BAVLNode reqs_tree_node;
92 uint32_t request_id;
93 uint8_t *request_data;
94 int request_len;
95 PacketPassInterface *send_qflow_iface;
96 PacketPassFifoQueueFlow send_qflow;
97 int state;
98 };
99  
100 int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, NCDStringIndex *string_index,
101 void *user,
102 NCDRequestClient_handler_error handler_error,
103 NCDRequestClient_handler_connected handler_connected) WARN_UNUSED;
104 void NCDRequestClient_Free (NCDRequestClient *o);
105  
106 int NCDRequestClientRequest_Init (NCDRequestClientRequest *o, NCDRequestClient *client, NCDValRef payload_value, void *user,
107 NCDRequestClientRequest_handler_sent handler_sent,
108 NCDRequestClientRequest_handler_reply handler_reply,
109 NCDRequestClientRequest_handler_finished handler_finished) WARN_UNUSED;
110 void NCDRequestClientRequest_Free (NCDRequestClientRequest *o);
111 void NCDRequestClientRequest_Abort (NCDRequestClientRequest *o);
112  
113 #endif