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.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  6.6 KB  |  309 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Contains the Services_DynDNS 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: DynDNS.php,v 1.1 2005/08/13 14:25:34 bdunlap Exp $
  22.  * @link       http://pear.php.net/package/Services_DynDNS
  23.  */
  24.  
  25. /**
  26.  * Load Services_DynDNS_Request
  27.  */
  28. require_once 'Services/DynDNS/Request.php';
  29.  
  30. /**
  31.  * Load Services_DynDNS_Response
  32.  */
  33. require_once 'Services/DynDNS/Response.php';
  34.  
  35. // {{{ constants
  36.  
  37. /**
  38.  * API Version of this package
  39.  */
  40. define('SERVICES_DYNDNS_API_VERSION', '0.3.1');
  41.  
  42. // {{{ defaults
  43.  
  44. /**
  45.  * The host name of the DynDNS web service
  46.  */
  47. define('SERVICES_DYNDNS_DEFAULT_HOST', 'members.dyndns.org');
  48.  
  49. /**
  50.  * The default HTTP version to use in requests
  51.  */
  52. define('SERVICES_DYNDNS_DEFAULT_HTTP_VERSION', '1.0');
  53.  
  54. /**
  55.  * The path to the DynDNS web service
  56.  */
  57. define('SERVICES_DYNDNS_DEFAULT_SERVICE', '/nic/update');
  58.  
  59. /**
  60.  * The default system to use for requests 
  61.  */
  62. define('SERVICES_DYNDNS_DEFAULT_SYSTEM', 'dyndns');
  63.  
  64. /**
  65.  * The default HTTP request method to use
  66.  */
  67. define('SERVICES_DYNDNS_DEFAULT_REQUEST_TYPE', HTTP_REQUEST_METHOD_GET);
  68.  
  69. /**
  70.  * Name of the user agent to use in requests
  71.  */
  72. define('SERVICES_DYNDNS_DEFAULT_USER_AGENT', 'Services_DynDNS/' . 
  73.                                              SERVICES_DYNDNS_API_VERSION);
  74.  
  75. // }}}
  76. // {{{ error codes
  77.  
  78. /**
  79.  * Unknown error
  80.  */
  81. define('SERVICES_DYNDNS_ERROR', 'unknown');
  82.  
  83. /**
  84.  * User agent blocked
  85.  */
  86. define('SERVICES_DYNDNS_ERROR_BADAGENT', 'badagent');
  87.  
  88. /**
  89.  * Username and/or password not valid
  90.  */
  91. define('SERVICES_DYNDNS_ERROR_BADAUTH', 'badauth');
  92.  
  93. /**
  94.  * Not a recognized DynDNS system
  95.  */
  96. define('SERVICES_DYNDNS_ERROR_BADSYS', 'badsys');
  97.  
  98. /**
  99.  * Not a credited user account
  100.  */
  101. define('SERVICES_DYNDNS_ERROR_NODONATOR', '!donator');
  102.  
  103. /**
  104.  * Not a fully qualified domain name
  105.  */
  106. define('SERVICES_DYNDNS_ERROR_NOFQDN', 'notfqdn');
  107.  
  108. /**
  109.  * Hostname does not exist
  110.  */
  111. define('SERVICES_DYNDNS_ERROR_NOHOST', 'nohost');
  112.  
  113. /**
  114.  * Hostname does not belong to this user account
  115.  */
  116. define('SERVICES_DYNDNS_ERROR_NOTYOURS', '!yours');
  117.  
  118. /**
  119.  * Hostname blocked for update abuse
  120.  */
  121. define('SERVICES_DYNDNS_ERROR_ABUSE', 'abuse');
  122.  
  123. /**
  124.  * Name of the user agent to use in requests
  125.  */
  126. define('SERVICES_DYNDNS_ERROR_NUMHOST', 'numhost');
  127.  
  128. /**
  129.  * DNS error
  130.  */
  131. define('SERVICES_DYNDNS_ERROR_DNSERROR', 'dnserr');
  132.  
  133. /**
  134.  * Critical error
  135.  */
  136. define('SERVICES_DYNDNS_ERROR_CRITICAL', '911');
  137.  
  138. // }}}
  139. // {{{ success codes
  140.  
  141. /**
  142.  * Update successful
  143.  */
  144. define('SERVICES_DYNDNS_SUCCESS_GOOD', 'good');
  145.  
  146. /**
  147.  * Update successful - no data changed
  148.  */
  149. define('SERVICES_DYNDNS_SUCCESS_NOCHG', 'nochg');
  150.  
  151. // }}}
  152. // {{{ parameter values
  153.  
  154. /**
  155.  * Parameter value for 'off'
  156.  */
  157. define('SERVICES_DYNDNS_PARAM_VALUE_OFF', 'OFF');
  158.  
  159. /**
  160.  * Parameter value for 'on'
  161.  */
  162. define('SERVICES_DYNDNS_PARAM_VALUE_ON', 'ON');
  163.  
  164. /**
  165.  * Parameter value for 'no'
  166.  */
  167. define('SERVICES_DYNDNS_PARAM_VALUE_NO', 'NO');
  168.  
  169. /**
  170.  * Parameter value for 'no change'
  171.  */
  172. define('SERVICES_DYNDNS_PARAM_VALUE_NOCHG', 'NOCHG');
  173.  
  174. /**
  175.  * Parameter value for 'yes'
  176.  */
  177. define('SERVICES_DYNDNS_PARAM_VALUE_YES', 'YES');
  178.  
  179. // }}}
  180.  
  181.  
  182.  
  183. // }}}
  184. // {{{ Services_DynDNS
  185.  
  186. /**
  187.  * A container class with a static service method for sending requests to the
  188.  * DynDNS REST API
  189.  *
  190.  * @category   Web Services
  191.  * @package    Services_DynDNS
  192.  * @author     Bryan Dunlap <bdunlap@bryandunlap.com>
  193.  * @copyright  2005 Bryan Dunlap
  194.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  195.  * @version    Release: 0.3.1
  196.  */
  197. class Services_DynDNS
  198. {
  199.  
  200.     // {{{ apiVersion()
  201.     
  202.     /**
  203.      * Gets the current API version for the Services_DynDNS package
  204.      *
  205.      * @return string
  206.      * @access public
  207.      * @static
  208.      */
  209.     function apiVersion()
  210.     {
  211.         return SERVICES_DYNDNS_API_VERSION;
  212.     }
  213.     
  214.     // }}}
  215.     // {{{ getUserAgent()
  216.     
  217.     /**
  218.      * Retrieves the current user agent
  219.      *
  220.      * @return string
  221.      * @access public
  222.      * @static
  223.      */
  224.     function getUserAgent()
  225.     {
  226.         return Services_DynDNS::_userAgent();
  227.     }
  228.  
  229.     // }}}
  230.     // {{{ setUserAgent()
  231.     
  232.     /**
  233.      * Sets a client-specific user agent
  234.      *
  235.      * @param  string $userAgent  a string containing the user-agent
  236.      * @return void
  237.      * @access public
  238.      * @static
  239.      */
  240.     function setUserAgent($userAgent)
  241.     {
  242.         Services_DynDNS::_userAgent($userAgent);
  243.     }
  244.     
  245.     // }}}
  246.     // {{{ sendRequest()
  247.  
  248.     /**
  249.      * Sends a DynDNS_Request to the DynDNS REST web service
  250.      *
  251.      * @param  object $request  a DynDNS_Request object
  252.      * @return object A Services_DynDNS_Response object, PEAR_Error on failure
  253.      * @access public
  254.      * @static
  255.      */
  256.     function &sendRequest(&$request)
  257.     {
  258.         if (!is_a($request, 'Services_DynDNS_Request_common')) {
  259.             return PEAR::raiseError("Not a valid instance of " .
  260.                                     "'Services_DynDNS_Request_common'");
  261.         }
  262.         $httpRequest =& $request->build();
  263.         $httpRequest->sendRequest();
  264.         if ($httpRequest->getResponseCode() != '200') {
  265.             return PEAR::raiseError("Unexpected HTTP response code " .
  266.                                     "'{$httpRequest->getResponseCode()}'",
  267.                                     $httpRequest->getResponseCode());
  268.         }
  269.         return new Services_DynDNS_Response($request->getParameter('hostname'),
  270.                                             $request->getParameter('myip'),
  271.                                             $httpRequest->getResponseBody());
  272.     }
  273.     
  274.     // }}}
  275.     // {{{ _userAgent()
  276.     
  277.     /**
  278.      * Provides internal read/write access to the static user agent variable
  279.      *
  280.      * @param  string $value  (optional) a string containing the user-agent
  281.      * @return mixed                     $userAgent if $value is false, or void
  282.      * @access private
  283.      * @static
  284.      */
  285.     function _userAgent($value = false)
  286.     {
  287.         static $userAgent;
  288.         if ($value === false) {
  289.             return $userAgent;
  290.         }
  291.         $userAgent = $value;
  292.     }
  293.     
  294.     // }}}
  295.     
  296. }
  297.  
  298. // }}}
  299.  
  300. /*
  301.  * Local variables:
  302.  * tab-width: 4
  303.  * c-basic-offset: 4
  304.  * c-hanging-comment-ender-p: nil
  305.  * End:
  306.  */
  307.  
  308. ?>
  309.