[8182] | 1 | #include "oaimain.h"
|
---|
| 2 |
|
---|
| 3 | /**********************************************************************
|
---|
| 4 | *
|
---|
| 5 | * oaimain.cpp --
|
---|
| 6 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 7 | *
|
---|
| 8 | * A component of the Greenstone digital library software
|
---|
| 9 | * from the New Zealand Digital Library Project at the
|
---|
| 10 | * University of Waikato, New Zealand.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
[9408] | 28 | #include "gsdlconf.h"
|
---|
| 29 |
|
---|
[8306] | 30 | #if defined(GSDL_USE_IOS_H)
|
---|
| 31 | # if defined(__WIN32__)
|
---|
| 32 | # include <strstrea.h> // vc4
|
---|
| 33 | # else
|
---|
| 34 | # include <strstream.h>
|
---|
| 35 | # endif
|
---|
[8182] | 36 | #else
|
---|
[8306] | 37 | # include <sstream>
|
---|
[8182] | 38 | #endif
|
---|
| 39 |
|
---|
| 40 | #include "fileutil.h"
|
---|
| 41 | #include "nullproto.h"
|
---|
| 42 | #include "collectset.h"
|
---|
| 43 | #include "cgiargs.h"
|
---|
| 44 |
|
---|
[15844] | 45 | #include "identifyaction.h"
|
---|
[8182] | 46 | #include "recordaction.h"
|
---|
| 47 | #include "listsetsaction.h"
|
---|
| 48 | #include "listrecsaction.h"
|
---|
| 49 | #include "listidsaction.h"
|
---|
| 50 | #include "metaformatsaction.h"
|
---|
| 51 | #include "oaidispatcher.h"
|
---|
| 52 | #include "oaiconfig.h"
|
---|
| 53 |
|
---|
| 54 | void get_cgi_args(text_t &argstring)
|
---|
| 55 | {
|
---|
| 56 | // get the query string if it is not being run as a fastcgi
|
---|
| 57 | // script
|
---|
| 58 | text_t argstr = "";
|
---|
| 59 | char *aURIStr;
|
---|
| 60 | char *request_method_str = getenv("REQUEST_METHOD");
|
---|
| 61 | char *content_length_str = getenv("CONTENT_LENGTH");
|
---|
| 62 | if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
|
---|
| 63 | content_length_str != NULL) {
|
---|
| 64 | // POST form data
|
---|
| 65 | int content_length = text_t(content_length_str).getint();
|
---|
| 66 | if (content_length > 0) {
|
---|
| 67 | char c;
|
---|
| 68 | do {
|
---|
| 69 | cin.get(c);
|
---|
| 70 | if (cin.eof())
|
---|
| 71 | break;
|
---|
| 72 | argstr.push_back (c);
|
---|
[9608] | 73 | --content_length;
|
---|
[8182] | 74 | } while (content_length > 0);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | } else {
|
---|
| 78 | aURIStr = getenv("QUERY_STRING");
|
---|
| 79 | if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
|
---|
| 80 | || aURIStr != NULL) {
|
---|
| 81 | // GET form data
|
---|
| 82 | if (aURIStr != NULL)
|
---|
| 83 | argstr = aURIStr;
|
---|
| 84 | } else {
|
---|
| 85 | // debugging from command line
|
---|
| 86 | // debug = true;
|
---|
| 87 | char inStr[1024];
|
---|
| 88 |
|
---|
| 89 | cin.get(inStr, 1024);
|
---|
| 90 | argstr = inStr;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | argstring = argstr;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[9408] | 96 |
|
---|
[8182] | 97 | int main(int argc, char *argv[])
|
---|
| 98 | {
|
---|
| 99 | text_t cgiargstring;
|
---|
| 100 | nullproto nproto;
|
---|
| 101 | collectset *cservers;
|
---|
| 102 | text_t gsdlhome;
|
---|
[16310] | 103 | text_t collecthome;
|
---|
[8182] | 104 | text_t gsdlcollect = "";
|
---|
| 105 | oaiargs args;
|
---|
[8314] | 106 | ofstream logout("oai.log", ios::app);
|
---|
| 107 |
|
---|
[8182] | 108 | // convert cgi to oai map
|
---|
| 109 | get_cgi_args(cgiargstring);
|
---|
| 110 |
|
---|
| 111 | char *cstr = cgiargstring.getcstr();
|
---|
[8330] | 112 | #if defined(GSDL_USE_IOS_H)
|
---|
| 113 | istrstream cgi_in(cstr, cgiargstring.size());
|
---|
| 114 | #else
|
---|
[8317] | 115 | istringstream cgi_in(cstr);
|
---|
[8330] | 116 | #endif
|
---|
[8182] | 117 |
|
---|
| 118 | // parse the arguments
|
---|
| 119 | args.readArgs(cgi_in);
|
---|
| 120 |
|
---|
[9632] | 121 | delete []cstr;
|
---|
[8182] | 122 |
|
---|
[16310] | 123 | cservers = new collectset(gsdlhome,collecthome);
|
---|
[8182] | 124 |
|
---|
| 125 | // set up the null protocol
|
---|
| 126 | nproto.set_collectset(cservers);
|
---|
| 127 |
|
---|
| 128 | // get the oai configuration
|
---|
| 129 | oaiconfig config(gsdlhome, gsdlcollect);
|
---|
| 130 |
|
---|
| 131 | // set up the dispatcher
|
---|
| 132 | oaidispatcher dispatcher;
|
---|
| 133 | dispatcher.setConfiguration(&config);
|
---|
| 134 |
|
---|
[15844] | 135 | identifyaction *id = new identifyaction;
|
---|
[18890] | 136 | recordaction *rec = new recordaction(config.getMetadataSet());
|
---|
[8182] | 137 | listsetsaction *sets = new listsetsaction;
|
---|
| 138 | listrecsaction *records = new listrecsaction;
|
---|
| 139 | records->set_recordMaker(rec);
|
---|
| 140 |
|
---|
| 141 | listidsaction *ids = new listidsaction;
|
---|
| 142 | metaformatsaction *formats = new metaformatsaction;
|
---|
| 143 | formats->set_formats(rec->get_formats());
|
---|
| 144 |
|
---|
| 145 | dispatcher.addAction(id);
|
---|
| 146 | dispatcher.addAction(rec);
|
---|
| 147 | dispatcher.addAction(sets);
|
---|
| 148 | dispatcher.addAction(records);
|
---|
| 149 | dispatcher.addAction(ids);
|
---|
| 150 | dispatcher.addAction(formats);
|
---|
| 151 |
|
---|
| 152 | // deal with this request
|
---|
| 153 | comerror_t error;
|
---|
[8314] | 154 | nproto.init(error, logout);
|
---|
[8182] | 155 |
|
---|
| 156 | // GRB: any checks that a collection exists would be done here
|
---|
| 157 | // At present, I foresee no useful application of that requirement.
|
---|
| 158 |
|
---|
| 159 | dispatcher.doAction(cout, &nproto, args);
|
---|
| 160 |
|
---|
| 161 | delete cservers;
|
---|
| 162 | return 0;
|
---|
| 163 | }
|
---|