From: hickert Date: Fri, 11 Jan 2008 15:05:35 +0000 (+0000) Subject: Added deamon class. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d6e24e36fed1099487ea8435cb78a05e7b0aa997;p=gosa.git Added deamon class. -Not working at all. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8315 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_gosaSupportDaemon.inc b/gosa-core/include/class_gosaSupportDaemon.inc new file mode 100755 index 000000000..93381e07b --- /dev/null +++ b/gosa-core/include/class_gosaSupportDaemon.inc @@ -0,0 +1,142 @@ +s_host = $host; + $this->i_port = $port; + $this->i_timeout = $timeout; + $this->s_encryption_key = $key; + } + + public function connect() + { + $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->i_timeout); + $this->o_sock->setEncryptionKey($this->s_encryption_key); + if($this->o_sock->connected()){ + $this->is_connected = TRUE; + }else{ + $this->is_connected = FALSE; + } + } + + public function disconnect() + { + $this->o_sock->close(); + $this->is_connected = FALSE; + } + + + public function __reload() + { + echo "Reload"; + $this->entries = array(); + $xml_msg = "
gosa_query_jobdb
*
"; + $this->connect(); + if($this->is_connected){ + $this->o_sock->write($xml_msg); + $str = trim($this->o_sock->read()); + $entries = $this->xml_to_array($str); + if(!isset($entries['XML'])){ + print_a($entries); + echo htmlentities($str); + $this->set_error("Couldn't parse xml."); + $this->disconnect(); + return(FALSE); + }else{ + $ret = array_values($entries['XML']); + } + $this->entries = $ret; + $this->disconnect(); + return(TRUE); + } + $this->set_error("Could not establish socket connection."); + return(FALSE); + } + + function xml_to_array($xml) + { + $params = array(); + $level = array(); + $parser = xml_parser_create_ns(); + xml_parse_into_struct($parser, $xml, $vals, $index); + + $err_id = xml_get_error_code($parser); + if($err_id){ + $this->set_error(xml_error_string(xml_get_error_code($parser))); + xml_parser_free($parser); + }else{ + xml_parser_free($parser); + + foreach ($vals as $xml_elem) { + if ($xml_elem['type'] == 'open') { + if (array_key_exists('attributes',$xml_elem)) { + list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); + } else { + $level[$xml_elem['level']] = $xml_elem['tag']; + } + } + if ($xml_elem['type'] == 'complete') { + $start_level = 1; + $php_stmt = '$params'; + while($start_level < $xml_elem['level']) { + $php_stmt .= '[$level['.$start_level.']]'; + $start_level++; + } + $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; + eval($php_stmt); + } + } + } + return($params); + } + + public function load() + { + return($this->__reload()); + } + + public function fetch() + { + if(isset($this->entries[$this->pointer])){ + $p = $this->entries[$this->pointer]; + $this->pointer ++; + return($p); + } + return(FALSE); + } + + private function set_error($str) + { + $this->b_error = TRUE; + $this->s_error = $str; + } + + public function is_error() + { + return($this->b_error); + } + + public function get_error() + { + return($this->s_error); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?>