source: gsdl/trunk/runtime-src/src/oaiservr/oaimain.cpp@ 19294

Last change on this file since 19294 was 18890, checked in by kjdon, 15 years ago

pass metadata set to recordaction constructor

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