Exemple #1
0
 /**
  * Closes this connection
  *
  * @param boolean|string $connection - If connection is not given, or
  *   FALSE then connection that would be selected for writes would be
  *   closed. In a single-node configuration, that is then the whole
  *   connection, but if you are connected to a replica set, close() will
  *   only close the connection to the primary server.
  *
  * @return bool - Returns if the connection was successfully closed.
  */
 public function close($connection = null)
 {
     if ($this->socket) {
         $this->socket->disconnect();
         $this->protocol = null;
     }
     //TODO: implement $connection handling
 }
Exemple #2
0
Fichier : FTP.php Projet : uda/jaws
 /**
  * This function close the FTP-connection
  *
  * @access  public
  * @return  mixed Returns true on success, Jaws_Error on failure
  */
 function disconnect()
 {
     $res = $this->_ftp->disconnect();
     if (PEAR::isError($res)) {
         return new Jaws_Error('Error while disconnecting from server ' . $this->_host, __FUNCTION__);
     }
     return true;
 }
 /**
  * Destructs the storage object.
  */
 function __destruct()
 {
     $this->foowd->track('smdoc_db->destructor');
     // clean up object cache
     $this->objects->__destruct();
     // close connection
     $this->conn->disconnect();
     $this->foowd->track();
 }
Exemple #4
0
 /**
  * Attempt to disconnect from the SMTP server.
  *
  * @return mixed Returns a PEAR_Error with an error message on any
  *               kind of failure, or true on success.
  * @access public
  * @since  1.0
  */
 function disconnect()
 {
     if (PEAR::isError($error = $this->_put('QUIT'))) {
         return $error;
     }
     if (PEAR::isError($error = $this->_parseResponse(221))) {
         return $error;
     }
     if (PEAR::isError($error = $this->_socket->disconnect())) {
         return new PEAR_Error('Failed to disconnect socket: ' . $error->getMessage());
     }
     return true;
 }
Exemple #5
0
 /**
  * Attempt to disconnect from the SMTP server.
  *
  * @return mixed Returns a PEAR_Error with an error message on any
  *               kind of failure, or true on success.
  * @access public
  */
 function disconnect()
 {
     if (PEAR::isError($this->socket->write("QUIT\r\n"))) {
         return new PEAR_Error('write to socket failed');
     }
     if (!$this->validateResponse('221')) {
         return new PEAR_Error('221 Bye not received');
     }
     if (PEAR::isError($this->socket->disconnect())) {
         return new PEAR_Error('socket disconnect failed');
     }
     return true;
 }
 /**
  * Attempt to disconnect from the iMAP server.
  *
  * @return array Returns an array containing the response
  *
  * @access public
  * @since  1.0
  */
 function cmdLogout()
 {
     if (!$this->_connected) {
         return new PEAR_Error('not connected!');
     }
     if (PEAR::isError($args = $this->_genericCommand('LOGOUT'))) {
         return $args;
     }
     if (PEAR::isError($this->_socket->disconnect())) {
         return new PEAR_Error('socket disconnect failed');
     }
     return $args;
     // not for now
     //return $this->_genericImapResponseParser($args,$cmdid);
 }
 /**
  * Attempt to disconnect from the iMAP server.
  *
  * @return array Returns an array containing the response
  *
  * @access public
  * @since  1.0
  */
 function cmdLogout()
 {
     if (!$this->_connected) {
         return new PEAR_Error('not connected!');
     }
     $cmdid = $this->_getCmdId();
     if (PEAR::isError($error = $this->_putCMD($cmdid, 'LOGOUT'))) {
         return $error;
     }
     if (PEAR::isError($args = $this->_getRawResponse())) {
         return $args;
     }
     if (PEAR::isError($this->_socket->disconnect())) {
         return new PEAR_Error('socket disconnect failed');
     }
     return $args;
     // not for now
     //return $this->_genericImapResponseParser($args,$cmdid);
 }
