X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fxmlrpcclient.php;h=c359730f33921044b00f9a07187645051d4d8f5c;hb=c504af53e5b3e13f19039f1ab03cd16279ce4967;hp=8784a0c2b5d392da58aadb457a17616fef4e6685;hpb=df69f0b9e58a6edcd47e9b6dfcf971526f268d45;p=platal.git diff --git a/classes/xmlrpcclient.php b/classes/xmlrpcclient.php index 8784a0c..c359730 100644 --- a/classes/xmlrpcclient.php +++ b/classes/xmlrpcclient.php @@ -1,147 +1,6 @@ url = $url; $this->urlparts = parse_url($this->url); - foreach (array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) { - if (!isset($this->urlparts[$part])) { - $this->urlparts[$part] = null; - } + + if (empty($this->urlparts['port'])) { + $this->urlparts['port'] = 80; + } + + if (empty($this->urlparts['path'])) { + $this->urlparts['path'] = '/'; } } - function __call($function, $arguments) + private function http_post($request) { - $requestprms['host'] = $this->urlparts['host']; - $requestprms['port'] = $this->urlparts['port']; - $requestprms['uri'] = $this->urlparts['path']; - $requestprms['user'] = $this->urlparts['user']; - $requestprms['pass'] = $this->urlparts['pass']; - $requestprms['method'] = $function; - $requestprms['args'] = $arguments; - $requestprms['timeout'] = 0; - $requestprms['secure'] = 0; - - $result = xu_rpc_http_concise($requestprms); + $host = $path = $port = $user = $pass = null; + extract($this->urlparts); + + if ($scheme == 'https') { + $host = 'ssl://'.$host; + } + + $query_fd = fsockopen($host, $port, $errno, $errstr, 10); + if (!$query_fd) + return null; + + $auth = ''; + if ($user) { + $auth = 'Authorization: Basic ' . base64_encode("$user:$pass") . "\r\n"; + } + + $content_len = strlen($request); + $http_request = + "POST $path HTTP/1.0\r\n" . + $auth . + "Content-Type: text/xml\r\n" . + "Content-Length: $content_len\r\n" . + "Connection: Close\r\n" . + "Host: $host:$port\r\n" . + "\r\n" . + $request; + + fputs($query_fd, $http_request, strlen($http_request)); + + $buf = ''; + while (!feof($query_fd)) { + $buf .= fread($query_fd, 8192); + } + + fclose($query_fd); + return $buf; + } + + private function find_and_decode_xml($buf) + { + $pos = strpos($buf, 'bt) { + $this->bt->start($method . "\n" . var_export($args, true)); + } + $answer = $this->http_post($query, $this->urlparts); + if ($this->bt) { + $this->bt->stop(); + } + $result = $this->find_and_decode_xml($answer); + if ($this->bt) { + if (is_array($result) && isset($result['faultCode'])) { + $this->bt->update(0, $result['faultString']); + } else { + $this->bt->update(count($result)); + } + } + if (is_array($result) && isset($result['faultCode'])) { - print('Error in xmlrpc call \''.$function.'\''."\n"); - print(' code : '.$result['faultCode']."\n"); - print(' message: '.$result['faultString']."\n"); + trigger_error("Error in xmlrpc call $function\n". + " code : {$result['faultCode']}\n". + " message: {$result['faultString']}\n"); return null; } return $result; } - } -// vim:set et sw=4 sts=4 sws=4: +// vim:set et sw=4 sts=4 sws=4 enc=utf-8: ?>