line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
55058
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
123
|
|
2
|
3
|
|
|
3
|
|
28
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
241
|
|
3
|
|
|
|
|
|
|
package Net::MQTT::Constants; |
4
|
|
|
|
|
|
|
$Net::MQTT::Constants::VERSION = '1.163170'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Module to export constants for MQTT protocol |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
18
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
489
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %constants = |
11
|
|
|
|
|
|
|
( |
12
|
|
|
|
|
|
|
MQTT_CONNECT => 0x1, |
13
|
|
|
|
|
|
|
MQTT_CONNACK => 0x2, |
14
|
|
|
|
|
|
|
MQTT_PUBLISH => 0x3, |
15
|
|
|
|
|
|
|
MQTT_PUBACK => 0x4, |
16
|
|
|
|
|
|
|
MQTT_PUBREC => 0x5, |
17
|
|
|
|
|
|
|
MQTT_PUBREL => 0x6, |
18
|
|
|
|
|
|
|
MQTT_PUBCOMP => 0x7, |
19
|
|
|
|
|
|
|
MQTT_SUBSCRIBE => 0x8, |
20
|
|
|
|
|
|
|
MQTT_SUBACK => 0x9, |
21
|
|
|
|
|
|
|
MQTT_UNSUBSCRIBE => 0xa, |
22
|
|
|
|
|
|
|
MQTT_UNSUBACK => 0xb, |
23
|
|
|
|
|
|
|
MQTT_PINGREQ => 0xc, |
24
|
|
|
|
|
|
|
MQTT_PINGRESP => 0xd, |
25
|
|
|
|
|
|
|
MQTT_DISCONNECT => 0xe, |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
MQTT_QOS_AT_MOST_ONCE => 0x0, |
28
|
|
|
|
|
|
|
MQTT_QOS_AT_LEAST_ONCE => 0x1, |
29
|
|
|
|
|
|
|
MQTT_QOS_EXACTLY_ONCE => 0x2, |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
MQTT_CONNECT_ACCEPTED => 0, |
32
|
|
|
|
|
|
|
MQTT_CONNECT_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION => 1, |
33
|
|
|
|
|
|
|
MQTT_CONNECT_REFUSED_IDENTIFIER_REJECTED => 2, |
34
|
|
|
|
|
|
|
MQTT_CONNECT_REFUSED_SERVER_UNAVAILABLE => 3, |
35
|
|
|
|
|
|
|
MQTT_CONNECT_REFUSED_BAD_USER_NAME_OR_PASSWORD => 4, |
36
|
|
|
|
|
|
|
MQTT_CONNECT_REFUSED_NOT_AUTHORIZED => 5, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
3
|
|
|
3
|
|
18
|
no strict qw/refs/; ## no critic |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3181
|
|
41
|
42
|
|
|
42
|
|
120
|
my $pkg = caller(0); |
42
|
42
|
|
|
|
|
264
|
foreach (keys %constants) { |
43
|
966
|
|
|
|
|
912
|
my $v = $constants{$_}; |
44
|
966
|
|
|
0
|
|
3888
|
*{$pkg.'::'.$_} = sub () { $v }; |
|
966
|
|
|
|
|
3914
|
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
42
|
|
|
|
|
119
|
foreach (qw/decode_byte encode_byte |
47
|
|
|
|
|
|
|
decode_short encode_short |
48
|
|
|
|
|
|
|
decode_string encode_string |
49
|
|
|
|
|
|
|
decode_remaining_length encode_remaining_length |
50
|
|
|
|
|
|
|
qos_string |
51
|
|
|
|
|
|
|
message_type_string |
52
|
|
|
|
|
|
|
dump_string |
53
|
|
|
|
|
|
|
connect_return_code_string |
54
|
|
|
|
|
|
|
/) { |
55
|
504
|
|
|
|
|
384
|
*{$pkg.'::'.$_} = \&{$_}; |
|
504
|
|
|
|
|
10048
|
|
|
504
|
|
|
|
|
711
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub decode_remaining_length { |
61
|
25
|
|
|
25
|
1
|
41
|
my ($data, $offset) = @_; |
62
|
25
|
|
|
|
|
29
|
my $multiplier = 1; |
63
|
25
|
|
|
|
|
26
|
my $v = 0; |
64
|
25
|
|
|
|
|
26
|
my $d; |
65
|
25
|
|
|
|
|
26
|
do { |
66
|
30
|
|
|
|
|
53
|
$d = decode_byte($data, $offset); |
67
|
28
|
|
|
|
|
51
|
$v += ($d&0x7f) * $multiplier; |
68
|
28
|
|
|
|
|
79
|
$multiplier *= 128; |
69
|
|
|
|
|
|
|
} while ($d&0x80); |
70
|
23
|
|
|
|
|
53
|
$v |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub encode_remaining_length { |
75
|
42
|
|
|
42
|
1
|
47
|
my $v = shift; |
76
|
42
|
|
|
|
|
44
|
my $o; |
77
|
|
|
|
|
|
|
my $d; |
78
|
42
|
|
|
|
|
42
|
do { |
79
|
44
|
|
|
|
|
57
|
$d = $v % 128; |
80
|
44
|
|
|
|
|
90
|
$v = int($v/128); |
81
|
44
|
100
|
|
|
|
83
|
if ($v) { |
82
|
2
|
|
|
|
|
4
|
$d |= 0x80; |
83
|
|
|
|
|
|
|
} |
84
|
44
|
|
|
|
|
65
|
$o .= encode_byte($d); |
85
|
|
|
|
|
|
|
} while ($d&0x80); |
86
|
42
|
|
|
|
|
92
|
$o; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub decode_byte { |
91
|
68
|
|
|
68
|
1
|
801
|
my ($data, $offset) = @_; |
92
|
68
|
100
|
|
|
|
818
|
croak 'decode_byte: insufficient data' unless (length $data >= $$offset+1); |
93
|
65
|
|
|
|
|
148
|
my $res = unpack 'C', substr $data, $$offset, 1; |
94
|
65
|
|
|
|
|
77
|
$$offset++; |
95
|
65
|
|
|
|
|
128
|
$res |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub encode_byte { |
100
|
110
|
|
|
110
|
1
|
483
|
pack 'C', $_[0]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub decode_short { |
105
|
29
|
|
|
29
|
1
|
543
|
my ($data, $offset) = @_; |
106
|
29
|
100
|
|
|
|
274
|
croak 'decode_short: insufficient data' unless (length $data >= $$offset+2); |
107
|
27
|
|
|
|
|
64
|
my $res = unpack 'n', substr $data, $$offset, 2; |
108
|
27
|
|
|
|
|
35
|
$$offset += 2; |
109
|
27
|
|
|
|
|
58
|
$res; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub encode_short { |
114
|
24
|
|
|
24
|
1
|
72
|
pack 'n', $_[0]; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub decode_string { |
119
|
16
|
|
|
16
|
1
|
914
|
my ($data, $offset) = @_; |
120
|
16
|
|
|
|
|
32
|
my $len = decode_short($data, $offset); |
121
|
15
|
100
|
|
|
|
138
|
croak 'decode_string: insufficient data' |
122
|
|
|
|
|
|
|
unless (length $data >= $$offset+$len); |
123
|
14
|
|
|
|
|
31
|
my $res = substr $data, $$offset, $len; |
124
|
14
|
|
|
|
|
18
|
$$offset += $len; |
125
|
14
|
|
|
|
|
55
|
$res; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub encode_string { |
130
|
28
|
|
|
28
|
1
|
131
|
pack "n/a*", $_[0]; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub qos_string { |
135
|
48
|
|
|
48
|
1
|
200
|
[qw/at-most-once at-least-once exactly-once reserved/]->[$_[0]] |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub message_type_string { |
140
|
42
|
|
|
42
|
1
|
421
|
[qw/Reserved0 Connect ConnAck Publish PubAck PubRec PubRel PubComp |
141
|
|
|
|
|
|
|
Subscribe SubAck Unsubscribe UnsubAck PingReq PingResp Disconnect |
142
|
|
|
|
|
|
|
Reserved15/]->[$_[0]]; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub dump_string { |
147
|
42
|
|
100
|
42
|
1
|
127
|
my $data = shift || ''; |
148
|
42
|
|
100
|
|
|
131
|
my $prefix = shift || ''; |
149
|
42
|
|
|
|
|
61
|
$prefix .= ' '; |
150
|
42
|
|
|
|
|
77
|
my @lines; |
151
|
42
|
|
|
|
|
100
|
while (length $data) { |
152
|
26
|
|
|
|
|
77
|
my $d = substr $data, 0, 16, ''; |
153
|
26
|
|
|
|
|
71
|
my $line = unpack 'H*', $d; |
154
|
26
|
|
|
|
|
493
|
$line =~ s/([A-F0-9]{2})/$1 /ig; |
155
|
26
|
|
|
|
|
57
|
$d =~ s/[^ -~]/./g; |
156
|
26
|
|
|
|
|
108
|
$line = sprintf "%-48s %s", $line, $d; |
157
|
26
|
|
|
|
|
92
|
push @lines, $line |
158
|
|
|
|
|
|
|
} |
159
|
42
|
100
|
|
|
|
202
|
scalar @lines ? "\n".$prefix.(join "\n".$prefix, @lines) : '' |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub connect_return_code_string { |
165
|
|
|
|
|
|
|
[ |
166
|
4
|
100
|
|
4
|
1
|
45
|
'Connection Accepted', |
167
|
|
|
|
|
|
|
'Connection Refused: unacceptable protocol version', |
168
|
|
|
|
|
|
|
'Connection Refused: identifier rejected', |
169
|
|
|
|
|
|
|
'Connection Refused: server unavailable', |
170
|
|
|
|
|
|
|
'Connection Refused: bad user name or password', |
171
|
|
|
|
|
|
|
'Connection Refused: not authorized', |
172
|
|
|
|
|
|
|
]->[$_[0]] || 'Reserved' |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |