2 * Copyright (c) 1999, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: otherinfo.c,v $
7 * Revision 1.1 1999-06-08 10:10:16 adam
8 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
10 * Revision 1.1 1999/04/26 07:25:25 adam
11 * Implemented OtherInfo utility.
18 #include <otherinfo.h>
20 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
24 case Z_APDU_initRequest:
25 *oip = &apdu->u.initRequest->otherInfo;
27 case Z_APDU_searchRequest:
28 *oip = &apdu->u.searchRequest->otherInfo;
30 case Z_APDU_presentRequest:
31 *oip = &apdu->u.presentRequest->otherInfo;
33 case Z_APDU_sortRequest:
34 *oip = &apdu->u.sortRequest->otherInfo;
36 case Z_APDU_scanRequest:
37 *oip = &apdu->u.scanRequest->otherInfo;
39 case Z_APDU_initResponse:
40 *oip = &apdu->u.initResponse->otherInfo;
42 case Z_APDU_searchResponse:
43 *oip = &apdu->u.searchResponse->otherInfo;
45 case Z_APDU_presentResponse:
46 *oip = &apdu->u.presentResponse->otherInfo;
48 case Z_APDU_sortResponse:
49 *oip = &apdu->u.sortResponse->otherInfo;
51 case Z_APDU_scanResponse:
52 *oip = &apdu->u.scanResponse->otherInfo;
60 Z_OtherInformationUnit *yaz_oi_update (
61 Z_OtherInformation **otherInformationP, ODR odr,
62 int *oid, int categoryValue)
65 Z_OtherInformation *otherInformation = *otherInformationP;
66 if (!otherInformation)
70 otherInformation = *otherInformationP = (Z_OtherInformation *)
71 odr_malloc (odr, sizeof(*otherInformation));
72 otherInformation->num_elements = 0;
73 otherInformation->list = 0;
75 for (i = 0; i<otherInformation->num_elements; i++)
79 if (!otherInformation->list[i]->category)
80 return otherInformation->list[i];
84 if (otherInformation->list[i]->category &&
86 *otherInformation->list[i]->category->categoryValue &&
87 !oid_oidcmp (oid, otherInformation->list[i]->category->
89 return otherInformation->list[i];
96 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
97 odr_malloc(odr, otherInformation->num_elements+1 *
99 for (i = 0; i<otherInformation->num_elements; i++)
100 newlist[i] = otherInformation->list[i];
101 otherInformation->list = newlist;
103 otherInformation->list[i] = (Z_OtherInformationUnit*)
104 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
107 otherInformation->list[i]->category = (Z_InfoCategory*)
108 odr_malloc (odr, sizeof(Z_InfoCategory));
109 otherInformation->list[i]->category->categoryTypeId = (int*)
110 odr_oiddup (odr, oid);
111 otherInformation->list[i]->category->categoryValue = (int*)
112 odr_malloc (odr, sizeof(int));
113 *otherInformation->list[i]->category->categoryValue =
117 otherInformation->list[i]->category = 0;
118 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
119 otherInformation->list[i]->information.characterInfo = 0;
121 otherInformation->num_elements = i+1;
122 return otherInformation->list[i];
126 void yaz_oi_set_string_oid (
127 Z_OtherInformation **otherInformation, ODR odr,
128 int *oid, int categoryValue,
131 Z_OtherInformationUnit *oi =
132 yaz_oi_update(otherInformation, odr, oid, categoryValue);
135 oi->which = Z_OtherInfo_characterInfo;
136 oi->information.characterInfo = odr_strdup (odr, str);
139 void yaz_oi_set_string_oidval (
140 Z_OtherInformation **otherInformation, ODR odr,
141 int oidval, int categoryValue,
146 ent.proto = PROTO_Z3950;
147 ent.oclass = CLASS_USERINFO;
148 ent.value = (oid_value) oidval;
149 if (!oid_ent_to_oid (&ent, oid))
151 yaz_oi_set_string_oid(otherInformation,
152 odr, oid, categoryValue, str);
155 char *yaz_oi_get_string_oid (
156 Z_OtherInformation **otherInformation,
157 int *oid, int categoryValue)
159 Z_OtherInformationUnit *oi;
161 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1)) &&
162 oi->which == Z_OtherInfo_characterInfo)
163 return oi->information.characterInfo;
167 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
168 int oidval, int categoryValue)
172 ent.proto = PROTO_Z3950;
173 ent.oclass = CLASS_USERINFO;
174 ent.value = (oid_value) oidval;
176 if (!oid_ent_to_oid (&ent, oid))
178 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue);