Add comparison routines for some Z-types
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 20 Sep 2013 11:54:56 +0000 (13:54 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 20 Sep 2013 11:54:56 +0000 (13:54 +0200)
include/yaz/copy_types.h
src/copy_types.c

index 7162368..f8b297d 100644 (file)
@@ -47,19 +47,34 @@ YAZ_EXPORT
 Z_RPNQuery *yaz_clone_z_RPNQuery(Z_RPNQuery *q, NMEM out);
 
 YAZ_EXPORT
 Z_RPNQuery *yaz_clone_z_RPNQuery(Z_RPNQuery *q, NMEM out);
 
 YAZ_EXPORT
+int yaz_compare_z_RPNQuery(Z_RPNQuery *a, Z_RPNQuery *b);
+
+YAZ_EXPORT
 Z_Query *yaz_clone_z_Query(Z_Query *q, NMEM out);
 
 YAZ_EXPORT
 Z_Query *yaz_clone_z_Query(Z_Query *q, NMEM out);
 
 YAZ_EXPORT
+int yaz_compare_z_Query(Z_Query *a, Z_Query *b);
+
+YAZ_EXPORT
 Z_NamePlusRecord *yaz_clone_z_NamePlusRecord(Z_NamePlusRecord *s, NMEM out);
 Z_NamePlusRecord *yaz_clone_z_NamePlusRecord(Z_NamePlusRecord *s, NMEM out);
+YAZ_EXPORT
+int yaz_compare_z_NamePlusRecord(Z_NamePlusRecord *a, Z_NamePlusRecord *b);
 
 YAZ_EXPORT
 Z_RecordComposition *yaz_clone_z_RecordComposition(Z_RecordComposition *s,
                                                    NMEM out);
 
 YAZ_EXPORT
 Z_RecordComposition *yaz_clone_z_RecordComposition(Z_RecordComposition *s,
                                                    NMEM out);
+YAZ_EXPORT
+int yaz_compare_z_RecordComposition(Z_RecordComposition *a,
+                                    Z_RecordComposition *b);
 
 YAZ_EXPORT
 Z_OtherInformation *yaz_clone_z_OtherInformation(Z_OtherInformation *s,
                                                  NMEM out);
 
 
 YAZ_EXPORT
 Z_OtherInformation *yaz_clone_z_OtherInformation(Z_OtherInformation *s,
                                                  NMEM out);
 
+YAZ_EXPORT
+int yaz_compare_z_OtherInformation(Z_OtherInformation *a,
+                                   Z_OtherInformation *b);
+
 YAZ_END_CDECL
 
 #endif
 YAZ_END_CDECL
 
 #endif
index 7930d64..3b37152 100644 (file)
@@ -9,6 +9,7 @@
 #include <config.h>
 #endif
 
 #include <config.h>
 #endif
 
+#include <string.h>
 #include <yaz/copy_types.h>
 
 /** macro clone_z_type copies a given ASN.1 type */
 #include <yaz/copy_types.h>
 
 /** macro clone_z_type copies a given ASN.1 type */
@@ -32,6 +33,27 @@ Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \
     odr_destroy(enc); \
     odr_destroy(dec); \
     return q1; \
     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(NamePlusRecord)