ctdb-tests: Force symbolic link targets to be absolute
[Samba.git] / ctdb / protocol / protocol_keepalive.c
blob3a1fc0ec674f46e2ad650213a6019d3963a323c6
1 /*
2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2017
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.
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.
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/>.
20 #include "replace.h"
21 #include "system/network.h"
23 #include <talloc.h>
24 #include <tdb.h>
26 #include "protocol.h"
27 #include "protocol_api.h"
28 #include "protocol_private.h"
30 size_t ctdb_req_keepalive_len(struct ctdb_req_header *h,
31 struct ctdb_req_keepalive *c)
33 return ctdb_req_header_len(h) +
34 ctdb_uint32_len(&c->version) +
35 ctdb_uint32_len(&c->uptime);
38 int ctdb_req_keepalive_push(struct ctdb_req_header *h,
39 struct ctdb_req_keepalive *c,
40 uint8_t *buf, size_t *buflen)
42 size_t length, offset = 0, np;
44 length = ctdb_req_keepalive_len(h, c);
45 if (*buflen < length) {
46 *buflen = length;
47 return EMSGSIZE;
50 h->length = *buflen;
51 ctdb_req_header_push(h, buf+offset, &np);
52 offset += np;
54 ctdb_uint32_push(&c->version, buf+offset, &np);
55 offset += np;
57 ctdb_uint32_push(&c->uptime, buf+offset, &np);
58 offset += np;
60 return 0;
63 int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen,
64 struct ctdb_req_header *h,
65 TALLOC_CTX *mem_ctx,
66 struct ctdb_req_keepalive *c)
68 struct ctdb_req_header header;
69 size_t offset = 0, np;
70 int ret;
72 ret = ctdb_req_header_pull(buf, buflen, &header, &np);
73 if (ret != 0) {
74 return ret;
76 offset += np;
78 if (h != NULL) {
79 *h = header;
82 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->version, &np);
83 if (ret != 0) {
84 return ret;
86 offset += np;
88 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->uptime, &np);
89 if (ret != 0) {
90 return ret;
92 offset += np;
94 return 0;