nanoserv
[ class tree: nanoserv ] [ index: nanoserv ] [ all elements ]

Source for file NS_Syslog_Handler.php

Documentation is available at NS_Syslog_Handler.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * nanoserv handlers - Syslog protocol handler
  6.  * 
  7.  * Copyright (C) 2004-2010 Vincent Negrier aka. sIX <six@aegis-corp.org>
  8.  * 
  9.  * This library is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU Lesser General Public
  11.  * License as published by the Free Software Foundation; either
  12.  * version 2.1 of the License, or (at your option) any later version.
  13.  * 
  14.  * This library is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.  * Lesser General Public License for more details.
  18.  * 
  19.  * You should have received a copy of the GNU Lesser General Public
  20.  * License along with this library; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
  22.  *
  23.  * @package nanoserv
  24.  * @subpackage Handlers
  25.  */
  26.  
  27. /**
  28.  * Require the nanoserv core
  29.  */
  30. require_once "nanoserv-compat/nanoserv.php";
  31.  
  32. /**
  33.  * Syslog protocol handler handler class
  34.  *
  35.  * @package nanoserv
  36.  * @subpackage Handlers
  37.  */
  38. abstract class NS_Syslog_Handler extends NS_Datagram_Handler {
  39.  
  40.     /**
  41.      * Get facility name from numerical code
  42.      *
  43.      * @param int $code 
  44.      * @return string 
  45.      */
  46.     static public function Code_To_Facility($code{
  47.  
  48.         switch ($code{
  49.  
  50.             case 0:        return "kern";
  51.             case 1:        return "user";
  52.             case 2:        return "mail";
  53.             case 3:        return "daemon";
  54.             case 4:        return "auth";
  55.             case 5:        return "syslog";
  56.             case 6:        return "lpr";
  57.             case 7:        return "news";
  58.             case 8:        return "uucp";
  59.             case 9:        return "cron";
  60.             case 10:    return "auth";
  61.             case 11:    return "ftp";
  62.             case 12:    return "ntp";
  63.             case 15:    return "cron";
  64.             case 16:    return "local0";
  65.             case 17:    return "local1";
  66.             case 18:    return "local2";
  67.             case 19:    return "local3";
  68.             case 20:    return "local4";
  69.             case 21:    return "local5";
  70.             case 22:    return "local6";
  71.             case 23:    return "local7";
  72.         
  73.         }
  74.     
  75.     }
  76.     
  77.     /**
  78.      * Get facility numerical code from name
  79.      *
  80.      * @param string $name 
  81.      * @return int 
  82.      */
  83.     static public function Facility_To_Code($name{
  84.  
  85.         switch (strtolower($name)) {
  86.  
  87.             case "kern":    return 0;
  88.             case "user":    return 1;
  89.             case "mail":    return 2;
  90.             case "daemon":    return 3;
  91.             case "auth":    return 4;
  92.             case "syslog":    return 5;
  93.             case "lpr":        return 6;
  94.             case "news":    return 7;
  95.             case "uucp":    return 8;
  96.             case "cron":    return 9;
  97.             case "ftp":        return 11;
  98.             case "ntp":        return 12;
  99.             case "local0":    return 16;
  100.             case "local1":    return 17;
  101.             case "local2":    return 18;
  102.             case "local3":    return 19;
  103.             case "local4":    return 20;
  104.             case "local5":    return 21;
  105.             case "local6":    return 22;
  106.             case "local7":    return 23;
  107.         
  108.         }
  109.     
  110.     }
  111.     
  112.     final public function on_Read($from$data{
  113.  
  114.         $host strtok($from":");
  115.  
  116.         if (($data{0!== "<"|| (($p strpos($data">")) === false)) return;
  117.  
  118.         $pri = (int)substr($data1$p 1);
  119.         $msg substr($data$p 1);
  120.         
  121.         $this->on_Event($host$pri >> 3$pri 7$msg);
  122.  
  123.     }
  124.  
  125.     /**
  126.      * Event called on new syslog event
  127.      *
  128.      * @param string $host 
  129.      * @param int $facility 
  130.      * @param int $severity 
  131.      * @param string $message 
  132.      */
  133.     abstract public function on_Event($host$facility$severity$message);
  134.  
  135. }
  136.  
  137. ?>

Documentation generated on Wed, 30 Nov 2011 22:03:25 +0100 by phpDocumentor 1.4.3