1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
/* This file is part of the YAZ toolkit.
* Copyright (C) 1995-2012 Index Data
* See the file LICENSE for details.
*/
/** \file copy_types.c
\brief Copies various Z39.50 types
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <yaz/copy_types.h>
/** macro clone_z_type copies a given ASN.1 type */
#define clone_z_type(x) \
Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \
{ \
Z_##x *q1 = 0; \
ODR enc = odr_createmem(ODR_ENCODE); \
ODR dec = odr_createmem(ODR_DECODE); \
if (z_##x(enc, &q, 0, 0)) \
{ \
int len; \
char *buf = odr_getbuf(enc, &len, 0); \
if (buf) \
{ \
odr_setbuf(dec, buf, len, 0); \
z_##x(dec, &q1, 0, 0); \
nmem_transfer(nmem_out, dec->mem); \
} \
} \
odr_destroy(enc); \
odr_destroy(dec); \
return q1; \
}
clone_z_type(NamePlusRecord)
clone_z_type(RPNQuery)
clone_z_type(Query)
clone_z_type(RecordComposition)
Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out)
{
return yaz_clone_z_RPNQuery(q, out->mem);
}
Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out)
{
return yaz_clone_z_Query(q, out->mem);
}
/*
* Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
|