1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements Z39.50 OtherInfo utilities
16 #include <yaz/otherinfo.h>
18 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
22 case Z_APDU_initRequest:
23 *oip = &apdu->u.initRequest->otherInfo;
25 case Z_APDU_searchRequest:
26 *oip = &apdu->u.searchRequest->otherInfo;
28 case Z_APDU_presentRequest:
29 *oip = &apdu->u.presentRequest->otherInfo;
31 case Z_APDU_sortRequest:
32 *oip = &apdu->u.sortRequest->otherInfo;
34 case Z_APDU_scanRequest:
35 *oip = &apdu->u.scanRequest->otherInfo;
37 case Z_APDU_extendedServicesRequest:
38 *oip = &apdu->u.extendedServicesRequest->otherInfo;
40 case Z_APDU_deleteResultSetRequest:
41 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
43 case Z_APDU_initResponse:
44 *oip = &apdu->u.initResponse->otherInfo;
46 case Z_APDU_searchResponse:
47 *oip = &apdu->u.searchResponse->otherInfo;
49 case Z_APDU_presentResponse:
50 *oip = &apdu->u.presentResponse->otherInfo;
52 case Z_APDU_sortResponse:
53 *oip = &apdu->u.sortResponse->otherInfo;
55 case Z_APDU_scanResponse:
56 *oip = &apdu->u.scanResponse->otherInfo;
58 case Z_APDU_extendedServicesResponse:
59 *oip = &apdu->u.extendedServicesResponse->otherInfo;
61 case Z_APDU_deleteResultSetResponse:
62 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
64 case Z_APDU_duplicateDetectionRequest:
65 *oip = &apdu->u.duplicateDetectionRequest->otherInfo;
67 case Z_APDU_duplicateDetectionResponse:
68 *oip = &apdu->u.duplicateDetectionResponse->otherInfo;
76 Z_OtherInformationUnit *yaz_oi_update(
77 Z_OtherInformation **otherInformationP, ODR odr,
78 const Odr_oid *oid, int categoryValue, int delete_flag)
81 Z_OtherInformation *otherInformation;
83 if (!otherInformationP)
85 otherInformation = *otherInformationP;
86 if (!otherInformation)
90 otherInformation = *otherInformationP = (Z_OtherInformation *)
91 odr_malloc (odr, sizeof(*otherInformation));
92 otherInformation->num_elements = 0;
93 otherInformation->list = 0;
95 for (i = 0; i<otherInformation->num_elements; i++)
99 /* DS: Want does this do? Returns the first element without a category */
100 if (!otherInformation->list[i]->category)
101 return otherInformation->list[i];
105 if (otherInformation->list[i]->category &&
107 *otherInformation->list[i]->category->categoryValue &&
108 !oid_oidcmp (oid, otherInformation->list[i]->category->
111 Z_OtherInformationUnit *this_list = otherInformation->list[i];
115 (otherInformation->num_elements)--;
116 while (i < otherInformation->num_elements)
118 otherInformation->list[i] =
119 otherInformation->list[i+1];
131 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
132 odr_malloc(odr, (otherInformation->num_elements+1) *
134 for (i = 0; i<otherInformation->num_elements; i++)
135 newlist[i] = otherInformation->list[i];
136 otherInformation->list = newlist;
138 otherInformation->list[i] = (Z_OtherInformationUnit*)
139 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
142 otherInformation->list[i]->category = (Z_InfoCategory*)
143 odr_malloc (odr, sizeof(Z_InfoCategory));
144 otherInformation->list[i]->category->categoryTypeId = (Odr_oid*)
145 odr_oiddup (odr, oid);
146 otherInformation->list[i]->category->categoryValue =
147 odr_intdup(odr, categoryValue);
150 otherInformation->list[i]->category = 0;
151 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
152 otherInformation->list[i]->information.characterInfo = 0;
154 otherInformation->num_elements = i+1;
155 return otherInformation->list[i];
159 void yaz_oi_set_string_oid (
160 Z_OtherInformation **otherInformation, ODR odr,
161 const Odr_oid *oid, int categoryValue,
164 Z_OtherInformationUnit *oi =
165 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
168 oi->which = Z_OtherInfo_characterInfo;
169 oi->information.characterInfo = odr_strdup (odr, str);
172 char *yaz_oi_get_string_oid (
173 Z_OtherInformation **otherInformation,
174 const Odr_oid *oid, int categoryValue, int delete_flag)
176 Z_OtherInformationUnit *oi;
178 if ((oi = yaz_oi_update(otherInformation, 0, oid, categoryValue,
180 oi->which == Z_OtherInfo_characterInfo)
181 return oi->information.characterInfo;
189 * c-file-style: "Stroustrup"
190 * indent-tabs-mode: nil
192 * vim: shiftwidth=4 tabstop=8 expandtab