Overview

Packages

  • Horde
    • Imsp

Classes

  • Horde_Imsp_Auth_Base
  • Horde_Imsp_Auth_CramMd5
  • Horde_Imsp_Auth_Imtest
  • Horde_Imsp_Auth_Plaintext
  • Horde_Imsp_Book
  • Horde_Imsp_Client_Base
  • Horde_Imsp_Client_Socket
  • Horde_Imsp_Exception
  • Horde_Imsp_Options
  • Horde_Imsp_Translation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde_Imsp_Options Class - provides an interface to IMSP server-based
  4:  * options storage.
  5:  *
  6:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author  Michael J Rubinsky <mrubinsk@horde.org>
 12:  * @package Horde_Imsp
 13:  */
 14: class Horde_Imsp_Options
 15: {
 16:     /**
 17:      * Horde_Imsp object.
 18:      *
 19:      * @var Horde_Imsp_Client_Base
 20:      */
 21:     protected $_imsp;
 22: 
 23:     /**
 24:      * Parameter list.
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_params;
 29: 
 30:     /**
 31:      * Constructor.
 32:      *
 33:      * @param Horde_Imsp_Client_base $client  The client connection.
 34:      * @param array $params                   Hash containing IMSP parameters.
 35:      */
 36:     public function __construct(Horde_Imsp_Client_Base $client, array $params)
 37:     {
 38:         $this->_params = $params;
 39:         $this->_imsp = $client;
 40:         $this->_imsp->_logger->debug('Horde_Imsp_Options initialized.');
 41:     }
 42: 
 43:     /**
 44:      * Function sends a GET command to IMSP server and retrieves values.
 45:      *
 46:      * @param  string $option  Name of option to retrieve. Accepts '*' as wild
 47:      *                         card.
 48:      *
 49:      * @return array  Hash containing option=>value pairs.
 50:      * @throws Horde_Imsp_Exception
 51:      */
 52:     public function get($option)
 53:     {
 54:         $options = array();
 55:         $this->_imsp->send("GET $option", true, true);
 56:         $server_response = $this->_imsp->receive();
 57:         while (preg_match("/^\* OPTION/", $server_response)) {
 58:             /* First, check for a {}. */
 59:             if (preg_match(Horde_Imsp_Client_Base::OCTET_COUNT, $server_response, $tempArray)) {
 60:                 $temp = explode(' ', $server_response);
 61:                 $options[$temp[2]] = $this->_imsp->receiveStringLiteral($tempArray[2]);
 62:                 $this->_imsp->receive();
 63:             } else {
 64:                 $temp = explode(' ', $server_response);
 65:                 $options[$temp[2]] = trim($temp[3]);
 66:                 $i = 3;
 67:                 $lastChar = "";
 68:                 $nextElement = trim($temp[3]);
 69: 
 70:                 /* Was the value quoted and spaced? */
 71:                 if ((substr($nextElement, 0, 1) == '"') &&
 72:                     (substr($nextElement, strlen($nextElement) - 1, 1) != '"')) {
 73:                     do {
 74:                         $nextElement = $temp[$i + 1];
 75:                         $lastChar = substr($nextElement, strlen($nextElement) - 1, 1);
 76:                         $options[$temp[2]] .= ' ' . $nextElement;
 77:                         if ($lastChar == '"') {
 78:                             $done = true;
 79:                         } else {
 80:                             $done = false;
 81:                             $lastChar = substr($temp[$i + 2], strlen($temp[$i + 2]) - 1, 1);
 82:                             $i++;
 83:                         }
 84: 
 85:                     } while ($lastChar != '"');
 86: 
 87:                     if (!$done) {
 88:                         $nextElement = $temp[$i + 1];
 89:                         $options[$temp[2]] .= ' ' . $nextElement;
 90:                     }
 91:                 }
 92:             }
 93:             $server_response = $this->_imsp->receive();
 94:         }
 95: 
 96:         if ($server_response != 'OK') {
 97:             throw new Horde_Imsp_Exception('Did not receive the expected response from the server.');
 98:         }
 99: 
100:         $this->_imsp->_logger->debug('GET command OK.');
101:         return $options;
102:     }
103: 
104:     /**
105:      * Function sets an option value on the IMSP server.
106:      *
107:      * @param string $name  Name of option to set.
108:      * @param string $value Value to assign.
109:      *
110:      * @throws Horde_Imsp_Exception
111:      */
112:     public function set($option, $value)
113:     {
114:         /* Send the beginning of the command. */
115:         $this->_imsp->send("SET $option ", true, false);
116: 
117:         /* Send $optionValue as a literal {}? */
118:         if (preg_match(Horde_Imsp_Client_Base::MUST_USE_LITERAL, $value)) {
119:             $biValue = sprintf("{%d}", strlen($value));
120:             $result = $this->_imsp->send($biValue, false, true, true);
121:         }
122: 
123:         /* Now send the rest of the command. */
124:         $result = $this->_imsp->send($value, false, true);
125:         $server_response = $this->_imsp->receive();
126:         if ($server_response != 'OK') {
127:             throw new Horde_Imsp_Exception('The option could not be set on the IMSP server.');
128:         }
129:         $this->_imsp->_logger->debug('SET command OK.');
130:     }
131: 
132:     public function logout()
133:     {
134:         $this->_imsp->logout();
135:     }
136: 
137: }
138: 
API documentation generated by ApiGen