<?php
define('in_ISO88591', 0);
define('in_UTF8', 1);

$String2Language = array(
    'unknown' => 0,
    'en' => 1,
    'english' => 1,
    'fr' => 2,
    'french' => 2,
    'de' => 3,
    'german' => 3,
    'es' => 4,
    'spanish' => 4,
    'it' => 5,
    'italian' => 5,
    'nl' => 6,
    'dutch' => 6,
    'sv' => 7,
    'se' => 7,
    'swedish' => 7,
    'no' => 8,
    'norwegian' => 8,
    'da' => 9,
    'dk' => 9,
    'danish' => 9,
    'pl' => 10,
    'polish' => 10,
    'ja' => 11,
    'japanese' => 11,
    'tw' => 12,
    'traditional-chinese' => 12,
    'zh' => 12,
    'zh-cht' => 12,
    'zh-tw' => 12,
    'th' => 13,
    'thai' => 13,
    'ko' => 14,
    'korean' => 14,
    'pt' => 15,
    'portuguese' => 15,
    'ar' => 16,
    'arabic' => 16,
    'el' => 17,
    'greek' => 17,
    'fi' => 18,
    'finnish' => 18,
    'ru' => 19,
    'russian' => 19,
    'simplified-chinese' => 20,
    'hr' => 21,
    'croatian' => 21,
    'ee' => 22,
    'estonian' => 22,
    'hu' => 23,
    'hungarian' => 23,
    'lv' => 24,
    'latvian' => 24,
    'ro' => 25,
    'romanian' => 25,
    'si' => 26,
    'slovenian' => 26,
    'sk' => 27,
    'slovak' => 27,
    'cz' => 28,
    'czech' => 28,
    'tr' => 29,
    'turkish' => 29,
    'auto' => 30,
    'autodetect' => 30
);

class iDemarshaling
{

    var $the_message;

    var $error_message;

    var $where_in_message;

    var $charset;

    function status()
    {
        return $this->error_message;
    }

    function __construct(& $charset)
    {
        $this->the_message = '';
        $this->charset = $charset;
    }

    function Receive(& $the_socket)
    {
        $read_count = 0;
        $datum = '';
        do {
            $slice = @fread($the_socket, 4 - $read_count);
            $length = strlen($slice);
            if ($length == 0)
                return false;
            $read_count += $length;
            $datum .= $slice;
        } while ($read_count < 4);
        
        $the_size = (0xff000000 & (ord(substr($datum, 0, 1)) << 24)) | ((ord(substr($datum, 1, 1)) << 16) & 0x00ff0000) | ((ord(substr($datum, 2, 1)) << 8) & 0xff00) | (ord(substr($datum, 3, 1)) & 0xff);
        
        $read_count = 0;
        do {
            $slice = @fread($the_socket, $the_size - $read_count);
            $length = strlen($slice);
            if ($length == 0)
                break;
            $read_count += $length;
            $this->the_message .= $slice;
        } while ($read_count < $the_size);
        
        $this->where_in_message = 0;
        
        return true;
    }

    function &ReadInteger()
    {
        $value = (0xff000000 & (ord(substr($this->the_message, $this->where_in_message, 1)) << 24)) | ((ord(substr($this->the_message, $this->where_in_message + 1, 1)) << 16) & 0x00ff0000) | ((ord(substr($this->the_message, $this->where_in_message + 2, 1)) << 8) & 0xff00) | (ord(substr($this->the_message, $this->where_in_message + 3, 1)) & 0xff);
        
        $this->where_in_message += 4;
        return $value;
    }

    function &Unicode2UTF8($str)
    {
        $value = '';
        $b = strlen($str);
        for ($i = 0; $i < $b; $i += 2) {
            $char = ((ord($str[$i]) << 8) & 0xff00) + (ord($str[$i + 1]) & 0xff);
            if ($char < 0x80)
                $value .= chr($char);
            else if ($char < 0x800)
                $value .= chr(($char >> 6) | 0xc0) . chr(($char & 0x3f) | 0x80);
            else
                $value .= chr(($char >> 12) | 0xe0) . chr((($char >> 6) & 0x3f) | 0x80) . chr(($char & 0x3f) | 0x80);
        }
        return $value;
    }

