OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESApacheWrapper.cc
Go to the documentation of this file.
1 // BESApacheWrapper.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <string>
34 
35 using std::string ;
36 
37 #include "BESApacheWrapper.h"
38 #include "BESApacheRequests.h"
39 #include "BESApacheInterface.h"
41 #include "BESGlobalIQ.h"
42 #include "BESDefaultModule.h"
43 #include "BESDefaultCommands.h"
44 
46 {
47  _data_request = 0 ;
48  _user_name = 0 ;
49  _token = 0 ;
50  _requests = 0 ;
51 
53  BESDefaultCommands::initialize( 0, 0 ) ;
54 
56 }
57 
59 {
60  if( _data_request )
61  {
62  delete [] _data_request ;
63  _data_request = 0 ;
64  }
65  if( _user_name )
66  {
67  delete [] _user_name ;
68  _user_name = 0 ;
69  }
70  if( _token )
71  {
72  delete [] _token ;
73  _token = 0 ;
74  }
76 }
77 
85 int
87 {
88  BESApacheInterface interface( re ) ;
89  int status = interface.execute_request() ;
90  if( status != 0 )
91  {
92  interface.finish_with_error( status ) ;
93  }
94  return status ;
95 }
96 
101 void
103 {
104  BESProcessEncodedString h( s ) ;
105  string str = h.get_key( "request" ) ;
106  _requests = new BESApacheRequests( str ) ;
107 }
108 
109 const char *
111 {
112  if( _requests )
113  {
116  if( rcurr == rend )
117  return 0 ;
118  return (*rcurr).c_str() ;
119  }
120  return 0 ;
121 }
122 
123 const char *
125 {
126  if( _requests )
127  {
128  static BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
129  static BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
130  if( rcurr == rend )
131  return 0 ;
132  rcurr++ ;
133  if( rcurr == rend )
134  return 0 ;
135  return (*rcurr).c_str() ;
136  }
137  return 0 ;
138 }
139 
145 const char *
147 {
148  BESProcessEncodedString h( s ) ;
149  string str = h.get_key( "username" ) ;
150  if( str == "" )
151  {
152  _user_name = new char[strlen( str.c_str() ) + 1] ;
153  strcpy( _user_name, str.c_str() ) ;
154  }
155  else
156  {
157  _user_name = new char[strlen( str.c_str() ) + 20] ;
158  sprintf( _user_name, "OpenDAP.remoteuser=%s", str.c_str() ) ;
159  }
160  return _user_name ;
161 }
162 
168 const char *
170 {
171  BESProcessEncodedString h( s ) ;
172  string str = h.get_key( "token" ) ;
173  _token = new char[strlen( str.c_str() ) + 1] ;
174  strcpy( _token, str.c_str() ) ;
175  return _token ;
176 }
177 
virtual requests_citer get_end_request()
static int initialize(int argc, char **argv)
virtual int execute_request()
Override execute_request in order to register memory pool.
const char * process_token(const char *s)
Find the session token from the URL and convert it to readable format.
const char * process_user(const char *s)
Find the username from the URL and convert it to readable format.
list< string >::const_iterator requests_citer
static bool BESGlobalQuit(void)
Runs the termination functions in reverse order of initialization, providing the application to clean...
Definition: BESGlobalIQ.cc:94
int call_BES(const BESDataRequestInterface &re)
Execute the given request using BESApacheInterface interface.
Structure storing information from the Apache module.
virtual requests_citer get_first_request()
const char * get_next_request()
void process_request(const char *s)
Find the request from the URL and convert it to readable format.
static bool BESGlobalInit(int argc, char **argv)
initialize global objects in an orderly fashion.
Definition: BESGlobalIQ.cc:61
Entry point into OPeNDAP using apache modules.
const char * get_first_request()
string get_key(const string &s)