line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
32982
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
111
|
|
2
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
166
|
|
3
|
|
|
|
|
|
|
package Net::MQTT::Constants; |
4
|
|
|
|
|
|
|
$Net::MQTT::Constants::VERSION = '1.143250'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Module to export constants for MQTT protocol |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
13
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
340
|
|
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
|
|
17
|
no strict qw/refs/; ## no critic |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
2424
|
|
41
|
42
|
|
|
42
|
|
98
|
my $pkg = caller(0); |
42
|
42
|
|
|
|
|
203
|
foreach (keys %constants) { |
43
|
966
|
|
|
|
|
839
|
my $v = $constants{$_}; |
44
|
966
|
|
|
0
|
|
3255
|
*{$pkg.'::'.$_} = sub () { $v }; |
|
966
|
|
|
|
|
3255
|
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
42
|
|
|
|
|
102
|
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
|
|
|
|
|
319
|
*{$pkg.'::'.$_} = \&{$_}; |
|
504
|
|
|
|
|
7577
|
|
|
504
|
|
|
|
|
627
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub decode_remaining_length { |
61
|
25
|
|
|
25
|
1
|
30
|
my ($data, $offset) = @_; |
62
|
25
|
|
|
|
|
26
|
my $multiplier = 1; |
63
|
25
|
|
|
|
|
17
|
my $v = 0; |
64
|
25
|
|
|
|
|
18
|
my $d; |
65
|
25
|
|
|
|
|
21
|
do { |
66
|
30
|
|
|
|
|
31
|
$d = decode_byte($data, $offset); |
67
|
28
|
|
|
|
|
40
|
$v += ($d&0x7f) * $multiplier; |
68
|
28
|
|
|
|
|
54
|
$multiplier *= 128; |
69
|
|
|
|
|
|
|
} while ($d&0x80); |
70
|
23
|
|
|
|
|
39
|
$v |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub encode_remaining_length { |
75
|
42
|
|
|
42
|
1
|
37
|
my $v = shift; |
76
|
42
|
|
|
|
|
35
|
my $o; |
77
|
|
|
|
|
|
|
my $d; |
78
|
42
|
|
|
|
|
31
|
do { |
79
|
44
|
|
|
|
|
46
|
$d = $v % 128; |
80
|
44
|
|
|
|
|
66
|
$v = int($v/128); |
81
|
44
|
100
|
|
|
|
67
|
if ($v) { |
82
|
2
|
|
|
|
|
2
|
$d |= 0x80; |
83
|
|
|
|
|
|
|
} |
84
|
44
|
|
|
|
|
58
|
$o .= encode_byte($d); |
85
|
|
|
|
|
|
|
} while ($d&0x80); |
86
|
42
|
|
|
|
|
71
|
$o; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub decode_byte { |
91
|
68
|
|
|
68
|
1
|
435
|
my ($data, $offset) = @_; |
92
|
68
|
100
|
|
|
|
549
|
croak 'decode_byte: insufficient data' unless (length $data >= $$offset+1); |
93
|
65
|
|
|
|
|
110
|
my $res = unpack 'C', substr $data, $$offset, 1; |
94
|
65
|
|
|
|
|
58
|
$$offset++; |
95
|
65
|
|
|
|
|
101
|
$res |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub encode_byte { |
100
|
110
|
|
|
110
|
1
|
312
|
pack 'C', $_[0]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub decode_short { |
105
|
29
|
|
|
29
|
1
|
380
|
my ($data, $offset) = @_; |
106
|
29
|
100
|
|
|
|
233
|
croak 'decode_short: insufficient data' unless (length $data >= $$offset+2); |
107
|
27
|
|
|
|
|
45
|
my $res = unpack 'n', substr $data, $$offset, 2; |
108
|
27
|
|
|
|
|
29
|
$$offset += 2; |
109
|
27
|
|
|
|
|
40
|
$res; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub encode_short { |
114
|
24
|
|
|
24
|
1
|
52
|
pack 'n', $_[0]; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub decode_string { |
119
|
16
|
|
|
16
|
1
|
652
|
my ($data, $offset) = @_; |
120
|
16
|
|
|
|
|
21
|
my $len = decode_short($data, $offset); |
121
|
15
|
100
|
|
|
|
117
|
croak 'decode_string: insufficient data' |
122
|
|
|
|
|
|
|
unless (length $data >= $$offset+$len); |
123
|
14
|
|
|
|
|
15
|
my $res = substr $data, $$offset, $len; |
124
|
14
|
|
|
|
|
14
|
$$offset += $len; |
125
|
14
|
|
|
|
|
33
|
$res; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub encode_string { |
130
|
28
|
|
|
28
|
1
|
76
|
pack "n/a*", $_[0]; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub qos_string { |
135
|
48
|
|
|
48
|
1
|
147
|
[qw/at-most-once at-least-once exactly-once reserved/]->[$_[0]] |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub message_type_string { |
140
|
42
|
|
|
42
|
1
|
303
|
[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
|
107
|
my $data = shift || ''; |
148
|
42
|
|
100
|
|
|
97
|
my $prefix = shift || ''; |
149
|
42
|
|
|
|
|
42
|
$prefix .= ' '; |
150
|
42
|
|
|
|
|
32
|
my @lines; |
151
|
42
|
|
|
|
|
79
|
while (length $data) { |
152
|
26
|
|
|
|
|
34
|
my $d = substr $data, 0, 16, ''; |
153
|
26
|
|
|
|
|
44
|
my $line = unpack 'H*', $d; |
154
|
26
|
|
|
|
|
272
|
$line =~ s/([A-F0-9]{2})/$1 /ig; |
155
|
26
|
|
|
|
|
31
|
$d =~ s/[^ -~]/./g; |
156
|
26
|
|
|
|
|
84
|
$line = sprintf "%-48s %s", $line, $d; |
157
|
26
|
|
|
|
|
60
|
push @lines, $line |
158
|
|
|
|
|
|
|
} |
159
|
42
|
100
|
|
|
|
144
|
scalar @lines ? "\n".$prefix.(join "\n".$prefix, @lines) : '' |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub connect_return_code_string { |
165
|
|
|
|
|
|
|
[ |
166
|
4
|
100
|
|
4
|
1
|
26
|
'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__ |