static void test_reply_control_data_test(void) { TALLOC_CTX *mem_ctx; size_t buflen; int ret; struct ctdb_reply_control_data cd, cd2; uint32_t opcode; printf("ctdb_reply_control_data\n"); fflush(stdout); for (opcode=0; opcode<NUM_CONTROLS; opcode++) { mem_ctx = talloc_new(NULL); assert(mem_ctx != NULL); printf("%u.. ", opcode); fflush(stdout); fill_ctdb_reply_control_data(mem_ctx, &cd, opcode); buflen = ctdb_reply_control_data_len(&cd); ctdb_reply_control_data_push(&cd, BUFFER); ret = ctdb_reply_control_data_pull(BUFFER, buflen, opcode, mem_ctx, &cd2); assert(ret == 0); verify_ctdb_reply_control_data(&cd, &cd2); talloc_free(mem_ctx); } printf("\n"); fflush(stdout); }
int ctdb_reply_control_push(struct ctdb_req_header *h, struct ctdb_reply_control *reply, TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len) { struct ctdb_reply_control_wire *wire; uint8_t *buf; size_t length, buflen, datalen, errlen; int ret; if (reply->status == 0) { datalen = ctdb_reply_control_data_len(&reply->rdata); } else { datalen = 0; } if (reply->errmsg == NULL) { errlen = 0; } else { errlen = strlen(reply->errmsg) + 1; } length = offsetof(struct ctdb_reply_control_wire, data) + datalen + errlen; ret = allocate_pkt(mem_ctx, length, &buf, &buflen); if (ret != 0) { return ret; } wire = (struct ctdb_reply_control_wire *)buf; h->length = buflen; memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header)); wire->status = reply->status; wire->datalen = datalen; if (reply->status == 0) { ctdb_reply_control_data_push(&reply->rdata, wire->data); } wire->errorlen = errlen; if (errlen > 0) { memcpy(wire->data + datalen, reply->errmsg, wire->errorlen); } *pkt = buf; *pkt_len = buflen; return 0; }
int ctdb_reply_control_push(struct ctdb_req_header *h, struct ctdb_reply_control *c, uint8_t *buf, size_t *buflen) { size_t offset = 0, np; size_t length; uint32_t dsize, esize; length = ctdb_reply_control_len(h, c); if (*buflen < length) { *buflen = length; return EMSGSIZE; } h->length = *buflen; ctdb_req_header_push(h, buf+offset, &np); offset += np; ctdb_int32_push(&c->status, buf+offset, &np); offset += np; if (c->status == 0) { dsize = ctdb_reply_control_data_len(&c->rdata); esize = 0; } else { dsize = 0; esize = ctdb_string_len(&c->errmsg); } ctdb_uint32_push(&dsize, buf+offset, &np); offset += np; ctdb_uint32_push(&esize, buf+offset, &np); offset += np; if (c->status == 0) { ctdb_reply_control_data_push(&c->rdata, buf+offset, &np); } else { ctdb_string_push(&c->errmsg, buf+offset, &np); } offset += np; return 0; }
size_t ctdb_reply_control_len(struct ctdb_req_header *h, struct ctdb_reply_control *c) { uint32_t dsize, esize; if (c->status == 0) { dsize = ctdb_reply_control_data_len(&c->rdata); esize = 0; } else { dsize = 0; esize = ctdb_string_len(&c->errmsg); } return ctdb_req_header_len(h) + ctdb_int32_len(&c->status) + ctdb_uint32_len(&dsize) + ctdb_uint32_len(&esize) + dsize + esize; }