r4891: - added a generic resolve_name() async interface in libcli/resolve/,
[garming/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 #include "librpc/gen_ndr/ndr_nbt.h"
24
25 /*
26   possible states for pending requests
27 */
28 enum nbt_request_state {NBT_REQUEST_SEND, 
29                         NBT_REQUEST_WAIT, 
30                         NBT_REQUEST_DONE,
31                         NBT_REQUEST_TIMEOUT,
32                         NBT_REQUEST_ERROR};
33
34 /*
35   a nbt name request
36 */
37 struct nbt_name_request {
38         struct nbt_name_request *next, *prev;
39
40         enum nbt_request_state state;
41
42         NTSTATUS status;
43
44         /* the socket this was on */
45         struct nbt_name_socket *nbtsock;
46
47         /* where to send the request */
48         const char *dest_addr;
49         int dest_port;
50
51         /* the timeout event */
52         struct timed_event *te;
53
54         struct nbt_name_packet *request;
55
56         /* shall we allow multiple replies? */
57         BOOL allow_multiple_replies;
58
59         uint_t num_replies;
60         struct nbt_name_reply {
61                 struct nbt_name_packet *packet;
62                 const char *reply_addr;
63                 int reply_port;
64         } *replies;
65
66         /* information on what to do on completion */
67         struct {
68                 void (*fn)(struct nbt_name_request *);
69                 void *private;
70         } async;
71 };
72
73
74
75 /*
76   context structure for operations on name queries
77 */
78 struct nbt_name_socket {
79         struct socket_context *sock;
80         struct event_context *event_ctx;
81
82         /* a queue of requests pending to be sent */
83         struct nbt_name_request *send_queue;
84
85         /* the fd event */
86         struct fd_event *fde;
87
88         /* mapping from name_trn_id to pending event */
89         struct idr_context *idr;
90
91         /* how many requests are waiting for a reply */
92         uint16_t num_pending;
93 };
94
95
96 /* a simple name query */
97 struct nbt_name_query {
98         struct {
99                 struct nbt_name name;
100                 const char *dest_addr;
101                 BOOL broadcast;
102                 BOOL wins_lookup;
103                 int timeout; /* in seconds */
104         } in;
105         struct {
106                 const char *reply_from;
107                 struct nbt_name name;
108                 const char *reply_addr;
109         } out;
110 };
111
112 /* a simple name status query */
113 struct nbt_name_status {
114         struct {
115                 struct nbt_name name;
116                 const char *dest_addr;
117                 int timeout; /* in seconds */
118         } in;
119         struct {
120                 const char *reply_from;
121                 struct nbt_name name;
122                 struct nbt_rdata_status status;
123         } out;
124 };