示例#1
0
文件: Book.php 项目: raz0rsdge/horde
 /**
  * Sets an Access Control List for an abook.
  *
  * @param string $abook Name of address book.
  * @param string $ident Name of user for this acl.
  * @param string $acl   acl for this user/book.
  *
  * @return mixed True on success / PEAR_Error on failure.
  */
 public function setACL($abook, $ident, $acl)
 {
     // Verify that $acl looks good.
     if (preg_match("/[^" . self::ACL_RIGHTS . "]/", $acl)) {
         $this->_imsp->_logger('Bad Argument');
         throw new InvalidArgumentException();
     }
     // Begin sending command.
     $this->_imsp->send('SETACL ADDRESSBOOK ', true, false);
     // {} for book name?
     if (preg_match(Horde_Imsp_Client_Base::MUST_USE_LITERAL, $abook)) {
         $biBook = sprintf("{%d}", strlen($abook));
         $this->_imsp->send($biBook, false, true, true);
     }
     $this->_imsp->send("{$abook} ", false, false);
     // {} for ident?
     if (preg_match(Horde_Imsp_Client_Base::MUST_USE_LITERAL, $ident)) {
         $biIdent = sprintf("{%d}", strlen($ident));
         $this->_imsp->send($biIdent, false, true, true);
     }
     $this->_imsp->send("{$ident} ", false, false);
     // Now finish up with the actual ACL.
     $this->_imsp->send($acl, false, true);
     $response = $this->_imsp->receive();
     switch ($response) {
         case 'NO':
             // Could not create abook.
             $this->_imsp->_logger->err('IMSP server is unable to perform your request.');
             throw new Horde_Imsp_Exception('IMSP server is unable to perform your request.');
         case 'BAD':
             $this->_imsp->_logger->err('The IMSP server did not understand your request.');
             throw new Horde_Imsp_Exception('The IMSP server did not understand your request.');
         case 'OK':
             $this->_imsp->_logger->debug("ACL set for {$ident} on {$abook}");
             break;
         default:
             // Do not know why we would make it down here.
             $this->_imsp->_logger->err('Did not receive the expected response from the server.');
             throw new Horde_Imsp_Exception('Did not receive the expected response from the server.');
     }
 }