    function &ISO2UTF8($str)
    {
        $value = '';
        $b = strlen($str);
        for ($i = 0; $i < $b; $i ++) {
            $char = ord($str[$i]) & 0xff;
            if ($char < 0x80)
                $value .= chr($char);
            else if ($char < 0x800)
                $value .= chr(($char >> 6) | 0xc0) . chr(($char & 0x3f) | 0x80);
        }
        return $value;
    }

    function &ReadString()
    {
        $value = '';
        
        $the_size = $this->ReadInteger();
        
        if ($the_size == 0xffffffff)
            return $value;
        
        if ($the_size & 0x80000000) {
            $the_size &= 0x7fffffff;
            $value = $this->Unicode2UTF8(substr($this->the_message, $this->where_in_message, 2 * $the_size));
            $this->where_in_message += 2 * $the_size;
        } else {
            $value = substr($this->the_message, $this->where_in_message, $the_size);
            if ($this->charset == 1)
                $value = $this->ISO2UTF8($value);
            $this->where_in_message += $the_size;
        }
        return $value;
    }

    function &ReadIntegerArray()
    {
        $value = array();
        $the_size = $this->ReadInteger();
        for ($the_item = 0; $the_item < $the_size; $the_item ++)
            $value[] = $this->ReadInteger();
        return $value;
    }

    function &ReadStringArray()
    {
        $value = array();
        $the_size = $this->ReadInteger();
        for ($the_item = 0; $the_item < $the_size; $the_item ++)
            $value[] = $this->ReadString();
        return $value;
    }
}

class iMarshaling
{

    var $the_message;

    var $error_message;

    function &status()
    {
        return $this->error_message;
    }

    function __construct()
    {
        $this->the_message = '';
    }

    function WriteString(& $the_string)
    {
        $the_size = strlen($the_string);
        $this->WriteInteger($the_size);
        $this->the_message .= $the_string;
    }

    function WriteInteger($the_integer)
    {
        $dummy = sprintf('%c%c%c%c', (integer) (0xff000000 & $the_integer) >> 24, (integer) (0xff0000 & $the_integer) >> 16, (integer) (0xff00 & $the_integer) >> 8, (0xff & $the_integer));
        $this->the_message .= $dummy;
    }

    function WriteStringArray(& $the_array)
    {
        $this->WriteInteger(count($the_array));
        foreach ($the_array as & $val)
            $this->WriteString($val);
    }

    function Prepare()
    {
        $size = strlen($this->the_message);
        $length = sprintf('%c%c%c%c', (0xff000000 & $size) >> 24, (0xff0000 & $size) >> 16, (0xff00 & $size) >> 8, (0xff & $size));
        $this->the_message = $length . $this->the_message;
    }

    function Send(& $the_socket)
    {
        $this->Prepare();
        
        $the_size = strlen($this->the_message);
        
        $sent = @fwrite($the_socket, $this->the_message, $the_size);
        if ($sent != $the_size) {
            $this->error_message = 'tcp write failure (Connection reset) sent ' . $sent . ' / ' . $the_size;
            return false;
        }
        return true;
    }
}

class iQuery
{

    var $the_id, $the_socket, $the_tuples, $the_current_tuple, $the_page_size, $the_tuples_count, $the_available_tuples_count, $the_columns_count, $the_columns_caption, $the_columns_type, $the_first_tuple, $the_last_tuple, $the_skip, $the_session_id, $the_offset, $the_attributes, $charset, $version;

    function &status()
    {
        return $this->error_message;
    }

