Code

Updated get_sub_list
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index 98b568701a99f042a045e1ee26312fa40146d59d..a657419d6303eee9825965a2763d44630f13bd5a 100644 (file)
@@ -92,7 +92,8 @@ class gosaSupportDaemon
       $this->o_sock->setEncryptionKey($this->s_encryption_key); 
       $this->is_connected = TRUE;
     }else{
-      $this->error = $this->o_sock->get_error();
+      $this->s_error = $this->o_sock->get_error();
+      $this->b_error = TRUE;
       $this->disconnect();
     }
     return($this->is_connected);
@@ -139,7 +140,7 @@ class gosaSupportDaemon
   /*! \brief  Returns an array containing all queued entries.
     @return Array All queued entries as an array.
    */
-  public function get_queued_entries($from=0,$to=10,$sort="timestamp DESC")
+  public function get_queued_entries($from=-1,$to=-1,$sort="timestamp DESC")
   {
     $this->b_error = FALSE;
     $this->s_error = "";
@@ -155,11 +156,15 @@ class gosaSupportDaemon
         </phrase>
       </clause>
       </where>
-      <orderby>".$sort."</orderby>
+      <orderby>".$sort."</orderby>";
+if($from != -1 && $to != -1){
+$xml_msg.= "
       <limit>
-      <from>".$from."</from>
-      <to>".$to."</to>
-      </limit>
+       <from>".$from."</from>
+       <to>".$to."</to>
+      </limit>";
+}
+$xml_msg.= "
       </xml>";
 
     if($this->connect()){
@@ -167,7 +172,16 @@ class gosaSupportDaemon
       $str = trim($this->o_sock->read());
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
-        $ret = $entries; 
+
+        /* Check if returned values represent a valid answer */
+        if($entries['XML']['HEADER'] == "answer"){
+          
+          /* Unset header tags */
+          foreach(array("HEADER","SOURCE","TARGET") as $type){
+            unset($entries['XML'][$type]);
+          }
+          $ret = $entries['XML']; 
+        }
       }
     }
     
@@ -211,7 +225,9 @@ class gosaSupportDaemon
       $entries = $this->xml_to_array($str);
       if(isset($entries['XML']) && is_array($entries['XML'])){
         foreach($entries['XML'] as $entry){
-          $ret[] = $entry['ID'];
+          if(isset($entry['ID'])){
+            $ret[] = $entry['ID'];
+          }
         }
       }
     }
@@ -244,7 +260,6 @@ class gosaSupportDaemon
         <operator>eq</operator>
         <id>".$id."</id>
         </phrase>";
-      $ret[$id] = FALSE;
     }
     $xml_msg .= "</clause>
       </where>
@@ -255,7 +270,11 @@ class gosaSupportDaemon
       $str = trim($this->o_sock->read());
       $entries = $this->xml_to_array($str); 
       if(isset($entries['XML'])){
-        $ret = $entries['XML'];
+        foreach($entries['XML'] as $name => $entry){
+          if(preg_match("/^ANSWER[0-9]*$/",$name)){
+            $ret[$name] = $entry;
+          }
+        }
       }
     }
     return($ret);
@@ -291,7 +310,9 @@ class gosaSupportDaemon
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
       $entries = $this->xml_to_array($str); 
-      if(isset($entries['XML']['ANSWER1'])){
+      if( isset($entries['XML']['HEADER']) && 
+          $entries['XML']['HEADER']=="answer" && 
+          isset($entries['XML']['ANSWER1'])){
         return(TRUE);
       }
     }
@@ -328,7 +349,9 @@ class gosaSupportDaemon
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
       $entries = $this->xml_to_array($str); 
-      if(isset($entries['XML']['ANSWER1'])){
+      if( isset($entries['XML']['HEADER']) &&
+          $entries['XML']['HEADER']=="answer" &&
+          isset($entries['XML']['ANSWER1'])){
         $ret = $entries['XML']['ANSWER1'];
       }
     }
@@ -544,19 +567,19 @@ class gosaSupportDaemon
 
     if($this->connect()){
       $this->o_sock->write($data);
-      if ($answer_exepcted){
-       $str = trim($this->o_sock->read());
-       $entries = $this->xml_to_array($str);
-       if(isset($entries['XML']) && is_array($entries['XML'])){
-         $ret = $entries; 
-       }
+      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())
+  static function send($header, $to, $data= array(), $answer_expected = FALSE)
   {
     $xml_message= "";
 
@@ -568,10 +591,22 @@ class gosaSupportDaemon
       $xml_message.= "<$key>$value</$key>";
     }
 
-    return $d->_send("<xml><header>$header</header><target>$to</target>".$xml_message."</xml>");
+    return $d->_send("<xml><header>$header</header><source>GOSA</source><target>$to</target>".$xml_message."</xml>",$answer_expected);
   }
 
 
+  static function ping($target)
+  {
+    if (tests::is_mac($target)){
+    /* Get communication object */
+       $d= new gosaSupportDaemon(TRUE,0.5);
+       $answer= $d->_send("<xml><header>gosa_ping</header><source>GOSA</source><target>$target</target></xml>", TRUE);
+       return (count($answer) ? TRUE:FALSE);
+    }
+
+    return (FALSE);
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: