ctdb-protocol: Add marshalling for TDB_DATA
[obnox/samba/samba-obnox.git] / ctdb / protocol / protocol_types.c
index f868d767d079911d1b259a312c5ffeeb9bf0f0cc..bb472882e3cc4f6b04d6f9f8bc0a9e17581c366e 100644 (file)
@@ -2424,6 +2424,35 @@ int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        return 0;
 }
 
+size_t ctdb_tdb_data_len(TDB_DATA data)
+{
+       return data.dsize;
+}
+
+void ctdb_tdb_data_push(TDB_DATA data, uint8_t *buf)
+{
+       memcpy(buf, data.dptr, data.dsize);
+}
+
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      TDB_DATA *out)
+{
+       TDB_DATA data;
+
+       data.dsize = buflen;
+       if (data.dsize > 0) {
+               data.dptr = talloc_memdup(mem_ctx, buf, buflen);
+               if (data.dptr == NULL) {
+                       return ENOMEM;
+               }
+       } else {
+               data.dptr = NULL;
+       }
+
+       *out = data;
+       return 0;
+}
+
 size_t ctdb_server_id_len(struct ctdb_server_id *sid)
 {
        return sizeof(struct ctdb_server_id);