BESApacheWrapper.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string>
00034
00035 using std::string ;
00036
00037 #include "BESApacheWrapper.h"
00038 #include "BESApacheRequests.h"
00039 #include "BESApacheInterface.h"
00040 #include "BESProcessEncodedString.h"
00041 #include "BESGlobalIQ.h"
00042 #include "BESDefaultModule.h"
00043 #include "BESDefaultCommands.h"
00044
00045 BESApacheWrapper::BESApacheWrapper()
00046 {
00047 _data_request = 0 ;
00048 _user_name = 0 ;
00049 _token = 0 ;
00050 _requests = 0 ;
00051
00052 BESDefaultModule::initialize( 0, 0 ) ;
00053 BESDefaultCommands::initialize( 0, 0 ) ;
00054
00055 BESGlobalIQ::BESGlobalInit( 0, 0 ) ;
00056 }
00057
00058 BESApacheWrapper::~BESApacheWrapper()
00059 {
00060 if( _data_request )
00061 {
00062 delete [] _data_request ;
00063 _data_request = 0 ;
00064 }
00065 if( _user_name )
00066 {
00067 delete [] _user_name ;
00068 _user_name = 0 ;
00069 }
00070 if( _token )
00071 {
00072 delete [] _token ;
00073 _token = 0 ;
00074 }
00075 BESGlobalIQ::BESGlobalQuit() ;
00076 }
00077
00085 int
00086 BESApacheWrapper::call_BES( const BESDataRequestInterface & re )
00087 {
00088 BESApacheInterface interface( re ) ;
00089 int status = interface.execute_request() ;
00090 if( status != 0 )
00091 {
00092 interface.finish_with_error( status ) ;
00093 }
00094 return status ;
00095 }
00096
00101 void
00102 BESApacheWrapper::process_request(const char*s)
00103 {
00104 BESProcessEncodedString h( s ) ;
00105 string str = h.get_key( "request" ) ;
00106 _requests = new BESApacheRequests( str ) ;
00107 }
00108
00109 const char *
00110 BESApacheWrapper::get_first_request()
00111 {
00112 if( _requests )
00113 {
00114 BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00115 BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00116 if( rcurr == rend )
00117 return 0 ;
00118 return (*rcurr).c_str() ;
00119 }
00120 return 0 ;
00121 }
00122
00123 const char *
00124 BESApacheWrapper::get_next_request()
00125 {
00126 if( _requests )
00127 {
00128 static BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00129 static BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00130 if( rcurr == rend )
00131 return 0 ;
00132 rcurr++ ;
00133 if( rcurr == rend )
00134 return 0 ;
00135 return (*rcurr).c_str() ;
00136 }
00137 return 0 ;
00138 }
00139
00145 const char *
00146 BESApacheWrapper::process_user(const char*s)
00147 {
00148 BESProcessEncodedString h( s ) ;
00149 string str = h.get_key( "username" ) ;
00150 if( str == "" )
00151 {
00152 _user_name = new char[strlen( str.c_str() ) + 1] ;
00153 strcpy( _user_name, str.c_str() ) ;
00154 }
00155 else
00156 {
00157 _user_name = new char[strlen( str.c_str() ) + 20] ;
00158 sprintf( _user_name, "OpenDAP.remoteuser=%s", str.c_str() ) ;
00159 }
00160 return _user_name ;
00161 }
00162
00168 const char *
00169 BESApacheWrapper::process_token(const char*s)
00170 {
00171 BESProcessEncodedString h( s ) ;
00172 string str = h.get_key( "token" ) ;
00173 _token = new char[strlen( str.c_str() ) + 1] ;
00174 strcpy( _token, str.c_str() ) ;
00175 return _token ;
00176 }
00177