    function Open(& $the_statement, & $the_socket, & $the_session_id, & $version, & $charset)
    {
        $this->the_socket = $the_socket;
        $this->the_session_id = $the_session_id;
        $this->charset = $charset;
        $this->version = $version;
        
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(36);
        $the_message->WriteInteger($this->the_session_id);
        $the_message->WriteString($the_statement);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return NULL;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return NULL;
        }
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return NULL;
        }
        
        $the_query_status = $the_response->ReadInteger();
        if ($the_query_status != 0) {
            $this->error_message = $the_response->ReadString();
            return NULL;
        }
        
        $this->the_id = $the_response->ReadInteger();
        $this->the_page_size = $the_response->ReadInteger();
        $this->the_available_tuples_count = $the_response->ReadInteger();
        $this->the_skip = $the_response->ReadInteger();
        $this->the_tuples_count = $the_response->ReadInteger();
        $this->the_columns_count = $the_response->ReadInteger();
        
        $this->the_columns_caption = array();
        $this->the_columns_type = array();
        
        for ($the_column = 0; $the_column < $this->the_columns_count; $the_column ++) {
            $this->the_columns_caption[] = strtolower($the_response->ReadString());
            $this->the_columns_type[] = $the_response->ReadInteger();
        }
        
        $this->the_tuples = array();
        $this->the_available_tuples_count = $the_response->ReadInteger();
        
        $this->the_attributes = array();
        
        if ($version >= 300) {
            $size = $the_response->ReadInteger();
            for ($the_attribute = 0; $the_attribute < $size; $the_attribute ++) {
                $key = $the_response->ReadString();
                $this->the_attributes[strtolower($key)] = $the_response->ReadString();
            }
        }
        
        for ($the_tuple = 0; $the_tuple < $this->the_available_tuples_count; $the_tuple ++) {
            $current_tuple = array();
            for ($the_column = 0; $the_column < $this->the_columns_count; $the_column ++)
                $current_tuple[$this->the_columns_caption[$the_column]] = $the_response->ReadString();
            
            foreach ($this->the_attributes as $key => & $value)
                $current_tuple[strtolower($key)] = $value;
            
            array_push($this->the_tuples, $current_tuple);
        }
        
        $this->the_offset = $this->the_skip;
        $this->the_first_tuple = $this->the_offset;
        $this->the_last_tuple = $this->the_first_tuple + $this->the_available_tuples_count - 1;
        $this->the_current_tuple = $this->the_first_tuple;
        return $this;
    }

    function &in_num_rows()
    {
        return $this->the_tuples_count;
    }

    function &in_num_fields()
    {
        return $this->the_columns_count;
    }

    function in_data_seek($the_tuple)
    {
        if (($the_tuple >= $this->the_first_tuple) && ($the_tuple <= $this->the_last_tuple)) {
            $this->the_current_tuple = $the_tuple;
            return;
        }
        
        if ($the_tuple > $this->the_first_tuple) {
            $the_page_number = (integer) ($the_tuple / $this->the_page_size);
            
            $the_message = new iMarshaling();
            
            $the_message->WriteInteger(37);
            $the_message->WriteInteger($this->the_session_id);
            $the_message->WriteInteger($this->the_id);
            $the_message->WriteInteger($the_page_number);
            $the_message->WriteInteger($this->the_page_size);
            
            if (! $the_message->Send($this->the_socket)) {
                $this->error_message = $the_message->status();
                return 0;
            }
            
            $the_response = new iDemarshaling($this->charset);
            if (! $the_response->Receive($this->the_socket)) {
                $this->error_message = $the_message->status();
                return 0;
            }
            $the_status = $the_response->ReadInteger();
            
            if ($the_status != 0) {
                $this->error_message = $the_response->ReadString();
                return 0;
            }
            
            $this->the_available_tuples_count = $the_response->ReadInteger();
            $this->the_tuples = array();
            
            for ($tuple = 0; $tuple < $this->the_available_tuples_count; $tuple ++) {
                $current_tuple = array();
                for ($the_column = 0; $the_column < $this->the_columns_count; $the_column ++)
                    $current_tuple[$this->the_columns_caption[$the_column]] = $the_response->ReadString();
                
                foreach ($this->the_attributes as $key => & $value)
                    $current_tuple[strtolower($key)] = $value;
                
                array_push($this->the_tuples, $current_tuple);
            }
            
            $this->the_current_tuple = $the_tuple;
            $this->the_offset = ($the_page_number * $this->the_page_size);
            $this->the_first_tuple = $this->the_offset;
            $this->the_last_tuple = $this->the_first_tuple + $this->the_available_tuples_count - 1;
            
            return;
        }
    }

    function in_fetch_attribute($the_attribute_name)
    {
        if ($this->version >= 300)
            return $this->the_attributes[strtolower($the_attribute_name)];
        else
            return '';
    }

    function &in_fetch_array()
    {
        $value = 0;
        if (($this->the_current_tuple > $this->the_last_tuple) || ($this->the_current_tuple < $this->the_first_tuple))
            return $value;
        
        $this->the_current_tuple = $this->the_current_tuple + 1;
        $the_index = $this->the_current_tuple - $this->the_offset - 1;
        
        return $this->the_tuples[$the_index];
    }

    function in_rewind()
    {
        $this->the_current_tuple = $this->the_first_tuple;
    }

    function &in_fetch_row()
    {
        $value = 0;
        if (($this->the_current_tuple > $this->the_last_tuple) || ($this->the_current_tuple < $this->the_first_tuple))
            return $value;
        
        $this->the_current_tuple = $this->the_current_tuple + 1;
        $the_index = $this->the_current_tuple - $this->the_offset - 1;
        
        return $this->the_tuples[$the_index];
    }

    function &in_page_size()
    {
        return $this->the_page_size;
    }

    function &in_field_names()
    {
        return $this->the_columns_caption;
    }

    function &in_field_types()
    {
        return $this->the_columns_type;
    }

    function close()
    {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(12);
        $the_message->WriteInteger($this->the_session_id);
        $the_message->WriteInteger($this->the_id);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return 0;
        }
    }

    function &in_free_result()
    {
        return $this->close();
    }
}

