[166] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * comtypes.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 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.
|
---|
[166] | 9 | *
|
---|
[533] | 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 | *
|
---|
[166] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "comtypes.h"
|
---|
| 27 |
|
---|
| 28 |
|
---|
[199] | 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";
|
---|
[226] | 33 | else if (err == configurationError) return "configuration error";
|
---|
[199] | 34 | else if (err == systemProblem) return "system problem";
|
---|
[4219] | 35 | else if (err == syntaxError) return "query syntax error";
|
---|
[199] | 36 | return "unknown problem";
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
[187] | 40 | void ShortColInfo_t::clear() {
|
---|
| 41 | name.clear();
|
---|
| 42 | host.clear();
|
---|
| 43 | port = 0;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[4974] | 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 |
|
---|
[187] | 51 | void ColInfoResponse_t::clear () {
|
---|
| 52 | shortInfo.clear();
|
---|
[1994] | 53 | isPublic=true;
|
---|
[166] | 54 | isBeta=false;
|
---|
[6584] | 55 | isSegmented=false;
|
---|
[823] | 56 | languages.erase(languages.begin(), languages.end());
|
---|
| 57 | ccsCols.erase(ccsCols.begin(), ccsCols.end());
|
---|
[10789] | 58 | ccsOptions = 0;
|
---|
[166] | 59 | buildDate=0;
|
---|
[1330] | 60 | buildType.clear();
|
---|
[4753] | 61 | searchTypes.erase(searchTypes.begin(), searchTypes.end());
|
---|
[166] | 62 | numDocs=0;
|
---|
[1253] | 63 | numSections=0;
|
---|
[166] | 64 | numWords=0;
|
---|
| 65 | numBytes=0;
|
---|
[336] | 66 | format.erase(format.begin(), format.end());
|
---|
[823] | 67 | building.erase(format.begin(), format.end());
|
---|
[1860] | 68 | httpdomain.clear();
|
---|
| 69 | httpprefix.clear();
|
---|
[432] | 70 | receptionist.clear();
|
---|
[4974] | 71 |
|
---|
[5017] | 72 | // Setting some authentication parameters use with
|
---|
| 73 | // various parts of the code.
|
---|
| 74 |
|
---|
[5024] | 75 | authenticate.clear(); // turned off by default, individual collection authentication
|
---|
[5017] | 76 | auth_group.clear(); // turned off by default, authentication by groups method
|
---|
[5024] | 77 | public_documents.clear(); // turned off by default, allow access to these documents <list>
|
---|
| 78 | private_documents.clear(); // turned off by default, disallow access to these documents <list>
|
---|
| 79 |
|
---|
[166] | 80 | }
|
---|
| 81 |
|
---|
[9930] | 82 | text_t ColInfoResponse_t::get_collectionmeta(text_t name, text_t lang) {
|
---|
| 83 | text_t value = collectionmeta[name][lang];
|
---|
| 84 | if (value.empty()) {
|
---|
| 85 | value = collectionmeta[name][g_EmptyText];
|
---|
| 86 | }
|
---|
| 87 | return value;
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[220] | 91 | void InfoFiltersResponse_t::clear () {
|
---|
| 92 | filterNames.erase(filterNames.begin(), filterNames.end());
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | void InfoFilterOptionsRequest_t::clear () {
|
---|
| 97 | filterName.clear();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[187] | 101 | void FilterOption_t::clear () {
|
---|
| 102 | name.clear();
|
---|
| 103 | type = booleant;
|
---|
| 104 | repeatable = onePerQuery;
|
---|
| 105 | defaultValue.clear();
|
---|
| 106 | validValues.erase(validValues.begin(), validValues.end());
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[197] | 109 | void FilterOption_t::check_defaultValue () {
|
---|
[226] | 110 | text_tarray::iterator here, end;
|
---|
[197] | 111 |
|
---|
[226] | 112 | // how the default is interpreted depends on the option type
|
---|
| 113 | switch (type) {
|
---|
| 114 | case booleant:
|
---|
| 115 | case enumeratedt: // has to be one of the validValues
|
---|
| 116 | here = validValues.begin ();
|
---|
| 117 | end = validValues.end ();
|
---|
| 118 | while (here != end) {
|
---|
| 119 | if (*here == defaultValue) return;
|
---|
[9620] | 120 | ++here;
|
---|
[197] | 121 | }
|
---|
[226] | 122 |
|
---|
| 123 | break;
|
---|
[197] | 124 |
|
---|
[226] | 125 | case integert: // has to be in the validValues range
|
---|
| 126 | if ((validValues.size() >= 2) &&
|
---|
| 127 | (validValues[0].getint() <= defaultValue.getint()) &&
|
---|
| 128 | (validValues[1].getint() >= defaultValue.getint()))
|
---|
| 129 | return;
|
---|
| 130 | break;
|
---|
| 131 |
|
---|
| 132 | case stringt: // any value is valid
|
---|
| 133 | return;
|
---|
[197] | 134 | }
|
---|
| 135 |
|
---|
[226] | 136 | // did not find the defaultValue
|
---|
| 137 | if (validValues.empty()) defaultValue.clear();
|
---|
| 138 | else defaultValue = validValues[0];
|
---|
[197] | 139 | }
|
---|
| 140 |
|
---|
[187] | 141 |
|
---|
[509] | 142 | bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
| 143 | return ((x.name == y.name) &&
|
---|
| 144 | (x.type == y.type) &&
|
---|
| 145 | (x.repeatable == y.repeatable) &&
|
---|
| 146 | (x.defaultValue == y.defaultValue) &&
|
---|
| 147 | (x.validValues == y.validValues));
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
| 151 | return ((x.name < y.name) ||
|
---|
| 152 | ((x.name == y.name) &&
|
---|
| 153 | ((x.type < y.type) ||
|
---|
| 154 | ((x.type == y.type) &&
|
---|
| 155 | ((x.repeatable < y.repeatable) ||
|
---|
| 156 | ((x.repeatable == y.repeatable) &&
|
---|
| 157 | ((x.defaultValue < y.defaultValue) ||
|
---|
| 158 | ((x.defaultValue == y.defaultValue) &&
|
---|
| 159 | (x.validValues < y.validValues)))))))));
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
[187] | 164 | void InfoFilterOptionsResponse_t::clear () {
|
---|
| 165 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
| 166 | }
|
---|
| 167 |
|
---|
[220] | 168 |
|
---|
[187] | 169 | void OptionValue_t::clear () {
|
---|
| 170 | name.clear();
|
---|
| 171 | value.clear();
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[220] | 174 |
|
---|
[187] | 175 | void FilterRequest_t::clear () {
|
---|
| 176 | filterName.clear();
|
---|
[7422] | 177 | filterLang.clear();
|
---|
[187] | 178 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
| 179 | docSet.erase(docSet.begin(), docSet.end());
|
---|
| 180 | filterResultOptions = 0;
|
---|
[220] | 181 | requestParams.clear();
|
---|
| 182 | refParams.clear();
|
---|
| 183 | fields.erase(fields.begin(), fields.end());
|
---|
[272] | 184 | getParents = false;
|
---|
[187] | 185 | }
|
---|
| 186 |
|
---|
[220] | 187 |
|
---|
[187] | 188 | void TermInfo_t::clear () {
|
---|
| 189 | term.clear();
|
---|
| 190 | freq = 0;
|
---|
| 191 | matchTerms.erase (matchTerms.begin(), matchTerms.end());
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[197] | 194 |
|
---|
[220] | 195 | void MetadataInfo_t::clear () {
|
---|
| 196 | params.clear();
|
---|
| 197 | isRef = false;
|
---|
[241] | 198 | values.erase(values.begin(), values.end());
|
---|
[671] | 199 | if (parent != NULL) {
|
---|
| 200 | delete parent;
|
---|
| 201 | parent = NULL;
|
---|
| 202 | }
|
---|
[220] | 203 | }
|
---|
| 204 |
|
---|
[671] | 205 | MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
|
---|
[220] | 206 |
|
---|
[671] | 207 | // copy constructor
|
---|
| 208 | MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
|
---|
| 209 | params = x.params;
|
---|
| 210 | isRef = x.isRef;
|
---|
| 211 | values = x.values;
|
---|
| 212 | if (x.parent == NULL) parent = NULL;
|
---|
| 213 | else {
|
---|
| 214 | parent = new MetadataInfo_t ();
|
---|
| 215 | *parent = *(x.parent);
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | MetadataInfo_t::~MetadataInfo_t () {
|
---|
| 220 | if (parent != NULL) {
|
---|
| 221 | delete parent;
|
---|
| 222 | parent = NULL;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
|
---|
| 227 | if (&x != this) {
|
---|
| 228 | params = x.params;
|
---|
| 229 | isRef = x.isRef;
|
---|
| 230 | values = x.values;
|
---|
| 231 | if (x.parent == NULL) parent = NULL;
|
---|
| 232 | else {
|
---|
| 233 | parent = new MetadataInfo_t ();
|
---|
| 234 | *parent = *(x.parent);
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | return *this;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[187] | 240 | void ResultDocInfo_t::clear () {
|
---|
| 241 | OID.clear ();
|
---|
[220] | 242 | ranking = 0;
|
---|
[353] | 243 | result_num = 0;
|
---|
[310] | 244 | num_terms_matched = 0;
|
---|
[348] | 245 | num_phrase_match = 0;
|
---|
[187] | 246 | docFreq.erase(docFreq.begin(), docFreq.end());
|
---|
[220] | 247 | metadata.erase(metadata.begin(), metadata.end());
|
---|
[823] | 248 | classifier_metadata_type.erase(classifier_metadata_type.begin(),
|
---|
| 249 | classifier_metadata_type.end());
|
---|
| 250 | classifier_metadata_offset = 0;
|
---|
| 251 |
|
---|
[187] | 252 | }
|
---|
| 253 |
|
---|
[197] | 254 | ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
|
---|
[763] | 255 | OID = x.OID;
|
---|
| 256 | ranking = x.ranking;
|
---|
| 257 | result_num = x.result_num;
|
---|
| 258 | num_terms_matched = x.num_terms_matched;
|
---|
[348] | 259 | num_phrase_match = x.num_phrase_match;
|
---|
[763] | 260 | docFreq = x.docFreq;
|
---|
| 261 | metadata = x.metadata;
|
---|
[197] | 262 | return *this;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[187] | 265 | void FilterResponse_t::clear () {
|
---|
[220] | 266 | numDocs = 0;
|
---|
[398] | 267 | isApprox = Exact;
|
---|
[187] | 268 | termInfo.erase (termInfo.begin(), termInfo.end());
|
---|
| 269 | docInfo.erase (docInfo.begin(), docInfo.end());
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[763] | 272 | FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
|
---|
| 273 | numDocs = x.numDocs;
|
---|
| 274 | isApprox = x.isApprox;
|
---|
| 275 | termInfo = x.termInfo;
|
---|
| 276 | docInfo = x.docInfo;
|
---|
| 277 | return *this;
|
---|
| 278 | }
|
---|
[257] | 279 |
|
---|
| 280 | void DocumentRequest_t::clear () {
|
---|
| 281 | OID.clear();
|
---|
| 282 | docType.clear();
|
---|
| 283 | docFormat.clear();
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | void DocumentResponse_t::clear () {
|
---|
| 287 | doc.clear();
|
---|
| 288 | }
|
---|