From 046d4688231c6a2338e581f0d87f2611c1e9f877 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 1 Mar 2018 18:20:19 +1100 Subject: [PATCH] ctdb-protocol: Separate protocol-basic subsystem This includes marshalling code for basic data types. This will be used by other daemons. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/protocol/protocol_basic.c | 4 +- ctdb/protocol/protocol_basic.h | 86 ++++++++++++++++++++++++++++++++ ctdb/protocol/protocol_private.h | 64 +----------------------- ctdb/wscript | 8 ++- 4 files changed, 94 insertions(+), 68 deletions(-) create mode 100644 ctdb/protocol/protocol_basic.h diff --git a/ctdb/protocol/protocol_basic.c b/ctdb/protocol/protocol_basic.c index 4e86ef32df7..94b18c1cd10 100644 --- a/ctdb/protocol/protocol_basic.c +++ b/ctdb/protocol/protocol_basic.c @@ -21,10 +21,8 @@ #include "system/network.h" #include -#include -#include "protocol.h" -#include "protocol_private.h" +#include "protocol_basic.h" /* * Basic data types diff --git a/ctdb/protocol/protocol_basic.h b/ctdb/protocol/protocol_basic.h new file mode 100644 index 00000000000..4086e81e87b --- /dev/null +++ b/ctdb/protocol/protocol_basic.h @@ -0,0 +1,86 @@ +/* + CTDB protocol marshalling + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#ifndef __PROTOCOL_BASIC_H__ +#define __PROTOCOL_BASIC_H__ + +/* + * From protocol/protocol_basic.c + */ + +size_t ctdb_uint8_len(uint8_t *in); +void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush); +int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull); + +size_t ctdb_uint16_len(uint16_t *in); +void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush); +int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_t *out, + size_t *npull); + +size_t ctdb_int32_len(int32_t *in); +void ctdb_int32_push(int32_t *in, uint8_t *buf, size_t *npush); +int ctdb_int32_pull(uint8_t *buf, size_t buflen, int32_t *out, size_t *npull); + +size_t ctdb_uint32_len(uint32_t *in); +void ctdb_uint32_push(uint32_t *in, uint8_t *buf, size_t *npush); +int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out, + size_t *npull); + +size_t ctdb_uint64_len(uint64_t *in); +void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush); +int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out, + size_t *npull); + +size_t ctdb_double_len(double *in); +void ctdb_double_push(double *in, uint8_t *buf, size_t *npush); +int ctdb_double_pull(uint8_t *buf, size_t buflen, double *out, size_t *npull); + +size_t ctdb_bool_len(bool *in); +void ctdb_bool_push(bool *in, uint8_t *buf, size_t *npush); +int ctdb_bool_pull(uint8_t *buf, size_t buflen, bool *out, size_t *npull); + +size_t ctdb_chararray_len(char *in, size_t len); +void ctdb_chararray_push(char *in, size_t len, uint8_t *buf, size_t *npush); +int ctdb_chararray_pull(uint8_t *buf, size_t buflen, char *out, size_t len, + size_t *npull); + +size_t ctdb_string_len(const char **in); +void ctdb_string_push(const char **in, uint8_t *buf, size_t *npush); +int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, + const char **out, size_t *npull); + +size_t ctdb_stringn_len(const char **in); +void ctdb_stringn_push(const char **in, uint8_t *buf, size_t *npush); +int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, + const char **out, size_t *npull); + +size_t ctdb_pid_len(pid_t *in); +void ctdb_pid_push(pid_t *in, uint8_t *buf, size_t *npush); +int ctdb_pid_pull(uint8_t *buf, size_t buflen, pid_t *out, size_t *npull); + +size_t ctdb_timeval_len(struct timeval *in); +void ctdb_timeval_push(struct timeval *in, uint8_t *buf, size_t *npush); +int ctdb_timeval_pull(uint8_t *buf, size_t buflen, struct timeval *out, + size_t *npull); + +size_t ctdb_padding_len(int count); +void ctdb_padding_push(int count, uint8_t *buf, size_t *npush); +int ctdb_padding_pull(uint8_t *buf, size_t buflen, int count, size_t *npull); + +#endif /* __PROTOCOL_BASIC_H__ */ diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index c3fab3f3a24..1c3e56fcb7a 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -21,69 +21,7 @@ #define __PROTOCOL_PRIVATE_H__ #include "protocol.h" - -/* - * From protocol/protocol_basic.c - */ - -size_t ctdb_uint8_len(uint8_t *in); -void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush); -int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull); - -size_t ctdb_uint16_len(uint16_t *in); -void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush); -int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_t *out, - size_t *npull); - -size_t ctdb_int32_len(int32_t *in); -void ctdb_int32_push(int32_t *in, uint8_t *buf, size_t *npush); -int ctdb_int32_pull(uint8_t *buf, size_t buflen, int32_t *out, size_t *npull); - -size_t ctdb_uint32_len(uint32_t *in); -void ctdb_uint32_push(uint32_t *in, uint8_t *buf, size_t *npush); -int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out, - size_t *npull); - -size_t ctdb_uint64_len(uint64_t *in); -void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush); -int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out, - size_t *npull); - -size_t ctdb_double_len(double *in); -void ctdb_double_push(double *in, uint8_t *buf, size_t *npush); -int ctdb_double_pull(uint8_t *buf, size_t buflen, double *out, size_t *npull); - -size_t ctdb_bool_len(bool *in); -void ctdb_bool_push(bool *in, uint8_t *buf, size_t *npush); -int ctdb_bool_pull(uint8_t *buf, size_t buflen, bool *out, size_t *npull); - -size_t ctdb_chararray_len(char *in, size_t len); -void ctdb_chararray_push(char *in, size_t len, uint8_t *buf, size_t *npush); -int ctdb_chararray_pull(uint8_t *buf, size_t buflen, char *out, size_t len, - size_t *npull); - -size_t ctdb_string_len(const char **in); -void ctdb_string_push(const char **in, uint8_t *buf, size_t *npush); -int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, - const char **out, size_t *npull); - -size_t ctdb_stringn_len(const char **in); -void ctdb_stringn_push(const char **in, uint8_t *buf, size_t *npush); -int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, - const char **out, size_t *npull); - -size_t ctdb_pid_len(pid_t *in); -void ctdb_pid_push(pid_t *in, uint8_t *buf, size_t *npush); -int ctdb_pid_pull(uint8_t *buf, size_t buflen, pid_t *out, size_t *npull); - -size_t ctdb_timeval_len(struct timeval *in); -void ctdb_timeval_push(struct timeval *in, uint8_t *buf, size_t *npush); -int ctdb_timeval_pull(uint8_t *buf, size_t buflen, struct timeval *out, - size_t *npull); - -size_t ctdb_padding_len(int count); -void ctdb_padding_push(int count, uint8_t *buf, size_t *npush); -int ctdb_padding_pull(uint8_t *buf, size_t buflen, int count, size_t *npull); +#include "protocol_basic.h" /* * From protocol/protocol_types.c diff --git a/ctdb/wscript b/ctdb/wscript index c6883d8c348..deef78f1bea 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -411,10 +411,14 @@ def build(bld): source='common/logging_conf.c', deps='ctdb-util talloc') + bld.SAMBA_SUBSYSTEM('ctdb-protocol-basic', + source=bld.SUBDIR('protocol', 'protocol_basic.c'), + deps='talloc tdb') + bld.SAMBA_SUBSYSTEM('ctdb-protocol', source=bld.SUBDIR('protocol', '''protocol_header.c protocol_packet.c - protocol_basic.c protocol_types.c + protocol_types.c protocol_call.c protocol_message.c protocol_control.c @@ -425,7 +429,7 @@ def build(bld): protocol_event.c protocol_sock.c'''), includes='include', - deps='replace talloc tdb') + deps='ctdb-protocol-basic replace talloc tdb') bld.SAMBA_SUBSYSTEM('ctdb-protocol-util', source='protocol/protocol_util.c',