Code

removed debug code.
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index 398160ee38be2b44d8b10476ef8d0a0224eb3cad..7dc12f1d21b115bfb90626c4371c043d4f6f004c 100644 (file)
@@ -39,19 +39,18 @@ Function overview:
    number_of_queued_entries - Returns the number of currently queued entries.   
 */
 
-
-
 class gosaSupportDaemon
 {
-  private $o_sock       = NULL;
   private $s_host       = "";
   private $i_port       = 0;
+  private $s_encryption_key = "";
+
+  private $o_sock       = NULL;
   private $f_timeout    = 2;
   private $s_error      = "";
   private $b_error      = FALSE;
 
   private $is_connected     = FALSE;
-  private $s_encryption_key = "";
 
 
   /*! \brief  Creates a new gosaSupportDaemon object.
@@ -61,14 +60,24 @@ class gosaSupportDaemon
     @param boolean  Connect Directly connect to deamon socket.
     @param float    Timeout The timelimit for all socket actions.
    */
-  public function __construct($host,$port,$key="secret-gosa-password",$connect=TRUE,$timeout=0.2)
+  public function __construct($connect=TRUE,$timeout=0.2)
   {
-    $this->s_host    = $host;
-    $this->i_port    = $port;
-    $this->f_timeout = $timeout;
-    $this->s_encryption_key = $key;
-    if($connect){
-      $this->connect();
+    #FIXME: bad idea about referencing global variables from within classes
+    global $config;
+
+    # load from config, store statically
+    if (isset($config->current['GOSA_SI'])){
+
+      if ($this->s_host == ""){
+        $this->s_host= preg_replace("/^.*@([^:]+):.*$/", "$1", $config->current['GOSA_SI']);
+        $this->i_port= preg_replace("/^.*@[^:]+:(.*)$/", "$1", $config->current['GOSA_SI']);
+        $this->s_encryption_key = preg_replace("/^(.*)@[^:]+:.*$/", "$1", $config->current['GOSA_SI']);
+      }
+
+      $this->f_timeout = $timeout;
+      if($connect){
+        $this->connect();
+      }
     }
   }
 
@@ -161,9 +170,11 @@ class gosaSupportDaemon
         $ret = $entries; 
       }
     }
+    
     return($ret);
   }
 
+
   /*! \brief  Checks if the given ids are used queue ids.
     @param  Array   The ids we want to check..
     @return Array   An array containing all ids as index and TRUE/FALSE as value. 
@@ -439,10 +450,14 @@ class gosaSupportDaemon
         }
       }
     }
+
     if(!isset($params['XML'])){
-      $this->set_error(_("Could not parse XML."));
-      $params = array();
+      if (!array_key_exists('XML', $params)){
+        $this->set_error(_("Could not parse XML."));
+      }
+      $params = array("COUNT" => 0);
     }
+
     return($params); 
   }
 
@@ -516,6 +531,47 @@ class gosaSupportDaemon
     }
     return(-1);
   } 
+
+
+  /*! \brief  Returns an array containing all queued entries.
+    @return Array All queued entries as an array.
+   */
+  public function _send($data, $answer_expected= FALSE)
+  {
+    $this->b_error = FALSE;
+    $this->s_error = "";
+    $ret = array();
+
+    if($this->connect()){
+      $this->o_sock->write($data);
+      if ($answer_expected){
+        $str = trim($this->o_sock->read());
+        $entries = $this->xml_to_array($str);
+        if(isset($entries['XML']) && is_array($entries['XML'])){
+          $ret = $entries; 
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+  static function send($header, $to, $data= array())
+  {
+    $xml_message= "";
+
+    /* Get communication object */
+    $d= new gosaSupportDaemon(TRUE,10);
+
+    /* Prepare data */
+    foreach ($data as $key => $value){
+      $xml_message.= "<$key>$value</$key>";
+    }
+
+    return $d->_send("<xml><header>$header</header><source>GOSA</source><target>$to</target>".$xml_message."</xml>");
+  }
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: