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.1 1999-04-26 07:25:25 adam
8 * Implemented OtherInfo utility.
15 #include <otherinfo.h>
17 void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
21 case Z_APDU_initRequest:
22 *oip = &apdu->u.initRequest->otherInfo;
24 case Z_APDU_searchRequest:
25 *oip = &apdu->u.searchRequest->otherInfo;
27 case Z_APDU_presentRequest:
28 *oip = &apdu->u.presentRequest->otherInfo;
30 case Z_APDU_sortRequest:
31 *oip = &apdu->u.sortRequest->otherInfo;
33 case Z_APDU_scanRequest:
34 *oip = &apdu->u.scanRequest->otherInfo;
36 case Z_APDU_initResponse:
37 *oip = &apdu->u.initResponse->otherInfo;
39 case Z_APDU_searchResponse:
40 *oip = &apdu->u.searchResponse->otherInfo;
42 case Z_APDU_presentResponse:
43 *oip = &apdu->u.presentResponse->otherInfo;
45 case Z_APDU_sortResponse:
46 *oip = &apdu->u.sortResponse->otherInfo;
48 case Z_APDU_scanResponse:
49 *oip = &apdu->u.scanResponse->otherInfo;
57 Z_OtherInformationUnit *yaz_oi_update (
58 Z_OtherInformation **otherInformationP, ODR odr,
59 int *oid, int categoryValue)
62 Z_OtherInformation *otherInformation = *otherInformationP;
63 if (!otherInformation)
67 otherInformation = *otherInformationP = (Z_OtherInformation *)
68 odr_malloc (odr, sizeof(*otherInformation));
69 otherInformation->num_elements = 0;
70 otherInformation->list = 0;
72 for (i = 0; i<otherInformation->num_elements; i++)
76 if (!otherInformation->list[i]->category)
77 return otherInformation->list[i];
81 if (otherInformation->list[i]->category &&
83 *otherInformation->list[i]->category->categoryValue &&
84 !oid_oidcmp (oid, otherInformation->list[i]->category->
86 return otherInformation->list[i];
93 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
94 odr_malloc(odr, otherInformation->num_elements+1 *
96 for (i = 0; i<otherInformation->num_elements; i++)
97 newlist[i] = otherInformation->list[i];
98 otherInformation->list = newlist;
100 otherInformation->list[i] = (Z_OtherInformationUnit*)
101 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
104 otherInformation->list[i]->category = (Z_InfoCategory*)
105 odr_malloc (odr, sizeof(Z_InfoCategory));
106 otherInformation->list[i]->category->categoryTypeId = (int*)
107 odr_oiddup (odr, oid);
108 otherInformation->list[i]->category->categoryValue = (int*)
109 odr_malloc (odr, sizeof(int));
110 *otherInformation->list[i]->category->categoryValue =
114 otherInformation->list[i]->category = 0;
115 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
116 otherInformation->list[i]->information.characterInfo = 0;
118 otherInformation->num_elements = i+1;
119 return otherInformation->list[i];
123 void yaz_oi_set_string_oid (
124 Z_OtherInformation **otherInformation, ODR odr,
125 int *oid, int categoryValue,
128 Z_OtherInformationUnit *oi =
129 yaz_oi_update(otherInformation, odr, oid, categoryValue);
132 oi->which = Z_OtherInfo_characterInfo;
133 oi->information.characterInfo = odr_strdup (odr, str);
136 void yaz_oi_set_string_oidval (
137 Z_OtherInformation **otherInformation, ODR odr,
138 int oidval, int categoryValue,
143 ent.proto = PROTO_Z3950;
144 ent.oclass = CLASS_USERINFO;
145 ent.value = (oid_value) oidval;
146 if (!oid_ent_to_oid (&ent, oid))
148 yaz_oi_set_string_oid(otherInformation,
149 odr, oid, categoryValue, str);
152 char *yaz_oi_get_string_oid (
153 Z_OtherInformation **otherInformation,
154 int *oid, int categoryValue)
156 Z_OtherInformationUnit *oi;
158 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1)) &&
159 oi->which == Z_OtherInfo_characterInfo)
160 return oi->information.characterInfo;
164 char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
165 int oidval, int categoryValue)
169 ent.proto = PROTO_Z3950;
170 ent.oclass = CLASS_USERINFO;
171 ent.value = (oid_value) oidval;
173 if (!oid_ent_to_oid (&ent, oid))
175 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue);