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.2 1999-09-13 12:51:35 adam
8 * Fixed bug in yaz_oi_update and added delete option.
10 * Revision 1.1 1999/06/08 10:10:16 adam
11 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
13 * Revision 1.1 1999/04/26 07:25:25 adam
14 * Implemented OtherInfo utility.
21 #include <otherinfo.h>
23 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
27 case Z_APDU_initRequest:
28 *oip = &apdu->u.initRequest->otherInfo;
30 case Z_APDU_searchRequest:
31 *oip = &apdu->u.searchRequest->otherInfo;
33 case Z_APDU_presentRequest:
34 *oip = &apdu->u.presentRequest->otherInfo;
36 case Z_APDU_sortRequest:
37 *oip = &apdu->u.sortRequest->otherInfo;
39 case Z_APDU_scanRequest:
40 *oip = &apdu->u.scanRequest->otherInfo;
42 case Z_APDU_initResponse:
43 *oip = &apdu->u.initResponse->otherInfo;
45 case Z_APDU_searchResponse:
46 *oip = &apdu->u.searchResponse->otherInfo;
48 case Z_APDU_presentResponse:
49 *oip = &apdu->u.presentResponse->otherInfo;
51 case Z_APDU_sortResponse:
52 *oip = &apdu->u.sortResponse->otherInfo;
54 case Z_APDU_scanResponse:
55 *oip = &apdu->u.scanResponse->otherInfo;
63 Z_OtherInformationUnit *yaz_oi_update (
64 Z_OtherInformation **otherInformationP, ODR odr,
65 int *oid, int categoryValue, int delete_flag)
68 Z_OtherInformation *otherInformation = *otherInformationP;
69 if (!otherInformation)
73 otherInformation = *otherInformationP = (Z_OtherInformation *)
74 odr_malloc (odr, sizeof(*otherInformation));
75 otherInformation->num_elements = 0;
76 otherInformation->list = 0;
78 for (i = 0; i<otherInformation->num_elements; i++)
82 if (!otherInformation->list[i]->category)
83 return otherInformation->list[i];
87 if (otherInformation->list[i]->category &&
89 *otherInformation->list[i]->category->categoryValue &&
90 !oid_oidcmp (oid, otherInformation->list[i]->category->
93 Z_OtherInformationUnit *this_list = otherInformation->list[i];
97 (otherInformation->num_elements)--;
98 while (i < otherInformation->num_elements)
100 otherInformation->list[i] =
101 otherInformation->list[i+1];
113 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
114 odr_malloc(odr, (otherInformation->num_elements+1) *
116 for (i = 0; i<otherInformation->num_elements; i++)
117 newlist[i] = otherInformation->list[i];
118 otherInformation->list = newlist;
120 otherInformation->list[i] = (Z_OtherInformationUnit*)
121 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
124 otherInformation->list[i]->category = (Z_InfoCategory*)
125 odr_malloc (odr, sizeof(Z_InfoCategory));
126 otherInformation->list[i]->category->categoryTypeId = (int*)
127 odr_oiddup (odr, oid);
128 otherInformation->list[i]->category->categoryValue = (int*)
129 odr_malloc (odr, sizeof(int));
130 *otherInformation->list[i]->category->categoryValue =
134 otherInformation->list[i]->category = 0;
135 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
136 otherInformation->list[i]->information.characterInfo = 0;
138 otherInformation->num_elements = i+1;
139 return otherInformation->list[i];
143 void yaz_oi_set_string_oid (
144 Z_OtherInformation **otherInformation, ODR odr,
145 int *oid, int categoryValue,
148 Z_OtherInformationUnit *oi =
149 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
152 oi->which = Z_OtherInfo_characterInfo;
153 oi->information.characterInfo = odr_strdup (odr, str);
156 void yaz_oi_set_string_oidval (
157 Z_OtherInformation **otherInformation, ODR odr,
158 int oidval, int categoryValue,
163 ent.proto = PROTO_Z3950;
164 ent.oclass = CLASS_USERINFO;
165 ent.value = (oid_value) oidval;
166 if (!oid_ent_to_oid (&ent, oid))
168 yaz_oi_set_string_oid(otherInformation,
169 odr, oid, categoryValue, str);
172 char *yaz_oi_get_string_oid (
173 Z_OtherInformation **otherInformation,
174 int *oid, int categoryValue, int delete_flag)
176 Z_OtherInformationUnit *oi;
178 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1, delete_flag)) &&
179 oi->which == Z_OtherInfo_characterInfo)
180 return oi->information.characterInfo;
184 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
185 int oidval, int categoryValue, int delete_flag)
189 ent.proto = PROTO_Z3950;
190 ent.oclass = CLASS_USERINFO;
191 ent.value = (oid_value) oidval;
193 if (!oid_ent_to_oid (&ent, oid))
195 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,