From 3d47aeca3756dc7d1c2ea91f74fef2b0886f76e8 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 10 Jul 2003 11:51:46 +0000 Subject: [PATCH] Add oid_name_to_oid(), oid_to_dotstring() and id_name_to_dotstring() --- include/yaz/oid.h | 6 +++++- util/oid.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/yaz/oid.h b/include/yaz/oid.h index f5eaa23..044fd1d 100644 --- a/include/yaz/oid.h +++ b/include/yaz/oid.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: oid.h,v 1.16 2003-06-02 12:53:27 adam Exp $ + * $Id: oid.h,v 1.17 2003-07-10 11:51:46 mike Exp $ */ #ifndef OID_H @@ -245,6 +245,10 @@ YAZ_EXPORT void oid_trav (void (*func)(struct oident *oidinfo, void *vp), YAZ_EXPORT void oid_init(void); YAZ_EXPORT void oid_exit(void); +YAZ_EXPORT int *oid_name_to_oid(oid_class oclass, const char *name, int *oid); +YAZ_EXPORT char *oid_to_dotstring(const int *oid, char *oidbuf); +YAZ_EXPORT char *oid_name_to_dotstring(oid_class oclass, const char *name, + char *oidbuf); YAZ_END_CDECL diff --git a/util/oid.c b/util/oid.c index a7f6914..4aeddfe 100644 --- a/util/oid.c +++ b/util/oid.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: oid.c,v 1.62 2003-06-02 12:53:28 adam Exp $ + * $Id: oid.c,v 1.63 2003-07-10 11:52:37 mike Exp $ */ /* @@ -572,3 +572,40 @@ void oid_trav (void (*func)(struct oident *oidinfo, void *vp), void *vp) for (ol = oident_table; ol; ol = ol->next) (*func)(&ol->oident, vp); } + +int *oid_name_to_oid(oid_class oclass, const char *name, int *oid) { + struct oident ent; + + /* Translate syntax to oid_val */ + oid_value value = oid_getvalbyname(name); + + /* Build it into an oident */ + ent.proto = PROTO_Z3950; + ent.oclass = oclass; + ent.value = value; + + /* Translate to an array of int */ + return oid_ent_to_oid(&ent, oid); +} + +char *oid_to_dotstring(const int *oid, char *oidbuf) { + char tmpbuf[20]; + int i; + + oidbuf[0] = '\0'; + for (i = 0; oid[i] != -1; i++) { + sprintf(tmpbuf, "%d", oid[i]); + if (i > 0) strcat(oidbuf, "."); + strcat(oidbuf, tmpbuf); + } + + return oidbuf; +} + +char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oidbuf) { + int oid[OID_SIZE]; + + (void) oid_name_to_oid(oclass, name, oid); + return oid_to_dotstring(oid, oidbuf); +} + -- 1.7.10.4