| 1 |
|
| |
| 2 |
|
| #ifdef __cplusplus |
| 3 |
|
| extern "C" { |
| 4 |
|
| #endif |
| 5 |
|
| |
| 6 |
|
| #include "EXTERN.h" |
| 7 |
|
| #include "perl.h" |
| 8 |
|
| #include "XSUB.h" |
| 9 |
|
| #undef do_open |
| 10 |
|
| #undef do_close |
| 11 |
|
| |
| 12 |
|
| #ifdef __cplusplus |
| 13 |
|
| } |
| 14 |
|
| #endif |
| 15 |
|
| |
| 16 |
|
| #include "os.h" |
| 17 |
|
| #include "getpagesize.c" |
| 18 |
|
| |
| 19 |
|
| #include "stdinc.h" |
| 20 |
|
| #include "TigerHash.cpp" |
| 21 |
|
| #include "Encoder.cpp" |
| 22 |
|
| #include "MerkleTree.h" |
| 23 |
|
| |
| 24 |
|
| |
| 25 |
|
| MODULE = Net::DirectConnect::TigerHash PACKAGE = Net::DirectConnect::TigerHash |
| 26 |
|
| |
| 27 |
|
| |
| 28 |
|
| SV * |
| 29 |
|
| tthbin(s) |
| 30 |
|
| SV *s |
| 31 |
|
| PROTOTYPE: $ |
| 32 |
|
| CODE: |
| 33 |
|
| STRLEN len; |
| 34 |
0 |
| char * ptr = SvPV(s, len); |
| 35 |
0 |
| dcpp::TigerHash th; |
| 36 |
0 |
▶ | th.update(ptr, len); |
Branch: 1 branch
| Branch | True | False | Total |
| th.update(ptr, len); |
0 |
0 |
0 |
|
| 37 |
0 |
▶ | RETVAL = newSVpv((const char*)(th.finalize()), (STRLEN)dcpp::TigerHash::BYTES); |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = newSVpv((const char*)(th.finalize()), (STRLEN)dcpp::TigerHash::BYTES); |
0 |
0 |
0 |
| RETVAL = newSVpv((const char*)(th.finalize()), (STRLEN)dcpp::TigerHash::BYTES); |
0 |
0 |
0 |
| RETVAL = newSVpv((const char*)(th.finalize()), (STRLEN)dcpp::TigerHash::BYTES); |
0 |
0 |
0 |
|
| 38 |
|
| OUTPUT: |
| 39 |
|
| RETVAL |
| 40 |
|
| |
| 41 |
|
| |
| 42 |
|
| SV * |
| 43 |
|
| tth(s) |
| 44 |
|
| SV *s |
| 45 |
|
| PROTOTYPE: $ |
| 46 |
|
| CODE: |
| 47 |
|
| STRLEN len; |
| 48 |
5 |
| char * ptr = SvPV(s, len); |
| 49 |
5 |
| dcpp::TigerHash th; |
| 50 |
5 |
▶ | th.update(ptr, len); |
Branch: 1 branch
| Branch | True | False | Total |
| th.update(ptr, len); |
5 |
0 |
5 |
|
| 51 |
5 |
| std::string enc ; |
| 52 |
5 |
▶ | dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
Branch: 2 branches
| Branch | True | False | Total |
| dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
5 |
0 |
5 |
| dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
5 |
0 |
5 |
|
| 53 |
5 |
▶ | RETVAL = newSVpv( enc.data(), enc.length()); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = newSVpv( enc.data(), enc.length()); |
5 |
0 |
5 |
| RETVAL = newSVpv( enc.data(), enc.length()); |
5 |
0 |
5 |
|
| 54 |
|
| OUTPUT: |
| 55 |
|
| RETVAL |
| 56 |
|
| |
| 57 |
|
| SV * |
| 58 |
|
| tthfile(s) |
| 59 |
|
| SV *s |
| 60 |
|
| PROTOTYPE: $ |
| 61 |
|
| CODE: |
| 62 |
|
| |
| 63 |
|
| STRLEN len; |
| 64 |
13 |
| char * file = SvPV(s, len); |
| 65 |
13 |
▶ | long fd = open(file, O_RDONLY | O_BINARY); |
Branch: 1 branch
| Branch | True | False | Total |
| long fd = open(file, O_RDONLY | O_BINARY); |
13 |
0 |
13 |
|
| 66 |
13 |
▶ | if(fd <=0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(fd <=0 ) { |
2 |
11 |
13 |
|
| 67 |
3 |
| XSRETURN_UNDEF; |
| 68 |
|
| } |
| 69 |
|
| STAT buffer; |
| 70 |
11 |
| int status = fstat(fd, &buffer); |
| 71 |
|
| |
| 72 |
11 |
▶ | if (!(S_ISREG(buffer.st_mode) || S_ISLNK(buffer.st_mode))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(S_ISREG(buffer.st_mode) || S_ISLNK(buffer.st_mode))) { |
1 |
10 |
11 |
| if (!(S_ISREG(buffer.st_mode) || S_ISLNK(buffer.st_mode))) { |
1 |
0 |
1 |
|
| 73 |
1 |
▶ | close(fd); |
Branch: 1 branch
| Branch | True | False | Total |
| close(fd); |
1 |
0 |
1 |
|
| 74 |
1 |
| XSRETURN_UNDEF; |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
10 |
| int64_t size = buffer.st_size; |
| 78 |
10 |
| int64_t pos = 0; |
| 79 |
10 |
▶ | static const int64_t BUF_SIZE = 0x1000000 - (0x1000000 % getpagesize()); |
Branch: 2 branches
| Branch | True | False | Total |
| static const int64_t BUF_SIZE = 0x1000000 - (0x1000000 % getpagesize()); |
1 |
9 |
10 |
| static const int64_t BUF_SIZE = 0x1000000 - (0x1000000 % getpagesize()); |
1 |
0 |
1 |
|
| 80 |
10 |
| const int64_t MIN_BLOCK_SIZE = 64*1024; |
| 81 |
10 |
▶ | uint8_t* buf = new uint8_t[BUF_SIZE]; |
Branch: 1 branch
| Branch | True | False | Total |
| uint8_t* buf = new uint8_t[BUF_SIZE]; |
10 |
0 |
10 |
|
| 82 |
|
| |
| 83 |
10 |
| size_t n = 0; |
| 84 |
10 |
| int64_t bs = std::max((unsigned long)dcpp::TigerTree::calcBlockSize(size, 10), (unsigned long)MIN_BLOCK_SIZE); |
| 85 |
10 |
▶ | dcpp::TigerTree th(bs); |
Branch: 1 branch
| Branch | True | False | Total |
| dcpp::TigerTree th(bs); |
10 |
0 |
10 |
|
| 86 |
|
| do { |
| 87 |
19 |
▶ | if (( n = read(fd, buf, BUF_SIZE))>0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (( n = read(fd, buf, BUF_SIZE))>0) { |
19 |
0 |
19 |
| if (( n = read(fd, buf, BUF_SIZE))>0) { |
9 |
10 |
19 |
|
| 88 |
9 |
▶ | th.update(buf, n); |
Branch: 1 branch
| Branch | True | False | Total |
| th.update(buf, n); |
9 |
0 |
9 |
|
| 89 |
9 |
| pos += n; |
| 90 |
|
| } |
| 91 |
19 |
▶ | } while (n > 0); |
Branch: 1 branch
| Branch | True | False | Total |
| } while (n > 0); |
9 |
10 |
19 |
|
| 92 |
10 |
▶ | close(fd); |
Branch: 1 branch
| Branch | True | False | Total |
| close(fd); |
10 |
0 |
10 |
|
| 93 |
10 |
▶ | th.update(buf, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| th.update(buf, 0); |
10 |
0 |
10 |
|
| 94 |
10 |
| std::string enc; |
| 95 |
10 |
▶ | dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
Branch: 2 branches
| Branch | True | False | Total |
| dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
10 |
0 |
10 |
| dcpp::Encoder::toBase32( th.finalize(), dcpp::TigerHash::BYTES, enc); |
10 |
0 |
10 |
|
| 96 |
10 |
▶ | delete [] buf; |
Branch: 1 branch
| Branch | True | False | Total |
| delete [] buf; |
10 |
0 |
10 |
|
| 97 |
10 |
▶ | RETVAL = newSVpv( enc.data(), enc.length()); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = newSVpv( enc.data(), enc.length()); |
10 |
0 |
10 |
| RETVAL = newSVpv( enc.data(), enc.length()); |
10 |
0 |
10 |
|
| 98 |
|
| |
| 99 |
|
| OUTPUT: |
| 100 |
|
| RETVAL |
| 101 |
|
| |
| 102 |
|
| |
| 103 |
|
| SV * |
| 104 |
|
| toBase32(s) |
| 105 |
|
| SV *s |
| 106 |
|
| PROTOTYPE: $ |
| 107 |
|
| CODE: |
| 108 |
|
| STRLEN len; |
| 109 |
2 |
| char * ptr = SvPV(s, len); |
| 110 |
2 |
| std::string enc; |
| 111 |
2 |
▶ | dcpp::Encoder::toBase32((const uint8_t*)ptr, len, enc); |
Branch: 1 branch
| Branch | True | False | Total |
| dcpp::Encoder::toBase32((const uint8_t*)ptr, len, enc); |
2 |
0 |
2 |
|
| 112 |
2 |
▶ | RETVAL = newSVpv( enc.data(), enc.length()); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = newSVpv( enc.data(), enc.length()); |
2 |
0 |
2 |
| RETVAL = newSVpv( enc.data(), enc.length()); |
2 |
0 |
2 |
|
| 113 |
|
| OUTPUT: |
| 114 |
|
| RETVAL |
| 115 |
|
| |
| 116 |
|
| |
| 117 |
|
| SV * |
| 118 |
|
| fromBase32(s) |
| 119 |
|
| SV *s |
| 120 |
|
| PROTOTYPE: $ |
| 121 |
|
| CODE: |
| 122 |
|
| STRLEN len; |
| 123 |
2 |
| char * ptr = SvPV(s, len); |
| 124 |
2 |
| len = len * 5 / 8; |
| 125 |
2 |
▶ | uint8_t* dst = new uint8_t [len]; |
Branch: 1 branch
| Branch | True | False | Total |
| uint8_t* dst = new uint8_t [len]; |
2 |
0 |
2 |
|
| 126 |
2 |
▶ | dcpp::Encoder::fromBase32(ptr, dst, len); |
Branch: 1 branch
| Branch | True | False | Total |
| dcpp::Encoder::fromBase32(ptr, dst, len); |
2 |
0 |
2 |
|
| 127 |
2 |
▶ | RETVAL = newSVpv((const char*) dst, len); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = newSVpv((const char*) dst, len); |
2 |
0 |
2 |
| RETVAL = newSVpv((const char*) dst, len); |
2 |
0 |
2 |
|
| 128 |
|
| OUTPUT: |
| 129 |
|
| RETVAL |
| 130 |
|
| |
| 131 |
|
| |