Switch to unified view

a/src/query/docseqhist.cpp b/src/query/docseqhist.cpp
...
...
23
23
24
#include "docseqhist.h"
24
#include "docseqhist.h"
25
#include "rcldb.h"
25
#include "rcldb.h"
26
#include "fileudi.h"
26
#include "fileudi.h"
27
#include "internfile.h"
27
#include "internfile.h"
28
#include "base64.h"
29
#include "debuglog.h"
30
#include "smallut.h"
31
32
// Encode document history entry: 
33
// U + Unix time + base64 of udi
34
// The U distinguishes udi-based entries from older fn+ipath ones
35
bool RclDHistoryEntry::encode(string& value)
36
{
37
    char chartime[20];
38
    sprintf(chartime, "%ld", unixtime);
39
    string budi;
40
    base64_encode(udi, budi);
41
    value = string("U ") + string(chartime) + " " + budi;
42
    return true;
43
}
44
45
// Decode. We support historical entries which were like "time b64fn [b64ipath]"
46
// Current entry format is "U time b64udi"
47
bool RclDHistoryEntry::decode(const string &value)
48
{
49
    list<string> vall;
50
    stringToStrings(value, vall);
51
52
    list<string>::const_iterator it = vall.begin();
53
    udi.erase();
54
    string fn, ipath;
55
    switch (vall.size()) {
56
    case 2:
57
        // Old fn+ipath, null ipath case 
58
        unixtime = atol((*it++).c_str());
59
        base64_decode(*it++, fn);
60
        break;
61
    case 3:
62
        if (!it->compare("U")) {
63
            // New udi-based entry
64
            it++;
65
            unixtime = atol((*it++).c_str());
66
            base64_decode(*it++, udi);
67
        } else {
68
            // Old fn + ipath. We happen to know how to build an udi
69
            unixtime = atol((*it++).c_str());
70
            base64_decode(*it++, fn);
71
            base64_decode(*it, ipath);
72
        }
73
        break;
74
    default: 
75
        return false;
76
    }
77
78
    if (!fn.empty()) {
79
        // Old style entry found, make an udi, using the fs udi maker
80
        make_udi(fn, ipath, udi);
81
    }
82
    LOGDEB(("RclDHistoryEntry::decode: udi [%s]\n", udi.c_str()));
83
    return true;
84
}
85
86
bool RclDHistoryEntry::equal(const DynConfEntry& other)
87
{
88
    const RclDHistoryEntry& e = dynamic_cast<const RclDHistoryEntry&>(other);
89
    return e.udi == udi;
90
}
91
92
bool historyEnterDoc(RclDynConf *dncf, const string& udi)
93
{
94
    LOGDEB(("historyEnterDoc: [%s] into %s\n", 
95
      udi.c_str(), dncf->getFilename().c_str()));
96
    RclDHistoryEntry ne(time(0), udi);
97
    RclDHistoryEntry scratch;
98
    return dncf->insertNew(docHistSubKey, ne, scratch, 200);
99
}
100
101
list<RclDHistoryEntry> getDocHistory(RclDynConf* dncf)
102
{
103
    return dncf->getList<RclDHistoryEntry>(docHistSubKey);
104
}
105
28
106
29
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) 
107
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) 
30
{
108
{
31
    // Retrieve history list
109
    // Retrieve history list
32
    if (!m_hist)
110
    if (!m_hist)
33
    return false;
111
    return false;
34
    if (m_hlist.empty())
112
    if (m_hlist.empty())
35
    m_hlist = m_hist->getDocHistory();
113
    m_hlist = getDocHistory(m_hist);
36
114
37
    if (num < 0 || num >= (int)m_hlist.size())
115
    if (num < 0 || num >= (int)m_hlist.size())
38
    return false;
116
    return false;
39
    int skip;
117
    int skip;
40
    if (m_prevnum >= 0 && num >= m_prevnum) {
118
    if (m_prevnum >= 0 && num >= m_prevnum) {
...
...
46
    }
124
    }
47
    m_prevnum = num;
125
    m_prevnum = num;
48
    while (skip--) 
126
    while (skip--) 
49
    m_it++;
127
    m_it++;
50
    if (sh) {
128
    if (sh) {
129
  if (m_prevtime < 0 || 
51
  if (m_prevtime < 0 || abs (float(m_prevtime) - float(m_it->unixtime)) > 86400) {
130
            abs (float(m_prevtime) - float(m_it->unixtime)) > 86400) {
52
        m_prevtime = m_it->unixtime;
131
        m_prevtime = m_it->unixtime;
53
        time_t t = (time_t)(m_it->unixtime);
132
        time_t t = (time_t)(m_it->unixtime);
54
        *sh = string(ctime(&t));
133
        *sh = string(ctime(&t));
55
        // Get rid of the final \n in ctime
134
        // Get rid of the final \n in ctime
56
        sh->erase(sh->length()-1);
135
        sh->erase(sh->length()-1);
57
    } else
136
    } else
58
        sh->erase();
137
        sh->erase();
59
    }
138
    }
60
    string udi;
61
    make_udi(m_it->fn, m_it->ipath, udi);
62
    bool ret = m_db->getDoc(udi, doc);
139
    bool ret = m_db->getDoc(m_it->udi, doc);
63
    if (!ret) {
140
    if (!ret) {
64
  doc.url = string("file://") + m_it->fn;
141
  doc.url = "UNKNOWN";
65
  doc.ipath = m_it->ipath;
142
        doc.ipath = "";
66
    }
143
    }
67
    return ret;
144
    return ret;
68
}
145
}
69
146
70
bool DocSequenceHistory::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc) 
147
bool DocSequenceHistory::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc) 
...
...
77
}
154
}
78
155
79
int DocSequenceHistory::getResCnt()
156
int DocSequenceHistory::getResCnt()
80
{   
157
{   
81
    if (m_hlist.empty())
158
    if (m_hlist.empty())
82
    m_hlist = m_hist->getDocHistory();
159
    m_hlist = getDocHistory(m_hist);
83
    return m_hlist.size();
160
    return m_hlist.size();
84
}
161
}