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.4 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.3 1999/11/10 09:06:40 adam
11 * Fixed yaz_oi_update so that it ignores NULL pointer.
13 * Revision 1.2 1999/09/13 12:51:35 adam
14 * Fixed bug in yaz_oi_update and added delete option.
16 * Revision 1.1 1999/06/08 10:10:16 adam
17 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
19 * Revision 1.1 1999/04/26 07:25:25 adam
20 * Implemented OtherInfo utility.
27 #include <yaz/otherinfo.h>
29 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
33 case Z_APDU_initRequest:
34 *oip = &apdu->u.initRequest->otherInfo;
36 case Z_APDU_searchRequest:
37 *oip = &apdu->u.searchRequest->otherInfo;
39 case Z_APDU_presentRequest:
40 *oip = &apdu->u.presentRequest->otherInfo;
42 case Z_APDU_sortRequest:
43 *oip = &apdu->u.sortRequest->otherInfo;
45 case Z_APDU_scanRequest:
46 *oip = &apdu->u.scanRequest->otherInfo;
48 case Z_APDU_extendedServicesRequest:
49 *oip = &apdu->u.extendedServicesRequest->otherInfo;
51 case Z_APDU_deleteResultSetRequest:
52 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
54 case Z_APDU_initResponse:
55 *oip = &apdu->u.initResponse->otherInfo;
57 case Z_APDU_searchResponse:
58 *oip = &apdu->u.searchResponse->otherInfo;
60 case Z_APDU_presentResponse:
61 *oip = &apdu->u.presentResponse->otherInfo;
63 case Z_APDU_sortResponse:
64 *oip = &apdu->u.sortResponse->otherInfo;
66 case Z_APDU_scanResponse:
67 *oip = &apdu->u.scanResponse->otherInfo;
69 case Z_APDU_extendedServicesResponse:
70 *oip = &apdu->u.extendedServicesResponse->otherInfo;
72 case Z_APDU_deleteResultSetResponse:
73 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
81 Z_OtherInformationUnit *yaz_oi_update (
82 Z_OtherInformation **otherInformationP, ODR odr,
83 int *oid, int categoryValue, int delete_flag)
86 Z_OtherInformation *otherInformation;
88 if (!otherInformationP)
90 otherInformation = *otherInformationP;
91 if (!otherInformation)
95 otherInformation = *otherInformationP = (Z_OtherInformation *)
96 odr_malloc (odr, sizeof(*otherInformation));
97 otherInformation->num_elements = 0;
98 otherInformation->list = 0;
100 for (i = 0; i<otherInformation->num_elements; i++)
104 if (!otherInformation->list[i]->category)
105 return otherInformation->list[i];
109 if (otherInformation->list[i]->category &&
111 *otherInformation->list[i]->category->categoryValue &&
112 !oid_oidcmp (oid, otherInformation->list[i]->category->
115 Z_OtherInformationUnit *this_list = otherInformation->list[i];
119 (otherInformation->num_elements)--;
120 while (i < otherInformation->num_elements)
122 otherInformation->list[i] =
123 otherInformation->list[i+1];
135 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
136 odr_malloc(odr, (otherInformation->num_elements+1) *
138 for (i = 0; i<otherInformation->num_elements; i++)
139 newlist[i] = otherInformation->list[i];
140 otherInformation->list = newlist;
142 otherInformation->list[i] = (Z_OtherInformationUnit*)
143 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
146 otherInformation->list[i]->category = (Z_InfoCategory*)
147 odr_malloc (odr, sizeof(Z_InfoCategory));
148 otherInformation->list[i]->category->categoryTypeId = (int*)
149 odr_oiddup (odr, oid);
150 otherInformation->list[i]->category->categoryValue = (int*)
151 odr_malloc (odr, sizeof(int));
152 *otherInformation->list[i]->category->categoryValue =
156 otherInformation->list[i]->category = 0;
157 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
158 otherInformation->list[i]->information.characterInfo = 0;
160 otherInformation->num_elements = i+1;
161 return otherInformation->list[i];
165 void yaz_oi_set_string_oid (
166 Z_OtherInformation **otherInformation, ODR odr,
167 int *oid, int categoryValue,
170 Z_OtherInformationUnit *oi =
171 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
174 oi->which = Z_OtherInfo_characterInfo;
175 oi->information.characterInfo = odr_strdup (odr, str);
178 void yaz_oi_set_string_oidval (
179 Z_OtherInformation **otherInformation, ODR odr,
180 int oidval, int categoryValue,
185 ent.proto = PROTO_Z3950;
186 ent.oclass = CLASS_USERINFO;
187 ent.value = (oid_value) oidval;
188 if (!oid_ent_to_oid (&ent, oid))
190 yaz_oi_set_string_oid(otherInformation,
191 odr, oid, categoryValue, str);
194 char *yaz_oi_get_string_oid (
195 Z_OtherInformation **otherInformation,
196 int *oid, int categoryValue, int delete_flag)
198 Z_OtherInformationUnit *oi;
200 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1, delete_flag)) &&
201 oi->which == Z_OtherInfo_characterInfo)
202 return oi->information.characterInfo;
206 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
207 int oidval, int categoryValue, int delete_flag)
211 ent.proto = PROTO_Z3950;
212 ent.oclass = CLASS_USERINFO;
213 ent.value = (oid_value) oidval;
215 if (!oid_ent_to_oid (&ent, oid))
217 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,