|
a/src/internfile/mimehandler.cpp |
|
b/src/internfile/mimehandler.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.16 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.17 2006-03-20 16:05:41 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
29 |
#include "smallut.h"
|
29 |
#include "smallut.h"
|
30 |
#include "mh_html.h"
|
30 |
#include "mh_html.h"
|
31 |
#include "mh_mail.h"
|
31 |
#include "mh_mail.h"
|
32 |
#include "mh_text.h"
|
32 |
#include "mh_text.h"
|
33 |
#include "mh_exec.h"
|
33 |
#include "mh_exec.h"
|
|
|
34 |
#include "mh_unknown.h"
|
34 |
|
35 |
|
35 |
/** Create internal handler object appropriate for given mime type */
|
36 |
/** Create internal handler object appropriate for given mime type */
|
36 |
static MimeHandler *mhFactory(const string &mime)
|
37 |
static MimeHandler *mhFactory(const string &mime)
|
37 |
{
|
38 |
{
|
38 |
if (!stringlowercmp("text/plain", mime))
|
39 |
if (!stringlowercmp("text/plain", mime))
|
|
... |
|
... |
50 |
* Return handler object for given mime type:
|
51 |
* Return handler object for given mime type:
|
51 |
*/
|
52 |
*/
|
52 |
MimeHandler *getMimeHandler(const string &mtype, RclConfig *cfg)
|
53 |
MimeHandler *getMimeHandler(const string &mtype, RclConfig *cfg)
|
53 |
{
|
54 |
{
|
54 |
// Get handler definition for mime type
|
55 |
// Get handler definition for mime type
|
|
|
56 |
string hs;
|
|
|
57 |
if (!mtype.empty())
|
55 |
string hs = cfg->getMimeHandlerDef(mtype);
|
58 |
hs = cfg->getMimeHandlerDef(mtype);
|
56 |
if (hs.empty())
|
|
|
57 |
return 0;
|
|
|
58 |
|
59 |
|
|
|
60 |
if (!hs.empty()) {
|
59 |
// Break definition into type and name
|
61 |
// Break definition into type and name
|
60 |
list<string> toks;
|
62 |
list<string> toks;
|
61 |
stringToStrings(hs, toks);
|
63 |
stringToStrings(hs, toks);
|
62 |
if (toks.empty()) {
|
64 |
if (toks.empty()) {
|
63 |
LOGERR(("getMimeHandler: bad mimeconf line for %s\n", mtype.c_str()));
|
65 |
LOGERR(("getMimeHandler: bad mimeconf line for %s\n",
|
|
|
66 |
mtype.c_str()));
|
|
|
67 |
return 0;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Retrieve handler function according to type
|
|
|
71 |
if (!stringlowercmp("internal", toks.front())) {
|
|
|
72 |
return mhFactory(mtype);
|
|
|
73 |
} else if (!stringlowercmp("dll", toks.front())) {
|
|
|
74 |
} else if (!stringlowercmp("exec", toks.front())) {
|
|
|
75 |
if (toks.size() < 2) {
|
|
|
76 |
LOGERR(("getMimeHandler: bad line for %s: %s\n",
|
|
|
77 |
mtype.c_str(), hs.c_str()));
|
|
|
78 |
return 0;
|
|
|
79 |
}
|
|
|
80 |
MimeHandlerExec *h = new MimeHandlerExec;
|
|
|
81 |
list<string>::const_iterator it1 = toks.begin();
|
|
|
82 |
it1++;
|
|
|
83 |
for (;it1 != toks.end();it1++)
|
|
|
84 |
h->params.push_back(*it1);
|
|
|
85 |
return h;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// We are supposed to get here if there was no specific error, but
|
|
|
90 |
// there is no identified mime type, or no handler
|
|
|
91 |
// associated. These files are either ignored or their name is
|
|
|
92 |
// indexed, depending on configuration
|
|
|
93 |
bool indexunknown = false;
|
|
|
94 |
cfg->getConfParam("indexallfilenames", &indexunknown);
|
|
|
95 |
if (indexunknown) {
|
|
|
96 |
return new MimeHandlerUnknown;
|
|
|
97 |
} else {
|
64 |
return 0;
|
98 |
return 0;
|
65 |
}
|
99 |
}
|
66 |
|
|
|
67 |
// Retrieve handler function according to type
|
|
|
68 |
if (!stringlowercmp("internal", toks.front())) {
|
|
|
69 |
return mhFactory(mtype);
|
|
|
70 |
} else if (!stringlowercmp("dll", toks.front())) {
|
|
|
71 |
return 0;
|
|
|
72 |
} else if (!stringlowercmp("exec", toks.front())) {
|
|
|
73 |
if (toks.size() < 2) {
|
|
|
74 |
LOGERR(("getMimeHandler: bad line for %s: %s\n", mtype.c_str(),
|
|
|
75 |
hs.c_str()));
|
|
|
76 |
return 0;
|
|
|
77 |
}
|
|
|
78 |
MimeHandlerExec *h = new MimeHandlerExec;
|
|
|
79 |
list<string>::const_iterator it1 = toks.begin();
|
|
|
80 |
it1++;
|
|
|
81 |
for (;it1 != toks.end();it1++)
|
|
|
82 |
h->params.push_back(*it1);
|
|
|
83 |
return h;
|
|
|
84 |
}
|
|
|
85 |
return 0;
|
|
|
86 |
}
|
100 |
}
|