1 | // Standard headers
|
---|
2 | #include <iostream.h>
|
---|
3 | #include <fstream.h>
|
---|
4 |
|
---|
5 | // protocol headers
|
---|
6 | #include "corbaiface.h"
|
---|
7 | using namespace gsdlInterface;
|
---|
8 |
|
---|
9 | #include "corbaconv_text_t.h"
|
---|
10 |
|
---|
11 | // library headers
|
---|
12 | #include "fileutil.h"
|
---|
13 | //#include "gsdlhome.h"
|
---|
14 |
|
---|
15 | // greenstone headers
|
---|
16 | #include "comtypes.h"
|
---|
17 | #include "recptproto.h"
|
---|
18 | #include "nullproto.h"
|
---|
19 |
|
---|
20 | // local headers
|
---|
21 | #include "corbatext_t.h"
|
---|
22 |
|
---|
23 | void corbatext_setToCorbaArray(text_tset set, corbatext_tset *cset);
|
---|
24 | void corbatext_corbaArrayToSet(corbatext_tset cset, text_tset *set);
|
---|
25 | void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *tm);
|
---|
26 | void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo);
|
---|
27 |
|
---|
28 | void corbaresponse_termInfoToCorba(TermInfo_tarray terminfo, corbaTermInfo_array &corbainfo) {
|
---|
29 | TermInfo_tarray::iterator here = terminfo.begin();
|
---|
30 | TermInfo_tarray::iterator end = terminfo.end();
|
---|
31 | unsigned int i;
|
---|
32 |
|
---|
33 | i = 0;
|
---|
34 |
|
---|
35 | while (here != end)
|
---|
36 | {
|
---|
37 | corbainfo.length(i+1);
|
---|
38 |
|
---|
39 | corbainfo[i].frequency = here->freq;
|
---|
40 | corbaconv_text_t::getCorbatext(here->term,corbainfo[i].term);
|
---|
41 | corbatext_arrayToCorbaArray(here->matchTerms, &corbainfo[i].matchTerms);
|
---|
42 |
|
---|
43 | i ++;
|
---|
44 | here ++;
|
---|
45 | }
|
---|
46 | cout << "Terminfo " << i << endl;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void corbatext_optionValueArrayToC(corbaOptionValue_array corba, OptionValue_tarray &array)
|
---|
50 | {
|
---|
51 | unsigned int i = 0;
|
---|
52 | OptionValue_t option;
|
---|
53 |
|
---|
54 | for (i = 0; i < corba.length(); i ++)
|
---|
55 | {
|
---|
56 | corbaconv_text_t::setCorbatext(option.name,corba[i].name);
|
---|
57 | corbaconv_text_t::setCorbatext(option.value,corba[i].value);
|
---|
58 |
|
---|
59 | // cout << corbatext_string(corba[i].name) << "?" << option
|
---|
60 |
|
---|
61 | array.push_back(option);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | class corbaServer : virtual public corbaiface_skel
|
---|
66 | {
|
---|
67 | private:
|
---|
68 | text_tarray collections;
|
---|
69 | recptproto *protocol;
|
---|
70 | text_t gsdlhome;
|
---|
71 |
|
---|
72 | void openLogfile(text_t extension, ofstream &out)
|
---|
73 | {
|
---|
74 | char *cfilename;
|
---|
75 | text_t filename;
|
---|
76 |
|
---|
77 | filename = filename_cat(gsdlhome, extension);
|
---|
78 | cfilename = filename.getcstr();
|
---|
79 |
|
---|
80 | out.open(cfilename);
|
---|
81 | delete cfilename;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public:
|
---|
85 | corbaServer(recptproto *protocol, text_t home)
|
---|
86 | {
|
---|
87 | text_t dirname;
|
---|
88 | char * cdirname;
|
---|
89 |
|
---|
90 | cout << "CorbaServer: gsdlhome = " << home << endl;
|
---|
91 |
|
---|
92 | this->gsdlhome = home;
|
---|
93 | cout << gsdlhome.getcstr() << endl;
|
---|
94 | dirname = filename_cat(gsdlhome, "/collect");
|
---|
95 | cdirname = dirname.getcstr();
|
---|
96 | if (!read_dir (cdirname, collections)) exit (1);
|
---|
97 | delete cdirname;
|
---|
98 |
|
---|
99 | cout << "Constructing set list server" << endl;
|
---|
100 | this->protocol = protocol;
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 | CORBA::Boolean initialise(corbaComError &err)
|
---|
105 | {
|
---|
106 | ofstream logout;
|
---|
107 | int reply;
|
---|
108 | comerror_t error;
|
---|
109 |
|
---|
110 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
111 | reply = protocol->init(error, logout);
|
---|
112 | logout.close();
|
---|
113 | return (reply != 0 ? 1 : 0);
|
---|
114 | }
|
---|
115 |
|
---|
116 | void configure(const corbatext_t &corbaKey, const corbatext_tarray &corbaCfgline,corbaComError &err)
|
---|
117 | {
|
---|
118 | text_t key;
|
---|
119 | text_tarray cfgline;
|
---|
120 | comerror_t error;
|
---|
121 |
|
---|
122 | corbaconv_text_t::setCorbatext(key,corbaKey);
|
---|
123 | corbatext_corbaArrayToArray(corbaCfgline, &cfgline);
|
---|
124 |
|
---|
125 |
|
---|
126 | // ****
|
---|
127 | cout << "Recieved " << key << " = ";
|
---|
128 | for (int unsigned i=0; i<cfgline.size(); i++)
|
---|
129 | {
|
---|
130 | cout << cfgline[i] << " ";
|
---|
131 | }
|
---|
132 | cout << endl;
|
---|
133 |
|
---|
134 | // DB // ****
|
---|
135 | if (key=="gsdlhome")
|
---|
136 | {
|
---|
137 | text_tarray cfgline;
|
---|
138 | cfgline.push_back (gsdlhome);
|
---|
139 | cout << "Changing gsdlhome to " << gsdlhome << endl;
|
---|
140 | protocol->configure(key, cfgline, error);
|
---|
141 | }
|
---|
142 | else if (key=="httpdomain")
|
---|
143 | {
|
---|
144 | // Only let gsdlhome through !!!! // ****
|
---|
145 | cout << "Supressing httpdomain" << endl;
|
---|
146 | }
|
---|
147 | else if (key=="httpprefix")
|
---|
148 | {
|
---|
149 | cout << "Supressing httpprefix" << endl;
|
---|
150 | }
|
---|
151 | else
|
---|
152 | {
|
---|
153 | protocol->configure(key, cfgline,error);
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | void hasCollection(const corbatext_t &corbaCollect, CORBA::Boolean &has,
|
---|
158 | corbaComError &error) {
|
---|
159 | // do nowt!
|
---|
160 | corbaconv_text_t *cct;
|
---|
161 | bool _has;
|
---|
162 | comerror_t err;
|
---|
163 | ofstream logout;
|
---|
164 |
|
---|
165 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
166 |
|
---|
167 | cct = new corbaconv_text_t(corbaCollect);
|
---|
168 |
|
---|
169 | cout << "Collection: " << cct->getcstr() << endl;
|
---|
170 |
|
---|
171 | protocol->has_collection(*cct, _has, err, logout); // 'cct' typecast to text_t
|
---|
172 | if (_has)
|
---|
173 | {
|
---|
174 | has = 1;
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | has = 0;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // cout << " " << has << endl;
|
---|
182 |
|
---|
183 | delete cct;
|
---|
184 |
|
---|
185 | error = corbaNoError;
|
---|
186 | logout.close();
|
---|
187 | }
|
---|
188 |
|
---|
189 | void ping(const struct corbatext_t &corbaCollect, CORBA::Boolean &wasSuccess, corbaComError &corbaError)
|
---|
190 | {
|
---|
191 | text_t collection;
|
---|
192 | bool success;
|
---|
193 | comerror_t error;
|
---|
194 | ofstream logout;
|
---|
195 |
|
---|
196 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
197 |
|
---|
198 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
199 | protocol->ping(collection, success, error, logout);
|
---|
200 |
|
---|
201 | corbaError = (corbaComError) error;
|
---|
202 | wasSuccess = (CORBA::Boolean) success;
|
---|
203 | logout.close();
|
---|
204 | }
|
---|
205 |
|
---|
206 | void filter(const struct corbatext_t &corbaCollect,
|
---|
207 | const struct corbaFilterRequest &corbaRequest,
|
---|
208 | struct corbaFilterResponse &corbaResponse,
|
---|
209 | corbaComError &corbaError)
|
---|
210 | {
|
---|
211 | // variables for action
|
---|
212 | FilterRequest_t request;
|
---|
213 | FilterResponse_t response;
|
---|
214 | comerror_t error = noError;
|
---|
215 | text_t collection;
|
---|
216 | ofstream logout;
|
---|
217 |
|
---|
218 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
219 |
|
---|
220 | // copy collection id
|
---|
221 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
222 |
|
---|
223 | // copy request values
|
---|
224 | corbaconv_text_t::setCorbatext(request.filterName,corbaRequest.filter);
|
---|
225 | corbatext_optionValueArrayToC(corbaRequest.filterOptions, request.filterOptions);
|
---|
226 | corbatext_corbaArrayToArray(corbaRequest.docSet, &request.docSet);
|
---|
227 | request.filterResultOptions = corbaRequest.filterResultOptions;
|
---|
228 | corbaconv_text_t::setCorbatext(request.requestParams,corbaRequest.requestParams);
|
---|
229 | corbaconv_text_t::setCorbatext(request.refParams,corbaRequest.refParams);
|
---|
230 | corbatext_corbaArrayToSet(corbaRequest.fields, &request.fields);
|
---|
231 | request.getParents = corbaRequest.getParents;
|
---|
232 |
|
---|
233 | protocol->filter(collection, request, response, error, logout);
|
---|
234 |
|
---|
235 | // copy response values
|
---|
236 | corbaResponse.numDocs = response.numDocs;
|
---|
237 | corbaResponse.isApprox = (::gsdlInterface::corbaIsApprox) response.isApprox;
|
---|
238 | corbaresponse_termInfoToCorba(response.termInfo, corbaResponse.termInfo);
|
---|
239 | corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
|
---|
240 |
|
---|
241 | // tidy up variables
|
---|
242 | logout.close();
|
---|
243 | corbaError = (corbaComError) error;
|
---|
244 | cout << "Filter prepared" << corbaResponse.docInfo.length() << "," << corbaResponse.numDocs << endl;
|
---|
245 | }
|
---|
246 |
|
---|
247 | void getCollectInfo(const struct corbatext_t &corbaCollect,
|
---|
248 | corbaColInfoResponse &corbaResponse,
|
---|
249 | corbaComError &corbaError)
|
---|
250 | {
|
---|
251 | ColInfoResponse_t response;
|
---|
252 | comerror_t error;
|
---|
253 | text_t collection;
|
---|
254 | ofstream logout;
|
---|
255 |
|
---|
256 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
257 |
|
---|
258 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
259 | protocol->get_collectinfo(collection, response, error, logout);
|
---|
260 |
|
---|
261 | cout << "IsPublic = " << ((response.isPublic)?"True":"False") << endl;
|
---|
262 | cout << "IsBeta = " << ((response.isBeta) ?"True":"False") << endl;
|
---|
263 | cout << "BuildDate = " << response.buildDate << endl;
|
---|
264 | cout << "NumDocs = " << response.numDocs << endl;
|
---|
265 | cout << "NumBytes = " << response.numBytes << endl;
|
---|
266 | cout << "NumWords = " << response.numWords << endl;
|
---|
267 |
|
---|
268 | corbaResponse.isPublic = response.isPublic;
|
---|
269 | corbaResponse.isBeta = response.isBeta;
|
---|
270 | corbaResponse.buildDate = response.buildDate;
|
---|
271 | corbatext_arrayToCorbaArray(response.languages, &corbaResponse.languages);
|
---|
272 | corbatext_arrayToCorbaArray(response.ccsCols, &corbaResponse.ccsCols);
|
---|
273 | corbaResponse.numDocs = response.numDocs;
|
---|
274 | corbaResponse.numBytes = response.numWords;
|
---|
275 | corbaResponse.numWords = response.numBytes;
|
---|
276 |
|
---|
277 | corbatext_mapToCorbaMap(response.collectionmeta, &corbaResponse.collectionMeta);
|
---|
278 | corbatext_mapToCorbaMap(response.format, &corbaResponse.format);
|
---|
279 | corbatext_mapToCorbaMap(response.building, &corbaResponse.building);
|
---|
280 | corbaconv_text_t::getCorbatext(response.httpdomain,corbaResponse.httpdomain);
|
---|
281 |
|
---|
282 | corbaconv_text_t::getCorbatext(response.httpprefix,corbaResponse.httpprefix);
|
---|
283 | corbaconv_text_t::getCorbatext(response.receptionist,corbaResponse.receptionist);
|
---|
284 |
|
---|
285 | /* text_tmap::iterator f_here = response.format.begin();
|
---|
286 | text_tmap::iterator f_end = response.format.end();
|
---|
287 | while (f_here!=f_end)
|
---|
288 | {
|
---|
289 | cout << "**** format: " << f_here->first << " = " << f_here->second << endl;
|
---|
290 | f_here++;
|
---|
291 | }
|
---|
292 | */ // ****
|
---|
293 |
|
---|
294 | logout.close();
|
---|
295 | corbaError = (corbaComError) error;
|
---|
296 | }
|
---|
297 |
|
---|
298 | void getFilterOptions(const struct corbatext_t &corbaCollect,
|
---|
299 | const struct corbatext_t &corbaFilterName,
|
---|
300 | struct corbaFilterOptionsResponse &corbaResponse,
|
---|
301 | enum corbaComError &corbaError)
|
---|
302 | {
|
---|
303 | text_t collection;
|
---|
304 | InfoFilterOptionsRequest_t request;
|
---|
305 | InfoFilterOptionsResponse_t response;
|
---|
306 | comerror_t error;
|
---|
307 | unsigned int i;
|
---|
308 | ofstream logout;
|
---|
309 |
|
---|
310 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
311 |
|
---|
312 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
313 | corbaconv_text_t::setCorbatext(request.filterName,corbaFilterName);
|
---|
314 | protocol->get_filteroptions(collection, request, response, error, logout);
|
---|
315 |
|
---|
316 | // decode filters back into corba format
|
---|
317 | FilterOption_tmap::iterator here = response.filterOptions.begin();
|
---|
318 | FilterOption_tmap::iterator end = response.filterOptions.end();
|
---|
319 | i = 0;
|
---|
320 | while (here != end)
|
---|
321 | {
|
---|
322 | // set array for name/options to be one bigger
|
---|
323 | corbaResponse.names.length(i+1);
|
---|
324 | corbaResponse.options.length(i+1);
|
---|
325 |
|
---|
326 | // get left-hand side of map
|
---|
327 | corbaconv_text_t::getCorbatext((*here).first,corbaResponse.names[i]);
|
---|
328 |
|
---|
329 | // get right-hand side of map
|
---|
330 | corbaconv_text_t::getCorbatext((*here).second.name,corbaResponse.options[i].name);
|
---|
331 | corbaResponse.options[i].type =
|
---|
332 | (::gsdlInterface::corbaFilterType)(*here).second.type;
|
---|
333 | corbaResponse.options[i].repeatable =
|
---|
334 | (::gsdlInterface::corbaFilterRepeatable)(*here).second.repeatable;
|
---|
335 | corbaconv_text_t::getCorbatext((*here).second.defaultValue,corbaResponse.options[i].defaultValue);
|
---|
336 | corbatext_arrayToCorbaArray((*here).second.validValues, &corbaResponse.options[i].validValues);
|
---|
337 |
|
---|
338 | // take next iterators
|
---|
339 | i++;
|
---|
340 | here ++;
|
---|
341 | }
|
---|
342 |
|
---|
343 | logout.close();
|
---|
344 | corbaError = (corbaComError) error;
|
---|
345 | }
|
---|
346 |
|
---|
347 | void getFilterInfo(const struct corbatext_t &corbaCollect,
|
---|
348 | corbatext_tarray &filterNames,
|
---|
349 | enum corbaComError &corbaError)
|
---|
350 | { text_tarray ta;
|
---|
351 | comerror_t error = noError;
|
---|
352 | text_t collection;
|
---|
353 | InfoFiltersResponse_t response;
|
---|
354 | ofstream logout;
|
---|
355 |
|
---|
356 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
357 |
|
---|
358 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
359 | cout << collection.getcstr() << endl;
|
---|
360 |
|
---|
361 | protocol->get_filterinfo(collection, response, error, logout);
|
---|
362 | corbatext_setToCorbaArray(response.filterNames, &filterNames);
|
---|
363 |
|
---|
364 | corbaError = (corbaComError) error;
|
---|
365 | logout.close();
|
---|
366 | }
|
---|
367 |
|
---|
368 | void getDocument(const struct corbatext_t &corbaCollection, struct corbaDocRequest &corbaRequest,
|
---|
369 | struct corbaDocResponse &corbaResponse, enum corbaComError &corbaError)
|
---|
370 | { DocumentRequest_t request;
|
---|
371 | DocumentResponse_t response;
|
---|
372 | comerror_t error = noError;
|
---|
373 | text_t collection;
|
---|
374 | ofstream logout;
|
---|
375 |
|
---|
376 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
377 |
|
---|
378 | // set up request
|
---|
379 | corbaconv_text_t::setCorbatext(collection,corbaCollection);
|
---|
380 | corbaconv_text_t::setCorbatext(request.OID,corbaRequest.OID);
|
---|
381 | corbaconv_text_t::setCorbatext(request.docType,corbaRequest.docType);
|
---|
382 | corbaconv_text_t::setCorbatext(request.docFormat,corbaRequest.docFormat);
|
---|
383 |
|
---|
384 | // do actual get document
|
---|
385 | protocol->get_document(collection, request, response, error, logout);
|
---|
386 | corbaconv_text_t::getCorbatext(response.doc,corbaResponse.doc);
|
---|
387 |
|
---|
388 | // decode response
|
---|
389 | corbaError = (corbaComError) error;
|
---|
390 |
|
---|
391 | logout.close();
|
---|
392 | }
|
---|
393 |
|
---|
394 | void collectionList(corbatext_tarray &corbalist, corbaComError &error)
|
---|
395 | {
|
---|
396 | /* stringSeq *reply;
|
---|
397 | unsigned int i;
|
---|
398 | char *istring; */
|
---|
399 |
|
---|
400 | text_tarray collist;
|
---|
401 | comerror_t err;
|
---|
402 | ofstream logout;
|
---|
403 |
|
---|
404 | cout << "Received collection list request" << endl;
|
---|
405 |
|
---|
406 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
407 |
|
---|
408 | protocol->get_collection_list(collist, err, logout);
|
---|
409 |
|
---|
410 | /* reply = new stringSeq(collections.size());
|
---|
411 |
|
---|
412 | (*reply).length(collections.size());
|
---|
413 | for (i = 0; i < collections.size(); i ++)
|
---|
414 | {
|
---|
415 | istring = collections[i].getcstr();
|
---|
416 | (*reply)[i] = CORBA::string_dup(istring);
|
---|
417 | delete istring;
|
---|
418 | }
|
---|
419 |
|
---|
420 | return reply;
|
---|
421 | */
|
---|
422 |
|
---|
423 | corbatext_arrayToCorbaArray(collist, &corbalist);
|
---|
424 | cout << "Replying " << collist.size() << ": " << endl;
|
---|
425 |
|
---|
426 | for (int unsigned i = 0; i < collist.size(); i ++)
|
---|
427 | {
|
---|
428 | cout << collist[i];
|
---|
429 | if (i<collist.size()-1) cout << ", ";
|
---|
430 | }
|
---|
431 | cout << endl;
|
---|
432 |
|
---|
433 | logout.close();
|
---|
434 | // CORBA::string_dup(_listString);
|
---|
435 | }
|
---|
436 | };
|
---|
437 |
|
---|
438 | int main (int argc, char *argv[])
|
---|
439 | {
|
---|
440 | nullproto protocol;
|
---|
441 | collectset *cservers;
|
---|
442 | text_t gsdlhome;
|
---|
443 |
|
---|
444 | cservers = new collectset(gsdlhome);
|
---|
445 | protocol.set_collectset(cservers);
|
---|
446 |
|
---|
447 | cout << "Started Corba ..." << endl;
|
---|
448 |
|
---|
449 | // ORB initialization
|
---|
450 | CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "mico-local-orb" );
|
---|
451 | CORBA::BOA_var boa = orb->BOA_init( argc, argv, "mico-local-boa" );
|
---|
452 |
|
---|
453 | cout << "Initialised ORB and BOA" << endl;
|
---|
454 |
|
---|
455 | corbaServer* server = new corbaServer(&protocol, gsdlhome);
|
---|
456 |
|
---|
457 | cout << "Initialised server" << endl;
|
---|
458 |
|
---|
459 | CORBA::String_var ref = orb->object_to_string( server );
|
---|
460 |
|
---|
461 | cout << "Mapped Corba object to string" << endl;
|
---|
462 |
|
---|
463 | // write id to "naming service"
|
---|
464 | ofstream out ("/tmp/localcorba.objid");
|
---|
465 | out << ref << endl;
|
---|
466 | out.close ();
|
---|
467 |
|
---|
468 | cout << "Corba string is " << ref << endl;
|
---|
469 |
|
---|
470 | // indicate readiness and run
|
---|
471 | boa->impl_is_ready( CORBA::ImplementationDef::_nil() );
|
---|
472 | orb->run ();
|
---|
473 | CORBA::release( server );
|
---|
474 | return 0;
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|