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.3 1999-11-10 09:06:40 adam
8 * Fixed yaz_oi_update so that it ignores NULL pointer.
10 * Revision 1.2 1999/09/13 12:51:35 adam
11 * Fixed bug in yaz_oi_update and added delete option.
13 * Revision 1.1 1999/06/08 10:10:16 adam
14 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
16 * Revision 1.1 1999/04/26 07:25:25 adam
17 * Implemented OtherInfo utility.
24 #include <otherinfo.h>
26 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
30 case Z_APDU_initRequest:
31 *oip = &apdu->u.initRequest->otherInfo;
33 case Z_APDU_searchRequest:
34 *oip = &apdu->u.searchRequest->otherInfo;
36 case Z_APDU_presentRequest:
37 *oip = &apdu->u.presentRequest->otherInfo;
39 case Z_APDU_sortRequest:
40 *oip = &apdu->u.sortRequest->otherInfo;
42 case Z_APDU_scanRequest:
43 *oip = &apdu->u.scanRequest->otherInfo;
45 case Z_APDU_extendedServicesRequest:
46 *oip = &apdu->u.extendedServicesRequest->otherInfo;
48 case Z_APDU_deleteResultSetRequest:
49 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
51 case Z_APDU_initResponse:
52 *oip = &apdu->u.initResponse->otherInfo;
54 case Z_APDU_searchResponse:
55 *oip = &apdu->u.searchResponse->otherInfo;
57 case Z_APDU_presentResponse:
58 *oip = &apdu->u.presentResponse->otherInfo;
60 case Z_APDU_sortResponse:
61 *oip = &apdu->u.sortResponse->otherInfo;
63 case Z_APDU_scanResponse:
64 *oip = &apdu->u.scanResponse->otherInfo;
66 case Z_APDU_extendedServicesResponse:
67 *oip = &apdu->u.extendedServicesResponse->otherInfo;
69 case Z_APDU_deleteResultSetResponse:
70 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
78 Z_OtherInformationUnit *yaz_oi_update (
79 Z_OtherInformation **otherInformationP, ODR odr,
80 int *oid, int categoryValue, int delete_flag)
83 Z_OtherInformation *otherInformation;
85 if (!otherInformationP)
87 otherInformation = *otherInformationP;
88 if (!otherInformation)
92 otherInformation = *otherInformationP = (Z_OtherInformation *)
93 odr_malloc (odr, sizeof(*otherInformation));
94 otherInformation->num_elements = 0;
95 otherInformation->list = 0;
97 for (i = 0; i<otherInformation->num_elements; i++)
101 if (!otherInformation->list[i]->category)
102 return otherInformation->list[i];
106 if (otherInformation->list[i]->category &&
108 *otherInformation->list[i]->category->categoryValue &&
109 !oid_oidcmp (oid, otherInformation->list[i]->category->
112 Z_OtherInformationUnit *this_list = otherInformation->list[i];
116 (otherInformation->num_elements)--;
117 while (i < otherInformation->num_elements)
119 otherInformation->list[i] =
120 otherInformation->list[i+1];
132 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
133 odr_malloc(odr, (otherInformation->num_elements+1) *
135 for (i = 0; i<otherInformation->num_elements; i++)
136 newlist[i] = otherInformation->list[i];
137 otherInformation->list = newlist;
139 otherInformation->list[i] = (Z_OtherInformationUnit*)
140 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
143 otherInformation->list[i]->category = (Z_InfoCategory*)
144 odr_malloc (odr, sizeof(Z_InfoCategory));
145 otherInformation->list[i]->category->categoryTypeId = (int*)
146 odr_oiddup (odr, oid);
147 otherInformation->list[i]->category->categoryValue = (int*)
148 odr_malloc (odr, sizeof(int));
149 *otherInformation->list[i]->category->categoryValue =
153 otherInformation->list[i]->category = 0;
154 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
155 otherInformation->list[i]->information.characterInfo = 0;
157 otherInformation->num_elements = i+1;
158 return otherInformation->list[i];
162 void yaz_oi_set_string_oid (
163 Z_OtherInformation **otherInformation, ODR odr,
164 int *oid, int categoryValue,
167 Z_OtherInformationUnit *oi =
168 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
171 oi->which = Z_OtherInfo_characterInfo;
172 oi->information.characterInfo = odr_strdup (odr, str);
175 void yaz_oi_set_string_oidval (
176 Z_OtherInformation **otherInformation, ODR odr,
177 int oidval, int categoryValue,
182 ent.proto = PROTO_Z3950;
183 ent.oclass = CLASS_USERINFO;
184 ent.value = (oid_value) oidval;
185 if (!oid_ent_to_oid (&ent, oid))
187 yaz_oi_set_string_oid(otherInformation,
188 odr, oid, categoryValue, str);
191 char *yaz_oi_get_string_oid (
192 Z_OtherInformation **otherInformation,
193 int *oid, int categoryValue, int delete_flag)
195 Z_OtherInformationUnit *oi;
197 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1, delete_flag)) &&
198 oi->which == Z_OtherInfo_characterInfo)
199 return oi->information.characterInfo;
203 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
204 int oidval, int categoryValue, int delete_flag)
208 ent.proto = PROTO_Z3950;
209 ent.oclass = CLASS_USERINFO;
210 ent.value = (oid_value) oidval;
212 if (!oid_ent_to_oid (&ent, oid))
214 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,