1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

ctdb-protocol: Fix marshalling for ctdb_event_reply_data

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-27 01:48:51 +10:00 committed by Martin Schwenke
parent ab88bad3e2
commit f8e1aaa321
3 changed files with 20 additions and 40 deletions

View File

@ -711,7 +711,7 @@ static size_t ctdb_event_reply_data_len(struct ctdb_event_reply_data *in)
}
static void ctdb_event_reply_data_push(struct ctdb_event_reply_data *in,
uint8_t *buf)
uint8_t *buf, size_t *npush)
{
size_t offset = 0, np;
@ -721,6 +721,7 @@ static void ctdb_event_reply_data_push(struct ctdb_event_reply_data *in,
ctdb_int32_push(&in->result, buf+offset, &np);
offset += np;
np = 0;
switch (in->command) {
case CTDB_EVENT_COMMAND_RUN:
break;
@ -740,11 +741,15 @@ static void ctdb_event_reply_data_push(struct ctdb_event_reply_data *in,
case CTDB_EVENT_COMMAND_SCRIPT_DISABLE:
break;
}
offset += np;
*npush = offset;
}
static int ctdb_event_reply_data_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_event_reply_data *out)
struct ctdb_event_reply_data *out,
size_t *npull)
{
size_t offset = 0, np;
int ret;
@ -762,6 +767,7 @@ static int ctdb_event_reply_data_pull(uint8_t *buf, size_t buflen,
}
offset += np;
np = 0;
switch (out->command) {
case CTDB_EVENT_COMMAND_RUN:
break;
@ -789,6 +795,9 @@ static int ctdb_event_reply_data_pull(uint8_t *buf, size_t buflen,
return ret;
}
offset += np;
*npull = offset;
return 0;
}
@ -892,7 +901,7 @@ size_t ctdb_event_reply_len(struct ctdb_event_reply *in)
int ctdb_event_reply_push(struct ctdb_event_reply *in,
uint8_t *buf, size_t *buflen)
{
size_t len, offset = 0;
size_t len, offset = 0, np;
len = ctdb_event_reply_len(in);
if (*buflen < len) {
@ -905,7 +914,7 @@ int ctdb_event_reply_push(struct ctdb_event_reply *in,
ctdb_event_header_push(&in->header, buf);
offset += ctdb_event_header_len(&in->header);
ctdb_event_reply_data_push(&in->rdata, buf+offset);
ctdb_event_reply_data_push(&in->rdata, buf+offset, &np);
return 0;
}
@ -914,7 +923,7 @@ int ctdb_event_reply_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_event_reply *out)
{
size_t offset = 0;
size_t offset = 0, np;
int ret;
ret = ctdb_event_header_pull(buf, buflen, mem_ctx, &out->header);
@ -924,7 +933,7 @@ int ctdb_event_reply_pull(uint8_t *buf, size_t buflen,
offset += ctdb_event_header_len(&out->header);
ret = ctdb_event_reply_data_pull(buf+offset, buflen-offset,
mem_ctx, &out->rdata);
mem_ctx, &out->rdata, &np);
if (ret != 0) {
return ret;
}

View File

@ -21,8 +21,7 @@ generate_output ()
output=$(
echo "ctdb_event_header"
generate_output "ctdb_event_request_data"
echo "ctdb_event_reply_data"
echo "$command_output"
generate_output "ctdb_event_reply_data"
echo "ctdb_event_request"
echo "$command_output"
echo "ctdb_event_reply"

View File

@ -120,37 +120,6 @@ static void test_ctdb_event_header(void)
#define NUM_COMMANDS 5
static void test_ctdb_event_reply_data(void)
{
TALLOC_CTX *mem_ctx;
size_t buflen;
struct ctdb_event_reply_data rd, rd2;
uint32_t command;
int ret;
printf("ctdb_event_reply_data\n");
fflush(stdout);
for (command=1; command<=NUM_COMMANDS; command++) {
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
printf("%u.. ", command);
fflush(stdout);
fill_ctdb_event_reply_data(mem_ctx, &rd, command);
buflen = ctdb_event_reply_data_len(&rd);
ctdb_event_reply_data_push(&rd, BUFFER);
ret = ctdb_event_reply_data_pull(BUFFER, buflen, mem_ctx, &rd2);
assert(ret == 0);
verify_ctdb_event_reply_data(&rd, &rd2);
talloc_free(mem_ctx);
}
printf("\n");
fflush(stdout);
}
static void test_ctdb_event_request(void)
{
TALLOC_CTX *mem_ctx;
@ -243,6 +212,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_script_list,
ctdb_event_reply_script_list);
PROTOCOL_EVENT1_TEST(struct ctdb_event_request_data, ctdb_event_request_data);
PROTOCOL_EVENT1_TEST(struct ctdb_event_reply_data, ctdb_event_reply_data);
int main(int argc, char *argv[])
{
@ -265,7 +235,9 @@ int main(int argc, char *argv[])
for (command=1; command<=NUM_COMMANDS; command++) {
TEST_FUNC(ctdb_event_request_data)(command);
}
test_ctdb_event_reply_data();
for (command=1; command<=NUM_COMMANDS; command++) {
TEST_FUNC(ctdb_event_reply_data)(command);
}
test_ctdb_event_request();
test_ctdb_event_reply();