X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fcopy_types.c;h=9062d866b7bc11e872c61414905627c2a34a1c1c;hp=dc3499307319dc73e29b8148e7af35545b50a668;hb=480f849f7e012d2d742d2d1dffbd1b0691dcd33a;hpb=88d3bedf772316f87e1996f655ccf8d1e2589755 diff --git a/src/copy_types.c b/src/copy_types.c index dc34993..9062d86 100644 --- a/src/copy_types.c +++ b/src/copy_types.c @@ -1,12 +1,15 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ - /** \file copy_types.c \brief Copies various Z39.50 types */ +#if HAVE_CONFIG_H +#include +#endif +#include #include /** macro clone_z_type copies a given ASN.1 type */ @@ -30,12 +33,34 @@ Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \ odr_destroy(enc); \ odr_destroy(dec); \ return q1; \ +} \ +int yaz_compare_z_##x(Z_##x *a, Z_##x *b) \ +{ \ + int ret = 0; \ + ODR o_a = odr_createmem(ODR_ENCODE); \ + ODR o_b = odr_createmem(ODR_ENCODE); \ + int r_a = z_##x(o_a, &a, 1, 0); \ + int r_b = z_##x(o_b, &b, 1, 0); \ + if (r_a && r_b) \ + { \ + int len_a, len_b; \ + char *buf_a = odr_getbuf(o_a, &len_a, 0); \ + char *buf_b = odr_getbuf(o_b, &len_b, 0); \ + if (buf_a && buf_b && len_a == len_b && !memcmp(buf_a, buf_b, len_a)) \ + ret = 1; \ + else if (!buf_a && !buf_b) \ + ret = 1; \ + } \ + odr_destroy(o_a); \ + odr_destroy(o_b); \ + return ret; \ } clone_z_type(NamePlusRecord) clone_z_type(RPNQuery) clone_z_type(Query) clone_z_type(RecordComposition) +clone_z_type(OtherInformation) Z_RPNQuery *yaz_copy_z_RPNQuery(Z_RPNQuery *q, ODR out) {