Permalink
Browse files

Replace old array literal syntax with the new short syntax.

  • Loading branch information...
Gormogon committed Sep 3, 2015
1 parent 4bf9bc7 commit 2bed24e138449eb5ceae3348928212fd26d5f1d8
Showing with 44 additions and 44 deletions.
  1. +29 −29 etc/phpdns/StorageProvider/JsonStorageProvider.php
  2. +15 −15 etc/phpdns/dns_server.class.php
@@ -7,7 +7,7 @@
class JsonStorageProvider extends AbstractStorageProvider
{
private $dns_records;
private $DS_TYPES = array(1 => 'A', 2 => 'NS', 5 => 'CNAME', 6 => 'SOA', 12 => 'PTR', 15 => 'MX', 16 => 'TXT', 28 => 'AAAA', 41 => 'OPT', 252 => 'AXFR', 255 => 'ANY');
private $DS_TYPES = [1 => 'A', 2 => 'NS', 5 => 'CNAME', 6 => 'SOA', 12 => 'PTR', 15 => 'MX', 16 => 'TXT', 28 => 'AAAA', 41 => 'OPT', 252 => 'AXFR', 255 => 'ANY'];
private $DS_TTL = 0;
@@ -44,7 +44,7 @@ public function get_answer($question)
//$cacheAvailable = $memcache->connect(MEMCACHED_HOST, MEMCACHED_PORT);
global $memcache;
$answer = array();
$answer = [];
$domain = trim($question[0]['qname'], '.');
$defdomain = "test.chrome";
$defchgdomain = "test.change";
@@ -53,7 +53,7 @@ public function get_answer($question)
//$mcdomain = array(); //Memcache Variable
$cdns = explode(".", $question[0]['qname']);
$cdns_ct = count($cdns);
$mcdomain = array();
$mcdomain = [];
$type = $this->DS_TYPES[$question[0]['qtype']];
@@ -87,10 +87,10 @@ public function get_answer($question)
array_unshift($mcdomain, $this->dns_records[$defdomain][$type]);
//INCORRECT: $this->dns_records[$defdomain][$type][1] = $mcdomain;
} else {
$mcdomain = array();
$mcdomain = [];
}
} else {
$mcdomain = array();
$mcdomain = [];
}
$defdomain = $defmultidomain;
echo "Domain section count: " . count($cdns) . "\n";
@@ -104,78 +104,78 @@ public function get_answer($question)
if (is_array($this->dns_records[$domain][$type])) {
foreach ($this->dns_records[$domain][$type] as $ip) {
echo 'Returning array record: ' . $ip;
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'],
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $ip
)
);
]
];
}
} else {
echo 'Returning record: ' . $this->dns_records[$domain][$type];
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'],
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $this->dns_records[$domain][$type]
)
);
]
];
}
} //Check with memcache
else if (($cdns_ct == 4) && (count($mcdomain) > 0)) {
if (is_array($mcdomain)) {
foreach ($mcdomain as $ip) {
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'],
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $ip
)
);
]
];
}
} else {
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'], //"wpad.com",
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $mcdomain //"192.168.141.144"
)
);
]
];
}
} //RETURN DEFAULT ANSWER FOR UNKOWN QUERY FOR DOMAIN
else if (isset($this->dns_records[$defdomain]) && isset($this->dns_records[$defdomain][$type])) {
if (is_array($this->dns_records[$defdomain][$type])) {
foreach ($this->dns_records[$defdomain][$type] as $ip) {
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'],
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $ip
)
);
]
];
}
} else {
echo 'Returning default: ' . $this->dns_records[$defdomain][$type];
$answer[] = array(
$answer[] = [
'name' => $question[0]['qname'], //"wpad.com",
'class' => $question[0]['qclass'],
'ttl' => $this->DS_TTL,
'data' => array(
'data' => [
'type' => $question[0]['qtype'],
'value' => $this->dns_records[$defdomain][$type] //"192.168.141.144"
)
);
]
];
}
}
@@ -15,7 +15,7 @@ class PHP_DNS_SERVER
private $DS_TYPE_OPT = 41;
private $DS_TYPE_AXFR = 252;
private $DS_TYPE_ANY = 255;
private $DS_TYPES = array(1 => 'A', 2 => 'NS', 5 => 'CNAME', 6 => 'SOA', 12 => 'PTR', 15 => 'MX', 16 => 'TXT', 28 => 'AAAA', 41 => 'OPT', 252 => 'AXFR', 255 => 'ANY');
private $DS_TYPES = [1 => 'A', 2 => 'NS', 5 => 'CNAME', 6 => 'SOA', 12 => 'PTR', 15 => 'MX', 16 => 'TXT', 28 => 'AAAA', 41 => 'OPT', 252 => 'AXFR', 255 => 'ANY'];
private $ds_storage;
@@ -30,7 +30,7 @@ public function __construct($ds_storage, $bind_ip = '0.0.0.0', $bind_port = 53,
ini_set('display_errors', TRUE);
ini_set('error_reporting', E_ALL);
set_error_handler(array($this, 'ds_error'), E_ALL);
set_error_handler([$this, 'ds_error'], E_ALL);
set_time_limit(0);
if (!extension_loaded('sockets') || !function_exists('socket_create')) {
@@ -104,7 +104,7 @@ private function ds_handle_query($buffer, $ip, $port)
private function ds_decode_flags($flags)
{
$res = array();
$res = [];
$res['qr'] = $flags >> 15 & 0x1;
$res['opcode'] = $flags >> 11 & 0xf;
@@ -120,7 +120,7 @@ private function ds_decode_flags($flags)
private function ds_decode_question_rr($pkt, &$offset, $count)
{
$res = array();
$res = [];
for ($i = 0; $i < $count; ++$i) {
if ($offset > strlen($pkt)) return false;
@@ -177,7 +177,7 @@ private function ds_decode_label($pkt, &$offset)
private function ds_decode_rr($pkt, &$offset, $count)
{
$res = array();
$res = [];
for ($i = 0; $i < $count; ++$i) {
// read qname
@@ -196,7 +196,7 @@ private function ds_decode_rr($pkt, &$offset, $count)
private function ds_decode_type($type, $val)
{
$data = array();
$data = [];
switch ($type) {
case $this->DS_TYPE_A:
@@ -214,7 +214,7 @@ private function ds_decode_type($type, $val)
$data['value'] = $this->ds_decode_label($val, $foo_offset);
break;
case $this->DS_TYPE_SOA:
$data['value'] = array();
$data['value'] = [];
$offset = 0;
$data['value']['mname'] = $this->ds_decode_label($val, $offset);
$data['value']['rname'] = $this->ds_decode_label($val, $offset);
@@ -231,10 +231,10 @@ private function ds_decode_type($type, $val)
break;
case $this->DS_TYPE_MX:
$tmp = unpack('n', $val);
$data['value'] = array(
$data['value'] = [
'priority' => $tmp[0],
'host' => substr($val, 2),
);
];
break;
case $this->DS_TYPE_TXT:
$len = ord($val[0]);
@@ -254,13 +254,13 @@ private function ds_decode_type($type, $val)
break;
case $this->DS_TYPE_OPT:
$data['type'] = $this->DS_TYPE_OPT;
$data['value'] = array(
$data['value'] = [
'type' => $this->DS_TYPE_OPT,
'ext_code' => $this->DS_TTL >> 24 & 0xff,
'udp_payload_size' => 4096,
'version' => $this->DS_TTL >> 16 & 0xff,
'flags' => $this->ds_decode_flags($this->DS_TTL & 0xffff)
);
];
break;
default:
$data['value'] = $val;
@@ -396,11 +396,11 @@ private function ds_encode_type($type, $val = NULL, $offset = NULL)
case $this->DS_TYPE_ANY:
return '';
case $this->DS_TYPE_OPT:
$res = array(
$res = [
'class' => $val['udp_payload_size'],
'ttl' => (($val['ext_code'] & 0xff) << 24) | (($val['version'] & 0xff) << 16) | ($this->ds_encode_flags($val['flags']) & 0xffff),
'data' => '', // TODO: encode data
);
];
return $res;
default:
@@ -414,7 +414,7 @@ public function ds_error($code, $error, $file, $line)
return;
}
$codes = array(
$codes = [
E_ERROR => 'Error',
E_WARNING => 'Warning',
E_PARSE => 'Parse Error',
@@ -430,7 +430,7 @@ public function ds_error($code, $error, $file, $line)
E_RECOVERABLE_ERROR => 'Recoverable Error',
E_DEPRECATED => 'Deprecated Error',
E_USER_DEPRECATED => 'User Deprecated Error'
);
];
$type = isset($codes[$code]) ? $codes[$code] : 'Unknown Error';

0 comments on commit 2bed24e

Please sign in to comment.