* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* $Id: oid_db.h,v 1.8 2007-05-08 08:22:35 adam Exp $ */
+/* $Id: oid_db.h,v 1.9 2007-06-24 19:27:11 adam Exp $ */
/**
* \file oid_db.h
const char *yaz_oid_to_string_buf(const Odr_oid *oid,
oid_class *oclass, char *buf);
+
+/** \brief maps named from standard database to dot notation
+ \param oclass class of string (enum oid_class)
+ \param name named OID
+ \param oid_buf buffer for result (must be of size OID_STR_MAX)
+ \returns OID string or NULL if name is not registered in database
+*/
+YAZ_EXPORT
+char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf);
+
+
/** \brief traverses OIDs in a database
\param oid_db OID database
\param func function to be called for each OID
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: oid_db.c,v 1.8 2007-05-08 08:22:36 adam Exp $
+ * $Id: oid_db.c,v 1.9 2007-06-24 19:27:12 adam Exp $
*/
/**
return oid_oid_to_dotstring(oid, buf);
}
+
+char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf)
+{
+ const Odr_oid *oid = yaz_string_to_oid(yaz_oid_std(), oclass, name);
+ if (oid)
+ return oid_oid_to_dotstring(oid, oid_buf);
+ return 0;
+}
+
+
int yaz_oid_is_iso2709(const Odr_oid *oid)
{
if (oid_oidlen(oid) == 6 && oid[0] == 1 && oid[1] == 2
## Copyright (C) 1995-2007, Index Data ApS
## All rights reserved.
-## $Id: Makefile.am,v 1.34 2007-04-10 14:42:31 adam Exp $
+## $Id: Makefile.am,v 1.35 2007-06-24 19:27:12 adam Exp $
check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \
tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \
tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \
- tst_timing tst_query_charset
+ tst_timing tst_query_charset tst_oid
check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh tstmarccol.sh
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
tstpquery_SOURCES = tstpquery.c
tst_comstack_SOURCES = tst_comstack.c
tst_filepath_SOURCES = tst_filepath.c
+tst_oid_SOURCES = tst_oid.c
tst_record_conv_SOURCES = tst_record_conv.c
tst_retrieval_SOURCES = tst_retrieval.c
tst_tpath_SOURCES = tst_tpath.c
--- /dev/null
+/*
+ * Copyright (C) 1995-2007, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: tst_oid.c,v 1.1 2007-06-24 19:27:12 adam Exp $
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/oid_db.h>
+
+static void tst(void)
+{
+ char oid_buf[OID_STR_MAX];
+ const char *n;
+ yaz_oid_db_t db;
+ const Odr_oid *c_oid;
+ Odr_oid *oid;
+ NMEM nmem = nmem_create();
+ ODR odr = odr_createmem(ODR_ENCODE);
+
+ db = yaz_oid_std();
+ YAZ_CHECK(db);
+
+ c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "Bib-1");
+ YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
+
+ c_oid = yaz_string_to_oid(db, CLASS_GENERAL, "Bib-1");
+ YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
+
+ c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "unknown");
+ YAZ_CHECK(c_oid == 0);
+
+ oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "1.2.840.10003.3.1", nmem);
+ YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
+
+ oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "unknown", nmem);
+ YAZ_CHECK(oid == 0);
+
+ oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "1.2.840.10003.3.1", odr);
+ YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
+
+ oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "unknown", odr);
+ YAZ_CHECK(oid == 0);
+
+ n = yaz_oid_to_string(db, yaz_oid_attset_bib_1, 0);
+ YAZ_CHECK(n && !strcmp(n, "Bib-1"));
+
+ n = oid_name_to_dotstring(CLASS_ATTSET, "Bib-1", oid_buf);
+ YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.3.1"));
+
+ n = oid_name_to_dotstring(CLASS_DIAGSET, "Bib-1", oid_buf);
+ YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.4.1"));
+
+ n = oid_name_to_dotstring(CLASS_DIAGSET, "unknown", oid_buf);
+ YAZ_CHECK(!n);
+
+ n = oid_name_to_dotstring(CLASS_DIAGSET, "1.2.840.10003.3.1", oid_buf);
+ YAZ_CHECK(!n);
+
+ nmem_destroy(nmem);
+ odr_destroy(odr);
+}
+
+
+int main (int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_LOG();
+ tst();
+ YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+