8e2bf9a87365ea8ba7c6ccad509ed3d1183bfe2f
[yaz-moved-to-github.git] / src / elementset.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: elementset.c,v 1.3 2007-01-03 08:42:15 adam Exp $
6  */
7 /**
8  * \file elementset.c
9  * \brief Z39.50 element set utilities
10  */
11
12 #if HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <yaz/proto.h>
17
18 const char *yaz_get_esn(Z_RecordComposition *comp)
19 {
20     if (comp && comp->which == Z_RecordComp_complex)
21     {
22         if (comp->u.complex->generic
23             && comp->u.complex->generic->elementSpec
24             && (comp->u.complex->generic->elementSpec->which ==
25                 Z_ElementSpec_elementSetName))
26             return comp->u.complex->generic->elementSpec->u.elementSetName;
27     }
28     else if (comp && comp->which == Z_RecordComp_simple &&
29              comp->u.simple->which == Z_ElementSetNames_generic)
30         return comp->u.simple->u.generic;
31     return 0;
32 }
33
34 void yaz_set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem)
35 {
36     Z_RecordComposition *comp = nmem_malloc(nmem, sizeof(*comp));
37     
38     comp->which = Z_RecordComp_simple;
39     comp->u.simple = nmem_malloc(nmem, sizeof(*comp->u.simple));
40     comp->u.simple->which = Z_ElementSetNames_generic;
41     comp->u.simple->u.generic = nmem_strdup(nmem, esn);
42     *comp_p = comp;
43 }
44
45
46
47 /*
48  * Local variables:
49  * c-basic-offset: 4
50  * indent-tabs-mode: nil
51  * End:
52  * vim: shiftwidth=4 tabstop=8 expandtab
53  */
54