class iSession
{

    var $the_id, $the_socket, $error_message, $answers_limit, $page_size, $version, $charset;

    function in_set_charset()
    {
        $this->charset = func_get_arg(0);
    }

    function &status()
    {
        return $this->error_message;
    }

    function __construct()
    {
        $this->answers_limit = 10000;
        $this->page_size = 1000;
        $this->version = 418;
        $this->charset = 0;
    }

    function in_set_page_size()
    {
        $this->page_size = func_get_arg(0);
    }

    function in_set_answers_limit()
    {
        $this->answers_limit = func_get_arg(0);
    }

    function &in_answers_limit()
    {
        return $this->answers_limit;
    }

    function &in_page_size()
    {
        return $this->page_size;
    }

    function connect()
    {
        $opts = array(
            'host' => '127.0.0.1',
            'port' => 8088,
            'read_only' => 1,
            'database' => '*',
            'user' => '',
            'password' => '',
            'charset' => 0,
            'page_size' => 1000,
            'max_answers_count' => 10000,
            'default-language' => 'en'
        );
        
        if (func_num_args() == 1) {
            $args = func_get_arg(0);
            if (! is_array($args)) {
                $this->error_message = 'invalid argument to iSession->connect ; (expecting an array)\n';
                return 0;
            }
            
            foreach ($args as $key => & $value)
                if (array_key_exists(strtolower($key), $args))
                    $opts[strtolower($key)] = $value;
                else {
                    $this->error_message = "Error : unknown parameter '" . $key . "'\n";
                    return 0;
                }
            
            $connection_string = '';
            if (array_key_exists('host', $opts))
                $connection_string = $opts['host'] . ':';
            else
                $connection_string = '127.0.0.1:';
            
            if (array_key_exists('port', $opts))
                $connection_string .= $opts['port'];
            else
                $connection_string .= '8088';
            
            if (array_key_exists('password', $opts))
                $opts['password'] = '[php]/' . $opts['password'];
            else
                $opts['password'] = '[php]/';
            
            return $this->in_connect($connection_string, $opts['user'], $opts['password'], $opts['read_only'], 1, $opts['database'], $opts['max_answers_count'], $opts['default-language'], $opts['charset'], $opts['page_size']);
        } else
            return $this->in_connect(func_get_args());
    }

