r23792: convert Samba4 to GPLv3
[bbaumbach/samba-autobuild/.git] / source4 / libcli / dgram / libdgram.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    a raw async NBT DGRAM 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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "librpc/gen_ndr/nbt.h"
23
24 /*
25   a datagram name request
26 */
27 struct nbt_dgram_request {
28         struct nbt_dgram_request *next, *prev;
29
30         /* where to send the request */
31         struct socket_address *dest;
32
33         /* the encoded request */
34         DATA_BLOB encoded;
35 };
36
37 /*
38   context structure for operations on dgram packets
39 */
40 struct nbt_dgram_socket {
41         struct socket_context *sock;
42         struct event_context *event_ctx;
43
44         /* the fd event */
45         struct fd_event *fde;
46
47         /* a queue of outgoing requests */
48         struct nbt_dgram_request *send_queue;
49
50         /* a list of mailslot handlers */
51         struct dgram_mailslot_handler *mailslot_handlers;
52
53         /* what to do with incoming request packets */
54         struct {
55                 void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *, 
56                                 struct socket_address *src);
57                 void *private;
58         } incoming;
59 };
60
61
62 /*
63   the mailslot code keeps a list of mailslot handlers. A mailslot
64   handler is a function that receives incoming packets for a specific
65   mailslot name. When a caller needs to send a mailslot and wants to
66   get a reply then it needs to register itself as listening for
67   incoming packets on the reply mailslot
68 */
69
70 typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *, 
71                                          struct nbt_dgram_packet *, 
72                                          struct socket_address *src);
73
74 struct dgram_mailslot_handler {
75         struct dgram_mailslot_handler *next, *prev;
76
77         struct nbt_dgram_socket *dgmsock;
78         const char *mailslot_name;
79
80         dgram_mailslot_handler_t handler;
81         void *private;
82 };
83
84
85 /* prototypes */
86 NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
87                         struct nbt_dgram_packet *packet,
88                         struct socket_address *dest);
89 NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
90                                     void (*handler)(struct nbt_dgram_socket *, 
91                                                     struct nbt_dgram_packet *, 
92                                                     struct socket_address *),
93                                     void *private);
94 struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx, 
95                                                struct event_context *event_ctx);
96
97 const char *dgram_mailslot_name(struct nbt_dgram_packet *packet);
98 struct dgram_mailslot_handler *dgram_mailslot_find(struct nbt_dgram_socket *dgmsock,
99                                                    const char *mailslot_name);
100 struct dgram_mailslot_handler *dgram_mailslot_listen(struct nbt_dgram_socket *dgmsock,
101                                                      const char *mailslot_name,
102                                                      dgram_mailslot_handler_t handler,
103                                                      void *private);
104 struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgmsock,
105                                                    const char *mailslot_name,
106                                                    dgram_mailslot_handler_t handler,
107                                                    void *private);
108 DATA_BLOB dgram_mailslot_data(struct nbt_dgram_packet *dgram);
109
110
111 NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
112                              enum dgram_msg_type msg_type,
113                              const char *mailslot_name,
114                              struct nbt_name *dest_name,
115                              struct socket_address *dest,
116                              struct nbt_name *src_name,
117                              DATA_BLOB *request);
118
119 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
120                                       struct nbt_name *dest_name,
121                                       struct socket_address *dest,
122                                       struct nbt_name *src_name,
123                                       struct nbt_netlogon_packet *request);
124 NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
125                                        struct nbt_dgram_packet *request,
126                                        const char *mailslot_name,
127                                        struct nbt_netlogon_packet *reply);
128 NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
129                                        TALLOC_CTX *mem_ctx,
130                                        struct nbt_dgram_packet *dgram,
131                                        struct nbt_netlogon_packet *netlogon);
132
133 NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
134                                      enum dgram_msg_type msg_type,
135                                      struct nbt_name *dest_name,
136                                      struct socket_address *dest,
137                                      struct nbt_name *src_name,
138                                      struct nbt_ntlogon_packet *request);
139 NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
140                                        struct nbt_dgram_packet *request,
141                                        const char *mailslot_name,
142                                        struct nbt_ntlogon_packet *reply);
143 NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
144                                        TALLOC_CTX *mem_ctx,
145                                        struct nbt_dgram_packet *dgram,
146                                        struct nbt_ntlogon_packet *ntlogon);
147
148 NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
149                                     struct nbt_name *dest_name,
150                                     struct socket_address *dest,
151                                     struct nbt_name *src_name,
152                                     struct nbt_browse_packet *request);
153
154 NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
155                                      struct nbt_dgram_packet *request,
156                                      const char *mailslot_name,
157                                      struct nbt_browse_packet *reply);
158
159 NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
160                                      TALLOC_CTX *mem_ctx,
161                                      struct nbt_dgram_packet *dgram,
162                                      struct nbt_browse_packet *pkt);