OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESApacheWrapper.cc
Go to the documentation of this file.
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-2009 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     if ( _requests )
00076     {
00077         delete _requests ;
00078         _requests = 0 ;
00079     }
00080     BESGlobalIQ::BESGlobalQuit() ;
00081 }
00082 
00090 int
00091 BESApacheWrapper::call_BES( const BESDataRequestInterface & re )
00092 {
00093     BESApacheInterface interface( re ) ;
00094     int status = interface.execute_request() ;
00095     if( status != 0 )
00096     {
00097         interface.finish_with_error( status ) ;
00098     }
00099     return status ;
00100 }
00101 
00106 void
00107 BESApacheWrapper::process_request(const char*s)
00108 {
00109     BESProcessEncodedString h( s ) ;
00110     string str = h.get_key( "request" ) ;
00111     _requests = new BESApacheRequests( str ) ;
00112 }
00113 
00114 const char *
00115 BESApacheWrapper::get_first_request()
00116 {
00117     if( _requests )
00118     {
00119         BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00120         BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00121         if( rcurr == rend )
00122             return 0 ;
00123         return (*rcurr).c_str() ;
00124     }
00125     return 0 ;
00126 }
00127 
00128 const char *
00129 BESApacheWrapper::get_next_request()
00130 {
00131     if( _requests )
00132     {
00133         static BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00134         static BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00135         if( rcurr == rend )
00136             return 0 ;
00137         ++rcurr ;
00138         if( rcurr == rend )
00139             return 0 ;
00140         return (*rcurr).c_str() ;
00141     }
00142     return 0 ;
00143 }
00144 
00150 const char *
00151 BESApacheWrapper::process_user(const char*s)
00152 {
00153     BESProcessEncodedString h( s ) ;
00154     string str = h.get_key( "username" ) ;
00155     if( str == "" )
00156     {
00157         _user_name = new char[strlen( str.c_str() ) + 1] ;
00158         strcpy( _user_name, str.c_str() ) ;
00159     }
00160     else
00161     {
00162         _user_name = new char[strlen( str.c_str() ) + 20] ;
00163         sprintf( _user_name, "OpenDAP.remoteuser=%s", str.c_str() ) ;
00164     }
00165     return _user_name ;
00166 }
00167 
00173 const char *
00174 BESApacheWrapper::process_token(const char*s)
00175 {
00176     BESProcessEncodedString h( s ) ;
00177     string str = h.get_key( "token" ) ;
00178     _token = new char[strlen( str.c_str() ) + 1] ;
00179     strcpy( _token, str.c_str() ) ;
00180     return _token ;
00181 }
00182