1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 06:14:39 +01:00

Applied fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-11-17 14:26:20 +00:00 committed by StyleCI Bot
parent ddf5bc7050
commit b18c16aedc
11 changed files with 58 additions and 45 deletions

View File

@ -16,6 +16,7 @@ class API extends Tools
{
public $API;
public $settings;
public function __construct($params = [])
{
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);

View File

@ -27,5 +27,4 @@ class APIFactory
{
return $this->API->method_call($this->namespace.$name, $arguments[0]);
}
}

View File

@ -17,7 +17,7 @@ namespace danog\MadelineProto;
*/
class DataCenter extends Tools
{
public $referenced_variables = ["time_delta", "temp_auth_key", "auth_key", "session_id", "seq_no"];
public $referenced_variables = ['time_delta', 'temp_auth_key', 'auth_key', 'session_id', 'seq_no'];
public $sockets;
public function __construct($dclist, $settings)
@ -72,23 +72,26 @@ class DataCenter extends Tools
$address = 'https://'.$subdomain.'.web.telegram.org/'.$path;
}
$this->sockets[$dc_number] = new Connection($address, $settings['port'], $settings['protocol']);
return true;
}
public function set_curdc($dc_number) {
public function set_curdc($dc_number)
{
$this->curdc = $dc_number;
foreach ($this->referenced_variables as $key) {
$this->{$key} = &$this->sockets[$dc_number]->{$key};
$this->{$key} = &$this->sockets[$dc_number]->{$key};
}
}
public function unset_curdc($dc_number) {
public function unset_curdc($dc_number)
{
unset($this->curdc);
foreach ($this->referenced_variables as $key) {
unset($this->sockets[$dc_number]->{$key});
}
}
public function __call($name, $arguments)
{
return $this->sockets[$this->curdc]->{$name}(...$arguments);

View File

@ -161,8 +161,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->datacenter->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']);
}
}
public function write_client_info($allow_switch) {
public function write_client_info($allow_switch)
{
\danog\MadelineProto\Logger::log('Writing client info...');
$nearest_dc = $this->method_call(
'invokeWithLayer',
@ -182,6 +183,5 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->switch_dc($nearest_dc['nearest_dc']);
$this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc'];
}
}
}

View File

@ -27,22 +27,22 @@ class AuthKeyHandler extends AckHandler
\danog\MadelineProto\Logger::log('Requesting pq');
/**
* ***********************************************************************
* Make pq request, DH exchange initiation.
*
* @method req_pq
*
* @param [
* int128 $nonce : The value of nonce is selected randomly by the client (random number) and identifies the client within this communication
* ]
*
* @return ResPQ [
* int128 $nonce : The value of nonce is selected randomly by the server
* int128 $server_nonce : The value of server_nonce is selected randomly by the server
* string $pq : This is a representation of a natural number (in binary big endian format). This number is the product of two different odd prime numbers
* Vector long $server_public_key_fingerprints : This is a list of public RSA key fingerprints
* ]
*/
* ***********************************************************************
* Make pq request, DH exchange initiation.
*
* @method req_pq
*
* @param [
* int128 $nonce : The value of nonce is selected randomly by the client (random number) and identifies the client within this communication
* ]
*
* @return ResPQ [
* int128 $nonce : The value of nonce is selected randomly by the server
* int128 $server_nonce : The value of server_nonce is selected randomly by the server
* string $pq : This is a representation of a natural number (in binary big endian format). This number is the product of two different odd prime numbers
* Vector long $server_public_key_fingerprints : This is a list of public RSA key fingerprints
* ]
*/
$nonce = \phpseclib\Crypt\Random::string(16);
$ResPQ = $this->method_call('req_pq',
[
@ -495,7 +495,7 @@ class AuthKeyHandler extends AckHandler
);
$int_message_id = $this->generate_message_id();
$this->check_message_id($int_message_id, true);
$message_id = \danog\PHP\Struct::pack('<Q', $int_message_id);
$seq_no = 0;
$encrypted_data = \phpseclib\Crypt\Random::string(16).$message_id.\danog\PHP\Struct::pack('<II', $seq_no, strlen($message_data)).$message_data;
@ -506,6 +506,7 @@ class AuthKeyHandler extends AckHandler
if ($this->method_call('auth.bindTempAuthKey', ['perm_auth_key_id' => $perm_auth_key_id, 'nonce' => $nonce, 'expires_at' => $expires_at, 'encrypted_message' => $encrypted_message], $int_message_id)) {
\danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.');
return true;
}
throw new Exception('An error occurred while binding temporary and permanent authorization keys.');

View File

@ -42,6 +42,7 @@ class CallHandler extends AuthKeyHandler
$dc = preg_replace('/[^0-9]+/', '', $response['error_message']);
\danog\MadelineProto\Logger::log('Received request to switch to DC '.$dc);
$this->switch_dc($dc);
return $this->method_call($this->outgoing_messages[$last_sent]['content']['method'], $this->outgoing_messages[$last_sent]['content']['args']);
break;

View File

@ -74,7 +74,7 @@ class MsgIdHandler extends MessageHandler
rand(0, 524288) << 2
);
*/
$keys = array_keys($this->outgoing_messages);
asort($keys);
$keys = end($keys);

View File

@ -35,15 +35,15 @@ class RSA extends TL\TL
sha1(
$this->serialize_param(
'bytes',
null,
null,
$this->n->toBytes()
)
.
$this->serialize_param(
'bytes',
null,
null,
$this->e->toBytes()
),
),
true
),
-8

View File

@ -123,7 +123,7 @@ class TL extends \danog\MadelineProto\Tools
break;
case 'int128':
case 'int256':
return (string)$value;
return (string) $value;
break;
case 'double':
return \danog\PHP\Struct::pack('<d', $value);
@ -222,7 +222,7 @@ class TL extends \danog\MadelineProto\Tools
break;
case 'vector':
if ($subtype == null) {
throw new Exception("deserialize: subtype is null");
throw new Exception('deserialize: subtype is null');
}
$count = \danog\PHP\Struct::unpack('<l', fread($bytes_io, 4)) [0];
$x = [];

View File

@ -50,22 +50,28 @@ class TLConstructor
}
$this->key++;
}
public function find_by_type($type) {
public function find_by_type($type)
{
$key = array_search($type, $this->type);
return ($key == false) ? false : [
'id' => $this->id[$key],
'id' => $this->id[$key],
'predicate' => $this->predicate[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
];
}
public function find_by_id($id) {
public function find_by_id($id)
{
$key = array_search($id, $this->id);
return ($key == false) ? false : [
'id' => $this->id[$key],
'id' => $this->id[$key],
'predicate' => $this->predicate[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
];
}
}

View File

@ -53,15 +53,17 @@ class TLMethod
}
$this->key++;
}
public function find_by_method($method) {
public function find_by_method($method)
{
$key = array_search($method, $this->method);
return ($key == false) ? false : [
'id' => $this->id[$key],
'method' => $this->method[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
'id' => $this->id[$key],
'method' => $this->method[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
'method_namespaced' => $this->method_namespaced[$key],
];
}
}