Exemple #8
0
 /**
  * Sends out email via SMTP
  *
  * @return bool Success
  * @access private
  */
 private function __smtp()
 {
     App::import('Core', array('CakeSocket'));
     $this->__smtpConnection = new CakeSocket(array_merge(array('protocol' => 'smtp'), $this->smtpOptions));
     if (!$this->__smtpConnection->connect()) {
         $this->smtpError = $this->__smtpConnection->lastError();
         return false;
     } elseif (!$this->__smtpSend(null, '220')) {
         return false;
     }
     $httpHost = env('HTTP_HOST');
     if (isset($this->smtpOptions['client'])) {
         $host = $this->smtpOptions['client'];
     } elseif (!empty($httpHost)) {
         $host = $httpHost;
     } else {
         $host = 'localhost';
     }
     if (!$this->__smtpSend("HELO {$host}", '250')) {
         return false;
     }
     if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
         $authRequired = $this->__smtpSend('AUTH LOGIN', '334|503');
         if ($authRequired == '334') {
             if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
                 return false;
             }
             if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
                 return false;
             }
         } elseif ($authRequired != '503') {
             return false;
         }
     }
     if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) {
         return false;
     }
     if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) {
         return false;
     }
     foreach ($this->cc as $cc) {
         if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) {
             return false;
         }
     }
     foreach ($this->bcc as $bcc) {
         if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) {
             return false;
         }
     }
     if (!$this->__smtpSend('DATA', '354')) {
         return false;
     }
     $header = implode("\r\n", $this->__header);
     $message = implode("\r\n", $this->__message);
     if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
         return false;
     }
     $this->__smtpSend('QUIT', false);
     $this->__smtpConnection->disconnect();
     return true;
 }
Exemple #9
0
 /**
  * Attempt to disconnect from the SMTP server.
  *
  * @throws PEAR_Exception
  */
 public function disconnect()
 {
     //if (PEAR::isError($error = $this->_put('QUIT'))) {
     if (($error = $this->_put('QUIT')) === false) {
         return $error;
     }
     //if (PEAR::isError($error = $this->_parseResponse(221))) {
     if (($error = $this->_parseResponse(221)) === false) {
         return $error;
     }
     //if (PEAR::isError($error = $this->_socket->disconnect())) {
     if (($error = $this->_socket->disconnect()) === false) {
         return Net_SMTP::raiseError('Failed to disconnect socket: ' . $error->getMessage());
     }
     return true;
 }
Exemple #10
0
 /**
  * Logs out of the server and terminates the connection.
  *
  * @param boolean $sendLogoutCMD Whether to send LOGOUT command before
  *                               disconnecting.
  *
  * @return boolean  True on success, PEAR_Error otherwise.
  */
 function _cmdLogout($sendLogoutCMD = true)
 {
     if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
         return PEAR::raiseError('Not currently connected', 1);
     }
     if ($sendLogoutCMD) {
         if (PEAR::isError($res = $this->_doCmd('LOGOUT'))) {
             return $res;
         }
     }
     $this->_sock->disconnect();
     $this->_state = NET_SIEVE_STATE_DISCONNECTED;
     return true;
 }
 /**
  * Close connection to the server
  *
  * @access public
  */
 function cmdQuit()
 {
     // Tell the server to close the connection
     $response = $this->_sendCommand('QUIT');
     if (PEAR::isError($response)) {
         return $response;
     }
     switch ($response) {
         case 205:
             // RFC977: 'closing connection - goodbye!'
             // If socket is still open, close it.
             if ($this->isConnected()) {
                 $this->_socket->disconnect();
             }
             return true;
             break;
         default:
             return PEAR::throwError('Unidentified response code', $response, $this->currentStatusResponse());
     }
 }
 /**
  * Close the file and forget the filehandle
  */
 function close()
 {
     $this->dbh->disconnect();
     $this->dbh = false;
 }
 protected function disconnect()
 {
     $this->objConnection->disconnect();
     unset($this->objConnection);
 }
Exemple #14
0
 /**
  * Attempt to disconnect from the SMTP server.
  *
  * @throws PEAR_Exception
  */
 public function disconnect()
 {
     try {
         $this->_put('QUIT');
         $this->_parseResponse(221);
         $this->_socket->disconnect();
     } catch (Net_Socket2_Exception $e) {
         // Already disconnected? Silence!
     }
     return true;
 }
Exemple #15
0
 /**
  * Desconnects from SMSC/SMS gateway gracefully
  * @access public
  * @return boolean Always TRUE
  */
 public function disconnect()
 {
     if ($this->state == ESS_BIND_TX || $this->state == ESS_BIND_RX) {
         l('ESME sending UNBIND command...');
         $this->sock->send($this->form_pdu(UNBIND));
         $pdu = $this->sock->pdu_wait_for(UNBIND | ACK, $this->sqn);
         $res = $this->parse_pdu_header(substr($pdu, 0, 16));
         if ($res['stat'] !== 0) {
             l('UNBIND failed: ' . $res['stat'] . '.', L_WARN);
         } else {
             l('UNBIND done.');
         }
     }
     $this->state = ESS_DISCONNECTED;
     $this->sock->disconnect();
     return true;
 }
