r5117: used a composite function to add 4 stage name registration. We send 3
[sfrench/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         /* what to do with incoming request packets */
95         struct {
96                 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, 
97                                 const char *, int );
98                 void *private;
99         } incoming;
100            
101 };
102
103
104 /* a simple name query */
105 struct nbt_name_query {
106         struct {
107                 struct nbt_name name;
108                 const char *dest_addr;
109                 BOOL broadcast;
110                 BOOL wins_lookup;
111                 int timeout; /* in seconds */
112         } in;
113         struct {
114                 const char *reply_from;
115                 struct nbt_name name;
116                 int16_t num_addrs;
117                 const char **reply_addrs;
118         } out;
119 };
120
121 /* a simple name status query */
122 struct nbt_name_status {
123         struct {
124                 struct nbt_name name;
125                 const char *dest_addr;
126                 int timeout; /* in seconds */
127         } in;
128         struct {
129                 const char *reply_from;
130                 struct nbt_name name;
131                 struct nbt_rdata_status status;
132         } out;
133 };
134
135 /* a name registration request */
136 struct nbt_name_register {
137         struct {
138                 struct nbt_name name;
139                 const char *dest_addr;
140                 const char *address;
141                 uint16_t nb_flags;
142                 BOOL register_demand;
143                 BOOL broadcast;
144                 uint32_t ttl;
145                 int timeout; /* in seconds */
146         } in;
147         struct {
148                 const char *reply_from;
149                 struct nbt_name name;
150                 const char *reply_addr;
151                 uint8_t rcode;
152         } out;
153 };
154
155 /* a send 3 times then demand name broadcast name registration */
156 struct nbt_name_register_bcast {
157         struct {
158                 struct nbt_name name;
159                 const char *dest_addr;
160                 const char *address;
161                 uint16_t nb_flags;
162                 uint32_t ttl;
163         } in;
164 };