Source for file exceptions.php

Documentation is available at exceptions.php

  1. <?php
  2.  
  3. /**
  4.  * exceptions.php
  5.  * 
  6.  * Definition of Exceptions and functions that throw those exceptions to be used by vmpsd_external and vmps_lastseen
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as published
  12.  * by the Free Software Foundation.
  13.  *
  14.  * @package            FreeNAC
  15.  * @author            Seiler Thomas (contributer)
  16.  * @copyright            2007 FreeNAC
  17.  * @license            http://www.gnu.org/copyleft/gpl.html   GNU Public License Version 2
  18.  * @version            SVN: $Id$
  19.  * @link            http://www.freenac.net
  20.  */
  21.  
  22. /**
  23.  * This Exception may be thrown at any point in the decision process to
  24.  * indicate that the current request should be denied
  25.  * This class extends the {@link Exception} class.
  26.  */
  27. class DenyException extends Exception
  28. {
  29.    # constructor      
  30.    function __construct($why{
  31.       parent::__construct("DENY: ".$why)
  32.    }
  33. }
  34.  
  35. /**
  36.  * This function is some syntactic sugar to throw a DenyException from the
  37.  * policy class
  38.  * @throws    DenyException
  39.  */
  40. function DENY($why=''{
  41.    throw new DenyException($why);
  42. }
  43.  
  44. /**
  45.  * This Exception may be thrown at any point in the decision process to
  46.  * indicate that the current request should be allowed into a given VLAN
  47.  * This class extends the {@link Exception} class.
  48.  */
  49. class AllowException extends Exception
  50. {
  51.    # The vlan that we communicate to VMPSD 
  52.    protected $decidedVlan;
  53.  
  54.    # Constructor to set this VLAN      
  55.    function __construct($vlan{
  56.       if isset($vlan) )
  57.          throw new DenyException('AllowException called without a vlan');
  58.       if is_integer($vlan) )
  59.       {
  60.          # Get the vlan mapping
  61.          if $lookup vlanId2Name($vlan) )
  62.          {
  63.             throw new DenyException("AllowException could not map vlan number $vlan to a name");
  64.          }
  65.          else
  66.          {
  67.             $this->decidedVlan = $lookup;
  68.          }
  69.       }
  70.       else
  71.       {
  72.          #Do we have only spaces?
  73.          $vlan trim($vlan);
  74.          if empty($vlan) )
  75.             throw new DenyException('AllowException called without a vlan');
  76.          $this->decidedVlan = $vlan;
  77.       }
  78.       parent::__construct("ALLOW {$this->decidedVlan}"); 
  79.    }
  80.  
  81.    public function getDecidedVlan() {
  82.       return $this->decidedVlan;
  83.    }    
  84. }
  85.  
  86. /**
  87.  * This function is some syntactic sugar to throw an AllowException 
  88.  * from the policy class. It also handles default vlan
  89.  * @param int $vlan    Vlan ID of the VLAN we want to assign
  90.  * @throws    AllowException
  91.  */
  92. function ALLOW($vlan) 
  93. {
  94.    throw new AllowException($vlan);
  95. }

Documentation generated on Mon, 17 Nov 2008 01:10:31 +0100 by phpDocumentor 1.4.0