1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * comtypes.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | #include "comtypes.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | text_t get_comerror_string (comerror_t err) {
|
---|
30 | if (err == noError) return "no error";
|
---|
31 | else if (err == authenticationFailure) return "authentication failure";
|
---|
32 | else if (err == protocolError) return "protocol error";
|
---|
33 | else if (err == configurationError) return "configuration error";
|
---|
34 | else if (err == systemProblem) return "system problem";
|
---|
35 | else if (err == syntaxError) return "query syntax error";
|
---|
36 | return "unknown problem";
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | void ShortColInfo_t::clear() {
|
---|
41 | name.clear();
|
---|
42 | host.clear();
|
---|
43 | port = 0;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /*
|
---|
47 | isPublic now defaults to true most values are default
|
---|
48 | similar to a constructor in a class to make some initializations
|
---|
49 | */
|
---|
50 |
|
---|
51 | void ColInfoResponse_t::clear () {
|
---|
52 | shortInfo.clear();
|
---|
53 | isPublic=true;
|
---|
54 | isBeta=false;
|
---|
55 | languages.erase(languages.begin(), languages.end());
|
---|
56 | ccsCols.erase(ccsCols.begin(), ccsCols.end());
|
---|
57 | buildDate=0;
|
---|
58 | buildType.clear();
|
---|
59 | searchTypes.erase(searchTypes.begin(), searchTypes.end());
|
---|
60 | numDocs=0;
|
---|
61 | numSections=0;
|
---|
62 | numWords=0;
|
---|
63 | numBytes=0;
|
---|
64 | format.erase(format.begin(), format.end());
|
---|
65 | building.erase(format.begin(), format.end());
|
---|
66 | httpdomain.clear();
|
---|
67 | httpprefix.clear();
|
---|
68 | receptionist.clear();
|
---|
69 |
|
---|
70 | // Setting some authentication parameters use with
|
---|
71 | // various parts of the code.
|
---|
72 |
|
---|
73 | auth_collection.clear(); // turned off by default, individual collection authentication
|
---|
74 | auth_group.clear(); // turned off by default, authentication by groups method
|
---|
75 | allow_acls= false; // turned off by default, our ACL switch either on or off in collect.cfg
|
---|
76 | allowallexcept.clear(); // turned off by default, our allow-all-except <grouplist>
|
---|
77 | denyallexcept.clear(); // turned off by default, out deny-all-except <grouplist>
|
---|
78 |
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 | void InfoFiltersResponse_t::clear () {
|
---|
83 | filterNames.erase(filterNames.begin(), filterNames.end());
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | void InfoFilterOptionsRequest_t::clear () {
|
---|
88 | filterName.clear();
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | void FilterOption_t::clear () {
|
---|
93 | name.clear();
|
---|
94 | type = booleant;
|
---|
95 | repeatable = onePerQuery;
|
---|
96 | defaultValue.clear();
|
---|
97 | validValues.erase(validValues.begin(), validValues.end());
|
---|
98 | }
|
---|
99 |
|
---|
100 | void FilterOption_t::check_defaultValue () {
|
---|
101 | text_tarray::iterator here, end;
|
---|
102 |
|
---|
103 | // how the default is interpreted depends on the option type
|
---|
104 | switch (type) {
|
---|
105 | case booleant:
|
---|
106 | case enumeratedt: // has to be one of the validValues
|
---|
107 | here = validValues.begin ();
|
---|
108 | end = validValues.end ();
|
---|
109 | while (here != end) {
|
---|
110 | if (*here == defaultValue) return;
|
---|
111 | here++;
|
---|
112 | }
|
---|
113 |
|
---|
114 | break;
|
---|
115 |
|
---|
116 | case integert: // has to be in the validValues range
|
---|
117 | if ((validValues.size() >= 2) &&
|
---|
118 | (validValues[0].getint() <= defaultValue.getint()) &&
|
---|
119 | (validValues[1].getint() >= defaultValue.getint()))
|
---|
120 | return;
|
---|
121 | break;
|
---|
122 |
|
---|
123 | case stringt: // any value is valid
|
---|
124 | return;
|
---|
125 | }
|
---|
126 |
|
---|
127 | // did not find the defaultValue
|
---|
128 | if (validValues.empty()) defaultValue.clear();
|
---|
129 | else defaultValue = validValues[0];
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
134 | return ((x.name == y.name) &&
|
---|
135 | (x.type == y.type) &&
|
---|
136 | (x.repeatable == y.repeatable) &&
|
---|
137 | (x.defaultValue == y.defaultValue) &&
|
---|
138 | (x.validValues == y.validValues));
|
---|
139 | }
|
---|
140 |
|
---|
141 | bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
142 | return ((x.name < y.name) ||
|
---|
143 | ((x.name == y.name) &&
|
---|
144 | ((x.type < y.type) ||
|
---|
145 | ((x.type == y.type) &&
|
---|
146 | ((x.repeatable < y.repeatable) ||
|
---|
147 | ((x.repeatable == y.repeatable) &&
|
---|
148 | ((x.defaultValue < y.defaultValue) ||
|
---|
149 | ((x.defaultValue == y.defaultValue) &&
|
---|
150 | (x.validValues < y.validValues)))))))));
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 | void InfoFilterOptionsResponse_t::clear () {
|
---|
156 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | void OptionValue_t::clear () {
|
---|
161 | name.clear();
|
---|
162 | value.clear();
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | void FilterRequest_t::clear () {
|
---|
167 | filterName.clear();
|
---|
168 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
169 | docSet.erase(docSet.begin(), docSet.end());
|
---|
170 | filterResultOptions = 0;
|
---|
171 | requestParams.clear();
|
---|
172 | refParams.clear();
|
---|
173 | fields.erase(fields.begin(), fields.end());
|
---|
174 | getParents = false;
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | void TermInfo_t::clear () {
|
---|
179 | term.clear();
|
---|
180 | freq = 0;
|
---|
181 | matchTerms.erase (matchTerms.begin(), matchTerms.end());
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | void MetadataInfo_t::clear () {
|
---|
186 | params.clear();
|
---|
187 | isRef = false;
|
---|
188 | values.erase(values.begin(), values.end());
|
---|
189 | if (parent != NULL) {
|
---|
190 | delete parent;
|
---|
191 | parent = NULL;
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
|
---|
196 |
|
---|
197 | // copy constructor
|
---|
198 | MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
|
---|
199 | params = x.params;
|
---|
200 | isRef = x.isRef;
|
---|
201 | values = x.values;
|
---|
202 | if (x.parent == NULL) parent = NULL;
|
---|
203 | else {
|
---|
204 | parent = new MetadataInfo_t ();
|
---|
205 | *parent = *(x.parent);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | MetadataInfo_t::~MetadataInfo_t () {
|
---|
210 | if (parent != NULL) {
|
---|
211 | delete parent;
|
---|
212 | parent = NULL;
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
|
---|
217 | if (&x != this) {
|
---|
218 | params = x.params;
|
---|
219 | isRef = x.isRef;
|
---|
220 | values = x.values;
|
---|
221 | if (x.parent == NULL) parent = NULL;
|
---|
222 | else {
|
---|
223 | parent = new MetadataInfo_t ();
|
---|
224 | *parent = *(x.parent);
|
---|
225 | }
|
---|
226 | }
|
---|
227 | return *this;
|
---|
228 | }
|
---|
229 |
|
---|
230 | void ResultDocInfo_t::clear () {
|
---|
231 | OID.clear ();
|
---|
232 | ranking = 0;
|
---|
233 | result_num = 0;
|
---|
234 | num_terms_matched = 0;
|
---|
235 | num_phrase_match = 0;
|
---|
236 | docFreq.erase(docFreq.begin(), docFreq.end());
|
---|
237 | metadata.erase(metadata.begin(), metadata.end());
|
---|
238 | classifier_metadata_type.erase(classifier_metadata_type.begin(),
|
---|
239 | classifier_metadata_type.end());
|
---|
240 | classifier_metadata_offset = 0;
|
---|
241 |
|
---|
242 | }
|
---|
243 |
|
---|
244 | ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
|
---|
245 | OID = x.OID;
|
---|
246 | ranking = x.ranking;
|
---|
247 | result_num = x.result_num;
|
---|
248 | num_terms_matched = x.num_terms_matched;
|
---|
249 | num_phrase_match = x.num_phrase_match;
|
---|
250 | docFreq = x.docFreq;
|
---|
251 | metadata = x.metadata;
|
---|
252 | return *this;
|
---|
253 | }
|
---|
254 |
|
---|
255 | void FilterResponse_t::clear () {
|
---|
256 | numDocs = 0;
|
---|
257 | isApprox = Exact;
|
---|
258 | termInfo.erase (termInfo.begin(), termInfo.end());
|
---|
259 | docInfo.erase (docInfo.begin(), docInfo.end());
|
---|
260 | }
|
---|
261 |
|
---|
262 | FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
|
---|
263 | numDocs = x.numDocs;
|
---|
264 | isApprox = x.isApprox;
|
---|
265 | termInfo = x.termInfo;
|
---|
266 | docInfo = x.docInfo;
|
---|
267 | return *this;
|
---|
268 | }
|
---|
269 |
|
---|
270 | void DocumentRequest_t::clear () {
|
---|
271 | OID.clear();
|
---|
272 | docType.clear();
|
---|
273 | docFormat.clear();
|
---|
274 | }
|
---|
275 |
|
---|
276 | void DocumentResponse_t::clear () {
|
---|
277 | doc.clear();
|
---|
278 | }
|
---|