You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by da...@apache.org on 2003/06/27 11:17:01 UTC

cvs commit: xml-axis/c/src/server/handlers Handler.cpp LogHandler.cpp LogHandler.h SimpleAuthorizationHandler.cpp SimpleAuthorizationHandler.h

damitha     2003/06/27 02:17:01

  Added:       c/src/server/handlers Handler.cpp LogHandler.cpp
                        LogHandler.h SimpleAuthorizationHandler.cpp
                        SimpleAuthorizationHandler.h
  Log:
  commiting c++ codebase
  
  Revision  Changes    Path
  1.1                  xml-axis/c/src/server/handlers/Handler.cpp
  
  Index: Handler.cpp
  ===================================================================
  // WsService.cpp : Defines the entry point for the DLL application.
  //
  #ifdef WIN32
  #define STORAGE_CLASS_INFO __declspec(dllexport)
  #else
  #define STORAGE_CLASS_INFO
  #endif
  
  #include "LogHandler.h"
  
  extern "C" {
  //the two export functions////////////////////////////////////////////
  
  //Following describes how the export function of the handler DLLs (or .so s)
  
  STORAGE_CLASS_INFO
  int GetClassInstance(BasicHandler **inst)
  {
  	*inst = new LogHandler();
  	if (*inst)
  	{
  		return SUCCESS;
  	}
  	return FAIL;
  }
  STORAGE_CLASS_INFO
  int DestroyInstance(BasicHandler *inst)
  {
  	if (inst)
  	{
  		delete inst;
  		return SUCCESS;
  	}
  	return FAIL;
  }
  
  }
  
  
  1.1                  xml-axis/c/src/server/handlers/LogHandler.cpp
  
  Index: LogHandler.cpp
  ===================================================================
  //////////////////////////////////////////////////////////////////////
  
  #include "LogHandler.h"
  #include "../soap/SoapDeSerializer.h"
  #include "../soap/SoapSerializer.h"
  #include <fstream>
  #include <string>
  
  using namespace std;
  
  //////////////////////////////////////////////////////////////////////
  // Construction/Destruction
  //////////////////////////////////////////////////////////////////////
  
  LogHandler::LogHandler()
  {
  
  }
  
  LogHandler::~LogHandler()
  {
  
  }
  // Implementation of BasicHandler interface.
  int LogHandler::Invoke(MessageData* md)
  {
    int iNumAccess = 0;
    WSDDService* oService =  md->GetService();
    if(oService)
    {
      string sFileName = oService->GetOption("logAccessCountFile");
      if(!sFileName.empty())
      {   
        string sNumAccess = oService->GetOption("num_access");      
        if(sNumAccess.empty())
        {
          iNumAccess = 0;
        }
        else
        {
          iNumAccess = atoi(sNumAccess.c_str());
        }
        
        iNumAccess++;
        sNumAccess = iNumAccess;
      
        const char * FileName = sFileName.c_str();
        ofstream fout(FileName);  // open for writing
        fout << "service accessed " << iNumAccess << "times";
    
        oService->SetOption("num_access", sNumAccess);
        return SUCCESS;
      }
      else
      {
        return FAIL;
      }
    }
    else
    {
      return FAIL;
    }
  }
  
  void LogHandler::OnFault(MessageData* mc)
  {
  
  }
  
  
  
  
  
  1.1                  xml-axis/c/src/server/handlers/LogHandler.h
  
  Index: LogHandler.h
  ===================================================================
  #include "../common/MessageData.h"
  #include "../wsdd/WSDDHandler.h"
  #include "../wsdd/WSDDService.h"
  #include "../common/BasicHandler.h"
  #include <list>
  
  class LogHandler : public BasicHandler, WSDDHandler
  {
  public:
  	LogHandler();
  	virtual ~LogHandler();
  
  	int Invoke(MessageData* pMsg);
  	void OnFault(MessageData* pMsg);
    
  };
  
  
  
  1.1                  xml-axis/c/src/server/handlers/SimpleAuthorizationHandler.cpp
  
  Index: SimpleAuthorizationHandler.cpp
  ===================================================================
  //////////////////////////////////////////////////////////////////////
  
  #include "SimpleAuthorizationHandler.h"
  #include "../soap/SoapDeSerializer.h"
  #include "../soap/SoapSerializer.h"
  #include <string.h>
  
  //////////////////////////////////////////////////////////////////////
  // Construction/Destruction
  //////////////////////////////////////////////////////////////////////
  
  SimpleAuthorizationHandler::SimpleAuthorizationHandler()
  {
  
  }
  
  SimpleAuthorizationHandler::~SimpleAuthorizationHandler()
  {
  
  }
  // Implementation of BasicHandler interface.
  int SimpleAuthorizationHandler::Invoke(MessageData* md)
  {
    string sValue = GetOption("allowByDefault");
    int intIsAllowed =   atoi(sValue.c_str());
    if(0 == intIsAllowed)
    {
      md->SetIsServiceAllowed(0);
      return SUCCESS;
    }
    m_sAuthUser = md->GetUserName();
    if(m_sAuthUser.empty())
    {
      WSDDService* m_Service =  md->GetService();
      if(m_Service)
      {
        string sServiceName = m_Service->GetServiceName();
        m_AllowedRoles =  m_Service->GetAllowedRoles();
        m_itCurrentRole = m_AllowedRoles.begin();
  	    while (m_itCurrentRole != m_AllowedRoles.end())
  	    {
          if(strcmp(m_sAuthUser.c_str(),(*m_itCurrentRole).c_str()) == 0)
          {
            return SUCCESS;
          }
  			  m_itCurrentRole++;
        }
       }
       else
       {
        return FAIL;
       }
    }
    else
    {
      return FAIL;
    }
  }
  
  void SimpleAuthorizationHandler::OnFault(MessageData* mc)
  {
  
  }
  
  
  
  
  
  1.1                  xml-axis/c/src/server/handlers/SimpleAuthorizationHandler.h
  
  Index: SimpleAuthorizationHandler.h
  ===================================================================
  #include "../common/MessageData.h"
  #include "../wsdd/WSDDHandler.h"
  #include "../wsdd/WSDDService.h"
  #include "../common/BasicHandler.h"
  #include <list>
  
  class SimpleAuthorizationHandler : public BasicHandler, WSDDHandler
  {
  public:
  	SimpleAuthorizationHandler();
  	virtual ~SimpleAuthorizationHandler();
  
  	virtual int Invoke(MessageData* pMsg) = 0;
  	virtual void OnFault(MessageData* pMsg) = 0;
  
  protected:
    string m_sAuthUser;
    list<string> m_AllowedRoles;
    list<string>::iterator m_itCurrentRole;
  };