diff --git a/gosa-core/include/class_gosaSupportDaemon.inc b/gosa-core/include/class_gosaSupportDaemon.inc
index a657419d6303eee9825965a2763d44630f13bd5a..d3ba4ac8ce4502978f720f4417d7e2eb00000f99 100644 (file)
Function overview:
- __construct - Create a new deamon handle.
- connect - Connect to deamon socket.
+ __construct - Create a new daemon handle.
+ connect - Connect to daemon socket.
disconnect - Disconnect from socket.
set_error - Sets a new error.
is_error - Returns TRUE if there was an error.
/*! \brief Creates a new gosaSupportDaemon object.
- @param string Host The Host where the deamon is running on.
- @param integer Port The port which the deamon use.
+ @param string Host The Host where the daemon is running on.
+ @param integer Port The port which the daemon use.
@param string Key The encryption string.
- @param boolean Connect Directly connect to deamon socket.
+ @param boolean Connect Directly connect to daemon socket.
@param float Timeout The timelimit for all socket actions.
*/
public function __construct($connect=TRUE,$timeout=0.2)
}
- /*! \brief Establish deamon connection.
+ /*! \brief Establish daemon connection.
@return boolean Returns true if the connection was succesfully established.
*/
public function connect()
$this->o_sock->setEncryptionKey($this->s_encryption_key);
$this->is_connected = TRUE;
}else{
- $this->s_error = $this->o_sock->get_error();
- $this->b_error = TRUE;
+ $this->set_error($this->o_sock->get_error());
$this->disconnect();
}
return($this->is_connected);
}
- /*! \brief Disconnect from gosa deamon.
+ /*! \brief Disconnect from gosa daemon.
*/
public function disconnect()
{
}
+ /*! \brief Sets an error message, which can be returned with get_error().
+ @param string The Error message,
+ */
+ private function reset_error()
+ {
+ $this->b_error = FALSE;
+ $this->s_error = "";
+ }
+
+
/*! \brief Checks if an error occured.
@return boolean returns TRUE or FALSE, whether there is an error or not.
*/
*/
public function get_error()
{
- return($this->s_error);
+ $str = $this->s_error;
+ $str = preg_replace("/ /"," ",$str);
+ return($str);
}
*/
public function get_queued_entries($from=-1,$to=-1,$sort="timestamp DESC")
{
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
$ret = array();
$xml_msg = "<xml>
<header>gosa_query_jobdb</header>
- <where>
- <clause>
- <phrase>
- <operator>ne</operator>
- <HEADERTAG>*</HEADERTAG>
- </phrase>
- </clause>
- </where>
+ <target>GOSA</target>
+ <source>GOSA</source>
<orderby>".$sort."</orderby>";
if($from != -1 && $to != -1){
$xml_msg.= "
if(isset($entries['XML']) && is_array($entries['XML'])){
/* Check if returned values represent a valid answer */
- if($entries['XML']['HEADER'] == "answer"){
+ if(isset($entries['XML'])){
/* Unset header tags */
foreach(array("HEADER","SOURCE","TARGET") as $type){
trigger_error("Requires an array as parameter.");
return;
}
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
$ret = array();
$xml_msg = "<xml>
<header>gosa_query_jobdb</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<connector>or</connector>";
trigger_error("Requires an array as parameter.");
return;
}
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
$ret = array();
$xml_msg = "<xml>
<header>gosa_query_jobdb</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<connector>or</connector>";
return;
}
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
+
$xml_msg = "<xml>
<header>gosa_query_jobdb</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<phrase>
trigger_error("Requires an integer as parameter.");
return;
}
+ $this->reset_error();
- $this->b_error = FALSE;
- $this->s_error = "";
$ret = array();
$xml_msg = "<xml>
<header>gosa_query_jobdb</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<phrase>
trigger_error("Requires an array as parameter.");
return;
}
- $this->b_error = FALSE;
- $this->s_error = "";
+
+ $this->reset_error();
$ret = array();
$xml_msg = "<xml>
<header>gosa_delete_jobdb_entry</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<connector>or</connector>";
$xml_msg .= "</clause>
</where>
</xml>";
- $this->b_error = FALSE;
- $this->s_error = "";
if($this->connect()){
$this->o_sock->write($xml_msg);
*/
public function remove_entry($id)
{
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
$xml_msg = "<xml>
<header>gosa_delete_jobdb_entry</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<phrase>
*/
public function update_entries($ids,$entry)
{
- $this->b_error = FALSE;
- $this->s_error = "";
+ $this->reset_error();
if(!is_array($ids)){
trigger_error("Requires an array as first parameter.");
return;
}
$xml_msg = "<xml>
<header>gosa_update_status_jobdb_entry</header>
+ <target>GOSA</target>
+ <source>GOSA</source>
<where>
<clause>
<connector>or</connector>";
*/
public function number_of_queued_entries()
{
- $xml_msg ="<xml><header>gosa_count_jobdb</header></xml>";
+ $xml_msg ="<xml><header>gosa_count_jobdb</header><target>GOSA</target><source>GOSA</source></xml>";
$this->connect();
if($this->connect()){
$this->o_sock->write($xml_msg);
}
+ public function send_data($header, $to, $data= array(), $answer_expected = FALSE)
+ {
+ $xml_message= "";
+
+ /* Prepare data */
+ foreach ($data as $key => $value){
+ $xml_message.= "<$key>$value</$key>";
+ }
+
+ /* Multiple targets? */
+ if (!is_array($to)){
+ $to_targets= array($to);
+ } else {
+ $to_targets= $to;
+ }
+
+ /* Build target strings */
+ $target ="";
+ foreach($to_targets as $to){
+ $target.= "<target>$to</target>";
+ }
+
+ return $this->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
+ }
+
+
/*! \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 = "";
+ $this->reset_error();
$ret = array();
if($this->connect()){
$str = trim($this->o_sock->read());
$entries = $this->xml_to_array($str);
if(isset($entries['XML']) && is_array($entries['XML'])){
- $ret = $entries;
+ $ret = $entries;
+ if(isset($entries['XML']['ERROR_STRING'])) {
+ $this->set_error($entries['XML']['ERROR_STRING']);
+ }
}
}
}
$xml_message.= "<$key>$value</$key>";
}
- return $d->_send("<xml><header>$header</header><source>GOSA</source><target>$to</target>".$xml_message."</xml>",$answer_expected);
+ /* Multiple targets? */
+ if (!is_array($to)){
+ $to_targets= array($to);
+ } else {
+ $to_targets= $to;
+ }
+
+ /* Build target strings */
+ $target ="";
+ foreach($to_targets as $to){
+ $target.= "<target>$to</target>";
+ }
+
+ return $d->_send("<xml><header>$header</header><source>GOSA</source>$target".$xml_message."</xml>",$answer_expected);
}