source: main/tags/2.53/gsdl/src/oaiservr/oaimain.cpp@ 33212

Last change on this file since 33212 was 8330, checked in by mdewsnip, 20 years ago

Fixed yesterday's fix so it works with Microsoft Visual C++ 4.

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