1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements Z39.50 OtherInfo utilities
12 #include <yaz/otherinfo.h>
14 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
18 case Z_APDU_initRequest:
19 *oip = &apdu->u.initRequest->otherInfo;
21 case Z_APDU_searchRequest:
22 *oip = &apdu->u.searchRequest->otherInfo;
24 case Z_APDU_presentRequest:
25 *oip = &apdu->u.presentRequest->otherInfo;
27 case Z_APDU_sortRequest:
28 *oip = &apdu->u.sortRequest->otherInfo;
30 case Z_APDU_scanRequest:
31 *oip = &apdu->u.scanRequest->otherInfo;
33 case Z_APDU_extendedServicesRequest:
34 *oip = &apdu->u.extendedServicesRequest->otherInfo;
36 case Z_APDU_deleteResultSetRequest:
37 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
39 case Z_APDU_initResponse:
40 *oip = &apdu->u.initResponse->otherInfo;
42 case Z_APDU_searchResponse:
43 *oip = &apdu->u.searchResponse->otherInfo;
45 case Z_APDU_presentResponse:
46 *oip = &apdu->u.presentResponse->otherInfo;
48 case Z_APDU_sortResponse:
49 *oip = &apdu->u.sortResponse->otherInfo;
51 case Z_APDU_scanResponse:
52 *oip = &apdu->u.scanResponse->otherInfo;
54 case Z_APDU_extendedServicesResponse:
55 *oip = &apdu->u.extendedServicesResponse->otherInfo;
57 case Z_APDU_deleteResultSetResponse:
58 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
60 case Z_APDU_duplicateDetectionRequest:
61 *oip = &apdu->u.duplicateDetectionRequest->otherInfo;
63 case Z_APDU_duplicateDetectionResponse:
64 *oip = &apdu->u.duplicateDetectionResponse->otherInfo;
72 Z_OtherInformationUnit *yaz_oi_update (
73 Z_OtherInformation **otherInformationP, ODR odr,
74 const Odr_oid *oid, int categoryValue, int delete_flag)
77 Z_OtherInformation *otherInformation;
79 if (!otherInformationP)
81 otherInformation = *otherInformationP;
82 if (!otherInformation)
86 otherInformation = *otherInformationP = (Z_OtherInformation *)
87 odr_malloc (odr, sizeof(*otherInformation));
88 otherInformation->num_elements = 0;
89 otherInformation->list = 0;
91 for (i = 0; i<otherInformation->num_elements; i++)
95 if (!otherInformation->list[i]->category)
96 return otherInformation->list[i];
100 if (otherInformation->list[i]->category &&
102 *otherInformation->list[i]->category->categoryValue &&
103 !oid_oidcmp (oid, otherInformation->list[i]->category->
106 Z_OtherInformationUnit *this_list = otherInformation->list[i];
110 (otherInformation->num_elements)--;
111 while (i < otherInformation->num_elements)
113 otherInformation->list[i] =
114 otherInformation->list[i+1];
126 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
127 odr_malloc(odr, (otherInformation->num_elements+1) *
129 for (i = 0; i<otherInformation->num_elements; i++)
130 newlist[i] = otherInformation->list[i];
131 otherInformation->list = newlist;
133 otherInformation->list[i] = (Z_OtherInformationUnit*)
134 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
137 otherInformation->list[i]->category = (Z_InfoCategory*)
138 odr_malloc (odr, sizeof(Z_InfoCategory));
139 otherInformation->list[i]->category->categoryTypeId = (Odr_oid*)
140 odr_oiddup (odr, oid);
141 otherInformation->list[i]->category->categoryValue =
142 odr_intdup(odr, categoryValue);
145 otherInformation->list[i]->category = 0;
146 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
147 otherInformation->list[i]->information.characterInfo = 0;
149 otherInformation->num_elements = i+1;
150 return otherInformation->list[i];
154 void yaz_oi_set_string_oid (
155 Z_OtherInformation **otherInformation, ODR odr,
156 const Odr_oid *oid, int categoryValue,
159 Z_OtherInformationUnit *oi =
160 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
163 oi->which = Z_OtherInfo_characterInfo;
164 oi->information.characterInfo = odr_strdup (odr, str);
167 char *yaz_oi_get_string_oid (
168 Z_OtherInformation **otherInformation,
169 const Odr_oid *oid, int categoryValue, int delete_flag)
171 Z_OtherInformationUnit *oi;
173 if ((oi = yaz_oi_update(otherInformation, 0, oid, categoryValue,
175 oi->which == Z_OtherInfo_characterInfo)
176 return oi->information.characterInfo;
183 * indent-tabs-mode: nil
185 * vim: shiftwidth=4 tabstop=8 expandtab