1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
6 \brief Copies various Z39.50 types
13 #include <yaz/copy_types.h>
15 /** macro clone_z_type copies a given ASN.1 type */
16 #define clone_z_type(x) \
17 Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \
20 ODR enc = odr_createmem(ODR_ENCODE); \
21 ODR dec = odr_createmem(ODR_DECODE); \
22 if (z_##x(enc, &q, 0, 0)) \
25 char *buf = odr_getbuf(enc, &len, 0); \
28 odr_setbuf(dec, buf, len, 0); \
29 z_##x(dec, &q1, 0, 0); \
30 nmem_transfer(nmem_out, dec->mem); \
37 int yaz_compare_z_##x(Z_##x *a, Z_##x *b) \
40 ODR o_a = odr_createmem(ODR_ENCODE); \
41 ODR o_b = odr_createmem(ODR_ENCODE); \
42 int r_a = z_##x(o_a, &a, 1, 0); \
43 int r_b = z_##x(o_b, &b, 1, 0); \
47 char *buf_a = odr_getbuf(o_a, &len_a, 0); \
48 char *buf_b = odr_getbuf(o_b, &len_b, 0); \
49 if (buf_a && buf_b && len_a == len_b && !memcmp(buf_a, buf_b, len_a)) \
51 else if (!buf_a && !buf_b) \
59 clone_z_type(NamePlusRecord)
60 clone_z_type(RPNQuery)
62 clone_z_type(RecordComposition)
63 clone_z_type(OtherInformation)
65 Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out)
67 return yaz_clone_z_RPNQuery(q, out->mem);
70 Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out)
72 return yaz_clone_z_Query(q, out->mem);
78 * c-file-style: "Stroustrup"
79 * indent-tabs-mode: nil
81 * vim: shiftwidth=4 tabstop=8 expandtab