2 * Copyright (c) 1999-2001, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: otherinfo.c,v $
7 * Revision 1.5 2001-09-24 21:51:56 adam
8 * New Z39.50 OID utilities: yaz_oidval_to_z3950oid, yaz_str_to_z3950oid
9 * and yaz_z3950oid_to_str.
11 * Revision 1.4 1999/11/30 13:47:12 adam
12 * Improved installation. Moved header files to include/yaz.
14 * Revision 1.3 1999/11/10 09:06:40 adam
15 * Fixed yaz_oi_update so that it ignores NULL pointer.
17 * Revision 1.2 1999/09/13 12:51:35 adam
18 * Fixed bug in yaz_oi_update and added delete option.
20 * Revision 1.1 1999/06/08 10:10:16 adam
21 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
23 * Revision 1.1 1999/04/26 07:25:25 adam
24 * Implemented OtherInfo utility.
31 #include <yaz/otherinfo.h>
33 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
37 case Z_APDU_initRequest:
38 *oip = &apdu->u.initRequest->otherInfo;
40 case Z_APDU_searchRequest:
41 *oip = &apdu->u.searchRequest->otherInfo;
43 case Z_APDU_presentRequest:
44 *oip = &apdu->u.presentRequest->otherInfo;
46 case Z_APDU_sortRequest:
47 *oip = &apdu->u.sortRequest->otherInfo;
49 case Z_APDU_scanRequest:
50 *oip = &apdu->u.scanRequest->otherInfo;
52 case Z_APDU_extendedServicesRequest:
53 *oip = &apdu->u.extendedServicesRequest->otherInfo;
55 case Z_APDU_deleteResultSetRequest:
56 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
58 case Z_APDU_initResponse:
59 *oip = &apdu->u.initResponse->otherInfo;
61 case Z_APDU_searchResponse:
62 *oip = &apdu->u.searchResponse->otherInfo;
64 case Z_APDU_presentResponse:
65 *oip = &apdu->u.presentResponse->otherInfo;
67 case Z_APDU_sortResponse:
68 *oip = &apdu->u.sortResponse->otherInfo;
70 case Z_APDU_scanResponse:
71 *oip = &apdu->u.scanResponse->otherInfo;
73 case Z_APDU_extendedServicesResponse:
74 *oip = &apdu->u.extendedServicesResponse->otherInfo;
76 case Z_APDU_deleteResultSetResponse:
77 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
85 Z_OtherInformationUnit *yaz_oi_update (
86 Z_OtherInformation **otherInformationP, ODR odr,
87 int *oid, int categoryValue, int delete_flag)
90 Z_OtherInformation *otherInformation;
92 if (!otherInformationP)
94 otherInformation = *otherInformationP;
95 if (!otherInformation)
99 otherInformation = *otherInformationP = (Z_OtherInformation *)
100 odr_malloc (odr, sizeof(*otherInformation));
101 otherInformation->num_elements = 0;
102 otherInformation->list = 0;
104 for (i = 0; i<otherInformation->num_elements; i++)
108 if (!otherInformation->list[i]->category)
109 return otherInformation->list[i];
113 if (otherInformation->list[i]->category &&
115 *otherInformation->list[i]->category->categoryValue &&
116 !oid_oidcmp (oid, otherInformation->list[i]->category->
119 Z_OtherInformationUnit *this_list = otherInformation->list[i];
123 (otherInformation->num_elements)--;
124 while (i < otherInformation->num_elements)
126 otherInformation->list[i] =
127 otherInformation->list[i+1];
139 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
140 odr_malloc(odr, (otherInformation->num_elements+1) *
142 for (i = 0; i<otherInformation->num_elements; i++)
143 newlist[i] = otherInformation->list[i];
144 otherInformation->list = newlist;
146 otherInformation->list[i] = (Z_OtherInformationUnit*)
147 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
150 otherInformation->list[i]->category = (Z_InfoCategory*)
151 odr_malloc (odr, sizeof(Z_InfoCategory));
152 otherInformation->list[i]->category->categoryTypeId = (int*)
153 odr_oiddup (odr, oid);
154 otherInformation->list[i]->category->categoryValue = (int*)
155 odr_malloc (odr, sizeof(int));
156 *otherInformation->list[i]->category->categoryValue =
160 otherInformation->list[i]->category = 0;
161 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
162 otherInformation->list[i]->information.characterInfo = 0;
164 otherInformation->num_elements = i+1;
165 return otherInformation->list[i];
169 void yaz_oi_set_string_oid (
170 Z_OtherInformation **otherInformation, ODR odr,
171 int *oid, int categoryValue,
174 Z_OtherInformationUnit *oi =
175 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
178 oi->which = Z_OtherInfo_characterInfo;
179 oi->information.characterInfo = odr_strdup (odr, str);
182 void yaz_oi_set_string_oidval (
183 Z_OtherInformation **otherInformation, ODR odr,
184 int oidval, int categoryValue,
189 ent.proto = PROTO_Z3950;
190 ent.oclass = CLASS_USERINFO;
191 ent.value = (oid_value) oidval;
192 if (!oid_ent_to_oid (&ent, oid))
194 yaz_oi_set_string_oid(otherInformation,
195 odr, oid, categoryValue, str);
198 char *yaz_oi_get_string_oid (
199 Z_OtherInformation **otherInformation,
200 int *oid, int categoryValue, int delete_flag)
202 Z_OtherInformationUnit *oi;
204 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1, delete_flag)) &&
205 oi->which == Z_OtherInfo_characterInfo)
206 return oi->information.characterInfo;
210 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
211 int oidval, int categoryValue, int delete_flag)
215 ent.proto = PROTO_Z3950;
216 ent.oclass = CLASS_USERINFO;
217 ent.value = (oid_value) oidval;
219 if (!oid_ent_to_oid (&ent, oid))
221 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,