ctdb-protocol: Add ctdb_connection utilities
[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 unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr);
45 void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port);
46 int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
47                           const ctdb_sock_addr *addr2);
48 int ctdb_sock_addr_cmp(const ctdb_sock_addr *addr1,
49                        const ctdb_sock_addr *addr2);
50 bool ctdb_sock_addr_same_ip(const ctdb_sock_addr *addr1,
51                             const ctdb_sock_addr *addr2);
52 bool ctdb_sock_addr_same(const ctdb_sock_addr *addr1,
53                          const ctdb_sock_addr *addr2);
54
55 int ctdb_connection_to_buf(char *buf, size_t buflen,
56                            struct ctdb_connection * conn, bool client_first);
57 const char *ctdb_connection_to_string(TALLOC_CTX *mem_ctx,
58                                       struct ctdb_connection * conn,
59                                       bool client_first);
60 int ctdb_connection_from_string(const char *str, bool client_first,
61                                 struct ctdb_connection *conn);
62
63 #endif /* __CTDB_PROTOCOL_UTIL_H__ */