Switch to unified view

a/src/internfile/mh_execm.cpp b/src/internfile/mh_execm.cpp
...
...
17
#include <stdio.h>
17
#include <stdio.h>
18
18
19
#include <iostream>
19
#include <iostream>
20
#include <sstream>
20
#include <sstream>
21
21
22
#include "cstr.h"
22
#include "mh_execm.h"
23
#include "mh_execm.h"
23
#include "mh_html.h"
24
#include "mh_html.h"
24
#include "debuglog.h"
25
#include "debuglog.h"
25
#include "cancelcheck.h"
26
#include "cancelcheck.h"
26
#include "smallut.h"
27
#include "smallut.h"
...
...
83
        return false;
84
        return false;
84
    }
85
    }
85
    // Empty line (end of message) ?
86
    // Empty line (end of message) ?
86
    if (!ibuf.compare("\n")) {
87
    if (!ibuf.compare("\n")) {
87
        LOGDEB(("MHExecMultiple: Got empty line\n"));
88
        LOGDEB(("MHExecMultiple: Got empty line\n"));
88
        name = "";
89
        name.clear();
89
        return true;
90
        return true;
90
    }
91
    }
91
92
92
    // Filters will sometimes abort before entering the real protocol, ie if
93
    // Filters will sometimes abort before entering the real protocol, ie if
93
    // a module can't be loaded. Check the special filter error first word:
94
    // a module can't be loaded. Check the special filter error first word:
...
...
120
    // Hack: check for 'Document:' and read directly the document data
121
    // Hack: check for 'Document:' and read directly the document data
121
    // to m_metaData["content"] to avoid an extra copy of the bulky
122
    // to m_metaData["content"] to avoid an extra copy of the bulky
122
    // piece
123
    // piece
123
    string *datap = &data;
124
    string *datap = &data;
124
    if (!stringlowercmp("document:", name)) {
125
    if (!stringlowercmp("document:", name)) {
125
        datap = &m_metaData["content"];
126
        datap = &m_metaData[cstr_content];
126
    } else {
127
    } else {
127
        datap = &data;
128
        datap = &data;
128
    }
129
    }
129
130
130
    // Read element data
131
    // Read element data
...
...
161
        // m_filefirst is set to true by set_document_file()
162
        // m_filefirst is set to true by set_document_file()
162
        m_filefirst = false;
163
        m_filefirst = false;
163
    } else {
164
    } else {
164
        obuf << "Filename: " << 0 << "\n";
165
        obuf << "Filename: " << 0 << "\n";
165
    }
166
    }
166
    if (m_ipath.length()) {
167
    if (!m_ipath.empty()) {
167
    LOGDEB(("next_doc: sending len %d val [%s]\n", m_ipath.length(),
168
    LOGDEB(("next_doc: sending len %d val [%s]\n", m_ipath.length(),
168
        m_ipath.c_str()));
169
        m_ipath.c_str()));
169
        obuf << "Ipath: " << m_ipath.length() << "\n" << m_ipath;
170
        obuf << "Ipath: " << m_ipath.length() << "\n" << m_ipath;
170
    }
171
    }
171
    if (!m_dfltInputCharset.empty()) {
172
    if (!m_dfltInputCharset.empty()) {
...
...
236
    }
237
    }
237
238
238
    // It used to be that eof could be signalled just by an empty document, but
239
    // It used to be that eof could be signalled just by an empty document, but
239
    // this was wrong. Empty documents can be found ie in zip files and should 
240
    // this was wrong. Empty documents can be found ie in zip files and should 
240
    // not be interpreted as eof.
241
    // not be interpreted as eof.
241
    if (m_metaData["content"].length() == 0) {
242
    if (m_metaData[cstr_content].empty()) {
242
        LOGDEB0(("MHExecMultiple: got empty document inside [%s]: [%s]\n", 
243
        LOGDEB0(("MHExecMultiple: got empty document inside [%s]: [%s]\n", 
243
                m_fn.c_str(), ipath.c_str()));
244
                m_fn.c_str(), ipath.c_str()));
244
    }
245
    }
245
246
246
    // If this has an ipath, it is an internal doc from a
247
    // If this has an ipath, it is an internal doc from a
247
    // multi-document file. In this case, either the filter supplies the 
248
    // multi-document file. In this case, either the filter supplies the 
248
    // mimetype, or the ipath MUST be a filename-like string which we can use
