home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Services / DynDNS / Response.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  5.0 KB  |  156 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Contains the Services_DynDNS_Response class
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  * 
  16.  * @category   Web Services
  17.  * @package    Services_DynDNS
  18.  * @author     Bryan Dunlap <bdunlap@bryandunlap.com>
  19.  * @copyright  2005 Bryan Dunlap
  20.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version    CVS: $Id: Response.php,v 1.2 2005/08/13 14:32:16 bdunlap Exp $
  22.  * @link       http://pear.php.net/package/Services_DynDNS
  23.  */
  24.  
  25. // {{{ Services_DynDNS_Response
  26.  
  27. /**
  28.  * Encapsulates a response (or collection of responses) returned 
  29.  * from the DynDNS REST API
  30.  *
  31.  * @category   Web Services
  32.  * @package    Services_DynDNS
  33.  * @author     Bryan Dunlap <bdunlap@bryandunlap.com>
  34.  * @copyright  2005 Bryan Dunlap
  35.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  36.  * @version    Release: 0.3.1
  37.  */
  38. class Services_DynDNS_Response
  39. {
  40.     
  41.     // {{{ properties
  42.     
  43.     /**
  44.      * IP Address that was part of the initial request
  45.      *
  46.      * @var    string
  47.      * @access private
  48.      */
  49.     var $_requestedIP;
  50.     
  51.     /**
  52.      * DynDNS error codes and custom error messages
  53.      *
  54.      * @var    array
  55.      * @access private
  56.      */
  57.     var $_errorCodes   = array(SERVICES_DYNDNS_ERROR           => 'unknown',
  58.                                SERVICES_DYNDNS_ERROR_BADAGENT  => 'bad user agent',
  59.                                SERVICES_DYNDNS_ERROR_BADAUTH   => 'bad username and/or password',
  60.                                SERVICES_DYNDNS_ERROR_BADSYS    => 'bad system type',
  61.                                SERVICES_DYNDNS_ERROR_NODONATOR => 'not a credited user',
  62.                                SERVICES_DYNDNS_ERROR_NOFQDN    => 'not a fqdn',
  63.                                SERVICES_DYNDNS_ERROR_NOHOST    => 'hostname not found',
  64.                                SERVICES_DYNDNS_ERROR_NOTYOURS  => 'hostname not with user account',
  65.                                SERVICES_DYNDNS_ERROR_ABUSE     => 'hostname blocked for abuse',
  66.                                SERVICES_DYNDNS_ERROR_NUMHOST   => 'too many or too few hosts',
  67.                                SERVICES_DYNDNS_ERROR_DNSERROR  => 'dns error',
  68.                                SERVICES_DYNDNS_ERROR_CRITICAL  => 'critical error');
  69.     
  70.     /**
  71.      * DynDNS success codes and custom success messages
  72.      *
  73.      * @var    array
  74.      * @access private
  75.      */
  76.     var $_successCodes = array(SERVICES_DYNDNS_SUCCESS_GOOD    => 'update successful',
  77.                                SERVICES_DYNDNS_SUCCESS_NOCHG   => 'update successful - no change');
  78.     
  79.     /**
  80.      * Response(s) from the DynDNS REST API
  81.      *
  82.      * @var    array
  83.      * @access private
  84.      */
  85.     var $_parts = array();
  86.     
  87.     // }}}
  88.     // {{{ constructor
  89.     
  90.     /**
  91.      * Constructor
  92.      *
  93.      * @param string $hostname          the string containing the hostname
  94.      * @param string $ipAddress         the string containing the ip address
  95.      * @param string $httpResponseBody  the string containing the
  96.      *                                     http response body
  97.      * @return void
  98.      * @access public
  99.      */
  100.     function Services_DynDNS_Response($hostname, $ipAddress, $httpResponseBody)
  101.     {
  102.         $hostnameParts = explode(',', $hostname);
  103.         $this->_requestedIP = $ipAddress;
  104.         $responseBodyParts = explode("\n", $httpResponseBody);
  105.         $count = count($hostnameParts);
  106.         for ($i = 0; $i < $count; $i++) {
  107.             $this->_parts[$i]['hostname'] = $hostnameParts[$i];
  108.             $this->_parts[$i]['responseBody'] = $responseBodyParts[$i];
  109.         }
  110.     }
  111.     
  112.     // }}}
  113.     // {{{ get()
  114.     
  115.     /**
  116.      * Retrieves the next available response
  117.      *
  118.      * @return array
  119.      * @access public
  120.      */
  121.     function get()
  122.     {
  123.         if (!$response = array_shift($this->_parts)) {
  124.             return false;
  125.         }
  126.         $responseBodyParts = explode(' ', $response['responseBody']);
  127.         $current = array();
  128.         $current['hostname'] = $response['hostname'];
  129.         $current['ipAddress'] = isset($responseBodyParts[1]) ?
  130.                                 $responseBodyParts[1] : $this->_requestedIP;
  131.         $current['code'] = $responseBodyParts[0];
  132.         $current['success'] = array_key_exists($current['code'], 
  133.                                                $this->_errorCodes) ?
  134.                                                false : true;
  135.         $current['message'] = $current['success'] ?
  136.                               $this->_successCodes[$current['code']] :
  137.                               $this->_errorCodes[$current['code']];
  138.         return $current;
  139.     }
  140.     
  141.     // }}}
  142.     
  143. }
  144.  
  145. // }}}
  146.  
  147. /*
  148.  * Local variables:
  149.  * tab-width: 4
  150.  * c-basic-offset: 4
  151.  * c-hanging-comment-ender-p: nil
  152.  * End:
  153.  */
  154.  
  155. ?>
  156.