    function in_connect()
    {
        $numargs = func_num_args();
        
        global $String2Language;
        
        $host = '127.0.0.1';
        $port = 8088;
        $database = '';
        $user = 'php4';
        $password = '';
        $readonly = 1;
        $allocated_requests = 1;
        $language = 1;
        
        if (($numargs == 1) && is_array(func_get_arg(0)))
            return $this->connect(func_get_arg(0));
        
        if ($numargs >= 1) {
            $host = func_get_arg(0);
            $pos = strpos($host, ':');
            if (! is_string($pos) || $pos) {
                $port = substr($host, $pos + 1);
                $host = substr($host, 0, $pos);
            }
        }
        
        if ($numargs >= 2)
            $user = func_get_arg(1);
        
        if ($numargs >= 3)
            $password = func_get_arg(2);
        
        if ($numargs >= 4)
            $readonly = func_get_arg(3);
        
        if ($numargs >= 5)
            $allocated_requests = func_get_arg(4);
        
        if ($numargs >= 6)
            $database = func_get_arg(5);
        
        if ($numargs >= 7)
            $this->answers_limit = func_get_arg(6);
        
        if ($numargs >= 8)
            $language = $GLOBALS['String2Language'][func_get_arg(7)];
        
        if ($numargs >= 9)
            $this->charset = func_get_arg(8);
        
        if ($numargs >= 10)
            $this->page_size = func_get_arg(9);
        
        $this->the_socket = @fsockopen($host, $port, $errno, $errstr, 5);
        if (! $this->the_socket || ($errno != 0)) {
            $this->error_message = 'Unable to reach the Intuition daemon at ' . $host . ':' . $port . '(' . $errstr . ' (' . $errno . '))';
            return 0;
        } else {
            // socket_set_blocking ($this->the_socket, TRUE);
            $the_message = new iMarshaling();
            
            $the_message->WriteInteger(62);
            $the_message->WriteString($user);
            $the_message->WriteString($password);
            $the_message->WriteInteger(($readonly + 2 * $this->version) | 0x80000000); // magic value
            $the_message->WriteInteger($language);
            $the_message->WriteInteger($allocated_requests);
            $the_message->WriteInteger($this->page_size); // page_size
            $the_message->WriteInteger($this->answers_limit); // max_answers_count
            $the_message->WriteInteger(1);
            
            if ($database == '')
                $database = '*';
            
            $selection = explode(',', $database);
            
            $the_message->WriteStringArray($selection);
            $the_message->WriteInteger($this->charset);
            
            if (! $the_message->Send($this->the_socket)) {
                $this->error_message = $the_message->status();
                return 0;
            }
            $the_response = new iDemarshaling($this->charset);
            if (! $the_response->Receive($this->the_socket)) {
                $this->error_message = $the_message->status();
                return 0;
            }
            $the_status = $the_response->ReadInteger();
            
            if ($the_status != 0) {
                $this->error_message = $the_response->ReadString();
                return 0;
            }
            
            $the_aliases = $the_response->ReadStringArray();
            $the_ids = $the_response->ReadIntegerArray();
            $this->the_id = $the_response->ReadInteger();
            
            $server_version = $the_response->ReadInteger();
            
            if ($server_version < $this->version)
                $this->version = $server_version;
            
            $this->error_message = '';
            return $this->the_socket;
        }
    }

    function close()
    {
        $this->in_close();
    }

