2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: otherinfo.c,v 1.5 2006-01-16 15:53:28 adam Exp $
9 * \brief Implements Z39.50 OtherInfo utilities
14 #include <yaz/otherinfo.h>
16 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
20 case Z_APDU_initRequest:
21 *oip = &apdu->u.initRequest->otherInfo;
23 case Z_APDU_searchRequest:
24 *oip = &apdu->u.searchRequest->otherInfo;
26 case Z_APDU_presentRequest:
27 *oip = &apdu->u.presentRequest->otherInfo;
29 case Z_APDU_sortRequest:
30 *oip = &apdu->u.sortRequest->otherInfo;
32 case Z_APDU_scanRequest:
33 *oip = &apdu->u.scanRequest->otherInfo;
35 case Z_APDU_extendedServicesRequest:
36 *oip = &apdu->u.extendedServicesRequest->otherInfo;
38 case Z_APDU_deleteResultSetRequest:
39 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
41 case Z_APDU_initResponse:
42 *oip = &apdu->u.initResponse->otherInfo;
44 case Z_APDU_searchResponse:
45 *oip = &apdu->u.searchResponse->otherInfo;
47 case Z_APDU_presentResponse:
48 *oip = &apdu->u.presentResponse->otherInfo;
50 case Z_APDU_sortResponse:
51 *oip = &apdu->u.sortResponse->otherInfo;
53 case Z_APDU_scanResponse:
54 *oip = &apdu->u.scanResponse->otherInfo;
56 case Z_APDU_extendedServicesResponse:
57 *oip = &apdu->u.extendedServicesResponse->otherInfo;
59 case Z_APDU_deleteResultSetResponse:
60 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
62 case Z_APDU_duplicateDetectionRequest:
63 *oip = &apdu->u.duplicateDetectionRequest->otherInfo;
65 case Z_APDU_duplicateDetectionResponse:
66 *oip = &apdu->u.duplicateDetectionResponse->otherInfo;
74 Z_OtherInformationUnit *yaz_oi_update (
75 Z_OtherInformation **otherInformationP, ODR odr,
76 int *oid, int categoryValue, int delete_flag)
79 Z_OtherInformation *otherInformation;
81 if (!otherInformationP)
83 otherInformation = *otherInformationP;
84 if (!otherInformation)
88 otherInformation = *otherInformationP = (Z_OtherInformation *)
89 odr_malloc (odr, sizeof(*otherInformation));
90 otherInformation->num_elements = 0;
91 otherInformation->list = 0;
93 for (i = 0; i<otherInformation->num_elements; i++)
97 if (!otherInformation->list[i]->category)
98 return otherInformation->list[i];
102 if (otherInformation->list[i]->category &&
104 *otherInformation->list[i]->category->categoryValue &&
105 !oid_oidcmp (oid, otherInformation->list[i]->category->
108 Z_OtherInformationUnit *this_list = otherInformation->list[i];
112 (otherInformation->num_elements)--;
113 while (i < otherInformation->num_elements)
115 otherInformation->list[i] =
116 otherInformation->list[i+1];
128 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
129 odr_malloc(odr, (otherInformation->num_elements+1) *
131 for (i = 0; i<otherInformation->num_elements; i++)
132 newlist[i] = otherInformation->list[i];
133 otherInformation->list = newlist;
135 otherInformation->list[i] = (Z_OtherInformationUnit*)
136 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
139 otherInformation->list[i]->category = (Z_InfoCategory*)
140 odr_malloc (odr, sizeof(Z_InfoCategory));
141 otherInformation->list[i]->category->categoryTypeId = (int*)
142 odr_oiddup (odr, oid);
143 otherInformation->list[i]->category->categoryValue = (int*)
144 odr_malloc (odr, sizeof(int));
145 *otherInformation->list[i]->category->categoryValue =
149 otherInformation->list[i]->category = 0;
150 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
151 otherInformation->list[i]->information.characterInfo = 0;
153 otherInformation->num_elements = i+1;
154 return otherInformation->list[i];
158 void yaz_oi_set_string_oid (
159 Z_OtherInformation **otherInformation, ODR odr,
160 int *oid, int categoryValue,
163 Z_OtherInformationUnit *oi =
164 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
167 oi->which = Z_OtherInfo_characterInfo;
168 oi->information.characterInfo = odr_strdup (odr, str);
171 void yaz_oi_set_string_oidval (
172 Z_OtherInformation **otherInformation, ODR odr,
173 int oidval, int categoryValue,
178 ent.proto = PROTO_Z3950;
179 ent.oclass = CLASS_USERINFO;
180 ent.value = (oid_value) oidval;
181 if (!oid_ent_to_oid (&ent, oid))
183 yaz_oi_set_string_oid(otherInformation,
184 odr, oid, categoryValue, str);
187 char *yaz_oi_get_string_oid (
188 Z_OtherInformation **otherInformation,
189 int *oid, int categoryValue, int delete_flag)
191 Z_OtherInformationUnit *oi;
193 if ((oi = yaz_oi_update(otherInformation, 0, oid, categoryValue,
195 oi->which == Z_OtherInfo_characterInfo)
196 return oi->information.characterInfo;
200 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
201 int oidval, int categoryValue, int delete_flag)
205 ent.proto = PROTO_Z3950;
206 ent.oclass = CLASS_USERINFO;
207 ent.value = (oid_value) oidval;
209 if (!oid_ent_to_oid (&ent, oid))
211 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,
218 * indent-tabs-mode: nil
220 * vim: shiftwidth=4 tabstop=8 expandtab