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 |
|
---|
28 | #if defined(GSDL_USE_STL_H)
|
---|
29 | #include <fstream.h>
|
---|
30 | #include <strstream.h>
|
---|
31 | #else
|
---|
32 | #include <fstream>
|
---|
33 | #include <strstream>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include "fileutil.h"
|
---|
37 | #include "nullproto.h"
|
---|
38 | #include "collectset.h"
|
---|
39 | #include "cgiargs.h"
|
---|
40 | #include "OIDtools.h"
|
---|
41 |
|
---|
42 | #include "identityaction.h"
|
---|
43 | #include "recordaction.h"
|
---|
44 | #include "listsetsaction.h"
|
---|
45 | #include "listrecsaction.h"
|
---|
46 | #include "listidsaction.h"
|
---|
47 | #include "metaformatsaction.h"
|
---|
48 | #include "oaidispatcher.h"
|
---|
49 | #include "oaiconfig.h"
|
---|
50 |
|
---|
51 | void get_cgi_args(text_t &argstring)
|
---|
52 | {
|
---|
53 | // get the query string if it is not being run as a fastcgi
|
---|
54 | // script
|
---|
55 | text_t argstr = "";
|
---|
56 | char *aURIStr;
|
---|
57 | char *request_method_str = getenv("REQUEST_METHOD");
|
---|
58 | char *content_length_str = getenv("CONTENT_LENGTH");
|
---|
59 | if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
|
---|
60 | content_length_str != NULL) {
|
---|
61 | // POST form data
|
---|
62 | int content_length = text_t(content_length_str).getint();
|
---|
63 | if (content_length > 0) {
|
---|
64 | char c;
|
---|
65 | do {
|
---|
66 | cin.get(c);
|
---|
67 | if (cin.eof())
|
---|
68 | break;
|
---|
69 | argstr.push_back (c);
|
---|
70 | content_length--;
|
---|
71 | } while (content_length > 0);
|
---|
72 | }
|
---|
73 |
|
---|
74 | } else {
|
---|
75 | aURIStr = getenv("QUERY_STRING");
|
---|
76 | if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
|
---|
77 | || aURIStr != NULL) {
|
---|
78 | // GET form data
|
---|
79 | if (aURIStr != NULL)
|
---|
80 | argstr = aURIStr;
|
---|
81 | } else {
|
---|
82 | // debugging from command line
|
---|
83 | // debug = true;
|
---|
84 | char inStr[1024];
|
---|
85 |
|
---|
86 | cin.get(inStr, 1024);
|
---|
87 | argstr = inStr;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | argstring = argstr;
|
---|
91 | }
|
---|
92 |
|
---|
93 | int main(int argc, char *argv[])
|
---|
94 | {
|
---|
95 | text_t cgiargstring;
|
---|
96 | nullproto nproto;
|
---|
97 | collectset *cservers;
|
---|
98 | text_t gsdlhome;
|
---|
99 | text_t gsdlcollect = "";
|
---|
100 | oaiargs args;
|
---|
101 |
|
---|
102 | // convert cgi to oai map
|
---|
103 | get_cgi_args(cgiargstring);
|
---|
104 |
|
---|
105 | char *cstr = cgiargstring.getcstr();
|
---|
106 | istrstream cgi_in(cstr, cgiargstring.size());
|
---|
107 |
|
---|
108 | // parse the arguments
|
---|
109 | args.readArgs(cgi_in);
|
---|
110 |
|
---|
111 | delete cstr;
|
---|
112 |
|
---|
113 | cservers = new collectset(gsdlhome);
|
---|
114 |
|
---|
115 | // set up the null protocol
|
---|
116 | nproto.set_collectset(cservers);
|
---|
117 |
|
---|
118 | // get the oai configuration
|
---|
119 | oaiconfig config(gsdlhome, gsdlcollect);
|
---|
120 |
|
---|
121 | // set up the dispatcher
|
---|
122 | oaidispatcher dispatcher;
|
---|
123 | dispatcher.setConfiguration(&config);
|
---|
124 |
|
---|
125 | identityaction *id = new identityaction;
|
---|
126 | recordaction *rec = new recordaction;
|
---|
127 | listsetsaction *sets = new listsetsaction;
|
---|
128 | listrecsaction *records = new listrecsaction;
|
---|
129 | records->set_recordMaker(rec);
|
---|
130 |
|
---|
131 | listidsaction *ids = new listidsaction;
|
---|
132 | metaformatsaction *formats = new metaformatsaction;
|
---|
133 | formats->set_formats(rec->get_formats());
|
---|
134 |
|
---|
135 | dispatcher.addAction(id);
|
---|
136 | dispatcher.addAction(rec);
|
---|
137 | dispatcher.addAction(sets);
|
---|
138 | dispatcher.addAction(records);
|
---|
139 | dispatcher.addAction(ids);
|
---|
140 | dispatcher.addAction(formats);
|
---|
141 |
|
---|
142 | // deal with this request
|
---|
143 | // ofstream fout;
|
---|
144 | comerror_t error;
|
---|
145 | // fout.open("grb.txt");
|
---|
146 | nproto.init(error, cout);
|
---|
147 |
|
---|
148 | // GRB: any checks that a collection exists would be done here
|
---|
149 | // At present, I foresee no useful application of that requirement.
|
---|
150 |
|
---|
151 | dispatcher.doAction(cout, &nproto, args);
|
---|
152 |
|
---|
153 | delete cservers;
|
---|
154 | return 0;
|
---|
155 | }
|
---|