Added cs_get_SSL. yaz-client-ssl prints peer info
[yaz-moved-to-github.git] / src / grs1disp.c
1 /*
2  * Copyright (c) 2002, Index Data.
3  * See the file LICENSE for details.
4  *
5  * $Id: grs1disp.c,v 1.1 2003-10-27 12:21:30 adam Exp $
6  */
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <ctype.h>
12
13 #include <yaz/proto.h>
14
15 static void display_variant(WRBUF w, Z_Variant *v, int level)
16 {
17     int i;
18
19     for (i = 0; i < v->num_triples; i++)
20     {
21         printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
22             *v->triples[i]->type);
23         if (v->triples[i]->which == Z_Triple_internationalString)
24             printf(",value=%s\n", v->triples[i]->value.internationalString);
25         else
26             printf("\n");
27     }
28 }
29
30 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
31 {
32     int i;
33
34     if (!r)
35     {
36         return;
37     }
38     for (i = 0; i < r->num_elements; i++)
39     {
40         Z_TaggedElement *t;
41
42         wrbuf_printf(w, "%*s", level * 4, "");
43         t = r->elements[i];
44         wrbuf_printf(w, "(");
45         if (t->tagType)
46             wrbuf_printf(w, "%d,", *t->tagType);
47         else
48             wrbuf_printf(w, "?,");
49         if (t->tagValue->which == Z_StringOrNumeric_numeric)
50             wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
51         else
52             wrbuf_printf(w, "%s) ", t->tagValue->u.string);
53         if (t->content->which == Z_ElementData_subtree)
54         {
55             if (!t->content->u.subtree)
56                 printf (" (no subtree)\n");
57             else
58             {
59                 wrbuf_printf(w, "\n");
60                 display_grs1(w, t->content->u.subtree, level+1);
61             }
62         }
63         else if (t->content->which == Z_ElementData_string)
64             wrbuf_printf(w, "%s\n", t->content->u.string);
65         else if (t->content->which == Z_ElementData_numeric)
66             wrbuf_printf(w, "%d\n", *t->content->u.numeric);
67         else if (t->content->which == Z_ElementData_oid)
68         {
69             int *ip = t->content->u.oid;
70             oident *oent;
71             
72             if ((oent = oid_getentbyoid(t->content->u.oid)))
73                 wrbuf_printf(w, "OID: %s\n", oent->desc);
74             else
75             {
76                 wrbuf_printf(w, "{");
77                 while (ip && *ip >= 0)
78                     wrbuf_printf(w, " %d", *(ip++));
79                 wrbuf_printf(w, " }\n");
80             }
81         }
82         else if (t->content->which == Z_ElementData_noDataRequested)
83             wrbuf_printf(w, "[No data requested]\n");
84         else if (t->content->which == Z_ElementData_elementEmpty)
85             wrbuf_printf(w, "[Element empty]\n");
86         else if (t->content->which == Z_ElementData_elementNotThere)
87             wrbuf_printf(w, "[Element not there]\n");
88         else if (t->content->which == Z_ElementData_date)
89             wrbuf_printf(w, "Date: %s\n", t->content->u.date);
90         else if (t->content->which == Z_ElementData_ext)
91         {
92             printf ("External\n");
93             /* we cannot print externals here. Srry */
94         } 
95         else
96             wrbuf_printf(w, "? type = %d\n",t->content->which);
97         if (t->appliedVariant)
98             display_variant(w, t->appliedVariant, level+1);
99         if (t->metaData && t->metaData->supportedVariants)
100         {
101             int c;
102
103             wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
104             for (c = 0; c < t->metaData->num_supportedVariants; c++)
105             {
106                 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
107                 display_variant(w, t->metaData->supportedVariants[c], level+2);
108             }
109         }
110     }
111 }
112
113 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
114 {
115     display_grs1 (wrbuf, r, 0);
116 }
117