[1860] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * corbaproto.cpp --
|
---|
| 4 | * Copyright (C) 2000 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 | * $Id: corbaproto.mpp 25231 2012-03-16 08:38:01Z ak19 $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
[25231] | 28 | #define USE_POA
|
---|
[1860] | 29 |
|
---|
[25231] | 30 | #include <iostream>
|
---|
| 31 | #include <fstream>
|
---|
| 32 |
|
---|
[1860] | 33 | #include "fileutil.h"
|
---|
| 34 |
|
---|
| 35 | // protocol headers for CORBA
|
---|
| 36 | #include "corbaiface.h"
|
---|
| 37 | using namespace gsdlInterface;
|
---|
| 38 |
|
---|
| 39 | // greenstone library headers
|
---|
| 40 | #include "corbaconv_text_t.h"
|
---|
| 41 |
|
---|
| 42 | // greenstone local headers
|
---|
| 43 | #include "corbatext_t.h"
|
---|
| 44 |
|
---|
| 45 | #include "corbaproto.h"
|
---|
| 46 | #include "colservrconfig.h"
|
---|
| 47 |
|
---|
| 48 | // default headers
|
---|
| 49 | #include <assert.h>
|
---|
| 50 |
|
---|
| 51 | void corbatext_optionValueArrayToCorba(OptionValue_tarray array, corbaOptionValue_array &corba)
|
---|
| 52 | {
|
---|
| 53 | unsigned int i = 0;
|
---|
| 54 | OptionValue_tarray::iterator here = array.begin();
|
---|
| 55 | OptionValue_tarray::iterator end = array.end();
|
---|
| 56 |
|
---|
| 57 | while (here != end)
|
---|
| 58 | {
|
---|
| 59 | corba.length(i+1);
|
---|
| 60 |
|
---|
| 61 | corbaconv_text_t::getCorbatext(here->name,corba[i].name);
|
---|
| 62 | corbaconv_text_t::getCorbatext(here->value,corba[i].value);
|
---|
| 63 |
|
---|
| 64 | i ++;
|
---|
| 65 | here ++;
|
---|
| 66 | }
|
---|
[25231] | 67 | // std::cout << "Options " << i << std::endl;
|
---|
[1860] | 68 | }
|
---|
| 69 |
|
---|
| 70 | void corbaresponse_resultMetadataToCorba(MetadataInfo_t &meta, corbaMetadataInfo &corbaMeta)
|
---|
| 71 | {
|
---|
| 72 | corbaconv_text_t::getCorbatext(meta.params,corbaMeta.params);
|
---|
| 73 | corbatext_arrayToCorbaArray(meta.values, &corbaMeta.values);
|
---|
| 74 | corbaMeta.isRef = meta.isRef;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void corbaresponse_resultMetadataToC(const corbaMetadataInfo &corbaMeta, MetadataInfo_t &meta)
|
---|
| 78 | {
|
---|
| 79 | corbaconv_text_t::setCorbatext(meta.params,corbaMeta.params);
|
---|
| 80 | corbatext_corbaArrayToArray(corbaMeta.values, &meta.values);
|
---|
| 81 | meta.isRef = corbaMeta.isRef;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | int corbaresponse_resultMetaParentToCorba(MetadataInfo_t *parent, corbaMetadataInfo_array &corbaparent)
|
---|
| 85 | {
|
---|
| 86 | int reply = -1, pid = -1;
|
---|
| 87 |
|
---|
| 88 | // extend for new parent
|
---|
| 89 | reply = corbaparent.length();
|
---|
| 90 | corbaparent.length(reply+1);
|
---|
| 91 |
|
---|
| 92 | // copy content into new array element
|
---|
| 93 | corbaresponse_resultMetadataToCorba(*parent, corbaparent[reply]);
|
---|
| 94 |
|
---|
| 95 | // deal with our own parent
|
---|
| 96 | if (parent->parent != NULL)
|
---|
| 97 | {
|
---|
| 98 | // get offset of new parent and extend parent vector
|
---|
| 99 |
|
---|
| 100 | pid = corbaresponse_resultMetaParentToCorba(parent->parent, corbaparent);
|
---|
| 101 | }
|
---|
| 102 | corbaparent[reply].parentid = pid;
|
---|
| 103 |
|
---|
| 104 | // return the parent id from here
|
---|
| 105 | return reply;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | MetadataInfo_t *corbaresponse_resultMetaParentToC(corbaMetadataInfo_array &corbaparent, int pid)
|
---|
| 109 | {
|
---|
| 110 | MetadataInfo_t *reply;
|
---|
| 111 |
|
---|
| 112 | reply = new MetadataInfo_t;
|
---|
| 113 |
|
---|
| 114 | corbaresponse_resultMetadataToC(corbaparent[pid], *reply);
|
---|
| 115 |
|
---|
| 116 | // deal with our own parent
|
---|
| 117 | if (corbaparent[pid].parentid >= 0)
|
---|
| 118 | {
|
---|
| 119 | // get offset of new parent and extend parent vector
|
---|
| 120 |
|
---|
| 121 | reply->parent = corbaresponse_resultMetaParentToC(corbaparent, corbaparent[pid].parentid);
|
---|
| 122 | }
|
---|
| 123 | else
|
---|
| 124 | {
|
---|
| 125 | reply->parent = NULL;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | // return the parent id from here
|
---|
| 129 | return reply;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo)
|
---|
| 133 | {
|
---|
| 134 | ResultDocInfo_tarray::iterator here = docinfo.begin();
|
---|
| 135 | ResultDocInfo_tarray::iterator end = docinfo.end();
|
---|
| 136 | unsigned int i;
|
---|
| 137 |
|
---|
| 138 | i = 0;
|
---|
| 139 | while (here != end)
|
---|
| 140 | {
|
---|
| 141 | corbainfo.length(i+1);
|
---|
| 142 |
|
---|
| 143 | // copy the easy bits
|
---|
| 144 | corbaconv_text_t::getCorbatext(here->OID,corbainfo[i].OID);
|
---|
| 145 |
|
---|
| 146 | corbainfo[i].resultNum = here->result_num;
|
---|
| 147 | corbainfo[i].ranking = here->ranking;
|
---|
| 148 | corbainfo[i].termsMatched = here->num_terms_matched;
|
---|
| 149 | corbainfo[i].phraseMatched = here->num_phrase_match;
|
---|
| 150 |
|
---|
| 151 | // copy the docFreq array
|
---|
| 152 | vector<int>::iterator fhere = here->docFreq.begin();
|
---|
| 153 | vector<int>::iterator fend = here->docFreq.end();
|
---|
| 154 | unsigned int fi = 0;
|
---|
| 155 |
|
---|
| 156 | while (fhere != fend)
|
---|
| 157 | {
|
---|
| 158 | corbainfo[i].docFreq.length(fi+1);
|
---|
| 159 |
|
---|
| 160 | corbainfo[i].docFreq[fi] = *fhere;
|
---|
| 161 |
|
---|
| 162 | fhere ++;
|
---|
| 163 | fi ++;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | // copy the MetadataInfo map
|
---|
| 167 | MetadataInfo_tmap::iterator mhere = here->metadata.begin();
|
---|
| 168 | MetadataInfo_tmap::iterator mend = here->metadata.end();
|
---|
| 169 | unsigned int mi = 0;
|
---|
| 170 |
|
---|
| 171 | while (mhere != mend)
|
---|
| 172 | {
|
---|
| 173 | corbainfo[i].metadata.names.length(mi+1);
|
---|
| 174 | corbainfo[i].metadata.values.length(mi+1);
|
---|
| 175 |
|
---|
| 176 | // copy name
|
---|
| 177 | corbaconv_text_t::getCorbatext((*mhere).first,corbainfo[i].metadata.names[mi]);
|
---|
| 178 |
|
---|
| 179 | // copy metadata
|
---|
| 180 | corbaresponse_resultMetadataToCorba((*mhere).second, corbainfo[i].metadata.values[mi]);
|
---|
| 181 | if (mhere->second.parent != NULL)
|
---|
| 182 | {
|
---|
| 183 | int pid;
|
---|
| 184 |
|
---|
| 185 | pid = corbaresponse_resultMetaParentToCorba(mhere->second.parent,
|
---|
| 186 | corbainfo[i].metaparents);
|
---|
| 187 | corbainfo[i].metadata.values[mi].parentid = pid;
|
---|
| 188 | }
|
---|
| 189 | else
|
---|
| 190 | {
|
---|
| 191 | corbainfo[i].metadata.values[mi].parentid = -1;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[25231] | 194 | std::cout << "Parent " << mi << " " << (off_t) &mhere->second << " " << (off_t) mhere->second.parent << std::endl;
|
---|
[1860] | 195 |
|
---|
| 196 | mhere ++;
|
---|
| 197 | mi ++;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | // Copy the classifier variables
|
---|
| 201 | corbaconv_text_t::getCorbatext(here->classifier_metadata_type, corbainfo[i].classifierMetadataType);
|
---|
| 202 | corbainfo[i].classifierMetadataOffset = here->classifier_metadata_offset;
|
---|
| 203 |
|
---|
| 204 | // Get next Docinfo item
|
---|
| 205 | i++;
|
---|
| 206 | here ++;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | void corbaresponse_resultDocInfoToC(corbaResultDocInfo_array corbainfo, ResultDocInfo_tarray &docinfo)
|
---|
| 211 | {
|
---|
| 212 | unsigned int i;
|
---|
| 213 | ResultDocInfo_t doc;
|
---|
| 214 |
|
---|
| 215 | for (i = 0; i < corbainfo.length(); i++)
|
---|
| 216 | {
|
---|
| 217 | corbaconv_text_t::setCorbatext(doc.OID,corbainfo[i].OID);
|
---|
| 218 | doc.result_num = corbainfo[i].resultNum;
|
---|
| 219 | doc.ranking = corbainfo[i].ranking;
|
---|
| 220 | doc.num_terms_matched = corbainfo[i].termsMatched;
|
---|
| 221 | doc.num_phrase_match = corbainfo[i].phraseMatched;
|
---|
| 222 |
|
---|
| 223 | // copy the doc freq array
|
---|
| 224 | unsigned int fi;
|
---|
| 225 | for (fi = 0; fi < corbainfo[i].docFreq.length(); fi ++)
|
---|
| 226 | {
|
---|
| 227 | doc.docFreq.push_back(corbainfo[i].docFreq[fi]);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | // copy the MetadataInfomap
|
---|
| 231 | unsigned int mi;
|
---|
| 232 | text_t mname;
|
---|
| 233 | MetadataInfo_t mdata;
|
---|
| 234 |
|
---|
| 235 | doc.metadata.clear();
|
---|
| 236 | for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
|
---|
| 237 | {
|
---|
| 238 | // get name
|
---|
| 239 | corbaconv_text_t::setCorbatext(mname,corbainfo[i].metadata.names[mi]);
|
---|
| 240 |
|
---|
| 241 | // get metadata
|
---|
| 242 | corbaresponse_resultMetadataToC(corbainfo[i].metadata.values[mi], mdata);
|
---|
| 243 |
|
---|
| 244 | if (corbainfo[i].metadata.values[mi].parentid >= 0)
|
---|
| 245 | {
|
---|
| 246 | mdata.parent =
|
---|
| 247 | corbaresponse_resultMetaParentToC(corbainfo[i].metaparents,
|
---|
| 248 | corbainfo[i].metadata.values[mi].parentid);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | doc.metadata.insert(make_pair(mname, mdata));
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | // GRB: sort out parent data
|
---|
| 255 | for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
|
---|
| 256 | {
|
---|
| 257 | if (corbainfo[i].metadata.values[mi].parentid != 0)
|
---|
| 258 | {
|
---|
| 259 | int pi;
|
---|
| 260 |
|
---|
| 261 | for (pi = 0; pi < corbainfo[i].metadata.names.length(); pi ++)
|
---|
| 262 | {
|
---|
| 263 | if (pi != mi &&
|
---|
| 264 | corbainfo[i].metadata.values[mi].parentid ==
|
---|
| 265 | corbainfo[i].metadata.values[pi].id)
|
---|
| 266 | {
|
---|
| 267 | doc.metadata[mi].parent = &doc.metadata[pi];
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 | // doc.metadata
|
---|
| 273 |
|
---|
| 274 | // convert metadata classifer information
|
---|
| 275 | corbaconv_text_t::setCorbatext(doc.classifier_metadata_type,corbainfo[i].classifierMetadataType);
|
---|
| 276 | doc.classifier_metadata_offset = corbainfo[i].classifierMetadataOffset;
|
---|
| 277 |
|
---|
| 278 | docinfo.push_back(doc);
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 |
|
---|
[1983] | 282 |
|
---|
| 283 | // Added 31/1/2001, Michael Dewsnip
|
---|
| 284 | void corbaresponse_resultTermInfoToC(corbaTermInfo_array corbainfo, TermInfo_tarray &terminfo)
|
---|
| 285 | {
|
---|
| 286 | TermInfo_t ti;
|
---|
| 287 |
|
---|
| 288 | for (unsigned int i = 0; i < corbainfo.length(); i++) {
|
---|
| 289 | corbaconv_text_t::setCorbatext(ti.term, corbainfo[i].term);
|
---|
| 290 | ti.freq = corbainfo[i].frequency;
|
---|
| 291 |
|
---|
| 292 | for (unsigned int j = 0; j < corbainfo[i].matchTerms.length(); j++) {
|
---|
| 293 | text_t mt;
|
---|
| 294 | corbaconv_text_t::setCorbatext(mt, corbainfo[i].matchTerms[j]);
|
---|
| 295 |
|
---|
| 296 | ti.matchTerms.push_back(mt);
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | terminfo.push_back(ti);
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 |
|
---|
[1860] | 304 | corbaproto::corbaproto(char* _site_name)
|
---|
| 305 | { char *dummyv[1] = {""};
|
---|
| 306 | int dummyc = 0;
|
---|
| 307 | // CORBA variables
|
---|
| 308 | /* static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
|
---|
| 309 | static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" ); */
|
---|
| 310 |
|
---|
| 311 | CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
|
---|
| 312 |
|
---|
[25231] | 313 | #if defined(USE_POA)
|
---|
| 314 | CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
|
---|
| 315 | PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
|
---|
| 316 | poa->the_POAManager()->activate();
|
---|
| 317 | #else
|
---|
| 318 | CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
|
---|
| 319 | #endif
|
---|
| 320 |
|
---|
[1860] | 321 | char objid_filename[256];
|
---|
| 322 | sprintf(objid_filename,"/tmp/%s.objid",_site_name);
|
---|
| 323 |
|
---|
| 324 | // Get ref from "naming service"
|
---|
| 325 | ifstream in (objid_filename);
|
---|
| 326 | char ref[1000];
|
---|
| 327 | in >> ref;
|
---|
| 328 | in.close ();
|
---|
| 329 |
|
---|
| 330 | // startup corba
|
---|
| 331 | // static CORBA::Object_var obj = orb->string_to_object (ref);
|
---|
| 332 | CORBA::Object_var obj = orb->string_to_object (ref);
|
---|
| 333 |
|
---|
| 334 | client = corbaiface::_narrow( obj );
|
---|
| 335 | // client = NULL; // ****
|
---|
| 336 |
|
---|
| 337 | gsdlhome.clear();
|
---|
| 338 | site_name = _site_name;
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | corbaiface_var corbaproto::getCorbaClient()
|
---|
| 342 | {
|
---|
| 343 | // This function was written to help corba when ORB and BOA were
|
---|
| 344 | // not working in "persistent" mode.
|
---|
| 345 | // Now that persistent mode is working it is not longer needed/used.
|
---|
| 346 |
|
---|
| 347 | char *dummyv[1] = {""};
|
---|
| 348 | int dummyc = 0;
|
---|
| 349 | // CORBA variables
|
---|
| 350 | // static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
|
---|
| 351 | // static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
|
---|
| 352 |
|
---|
| 353 | // DB // Try this out!! // ****
|
---|
| 354 | CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
|
---|
| 355 |
|
---|
[25231] | 356 | #if defined(USE_POA)
|
---|
| 357 | CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
|
---|
| 358 | PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
|
---|
| 359 |
|
---|
| 360 | poa->the_POAManager()->activate();
|
---|
| 361 | #else
|
---|
| 362 | CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
|
---|
| 363 | #endif
|
---|
| 364 |
|
---|
[1860] | 365 | /* char* site_name_chars = site_name.getcstr();
|
---|
| 366 | char objid_filename[256];
|
---|
| 367 | sprintf(objid_filename,"/tmp/%s.objid",site_name_chars);
|
---|
| 368 | // delete site_name_chars; */
|
---|
| 369 |
|
---|
| 370 | text_t objid_filename = "/tmp/" + site_name + ".objid";
|
---|
| 371 |
|
---|
| 372 | // Get ref from "naming service"
|
---|
| 373 | ifstream in (objid_filename.getcstr());
|
---|
| 374 | char ref[1000];
|
---|
| 375 | in >> ref;
|
---|
| 376 | in.close ();
|
---|
| 377 |
|
---|
| 378 | // startup corba
|
---|
| 379 | // DB // Try this out!! // ****
|
---|
| 380 | // static CORBA::Object_var obj = orb->string_to_object (ref);
|
---|
| 381 | CORBA::Object_var obj = orb->string_to_object (ref);
|
---|
| 382 |
|
---|
| 383 | return corbaiface::_narrow( obj );
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 |
|
---|
| 387 | // this configure will configure each of the collection servers
|
---|
[2113] | 388 | void corbaproto::configure (const text_t &key, const text_tarray &cfgline,
|
---|
| 389 | comerror_t &err) {
|
---|
[1860] | 390 | // the naming of the collection should not be done here,
|
---|
| 391 | // it should be done just after the collection server has been
|
---|
| 392 | // created
|
---|
| 393 |
|
---|
[25231] | 394 | // std::cout << "Corbaproto::Configure" << std::endl;
|
---|
[1860] | 395 | corbatext_t corbaKey;
|
---|
| 396 | corbatext_tarray corbaCfgline;
|
---|
[2223] | 397 | gsdlInterface::corbaComError error = corbaNoError;
|
---|
[1860] | 398 |
|
---|
| 399 | // get the corba client reference
|
---|
| 400 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 401 | corbaiface_var lclient = client;
|
---|
| 402 |
|
---|
| 403 | // convert all the requisite structures into their CORBA form
|
---|
| 404 | corbaconv_text_t::getCorbatext(key,corbaKey);
|
---|
| 405 | corbatext_arrayToCorbaArray(cfgline, &corbaCfgline);
|
---|
| 406 |
|
---|
| 407 | // execute the corba transaction
|
---|
[2173] | 408 | lclient->configure(corbaKey, corbaCfgline, error);
|
---|
[1860] | 409 |
|
---|
| 410 | if (key=="gsdlhome")
|
---|
| 411 | {
|
---|
| 412 | // store gsdlhome in corba prototype so it can be used later to
|
---|
| 413 | // check if icons specified in format statements exist on the
|
---|
| 414 | // recptionist's side
|
---|
| 415 | gsdlhome = cfgline[0];
|
---|
| 416 | }
|
---|
[2122] | 417 | err = (comerror_t) error;
|
---|
[1860] | 418 | }
|
---|
| 419 |
|
---|
| 420 | // this init will configure and init each of the collection servers
|
---|
[2113] | 421 | bool corbaproto::init (comerror_t &err, ostream &logout) {
|
---|
[25231] | 422 | // std::cout << "Corbaproto::Init" << std::endl;
|
---|
[2223] | 423 | gsdlInterface::corbaComError error = corbaNoError;
|
---|
[1860] | 424 |
|
---|
| 425 | // get the corba client reference
|
---|
| 426 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 427 | corbaiface_var lclient = client;
|
---|
| 428 |
|
---|
| 429 | // execute the corba transaction
|
---|
[2122] | 430 | return lclient->initialise(error);
|
---|
[1860] | 431 | }
|
---|
| 432 |
|
---|
| 433 | void corbaproto::cache_missing_icons(text_tmap& format_map,
|
---|
| 434 | text_t& httpdomain,
|
---|
| 435 | text_t& httpprefix)
|
---|
| 436 | {
|
---|
| 437 | // consider making this a member function in the object?
|
---|
| 438 |
|
---|
| 439 | text_tmap::iterator format_here = format_map.begin();
|
---|
| 440 | text_tmap::iterator format_end = format_map.end();
|
---|
| 441 | while (format_here!=format_end)
|
---|
| 442 | {
|
---|
| 443 | text_t format_line = format_here->second;
|
---|
| 444 |
|
---|
[25231] | 445 | // std::cout << "*** format line = " << format_line << std::endl; // ****
|
---|
[1860] | 446 |
|
---|
| 447 | text_t::iterator fl_begin = format_line.begin();
|
---|
| 448 | text_t::iterator fl_end = format_line.end();
|
---|
| 449 |
|
---|
| 450 | text_t::iterator httpimg_find = findword(fl_begin,fl_end,"_httpimg_");
|
---|
| 451 | text_t::iterator http_find = httpimg_find;
|
---|
| 452 |
|
---|
| 453 | while (httpimg_find!=fl_end)
|
---|
| 454 | {
|
---|
| 455 | http_find = httpimg_find+5;
|
---|
| 456 | httpimg_find += 9;
|
---|
| 457 |
|
---|
| 458 | // look for white space " or >
|
---|
| 459 | text_t::iterator filename_end = httpimg_find;
|
---|
| 460 | while (filename_end != fl_end)
|
---|
| 461 | {
|
---|
| 462 | if (*filename_end == ' ') break;
|
---|
| 463 | if (*filename_end == '\t') break;
|
---|
| 464 | if (*filename_end == '\"') break;
|
---|
| 465 | if (*filename_end == '>') break;
|
---|
| 466 | filename_end++;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | text_t img_filename = substr(httpimg_find,filename_end);
|
---|
| 470 |
|
---|
| 471 | text_t site_img_filename = filename_cat(gsdlhome,"images",img_filename);
|
---|
| 472 |
|
---|
| 473 | // look to see if img filename exists in images directory
|
---|
| 474 | if (!file_exists(site_img_filename))
|
---|
| 475 | {
|
---|
| 476 | text_t cache_img_dir
|
---|
| 477 | = filename_cat(gsdlhome,"images",".cache");
|
---|
| 478 |
|
---|
| 479 | text_t remote_img_url = "http://" + httpdomain + httpprefix
|
---|
| 480 | + "/images" + img_filename;
|
---|
| 481 |
|
---|
| 482 | text_t wget_cmd = "wget -q -N --directory-prefix="+cache_img_dir
|
---|
| 483 | + " " + remote_img_url;
|
---|
| 484 |
|
---|
| 485 | char* wget_cmd_chars = wget_cmd.getcstr();
|
---|
| 486 |
|
---|
| 487 | system(wget_cmd_chars);
|
---|
| 488 | delete wget_cmd_chars;
|
---|
| 489 |
|
---|
| 490 | format_map[format_here->first]
|
---|
| 491 | = substr(fl_begin,http_find) + "cache" + substr(http_find,fl_end);
|
---|
| 492 |
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | httpimg_find = findword(httpimg_find,fl_end,"_httpimg_");
|
---|
| 496 | }
|
---|
| 497 | format_here++;
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[2113] | 501 | text_t corbaproto::get_site_name (comerror_t &err) {
|
---|
[1860] | 502 | return site_name;
|
---|
| 503 | }
|
---|
| 504 |
|
---|
[2113] | 505 | text_t corbaproto::get_protocol_name (comerror_t &err) {
|
---|
[1860] | 506 | return "corbaproto";
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 |
|
---|
| 510 | void corbaproto::get_collection_list (text_tarray &collist, comerror_t &err,
|
---|
| 511 | ostream &/*logout*/) {
|
---|
| 512 |
|
---|
[25231] | 513 | // std::cout << "Corbaproto::Collection list" << std::endl;
|
---|
[1860] | 514 |
|
---|
| 515 | corbatext_tarray corba_collist;
|
---|
| 516 | text_tarray tcollist;
|
---|
[2223] | 517 | gsdlInterface::corbaComError error = corbaNoError;
|
---|
[1860] | 518 |
|
---|
| 519 | // get the corba client reference
|
---|
| 520 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 521 | corbaiface_var lclient = client;
|
---|
| 522 |
|
---|
| 523 | // execute the corba transaction
|
---|
[2122] | 524 | lclient->collectionList(corba_collist,error);
|
---|
[1860] | 525 |
|
---|
| 526 | // convert the response back to normal form
|
---|
| 527 | corbatext_corbaArrayToArray(corba_collist, &tcollist);
|
---|
| 528 | collist = tcollist;
|
---|
| 529 |
|
---|
[2122] | 530 | err = (comerror_t) error;
|
---|
[1860] | 531 | }
|
---|
| 532 |
|
---|
| 533 | void corbaproto::has_collection (const text_t &collection, bool &hascollection,
|
---|
| 534 | comerror_t &err, ostream &/*logout*/) {
|
---|
[25231] | 535 | // std::cout << "Corbaproto::Has collection" << std::endl;
|
---|
[1860] | 536 |
|
---|
| 537 | corbatext_t corbaCollection;
|
---|
[2223] | 538 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 539 | CORBA::Boolean corbaHas;
|
---|
| 540 |
|
---|
| 541 | // get the corba client reference
|
---|
| 542 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 543 | corbaiface_var lclient = client;
|
---|
| 544 |
|
---|
| 545 | // convert all the requisite structures into their CORBA form
|
---|
| 546 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
| 547 |
|
---|
| 548 | // execute the corba transaction
|
---|
| 549 | lclient->hasCollection(corbaCollection, corbaHas, corbaError);
|
---|
| 550 |
|
---|
| 551 | // convert the response back to normal form
|
---|
| 552 | hascollection = (corbaHas != 0);
|
---|
| 553 | err = noError;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | void corbaproto::ping (const text_t &collection, bool &wassuccess,
|
---|
| 557 | comerror_t &err, ostream &/*logout*/) {
|
---|
[25231] | 558 | // std::cout << "Corbaproto::Ping" << std::endl;
|
---|
[1860] | 559 |
|
---|
| 560 | corbatext_t corbaCollect;
|
---|
[2223] | 561 | corbaComError corbaError = corbaNoError;
|
---|
[2173] | 562 | CORBA::Boolean success;
|
---|
[1860] | 563 |
|
---|
| 564 | // get the corba client reference
|
---|
| 565 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 566 | corbaiface_var lclient = client;
|
---|
| 567 |
|
---|
| 568 | // convert all the requisite structures into their CORBA form
|
---|
| 569 | corbaconv_text_t::getCorbatext(collection,corbaCollect);
|
---|
| 570 |
|
---|
| 571 | // execute the corba transaction
|
---|
[2173] | 572 | lclient->ping(corbaCollect, success, corbaError);
|
---|
[1860] | 573 |
|
---|
| 574 | // convert the response back to normal form
|
---|
| 575 | wassuccess = (success != 0);
|
---|
[2223] | 576 | err = (comerror_t) corbaError;
|
---|
[25231] | 577 | std::cout << "Corbaproto::Ping" << err << std::endl;
|
---|
[1860] | 578 | }
|
---|
| 579 |
|
---|
| 580 |
|
---|
| 581 | void corbaproto::get_collectinfo (const text_t &collection,
|
---|
| 582 | ColInfoResponse_t &collectinfo,
|
---|
| 583 | comerror_t &err, ostream &logout) {
|
---|
[25231] | 584 | // std::cout << "Corbaproto::Collectinfo" << std::endl;
|
---|
[1860] | 585 |
|
---|
| 586 | corbatext_t corbaCollection;
|
---|
[2223] | 587 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 588 | corbaColInfoResponse corbaCollectInfo;
|
---|
| 589 |
|
---|
| 590 | // get the corba client reference
|
---|
| 591 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 592 | corbaiface_var lclient = client;
|
---|
| 593 |
|
---|
| 594 | // convert all the requisite structures into their CORBA form
|
---|
| 595 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
| 596 |
|
---|
| 597 | // execute the corba transaction
|
---|
| 598 | lclient->getCollectInfo(corbaCollection, corbaCollectInfo, corbaError);
|
---|
| 599 |
|
---|
| 600 | // convert the response back to normal form
|
---|
[13982] | 601 | collectinfo.useBook = corbaCollectInfo.useBook;
|
---|
[1860] | 602 | collectinfo.isPublic = corbaCollectInfo.isPublic;
|
---|
| 603 | collectinfo.isBeta = corbaCollectInfo.isBeta;
|
---|
| 604 | collectinfo.buildDate = corbaCollectInfo.buildDate;
|
---|
| 605 | corbatext_corbaArrayToArray(corbaCollectInfo.ccsCols, &collectinfo.ccsCols);
|
---|
| 606 | corbatext_corbaArrayToArray(corbaCollectInfo.languages, &collectinfo.languages);
|
---|
| 607 | collectinfo.numDocs = corbaCollectInfo.numDocs;
|
---|
| 608 | collectinfo.numWords = corbaCollectInfo.numWords;
|
---|
| 609 | collectinfo.numBytes = corbaCollectInfo.numBytes;
|
---|
[25231] | 610 | corbatext_corbaColmetamapToColmetamap(corbaCollectInfo.collectionMeta, collectinfo.collectionmeta);
|
---|
[1860] | 611 | corbatext_corbaMapToMap(corbaCollectInfo.format, collectinfo.format);
|
---|
| 612 | corbatext_corbaMapToMap(corbaCollectInfo.building, collectinfo.building);
|
---|
| 613 | corbaconv_text_t::setCorbatext(collectinfo.httpdomain,corbaCollectInfo.httpdomain);
|
---|
| 614 | corbaconv_text_t::setCorbatext(collectinfo.httpprefix,corbaCollectInfo.httpprefix);
|
---|
| 615 | corbaconv_text_t::setCorbatext(collectinfo.receptionist,corbaCollectInfo.receptionist);
|
---|
| 616 |
|
---|
[25231] | 617 | // Member variables in comtools mirrored in corbaiface (and corbaproto) on 14/03/2012.
|
---|
| 618 | // shortInfo (previously mistyped as "shoftInfo" in corbaiface.idl) has 3 simple fields
|
---|
| 619 | corbaconv_text_t::setCorbatext(collectinfo.shortInfo.name, corbaCollectInfo.shortInfo.name);
|
---|
| 620 | corbaconv_text_t::setCorbatext(collectinfo.shortInfo.host, corbaCollectInfo.shortInfo.host);
|
---|
| 621 | collectinfo.shortInfo.port = corbaCollectInfo.shortInfo.response;
|
---|
| 622 |
|
---|
| 623 | collectinfo.isSegmented = corbaCollectInfo.isSegmented;
|
---|
| 624 | collectinfo.isCollectGroup = corbaCollectInfo.isCollectGroup;
|
---|
| 625 |
|
---|
| 626 | collectinfo.numSections = corbaCollectInfo.numSections;
|
---|
| 627 | collectinfo.ccsOptions = corbaCollectInfo.ccsOptions;
|
---|
| 628 | collectinfo.stemIndexes = corbaCollectInfo.stemIndexes;
|
---|
| 629 |
|
---|
| 630 | corbatext_corbaColmetamapToColmetamap(corbaCollectInfo.collection_macros, collectinfo.collection_macros);
|
---|
| 631 |
|
---|
| 632 | corbaconv_text_t::setCorbatext(collectinfo.buildType,corbaCollectInfo.buildType);
|
---|
| 633 | corbaconv_text_t::setCorbatext(collectinfo.infodbType,corbaCollectInfo.infodbType);
|
---|
| 634 | corbaconv_text_t::setCorbatext(collectinfo.authenticate,corbaCollectInfo.authenticate);
|
---|
| 635 | corbaconv_text_t::setCorbatext(collectinfo.auth_group,corbaCollectInfo.auth_group);
|
---|
| 636 | corbaconv_text_t::setCorbatext(collectinfo.earliestDatestamp,corbaCollectInfo.earliestDatestamp);
|
---|
| 637 |
|
---|
| 638 | corbatext_corbaMapToMap(corbaCollectInfo.public_documents, collectinfo.public_documents);
|
---|
| 639 | corbatext_corbaMapToMap(corbaCollectInfo.private_documents, collectinfo.private_documents);
|
---|
| 640 | corbatext_corbaMapToMap(corbaCollectInfo.dynamic_classifiers, collectinfo.dynamic_classifiers);
|
---|
| 641 |
|
---|
| 642 |
|
---|
[1860] | 643 | cache_missing_icons(collectinfo.format,collectinfo.httpdomain,
|
---|
| 644 | collectinfo.httpprefix);
|
---|
| 645 |
|
---|
| 646 | err = (comerror_t) corbaError;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 |
|
---|
| 650 | void corbaproto::get_filterinfo (const text_t &collection,
|
---|
| 651 | InfoFiltersResponse_t &response,
|
---|
| 652 | comerror_t &err, ostream &logout) {
|
---|
[25231] | 653 | // std::cout << "Corbaproto::Filterinfo" << std::endl;
|
---|
[1860] | 654 |
|
---|
| 655 | corbatext_t corbaCollection;
|
---|
| 656 | corbatext_tset corbaResponse;
|
---|
[2223] | 657 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 658 |
|
---|
| 659 | // get the corba client reference
|
---|
| 660 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 661 | corbaiface_var lclient = client;
|
---|
| 662 |
|
---|
| 663 | // convert all the requisite structures into their CORBA form
|
---|
| 664 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
| 665 |
|
---|
| 666 | // execute the corba transaction
|
---|
| 667 | lclient->getFilterInfo(corbaCollection, corbaResponse, corbaError);
|
---|
| 668 |
|
---|
| 669 | // convert the response back to normal form
|
---|
| 670 | corbatext_corbaArrayToSet(corbaResponse, &response.filterNames);
|
---|
| 671 |
|
---|
| 672 | err = (comerror_t) corbaError;
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | void corbaproto::get_filteroptions (const text_t &collection,
|
---|
| 676 | const InfoFilterOptionsRequest_t &request,
|
---|
| 677 | InfoFilterOptionsResponse_t &response,
|
---|
| 678 | comerror_t &err, ostream &logout) {
|
---|
[25231] | 679 | // std::cout << "Corbaproto::Filteroptions" << std::endl;
|
---|
[1860] | 680 |
|
---|
| 681 | corbatext_t corbaCollection;
|
---|
| 682 | corbatext_t filterName;
|
---|
| 683 | corbaFilterOptionsResponse corbaResponse;
|
---|
[2223] | 684 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 685 | unsigned int i;
|
---|
| 686 | corbaconv_text_t *cc_name;
|
---|
| 687 | FilterOption_t *option;
|
---|
| 688 |
|
---|
| 689 | // get the corba client reference
|
---|
| 690 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 691 | corbaiface_var lclient = client;
|
---|
| 692 |
|
---|
| 693 | // convert all the requisite structures into their CORBA form
|
---|
| 694 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
| 695 | corbaconv_text_t::getCorbatext(request.filterName,filterName);
|
---|
| 696 |
|
---|
| 697 | // execute the corba transaction
|
---|
| 698 | lclient->getFilterOptions(corbaCollection, filterName, corbaResponse, corbaError);
|
---|
| 699 |
|
---|
| 700 | // convert the response back to normal form
|
---|
| 701 | for (i = 0; i < corbaResponse.names.length(); i ++)
|
---|
| 702 | {
|
---|
| 703 | cc_name = new corbaconv_text_t(corbaResponse.names[i]);
|
---|
| 704 |
|
---|
| 705 | option = new FilterOption_t;
|
---|
| 706 | corbaconv_text_t::setCorbatext(option->name,corbaResponse.options[i].name);
|
---|
| 707 | option->type = (FilterOption_t::type_t) corbaResponse.options[i].type;
|
---|
| 708 | option->repeatable = (FilterOption_t::repeatable_t) corbaResponse.options[i].repeatable;
|
---|
| 709 | corbaconv_text_t::setCorbatext(option->defaultValue,corbaResponse.options[i].defaultValue);
|
---|
| 710 | corbatext_corbaArrayToArray(corbaResponse.options[i].validValues, &option->validValues);
|
---|
| 711 |
|
---|
| 712 | response.filterOptions.insert(make_pair(*cc_name, *option)); // typecast to text_t
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | err = (comerror_t) corbaError;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
[24959] | 718 | // returns the contents of a collection's rss-items.rdf file (generated by BasePlugout)
|
---|
| 719 | void corbaproto::get_rss_items (const text_t &collection,
|
---|
| 720 | const text_t &gsdlhome,
|
---|
| 721 | text_t &rss_items,
|
---|
| 722 | comerror_t &err,
|
---|
| 723 | ostream &logout) {
|
---|
[1983] | 724 |
|
---|
[24959] | 725 | corbatext_t corbaCollection;
|
---|
| 726 | corbatext_t corbaGsdlHome;
|
---|
| 727 | corbatext_t corbaRssItems;
|
---|
| 728 | corbaComError corbaError = corbaNoError;
|
---|
| 729 |
|
---|
| 730 | // convert all the requisite structures into their CORBA form
|
---|
| 731 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
[24961] | 732 | corbaconv_text_t::getCorbatext(gsdlhome,corbaGsdlHome);
|
---|
[24959] | 733 |
|
---|
| 734 | // get the corba client reference
|
---|
| 735 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 736 | corbaiface_var lclient = client;
|
---|
| 737 |
|
---|
| 738 | // execute the corba transaction
|
---|
[25231] | 739 | lclient->getRssItems (corbaCollection, corbaGsdlHome, corbaRssItems, corbaError);
|
---|
[24959] | 740 |
|
---|
[25231] | 741 | err = (comerror_t) corbaError;
|
---|
| 742 |
|
---|
[24959] | 743 | // convert the response back to normal form
|
---|
[25231] | 744 | corbaconv_text_t::setCorbatext(rss_items,corbaRssItems);
|
---|
[24959] | 745 | }
|
---|
| 746 |
|
---|
[1860] | 747 | void corbaproto::filter (const text_t &collection,
|
---|
| 748 | FilterRequest_t &request,
|
---|
| 749 | FilterResponse_t &response,
|
---|
| 750 | comerror_t &err, ostream &logout) {
|
---|
[25231] | 751 | // std::cout << "Corbaproto::Filter" << std::endl;
|
---|
[1860] | 752 |
|
---|
| 753 | corbaFilterRequest corbaRequest;
|
---|
| 754 | corbaFilterResponse corbaResponse;
|
---|
| 755 | corbatext_t corbaCollection;
|
---|
[2223] | 756 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 757 |
|
---|
| 758 | // get the corba client reference
|
---|
| 759 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 760 | corbaiface_var lclient = client;
|
---|
| 761 |
|
---|
| 762 | // convert all the requisite structures into their CORBA form
|
---|
| 763 | corbaconv_text_t::getCorbatext(collection,corbaCollection);
|
---|
| 764 | corbaconv_text_t::getCorbatext(request.filterName,corbaRequest.filter);
|
---|
| 765 | corbatext_optionValueArrayToCorba(request.filterOptions, corbaRequest.filterOptions);
|
---|
| 766 | corbatext_arrayToCorbaArray(request.docSet, &corbaRequest.docSet);
|
---|
| 767 | corbaRequest.filterResultOptions = request.filterResultOptions;
|
---|
| 768 | corbaconv_text_t::getCorbatext(request.requestParams,corbaRequest.requestParams);
|
---|
| 769 | corbaconv_text_t::getCorbatext(request.refParams,corbaRequest.refParams);
|
---|
| 770 | corbaRequest.getParents = request.getParents;
|
---|
| 771 | corbatext_setToCorbaArray(request.fields, &corbaRequest.fields);
|
---|
| 772 |
|
---|
| 773 | corbaResponse.numDocs = response.numDocs;
|
---|
| 774 | corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
|
---|
| 775 |
|
---|
| 776 | // execute the corba transaction
|
---|
| 777 | lclient->filter (corbaCollection, corbaRequest, corbaResponse, corbaError);
|
---|
| 778 |
|
---|
| 779 | // convert the response back to normal form
|
---|
| 780 | response.numDocs = corbaResponse.numDocs;
|
---|
[2113] | 781 | response.isApprox = (enum isapprox) corbaResponse.isApprox;
|
---|
[1860] | 782 | corbaresponse_resultDocInfoToC(corbaResponse.docInfo, response.docInfo);
|
---|
| 783 |
|
---|
[1983] | 784 | // Added 31/1/2001, Michael Dewsnip
|
---|
| 785 | corbaresponse_resultTermInfoToC(corbaResponse.termInfo, response.termInfo);
|
---|
| 786 |
|
---|
[1860] | 787 | err = (comerror_t) corbaError;
|
---|
[25231] | 788 | // std::cout << "Corbaproto::Filter" << std::endl;
|
---|
[1860] | 789 | }
|
---|
| 790 |
|
---|
[1983] | 791 |
|
---|
[1860] | 792 | void corbaproto::get_document (const text_t &collection,
|
---|
| 793 | const DocumentRequest_t &request,
|
---|
| 794 | DocumentResponse_t &response,
|
---|
| 795 | comerror_t &err, ostream &logout) {
|
---|
[25231] | 796 | // std::cout << "Corbaproto::Get Document" << std::endl;
|
---|
[1860] | 797 |
|
---|
| 798 | corbatext_t corbaCollect;
|
---|
| 799 | corbaDocRequest corbaRequest;
|
---|
| 800 | corbaDocResponse corbaResponse;
|
---|
[2223] | 801 | corbaComError corbaError = corbaNoError;
|
---|
[1860] | 802 |
|
---|
| 803 | // get the corba client reference
|
---|
| 804 | // corbaiface_var lclient = this->getCorbaClient(); // ****
|
---|
| 805 | corbaiface_var lclient = client;
|
---|
| 806 |
|
---|
| 807 | // convert all the requisite structures into their CORBA form
|
---|
| 808 | corbaconv_text_t::getCorbatext(collection,corbaCollect);
|
---|
| 809 | corbaconv_text_t::getCorbatext(request.OID,corbaRequest.OID);
|
---|
| 810 | corbaconv_text_t::getCorbatext(request.docType,corbaRequest.docType);
|
---|
| 811 | corbaconv_text_t::getCorbatext(request.docFormat,corbaRequest.docFormat);
|
---|
| 812 |
|
---|
| 813 | // execute the corba transaction
|
---|
| 814 | lclient->getDocument(corbaCollect, corbaRequest, corbaResponse, corbaError);
|
---|
| 815 |
|
---|
| 816 | // convert the response back to normal form
|
---|
| 817 | corbaconv_text_t::setCorbatext(response.doc,corbaResponse.doc);
|
---|
| 818 |
|
---|
| 819 | err = (comerror_t) corbaError;
|
---|
| 820 | }
|
---|
| 821 |
|
---|