r24712: No longer expose the 'BOOL' data type in any interfaces.
[metze/samba/wip.git] / source4 / libcli / nbt / libnbt.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    a raw async NBT library
5
6    Copyright (C) Andrew Tridgell 2005
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef __LIBNBT_H__
23 #define __LIBNBT_H__
24
25 #include "librpc/gen_ndr/nbt.h"
26
27 /*
28   possible states for pending requests
29 */
30 enum nbt_request_state {NBT_REQUEST_SEND, 
31                         NBT_REQUEST_WAIT, 
32                         NBT_REQUEST_DONE,
33                         NBT_REQUEST_TIMEOUT,
34                         NBT_REQUEST_ERROR};
35
36 /*
37   a nbt name request
38 */
39 struct nbt_name_request {
40         struct nbt_name_request *next, *prev;
41
42         enum nbt_request_state state;
43
44         NTSTATUS status;
45
46         /* the socket this was on */
47         struct nbt_name_socket *nbtsock;
48
49         /* where to send the request */
50         struct socket_address *dest;
51
52         /* timeout between retries */
53         int timeout;
54
55         /* how many retries to send on timeout */
56         int num_retries;
57
58         /* whether we have received a WACK */
59         bool received_wack;
60
61         /* the timeout event */
62         struct timed_event *te;
63
64         /* the name transaction id */
65         uint16_t name_trn_id;
66
67         /* is it a reply? */
68         bool is_reply;
69         
70         /* the encoded request */
71         DATA_BLOB encoded;
72
73         /* shall we allow multiple replies? */
74         bool allow_multiple_replies;
75
76         unsigned int num_replies;
77         struct nbt_name_reply {
78                 struct nbt_name_packet *packet;
79                 struct socket_address *dest;
80         } *replies;
81
82         /* information on what to do on completion */
83         struct {
84                 void (*fn)(struct nbt_name_request *);
85                 void *private;
86         } async;
87 };
88
89
90
91 /*
92   context structure for operations on name queries
93 */
94 struct nbt_name_socket {
95         struct socket_context *sock;
96         struct event_context *event_ctx;
97
98         /* a queue of requests pending to be sent */
99         struct nbt_name_request *send_queue;
100
101         /* the fd event */
102         struct fd_event *fde;
103
104         /* mapping from name_trn_id to pending event */
105         struct idr_context *idr;
106
107         /* how many requests are waiting for a reply */
108         uint16_t num_pending;
109
110         /* what to do with incoming request packets */
111         struct {
112                 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, 
113                                 struct socket_address *);
114                 void *private;
115         } incoming;
116
117         /* what to do with unexpected replies */
118         struct {
119                 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, 
120                                 struct socket_address *);
121                 void *private;
122         } unexpected;
123 };
124
125
126 /* a simple name query */
127 struct nbt_name_query {
128         struct {
129                 struct nbt_name name;
130                 const char *dest_addr;
131                 bool broadcast;
132                 bool wins_lookup;
133                 int timeout; /* in seconds */
134                 int retries;
135         } in;
136         struct {
137                 const char *reply_from;
138                 struct nbt_name name;
139                 int16_t num_addrs;
140                 const char **reply_addrs;
141         } out;
142 };
143
144 /* a simple name status query */
145 struct nbt_name_status {
146         struct {
147                 struct nbt_name name;
148                 const char *dest_addr;
149                 int timeout; /* in seconds */
150                 int retries;
151         } in;
152         struct {
153                 const char *reply_from;
154                 struct nbt_name name;
155                 struct nbt_rdata_status status;
156         } out;
157 };
158
159 /* a name registration request */
160 struct nbt_name_register {
161         struct {
162                 struct nbt_name name;
163                 const char *dest_addr;
164                 const char *address;
165                 uint16_t nb_flags;
166                 bool register_demand;
167                 bool broadcast;
168                 bool multi_homed;
169                 uint32_t ttl;
170                 int timeout; /* in seconds */
171                 int retries;
172         } in;
173         struct {
174                 const char *reply_from;
175                 struct nbt_name name;
176                 const char *reply_addr;
177                 uint8_t rcode;
178         } out;
179 };
180
181 /* a send 3 times then demand name broadcast name registration */
182 struct nbt_name_register_bcast {
183         struct {
184                 struct nbt_name name;
185                 const char *dest_addr;
186                 const char *address;
187                 uint16_t nb_flags;
188                 uint32_t ttl;
189         } in;
190 };
191
192
193 /* wins name register with multiple wins servers to try and multiple
194    addresses to register */
195 struct nbt_name_register_wins {
196         struct {
197                 struct nbt_name name;
198                 const char **wins_servers;
199                 const char **addresses;
200                 uint16_t nb_flags;
201                 uint32_t ttl;
202         } in;
203         struct {
204                 const char *wins_server;
205                 uint8_t rcode;
206         } out;
207 };
208
209
210
211 /* a name refresh request */
212 struct nbt_name_refresh {
213         struct {
214                 struct nbt_name name;
215                 const char *dest_addr;
216                 const char *address;
217                 uint16_t nb_flags;
218                 bool broadcast;
219                 uint32_t ttl;
220                 int timeout; /* in seconds */
221                 int retries;
222         } in;
223         struct {
224                 const char *reply_from;
225                 struct nbt_name name;
226                 const char *reply_addr;
227                 uint8_t rcode;
228         } out;
229 };
230
231 /* wins name refresh with multiple wins servers to try and multiple
232    addresses to register */
233 struct nbt_name_refresh_wins {
234         struct {
235                 struct nbt_name name;
236                 const char **wins_servers;
237                 const char **addresses;
238                 uint16_t nb_flags;
239                 uint32_t ttl;
240         } in;
241         struct {
242                 const char *wins_server;
243                 uint8_t rcode;
244         } out;
245 };
246
247
248 /* a name release request */
249 struct nbt_name_release {
250         struct {
251                 struct nbt_name name;
252                 const char *dest_addr;
253                 const char *address;
254                 uint16_t nb_flags;
255                 bool broadcast;
256                 int timeout; /* in seconds */
257                 int retries;
258         } in;
259         struct {
260                 const char *reply_from;
261                 struct nbt_name name;
262                 const char *reply_addr;
263                 uint8_t rcode;
264         } out;
265 };
266
267 #include "libcli/nbt/nbt_proto.h"
268
269 #endif /* __LIBNBT_H__ */