e78f0464e78a2b8f943f3387782f6c50e7a8c110
[samba.git] / source4 / libcli / wrepl / winsrepl.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    structures for WINS replication client 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 #include "librpc/gen_ndr/ndr_winsrepl.h"
25
26 /*
27   main context structure for the wins replication client library
28 */
29 struct wrepl_socket {
30         struct socket_context *sock;
31         struct event_context *event_ctx;
32
33         /* a queue of requests pending to be sent */
34         struct wrepl_request *send_queue;
35
36         /* a queue of replies waiting to be received */
37         struct wrepl_request *recv_queue;
38
39         /* the fd event */
40         struct fd_event *fde;
41
42         /* the default timeout for requests, 0 means no timeout */
43 #define WREPL_SOCKET_REQUEST_TIMEOUT    (60)
44         uint32_t request_timeout;
45
46         /* counter for request timeouts, after 2 timeouts the socket is marked as dead */
47         uint32_t timeout_count;
48
49         /* remember is the socket is dead */
50         BOOL dead;
51 };
52
53 enum wrepl_request_state {
54         WREPL_REQUEST_SEND  = 0,
55         WREPL_REQUEST_RECV  = 1,
56         WREPL_REQUEST_DONE  = 2,
57         WREPL_REQUEST_ERROR = 3
58 };
59
60 /*
61   a WINS replication request
62 */
63 struct wrepl_request {
64         struct wrepl_request *next, *prev;
65         struct wrepl_socket *wrepl_socket;
66
67         enum wrepl_request_state state;
68         NTSTATUS status;
69
70         DATA_BLOB buffer;
71
72         size_t num_read;
73
74         struct timed_event *te;
75
76         struct wrepl_packet *packet;
77
78         struct {
79                 void (*fn)(struct wrepl_request *);
80                 void *private;
81         } async;
82 };
83
84
85 /*
86   setup an association
87 */
88 struct wrepl_associate {
89         struct {
90                 uint32_t assoc_ctx;
91         } out;
92 };
93
94 /*
95   pull the partner table
96 */
97 struct wrepl_pull_table {
98         struct {
99                 uint32_t assoc_ctx;
100         } in;
101         struct {
102                 uint32_t num_partners;
103                 struct wrepl_wins_owner *partners;
104         } out;
105 };
106
107 #define WREPL_NAME_TYPE(flags) (flags & WREPL_FLAGS_RECORD_TYPE)
108 #define WREPL_NAME_STATE(flags) ((flags & WREPL_FLAGS_RECORD_STATE)>>2)
109 #define WREPL_NAME_NODE(flags) ((flags & WREPL_FLAGS_NODE_TYPE)>>5)
110 #define WREPL_NAME_IS_STATIC(flags) ((flags & WREPL_FLAGS_IS_STATIC)?True:False)
111
112 #define WREPL_NAME_FLAGS(type, state, node, is_static) \
113         (type | (state << 2) | (node << 5) | \
114          (is_static ? WREPL_FLAGS_IS_STATIC : 0))
115
116 /*
117   a full pull replication
118 */
119 struct wrepl_pull_names {
120         struct {
121                 uint32_t assoc_ctx;
122                 struct wrepl_wins_owner partner;
123         } in;
124         struct {
125                 uint32_t num_names;
126                 struct wrepl_name {
127                         struct nbt_name name;
128                         enum wrepl_name_type type;
129                         enum wrepl_name_state state;
130                         enum wrepl_name_node node;
131                         BOOL is_static;
132                         uint32_t raw_flags;
133                         uint64_t version_id;
134                         const char *owner;
135                         uint32_t num_addresses;
136                         struct wrepl_address {
137                                 const char *owner;
138                                 const char *address;
139                         } *addresses;
140                 } *names;
141         } out;
142 };