00001 // BESApacheWrapper.cc 00002 00003 // This file is part of bes, A C++ back-end server implementation framework 00004 // for the OPeNDAP Data Access Protocol. 00005 00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research 00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu> 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // You can contact University Corporation for Atmospheric Research at 00024 // 3080 Center Green Drive, Boulder, CO 80301 00025 00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005 00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR. 00028 // 00029 // Authors: 00030 // pwest Patrick West <pwest@ucar.edu> 00031 // jgarcia Jose Garcia <jgarcia@ucar.edu> 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