root/gsdl/trunk/runtime-src/src/oaiservr/oaimain.cpp @ 20589

Revision 20589, 4.3 KB (checked in by mdewsnip, 10 years ago)

Removed some unnecessary #includes.

  • Property svn:keywords set to Author Date Id Revision
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#  if defined(__WIN32__)
32#    include <strstrea.h> // vc4
33#  else
34#    include <strstream.h>
35#  endif
36#else
37#  include <sstream>
38#endif
39
40#include "fileutil.h"
41#include "nullproto.h"
42#include "collectset.h"
43#include "cgiargs.h"
44
45#include "identifyaction.h"
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
54void 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);
73    --content_length;
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
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        collecthome;
104  text_t        gsdlcollect = "";
105  oaiargs       args;
106  ofstream      logout("oai.log", ios::app);
107 
108  // convert cgi to oai map
109  get_cgi_args(cgiargstring);
110 
111  char *cstr = cgiargstring.getcstr();
112#if defined(GSDL_USE_IOS_H)
113  istrstream cgi_in(cstr, cgiargstring.size());
114#else
115  istringstream cgi_in(cstr);
116#endif
117
118  // parse the arguments
119  args.readArgs(cgi_in);
120
121  delete []cstr;
122 
123  cservers = new collectset(gsdlhome,collecthome);
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
135  identifyaction *id   = new identifyaction;
136  recordaction   *rec  = new recordaction(config.getMetadataSet());
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;
154  nproto.init(error, logout);
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}
Note: See TracBrowser for help on using the browser.