int ctdb_req_control_pull(uint8_t *pkt, size_t pkt_len, struct ctdb_req_header *h, TALLOC_CTX *mem_ctx, struct ctdb_req_control *request) { struct ctdb_req_control_wire *wire = (struct ctdb_req_control_wire *)pkt; size_t length; int ret; length = offsetof(struct ctdb_req_control_wire, data); if (pkt_len < length) { return EMSGSIZE; } if (pkt_len < length + wire->datalen) { return EMSGSIZE; } memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header)); request->opcode = wire->opcode; request->pad = wire->pad; request->srvid = wire->srvid; request->client_id = wire->client_id; request->flags = wire->flags; ret = ctdb_req_control_data_pull(wire->data, wire->datalen, request->opcode, mem_ctx, &request->rdata); if (ret != 0) { return ret; } return 0; }
static void test_req_control_data_test(void) { TALLOC_CTX *mem_ctx; size_t buflen; int ret; struct ctdb_req_control_data cd, cd2; uint32_t opcode; printf("ctdb_req_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_req_control_data(mem_ctx, &cd, opcode); buflen = ctdb_req_control_data_len(&cd); ctdb_req_control_data_push(&cd, BUFFER); ret = ctdb_req_control_data_pull(BUFFER, buflen, opcode, mem_ctx, &cd2); assert(ret == 0); verify_ctdb_req_control_data(&cd, &cd2); talloc_free(mem_ctx); } printf("\n"); fflush(stdout); }
int ctdb_req_control_pull(uint8_t *buf, size_t buflen, struct ctdb_req_header *h, TALLOC_CTX *mem_ctx, struct ctdb_req_control *c) { struct ctdb_req_header header; size_t offset = 0, np; uint32_t u32; 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_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np); if (ret != 0) { return ret; } offset += np; ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np); if (ret != 0) { return ret; } offset += np; if (u32 > buflen-offset) { return EMSGSIZE; } ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx, &c->rdata, &np); if (ret != 0) { return ret; } offset += np; if (offset > buflen) { return EMSGSIZE; } return 0; }