⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apachemodule.cpp

📁 "More for C++" is a class library that provides some features that are usually common for object ori
💻 CPP
字号:
////  This file is part of the "More for C++" library////  Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)////  The "More for C++" library is free software; you can redistribute it and/or//  modify it under the terms of the license that comes with this package.////  Read "license.txt" for more details.////  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED//  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES//  OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#include <apache.hpp>#include <cstring>#include <more/gc.hpp>#include <more/glue.hpp>#include <more/servlet/apache/apachemodule.hpp>#include <more/create.hpp>#include <more/servlet/httprequest.hpp>#include "apachehttprequest.hpp"#include "apachehttpresponse.hpp"#include "apacheoutputstream.hpp"using namespace more;using namespace more::io;using namespace more::servlet;using namespace more::servlet::apache;////////////////////////////////////////////////////////////////////////////////#ifdef EAPI#define API_HOOKS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0#else#define API_HOOKS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0#endifextern "C"{  typedef void ( *InitHook )( server_rec*, pool* );  typedef int ( *RequestHook )( request_rec* );  static module module_descriptorTemplate =  {    STANDARD_MODULE_STUFF, API_HOOKS  };}////////////////////////////////////////////////////////////////////////////////ApacheModule::ApacheModule(  module_descriptor& rModuleDescriptor): m_rModuleDescriptor( rModuleDescriptor ){  module* pApacheModuleDescriptor = ( module* ) &m_rModuleDescriptor;  memset( &m_rModuleDescriptor, 0x00, sizeof( module_descriptor ) );  memcpy( &m_rModuleDescriptor, &module_descriptorTemplate, sizeof( module ) );  pApacheModuleDescriptor -> init = ( InitHook ) ApacheModule::init;  ApacheModule::pInstance = this;}////////////////////////////////////////////////////////////////////////////////ApacheModule::~ApacheModule( ){}////////////////////////////////////////////////////////////////////////////////void ApacheModule::registerServlet(  const String&         sNameOfHandler,  const p<HttpServlet>& pHttpServlet){  m_servletMap[sNameOfHandler] = pHttpServlet;}////////////////////////////////////////////////////////////////////////////////// void ApacheModule::init( server_rec*, pool* )void ApacheModule::init( void*, void* ){  ApacheModule*       pApacheModule = ApacheModule::pInstance;  handler_rec*        pHandlerRecords;  ServletMapIterator  pServletMapIterator;  module*             pApacheModuleDescriptor;  pApacheModule -> onInit( );  pHandlerRecords = new handler_rec[pApacheModule -> m_servletMap.size( ) + 1];  pServletMapIterator = pApacheModule -> m_servletMap.begin( );  pApacheModuleDescriptor = ( module* ) &pApacheModule -> m_rModuleDescriptor;  pApacheModuleDescriptor -> handlers = pHandlerRecords;  while( pServletMapIterator != pApacheModule -> m_servletMap.end( ) )  {    pHandlerRecords -> content_type = pServletMapIterator -> first;    pHandlerRecords -> handler = ( RequestHook ) ApacheModule::onRequest;    pHandlerRecords++;    pServletMapIterator++;  }  pHandlerRecords -> content_type = 0;  pHandlerRecords -> handler = 0;}////////////////////////////////////////////////////////////////////////////////// int ApacheModule::onRequest( request_rec* pRequest )int ApacheModule::onRequest(  void* pRequest_void){  int           nResult = OK;  request_rec*  pRequest = ( request_rec* ) pRequest_void;  pRequest -> content_type = "text/html";  if( pRequest -> header_only )  {    ap_send_http_header( pRequest );  }  else  {    ApacheModule*   pApacheModule = ApacheModule::pInstance;    const char*     pcNameOfHandler = pRequest -> handler;    p<HttpServlet>  pHttpServlet = pApacheModule -> m_servletMap[pcNameOfHandler];    if( pHttpServlet != 0 )    {      p<HttpRequest>  pHttpRequest = CREATE ApacheHttpRequest( pRequest );      p<HttpResponse> pHttpResponse = CREATE ApacheHttpResponse( pRequest );      p<OutputStream> pOutputStream = CREATE ApacheOutputStream( pRequest );      nResult = pHttpServlet -> onRequest( pHttpRequest, pHttpResponse, pOutputStream );      ap_send_http_header( pRequest );      pOutputStream -> flush( );    }    GC::collectObjects( );  }  return nResult;}////////////////////////////////////////////////////////////////////////////////ApacheModule* ApacheModule::pInstance = 0;////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -