line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ifndef SRL_READER_MISC_H_ |
2
|
|
|
|
|
|
|
#define SRL_READER_MISC_H_ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include "srl_inline.h" |
5
|
|
|
|
|
|
|
#include "srl_common.h" |
6
|
|
|
|
|
|
|
#include "srl_reader.h" |
7
|
|
|
|
|
|
|
#include "srl_protocol.h" |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
/* not sure that this's the best location for this function */ |
10
|
|
|
|
|
|
|
SRL_STATIC_INLINE IV |
11
|
875256
|
|
|
|
|
|
srl_validate_header_version(pTHX_ srl_reader_char_ptr strdata, STRLEN len) |
12
|
|
|
|
|
|
|
{ |
13
|
875256
|
100
|
|
|
|
|
if ( len >= SRL_MAGIC_STRLEN + 3 ) { |
14
|
|
|
|
|
|
|
/* + 3 above because: |
15
|
|
|
|
|
|
|
* at least one version/flag byte, |
16
|
|
|
|
|
|
|
* one byte for header len, |
17
|
|
|
|
|
|
|
* one type byte (smallest payload) |
18
|
|
|
|
|
|
|
*/ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
/* Do NOT do *((U32*)strdata at least for these reasons: |
21
|
|
|
|
|
|
|
* (1) Unaligned access can "Bus error" on you |
22
|
|
|
|
|
|
|
* (char* can be much less aligned than U32). |
23
|
|
|
|
|
|
|
* (2) In ILP64 even if aligned the U32 would be 64 bits wide, |
24
|
|
|
|
|
|
|
* and the deref would read 8 bytes, more than the smallest |
25
|
|
|
|
|
|
|
* (valid) message. |
26
|
|
|
|
|
|
|
* (3) Endianness. |
27
|
|
|
|
|
|
|
*/ |
28
|
875207
|
|
|
|
|
|
U8 version_encoding= strdata[SRL_MAGIC_STRLEN]; |
29
|
875207
|
|
|
|
|
|
U8 version= version_encoding & SRL_PROTOCOL_VERSION_MASK; |
30
|
|
|
|
|
|
|
|
31
|
875207
|
100
|
|
|
|
|
if ( memEQ(SRL_MAGIC_STRING, strdata, SRL_MAGIC_STRLEN) ) { |
32
|
252016
|
100
|
|
|
|
|
if ( 0 < version && version < 3 ) { |
|
|
100
|
|
|
|
|
|
33
|
252006
|
|
|
|
|
|
return version_encoding; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else |
37
|
623191
|
100
|
|
|
|
|
if ( memEQ(SRL_MAGIC_STRING_HIGHBIT, strdata, SRL_MAGIC_STRLEN) ) { |
38
|
623169
|
100
|
|
|
|
|
if ( 3 <= version ) { |
39
|
623153
|
|
|
|
|
|
return version_encoding; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else |
43
|
22
|
100
|
|
|
|
|
if ( memEQ(SRL_MAGIC_STRING_HIGHBIT_UTF8, strdata, SRL_MAGIC_STRLEN) ) { |
44
|
7
|
|
|
|
|
|
return 0; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
90
|
|
|
|
|
|
return -1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#endif |