r15387: Fix installation of dcerpc headers, remove more instances of uint_t
[nivanova/samba-autobuild/.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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifndef __LIBNBT_H__
24 #define __LIBNBT_H__
25
26 #include "librpc/gen_ndr/nbt.h"
27
28 /*
29   possible states for pending requests
30 */
31 enum nbt_request_state {NBT_REQUEST_SEND, 
32                         NBT_REQUEST_WAIT, 
33                         NBT_REQUEST_DONE,
34                         NBT_REQUEST_TIMEOUT,
35                         NBT_REQUEST_ERROR};
36
37 /*
38   a nbt name request
39 */
40 struct nbt_name_request {
41         struct nbt_name_request *next, *prev;
42
43         enum nbt_request_state state;
44
45         NTSTATUS status;
46
47         /* the socket this was on */
48         struct nbt_name_socket *nbtsock;
49
50         /* where to send the request */
51         struct socket_address *dest;
52
53         /* timeout between retries */
54         int timeout;
55
56         /* how many retries to send on timeout */
57         int num_retries;
58
59         /* whether we have received a WACK */
60         BOOL received_wack;
61
62         /* the timeout event */
63         struct timed_event *te;
64
65         /* the name transaction id */
66         uint16_t name_trn_id;
67
68         /* is it a reply? */
69         BOOL is_reply;
70         
71         /* the encoded request */
72         DATA_BLOB encoded;
73
74         /* shall we allow multiple replies? */
75         BOOL allow_multiple_replies;
76
77         unsigned int num_replies;
78         struct nbt_name_reply {
79                 struct nbt_name_packet *packet;
80                 struct socket_address *dest;
81         } *replies;
82
83         /* information on what to do on completion */
84         struct {
85                 void (*fn)(struct nbt_name_request *);
86                 void *private;
87         } async;
88 };
89
90
91
92 /*
93   context structure for operations on name queries
94 */
95 struct nbt_name_socket {
96         struct socket_context *sock;
97         struct event_context *event_ctx;
98
99         /* a queue of requests pending to be sent */
100         struct nbt_name_request *send_queue;
101
102         /* the fd event */
103         struct fd_event *fde;
104
105         /* mapping from name_trn_id to pending event */
106         struct idr_context *idr;
107
108         /* how many requests are waiting for a reply */
109         uint16_t num_pending;
110
111         /* what to do with incoming request packets */
112         struct {
113                 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, 
114                                 struct socket_address *);
115                 void *private;
116         } incoming;
117
118         /* what to do with unexpected replies */
119         struct {
120                 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, 
121                                 struct socket_address *);
122                 void *private;
123         } unexpected;
124 };
125
126
127 /* a simple name query */
128 struct nbt_name_query {
129         struct {
130                 struct nbt_name name;
131                 const char *dest_addr;
132                 BOOL broadcast;
133                 BOOL wins_lookup;
134                 int timeout; /* in seconds */
135                 int retries;
136         } in;
137         struct {
138                 const char *reply_from;
139                 struct nbt_name name;
140                 int16_t num_addrs;
141                 const char **reply_addrs;
142         } out;
143 };
144
145 /* a simple name status query */
146 struct nbt_name_status {
147         struct {
148                 struct nbt_name name;
149                 const char *dest_addr;
150                 int timeout; /* in seconds */
151                 int retries;
152         } in;
153         struct {
154                 const char *reply_from;
155                 struct nbt_name name;
156                 struct nbt_rdata_status status;
157         } out;
158 };
159
160 /* a name registration request */
161 struct nbt_name_register {
162         struct {
163                 struct nbt_name name;
164                 const char *dest_addr;
165                 const char *address;
166                 uint16_t nb_flags;
167                 BOOL register_demand;
168                 BOOL broadcast;
169                 BOOL multi_homed;
170                 uint32_t ttl;
171                 int timeout; /* in seconds */
172                 int retries;
173         } in;
174         struct {
175                 const char *reply_from;
176                 struct nbt_name name;
177                 const char *reply_addr;
178                 uint8_t rcode;
179         } out;
180 };
181
182 /* a send 3 times then demand name broadcast name registration */
183 struct nbt_name_register_bcast {
184         struct {
185                 struct nbt_name name;
186                 const char *dest_addr;
187                 const char *address;
188                 uint16_t nb_flags;
189                 uint32_t ttl;
190         } in;
191 };
192
193
194 /* wins name register with multiple wins servers to try and multiple
195    addresses to register */
196 struct nbt_name_register_wins {
197         struct {
198                 struct nbt_name name;
199                 const char **wins_servers;
200                 const char **addresses;
201                 uint16_t nb_flags;
202                 uint32_t ttl;
203         } in;
204         struct {
205                 const char *wins_server;
206                 uint8_t rcode;
207         } out;
208 };
209
210
211
212 /* a name refresh request */
213 struct nbt_name_refresh {
214         struct {
215                 struct nbt_name name;
216                 const char *dest_addr;
217                 const char *address;
218                 uint16_t nb_flags;
219                 BOOL broadcast;
220                 uint32_t ttl;
221                 int timeout; /* in seconds */
222                 int retries;
223         } in;
224         struct {
225                 const char *reply_from;
226                 struct nbt_name name;
227                 const char *reply_addr;
228                 uint8_t rcode;
229         } out;
230 };
231
232 /* wins name refresh with multiple wins servers to try and multiple
233    addresses to register */
234 struct nbt_name_refresh_wins {
235         struct {
236                 struct nbt_name name;
237                 const char **wins_servers;
238                 const char **addresses;
239                 uint16_t nb_flags;
240                 uint32_t ttl;
241         } in;
242         struct {
243                 const char *wins_server;
244                 uint8_t rcode;
245         } out;
246 };
247
248
249 /* a name release request */
250 struct nbt_name_release {
251         struct {
252                 struct nbt_name name;
253                 const char *dest_addr;
254                 const char *address;
255                 uint16_t nb_flags;
256                 BOOL broadcast;
257                 int timeout; /* in seconds */
258                 int retries;
259         } in;
260         struct {
261                 const char *reply_from;
262                 struct nbt_name name;
263                 const char *reply_addr;
264                 uint8_t rcode;
265         } out;
266 };
267
268 #include "libcli/nbt/nbt_proto.h"
269
270 #endif /* __LIBNBT_H__ */