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  }
75  if ( _requests )
76  {
77  delete _requests ;
78  _requests = 0 ;
79  }
81 }
82 
90 int
92 {
93  BESApacheInterface interface( re ) ;
94  int status = interface.execute_request() ;
95  if( status != 0 )
96  {
97  interface.finish_with_error( status ) ;
98  }
99  return status ;
100 }
101 
106 void
108 {
109  BESProcessEncodedString h( s ) ;
110  string str = h.get_key( "request" ) ;
111  _requests = new BESApacheRequests( str ) ;
112 }
113 
114 const char *
116 {
117  if( _requests )
118  {
121  if( rcurr == rend )
122  return 0 ;
123  return (*rcurr).c_str() ;
124  }
125  return 0 ;
126 }
127 
128 const char *
130 {
131  if( _requests )
132  {
133  static BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
134  static BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
135  if( rcurr == rend )
136  return 0 ;
137  ++rcurr ;
138  if( rcurr == rend )
139  return 0 ;
140  return (*rcurr).c_str() ;
141  }
142  return 0 ;
143 }
144 
150 const char *
152 {
153  BESProcessEncodedString h( s ) ;
154  string str = h.get_key( "username" ) ;
155  if( str == "" )
156  {
157  _user_name = new char[strlen( str.c_str() ) + 1] ;
158  strcpy( _user_name, str.c_str() ) ;
159  }
160  else
161  {
162  _user_name = new char[strlen( str.c_str() ) + 20] ;
163  sprintf( _user_name, "OpenDAP.remoteuser=%s", str.c_str() ) ;
164  }
165  return _user_name ;
166 }
167 
173 const char *
175 {
176  BESProcessEncodedString h( s ) ;
177  string str = h.get_key( "token" ) ;
178  _token = new char[strlen( str.c_str() ) + 1] ;
179  strcpy( _token, str.c_str() ) ;
180  return _token ;
181 }
182