source: trunk/gsdl/packages/yaz/zutil/otherinfo.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/*
2 * Copyright (c) 1999, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
5 *
6 * $Log$
7 * Revision 1.1 2000/08/03 03:12:36 johnmcp
8 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
9 *
10 * Revision 1.4 1999/11/30 13:47:12 adam
11 * Improved installation. Moved header files to include/yaz.
12 *
13 * Revision 1.3 1999/11/10 09:06:40 adam
14 * Fixed yaz_oi_update so that it ignores NULL pointer.
15 *
16 * Revision 1.2 1999/09/13 12:51:35 adam
17 * Fixed bug in yaz_oi_update and added delete option.
18 *
19 * Revision 1.1 1999/06/08 10:10:16 adam
20 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
21 *
22 * Revision 1.1 1999/04/26 07:25:25 adam
23 * Implemented OtherInfo utility.
24 *
25 */
26
27#include <stdio.h>
28#include <string.h>
29
30#include <yaz/otherinfo.h>
31
32void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
33{
34 switch (apdu->which)
35 {
36 case Z_APDU_initRequest:
37 *oip = &apdu->u.initRequest->otherInfo;
38 break;
39 case Z_APDU_searchRequest:
40 *oip = &apdu->u.searchRequest->otherInfo;
41 break;
42 case Z_APDU_presentRequest:
43 *oip = &apdu->u.presentRequest->otherInfo;
44 break;
45 case Z_APDU_sortRequest:
46 *oip = &apdu->u.sortRequest->otherInfo;
47 break;
48 case Z_APDU_scanRequest:
49 *oip = &apdu->u.scanRequest->otherInfo;
50 break;
51 case Z_APDU_extendedServicesRequest:
52 *oip = &apdu->u.extendedServicesRequest->otherInfo;
53 break;
54 case Z_APDU_deleteResultSetRequest:
55 *oip = &apdu->u.deleteResultSetRequest->otherInfo;
56 break;
57 case Z_APDU_initResponse:
58 *oip = &apdu->u.initResponse->otherInfo;
59 break;
60 case Z_APDU_searchResponse:
61 *oip = &apdu->u.searchResponse->otherInfo;
62 break;
63 case Z_APDU_presentResponse:
64 *oip = &apdu->u.presentResponse->otherInfo;
65 break;
66 case Z_APDU_sortResponse:
67 *oip = &apdu->u.sortResponse->otherInfo;
68 break;
69 case Z_APDU_scanResponse:
70 *oip = &apdu->u.scanResponse->otherInfo;
71 break;
72 case Z_APDU_extendedServicesResponse:
73 *oip = &apdu->u.extendedServicesResponse->otherInfo;
74 break;
75 case Z_APDU_deleteResultSetResponse:
76 *oip = &apdu->u.deleteResultSetResponse->otherInfo;
77 break;
78 default:
79 *oip = 0;
80 break;
81 }
82}
83
84Z_OtherInformationUnit *yaz_oi_update (
85 Z_OtherInformation **otherInformationP, ODR odr,
86 int *oid, int categoryValue, int delete_flag)
87{
88 int i;
89 Z_OtherInformation *otherInformation;
90
91 if (!otherInformationP)
92 return 0;
93 otherInformation = *otherInformationP;
94 if (!otherInformation)
95 {
96 if (!odr)
97 return 0;
98 otherInformation = *otherInformationP = (Z_OtherInformation *)
99 odr_malloc (odr, sizeof(*otherInformation));
100 otherInformation->num_elements = 0;
101 otherInformation->list = 0;
102 }
103 for (i = 0; i<otherInformation->num_elements; i++)
104 {
105 if (!oid)
106 {
107 if (!otherInformation->list[i]->category)
108 return otherInformation->list[i];
109 }
110 else
111 {
112 if (otherInformation->list[i]->category &&
113 categoryValue ==
114 *otherInformation->list[i]->category->categoryValue &&
115 !oid_oidcmp (oid, otherInformation->list[i]->category->
116 categoryTypeId))
117 {
118 Z_OtherInformationUnit *this_list = otherInformation->list[i];
119
120 if (delete_flag)
121 {
122 (otherInformation->num_elements)--;
123 while (i < otherInformation->num_elements)
124 {
125 otherInformation->list[i] =
126 otherInformation->list[i+1];
127 i++;
128 }
129 }
130 return this_list;
131 }
132 }
133 }
134 if (!odr)
135 return 0;
136 else
137 {
138 Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
139 odr_malloc(odr, (otherInformation->num_elements+1) *
140 sizeof(*newlist));
141 for (i = 0; i<otherInformation->num_elements; i++)
142 newlist[i] = otherInformation->list[i];
143 otherInformation->list = newlist;
144
145 otherInformation->list[i] = (Z_OtherInformationUnit*)
146 odr_malloc (odr, sizeof(Z_OtherInformationUnit));
147 if (oid)
148 {
149 otherInformation->list[i]->category = (Z_InfoCategory*)
150 odr_malloc (odr, sizeof(Z_InfoCategory));
151 otherInformation->list[i]->category->categoryTypeId = (int*)
152 odr_oiddup (odr, oid);
153 otherInformation->list[i]->category->categoryValue = (int*)
154 odr_malloc (odr, sizeof(int));
155 *otherInformation->list[i]->category->categoryValue =
156 categoryValue;
157 }
158 else
159 otherInformation->list[i]->category = 0;
160 otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
161 otherInformation->list[i]->information.characterInfo = 0;
162
163 otherInformation->num_elements = i+1;
164 return otherInformation->list[i];
165 }
166}
167
168void yaz_oi_set_string_oid (
169 Z_OtherInformation **otherInformation, ODR odr,
170 int *oid, int categoryValue,
171 const char *str)
172{
173 Z_OtherInformationUnit *oi =
174 yaz_oi_update(otherInformation, odr, oid, categoryValue, 0);
175 if (!oi)
176 return;
177 oi->which = Z_OtherInfo_characterInfo;
178 oi->information.characterInfo = odr_strdup (odr, str);
179}
180
181void yaz_oi_set_string_oidval (
182 Z_OtherInformation **otherInformation, ODR odr,
183 int oidval, int categoryValue,
184 const char *str)
185{
186 int oid[OID_SIZE];
187 struct oident ent;
188 ent.proto = PROTO_Z3950;
189 ent.oclass = CLASS_USERINFO;
190 ent.value = (oid_value) oidval;
191 if (!oid_ent_to_oid (&ent, oid))
192 return ;
193 yaz_oi_set_string_oid(otherInformation,
194 odr, oid, categoryValue, str);
195}
196
197char *yaz_oi_get_string_oid (
198 Z_OtherInformation **otherInformation,
199 int *oid, int categoryValue, int delete_flag)
200{
201 Z_OtherInformationUnit *oi;
202
203 if ((oi = yaz_oi_update(otherInformation, 0, oid, 1, delete_flag)) &&
204 oi->which == Z_OtherInfo_characterInfo)
205 return oi->information.characterInfo;
206 return 0;
207}
208
209char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
210 int oidval, int categoryValue, int delete_flag)
211{
212 int oid[OID_SIZE];
213 struct oident ent;
214 ent.proto = PROTO_Z3950;
215 ent.oclass = CLASS_USERINFO;
216 ent.value = (oid_value) oidval;
217
218 if (!oid_ent_to_oid (&ent, oid))
219 return 0;
220 return yaz_oi_get_string_oid (otherInformation, oid, categoryValue,
221 delete_flag);
222}
223
Note: See TracBrowser for help on using the repository browser.