Switch to unified view

a/src/internfile/mh_mbox.cpp b/src/internfile/mh_mbox.cpp
...
...
33
#include <regex.h>
33
#include <regex.h>
34
#endif
34
#endif
35
35
36
#include <cstring>
36
#include <cstring>
37
#include <map>
37
#include <map>
38
#include <mutex>
38
39
39
#include "cstr.h"
40
#include "cstr.h"
40
#include "mimehandler.h"
41
#include "mimehandler.h"
41
#include "log.h"
42
#include "log.h"
42
#include "readfile.h"
43
#include "readfile.h"
43
#include "mh_mbox.h"
44
#include "mh_mbox.h"
44
#include "smallut.h"
45
#include "smallut.h"
45
#include "rclconfig.h"
46
#include "rclconfig.h"
46
#include "md5ut.h"
47
#include "md5ut.h"
47
#include "conftree.h"
48
#include "conftree.h"
48
#include "ptmutex.h"
49
49
50
using namespace std;
50
using namespace std;
51
51
52
// Define maximum message size for safety. 100MB would seem reasonable
52
// Define maximum message size for safety. 100MB would seem reasonable
53
static const unsigned int max_mbox_member_size = 100 * 1024 * 1024;
53
static const unsigned int max_mbox_member_size = 100 * 1024 * 1024;
...
...
63
        }
63
        }
64
    }
64
    }
65
private: FILE **m_fpp;
65
private: FILE **m_fpp;
66
};
66
};
67
67
68
static PTMutexInit o_mcache_mutex;
68
static std::mutex o_mcache_mutex;
69
69
70
/**
70
/**
71
 * Handles a cache for message numbers to offset translations. Permits direct
71
 * Handles a cache for message numbers to offset translations. Permits direct
72
 * accesses inside big folders instead of having to scan up to the right place
72
 * accesses inside big folders instead of having to scan up to the right place
73
 *
73
 *
...
...
103
        LOGDEB0("MboxCache::get_offsets: udi ["  << (udi) << "] msgnum "  << (msgnum) << "\n" );
103
        LOGDEB0("MboxCache::get_offsets: udi ["  << (udi) << "] msgnum "  << (msgnum) << "\n" );
104
        if (!ok(config)) {
104
        if (!ok(config)) {
105
            LOGDEB0("MboxCache::get_offsets: init failed\n" );
105
            LOGDEB0("MboxCache::get_offsets: init failed\n" );
106
            return -1;
106
            return -1;
107
        }
107
        }
108
  PTMutexLocker locker(o_mcache_mutex);
108
        std::unique_lock<std::mutex> locker(o_mcache_mutex);
109
        string fn = makefilename(udi);
109
        string fn = makefilename(udi);
110
        FILE *fp = 0;
110
        FILE *fp = 0;
111
        if ((fp = fopen(fn.c_str(), "r")) == 0) {
111
        if ((fp = fopen(fn.c_str(), "r")) == 0) {
112
            LOGDEB("MboxCache::get_offsets: open failed, errno "  << (errno) << "\n" );
112
            LOGDEB("MboxCache::get_offsets: open failed, errno "  << (errno) << "\n" );
113
            return -1;
113
            return -1;
...
...
147
        LOGDEB0("MboxCache::put_offsets: "  << (offs.size()) << " offsets\n" );
147
        LOGDEB0("MboxCache::put_offsets: "  << (offs.size()) << " offsets\n" );
148
        if (!ok(config) || !maybemakedir())
148
        if (!ok(config) || !maybemakedir())
149
            return;
149
            return;
150
        if (fsize < m_minfsize)
150
        if (fsize < m_minfsize)
151
            return;
151
            return;
152
  PTMutexLocker locker(o_mcache_mutex);
152
        std::unique_lock<std::mutex> locker(o_mcache_mutex);
153
        string fn = makefilename(udi);
153
        string fn = makefilename(udi);
154
        FILE *fp;
154
        FILE *fp;
155
        if ((fp = fopen(fn.c_str(), "w")) == 0) {
155
        if ((fp = fopen(fn.c_str(), "w")) == 0) {
156
            LOGDEB("MboxCache::put_offsets: fopen errno "  << (errno) << "\n" );
156
            LOGDEB("MboxCache::put_offsets: fopen errno "  << (errno) << "\n" );
157
            return;
157
            return;
...
...
177
        }
177
        }
178
    }
178
    }
179
179
180
    // Check state, possibly initialize
180
    // Check state, possibly initialize
181
    bool ok(RclConfig *config) {
181
    bool ok(RclConfig *config) {
182
  PTMutexLocker locker(o_mcache_mutex);
182
        std::unique_lock<std::mutex> locker(o_mcache_mutex);
183
        if (m_minfsize == -1)
183
        if (m_minfsize == -1)
184
            return false;
184
            return false;
185
        if (!m_ok) {
185
        if (!m_ok) {
186
            int minmbs = 5;
186
            int minmbs = 5;
187
            config->getConfParam("mboxcacheminmbs", &minmbs);
187
            config->getConfParam("mboxcacheminmbs", &minmbs);
...
...
391
#define M_regexec(A, B, C, D, E) (!regex_match(B,A))
391
#define M_regexec(A, B, C, D, E) (!regex_match(B,A))
392
392
393
#endif
393
#endif
394
394
395
static bool regcompiled;
395
static bool regcompiled;
396
static PTMutexInit o_regex_mutex;
396
static std::mutex o_regex_mutex;
397
397
398
static void compileregexes()
398
static void compileregexes()
399
{
399
{
400
    PTMutexLocker locker(o_regex_mutex);
400
    std::unique_lock<std::mutex> locker(o_regex_mutex);
401
    // As the initial test of regcompiled is unprotected the value may
401
    // As the initial test of regcompiled is unprotected the value may
402
    // have changed while we were waiting for the lock. Test again now
402
    // have changed while we were waiting for the lock. Test again now
403
    // that we are alone.
403
    // that we are alone.
404
    if (regcompiled)
404
    if (regcompiled)
405
    return;
405
    return;