Exemple #16
0
 /**
  * Sends out email via SMTP
  *
  * @return bool Success
  * @access private
  */
 function __smtp()
 {
     App::import('Core', array('Socket'));
     $this->__smtpConnection =& new CakeSocket(array_merge(array('protocol' => 'smtp'), $this->smtpOptions));
     if (!$this->__smtpConnection->connect()) {
         $this->smtpError = $this->__smtpConnection->lastError();
         return false;
     } elseif (!$this->__smtpSend(null, '220')) {
         return false;
     }
     if (!$this->__smtpSend('HELO cake', '250')) {
         return false;
     }
     if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
         if (!$this->__smtpSend('AUTH LOGIN', '334')) {
             return false;
         }
         if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
             return false;
         }
         if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
             return false;
         }
     }
     if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) {
         return false;
     }
     if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) {
         return false;
     }
     foreach ($this->cc as $cc) {
         if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) {
             return false;
         }
     }
     foreach ($this->bcc as $bcc) {
         if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) {
             return false;
         }
     }
     if (!$this->__smtpSend('DATA', '354')) {
         return false;
     }
     $header = implode("\r\n", $this->__header);
     $message = implode("\r\n", $this->__message);
     if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
         return false;
     }
     $this->__smtpSend('QUIT', false);
     $this->__smtpConnection->disconnect();
     return true;
 }
 /**
  * Sends out email via SMTP
  *
  * @return bool Success
  * @access private
  */
 function _smtp()
 {
     App::import('Core', array('CakeSocket'));
     $defaults = array('host' => 'localhost', 'port' => 25, 'protocol' => 'smtp', 'timeout' => 30);
     $this->smtpOptions = array_merge($defaults, $this->smtpOptions);
     $this->_getSocket($this->smtpOptions);
     if (!$this->__smtpConnection->connect()) {
         $this->smtpError = $this->__smtpConnection->lastError();
         return false;
     } elseif (!$this->_smtpSend(null, '220')) {
         return false;
     }
     $httpHost = env('HTTP_HOST');
     if (isset($this->smtpOptions['client'])) {
         $host = $this->smtpOptions['client'];
     } elseif (!empty($httpHost)) {
         list($host) = explode(':', $httpHost);
     } else {
         $host = 'localhost';
     }
     if (!$this->_smtpSend("EHLO {$host}", '250') && !$this->_smtpSend("HELO {$host}", '250')) {
         return false;
     }
     if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
         $authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
         if ($authRequired == '334') {
             if (!$this->_smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
                 return false;
             }
             if (!$this->_smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
                 return false;
             }
         } elseif ($authRequired != '503') {
             return false;
         }
     }
     if (!$this->_smtpSend('MAIL FROM: ' . $this->_formatAddress($this->from, true))) {
         return false;
     }
     if (!is_array($this->to)) {
         $tos = array_map('trim', explode(',', $this->to));
     } else {
         $tos = $this->to;
     }
     foreach ($tos as $to) {
         if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($to, true))) {
             return false;
         }
     }
     foreach ($this->cc as $cc) {
         if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($cc, true))) {
             return false;
         }
     }
     foreach ($this->bcc as $bcc) {
         if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($bcc, true))) {
             return false;
         }
     }
     if (!$this->_smtpSend('DATA', '354')) {
         return false;
     }
     $header = implode("\r\n", $this->__header);
     $message = implode("\r\n", $this->__message);
     if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
         return false;
     }
     $this->_smtpSend('QUIT', false);
     $this->__smtpConnection->disconnect();
     return true;
 }
Exemple #18
0
 /**
  * Attempt to disconnect from the SMTP server.
  *
  * @return mixed Returns a PEAR_Error with an error message on any
  *			   kind of failure, or true on success.
  * @access public
  * @since  1.0
  */
 public function disconnect()
 {
     if (Error::is_error($error = $this->_put('QUIT'))) {
         return $error;
     }
     if (Error::is_error($error = $this->_parseResponse(221))) {
         return $error;
     }
     if (Error::is_error($error = $this->_socket->disconnect())) {
         throw Error::raise('Failed to disconnect socket: ' . $error->getMessage());
     }
     return true;
 }