/[drupal]/contributions/modules/asterisk/drupal_integration/support.inc
ViewVC logotype

Diff of /contributions/modules/asterisk/drupal_integration/support.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3, Fri Feb 16 05:18:04 2007 UTC revision 1.4, Sun Nov 11 06:08:58 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: support.inc,v 1.2 2006/09/12 04:19:53 thehunmonkgroup Exp $  // $Id: support.inc,v 1.3 2007/02/16 05:18:04 thehunmonkgroup Exp $
3    
4  /**  /**
5   * These are the additional functions needed to run XML-RPC client/server processes   * These are the additional functions needed to run XML-RPC client/server processes
# Line 35  function check_plain($text) { Line 35  function check_plain($text) {
35   *   redirect.   *   redirect.
36   * @return   * @return
37   *   An object containing the HTTP request headers, response code, headers,   *   An object containing the HTTP request headers, response code, headers,
38   *   data, and redirect status.   *   data and redirect status.
39   */   */
40  function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {  function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
41    $result = new stdClass();    $result = new stdClass();
42    
43    // Parse the URL, and make sure we can handle the schema.    // Parse the URL and make sure we can handle the schema.
44    $uri = parse_url($url);    $uri = parse_url($url);
45    
46    switch ($uri['scheme']) {    switch ($uri['scheme']) {
47      case 'http':      case 'http':
48        $port = isset($uri['port']) ? $uri['port'] : 80;        $port = isset($uri['port']) ? $uri['port'] : 80;
# Line 61  function drupal_http_request($url, $head Line 62  function drupal_http_request($url, $head
62    
63    // Make sure the socket opened properly.    // Make sure the socket opened properly.
64    if (!$fp) {    if (!$fp) {
65      $result->error = trim($errno .' '. $errstr);      // When a network error occurs, we make sure that it is a negative number so
66        // it can clash with the HTTP status codes.
67        $result->code = -$errno;
68        $result->error = trim($errstr);
69      return $result;      return $result;
70    }    }
71    
# Line 74  function drupal_http_request($url, $head Line 78  function drupal_http_request($url, $head
78    // Create HTTP request.    // Create HTTP request.
79    $defaults = array(    $defaults = array(
80      // RFC 2616: "non-standard ports MUST, default ports MAY be included".      // RFC 2616: "non-standard ports MUST, default ports MAY be included".
81      // We don't add the port to prevent from breaking rewrite rules checking      // We don't add the port to prevent from breaking rewrite rules checking the
82      // the host that do not take into account the port number.      // host that do not take into account the port number.
83      'Host' => "Host: $host",      'Host' => "Host: $host",
84      'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',      'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
85      'Content-Length' => 'Content-Length: '. strlen($data)      'Content-Length' => 'Content-Length: '. strlen($data)
86    );    );
87    
88      // If the server url has a user then attempt to use basic authentication
89      if (isset($uri['user'])) {
90        $defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
91      }
92    
93    foreach ($headers as $header => $value) {    foreach ($headers as $header => $value) {
94      $defaults[$header] = $header .': '. $value;      $defaults[$header] = $header .': '. $value;
95    }    }
# Line 129  function drupal_http_request($url, $head Line 138  function drupal_http_request($url, $head
138      400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',      400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
139      500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'      500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
140    );    );
141    // RFC 2616 states that all unknown HTTP codes must be treated the same as    // RFC 2616 states that all unknown HTTP codes must be treated the same as the
142    // the base code in their class.    // base code in their class.
143    if (!isset($responses[$code])) {    if (!isset($responses[$code])) {
144      $code = floor($code / 100) * 100;      $code = floor($code / 100) * 100;
145    }    }
# Line 180  function t($string, $args = 0) { Line 189  function t($string, $args = 0) {
189   * @param $url   * @param $url
190   *   An absolute URL of the XML-RPC endpoint.   *   An absolute URL of the XML-RPC endpoint.
191   *     Example:   *     Example:
192   *     http://www.domain.com/xmlrpc.php   *     http://www.example.com/xmlrpc.php
193   * @param ...   * @param ...
194   *   For one request:   *   For one request:
195   *     The method name followed by a variable number of arguments to the method.   *     The method name followed by a variable number of arguments to the method.

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2