fa7189c22a45805f007224298400c45fce54d77e
[metze/samba/wip.git] / ctdb / protocol / protocol_util.h
1 /*
2    CTDB protocol marshalling
3
4    Copyright (C) Amitay Isaacs  2015
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __CTDB_PROTOCOL_UTIL_H__
21 #define __CTDB_PROTOCOL_UTIL_H__
22
23 #include <talloc.h>
24
25 #include "protocol/protocol.h"
26
27 const char *ctdb_runstate_to_string(enum ctdb_runstate runstate);
28 enum ctdb_runstate ctdb_runstate_from_string(const char *runstate_str);
29
30 const char *ctdb_event_to_string(enum ctdb_event event);
31 enum ctdb_event ctdb_event_from_string(const char *event_str);
32
33 /*
34  * buflen must be long enough to hold the longest possible "address:port".
35  * For example, 1122:3344:5566:7788:99aa:bbcc:ddee:ff00:12345.
36  * 64 is sane value for buflen.
37  */
38 int ctdb_sock_addr_to_buf(char *buf, socklen_t buflen,
39                           ctdb_sock_addr *addr, bool with_port);
40 const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx,
41                                      ctdb_sock_addr *addr, bool with_port);
42 int ctdb_sock_addr_from_string(const char *str,
43                                ctdb_sock_addr *addr, bool with_port);
44 int ctdb_sock_addr_mask_from_string(const char *str,
45                                     ctdb_sock_addr *addr,
46                                     unsigned int *mask);
47 unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr);
48 void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port);
49 int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
50                           const ctdb_sock_addr *addr2);
51 int ctdb_sock_addr_cmp(const ctdb_sock_addr *addr1,
52                        const ctdb_sock_addr *addr2);
53 bool ctdb_sock_addr_same_ip(const ctdb_sock_addr *addr1,
54                             const ctdb_sock_addr *addr2);
55 bool ctdb_sock_addr_same(const ctdb_sock_addr *addr1,
56                          const ctdb_sock_addr *addr2);
57
58 int ctdb_connection_to_buf(char *buf, size_t buflen,
59                            struct ctdb_connection * conn, bool client_first);
60 const char *ctdb_connection_to_string(TALLOC_CTX *mem_ctx,
61                                       struct ctdb_connection * conn,
62                                       bool client_first);
63 int ctdb_connection_from_string(const char *str, bool client_first,
64                                 struct ctdb_connection *conn);
65
66 int ctdb_connection_list_add(struct ctdb_connection_list *conn_list,
67                              struct ctdb_connection *conn);
68 int ctdb_connection_list_sort(struct ctdb_connection_list *conn_list);
69 const char *ctdb_connection_list_to_string(
70         TALLOC_CTX *mem_ctx,
71         struct ctdb_connection_list *conn_list, bool client_first);
72 int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first,
73                               struct ctdb_connection_list **conn_list);
74
75 #endif /* __CTDB_PROTOCOL_UTIL_H__ */