|
a/src/utils/fileudi.cpp |
|
b/src/utils/fileudi.cpp |
|
... |
|
... |
24 |
#include "md5.h"
|
24 |
#include "md5.h"
|
25 |
#include "base64.h"
|
25 |
#include "base64.h"
|
26 |
|
26 |
|
27 |
using std::string;
|
27 |
using std::string;
|
28 |
|
28 |
|
29 |
// Debug only
|
|
|
30 |
#ifdef PATHHASH_HEX
|
|
|
31 |
static void md5hexprint(const unsigned char hash[16], string &out)
|
|
|
32 |
{
|
|
|
33 |
out.erase();
|
|
|
34 |
out.reserve(33);
|
|
|
35 |
static const char hex[]="0123456789abcdef";
|
|
|
36 |
for (int i = 0; i < 16; i++) {
|
|
|
37 |
out.append(1, hex[hash[i] >> 4]);
|
|
|
38 |
out.append(1, hex[hash[i] & 0x0f]);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
#endif
|
|
|
42 |
|
|
|
43 |
// Size of the hashed result (base64 of 16 bytes of md5, minus 2 pad chars)
|
29 |
// Size of the hashed result (base64 of 16 bytes of md5, minus 2 pad chars)
|
44 |
#define HASHLEN 22
|
30 |
#define HASHLEN 22
|
45 |
|
31 |
|
46 |
// Convert longish paths by truncating and appending hash of path
|
32 |
// Convert longish paths by truncating and appending hash of path
|
47 |
// The full length of the base64-encoded (minus pad) of the md5 is 22 chars
|
33 |
// The full length of the base64-encoded (minus pad) of the md5 is 22 chars
|
|
... |
|
... |
63 |
MD5_CTX ctx;
|
49 |
MD5_CTX ctx;
|
64 |
MD5Init(&ctx);
|
50 |
MD5Init(&ctx);
|
65 |
MD5Update(&ctx, (const unsigned char *)(path.c_str()+maxlen-HASHLEN),
|
51 |
MD5Update(&ctx, (const unsigned char *)(path.c_str()+maxlen-HASHLEN),
|
66 |
path.length() - (maxlen - HASHLEN));
|
52 |
path.length() - (maxlen - HASHLEN));
|
67 |
MD5Final(chash, &ctx);
|
53 |
MD5Final(chash, &ctx);
|
68 |
|
|
|
69 |
#ifdef PATHHASH_HEX
|
|
|
70 |
string hex;
|
|
|
71 |
md5hexprint(chash, hex);
|
|
|
72 |
printf("hex [%s]\n", hex.c_str());
|
|
|
73 |
#endif
|
|
|
74 |
|
54 |
|
75 |
// Encode it to ascii. This shouldn't be strictly necessary as
|
55 |
// Encode it to ascii. This shouldn't be strictly necessary as
|
76 |
// xapian terms can be binary
|
56 |
// xapian terms can be binary
|
77 |
string hash;
|
57 |
string hash;
|
78 |
base64_encode(string((char *)chash, 16), hash);
|
58 |
base64_encode(string((char *)chash, 16), hash);
|