249
    // mimetype, or the ipath MUST be a filename-like string which we can use
249
    // to compute a mime type
250
    // to compute a mime type
250
    if (!ipath.empty()) {
251
    if (!ipath.empty()) {
251
        m_metaData["ipath"] = ipath;
252
        m_metaData[cstr_ipath] = ipath;
252
        if (mtype.empty()) {
253
        if (mtype.empty()) {
253
        LOGDEB0(("MHExecMultiple: no mime type from filter, "
254
        LOGDEB0(("MHExecMultiple: no mime type from filter, "
254
            "using ipath for a guess\n"));
255
            "using ipath for a guess\n"));
255
            mtype = mimetype(ipath, 0, m_config, false);
256
            mtype = mimetype(ipath, 0, m_config, false);
256
            if (mtype.empty()) {
257
            if (mtype.empty()) {
257
                // mimetype() won't call idFile when there is no file. Do it
258
                // mimetype() won't call idFile when there is no file. Do it
258
                mtype = idFileMem(m_metaData["content"]);
259
                mtype = idFileMem(m_metaData[cstr_content]);
259
                if (mtype.empty()) {
260
                if (mtype.empty()) {
260
                    // Note this happens for example for directory zip members
261
                    // Note this happens for example for directory zip members
261
                    // We could recognize them by the end /, but wouldn't know
262
                    // We could recognize them by the end /, but wouldn't know
262
                    // what to do with them anyway.
263
                    // what to do with them anyway.
263
                    LOGINFO(("MHExecMultiple: cant guess mime type\n"));
264
                    LOGINFO(("MHExecMultiple: cant guess mime type\n"));
264
                    mtype = "application/octet-stream";
265
                    mtype = "application/octet-stream";
265
                }
266
                }
266
            }
267
            }
267
        }
268
        }
268
        m_metaData["mimetype"] = mtype;
269
        m_metaData[cstr_mimetype] = mtype;
269
        string md5, xmd5;
270
        string md5, xmd5;
270
        MD5String(m_metaData["content"], md5);
271
        MD5String(m_metaData[cstr_content], md5);
271
        m_metaData["md5"] = MD5HexPrint(md5, xmd5);
272
        m_metaData["md5"] = MD5HexPrint(md5, xmd5);
272
    } else {
273
    } else {
273
        m_metaData["mimetype"] = mtype.empty() ? "text/html" : mtype;
274
        m_metaData[cstr_mimetype] = mtype.empty() ? "text/html" : mtype;
274
        m_metaData.erase("ipath");
275
        m_metaData.erase(cstr_ipath);
275
        string md5, xmd5, reason;
276
        string md5, xmd5, reason;
276
        if (MD5File(m_fn, md5, &reason)) {
277
        if (MD5File(m_fn, md5, &reason)) {
277
            m_metaData["md5"] = MD5HexPrint(md5, xmd5);
278
            m_metaData["md5"] = MD5HexPrint(md5, xmd5);
278
        } else {
279
        } else {
279
            LOGERR(("MimeHandlerExecM: cant compute md5 for [%s]: %s\n",
280
            LOGERR(("MimeHandlerExecM: cant compute md5 for [%s]: %s\n",
...
...
290
        cfgFilterOutputCharset;
291
        cfgFilterOutputCharset;
291
    if (!stringlowercmp("default", charset)) {
292
    if (!stringlowercmp("default", charset)) {
292
        charset = m_dfltInputCharset;
293
        charset = m_dfltInputCharset;
293
    }
294
    }
294
    }
295
    }
295
    m_metaData["charset"] = charset;
296
    m_metaData[cstr_charset] = charset;
296
    
297
    
297
    if (eofnext_received)
298
    if (eofnext_received)
298
        m_havedoc = false;
299
        m_havedoc = false;
299
300
300
    LOGDEB0(("MHExecMultiple: returning %d bytes of content,"
301
    LOGDEB0(("MHExecMultiple: returning %d bytes of content,"
301
      " mtype [%s] charset [%s]\n", 
302
      " mtype [%s] charset [%s]\n", m_metaData[cstr_content].size(), 
302
      m_metaData["content"].size(), m_metaData["mimetype"].c_str(),
303
     m_metaData[cstr_mimetype].c_str(), m_metaData[cstr_charset].c_str()));
303
      m_metaData["charset"].c_str()));
304
    return true;
304
    return true;
305
}
305
}