1f561e6caa0d02c43f610901b6831e1399ba3984
[yaz-moved-to-github.git] / src / copy_types.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2009 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /** \file copy_types.c
7     \brief Copies various Z39.50 types
8  */
9
10 #include <yaz/copy_types.h>
11
12 Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out)
13 {
14     Z_RPNQuery *q1 = 0;
15     ODR enc = odr_createmem(ODR_ENCODE);
16     ODR dec = odr_createmem(ODR_DECODE);
17     if (!z_RPNQuery(enc, &q, 0, 0))
18         return 0;
19     else
20     {
21         int len;
22         char *buf = odr_getbuf(enc, &len, 0);
23         if (buf)
24         {
25             odr_setbuf(dec, buf, len, 0);
26             z_RPNQuery(dec, &q1, 0, 0);
27             nmem_transfer(out->mem, dec->mem);
28         }
29     }
30     odr_destroy(enc);
31     odr_destroy(dec);
32     return q1;
33 }
34
35 Z_Query *yaz_copy_Z_Query(Z_Query *q, ODR out)
36 {
37     Z_Query *q1 = 0;
38     ODR enc = odr_createmem(ODR_ENCODE);
39     ODR dec = odr_createmem(ODR_DECODE);
40     if (!z_Query(enc, &q, 0, 0))
41         return 0;
42     else
43     {
44         int len;
45         char *buf = odr_getbuf(enc, &len, 0);
46         if (buf)
47         {
48             odr_setbuf(dec, buf, len, 0);
49             z_Query(dec, &q1, 0, 0);
50             nmem_transfer(out->mem, dec->mem);
51         }
52     }
53     odr_destroy(enc);
54     odr_destroy(dec);
55     return q1;
56 }
57
58
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66