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,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 Atmostpheric 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 dods( re ) ;
00089     int ret = dods.execute_request() ;
00090     return ret ;
00091 }
00092 
00097 void
00098 BESApacheWrapper::process_request(const char*s)
00099 {
00100     BESProcessEncodedString h( s ) ;
00101     string str = h.get_key( "request" ) ;
00102     _requests = new BESApacheRequests( str ) ;
00103 }
00104 
00105 const char *
00106 BESApacheWrapper::get_first_request()
00107 {
00108     if( _requests )
00109     {
00110         BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00111         BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00112         if( rcurr == rend )
00113             return 0 ;
00114         return (*rcurr).c_str() ;
00115     }
00116     return 0 ;
00117 }
00118 
00119 const char *
00120 BESApacheWrapper::get_next_request()
00121 {
00122     if( _requests )
00123     {
00124         static BESApacheRequests::requests_citer rcurr = _requests->get_first_request() ;
00125         static BESApacheRequests::requests_citer rend = _requests->get_end_request() ;
00126         if( rcurr == rend )
00127             return 0 ;
00128         rcurr++ ;
00129         if( rcurr == rend )
00130             return 0 ;
00131         return (*rcurr).c_str() ;
00132     }
00133     return 0 ;
00134 }
00135 
00141 const char *
00142 BESApacheWrapper::process_user(const char*s)
00143 {
00144     BESProcessEncodedString h( s ) ;
00145     string str = h.get_key( "username" ) ;
00146     if( str == "" )
00147     {
00148         _user_name = new char[strlen( str.c_str() ) + 1] ;
00149         strcpy( _user_name, str.c_str() ) ;
00150     }
00151     else
00152     {
00153         _user_name = new char[strlen( str.c_str() ) + 20] ;
00154         sprintf( _user_name, "OpenDAP.remoteuser=%s", str.c_str() ) ;
00155     }
00156     return _user_name ;
00157 }
00158 
00164 const char *
00165 BESApacheWrapper::process_token(const char*s)
00166 {
00167     BESProcessEncodedString h( s ) ;
00168     string str = h.get_key( "token" ) ;
00169     _token = new char[strlen( str.c_str() ) + 1] ;
00170     strcpy( _token, str.c_str() ) ;
00171     return _token ;
00172 }
00173 

Generated on Wed Aug 29 03:24:04 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2