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_pull(uint8_t *pkt, size_t pkt_len, uint32_t opcode, struct ctdb_req_header *h, TALLOC_CTX *mem_ctx, struct ctdb_reply_control *reply) { struct ctdb_reply_control_wire *wire = (struct ctdb_reply_control_wire *)pkt; size_t length; int ret; length = offsetof(struct ctdb_reply_control_wire, data); if (pkt_len < length) { return EMSGSIZE; } if (pkt_len < length + wire->datalen + wire->errorlen) { return EMSGSIZE; } memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header)); reply->status = wire->status; if (reply->status != -1) { ret = ctdb_reply_control_data_pull(wire->data, wire->datalen, opcode, mem_ctx, &reply->rdata); if (ret != 0) { return ret; } } if (wire->errorlen > 0) { reply->errmsg = talloc_memdup(mem_ctx, wire->data + wire->datalen, wire->errorlen); } else { reply->errmsg = NULL; } return 0; }
int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode, struct ctdb_req_header *h, TALLOC_CTX *mem_ctx, struct ctdb_reply_control *c) { struct ctdb_req_header header; size_t offset = 0, np; uint32_t dsize, esize; int ret; ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np); if (ret != 0) { return ret; } offset += np; if (h != NULL) { *h = header; } ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np); if (ret != 0) { return ret; } offset += np; c->errmsg = NULL; if (c->status == 0) { if (buflen-offset < dsize) { return EMSGSIZE; } ret = ctdb_reply_control_data_pull(buf+offset, dsize, opcode, mem_ctx, &c->rdata, &np); if (ret != 0) { return ret; } offset += np; } else { if (buflen-offset < esize) { return EMSGSIZE; } ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg, &np); if (ret != 0) { return ret; } offset += np; } return 0; }