    function in_close()
    {
        fclose($this->the_socket);
        
        $this->the_socket = 0;
    }

    function ping()
    {
        return $this->is_alive();
    }

    function is_alive()
    {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(41);
        $the_message->WriteInteger($this->the_id);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        return 1;
    }

    function in_convert($the_data)
    {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(8);
        $the_message->WriteString($the_data);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return 0;
        }
        
        $converted = $the_response->ReadString();
        
        return $converted;
    }

    function in_server_information($the_data)
    {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(42);
        $the_message->WriteString($the_data);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return 0;
        }
        
        $information = $the_response->ReadString();
        
        return $information;
    }

    function in_reload_dictionaries()
    {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(61);
        
        if (! $the_message->Send($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling($this->charset);
        if (! $the_response->Receive($this->the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return 0;
        }
        
        return 1;
    }

    function in_query(& $the_request)
    {
        if (! $this->the_socket) {
            $this->error_message = 'Not connected';
            return 0;
        }
        
        $the_request = ltrim($the_request);
        
        $statement = strtolower(substr($the_request, 0, 6));
        
        if (strcmp($statement, 'select') == 0) {
            $query = new iQuery();
            if (is_null($query->Open($the_request, $this->the_socket, $this->the_id, $this->version, $this->charset))) {
                $this->error_message = $query->error_message;
                unset($query);
                return 0;
            }
            return $query;
        } else {
            $statement = strtolower(substr($the_request, 0, 15));
            
            if (strcmp($statement, "{unicode}select") == 0) {
                $query = new iQuery();
                if (is_null($query->Open($the_request, $this->the_socket, $this->the_id, $this->version, $this->charset))) {
                    $this->error_message = $query->error_message;
                    unset($query);
                    return 0;
                }
                return $query;
            } else {
                $the_message = new iMarshaling();
                
                $the_message->WriteInteger(40);
                $the_message->WriteInteger($this->the_id);
                $the_message->WriteString($the_request);
                
                if (! $the_message->Send($this->the_socket)) {
                    $this->error_message = $the_message->status();
                    return - 1;
                }
                
                $the_response = new iDemarshaling($this->charset);
                if (! $the_response->Receive($this->the_socket)) {
                    $this->error_message = $the_message->status();
                    return - 1;
                }
                $the_status = $the_response->ReadInteger();
                
                if ($the_status != 0) {
                    $this->error_message = $the_response->ReadString();
                    return - 1;
                }
                $the_tuples_count = $the_response->ReadInteger();
                return $the_tuples_count;
            }
        }
    }
}

function quote(& $string)
{
    return str_replace("'", "''", $string);
}

function encode(& $encoded)
{
    $thelength = strlen($encoded);
    return '\'' . '0xz' . sprintf('%08x', $thelength) . bin2hex(gzcompress($encoded, 9)) . "'";
}

function in_datasources(& $host)
{
    $port = 8088;
    $pos = strpos($host, ':');
    if (! is_string($pos) || $pos) {
        $port = (int) substr($host, $pos + 1);
        $host = substr($host, 0, $pos);
    }
    $the_socket = @fsockopen($host, $port, $errno, $errstr, 5);
    if (! $the_socket || ($errno != 0)) {
        $this->error_message = 'Unable to reach the Intuition daemon at ' . $host . ':' . $port . '(' . $errstr . ' (' . $errno . '))';
        return 0;
    } else {
        $the_message = new iMarshaling();
        
        $the_message->WriteInteger(0);
        
        if (! $the_message->Send($the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        
        $the_response = new iDemarshaling(0);
        if (! $the_response->Receive($the_socket)) {
            $this->error_message = $the_message->status();
            return 0;
        }
        $the_status = $the_response->ReadInteger();
        
        if ($the_status != 0) {
            $this->error_message = $the_response->ReadString();
            return 0;
        }
        $the_result = $the_response->ReadStringArray();
        @fclose($the_socket);
        return $the_result;
    }
}