LDB ASYNC: other backends
[Samba.git] / libcli / nbt / libnbt.h
blob4ef4e9d60d15766dad3eaacba24b30d1ef523ccc
1 /*
2 Unix SMB/CIFS implementation.
4 a raw async NBT library
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
22 #ifndef __LIBNBT_H__
23 #define __LIBNBT_H__
25 #include "librpc/gen_ndr/nbt.h"
26 #include "librpc/ndr/libndr.h"
29 possible states for pending requests
31 enum nbt_request_state {NBT_REQUEST_SEND,
32 NBT_REQUEST_WAIT,
33 NBT_REQUEST_DONE,
34 NBT_REQUEST_TIMEOUT,
35 NBT_REQUEST_ERROR};
38 a nbt name request
40 struct nbt_name_request {
41 struct nbt_name_request *next, *prev;
43 enum nbt_request_state state;
45 NTSTATUS status;
47 /* the socket this was on */
48 struct nbt_name_socket *nbtsock;
50 /* where to send the request */
51 struct socket_address *dest;
53 /* timeout between retries */
54 int timeout;
56 /* how many retries to send on timeout */
57 int num_retries;
59 /* whether we have received a WACK */
60 bool received_wack;
62 /* the timeout event */
63 struct timed_event *te;
65 /* the name transaction id */
66 uint16_t name_trn_id;
68 /* is it a reply? */
69 bool is_reply;
71 /* the encoded request */
72 DATA_BLOB encoded;
74 /* shall we allow multiple replies? */
75 bool allow_multiple_replies;
77 unsigned int num_replies;
78 struct nbt_name_reply {
79 struct nbt_name_packet *packet;
80 struct socket_address *dest;
81 } *replies;
83 /* information on what to do on completion */
84 struct {
85 void (*fn)(struct nbt_name_request *);
86 void *private_data;
87 } async;
93 context structure for operations on name queries
95 struct nbt_name_socket {
96 struct socket_context *sock;
97 struct event_context *event_ctx;
98 struct smb_iconv_convenience *iconv_convenience;
100 /* a queue of requests pending to be sent */
101 struct nbt_name_request *send_queue;
103 /* the fd event */
104 struct fd_event *fde;
106 /* mapping from name_trn_id to pending event */
107 struct idr_context *idr;
109 /* how many requests are waiting for a reply */
110 uint16_t num_pending;
112 /* what to do with incoming request packets */
113 struct {
114 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
115 struct socket_address *);
116 void *private_data;
117 } incoming;
119 /* what to do with unexpected replies */
120 struct {
121 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
122 struct socket_address *);
123 void *private_data;
124 } unexpected;
128 /* a simple name query */
129 struct nbt_name_query {
130 struct {
131 struct nbt_name name;
132 const char *dest_addr;
133 uint16_t dest_port;
134 bool broadcast;
135 bool wins_lookup;
136 int timeout; /* in seconds */
137 int retries;
138 } in;
139 struct {
140 const char *reply_from;
141 struct nbt_name name;
142 int16_t num_addrs;
143 const char **reply_addrs;
144 } out;
147 /* a simple name status query */
148 struct nbt_name_status {
149 struct {
150 struct nbt_name name;
151 const char *dest_addr;
152 uint16_t dest_port;
153 int timeout; /* in seconds */
154 int retries;
155 } in;
156 struct {
157 const char *reply_from;
158 struct nbt_name name;
159 struct nbt_rdata_status status;
160 } out;
163 /* a name registration request */
164 struct nbt_name_register {
165 struct {
166 struct nbt_name name;
167 const char *dest_addr;
168 uint16_t dest_port;
169 const char *address;
170 uint16_t nb_flags;
171 bool register_demand;
172 bool broadcast;
173 bool multi_homed;
174 uint32_t ttl;
175 int timeout; /* in seconds */
176 int retries;
177 } in;
178 struct {
179 const char *reply_from;
180 struct nbt_name name;
181 const char *reply_addr;
182 uint8_t rcode;
183 } out;
186 /* a send 3 times then demand name broadcast name registration */
187 struct nbt_name_register_bcast {
188 struct {
189 struct nbt_name name;
190 const char *dest_addr;
191 uint16_t dest_port;
192 const char *address;
193 uint16_t nb_flags;
194 uint32_t ttl;
195 } in;
199 /* wins name register with multiple wins servers to try and multiple
200 addresses to register */
201 struct nbt_name_register_wins {
202 struct {
203 struct nbt_name name;
204 const char **wins_servers;
205 uint16_t wins_port;
206 const char **addresses;
207 uint16_t nb_flags;
208 uint32_t ttl;
209 } in;
210 struct {
211 const char *wins_server;
212 uint8_t rcode;
213 } out;
218 /* a name refresh request */
219 struct nbt_name_refresh {
220 struct {
221 struct nbt_name name;
222 const char *dest_addr;
223 uint16_t dest_port;
224 const char *address;
225 uint16_t nb_flags;
226 bool broadcast;
227 uint32_t ttl;
228 int timeout; /* in seconds */
229 int retries;
230 } in;
231 struct {
232 const char *reply_from;
233 struct nbt_name name;
234 const char *reply_addr;
235 uint8_t rcode;
236 } out;
239 /* wins name refresh with multiple wins servers to try and multiple
240 addresses to register */
241 struct nbt_name_refresh_wins {
242 struct {
243 struct nbt_name name;
244 const char **wins_servers;
245 uint16_t wins_port;
246 const char **addresses;
247 uint16_t nb_flags;
248 uint32_t ttl;
249 } in;
250 struct {
251 const char *wins_server;
252 uint8_t rcode;
253 } out;
257 /* a name release request */
258 struct nbt_name_release {
259 struct {
260 struct nbt_name name;
261 const char *dest_addr;
262 uint16_t dest_port;
263 const char *address;
264 uint16_t nb_flags;
265 bool broadcast;
266 int timeout; /* in seconds */
267 int retries;
268 } in;
269 struct {
270 const char *reply_from;
271 struct nbt_name name;
272 const char *reply_addr;
273 uint8_t rcode;
274 } out;
277 struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
278 struct event_context *event_ctx,
279 struct smb_iconv_convenience *iconv_convenience);
280 struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
281 struct nbt_name_query *io);
282 NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
283 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
284 NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
285 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
286 struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
287 struct nbt_name_status *io);
288 NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
289 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
290 NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock,
291 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
293 NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname);
294 NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, DATA_BLOB *blob, struct nbt_name *name);
295 NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name);
296 void nbt_choose_called_name(TALLOC_CTX *mem_ctx, struct nbt_name *n, const char *name, int type);
297 char *nbt_name_string(TALLOC_CTX *mem_ctx, const struct nbt_name *name);
298 NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock,
299 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
300 NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock,
301 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
302 NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock,
303 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
304 NTSTATUS nbt_name_register_wins(struct nbt_name_socket *nbtsock,
305 TALLOC_CTX *mem_ctx,
306 struct nbt_name_register_wins *io);
307 NTSTATUS nbt_name_refresh_wins(struct nbt_name_socket *nbtsock,
308 TALLOC_CTX *mem_ctx,
309 struct nbt_name_refresh_wins *io);
310 NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
311 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
312 struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
313 struct nbt_name_register *io);
314 NTSTATUS nbt_name_release_recv(struct nbt_name_request *req,
315 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
317 struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
318 struct nbt_name_release *io);
320 NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
321 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
323 NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
324 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
325 struct socket_address *),
326 void *private_data);
327 NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
328 struct socket_address *dest,
329 struct nbt_name_packet *request);
332 NDR_SCALAR_PROTO(wrepl_nbt_name, const struct nbt_name *);
333 NDR_SCALAR_PROTO(nbt_string, const char *);
334 NDR_BUFFER_PROTO(nbt_name, struct nbt_name);
335 NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode);
337 struct composite_context;
338 struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock,
339 struct nbt_name_register_bcast *io);
340 NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c);
341 struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nbtsock,
342 struct nbt_name_register_wins *io);
343 NTSTATUS nbt_name_refresh_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
344 struct nbt_name_refresh_wins *io);
345 struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbtsock,
346 struct nbt_name_refresh_wins *io);
347 NTSTATUS nbt_name_register_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
348 struct nbt_name_register_wins *io);
351 #endif /* __LIBNBT_H__ */