setDebug(1); } // Build our key $timestamp = time(); $handshake_key = hash('sha256',$timestamp . hash('sha256',$key)); $encoded_key = new XML_RPC_Value($handshake_key,'string'); $timestamp = new XML_RPC_Value($timestamp,'int'); $xmlrpc_message = new XML_RPC_Message('xmlrpcserver.handshake',array($encoded_key,$timestamp)); // Send it off $response = $client->send($xmlrpc_message,10); if ($response->faultCode()) { $error_msg = _('Error connecting to') . " " . $client->server . " " . _("Code") . ": " . $response->faultCode() . " " . _("Reason") . ": " . $response->faultString(); debug_event('XMLCLIENT',$error_msg,'1'); Error::add('general',$error_msg); return; } $token = XML_RPC_Decode($response->value()); debug_event('XML-RPC',$token . ' returned from ' . $client->server,'3'); return $token; } // ampache_handshake /** * ampache_create_stream_session * This generates a new stream session, it takes a target_url and a token as generated by * a ampache_handshake action */ public static function ampache_create_stream_session($target_url,$token) { $client = self::create_client($target_url); // 6 that's right, the secret level because if you do have debug on most likely you're // going to just crash your browser... sorry folks if (Config::get('debug') AND Config::get('debug_level') == '6') { $client->setDebug(1); } $encoded_key = new XML_RPC_Value($token,'string'); $xmlrpc_message = new XML_RPC_Message('xmlrpcserver.create_stream_session',array($encoded_key)); $response = $client->send($xmlrpc_message,4); if ($response->faultCode() ) { $error_msg = _("Error connecting to") . " " . $client->server . " " . _("Code") . ": " . $response->faultCode() . " " . debug_event('XMLCLIENT',$error_msg,'1'); return false; } $sid = XML_RPC_Decode($response->value()); debug_event('XML-RPC', $sid . ' stream session ID returned from ' . $client->server,'3'); return $sid; } // ampache_create_stream_session /** * create_client * This creates the xmlrpc client object from a URL */ public static function create_client($target_url) { // Figure out the host etc preg_match("/http:\/\/([^\/\:]+):?(\d*)\/*(.*)/", $target_url, $match); $server = $match['1']; $port = $match['2'] ? intval($match['2']) : '80'; $path = $match['3']; if(Config::get('proxy_host') AND Config::get('proxy_port')) { $proxy_host = Config::get('proxy_host'); $proxy_port = Config::get('proxy_port'); $proxy_user = Config::get('proxy_user'); $proxy_pass = Config::get('proxy_pass'); } $full_url = "/" . ltrim($path . "/server/xmlrpc.server.php",'/'); $client = new XML_RPC_Client($full_url,$server,$port,$proxy_host,$proxy_port,$proxy_user,$proxy_pass); return $client; } // create_client } // xmlRpcClient ?>