r5108: the beginnings of a nbtd server for Samba4. Currently just displays
[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                 const char *reply_addr;
117         } out;
118 };
119
120 /* a simple name status query */
121 struct nbt_name_status {
122         struct {
123                 struct nbt_name name;
124                 const char *dest_addr;
125                 int timeout; /* in seconds */
126         } in;
127         struct {
128                 const char *reply_from;
129                 struct nbt_name name;
130                 struct nbt_rdata_status status;
131         } out;
132 };